Section 19.2.8

Inductive safety closure and widening termination

Definition

Inductive safety closure is the condition under which a computed set of states proves a safety property §1.11, a statement that no bad state is ever reached: the set contains every initial state, one step from any state in it leads back into it, and it contains no bad state. Widening termination is the guarantee that an analysis using widening, an operation that enlarges a still-growing summary of states, reaches a summary with the first two properties in finitely many rounds; the third must still be checked.

Where it fits

Main entry: Widening and narrowing (§3.23).

Write S0S_0 for the set of initial states, post(S)\mathrm{post}(S) for the set of states one step away from some state in a set SS, and BB for the set of bad states. The exact set of reachable states §3.21 is the least fixed point §3.22 of F(S)=S0∪post(S)F(S) = S_0 \cup \mathrm{post}(S): the smallest set SS with F(S)=SF(S) = S. A safety proof does not need it. Any set JJ with S0⊆J,post(J)⊆J,J∩B=∅S_0 \subseteq J, \qquad \mathrm{post}(J) \subseteq J, \qquad J \cap B = \emptyset contains every reachable state, by induction on the number of steps, and so proves that no run reaches BB. These are the three obligations of an inductive invariant §19.2.4. The first two together say F(J)⊆JF(J) \subseteq J. The Widening and narrowing entry calls such a JJ a post-fixed point; other texts call it a pre-fixed point, so state the inclusion instead of relying on the name. Neither name in this entry’s title is a standard term: textbooks speak of an inductive invariant that implies the property, or of a post-fixed point that excludes the bad states, and of the termination of widening.

Widening supplies such a JJ in finitely many rounds, as a summary a*a^{*} with F#(a*)⊑a*F^{\#}(a^{*}) \sqsubseteq a^{*}. Here F#F^{\#} is a sound counterpart of FF on summaries, and ⊑\sqsubseteq means “is at least as precise as”. The set of states that a*a^{*} stands for then passes the first two obligations. The third is a separate check. If the set contains a bad state, the analysis has proved nothing either way, because the bad state may have been added by the approximation.

A counter cc starts at 0, and while c<2c < 2 a step adds 1. The values reachable at the loop test are 0, 1 and 2, and the safety property is c≤3c \le 3.

Limits and common mistakes

Stopping is not closure. An implementation that stops after a fixed number of rounds, or when its data stops changing for any reason other than a passed test F#(a)⊑aF^{\#}(a) \sqsubseteq a, may stop at a summary that misses reachable states, as [0,1][0, 1] does above. The closure test must use a sound F#F^{\#} that includes every step of the model: resets, error paths and interrupts §6.11 as well as the loop body.

Narrowing keeps soundness §3.7 only while each of its results stays closed. The standard conditions on a narrowing operator guarantee this when F#F^{\#} is monotone, meaning that a more precise input never gives a less precise output, and they also make the shrinking phase stop.

Questions answered

Does the least fixed point need to be computed exactly?

No: a safety proof needs only some set of states that contains every initial state, is closed under the program’s steps (one step from any state in the set stays in the set), and contains no bad state. The least fixed point is the exact set of reachable states, the smallest set that contains the initial states and is closed. Every closed set that contains the initial states contains the least fixed point, so if such a set avoids the bad states, every reachable state does too.

Example: a counter starts at 0 and adds 1 while it is below 2, so it reaches 0, 1 and 2. The interval [0,3][0, 3] contains 0, its values below 2 step to 1 and 2, and all its values satisfy c≤3c \le 3. It therefore proves c≤3c \le 3 although it contains the unreachable value 3.

Computing the exact set is in general impossible, because whether a state is reachable is undecidable §19.2.1 for programs over unbounded integers. Widening, an operation that enlarges a still-growing summary, produces a closed overapproximation §19.2.5 in finitely many rounds instead. Two checks remain: the result must be closed under every step the model allows, which the implementation’s having stopped changing does not show, and it must contain no bad state, because a set that is too coarse proves nothing.

Related entries: Fixed point (§3.22), Loop invariant (§3.24), Inductive invariant and its three obligations (§19.2.4). Further reading: [69].