Prerequisites. Direct starred prerequisites: none. No later core chapter depends on this route.
Consider the two functions 𝑓(𝑥,𝑦):={𝑔(𝑥,𝑦−1)𝑦>0,0𝑦=0,𝑔(𝑥,𝑦):={𝑓(𝑥−1,𝑥)𝑥>0,0𝑥=0. The arguments range over ℕ, and subtraction is truncated at zero. The call from 𝑓 decreases its second argument; the call from 𝑔 decreases its first. No single argument decreases on every call. A componentwise checker therefore rejects the program even though every alternating pair of calls decreases the first argument of 𝑓. We need to compose information across calls before choosing the descending argument.
Matrices record usable decreases
Let ≺ be a well-founded relation on a value type 𝑉. Write 𝑎 ⪯𝑏 for its reflexive closure. The two relations have different roles: ≺ contributes strict descent, while ⪯ only transports a candidate thread through a call.
A size-change label is one of ?,⇓=,⇓<. The unknown label ? asserts nothing. The weak label ⇓= asserts 𝑣′ ⪯𝑣. The strict label ⇓< asserts 𝑣′ ≺𝑣. Their information order is ?<𝗂𝗇𝖿𝗈⇓=<𝗂𝗇𝖿𝗈⇓<.
Referenced from 3 locations
The decorations prevent the weak label from being confused with the object-language order ⪯. A label is information about one edge; it is not itself a comparison between values.
Suppose a caller 𝑓 has parameters 𝑥1,…,𝑥𝑚 and a callee 𝑔 has parameters 𝑦1,…,𝑦𝑛. A size-change matrix 𝑀 :𝑓 →𝑔 is an 𝑛-by-𝑚 matrix of labels. Its entry 𝑀𝑖𝑗 describes the relation of callee value 𝑦𝑖 to caller value 𝑥𝑗. The matrix is truthful for a call when every weak entry denotes a true 𝑦𝑖 ⪯𝑥𝑗 and every strict entry denotes a true 𝑦𝑖 ≺𝑥𝑗.
Referenced from 2 locations
Rows belong to the callee and columns to the caller. Reversing that convention transposes composition and can manufacture a false diagonal. For the displayed program, use parameter order (𝑥,𝑦) at both functions. The two call matrices are 𝑀𝑓𝑔=(⇓=??⇓<),𝑀𝑔𝑓=(⇓<?⇓=?). The guard 𝑦 >0 makes 𝑦 −1 <𝑦, so the lower-right entry of 𝑀𝑓𝑔 is strict. Without that guard, truncated subtraction at 𝑦 =0 would justify only a weak entry.
Define path composition 𝑎 ⊗𝑏 by 𝑎⊗𝑏:=⎧{
{⎨{
{⎩?𝑎=? or 𝑏=?,⇓<𝑎≠? and 𝑏≠? and (𝑎=⇓< or 𝑏=⇓<),⇓=𝑎=𝑏=⇓=. Define 𝑎 ⊕𝑏 as the greater label in the information order of definition 83.1. Thus competing paths retain the strongest comparison proved by either path.
Referenced from 2 locations
For 𝑀 :𝑓 →𝑔 and 𝑁 :𝑔 →ℎ, define 𝑁;𝑀 :𝑓 →ℎ by (𝑁;𝑀)𝑖𝑗:=⨁𝑘𝑁𝑖𝑘⊗𝑀𝑘𝑗. The middle index 𝑘 ranges over parameters of 𝑔.
Referenced from 3 locations
The product of two true weak comparisons is weak. A true strict comparison followed or preceded by a weak comparison is strict, by mixed transitivity of ≺ and ⪯. Therefore composition preserves truthfulness.
Let 𝑀 :𝑓 →𝑔 be truthful for a call ⃗𝑣 ↦⃗𝑤, and let 𝑁 :𝑔 →ℎ be truthful for a call ⃗𝑤 ↦⃗𝑧. Then 𝑁;𝑀 is truthful for the two-call path ⃗𝑣 ↦⃗𝑧.
Referenced from 2 locations
Proof of Lemma 83.5 — Truthful composition
Proof. Fix an entry (𝑖,𝑗). If (𝑁;𝑀)𝑖𝑗 =?, there is no claim to prove. A weak entry is obtained from some middle parameter 𝑘 with two weak entries. Their truth gives 𝑧𝑖 ⪯𝑤𝑘 ⪯𝑣𝑗, hence 𝑧𝑖 ⪯𝑣𝑗. A strict entry is obtained from a middle parameter 𝑘 for which one constituent entry is strict and the other is weak or strict. Mixed transitivity gives 𝑧𝑖 ≺𝑣𝑗. The join retains only a claim proved by at least one such 𝑘. ◻
For the two-call path 𝑓 →𝑔 →𝑓, 𝑀𝑔𝑓;𝑀𝑓𝑔=(⇓<?⇓=?). The strict first diagonal is the decrease missed by a one-call componentwise check. Squaring this self-matrix yields (⇓<?⇓<?), which is stable under another square.
★☆☆ Calculate 𝑀𝑓𝑔;𝑀𝑔𝑓 :𝑔 →𝑔. Identify every intermediate parameter that witnesses a known entry. Check its square and state which diagonal is strict.
Referenced from 3 locations
Multipaths and descending threads
A finite matrix calculation must rule out an infinite call sequence. The bridge is a thread: a sequence of parameter positions connected by known matrix entries.
A multipath is a finite or infinite composable sequence 𝑓0𝑀0←←←←←←→𝑓1𝑀1←←←←←←→𝑓2𝑀2←←←←←←→⋯. A thread chooses a parameter index 𝑖𝑘 of 𝑓𝑘 at each selected stage so that (𝑀𝑘)𝑖𝑘+1,𝑖𝑘 is known. It is infinitely descending when the selected labels are strict for infinitely many 𝑘.
Referenced from 2 locations
Truthfulness turns an infinitely descending thread into an infinite ≺-descent. Weak edges transport values between strict edges; deleting the finite weak segments gives 𝑣𝑘1≺𝑣𝑘0,𝑣𝑘2≺𝑣𝑘1,…, contradicting well-foundedness.
A finite call graph 𝐺 is size-change safe when every infinite call path permitted by its control-flow graph has a multipath containing an infinitely descending thread.
Referenced from 2 locations
Let 𝐺 be a finite first-order call graph over a well-founded value order. If every concrete call is covered by a truthful edge matrix and 𝐺 is size-change safe, then the program has no infinite call sequence.
Referenced from 6 locations
Proof of Theorem 83.8 — Size-change descent
Proof. Assume an infinite call sequence. Choose for each call a truthful covering matrix. Safety gives an infinitely descending thread through their multipath. Truthfulness and the preceding weak-segment contraction produce an infinite strict descent in the value order, contradicting well-foundedness. ◻
The proof uses every hypothesis. With a false strict label, the matrix thread need not describe the execution. With a non-well-founded order, a truthful infinite descent is possible. Without safety, the infinite path may contain no descending thread.
Finite closure detects every bad cycle
Safety quantifies over infinite paths. A checker needs an equivalent finite condition. There are finitely many function names, arities, and matrices, so composition reaches a fixed point after finitely many insertions.
The composition closure C(𝐺) contains every edge matrix of a finite call graph 𝐺 and every well-typed finite composition of its members. A square matrix 𝑀 :𝑓 →𝑓 is idempotent when 𝑀;𝑀 =𝑀. The idempotent-cycle test accepts 𝐺 when every idempotent 𝑀 :𝑓 →𝑓 in C(𝐺) has 𝑀𝑖𝑖=⇓< for some parameter 𝑖 of 𝑓.
Referenced from 4 locations
★★☆ Take the nonterminating call ℎ(𝑥) =ℎ(𝑥) on naturals. Label its self-edge strict and show that the idempotent-cycle test of definition 83.9 accepts it. Identify the exact hypothesis of theorem 83.8 that fails, then replace the label by the strongest truthful one.
Referenced from 3 locations
Closure is finite. A matrix between fixed arities has three choices per entry, and the graph has finitely many function pairs. Repeatedly inserting all composable products must therefore stop. Termination of this saturation algorithm is separate from termination of the analyzed program.
Let 𝑀 :𝑓 →𝑓 be idempotent and suppose 𝑀𝑖𝑖 = ⇓<. Then the infinite repetition 𝑀,𝑀,𝑀,… contains an infinitely descending thread at parameter 𝑖.
Referenced from 3 locations
Proof of Lemma 83.10 — A strict diagonal repeats
Proof. Choose index 𝑖 at every stage. Each selected entry is the strict diagonal 𝑀𝑖𝑖. Hence every edge of the thread is strict. ◻
Let 𝐺 be a finite first-order call graph. Every infinite multipath in 𝐺 has an infinitely descending thread if and only if every idempotent self-matrix in C(𝐺) has a strict diagonal.
Referenced from 5 locations
Proof of Theorem 83.11 — Finite idempotent criterion
Proof. The theorem is the graph criterion of Lee, Jones, and Ben-Amram at their finite size-change-graph signature [LJBA01].
For the reverse implication, suppose an infinite multipath has no infinitely descending thread. Some function 𝑓 occurs infinitely often. For two occurrences of 𝑓, color the pair by the composite matrix along the segment between them. There are finitely many colors. Infinite Ramsey’s theorem for pairs gives an infinite subsequence on which every segment has the same composite 𝑀 :𝑓 →𝑓. Three occurrences give 𝑀;𝑀 =𝑀. If 𝑀 had a strict diagonal, lemma 83.10 would give an infinitely descending thread through those segments. Hence 𝑀 is a bad idempotent in the closure.
For the forward implication, let 𝑀 :𝑓 →𝑓 be an idempotent without a strict diagonal. Repeat a path whose composite is 𝑀. The source graph lemma says that a thread through a finite segment exists exactly when the corresponding composite entry is known, and it is strict exactly when that entry is strict. Suppose a thread through the repeated path had infinitely many strict edges. Record its parameter index at every segment boundary. Some index 𝑖 occurs at two boundaries with a strict edge between them, by the pigeonhole principle. The corresponding entry of 𝑀𝑘 is strict for some 𝑘 >0; idempotence gives 𝑀𝑘 =𝑀, so 𝑀𝑖𝑖 is strict, a contradiction. The repeated multipath therefore has no infinitely descending thread. This is the contrapositive of the required direction. The graph lemma is proved by induction on segment length from definition 83.4; the two-step case is exactly the choice of the middle index 𝑘. ◻
Combining theorem 83.8, theorem 83.11 gives a sound termination certificate.
Let 𝐺 be finite, let its labels be truthful for all concrete calls, and let the value order be well founded. If the idempotent-cycle test accepts 𝐺, then the represented program has no infinite call sequence.
Referenced from 2 locations
Proof of Corollary 83.12 — Sound finite checker
Proof. By theorem 83.11, acceptance makes 𝐺 size-change safe. Apply theorem 83.8. ◻
The criterion is complete for safety of the finite graph abstraction. It is not complete for termination of programs: graph extraction may omit semantic facts, and a terminating program may have no safe abstraction in the selected three-label language.
★★☆ Let 𝑝(𝑚,𝑛,𝑟)=⎧{
{⎨{
{⎩𝑝(𝑚,𝑟−1,𝑛)𝑟>0,𝑝(𝑟,𝑛−1,𝑚)𝑟=0 and 𝑛>0,𝑚𝑟=𝑛=0. Build one matrix for each recursive branch. Compute enough closure matrices to exhibit the idempotent self-cycles and locate a strict diagonal in each.
Referenced from 3 locations
★★☆ Give three separate counterexamples to the soundness conclusion, dropping in turn truthfulness, well-foundedness of the value order, and the strict-diagonal condition. Keep the other two hypotheses valid in each example.
Referenced from 3 locations
Bibliographic note
The size-change graphs, multipaths, descent theorem, composition, and finite idempotent criterion are reconstructed from Lee, Jones, and Ben-Amram [LJBA01]. Their criterion concerns a finite first-order abstraction with truthful edges. It is not by itself a verified termination checker for a dependent language.
Suggested first pass.
None of these problems is a prerequisite for a later chapter. Begin with exercise 83.5, exercise 83.8.
★★★ For the mutually recursive 𝑓/𝑔 program at the chapter opening, build the two matrices, close them under path composition, and list every idempotent self-matrix. Prove that each has a strict diagonal. Then erase both positivity guards from the abstraction, replace the lower-right strict entry of 𝑀𝑓𝑔 and the upper-left strict entry of 𝑀𝑔𝑓 by weak entries, and calculate the first idempotent matrix with no strict diagonal.
Referenced from 4 locations
★★★ Reconstruct the reverse implication of theorem 83.11. State the finite coloring, use three members of the homogeneous set to derive idempotence, and show how a strict diagonal would produce the forbidden thread. Label the exact use of graph finiteness.
Referenced from 3 locations
★★★ Practical project.size-change-checker Implement in Kappa the three labels, matrix composition, finite closure, and the idempotent-cycle test of definition 83.9. Maintain the invariant that every stored edge has compatible source and target arities and that Closed is returned only at a genuine fixed point. For the chapter’s 𝑓/𝑔 graph, print the saturated self-cycle and accept it with a strict first diagonal. Replace that diagonal by a weak comparison; the mutated idempotent self-cycle must be rejected with the exact witness no-strict-diagonal. The acceptance test passes exactly when the first graph is accepted, the mutation is rejected with that witness, and audit returns [].
Referenced from 5 locations