The recursive call in 𝗀𝖼𝖽(𝑎,𝑏)={𝑎𝑏=0,𝗀𝖼𝖽(𝑏,𝑎𝗋𝖾𝗆𝑏)𝑏>0 does not receive a constructor field of either argument. It nevertheless decreases: the remainder is strictly smaller than the positive divisor. Structural recursion from chapter 28 sees syntax; this argument uses a relation. The missing object is a finite certificate that all smaller calls can themselves be evaluated.
Consider a constructor branch of the inductive schema of chapter 28 whose scrutinee has the form 𝖼𝑖(⃗𝑢,𝑓1,…,𝑓𝑟𝑖). A structural recursor may call itself only at 𝑓𝑗(⃗𝑧),1≤𝑗≤𝑟𝑖,⃗𝑧:Θ𝑖𝑗.(𝑆𝑡𝑟𝑢𝑐𝑡𝑢𝑟𝑎𝑙−𝑐𝑎𝑙𝑙) Thus every recursive argument is obtained by applying one recursive constructor field to arguments from its arity telescope. For recursion on the second input of 𝗀𝖼𝖽, the positive branch has input 𝑏≡𝗌𝗎𝖼(𝑏0), but its recursive input 𝑎𝗋𝖾𝗆𝑏 is neither the field 𝑏0 nor an application of a recursive constructor field. Recursing on the first input fails the same test because the recursive input is 𝑏, which need not be a constructor field of 𝑎. Hence neither choice makes the Euclidean call an instance of (Structural-call).
Let 𝐴:U𝑖 and let 𝑅:𝐴→𝐴→U𝑗 be a proof-relevant binary relation. We write 𝑏𝑅𝑎 when a recursive call at 𝑎 may call the function at 𝑏. The order of the arguments is part of this convention. The optional signature 𝑇𝗋𝖾𝖼 is 𝑇0 extended by the indexed accessibility schema and the labeled constructor, eliminator, and computation rules displayed in this section; accessibility is not a new judgmental principle of 𝑇0.
An element 𝑎:𝐴 is accessible for 𝑅 when every 𝑅-predecessor of 𝑎 is accessible. The indexed family 𝖠𝖼𝖼𝑅:𝐴→U𝑖⊔𝑗 is governed first by formation and introduction:
Γ⊢𝐴:U𝑖Γ⊢𝑅:𝐴→𝐴→U𝑗Γ⊢𝑎:𝐴
Γ⊢𝖠𝖼𝖼𝑅(𝑎):U𝑖⊔𝑗
Acc-form
Γ⊢𝑎:𝐴Γ⊢ℎ:∏𝑏:𝐴𝑏𝑅𝑎→𝖠𝖼𝖼𝑅(𝑏)
Γ⊢𝖺𝖼𝖼𝑎(ℎ):𝖠𝖼𝖼𝑅(𝑎)
Acc-intro
Thus its constructor has the type 𝖺𝖼𝖼𝑎:(∏𝑏:𝐴𝑏𝑅𝑎→𝖠𝖼𝖼𝑅(𝑏))→𝖠𝖼𝖼𝑅(𝑎). The relation 𝑅 is well founded when 𝖶𝖾𝗅𝗅𝖥𝗈𝗎𝗇𝖽𝖾𝖽(𝑅):=∏𝑎:𝐴𝖠𝖼𝖼𝑅(𝑎) is inhabited. This definition asserts accessibility of every element; it does not assert that a program can decide 𝑏𝑅𝑎.
The constructor stores precisely the recursive calls permitted below 𝑎. For 𝑝≡𝖺𝖼𝖼𝑎(ℎ) and 𝑟:𝑏𝑅𝑎, the proof ℎ𝑏𝑟 is the smaller certificate used by the recursive call.
If 𝑎0𝑅𝑎1𝑅⋯𝑅𝑎𝑛=𝑎0, then no term of 𝖠𝖼𝖼𝑅(𝑎0) exists in a normalizing theory. Repeatedly inspecting the outer 𝖺𝖼𝖼 constructor follows the cycle and produces an infinite sequence of proper subterms. Thus well-foundedness excludes every finite cycle. The converse fails for arbitrary relations: an acyclic relation may still contain an infinite descending chain. For example, on ℕ put 𝑏𝑅𝑎:=𝖨𝖽ℕ(𝑏,𝗌𝗎𝖼(𝑎)). This relation has no cycle, while 1𝑅0, 2𝑅1, 3𝑅2, and so on give the infinite sequence of successive predecessors 0,1,2,3,….
Let 𝑃:∏𝑎:𝐴𝖠𝖼𝖼𝑅(𝑎)→U𝑘. Put 𝐻(𝑎):=∏𝑏:𝐴𝑏𝑅𝑎→𝖠𝖼𝖼𝑅(𝑏),𝐾(𝑎,ℎ):=∏𝑏:𝐴∏𝑟:𝑏𝑅𝑎𝑃(𝑏,ℎ𝑏𝑟),𝖲𝗍𝖾𝗉𝑃:=∏𝑎:𝐴∏ℎ:𝐻(𝑎)𝐾(𝑎,ℎ)→𝑃(𝑎,𝖺𝖼𝖼𝑎(ℎ)). The proof-dependent accessibility eliminator has the compact rule
Γ⊢𝑃:∏𝑎:𝐴𝖠𝖼𝖼𝑅(𝑎)→U𝑘Γ⊢𝑎:𝐴Γ⊢𝑠:𝖲𝗍𝖾𝗉𝑃Γ⊢𝑝:𝖠𝖼𝖼𝑅(𝑎)
Γ⊢𝖺𝖼𝖼𝗂𝗇𝖽𝑃(𝑠,𝑎,𝑝):𝑃(𝑎,𝑝)
Acc-elim
and its computation rule is 𝖺𝖼𝖼𝖲𝗍𝖾𝗉𝑃(𝑠,𝑎,ℎ):=𝑠(𝑎,ℎ,𝜆𝑏.𝜆𝑟.𝖺𝖼𝖼𝗂𝗇𝖽𝑃(𝑠,𝑏,ℎ𝑏𝑟)).
Γ⊢𝑃:∏𝑎:𝐴𝖠𝖼𝖼𝑅(𝑎)→U𝑘Γ⊢𝑎:𝐴Γ⊢𝑠:𝖲𝗍𝖾𝗉𝑃Γ⊢ℎ:𝐻(𝑎)
𝖺𝖼𝖼𝗂𝗇𝖽𝑃(𝑠,𝑎,𝖺𝖼𝖼𝑎(ℎ))≡𝖺𝖼𝖼𝖲𝗍𝖾𝗉𝑃(𝑠,𝑎,ℎ):𝑃(𝑎,𝖺𝖼𝖼𝑎(ℎ))
Acc-β
Equivalently, 𝖺𝖼𝖼𝗂𝗇𝖽𝑃(𝑠,𝑎,𝖺𝖼𝖼𝑎(ℎ))≡𝑠(𝑎,ℎ,𝜆𝑏.𝜆𝑟.𝖺𝖼𝖼𝗂𝗇𝖽𝑃(𝑠,𝑏,ℎ𝑏𝑟)).(𝐴𝑐𝑐−𝛽) The argument ℎ exposes the immediate accessibility subproofs. The final argument gives the induction result at each such subproof. Taking 𝑃(𝑎,𝑝):=𝑄(𝑎) derives the non-proof-dependent eliminator used for ordinary well-founded recursion.
Let 𝑃:𝐴→U𝑘. Suppose 𝑠:∏𝑎:𝐴(∏𝑏:𝐴𝑏𝑅𝑎→𝑃(𝑏))→𝑃(𝑎). Define 𝑃′(𝑎,𝑝):=𝑃(𝑎) and 𝑠′(𝑎,ℎ,𝑘):=𝑠(𝑎,𝑘). Then 𝖺𝖼𝖼𝗂𝗇𝖽𝑃′(𝑠′):∏𝑎:𝐴𝖠𝖼𝖼𝑅(𝑎)→𝑃(𝑎). If 𝑤:𝖶𝖾𝗅𝗅𝖥𝗈𝗎𝗇𝖽𝖾𝖽(𝑅), then 𝜆𝑎.𝖺𝖼𝖼𝗂𝗇𝖽𝑃′(𝑠′,𝑎,𝑤𝑎):∏𝑎:𝐴𝑃(𝑎).
Proof. Fix 𝑎:𝐴 and 𝑝:𝖠𝖼𝖼𝑅(𝑎). Apply Acc-elim to 𝑝. For the constant-in-the-certificate motive 𝑃′, the displayed definition of 𝑠′ has type 𝖲𝗍𝖾𝗉𝑃′: its recursive-results argument 𝑘 has type ∏𝑏:𝐴𝑏𝑅𝑎→𝑃(𝑏), exactly the second argument required by 𝑠(𝑎). The eliminator has one constructor case. Write 𝑝≡𝖺𝖼𝖼𝑎(ℎ), where ℎ:∏𝑏:𝐴𝑏𝑅𝑎→𝖠𝖼𝖼𝑅(𝑏). For each 𝑏:𝐴 and 𝑟:𝑏𝑅𝑎, the induction hypothesis gives 𝖺𝖼𝖼𝗂𝗇𝖽𝑃′(𝑠′,𝑏,ℎ𝑏𝑟):𝑃(𝑏). Abstracting 𝑏 and 𝑟 produces the recursive-results argument required by 𝑠; applying 𝑠 gives 𝑃(𝑎). This is exactly the specialization of (Acc-β). If 𝑤 proves well-foundedness, instantiate the first conclusion with 𝑝:=𝑤𝑎 at every 𝑎. ◻
★☆☆ Assume 𝑞:𝑎𝑅𝑎. Induct directly on the accessibility certificate to construct 𝖠𝖼𝖼𝑅(𝑎)→𝟎. Write the structurally smaller certificate used by the recursive call explicitly. Explain why the nondependent eliminator of definition 82.4 with constant motive 𝟎 would not by itself establish this fixed-point argument.
Accessibility induction becomes recursion when the motive describes the result type. Keeping the accessibility certificate visible prevents a hidden proof-irrelevance assumption.
For 𝑃:𝐴→U𝑘 and 𝑠:∏𝑎:𝐴(∏𝑏:𝐴𝑏𝑅𝑎→𝑃(𝑏))→𝑃(𝑎), define the well-founded recursor𝗐𝖿𝗋𝖾𝖼𝑅,𝑃(𝑠,𝑎,𝑝):=𝖺𝖼𝖼𝗂𝗇𝖽𝜆𝑎.𝜆𝑝.𝑃(𝑎)(𝜆𝑎.𝜆ℎ.𝜆𝑘.𝑠(𝑎,𝑘),𝑎,𝑝). Its result and recursive-call types are therefore 𝗐𝖿𝗋𝖾𝖼𝑅,𝑃(𝑠,𝑎,𝑝):𝑃(𝑎),𝑘:∏𝑏:𝐴𝑏𝑅𝑎→𝑃(𝑏). For a constructor certificate it has the judgmental equation 𝗐𝖿𝗋𝖾𝖼𝑅,𝑃(𝑠,𝑎,𝖺𝖼𝖼𝑎(ℎ))≡𝑠(𝑎,𝜆𝑏.𝜆𝑟.𝗐𝖿𝗋𝖾𝖼𝑅,𝑃(𝑠,𝑏,ℎ𝑏𝑟)).(𝑊𝐹−𝛽) Given 𝑤:𝖶𝖾𝗅𝗅𝖥𝗈𝗎𝗇𝖽𝖾𝖽(𝑅), its total specialization is 𝗐𝖿𝗋𝖾𝖼𝑤𝑅,𝑃(𝑠,𝑎):=𝗐𝖿𝗋𝖾𝖼𝑅,𝑃(𝑠,𝑎,𝑤𝑎).
Equation (WF-β) computes on the accessibility constructor. An equation obtained by replacing 𝖺𝖼𝖼𝑎(ℎ) with an arbitrary 𝑤𝑎 is not judgmental unless 𝑤𝑎 unfolds to that constructor. This distinction matters in intensional type theory: different accessibility certificates need not be judgmentally equal.
Here is one complete instance. Let 𝑅∅ be the empty relation on 𝟏, let ℎ⋆:∏𝑏:𝟏𝑏𝑅∅⋆→𝖠𝖼𝖼𝑅∅(𝑏) eliminate its empty relation proof, and put 𝑠0(𝑥,𝑘):=𝟢 for 𝑥:𝟏. Abbreviate 𝑊(𝑥,𝑝):=𝗐𝖿𝗋𝖾𝖼𝑅∅,𝜆𝑥.ℕ(𝑠0,𝑥,𝑝). Then 𝑊(⋆,𝖺𝖼𝖼⋆(ℎ⋆))(𝑊𝐹−𝛽)≡𝑠0(⋆,𝜆𝑏.𝜆𝑟.𝑊(𝑏,ℎ⋆𝑏𝑟))𝑑𝑒𝑓𝑖𝑛𝑖𝑡𝑖𝑜𝑛𝑜𝑓𝑠0≡𝟢. By contrast, for a variable 𝑧:𝖠𝖼𝖼𝑅∅(⋆), the term 𝑊(⋆,𝑧) is neutral: its certificate has no outer 𝖺𝖼𝖼 constructor, so (WF-β) has no matching redex.
Assume that 𝑠 is pointwise extensional: for every 𝑎:𝐴 and recursive-result functions 𝑘,𝑘′, (∏𝑏:𝐴∏𝑟:𝑏𝑅𝑎𝖨𝖽𝑃(𝑏)(𝑘𝑏𝑟,𝑘′𝑏𝑟))→𝖨𝖽𝑃(𝑎)(𝑠(𝑎,𝑘),𝑠(𝑎,𝑘′)). Then for 𝑝,𝑞:𝖠𝖼𝖼𝑅(𝑎) there is an identification 𝖨𝖽𝑃(𝑎)(𝗐𝖿𝗋𝖾𝖼𝑅,𝑃(𝑠,𝑎,𝑝),𝗐𝖿𝗋𝖾𝖼𝑅,𝑃(𝑠,𝑎,𝑞)).
Proof of Proposition 82.7 — Extensional independence of certificates
Proof. Use accessibility induction on 𝑝 with the strengthened motive 𝑀(𝑎,𝑝):=∏𝑞:𝖠𝖼𝖼𝑅(𝑎)𝖨𝖽𝑃(𝑎)(𝗐𝖿𝗋𝖾𝖼𝑅,𝑃(𝑠,𝑎,𝑝),𝗐𝖿𝗋𝖾𝖼𝑅,𝑃(𝑠,𝑎,𝑞)). In the sole constructor case, let 𝑝≡𝖺𝖼𝖼𝑎(ℎ) and fix 𝑞:𝖠𝖼𝖼𝑅(𝑎). The second elimination uses the motive 𝑊𝑥(𝑞):=𝗐𝖿𝗋𝖾𝖼𝑅,𝑃(𝑠,𝑥,𝑞),𝐼(𝑥,ℎ0):=∏𝑏:𝐴∏𝑟:𝑏𝑅𝑥𝑀(𝑏,ℎ0𝑏𝑟),𝑁(𝑥,𝑞):=∏ℎ0:𝐻(𝑥)𝐼(𝑥,ℎ0)→𝖨𝖽𝑃(𝑥)(𝑊𝑥(𝖺𝖼𝖼𝑥(ℎ0)),𝑊𝑥(𝑞)). This motive re-abstracts both ℎ and the outer induction hypothesis, so Acc-elim applies to 𝑞 without assuming a judgmental inversion at the fixed index. Its constructor case has 𝑞≡𝖺𝖼𝖼𝑎(ℎ′). Instantiate the branch at ℎ and at the outer induction hypothesis. For 𝑏:𝐴 and 𝑟:𝑏𝑅𝑎, that hypothesis has type 𝑀(𝑏,ℎ𝑏𝑟). Instantiating its quantified certificate with ℎ′𝑏𝑟 gives 𝗐𝖿𝗋𝖾𝖼𝑅,𝑃(𝑠,𝑏,ℎ𝑏𝑟)=𝑃(𝑏)𝗐𝖿𝗋𝖾𝖼𝑅,𝑃(𝑠,𝑏,ℎ′𝑏𝑟). Abstracting 𝑏 and 𝑟 gives the premise of pointwise extensionality of 𝑠. Its conclusion identifies the two applications of 𝑠; conversion by the two instances of (WF-β) closes 𝑁(𝑎,𝖺𝖼𝖼𝑎(ℎ′)) at ℎ and the outer hypothesis. The recursive hypotheses generated by this inner Acc-elim are not needed. Hence the outer goal 𝑀(𝑎,𝖺𝖼𝖼𝑎(ℎ)) follows. No proof-irrelevance or judgmental equality of 𝑝 and 𝑞 is used. ◻
Function extensionality implies the pointwise-extensionality hypothesis for every step 𝑠: pointwise equal recursive-result functions are then equal, and congruence for 𝑘↦𝑠(𝑎,𝑘) gives the required identification. In pure intensional type theory, function extensionality is unavailable and the hypothesis cannot in general be deleted; proposition 82.7 therefore states the exact local extensionality used by its proof.
The recursor consumes 𝑝:𝖠𝖼𝖼𝑅(𝑎). It does not search source code for a decreasing argument. A termination checker is an algorithm that constructs such evidence for a selected source language. Soundness of that algorithm is a separate theorem; neither a timeout nor rejection refutes mathematical well-foundedness.
The usual order on natural numbers is written 𝑚<𝑛. Its proof-relevant presentation has constructors witnessing that zero is below every successor and that successor preserves order.
Γ⊢𝑛:ℕ
Γ⊢𝗅𝗍𝖹𝖾𝗋𝗈(𝑛):𝟢<𝗌𝗎𝖼(𝑛)
Lt-zero
Γ⊢𝑝:𝑚<𝑛
Γ⊢𝗅𝗍𝖲𝗎𝖼(𝑝):𝗌𝗎𝖼(𝑚)<𝗌𝗎𝖼(𝑛)
Lt-suc
These constructor names are used when the proofs below invert a strict inequality.
For 𝑚,𝑛:ℕ, write 𝑚≤𝑛:=𝖨𝖽ℕ(𝑚,𝑛)+(𝑚<𝑛). Thus a weak inequality records either equality or a strict inequality; the symbol ≤ in this chapter always denotes this sum type.
Proof of Lemma 82.11 — Natural-order inversion and mixed transitivity
Proof. For (1), eliminate the sum defining 𝑚≤𝟢. Its identity branch is the required term, while its strict branch has type 𝑚<𝟢 and is empty by inversion on Lt-zero and Lt-suc. For (2), induct on 𝑛. If 𝑛≡𝟢, inversion of ℓ<𝗌𝗎𝖼(𝟢) gives ℓ≡𝟢, hence the identity injection into ℓ≤𝟢. If 𝑛≡𝗌𝗎𝖼(𝑛′), inversion gives either ℓ≡𝟢, when 𝟢<𝗌𝗎𝖼(𝑛′), or ℓ≡𝗌𝗎𝖼(ℓ′) with ℓ′<𝗌𝗎𝖼(𝑛′). In the latter case, apply the induction hypothesis and map its identity and strict branches through 𝗌𝗎𝖼. These are precisely the two injections into ℓ≤𝗌𝗎𝖼(𝑛′). For (3), eliminate 𝑚≤𝑛. Transport along its identity branch turns ℓ<𝑚 into ℓ<𝑛. In the strict branch, strict transitivity follows by induction on the second <-derivation, applying Lt-suc in its successor case. ◻
Proof of Lemma 82.12 — Natural-number accessibility
Proof. Prove by induction on 𝑛 the strengthened statement 𝑄(𝑛):=∏𝑚:ℕ𝑚≤𝑛→𝖠𝖼𝖼<(𝑚). For 𝑛≡𝟢, fix an input 𝑚≤𝟢. By lemma 82.11(1), obtain 𝑒:𝖨𝖽ℕ(𝑚,𝟢). Construct 𝑝0:=𝖺𝖼𝖼𝟢(ℎ0), where ℎ0 eliminates its impossible premise ℓ<𝟢. Then 𝗍𝗋𝑥.𝖠𝖼𝖼<(𝑥)𝑒−1(𝑝0):𝖠𝖼𝖼<(𝑚).
For 𝑛≡𝗌𝗎𝖼(𝑛′), fix 𝑚≤𝗌𝗎𝖼(𝑛′). Construct 𝖺𝖼𝖼𝑚(ℎ). Given ℓ<𝑚, transitivity gives ℓ<𝗌𝗎𝖼(𝑛′) by lemma 82.11(3), and then lemma 82.11(2) gives ℓ≤𝑛′. The induction hypothesis at ℓ≤𝑛′ gives 𝖠𝖼𝖼<(ℓ), which defines ℎ. Taking 𝑚:=𝑛 and the left injection of reflexivity into 𝑛≤𝑛 concludes the lemma. ◻
For every 𝜇:𝐴→ℕ, the relation <𝜇 is well founded. Consequently a step of type ∏𝑎:𝐴(∏𝑏:𝐴𝜇(𝑏)<𝜇(𝑎)→𝑃(𝑏))→𝑃(𝑎) defines a proof-indexed total result at every 𝑎:𝐴.
Proof. For 𝑛:ℕ and 𝑝:𝖠𝖼𝖼<(𝑛), use accessibility induction with the strengthened motive 𝑀(𝑛,𝑝):=∏𝑎:𝐴𝖨𝖽ℕ(𝜇(𝑎),𝑛)→𝖠𝖼𝖼<𝜇(𝑎). In the constructor case 𝑝≡𝖺𝖼𝖼𝑛(ℎ), fix 𝑎:𝐴 and 𝑒:𝖨𝖽ℕ(𝜇(𝑎),𝑛). For 𝑏:𝐴 and 𝑟:𝜇(𝑏)<𝜇(𝑎), put 𝑟𝑒:=𝗍𝗋𝑣.𝜇(𝑏)<𝑣𝑒(𝑟):𝜇(𝑏)<𝑛,𝑝𝑏,𝑟:=ℎ𝜇(𝑏)𝑟𝑒. The induction hypothesis belonging to 𝑝𝑏,𝑟 proves 𝑀(𝜇(𝑏),𝑝𝑏,𝑟). Its instance at 𝑏 and reflexivity has type 𝖠𝖼𝖼<𝜇(𝑏); call that term 𝐼𝑏,𝑟. Hence 𝖺𝖼𝖼𝑎(𝜆𝑏.𝜆𝑟.𝐼𝑏,𝑟):𝖠𝖼𝖼<𝜇(𝑎). Finally apply this construction to 𝑛:=𝜇(𝑎), the accessibility proof of lemma 82.12, and reflexivity. Accessibility induction then gives the stated recursor. ◻
For relations 𝑅:𝐴→𝐴→U𝑖 and 𝑆:𝐵→𝐵→U𝑗, their lexicographic relation on 𝐴×𝐵 is the proof-relevant relation ((𝑎′,𝑏′)𝖫𝖾𝗑(𝑅,𝑆)(𝑎,𝑏)):=(𝑎′𝑅𝑎)+(𝖨𝖽𝐴(𝑎,𝑎′)×(𝑏′𝑆𝑏)). The left injection decreases the first coordinate and leaves the second coordinate unrestricted. The right injection keeps the first coordinate identified with 𝑎 and decreases the second.
Proof of Theorem 82.16 — Lexicographic well-foundedness
Proof. Let 𝑤𝑅:𝖶𝖾𝗅𝗅𝖥𝗈𝗎𝗇𝖽𝖾𝖽(𝑅) and 𝑤𝑆:𝖶𝖾𝗅𝗅𝖥𝗈𝗎𝗇𝖽𝖾𝖽(𝑆). Apply accessibility induction to 𝑤𝑅𝑎 with the outer motive 𝐿(𝑎,𝑝):=∏𝑏:𝐵𝖠𝖼𝖼𝖫𝖾𝗑(𝑅,𝑆)(𝑎,𝑏). In its constructor case 𝑝≡𝖺𝖼𝖼𝑎(ℎ𝑅), the outer induction hypothesis is 𝐼𝑅:∏𝑎′:𝐴𝑎′𝑅𝑎→∏𝑏′:𝐵𝖠𝖼𝖼𝖫𝖾𝗑(𝑅,𝑆)(𝑎′,𝑏′). Fix 𝑏:𝐵 and apply accessibility induction to 𝑤𝑆𝑏 with the inner motive 𝐽(𝑏,𝑞):=𝖠𝖼𝖼𝖫𝖾𝗑(𝑅,𝑆)(𝑎,𝑏). In the case 𝑞≡𝖺𝖼𝖼𝑏(ℎ𝑆), the inner induction hypothesis is 𝐼𝑆:∏𝑏′:𝐵𝑏′𝑆𝑏→𝖠𝖼𝖼𝖫𝖾𝗑(𝑅,𝑆)(𝑎,𝑏′). Construct 𝖺𝖼𝖼(𝑎,𝑏)(𝑘). For a predecessor (𝑎′,𝑏′), eliminate its witness in the sum of definition 82.15. A left witness 𝑟:𝑎′𝑅𝑎 is sent to 𝐼𝑅𝑎′𝑟𝑏′. A right witness (𝑒,𝑠):𝖨𝖽𝐴(𝑎,𝑎′)×(𝑏′𝑆𝑏) is sent to 𝗍𝗋𝑥.𝖠𝖼𝖼𝖫𝖾𝗑(𝑅,𝑆)(𝑥,𝑏′)𝑒(𝐼𝑆𝑏′𝑠):𝖠𝖼𝖼𝖫𝖾𝗑(𝑅,𝑆)(𝑎′,𝑏′). These clauses define 𝑘. The inner and outer inductions therefore prove accessibility of every pair. ◻
★★☆ Let 𝑅 and 𝑆 be relations on 𝐴 and 𝐵 with measures 𝜇:𝐴→ℕ and 𝜈:𝐵→ℕ. Prove that the relation which decreases both coordinates strictly is well founded using the measure (𝑎,𝑏)↦𝜇(𝑎)+𝜈(𝑏). Explain why this relation is smaller than the lexicographic relation of theorem 82.16.
Proof of Lemma 82.17 — Natural arithmetic interface
Proof. For decidability, recurse simultaneously on 𝑎 and 𝑏. At (𝟢,𝟢) choose 𝑏≤𝑎; at (𝟢,𝗌𝗎𝖼(𝑏′)) choose 𝑎<𝑏; and at (𝗌𝗎𝖼(𝑎′),𝟢) choose 𝑏≤𝑎. At (𝗌𝗎𝖼(𝑎′),𝗌𝗎𝖼(𝑏′)), recurse on (𝑎′,𝑏′) and apply the successor constructor to the selected order proof. These four clauses return a tagged decision in every case.
For the monus identity, induct on the proof of 𝑏≤𝑎, exposing 𝑎 and 𝑏 together. The zero case reduces to 𝑎=𝟢+𝑎. The successor case reduces 𝗌𝗎𝖼(𝑎′)=𝗌𝗎𝖼(𝑏′)+(𝗌𝗎𝖼(𝑎′)˙−𝗌𝗎𝖼(𝑏′)) to the induction hypothesis 𝑎′=𝑏′+(𝑎′˙−𝑏′). If 𝑏>0, write 𝑏=𝗌𝗎𝖼(𝑏′). The identity has the form 𝑎=𝗌𝗎𝖼(𝑏′)+𝑟 with 𝑟=𝑎˙−𝑏; induction on 𝑏′ constructs 𝑟<𝗌𝗎𝖼(𝑏′)+𝑟=𝑎. This proves the strict decrease without appealing to the earlier monus exercise.
For divisibility, first establish by natural-number induction the equations 𝑥+𝑦=𝑦+𝑥,𝑥𝑦=𝑦𝑥,𝑥(𝑦𝑧)=(𝑥𝑦)𝑧,𝑞(𝑘𝑐)=(𝑞𝑘)𝑐,(𝑥𝑐)+(𝑦𝑐)=(𝑥+𝑦)𝑐,(𝑥+𝑦)˙−𝑥=𝑦,(𝑥𝑐)˙−(𝑦𝑐)=(𝑥˙−𝑦)𝑐. The addition and multiplication laws use the zero and successor equations in the corresponding induction. For the fourth law, induct on 𝑥; the successor case first rewrites 𝗌𝗎𝖼(𝑥)+𝑦=𝗌𝗎𝖼(𝑥+𝑦) and then applies the successor–successor monus clause. For the last equation, use multiplication commutativity, proved by the same successor induction, to put 𝑐 first and induct on the pair (𝑥,𝑦). The successor–successor case cancels one common summand 𝑐 using (𝑢+𝑐)˙−(𝑣+𝑐)=𝑢˙−𝑣, whose proof is induction on 𝑐; the two zero cases are the defining monus equations. Thus these calculations cover all constructor pairs.
If 𝑏=𝑘𝑐 and 𝑟=𝑙𝑐, associativity and the first two equations give 𝑞𝑏+𝑟=𝑞(𝑘𝑐)+𝑙𝑐=(𝑞𝑘+𝑙)𝑐, so 𝑞𝑘+𝑙 is a divisibility witness. Conversely, suppose 𝑎=𝑘𝑐, 𝑏=𝑙𝑐, and 𝑎=𝑞𝑏+𝑟. Substitution into the fourth displayed law gives 𝑎˙−𝑞𝑏=𝑟. Therefore 𝑟=(𝑘𝑐)˙−((𝑞𝑙)𝑐)=(𝑘˙−𝑞𝑙)𝑐, so 𝑘˙−𝑞𝑙 is the required witness. ◻
There are functions 𝖽𝗂𝗏,𝗋𝖾𝗆:ℕ→ℕ→ℕ such that, for every 𝑎,𝑏:ℕ and 𝑢:𝑏>0, 𝑎=𝖽𝗂𝗏(𝑎,𝑏)𝑏+𝗋𝖾𝗆(𝑎,𝑏),𝗋𝖾𝗆(𝑎,𝑏)<𝑏,(𝐷𝑖𝑣) and both functions are computed, for fixed positive 𝑏, by well-founded recursion on 𝑎. Equivalently, the construction gives the two leading components of 𝖣𝗂𝗏𝖲𝗉𝖾𝖼(𝑑,𝑟):=∏𝑎,𝑏:ℕ𝑏>0→(𝖨𝖽ℕ(𝑎,𝑑(𝑎,𝑏)𝑏+𝑟(𝑎,𝑏))×(𝑟(𝑎,𝑏)<𝑏)). The resulting package inhabits ∑𝑑:ℕ→ℕ→ℕ∑𝑟:ℕ→ℕ→ℕ𝖣𝗂𝗏𝖲𝗉𝖾𝖼(𝑑,𝑟).
Proof. For 𝑏≡𝟢, define 𝖽𝗂𝗏(𝑎,𝑏):=𝟢 and 𝗋𝖾𝗆(𝑎,𝑏):=𝑎; the specification has no inhabitant 𝑢:𝑏>0 to check. For 𝑏≡𝗌𝗎𝖼(𝑏0), use its constructor proof of 𝑏>0 and recurse on the measure 𝑎. If 𝑎<𝑏, return 𝑞:=0 and 𝑟:=𝑎. Otherwise 𝑏≤𝑎; by lemma 82.17, 𝑎=𝑏+(𝑎˙−𝑏), and positivity of 𝑏 gives 𝑎˙−𝑏<𝑎. The recursive result at 𝑎˙−𝑏 has the form 𝑎˙−𝑏=𝑞′𝑏+𝑟,𝑟<𝑏. Return 𝑞:=𝗌𝗎𝖼(𝑞′) and the same 𝑟. Then 𝑎𝑙𝑒𝑚𝑚𝑎82.17=𝑏+(𝑎˙−𝑏)𝑟𝑒𝑐𝑢𝑟𝑠𝑖𝑣𝑒𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛=𝑏+(𝑞′𝑏+𝑟)𝑠𝑢𝑐𝑐𝑒𝑠𝑠𝑜𝑟𝑚𝑢𝑙𝑡𝑖𝑝𝑙𝑖𝑐𝑎𝑡𝑖𝑜𝑛𝑎𝑛𝑑𝑎𝑠𝑠𝑜𝑐𝑖𝑎𝑡𝑖𝑣𝑖𝑡𝑦=𝗌𝗎𝖼(𝑞′)𝑏+𝑟, while 𝑟<𝑏 is unchanged. The recursive call is admitted by theorem 82.14 because its displayed measure is strictly smaller. Define 𝖽𝗂𝗏(𝑎,𝑏):=𝑞 and 𝗋𝖾𝗆(𝑎,𝑏):=𝑟 from the two components returned by this recursion. The decidable cases cover all naturals, completing both functions and their specification. ◻
From this point onward, 𝑎𝗋𝖾𝗆𝑏:=𝗋𝖾𝗆(𝑎,𝑏) and 𝑎𝖽𝗂𝗏𝑏:=𝖽𝗂𝗏(𝑎,𝑏) denote the two functions constructed by lemma 82.18.
The strict inequality in (Div), rather than the equation itself, is the termination certificate.
Put 𝑋:=ℕ×ℕ and (𝑎′,𝑏′)𝑅E(𝑎,𝑏)⟺𝑏′<𝑏. This is the measure relation for 𝜇(𝑎,𝑏):=𝑏, so it is well founded by theorem 82.14. For 𝑘:∏𝑥′:𝑋𝑥′𝑅E𝑥→ℕ define 𝐸((𝑎,𝑏),𝑘):={𝑎,𝑏=0,𝑘((𝑏,𝑎𝗋𝖾𝗆𝑏),𝑟𝑎,𝑏,𝑢),𝑢:𝑏>0, where 𝑟𝑎,𝑏,𝑢:𝑎𝗋𝖾𝗆𝑏<𝑏 is the second component of lemma 82.18 at 𝑎,𝑏,𝑢. For any accessibility certificate 𝑝 put 𝗀𝖼𝖽𝑝(𝑎,𝑏):=𝗐𝖿𝗋𝖾𝖼𝑅E,𝜆𝑥.ℕ(𝐸,(𝑎,𝑏),𝑝). Fix the well-foundedness witness 𝑤E obtained from theorem 82.14 and define 𝗀𝖼𝖽(𝑎,𝑏):=𝗀𝖼𝖽𝑤E(𝑎,𝑏)(𝑎,𝑏). Certificate independence from proposition 82.7 identifies this choice propositionally with every 𝗀𝖼𝖽𝑝(𝑎,𝑏).
The distinction between proof-indexed computation and the fixed total function is visible before any arithmetic unfolds. If 𝑧:𝖠𝖼𝖼𝑅E(𝑎,𝑏) is a variable, then 𝗐𝖿𝗋𝖾𝖼𝑅E,𝜆𝑥.ℕ(𝐸,(𝑎,𝑏),𝑧) is stuck: the certificate position is neutral, so the left side of (WF-β) does not match. In particular, the same term with 𝑧:=𝑤E(𝑎,𝑏) need not reduce when the chosen well-foundedness proof is opaque.
Every recursive argument and its evidence are visible in the second branch: (𝑏,𝑎𝗋𝖾𝗆𝑏)𝑅E(𝑎,𝑏)because𝑎𝗋𝖾𝗆𝑏<𝑏. Neither component needs to be a constructor field of (𝑎,𝑏).
For all 𝑎,𝑏:ℕ, Euclid’s program is total and satisfies 𝗀𝖼𝖽(𝑎,0)=𝑎,𝑏>0⟹𝗀𝖼𝖽(𝑎,𝑏)=𝗀𝖼𝖽(𝑏,𝑎𝗋𝖾𝗆𝑏). The equalities are identifications independent of the chosen accessibility certificates. At the proof-indexed function 𝗀𝖼𝖽𝑝, the zero equation is judgmental when 𝑝 is a constructor certificate and the zero test reduces. The positive equation is judgmental when, in addition, 𝑏≡𝗌𝗎𝖼(𝑏0) is a numeral successor, so that its branch test reduces. The equations for the fixed 𝗀𝖼𝖽 remain identifications when 𝑤E(𝑎,𝑏) is opaque.
Proof of Theorem 82.20 — Euclid equations and termination
Proof. By well-foundedness of 𝑅E, every pair is accessible, so definition 82.6 gives a result in ℕ. Inspect the decidable test 𝑏=0. In the zero branch, (WF-β) and definition 82.19 return 𝑎. In the positive branch, lemma 82.18 gives 𝑟𝑎,𝑏,𝑢, so the recursive-results function may be applied at (𝑏,𝑎𝗋𝖾𝗆𝑏). Equation (WF-β) then gives the second equation. Changing the outer or recursive accessibility certificate preserves the result by proposition 82.7; the Euclidean step is pointwise extensional because each branch either ignores 𝑘 or applies it once at the same pair and order proof. ◻
The positive divisors in this calculation provide the displayed decrease at each recursive call: 𝗀𝖼𝖽(48,18)48𝗋𝖾𝗆18=12<18=𝗀𝖼𝖽(18,12)18𝗋𝖾𝗆12=6<12=𝗀𝖼𝖽(12,6)12𝗋𝖾𝗆6=0<6=𝗀𝖼𝖽(6,0)𝑡ℎ𝑒𝑜𝑟𝑒𝑚82.20=6. The measure sequence is 18>12>6>0. The calculation ends because this is a descending sequence of natural numbers, not because either original input is peeled one constructor at a time.
Proof of Theorem 82.22 — Common-divisor specification
Proof. Use accessibility induction on (𝑎,𝑏) for 𝑅E. If 𝑏=0, then 𝑑=𝑎: it divides 𝑎, it divides 0, and every common divisor divides 𝑎=𝑑.
Suppose 𝑏>0 and write 𝑎=𝑞𝑏+𝑟 with 𝑟=𝑎𝗋𝖾𝗆𝑏<𝑏. The induction hypothesis at (𝑏,𝑟) says 𝑑:=𝗀𝖼𝖽(𝑏,𝑟) is greatest among common divisors of 𝑏 and 𝑟. If 𝑑 divides 𝑏 and 𝑟, the first divisibility implication of lemma 82.17 gives 𝑑∣(𝑞𝑏+𝑟)=𝑎. Conversely, if 𝑐 divides 𝑎 and 𝑏, the second implication gives 𝑐∣𝑟 from 𝑎=𝑞𝑏+𝑟. Thus the common divisors of (𝑎,𝑏) are exactly the common divisors of (𝑏,𝑟). The second equation of theorem 82.20 identifies their computed greatest common divisors. ◻
★☆☆ Calculate 𝗀𝖼𝖽(1071,462) to a numeral. Put the remainder and strict decrease on every equality sign, and list the complete second-coordinate measure sequence.
★★☆ Let 𝗉𝖺𝗋𝗍𝗂𝗍𝗂𝗈𝗇(𝑝,𝑥𝑠) return lists 𝑙,𝑟 such that every element of 𝑙 is at most 𝑝, every element of 𝑟 is greater than 𝑝, and |𝑙|+|𝑟|=|𝑥𝑠|. Give the two strict inequalities needed to define quicksort by the measure |𝑥𝑠| on the input 𝑝::𝑥𝑠. State why the partition equation alone does not prove either strict inequality if the pivot is not removed.
The generic accessibility predicate mentions every predecessor admitted by a relation. A particular recursive specification often needs fewer calls. The Bove–Capretta construction records exactly those calls in an inductive domain predicate and then recurses structurally on its proof.
Fix a positive divisor 𝑑:ℕ with 𝑢:𝑑>0. Consider the equations 𝑞𝑑(𝑛)={0𝑛<𝑑,𝗌𝗎𝖼(𝑞𝑑(𝑛−𝑑))𝑑≤𝑛.(𝑄𝑢𝑜𝑡) The recursive input 𝑛−𝑑 is not a constructor field of 𝑛. Instead of choosing a general relation, read the call graph directly from this equation.
The family 𝖣𝗈𝗆𝑑:ℕ→U𝑖 has the two constructors 𝖻𝖾𝗅𝗈𝗐:∏𝑛:ℕ𝑛<𝑑→𝖣𝗈𝗆𝑑(𝑛),𝗌𝗎𝖻𝗍𝗋𝖺𝖼𝗍:∏𝑛:ℕ𝑑≤𝑛→𝖣𝗈𝗆𝑑(𝑛−𝑑)→𝖣𝗈𝗆𝑑(𝑛). The second constructor stores exactly the domain proof required by the sole recursive call in (Quot).
Define 𝑞♯𝑑(𝑛,𝑝):ℕ by structural recursion on 𝑝:𝖣𝗈𝗆𝑑(𝑛): 𝑞♯𝑑(𝑛,𝖻𝖾𝗅𝗈𝗐(𝑣)):=𝟢,𝑞♯𝑑(𝑛,𝗌𝗎𝖻𝗍𝗋𝖺𝖼𝗍(𝑣,𝑝′)):=𝗌𝗎𝖼(𝑞♯𝑑(𝑛−𝑑,𝑝′)). The recursive proof 𝑝′ is a constructor field, so this definition satisfies the structural-call invariant of definition 82.1.
Proof of Theorem 82.25 — The division domain is total
Proof. Use measure induction on 𝑛. Decide 𝑛<𝑑. In the positive case, 𝖻𝖾𝗅𝗈𝗐(𝑛,𝑣) has the required type. Otherwise obtain 𝑤:𝑑≤𝑛. Since 𝑢:𝑑>0, natural arithmetic gives 𝑛−𝑑<𝑛. The induction hypothesis at that strict decrease gives 𝑝′:𝖣𝗈𝗆𝑑(𝑛−𝑑). Hence 𝗌𝗎𝖻𝗍𝗋𝖺𝖼𝗍(𝑛,𝑤,𝑝′):𝖣𝗈𝗆𝑑(𝑛). ◻
Choose the proof 𝑝𝑛 supplied by theorem 82.25 and put 𝑞𝑑(𝑛):=𝑞♯𝑑(𝑛,𝑝𝑛). Certificate independence is proved by induction on the first domain proof: the branch decision at 𝑛 determines which constructor can inhabit the second proof, and the induction hypothesis identifies the recursive results. Consequently 𝑞𝑑 satisfies (Quot) propositionally even when 𝑝𝑛 is opaque.
This construction is special-purpose accessibility. The domain proof is the accessibility tree for the recursive calls generated by one equation; it does not replace the generic relation-indexed recursor. Bove and Capretta develop the same separation between a recursive equation, its domain predicate, structural recursion on domain evidence, and totality of that domain [BC05].
★★☆ Reconstruct theorem 82.5 from the sole constructor of 𝖠𝖼𝖼𝑅. Instantiate it with the motive 𝑃(𝑎):=ℕ and derive (WF-β) with the types of ℎ, 𝑘, and every recursive call visible.
★★★ Define a three-coordinate lexicographic relation on 𝐴×𝐵×𝐶. Assuming well-founded relations on the three factors, prove its well-foundedness by three nested accessibility inductions. In each predecessor case state which induction hypothesis decreases and which coordinates remain unrestricted.
★★★Practical project.well-founded-call-checker Implement in Kappa a checker for annotations of the form “recursive call 𝑥′ has natural measure smaller than 𝑥”. Maintain the invariant that every accepted call carries a checked proof of 𝜇(𝑥′)<𝜇(𝑥); do not accept a Boolean comparison without its proof. Run it on the calls of example 82.21, which must produce the measure trace 18,12,6,0, and on the mutation 𝗀𝖼𝖽(𝑎,𝑏)↦𝗀𝖼𝖽(𝑏,𝑎), which must be rejected at the first call from (48,18). The acceptance test passes exactly when all three Euclidean calls are accepted with those measures and the mutation is rejected at (48,18) with the nondecrease 48≮18.
Sources. The accessibility presentation and its recursion principle follow Paulson’s construction [Pau86]; the HoTT Book, §10.3, gives the same constructor and derives well-founded recursion [Uni13]. Abel and Pientka treat a stronger sized calculus [AP16]; none of its normalization theorem is used for 𝑇𝗋𝖾𝖼 here.