Lectures onType Theory
Chapter 78
Chapter 78Core route

Indexed Inductive Families and Dependent Pattern Matching

A list records its elements but not its length. Attaching a natural number to a list repairs the statement of lookup only externally: the type checker still cannot infer from the constructor that the number is zero or a successor. The result index of a constructor must therefore be part of the declaration.

The index is fixed by the constructor

The unindexed schema of definition 28.34 permits a constructor whose recursive arguments have the type being declared. It does not permit the attempted declaration vnil:Vec(A,0),vcons:n:NAVec(A,n)Vec(A,suc(n)), because there is no single unindexed result type to put in the constructor signature. Replacing every occurrence by n:NVec(A,n) loses the constraint: the tail of a purported successor vector may then carry an unrelated index. Write vcons for the constructor produced by this attempted replacement. If xs:Vec(A,5), then the raw package (suc(0),vcons(a,(5,xs))) claims outer index 1 while its displayed tail has index 5. No equation in the unindexed signature relates the two components. The index must occur in the result type of the constructor, not merely in a package around its recursive argument.

An indexed inductive family is generated simultaneously at every index, and each constructor specifies the index of its result. Extend the signature of definition 28.34 by the following vector family.

Definition 78.1 — Vectors

For A:Ui, the family Vec(A,):NUi is formed by

ΓA:UiΓn:N
ΓVec(A,n):Ui
Vec-form

Its constructors have types vnil:Vec(A,0),vcons:n:NAVec(A,n)Vec(A,suc(n)). For example, the successor constructor has the derivation Γn:NΓa:AΓxs:Vec(A,n)Γvcons(n,a,xs):Vec(A,suc(n))Vecintros. In this derivation Vec-form first forms the result family at suc(n), and Vec-intros then assigns the constructor the displayed result type. Its dependent eliminator has the following rule. Put P0:=P[0/n,vnil/v] and Ps:=P[suc(n)/n,vcons(n,a,xs)/v].

Γ,n:N,v:Vec(A,n)P:UjΓp0:P0Γ,n:N,a:A,xs:Vec(A,n),q:P[n/n,xs/v]ps:PsΓm:NΓys:Vec(A,m)
Γvind(P;p0;ps;m,ys):P[m/n,ys/v]
Vec-elim

Put r:=vind(P;p0;ps;n,xs). The two computation rules are vind(P;p0;ps;0,vnil)p0,vind(P;p0;ps;suc(n),vcons(n,a,xs))ps[n/n,a/a,xs/xs,r/q]. We refer to these two constructor equations collectively as Vec-comp. The variables displayed in the motive and successor branch are pairwise distinct and avoid dom(Γ).

The successor branch is the new feature. Its recursive hypothesis concerns xs:Vec(A,n), while its target concerns a value at index suc(n). Thus constructor typing performs the index refinement that an unindexed encoding could only postulate.

Construction 78.2 — Head and tail from the eliminator

First use natural-number recursion in the universe to define h,t:NUi by h(0):=1,h(suc(n)):=A,t(0):=1,t(suc(n)):=Vec(A,n). Now put H(n,v):=h(n) and T(n,v):=t(n) in the context n:N,v:Vec(A,n). These are well-formed motives because the recursion defining h and t is completed before weakening them by the dependent variable v; neither definition eliminates n while retaining a fixed v. The vector eliminator gives head+(m,ys):=vind(H;;n.a.xs.q.a;m,ys):H(m,ys),tail+(m,ys):=vind(T;;n.a.xs.q.xs;m,ys):T(m,ys). For ys:Vec(A,suc(n)), set head(ys):=head+(suc(n),ys) and tail(ys):=tail+(suc(n),ys). Their constructor computations are judgmental: head(vcons(n,a,xs))a,tail(vcons(n,a,xs))xs. No impossible vnil clause was assumed; the eliminator places that clause in the harmless types 1 and 1.

If m:N and ys:Vec(A,m) are variables, then vind(P;p0;ps;m,ys) is neutral: neither constructor computation rule applies. The vector rules contain no uniqueness equation that could reconstruct ys from this stuck eliminator.

Finite indices and direct programs

The recursive universe-valued family of construction 29.17 will be written FinLE: it satisfies FinLE(0)0 and FinLE(suc(n))FinLE(n)+1. An inductive presentation makes the two ways to inhabit a successor size available as constructors. The subscript LE recalls the strict inequality k<n used in the universe-valued definition; ind marks the constructor-generated presentation.

Definition 78.3 — Inductive finite indices

The family Finind:NU0 has constructors fz:n:NFinind(suc(n)),fs:n:NFinind(n)Finind(suc(n)). For a motive Q:n:NFinind(n)Uj, branches qz:n:NQ(suc(n),fz(n)),qs:n:Nk:Finind(n)Q(n,k)Q(suc(n),fs(n,k)) determine find(Q;qz;qs;n,k):Q(n,k), with judgmental computation on fz and fs. More precisely, elimination is governed by

Γ,n:N,k:Finind(n)Q(n,k):UjΓqz:n:NQ(suc(n),fz(n))Γqs:n:Nk:Finind(n)Q(n,k)Q(suc(n),fs(n,k))Γm:NΓu:Finind(m)
Γfind(Q;qz;qs;m,u):Q(m,u)
Fin-elim

Writing r:=find(Q;qz;qs;n,k), its computation equations are find(Q;qz;qs;suc(n),fz(n))qz(n),find(Q;qz;qs;suc(n),fs(n,k))qs(n,k,r).

Theorem 78.4 — The two finite families agree

For every n:N there are maps en:Finind(n)FinLE(n),dn:FinLE(n)Finind(n) and identifications dn(en(k))=k and en(dn(u))=u for all k and u in their respective domains.

Proof of Theorem 78.4 — The two finite families agree

Proof. Rule Fin-elim defines esuc(n)(fz(n)):=inr(),esuc(n)(fs(n,k)):=inl(en(k)). Natural-number induction defines d0 by empty elimination and dsuc(n)(inr()):=fz(n),dsuc(n)(inl(u)):=fs(n,dn(u)). For dnen, apply finite-index elimination. The fz branch is reflexivity; the fs branch applies ap to fs(n,) and the recursive hypothesis. For endn, apply natural-number induction. Its zero case is empty elimination. In the successor case apply coproduct elimination. The right branch is reflexivity; the left branch applies ap to inl and the induction hypothesis. These are all constructor cases, so the displayed definitions compute judgmentally before the final applications of ap. ◻

After theorem 78.4, write Fin(n) when a construction is invariant under these two inverse maps. The programs below use Finind because its eliminator exposes the zero and successor positions.

Construction 78.5 — Lookup, map, and append

Finite-index elimination avoids an impossible vector branch. Take Q(m,k):=Vec(A,m)A. The fz(n) method sends ys:Vec(A,suc(n)) to head(ys). The fs(n,k) method sends a recursive map q:Vec(A,n)A and ys:Vec(A,suc(n)) to q(tail(ys)). Define lookup(ys,k):=find(Q;qz;qs;m,k)(ys), where ys:Vec(A,m) and k:Finind(m). The two finite-index equations followed by the head and tail equations give lookup(vcons(n,a,xs),fz(n))a,lookup(vcons(n,a,xs),fs(n,k))lookup(xs,k). Thus lookup has no size-zero clause: there is no k:Finind(0) to eliminate.

For B:Ui and f:AB, vector elimination with motive P(n,xs):=Vec(B,n) defines map(f,vnil):=vnil,map(f,vcons(n,a,xs)):=vcons(n,f(a),map(f,xs)). To append xs:Vec(A,m) to ys:Vec(A,n), use the motive P(m,xs):=Vec(A,n+m). The fixed length n is written first because the addition of construction 28.23 recurs on its second argument. The equations are append(vnil,ys):=ys,append(vcons(m,a,xs),ys):=vcons(n+m,a,append(xs,ys)). The empty branch has the required type because n+0n by the orientation of construction 28.23. The second term has the required type because n+suc(m)suc(n+m) for that same orientation.

Exercise 78.1

★★☆ For f:AB, xs:Vec(A,n), and k:Finind(n), construct an identification lookup(map(f,xs),k)=f(lookup(xs,k)). Use vector elimination and display both finite-index cases in the successor branch.

No confusion and pattern clauses

A constructor pattern refines its index, but it must not silently assert an identity between constructor forms. The required facts are derived from eliminators.

Proposition 78.6 — No confusion used for vectors and finite indices

The following terms are derivable without K.

  1. For k:Finind(n), IdFinind(suc(n))(fz(n),fs(n,k))0.

  2. If p:IdFinind(suc(n))(fs(n,k),fs(n,l)), then there is an identification k=l in Finind(n).

  3. If p:IdVec(A,suc(n))(vcons(n,a,xs),vcons(n,b,ys)), then there are identifications a=b in A and xs=ys in Vec(A,n).

Proof of Proposition 78.6 — No confusion used for vectors and finite indices

Proof. For (i), finite-index elimination defines C:Finind(suc(n))U0. Its constructor equations are C(fz(n))1 and C(fs(n,k))0. Transporting :C(fz(n)) along p gives an element of 0.

For (ii), define a predecessor into Finind(n)+1 by sending fz to the right summand and fs(n,r) to inl(r). Applying this map to p gives inl(k)=inl(l). Choose a default value k and define q:Finind(n)+1Finind(n) by q(inl(r)):=r and q(inr()):=k. Applying apq to the displayed equality gives k=l. For (iii), apply ap to head and tail from construction 78.2. Their constructor computations identify the endpoints with a,b and xs,ys, respectively. ◻

The disjointness proof depends only on the eliminators and identity induction. Judgmental injectivity of raw constructors would require a normalization or term-model theorem; no such stronger assertion is used here.

A pattern clause is an equation whose left side is built from variables and constructors. The clauses have coverage when every constructor compatible with the scrutinee index has a branch. A clause is accepted only after coverage and the generated index equations have been checked. Write Tpattm(p) for the ordinary term tuple obtained from a pattern tuple p by erasing dots and reading every constructor pattern as the corresponding constructor term. For example, head(vcons(.n,a,xs))=a contains an inaccessible pattern .n: it records the value forced by unifying the scrutinee index suc(n) with the constructor result index, but it does not split on n.

Construction 78.7 — Compiling head and append

The head clause has one reachable constructor. Give Vec-elim the motive H of construction 78.2; its empty branch is , and its successor branch returns a. Restricting the result to successor indices is exactly head.

The two append clauses are covered by vnil and vcons. Give Vec-elim the motive P(m,xs):=Vec(A,n+m), the empty branch ys, and the successor branch m.a.xs.q.vcons(n+m,a,q). This is the eliminator term of construction 78.5; its two judgmental computations are the two pattern equations. Pattern syntax has therefore introduced no new proof principle in these examples.

Case trees without K

Coverage for indexed patterns is not merely a list of constructors. Splitting x:D(u) against a constructor ci:ΔiD(vi) produces the equation list u=vi. A unifier must either solve that list, prove the branch impossible by constructor conflict or a finite occurs check, or refuse the split.

The source argument uses equality of whole telescopes, not a heterogeneous equality hidden in the unifier. We first expose that equality and its eliminator.

Definition 78.8 — Homogeneous telescopic equality

For a telescope Δ, define the telescopic-equality type sΔt recursively: ()()():=1,(s;s)x:A;Δ(x)(t;t):=e:IdA(s,t)esΔ(t)t. Here es transports the later components of s along e. The expression sΔt is a type internal to the theory. It is distinct from the external judgmental-equality assertion st even though the two notations share a glyph. Reflexivity refls is defined recursively: at the empty telescope it is , and at (s;s) it is (refls,refls) after the reflexivity transport has computed. For a family C(s,t,e):Uj, iterated identity induction gives JΔ(C):(s:ΔC(s,s,refls))s,t:Δe:sΔtC(s,t,e). It satisfies JΔ(C,d,s,s,refls)d(s). The extension step first eliminates the head identity and then invokes J on the transported tail. Thus no identity proofs are equated. Telescopic symmetry is the derived map symΔ:sΔttΔs, obtained by JΔ with reflexivity clause refls. Its reflexivity computation is judgmental.

Definition 78.9 — Restricted unification

A unification problem is a telescope together with a homogeneous telescopic equality. The restricted transition system has four operations.

  1. Solution: replace a variable x by t when xFV(t).

  2. Injectivity: replace c(s)=c(t) by the equations sΔct, where Δc is the constructor argument telescope.

  3. Conflict: reject c(s)=d(t) when cd.

  4. Cycle: reject x=c(t[x]) when the displayed occurrence of x lies at a recursive argument position below a constructor. First-order pattern problems produce cycles only at these BelowD-reachable positions.

There is no transition deleting t=t. Before injectivity is applied to c(s)=c(t):D(u), the index problem uΞu must itself have a positive solution. A positive solution records a most general substitution; conflict or cycle is negative; a stuck problem is failure, not coverage.

These are the two restrictions imposed in Cockx–Devriese–Piessens, Section 3.1: no deletion, and self-unifiability of indices before constructor injectivity. The first rejects K(P,p,refl)=p for e:IdA(a,a), because matching e with reflexivity generates a=a. Deleting that equation would turn path induction with fixed endpoint into K. The second restriction blocks the same deletion from being concealed by constructor injectivity one level higher. The second restriction has its own boundary. Without it, injectivity would admit the single clause weakK(reflrefla)=reflreflrefla at the type weakK:e:IdIdA(a,a)(refla,refla)IdIdIdA(a,a)(refla,refla)(e,reflrefla). Splitting e compares refla with itself. Injectivity would accept that comparison if it inspected only the constructor heads, and the clause would prove that every loop at refla is reflexivity. The self-unifiability test first asks the restricted unifier to solve the index problem a=a; deletion is unavailable, so the problem is stuck and the clause is rejected. Thus each restriction blocks a separate route to K.

Definition 78.10 — Basic analysis and recursive hypotheses

Fix D:ΞUi. Abbreviate Rk,r:=Φk,rD(vk,r). Its constructors have the homogeneous telescopic form ck:(t:Δk)(x1:Rk,1)(xnk:Rk,nk)D(uk). For P:(u:Ξ)D(u)Uj, basic case analysis has type Bk(P):=(t:Δk)(x1:Rk,1)(xnk:Rk,nk)P(uk,cktx1xnk). The operation is caseD:(kBk(P))u:Ξx:D(u)P(u,x). It computes by selecting bk(t,x1,,xnk) on the kth constructor. The absent arguments are the recursive hypotheses of the full eliminator.

Define BelowD(P,u,x) by the dependent eliminator with universe-valued motive. Its kth constructor equation is the telescope product r=1nkϕ:Φk,rBelowD(P,vk,r,xrϕ)×P(vk,r,xrϕ). Thus nullary constructors produce 1, and a recursive function argument contributes one pair at each ϕ:Φk,r. Put D^:=u:ΞD(u),BelowD(P,(u;x)):=BelowD(P,u,x). The two-argument form is used only when its second argument is visibly a point of D^; otherwise all three arguments are printed. Put StepD(P):=u:Ξx:D(u)BelowD(P,u,x)P(u,x). Given p:StepD(P), the helper belowD(P,p):u:Ξx:D(u)BelowD(P,u,x) is defined by the full eliminator. At recursive argument xr with induction hypothesis hr, its tuple component is λϕ.(hr(ϕ),p(vk,r,xrϕ,hr(ϕ))). The associated recursor is recD:StepD(P)u:Ξx:D(u)P(u,x). We print the motive P as an explicit bookkeeping parameter, so an application has the form recD(P,p,u,x). It is defined by recD(P,p,u,x):=p(u,x,belowD(P,p,u,x)). All displayed constructor equations are judgmental.

Definition 78.11 — No confusion for an indexed family

Let a,b:D^. Define NoConfusionD by two applications of basic case analysis. For equal constructor tags it is the homogeneous telescopic equality of all constructor arguments; for distinct tags it is 0. Telescopic identity elimination and basic case analysis give noConfD(a,b):aΞ;DbNoConfusionD(a,b),noConfD1(a,b):NoConfusionD(a,b)aΞ;Db. On the diagonal, the first map returns reflexivity; the inverse transports the argument telescope through the constructor-and-index map and returns reflexivity.

Lemma 78.12 — No-confusion retraction

For a,b:D^ and e:aΞ;Db, noConfD1(a,b,noConfD(a,b,e))=e;

Proof of Lemma 78.12 — No-confusion retraction

Proof. Apply JΞ;D to e. Its reflexivity case computes by basic case analysis to reflexivity, which proves the displayed identity without equating arbitrary identity proofs. ◻

Definition 78.13 — Below complements

The acyclicity argument needs a second family elimination; constructor disjointness alone does not supply it. Retain D^:=u:ΞD(u) and write a bold argument a=(u;a):D^ for an index together with an inhabitant. Define aDb:=BelowD(λb.aΞ;Db0,b),notBelowEqD(a,b):=(aDb)×(aΞ;Db0).

Lemma 78.14 — Acyclicity of recursive descent

For a,b:D^ there is a term noCycleD:(a,b:D^)aΞ;DbaDb.

Proof of Lemma 78.14 — Acyclicity of recursive descent

Proof. Telescopic identity elimination reduces it to (a:D^)aDa. In the ci method of the first family eliminator, fix a recursive child xjϕ and define the complete child xj,ϕ:=(vi,j;xjϕ):D^. Define the auxiliary family Stepi,j(t,x,ϕ,b):=(xj,ϕDb)notBelowEqD((ui;citx),b). The second family eliminator, now on b, constructs stepi,j:(t,x,ϕ,b)Stepi,j(t,x,ϕ,b). To display its method, let b=(up;cptx), let hqϕ be the second eliminator’s hypothesis for the complete child xq,ϕ:=(vp,q;xqϕ), and assume H:xj,ϕD(up;cptx). Unfolding H gives, for every q,ϕ, the component Hq(ϕ):notBelowEqD(xj,ϕ,xq,ϕ). The method returns (α,β), where α:(ui;citx)D(up;cptx),αq(ϕ):=hq(ϕ)(pr1(Hqϕ)),β:(ui;citx)Ξ;D(up;cptx)0. For β, suppose e is such an equality. If ip, noConfD(e):0. If i=p, no confusion exposes the homogeneous equality of the argument telescopes. Its jth recursive component transports Hjϕ to notBelowEqD(xj,ϕ,xj,ϕ); the second projection applied to refl is in 0. These are the two components of the source construction: the parent is not below the descendant, and the parent is not the descendant.

Finally the ci method of the first eliminator is λt.x.h.(λϕ.stepi,1(t,x,ϕ,x1,ϕ,h1ϕ),,λϕ.stepi,ni(t,x,ϕ,xni,ϕ,hniϕ)). It has exactly the telescope product required by BelowD. The first eliminator computes to this tuple, and J computes at reflexivity. Thus the resulting noCycleD is obtained from two ordinary eliminations and J; it assumes neither K nor judgmental constructor injectivity. ◻

Definition 78.15 — Valid case tree

A case tree for f:(t:Δ)T is a finite tree. A leaf contains a body of its specialized type. A split selects x:D(u) and has the branches obtained by restricted unification with constructor result indices; negative branches have no subtree. A recursive leaf may call f only on a proper recursive field of one fixed datatype argument. The tree is valid when every split has only positive or negative solutions, all specialized leaves typecheck, constructor branches cover the selected family, and calls have the stated structural decrease. The translation uses caseD, BelowD, recD, no confusion, and acyclicity from definition 78.10, definition 78.11, lemma 78.14.

Lemma 78.16 — Proof-relevant specialization

Let a positive restricted solution of uΞv in Δ be represented by a telescope map σ:ΔΔ. For every T:(t:Δ)u(t)Ξv(t)Uj and m:(z:Δ)T(σz,refl) there is s:(t:Δ)(e:u(t)Ξv(t))T(t,e) such that s(σz,refl)m(z). A negative solution yields a term of the same target for arbitrary T.

Proof of Lemma 78.16 — Proof-relevant specialization

Proof. The internal transition terms must retain the proof argument. For a constructor c whose result indices have already self-unified, injectivity uses the term injectivityc:(Φ:(e:(u;cs)Ξ;D(u;ct))Uj)((q:sΔct)Φ(noConfD1(u;cs,u;ct,q)))(e:IdD(u)(cs,ct))Φ(reflu;e). It applies noConfD and then the supplied method. Its reflexivity calculation uses noConfD1noConfD=id, so it preserves the actual equality proof. The conflict transition and cycle transition both retain the proof parameter: conflict and cycle have targets (e:aΞ;Db)Φ(e): the former eliminates noConfD(e):0, and the latter eliminates noCycleD(a,b,e) at the offending descendant. These are proof-dependent transition terms, not conversions of equalities to mere constraints.

A solution step, possibly after a dependency-preserving permutation of its telescope, is J with the solved variable generalized. Its reflexivity branch is m. There is no deletion step. Inductively a positive run therefore has telescopes Δ0=Δ,,Δn=Δ and maps τr:ΔrΔr1 with σ=τ1τn. Only solution/permutation and injectivity occur on such a run. Write (J) for the reflexivity equation of J and (N) for the no-confusion retraction of lemma 78.12. If sr is its rth internal transition term, then s(σz,refl)=s1(s2(sn(m)))(τ1(τnz),refl)(J),(N)s2(sn(m))(τ2(τnz),refl)(J),(N)(J),(N)m(z). This proves (78.4) without proof irrelevance. ◻

Lemma 78.17 — One case-tree split is eliminable

Suppose a valid node in context Θ splits x:D(u) and has goal T. If every positive constructor branch has an eliminator-only term at its exact specialized type, then the node has an eliminator-only term of type T. On xcky, it reduces to the kth branch specialized by that branch’s telescope map.

Proof of Lemma 78.17 — One case-tree split is eliminable

Proof. Use basic case analysis with the proof-dependent motive Q(w,z):=(t:Θ)(u(t);x(t))Ξ;D(w;z)T(t). The ck branch has target (t:Θ)(u(t);x(t))Ξ;D(vk(y);cky)T(t). For a positive unifier this is the specializer target in lemma 78.16; insert the translated subtree as m. For a negative unifier, insert its empty eliminator. Apply the resulting caseD term to (u;x) and refl(u;x). On cky, the basic-case equation and then (78.4) contract to the specialized kth subtree. Replacing (78.7) by a motive that forgets the equality proof would silently assume proof irrelevance. ◻

Definition 78.18 — Root contraction of a case tree

Let C be a valid case tree for f:(t:Δ)T. The predicate CTC(t,u) holds if and only if there are a leaf fpi=ei of C and a well-typed substitution θ for its pattern variables such that the following three conditions hold.

  1. tTpattm(pi)[θ];

  2. starting at the root, constructor selection and the positive restricted unifier at each split follow the unique path to that leaf;

  3. u is the literal instance ei[θ], with recursive occurrences of f left unchanged.

This predicate defines root contraction only. Compatible closure, when needed, is the ordinary compatible closure of these contractions.

Theorem 78.19 — Elimination of valid dependent case trees

Work in intensional dependent type theory with homogeneous identity types but without K. If f:(t:Δ)T is given by a valid case tree C obeying definition 78.9, there is an eliminator-only f:(t:Δ)T. Write e[f/f] for replacement of recursive occurrences. If CTC(t,u), then ftu[f/f].

Proof of Theorem 78.19 — Elimination of valid dependent case trees

Proof. Let tj:D(v) be the designated structural argument. On a complete family argument x use the motive P(x):=(t:Δ)xΞ;D(v(t);tj(t))T(t). Suppose for the moment that m:(t:Δ)BelowD(P,v(t),tj(t))T(t). Its recursor step is the proof-dependent wrapper ms(x,H,t,e):=JΞ;D(λy.e.BelowD(P,y)T(t))(mt,(v(t);tj(t)),x,symΞ;D(e),H). Consequently ms((v;tj),H,t,refl)mtH. Define f(t):=recD(P,ms,v(t),tj(t))(t,refl). Write (R) for the defining equation of recD and (J) for the reflexivity equation of J. The head calculation is f(t)(R)ms((v;tj),belowD(P,ms,v,tj),t,refl)(J)mtbelowD(P,ms,v,tj).

It remains to construct m, by induction on the case tree. At a node whose patterns have variables Θ and induce τ:ΘΔ, retain the strengthened target mτ:(z:Θ)BelowD(P,(v;tj)(τz))T(τz). Suppose the node splits Θ=Θ1,(y:D(vy)),Θ2. For a constructor c:(s:Δc)D(uc), basic case analysis requires the method mc:(s:Δc)(z:Θ)(uc(s);cs)Ξ;D(vy(z);y(z))BelowD(P,(v;tj)(τz))T(τz). This is the proof-dependent target to which the transition terms above apply. A negative unification run supplies it by conflict or cycle. A positive run has a most general unifier (MGU) σ:ΘΔc;Θ. Write σΘ:=prΘσ for its projection to the original node variables. The subtree induction hypothesis is mc:(z:Θ)BelowD(P,(v;tj)(τσΘz))T(τσΘz). The specializer of lemma 78.16, instantiated with the remaining BelowD argument in its motive, turns mc into (78.13).

The computation is not hidden in an MGU assertion. When the selected value is cs, the equations are satisfied, so the syntactic first-order MGU computes z:Θ with the literal substitution identity σz(s;z1;cs;z2), where (z1,cs,z2) has the original valid telescope order. The factorization may permute independent declarations while finding z, but that permutation is reflected in the displayed literal identity and drops no dependent declaration. Write (B) for basic-case computation, (M) for this literal identity, and (S) for (78.4). Then mτ(z1;cs;z2,H)(B)mc(s,z1;cs;z2,refl,H)(M)mc(σz,refl,H)(S)mc(z,H). The last reduction is (78.6). This is why the factorization must preserve the telescope dependencies, not merely pass an occurs check. An empty node has only negative methods and no subtree.

At a leaf with body ei:Tτ, replace each structurally recursive call fr by the projection supplied by H. If rj is the named proper recursive child, that projection has type πH:(r:Δ)(w;rj)Ξ;D(v;tj)T(r). On the canonical below-package it calculates, using (R) and (J), πbelowD(P,ms,v,tj)(r,refl)(R)ms((w;rj),belowD(P,ms,w,rj),r,refl)(J)mrbelowD(P,ms,w,rj)(78.10)f(r). Thus the translated leaf ei is judgmentally equal to ei[f/f] when its H argument is canonical.

For a source clause fpi=ei, combine (78.11), the node calculations (78.15), and (78.16): Write (H) for (78.11), (N) for (78.15), and (L) for (78.16). Then f(Tpattm(pi))(H)mTpattm(pi)(belowD(P,ms,Tpattm(v;pi,j)))(N)ei[HbelowD(P,ms,Tpattm(v;pi,j))](L)ei[f/f]. By definition 78.18, every CTC(t,u) selects one such leaf and substitution. Substitution into the displayed calculation gives ftu[f/f]. No transition deletes a reflexive equation, and every use of equality is through its proof-dependent motive, so K is absent. ◻

This is a source-bounded reconstruction of Cockx–Devriese–Piessens, Theorem 1 [CDP16]. It retains the theorem’s homogeneous telescopic equality, dependency-preserving unifier factorization, proof-dependent internal transitions, basic case analysis, and BelowD recursion; only notation is normalized to the book. The specialization proof has no deletion case, and its injectivity case begins with the index self-unifier.

Example 78.20 — The identity family

Fix a:A. The single clause J(P,p,.a,refl)=p has input b:A,e:IdA(a,b). Splitting on e generates b=a. Solution replaces b by a without deleting a reflexive equation. The translated term is based identity induction, and on refl both the case clause and the translated J term reduce to p. If the input instead fixes e:IdA(a,a), the generated problem is a=a; restricted unification is stuck, so the K case tree is invalid.

Two larger indexed signatures

The eliminator discipline scales beyond a family whose constructors merely fix an index. It does not license theorem transfer from one larger signature mechanism to another. This section freezes two bounded rule cards: inductive–recursive signatures, where a datatype and a decoding function are generated together, and induction–induction, where a type and a family over it are generated together. We calculate their rules and stop there.

Inductive–recursive and indexed inductive–recursive signatures. Fix O:Uj. The selected IR signature codes are generated by ι(o),σ(A,S),δ(A,S), where o:O, A:Ui, S:ASigi(O) in the σ case, and S:(AO)Sigi(O) in the δ case. Given R:Ui and e:RO, define the constructor fields ES(R,e) and decoded output FS by Eι(o)(R,e):=1,Fι(o)():=o,Eσ(A,S)(R,e):=a:AES(a)(R,e),Fσ(A,S)(a,x):=FS(a)(x),Eδ(A,S)(R,e):=f:ARES(ef)(R,e),Fδ(A,S)(f,x):=FS(ef)(x). The generated type and decoder have the rules IR(S):Ui,El:IR(S)O,intro:ES(IR(S),El)IR(S), with recursive decoding equation El(intro(x))FS(x). For P:IR(S)Uk, let IHS(P,x) contain one P(f(a)) for every recursive field f:AIR(S) in a δ node and recurse through the residual signature. Then elimIR:(P:IR(S)Uk)((x:ES(IR(S),El))IHS(P,x)P(intro(x)))(z:IR(S))P(z), and elimIR(P,m,intro(x))m(x,mapIHS(elimIR(P,m),x)). A δ field is genuinely recursive: its decoded function Elf selects the continuation signature, and the method receives the recursively computed values for every f(a).

For indexed IR, fix I:Uk and O:IUj. A δ code now also carries ix:AI and continuation S:((a:A)O(ix(a)))Sigi(I,O). The generated objects are IIR(S):IUmax(i,k),El:IIR(S)(u)O(u),intro:ES(IIR(S),El,u)IIR(S)(u), again with El(intro(x))FS(x). For the vector signature, the cons branch chooses n:N, stores a:A, takes one recursive field at index n, and returns index suc(n). Its derived constructor and recursive-decoding calculation are cons:(n:N)AIIR(S)(n)IIR(S)(suc(n)),El(cons(n,a,as))FScons(n,a,as). The indexed eliminator has motives P:(u:I)IIR(S)(u)Ul; its cons computation passes the induction hypothesis P(n,as) to the cons method. These are precisely the formation, introduction, recursive-decoding, elimination, and computation rules used here from Kovács’s signatures [Kov26]. His canonicity construction is not imported.

A context/type induction–induction card. The small simultaneous signature has Con:U,Ty:ConU,ϵ:Con,ext:(Γ:Con)Ty(Γ)Con,U:(Γ:Con)Ty(Γ),El:(Γ:Con)Ty(ext(Γ,U(Γ))). Its dependent eliminator requires two motives, because the motive for types is indexed by the already computed context result: C:(Γ:Con)U,T:(Γ:Con)C(Γ)Ty(Γ)U. The four methods are e:C(ϵ),x:(c:C(Γ))T(Γ,c,A)C(ext(Γ,A)),u:(c:C(Γ))T(Γ,c,U(Γ)),q:(c:C(Γ))T(ext(Γ,U(Γ)),x(c,u(c)),El(Γ)). They produce simultaneous eliminators elimCon(Γ):C(Γ),elimTy(A):T(Γ,elimCon(Γ),A), with computations elimCon(ϵ)e,elimCon(ext(Γ,A))x(elimCon(Γ),elimTy(A)),elimTy(U(Γ))u(elimCon(Γ)),elimTy(El(Γ))q(elimCon(Γ)). The final equation is well typed because the C-result for the extended context computes by the preceding equation. This is the bounded context/type example of Lafont, Kaposi, and Kovács [KKL20]. We claim neither their reduction to ordinary induction nor initiality, extensional reduction, gluing, quotient, or path constructors.

Exercise 78.2

★★☆ Expand one δ case in the IR eliminator. Show where Elf selects the continuation signature, and calculate the induction-hypothesis component for one chosen a:A.

Exercise 78.3

★★☆ Type the method q in the context/type card. Use the computation for elimCon(ext(Γ,U(Γ))) to verify the classifier of the last displayed equation.

Exercise 78.4

★★☆ Run definition 78.9 on the two problems x=suc(y) and suc(x)=suc(x). Give the transition sequence for the first and identify the exact point at which the second fails. Explain why adding deletion would admit the second problem.

Exercise 78.5

★★☆ Construct last:n:NVec(A,suc(n))A from Vec-elim. State its value on a one-element vector and on a vector whose tail is nonempty, and justify both equations from Vec-comp.

Exercise 78.6

★★☆ Give constructor clauses for last from exercise 78.5. Build their valid case tree, including the dot pattern forced by the successor index, and apply theorem 78.19. Display the eliminator-only term and verify its one-element and nonempty-tail equations from definition 78.18. (Half a page.)

Suggested first pass.

Begin with exercise 78.7.

Exercise 78.7

★★☆ Reconstruct the eliminator term for append from construction 78.7. Prove by vector elimination that appending vnil on the right yields the input after the required transport. More precisely, first construct lm:IdN(0+m,m) by natural-number induction, and then construct trlmk.Vec(A,k)(append(xs,vnil))=xs(xs:Vec(A,m)). State why the equality is not judgmental for a neutral vector.

Exercise 78.8 — Executable dependent DSL

★★★ Practical project.indexed-format-parser Implement in Kappa a format-indexed parser for fixed-width unsigned decimal fields. A format contains field widths as an indexed vector; a typed intermediate form pairs each parsed field with evidence that its digit count is the constructor-determined width. Maintain this index invariant through parsing and printing. On the format [2,1,3], the program must parse 427105 as [42,7,105] and print the same six-character string. It must reject 42715 before constructing the typed intermediate form, naming the final field’s expected width 3 and actual width 2. The acceptance test compares these exact success and rejection results.

Sources. The no-K case-tree criterion, its two restricted-unification conditions, and the eliminator translation follow Cockx, Devriese, and Piessens, Eliminating Dependent Pattern Matching without K, Theorem 1 and Section 3.1 [CDP16]. The chapter has restated the theorem at its case-tree signature and proved the identity-family witness locally; it has not assumed Agda’s K axiom or a completeness theorem for unrestricted dependent unification. The IR/IIR rule card is restricted to the signature, introduction, decoding, elimination, and computation rules on pp. 4–8 of Kovács [Kov26]; its canonicity theorem is outside this chapter. The context/type induction–induction card reproduces the signature and general eliminator calculation on pp. 2–3 of Lafont, Kaposi, and Kovács [KKL20]; their reduction and uniqueness results are likewise not transferred.

Search the book

Type to search the local edition.