Lectures onType Theory
Chapter 82
Chapter 82Core route

Well-Founded Recursion

The recursive call in gcd(a,b)={ab=0,gcd(b,aremb)b>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.

Definition 82.1 — Structural-call invariant

Consider a constructor branch of the inductive schema of chapter 28 whose scrutinee has the form ci(u,f1,,fri). A structural recursor may call itself only at (Structuralcall)fj(z),1jri,z:Θij. 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 gcd, the positive branch has input bsuc(b0), but its recursive input aremb is neither the field b0 nor an application of a recursive constructor field. Recursing on the first input fails the same test because the recursive input is b, which need not be a constructor field of a. Hence neither choice makes the Euclidean call an instance of (Structural-call).

Accessibility records the recursive calls

Let A:Ui and let R:AAUj be a proof-relevant binary relation. We write bRa when a recursive call at a may call the function at b. The order of the arguments is part of this convention. The optional signature Trec is T0 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 T0.

Definition 82.2 — Accessibility and well-foundedness

An element a:A is accessible for R when every R-predecessor of a is accessible. The indexed family AccR:AUij is governed first by formation and introduction:

ΓA:UiΓR:AAUjΓa:A
ΓAccR(a):Uij
Acc-form
Γa:AΓh:b:AbRaAccR(b)
Γacca(h):AccR(a)
Acc-intro

Thus its constructor has the type acca:(b:AbRaAccR(b))AccR(a). The relation R is well founded when WellFounded(R):=a:AAccR(a) is inhabited. This definition asserts accessibility of every element; it does not assert that a program can decide bRa.

The constructor stores precisely the recursive calls permitted below a. For pacca(h) and r:bRa, the proof hbr is the smaller certificate used by the recursive call.

Remark 82.3 — Cycles are excluded

If a0Ra1RRan=a0, then no term of AccR(a0) exists in a normalizing theory. Repeatedly inspecting the outer acc 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 N put bRa:=IdN(b,suc(a)). This relation has no cycle, while 1R0, 2R1, 3R2, and so on give the infinite sequence of successive predecessors 0,1,2,3,.

Definition 82.4 — Accessibility elimination

Let P:a:AAccR(a)Uk. Put H(a):=b:AbRaAccR(b),K(a,h):=b:Ar:bRaP(b,hbr),StepP:=a:Ah:H(a)K(a,h)P(a,acca(h)). The proof-dependent accessibility eliminator has the compact rule

ΓP:a:AAccR(a)UkΓa:AΓs:StepPΓp:AccR(a)
ΓaccindP(s,a,p):P(a,p)
Acc-elim

and its computation rule is accStepP(s,a,h):=s(a,h,λb.λr.accindP(s,b,hbr)).

ΓP:a:AAccR(a)UkΓa:AΓs:StepPΓh:H(a)
accindP(s,a,acca(h))accStepP(s,a,h):P(a,acca(h))
Acc-β

Equivalently, (Accβ)accindP(s,a,acca(h))s(a,h,λb.λr.accindP(s,b,hbr)). The argument h exposes the immediate accessibility subproofs. The final argument gives the induction result at each such subproof. Taking P(a,p):=Q(a) derives the non-proof-dependent eliminator used for ordinary well-founded recursion.

Theorem 82.5 — Accessibility induction

Let P:AUk. Suppose s:a:A(b:AbRaP(b))P(a). Define P(a,p):=P(a) and s(a,h,k):=s(a,k). Then accindP(s):a:AAccR(a)P(a). If w:WellFounded(R), then λa.accindP(s,a,wa):a:AP(a).

Proof of Theorem 82.5 — Accessibility induction

Proof. Fix a:A and p:AccR(a). Apply Acc-elim to p. For the constant-in-the-certificate motive P, the displayed definition of s has type StepP: its recursive-results argument k has type b:AbRaP(b), exactly the second argument required by s(a). The eliminator has one constructor case. Write pacca(h), where h:b:AbRaAccR(b). For each b:A and r:bRa, the induction hypothesis gives accindP(s,b,hbr):P(b). Abstracting b and r produces the recursive-results argument required by s; applying s gives P(a). This is exactly the specialization of (Acc-β). If w proves well-foundedness, instantiate the first conclusion with p:=wa at every a. ◻

Exercise 82.1

★☆☆ Assume q:aRa. Induct directly on the accessibility certificate to construct AccR(a)0. Write the structurally smaller certificate used by the recursive call explicitly. Explain why the nondependent eliminator of definition 82.4 with constant motive 0 would not by itself establish this fixed-point argument.

The recursor and its exact equation

Accessibility induction becomes recursion when the motive describes the result type. Keeping the accessibility certificate visible prevents a hidden proof-irrelevance assumption.

Definition 82.6 — Proof-indexed well-founded recursion

For P:AUk and s:a:A(b:AbRaP(b))P(a), define the well-founded recursor wfrecR,P(s,a,p):=accindλa.λp.P(a)(λa.λh.λk.s(a,k),a,p). Its result and recursive-call types are therefore wfrecR,P(s,a,p):P(a),k:b:AbRaP(b). For a constructor certificate it has the judgmental equation (WFβ)wfrecR,P(s,a,acca(h))s(a,λb.λr.wfrecR,P(s,b,hbr)). Given w:WellFounded(R), its total specialization is wfrecR,Pw(s,a):=wfrecR,P(s,a,wa).

Equation (WF-β) computes on the accessibility constructor. An equation obtained by replacing acca(h) with an arbitrary wa is not judgmental unless wa 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 R be the empty relation on 1, let h:b:1bRAccR(b) eliminate its empty relation proof, and put s0(x,k):=0 for x:1. Abbreviate W(x,p):=wfrecR,λx.N(s0,x,p). Then W(,acc(h))(WFβ)s0(,λb.λr.W(b,hbr))definitionofs00. By contrast, for a variable z:AccR(), the term W(,z) is neutral: its certificate has no outer acc constructor, so (WF-β) has no matching redex.

Proposition 82.7 — Extensional independence of certificates

Assume that s is pointwise extensional: for every a:A and recursive-result functions k,k, (b:Ar:bRaIdP(b)(kbr,kbr))IdP(a)(s(a,k),s(a,k)). Then for p,q:AccR(a) there is an identification IdP(a)(wfrecR,P(s,a,p),wfrecR,P(s,a,q)).

Proof of Proposition 82.7 — Extensional independence of certificates

Proof. Use accessibility induction on p with the strengthened motive M(a,p):=q:AccR(a)IdP(a)(wfrecR,P(s,a,p),wfrecR,P(s,a,q)). In the sole constructor case, let pacca(h) and fix q:AccR(a). The second elimination uses the motive Wx(q):=wfrecR,P(s,x,q),I(x,h0):=b:Ar:bRxM(b,h0br),N(x,q):=h0:H(x)I(x,h0)IdP(x)(Wx(accx(h0)),Wx(q)). This motive re-abstracts both h and the outer induction hypothesis, so Acc-elim applies to q without assuming a judgmental inversion at the fixed index. Its constructor case has qacca(h). Instantiate the branch at h and at the outer induction hypothesis. For b:A and r:bRa, that hypothesis has type M(b,hbr). Instantiating its quantified certificate with hbr gives wfrecR,P(s,b,hbr)=P(b)wfrecR,P(s,b,hbr). Abstracting b and r gives the premise of pointwise extensionality of s. Its conclusion identifies the two applications of s; conversion by the two instances of (WF-β) closes N(a,acca(h)) at h and the outer hypothesis. The recursive hypotheses generated by this inner Acc-elim are not needed. Hence the outer goal M(a,acca(h)) follows. No proof-irrelevance or judgmental equality of p and q is used. ◻

Remark 82.8 — Boundary of certificate independence

Function extensionality implies the pointwise-extensionality hypothesis for every step s: pointwise equal recursive-result functions are then equal, and congruence for ks(a,k) 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.

Remark 82.9 — Mathematics versus recognition

The recursor consumes p:AccR(a). 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.

Measures and lexicographic descent

The usual order on natural numbers is written m<n. Its proof-relevant presentation has constructors witnessing that zero is below every successor and that successor preserves order.

Γn:N
ΓltZero(n):0<suc(n)
Lt-zero
Γp:m<n
ΓltSuc(p):suc(m)<suc(n)
Lt-suc

These constructor names are used when the proofs below invert a strict inequality.

Definition 82.10 — Weak natural-number order

For m,n:N, write mn:=IdN(m,n)+(m<n). Thus a weak inequality records either equality or a strict inequality; the symbol in this chapter always denotes this sum type.

Lemma 82.11 — Natural-order inversion and mixed transitivity

For ,m,n:N:

  1. m0IdN(m,0);

  2. <suc(n)n;

  3. <mn implies <n.

Proof of Lemma 82.11 — Natural-order inversion and mixed transitivity

Proof. For (1), eliminate the sum defining m0. Its identity branch is the required term, while its strict branch has type m<0 and is empty by inversion on Lt-zero and Lt-suc. For (2), induct on n. If n0, inversion of <suc(0) gives 0, hence the identity injection into 0. If nsuc(n), inversion gives either 0, when 0<suc(n), or suc() with <suc(n). In the latter case, apply the induction hypothesis and map its identity and strict branches through suc. These are precisely the two injections into suc(n). For (3), eliminate mn. Transport along its identity branch turns <m into <n. In the strict branch, strict transitivity follows by induction on the second <-derivation, applying Lt-suc in its successor case. ◻

Lemma 82.12 — Natural-number accessibility

Every n:N is accessible for <. Hence < is well founded.

Proof of Lemma 82.12 — Natural-number accessibility

Proof. Prove by induction on n the strengthened statement Q(n):=m:NmnAcc<(m). For n0, fix an input m0. By lemma 82.11(1), obtain e:IdN(m,0). Construct p0:=acc0(h0), where h0 eliminates its impossible premise <0. Then tre1x.Acc<(x)(p0):Acc<(m).

For nsuc(n), fix msuc(n). Construct accm(h). Given <m, transitivity gives <suc(n) by lemma 82.11(3), and then lemma 82.11(2) gives n. The induction hypothesis at n gives Acc<(), which defines h. Taking m:=n and the left injection of reflexivity into nn concludes the lemma. ◻

Definition 82.13 — Relation induced by a measure

For a function μ:AN, define b<μaif and only ifμ(b)<μ(a). The relation <μ is the measure relation induced by μ.

Theorem 82.14 — Measure recursion

For every μ:AN, the relation <μ is well founded. Consequently a step of type a:A(b:Aμ(b)<μ(a)P(b))P(a) defines a proof-indexed total result at every a:A.

Proof of Theorem 82.14 — Measure recursion

Proof. For n:N and p:Acc<(n), use accessibility induction with the strengthened motive M(n,p):=a:AIdN(μ(a),n)Acc<μ(a). In the constructor case paccn(h), fix a:A and e:IdN(μ(a),n). For b:A and r:μ(b)<μ(a), put re:=trev.μ(b)<v(r):μ(b)<n,pb,r:=hμ(b)re. The induction hypothesis belonging to pb,r proves M(μ(b),pb,r). Its instance at b and reflexivity has type Acc<μ(b); call that term Ib,r. Hence acca(λb.λr.Ib,r):Acc<μ(a). Finally apply this construction to n:=μ(a), the accessibility proof of lemma 82.12, and reflexivity. Accessibility induction then gives the stated recursor. ◻

Definition 82.15 — Lexicographic relation

For relations R:AAUi and S:BBUj, their lexicographic relation on A×B is the proof-relevant relation ((a,b)Lex(R,S)(a,b)):=(aRa)+(IdA(a,a)×(bSb)). The left injection decreases the first coordinate and leaves the second coordinate unrestricted. The right injection keeps the first coordinate identified with a and decreases the second.

Theorem 82.16 — Lexicographic well-foundedness

If R and S are well founded, then Lex(R,S) is well founded.

Proof of Theorem 82.16 — Lexicographic well-foundedness

Proof. Let wR:WellFounded(R) and wS:WellFounded(S). Apply accessibility induction to wRa with the outer motive L(a,p):=b:BAccLex(R,S)(a,b). In its constructor case pacca(hR), the outer induction hypothesis is IR:a:AaRab:BAccLex(R,S)(a,b). Fix b:B and apply accessibility induction to wSb with the inner motive J(b,q):=AccLex(R,S)(a,b). In the case qaccb(hS), the inner induction hypothesis is IS:b:BbSbAccLex(R,S)(a,b). Construct acc(a,b)(k). For a predecessor (a,b), eliminate its witness in the sum of definition 82.15. A left witness r:aRa is sent to IRarb. A right witness (e,s):IdA(a,a)×(bSb) is sent to trex.AccLex(R,S)(x,b)(ISbs):AccLex(R,S)(a,b). These clauses define k. The inner and outer inductions therefore prove accessibility of every pair. ◻

Exercise 82.2

★★☆ Let R and S be relations on A and B with measures μ:AN and ν:BN. Prove that the relation which decreases both coordinates strictly is well founded using the measure (a,b)μ(a)+ν(b). Explain why this relation is smaller than the lexicographic relation of theorem 82.16.

Euclid’s algorithm as a well-founded program

Write aremb for natural-number remainder. We use the following division result, whose proof uses the recursor of definition 82.6.

Lemma 82.17 — Natural arithmetic interface

Define truncated subtraction by a˙0a,0˙suc(b)0,suc(a)˙suc(b)a˙b. For all a,b,q,c,r:N:

  1. the alternative a<b or ba is decidable;

  2. if ba, then a=b+(a˙b), and if also b>0, then a˙b<a;

  3. writing cn for k:NIdN(n,kc), the implications cbcrc(qb+r),cacba=qb+rcr hold.

Proof of Lemma 82.17 — Natural arithmetic interface

Proof. For decidability, recurse simultaneously on a and b. At (0,0) choose ba; at (0,suc(b)) choose a<b; and at (suc(a),0) choose ba. At (suc(a),suc(b)), recurse on (a,b) 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 ba, exposing a and b together. The zero case reduces to a=0+a. The successor case reduces suc(a)=suc(b)+(suc(a)˙suc(b)) to the induction hypothesis a=b+(a˙b). If b>0, write b=suc(b). The identity has the form a=suc(b)+r with r=a˙b; induction on b constructs r<suc(b)+r=a. This proves the strict decrease without appealing to the earlier monus exercise.

For divisibility, first establish by natural-number induction the equations x+y=y+x,xy=yx,x(yz)=(xy)z,q(kc)=(qk)c,(xc)+(yc)=(x+y)c,(x+y)˙x=y,(xc)˙(yc)=(x˙y)c. The addition and multiplication laws use the zero and successor equations in the corresponding induction. For the fourth law, induct on x; the successor case first rewrites suc(x)+y=suc(x+y) and then applies the successor–successor monus clause. For the last equation, use multiplication commutativity, proved by the same successor induction, to put c first and induct on the pair (x,y). The successor–successor case cancels one common summand c using (u+c)˙(v+c)=u˙v, whose proof is induction on c; the two zero cases are the defining monus equations. Thus these calculations cover all constructor pairs.

If b=kc and r=lc, associativity and the first two equations give qb+r=q(kc)+lc=(qk+l)c, so qk+l is a divisibility witness. Conversely, suppose a=kc, b=lc, and a=qb+r. Substitution into the fourth displayed law gives a˙qb=r. Therefore r=(kc)˙((ql)c)=(k˙ql)c, so k˙ql is the required witness. ◻

Lemma 82.18 — Natural-number division

There are functions div,rem:NNN such that, for every a,b:N and u:b>0, (Div)a=div(a,b)b+rem(a,b),rem(a,b)<b, and both functions are computed, for fixed positive b, by well-founded recursion on a. Equivalently, the construction gives the two leading components of DivSpec(d,r):=a,b:Nb>0(IdN(a,d(a,b)b+r(a,b))×(r(a,b)<b)). The resulting package inhabits d:NNNr:NNNDivSpec(d,r).

Proof of Lemma 82.18 — Natural-number division

Proof. For b0, define div(a,b):=0 and rem(a,b):=a; the specification has no inhabitant u:b>0 to check. For bsuc(b0), use its constructor proof of b>0 and recurse on the measure a. If a<b, return q:=0 and r:=a. Otherwise ba; by lemma 82.17, a=b+(a˙b), and positivity of b gives a˙b<a. The recursive result at a˙b has the form a˙b=qb+r,r<b. Return q:=suc(q) and the same r. Then a=lemma82.17b+(a˙b)=recursiveequationb+(qb+r)=successormultiplicationandassociativitysuc(q)b+r, while r<b is unchanged. The recursive call is admitted by theorem 82.14 because its displayed measure is strictly smaller. Define div(a,b):=q and rem(a,b):=r from the two components returned by this recursion. The decidable cases cover all naturals, completing both functions and their specification. ◻

From this point onward, aremb:=rem(a,b) and adivb:=div(a,b) denote the two functions constructed by lemma 82.18.

The strict inequality in (Div), rather than the equation itself, is the termination certificate.

Definition 82.19 — Euclidean step

Put X:=N×N and (a,b)RE(a,b)b<b. This is the measure relation for μ(a,b):=b, so it is well founded by theorem 82.14. For k:x:XxRExN define E((a,b),k):={a,b=0,k((b,aremb),ra,b,u),u:b>0, where ra,b,u:aremb<b is the second component of lemma 82.18 at a,b,u. For any accessibility certificate p put gcdp(a,b):=wfrecRE,λx.N(E,(a,b),p). Fix the well-foundedness witness wE obtained from theorem 82.14 and define gcd(a,b):=gcdwE(a,b)(a,b). Certificate independence from proposition 82.7 identifies this choice propositionally with every gcdp(a,b).

The distinction between proof-indexed computation and the fixed total function is visible before any arithmetic unfolds. If z:AccRE(a,b) is a variable, then wfrecRE,λx.N(E,(a,b),z) is stuck: the certificate position is neutral, so the left side of (WF-β) does not match. In particular, the same term with z:=wE(a,b) need not reduce when the chosen well-foundedness proof is opaque.

Every recursive argument and its evidence are visible in the second branch: (b,aremb)RE(a,b)becausearemb<b. Neither component needs to be a constructor field of (a,b).

Theorem 82.20 — Euclid equations and termination

For all a,b:N, Euclid’s program is total and satisfies gcd(a,0)=a,b>0gcd(a,b)=gcd(b,aremb). The equalities are identifications independent of the chosen accessibility certificates. At the proof-indexed function gcdp, the zero equation is judgmental when p is a constructor certificate and the zero test reduces. The positive equation is judgmental when, in addition, bsuc(b0) is a numeral successor, so that its branch test reduces. The equations for the fixed gcd remain identifications when wE(a,b) is opaque.

Proof of Theorem 82.20 — Euclid equations and termination

Proof. By well-foundedness of RE, every pair is accessible, so definition 82.6 gives a result in N. Inspect the decidable test b=0. In the zero branch, (WF-β) and definition 82.19 return a. In the positive branch, lemma 82.18 gives ra,b,u, so the recursive-results function may be applied at (b,aremb). 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 k or applies it once at the same pair and order proof. ◻

Example 82.21 — A complete Euclidean calculation

The positive divisors in this calculation provide the displayed decrease at each recursive call: gcd(48,18)=48rem18=12<18gcd(18,12)=18rem12=6<12gcd(12,6)=12rem6=0<6gcd(6,0)=theorem82.206. 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.

Theorem 82.22 — Common-divisor specification

For all a,b:N, the result d:=gcd(a,b) divides both a and b. Every c:N dividing both a and b also divides d.

Proof of Theorem 82.22 — Common-divisor specification

Proof. Use accessibility induction on (a,b) for RE. If b=0, then d=a: it divides a, it divides 0, and every common divisor divides a=d.

Suppose b>0 and write a=qb+r with r=aremb<b. The induction hypothesis at (b,r) says d:=gcd(b,r) is greatest among common divisors of b and r. If d divides b and r, the first divisibility implication of lemma 82.17 gives d(qb+r)=a. Conversely, if c divides a and b, the second implication gives cr from a=qb+r. Thus the common divisors of (a,b) are exactly the common divisors of (b,r). The second equation of theorem 82.20 identifies their computed greatest common divisors. ◻

Exercise 82.3

★☆☆ Calculate gcd(1071,462) to a numeral. Put the remainder and strict decrease on every equality sign, and list the complete second-coordinate measure sequence.

Exercise 82.4

★★☆ Let partition(p,xs) return lists l,r such that every element of l is at most p, every element of r is greater than p, and |l|+|r|=|xs|. Give the two strict inequalities needed to define quicksort by the measure |xs| on the input p::xs. State why the partition equation alone does not prove either strict inequality if the pivot is not removed.

A special-purpose domain predicate

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 d:N with u:d>0. Consider the equations (Quot)qd(n)={0n<d,suc(qd(nd))dn. The recursive input nd is not a constructor field of n. Instead of choosing a general relation, read the call graph directly from this equation.

Definition 82.23 — Division domain

The family Domd:NUi has the two constructors below:n:Nn<dDomd(n),subtract:n:NdnDomd(nd)Domd(n). The second constructor stores exactly the domain proof required by the sole recursive call in (Quot).

Definition 82.24 — Structural quotient on a domain proof

Define qd(n,p):N by structural recursion on p:Domd(n): qd(n,below(v)):=0,qd(n,subtract(v,p)):=suc(qd(nd,p)). The recursive proof p is a constructor field, so this definition satisfies the structural-call invariant of definition 82.1.

The remaining obligation is to show that every intended input inhabits the domain. Positivity of d gives the decrease needed for that proof.

Theorem 82.25 — The division domain is total

For every n:N, the type Domd(n) is inhabited.

Proof of Theorem 82.25 — The division domain is total

Proof. Use measure induction on n. Decide n<d. In the positive case, below(n,v) has the required type. Otherwise obtain w:dn. Since u:d>0, natural arithmetic gives nd<n. The induction hypothesis at that strict decrease gives p:Domd(nd). Hence subtract(n,w,p):Domd(n). ◻

Choose the proof pn supplied by theorem 82.25 and put qd(n):=qd(n,pn). Certificate independence is proved by induction on the first domain proof: the branch decision at n determines which constructor can inhabit the second proof, and the induction hypothesis identifies the recursive results. Consequently qd satisfies (Quot) propositionally even when pn 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].

Suggested first pass.

None of these problems is a prerequisite. Begin with exercise 82.5, then complete exercise 82.7.

Exercise 82.5

★★☆ Reconstruct theorem 82.5 from the sole constructor of AccR. Instantiate it with the motive P(a):=N and derive (WF-β) with the types of h, k, and every recursive call visible.

Exercise 82.6

★★★ Define a three-coordinate lexicographic relation on A×B×C. 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.

A proof-carrying call checker.

Exercise 82.7

★★★ Practical project.well-founded-call-checker Implement in Kappa a checker for annotations of the form “recursive call x has natural measure smaller than x”. Maintain the invariant that every accepted call carries a checked proof of μ(x)<μ(x); 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 gcd(a,b)gcd(b,a), 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 4818.

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 Trec here.

Search the book

Type to search the local edition.