Algorithm Search⌘K

Theoremresearch

Transition invariant theorem

Also called disjunctive well-foundedness.

A program terminates iff its transition relation has a transition invariant that is a finite union of well-founded relations.

The transition invariant theorem of Podelski and Rybalchenko says that a program terminates if and only if the transitive closure of its step relation, on reachable states, is contained in a finite union of well-founded relations. Each relation in the union can be proved well-founded alone, often with one linear ranking function, and no single order for the whole program is needed. The "if" direction rests on the infinite form of Ramsey's theorem. The theorem is the basis of the Terminator tool and of many automatic termination provers.

Statement

Programs. A program is a set of states SS, a set of initial states I⊆SI \subseteq S and a transition relation R⊆S×SR \subseteq S \times S. A computation is a finite or infinite sequence s0,s1,…s_0, s_1, \ldots with s0∈Is_0 \in I and (sj,sj+1)∈R(s_j, s_{j+1}) \in R for each step. A state is reachable if it occurs in a computation; Acc\mathrm{Acc} is the set of reachable states. The program terminates if it has no infinite computation.

Relations. A relation T⊆S×ST \subseteq S \times S is well-founded if there is no infinite sequence x0,x1,x2,…x_0, x_1, x_2, \ldots with (xj,xj+1)∈T(x_j, x_{j+1}) \in T for all jj. TT is disjunctively well-founded if T=T1∪⋯∪TkT = T_1 \cup \cdots \cup T_k for some finite kk and well-founded T1,…,TkT_1, \ldots, T_k. R+R^+ is the transitive closure of RR: the pairs (s,s′)(s, s') such that s′s' is reached from ss in one or more steps.

Transition invariant. TT is a transition invariant of the program if R+∩(Acc×S)⊆TR^+ \cap (\mathrm{Acc} \times S) \subseteq T, that is, if (s,s′)∈T(s, s') \in T whenever ss is reachable and s′s' is reached from ss in at least one step.

Theorem. A program terminates if and only if it has a disjunctively well-founded transition invariant.

In plain words

To show that a loop stops, the classic way is one measure that drops on every step and cannot drop for ever. For a program with many paths, one such measure can be hard to find. This theorem says that you can use several simple measures instead. The condition is: for any two moments of a run, an earlier one and a later one, at least one of the measures has dropped between them. If each measure cannot drop for ever, the run must stop. The important detail is "any two moments", not only "two moments next to each other". With only next steps, two measures can take turns going down and up, and the run never stops.

Proof

Lemma (infinite Ramsey for pairs). Color every pair {i,j}\{i, j\} of natural numbers, i<ji < j, with one of kk colors. Then there is an infinite set H⊆NH \subseteq \mathbb{N} and a color mm such that every pair of HH has color mm.

Proof of the lemma. Put A0=NA_0 = \mathbb{N}. Given an infinite set AtA_t, let at=min⁡Ata_t = \min A_t. The infinitely many x∈At∖{at}x \in A_t \setminus \{a_t\} fall into kk classes by the color of {at,x}\{a_t, x\}, so one class is infinite, by the pigeonhole principle. Let At+1A_{t+1} be that class and ctc_t its color. Then a0<a1<⋯a_0 < a_1 < \cdots, since At+1⊆At∖{at}A_{t+1} \subseteq A_t \setminus \{a_t\} and ata_t is the least element of AtA_t, and for t<ut < u the element aua_u lies in At+1A_{t+1}, so {at,au}\{a_t, a_u\} has color ctc_t. The colors c0,c1,…c_0, c_1, \ldots take only kk values, so some color mm equals ctc_t for infinitely many tt, say t0<t1<⋯t_0 < t_1 < \cdots. Put H={at0,at1,…}H = \{a_{t_0}, a_{t_1}, \ldots\}. For p<qp < q, the pair {atp,atq}\{a_{t_p}, a_{t_q}\} has color ctp=mc_{t_p} = m. □\square

If. Let T=T1∪⋯∪TkT = T_1 \cup \cdots \cup T_k be a disjunctively well-founded transition invariant, and suppose that s0,s1,…s_0, s_1, \ldots is an infinite computation. For i<ji < j, sis_i is reachable and sjs_j is reached from sis_i in j−i≥1j - i \ge 1 steps, so (si,sj)∈R+∩(Acc×S)⊆T(s_i, s_j) \in R^+ \cap (\mathrm{Acc} \times S) \subseteq T. Color the pair {i,j}\{i, j\} with the least mm such that (si,sj)∈Tm(s_i, s_j) \in T_m. By the lemma there are indices h0<h1<h2<⋯h_0 < h_1 < h_2 < \cdots whose pairs all have the same color mm. In particular (shl,shl+1)∈Tm(s_{h_l}, s_{h_{l+1}}) \in T_m for every ll, so sh0,sh1,…s_{h_0}, s_{h_1}, \ldots is an infinite descending sequence of TmT_m. This contradicts the well-foundedness of TmT_m. So there is no infinite computation.

Only if. Suppose the program terminates. Take k=1k = 1 and T1=R+∩(Acc×S)T_1 = R^+ \cap (\mathrm{Acc} \times S). It is a transition invariant by definition. Suppose it is not well-founded, with an infinite sequence x0,x1,…x_0, x_1, \ldots and (xj,xj+1)∈T1(x_j, x_{j+1}) \in T_1. Then x0x_0 is reachable, so a computation s0,…,sr=x0s_0, \ldots, s_r = x_0 reaches it. Each pair (xj,xj+1)(x_j, x_{j+1}) is in R+R^+, so a path of one or more RR steps leads from xjx_j to xj+1x_{j+1}. Join the computation to x0x_0 and all these paths. The result is an infinite computation, since every path adds at least one step. This contradicts termination. ■\blacksquare

Consequences

  • Termination proofs by parts. To prove termination it is enough to cover R+R^+ by finitely many relations and give each a ranking function. Terminator by Cook, Podelski and Rybalchenko does this: it guesses TT, asks a model checker for a pair in R+R^+ that is not covered, synthesizes a ranking function for the loop path of that pair with linear ranking function synthesis, adds it to TT, and repeats.
  • The check is a safety property. "TT is a transition invariant" is a safety property of a program that runs PP, at some point saves a copy of the current state, and keeps running; the assertion is that the pair (saved state, current state) is in TT. So termination, a liveness property, is reduced to one safety check plus kk separate well-foundedness checks.
  • No lexicographic order needed. A lexicographic ranking function asks for a fixed priority among the measures. A disjunctive one needs none, so it is easier to find and to compose. The price is that the inductive check must be about R+R^+, not about RR.
  • The same argument as size-change termination. Size-change termination by Lee, Jones and Ben-Amram uses Ramsey's theorem in the same way, on the size-change graphs of the closure.
  • No decision procedure. Termination is undecidable, by the halting problem and Rice's theorem. The theorem does not change that: it says what a proof looks like, not how to find one. Tools search for TT in a restricted class, such as unions of linear ranking relations, and can fail.

Tightness

  • RR instead of R+R^+ is not enough. Take S=I={a,b}S = I = \{a, b\} and R={(a,b),(b,a)}R = \{(a, b), (b, a)\}. Then R={(a,b)}∪{(b,a)}R = \{(a, b)\} \cup \{(b, a)\} is a union of two well-founded relations, each with one pair, but a,b,a,b,…a, b, a, b, \ldots is an infinite computation. The closure R+R^+ contains (a,a)(a, a), and no well-founded relation contains a pair (a,a)(a, a), so no disjunctively well-founded TT covers R+R^+. A union of well-founded relations is not well-founded in general, and the theorem uses the closure exactly to get around this.
  • The union must be finite. Take S=I=NS = I = \mathbb{N} and R={(x,x+1)}R = \{(x, x + 1)\}. The program does not terminate. But R+={(x,y):x<y}R^+ = \{(x, y) : x < y\} is the union of the infinitely many one-pair relations {(x,y)}\{(x, y)\}, and each is well-founded. The proof needs kk finite to apply Ramsey's theorem with kk colors.
  • The restriction to reachable states is needed for "only if". Add to a terminating program a state c∉Ic \notin I with (c,c)∈R(c, c) \in R that no computation reaches. The program still terminates, but R+R^+ contains (c,c)(c, c), so without the restriction to Acc×S\mathrm{Acc} \times S no disjunctively well-founded relation would cover it.
  • The proof is not constructive. The "if" direction uses the infinite Ramsey theorem and gives no bound on the length of a run in terms of the kk ranking functions, unlike one ranking function, which bounds the run by its starting value.

History

Floyd proved termination in 1967 with a function into a well-founded set, which is one relation that covers RR. Lee, Jones and Ben-Amram used Ramsey's theorem in 2001 to prove the size-change termination principle. Podelski and Rybalchenko defined transition invariants and proved this theorem at LICS 2004, and gave the linear ranking function synthesis that it uses in the same year. Cook, Podelski and Rybalchenko built Terminator on it and reported termination proofs of Windows device drivers at PLDI 2006. Ramsey's theorem is from 1930.

References

  1. Andreas Podelski and Andrey Rybalchenko, Transition invariants, Proceedings of the 19th IEEE Symposium on Logic in Computer Science (LICS 2004), the definitions of transition invariant and disjunctive well-foundedness, and the theorem that a program terminates if and only if it has a disjunctively well-founded transition invariant, proved with Ramsey's theorem
  2. Byron Cook, Andreas Podelski and Andrey Rybalchenko, Termination proofs for systems code, Proceedings of PLDI 2006, the Terminator tool, which builds a disjunctively well-founded transition invariant one ranking function at a time and checks it as a safety property
  3. Chin Soon Lee, Neil D. Jones and Amir M. Ben-Amram, The size-change principle for program termination, Proceedings of POPL 2001, pp. 81 to 92, the earlier use of Ramsey's theorem to prove termination from the idempotent size-change graphs of the closure
  4. F. P. Ramsey, On a problem of formal logic, Proceedings of the London Mathematical Society s2-30(1), 264 to 286 (1930), the infinite form of the theorem on colorings of the r-subsets of an infinite set

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/D0628W/text.yaml