Describe how abstract interpretation can be used to generate loop invariants, and what determines the precision of the generated invariants.
Think about your answer, then reveal below.
Model answer: Abstract interpretation computes a fixed point of the abstract transfer function for the loop body, starting from the abstract initial state. The fixed point IS the loop invariant (in the abstract domain). Widening forces convergence when the domain has infinite ascending chains. The precision of the invariant depends on the abstract domain: interval analysis generates bounds (x in [0, 100]), octagon analysis generates relational constraints (+/-x +/- y <= c), and polyhedra analysis generates arbitrary linear constraints. Richer domains yield stronger invariants but at higher computational cost.
This is the most principled approach to invariant generation. The abstract domain determines what kinds of invariants can be expressed. If the true invariant is 'x + y <= n', interval analysis cannot discover it (it only tracks individual variables), but octagon analysis can. If the invariant involves nonlinear relationships, all these domains fail, and you need polynomial invariants or template-based approaches. Choosing the right domain for the target property is the key engineering decision.