Lectures onType Theory
ch:indexed-inductive-families: ch:indexed-inductive-families
appendix sectionsolutions

ch:indexed-inductive-families: ch:indexed-inductive-families

Exercise 78.1.

Induct on xs. The empty branch has k:Finind(0) and closes by empty elimination. In a successor branch xs=vcons(n,a,as), eliminate k. For k=fz(n), both sides compute to f(a), so use reflexivity. For k=fs(n,l), the calculation is lookup(map(f,vcons(n,a,as)),fs(n,l))lookup(map(f,as),l)=f(lookup(as,l)). The first step is the two constructor computations; the second is the propositional induction hypothesis at l. It is not a judgmental map–lookup equation for a neutral tail.

Exercise 78.2.

At a δ(A,S) node the constructor field is a pair (f,x) with f:AIR(S0) and x:ES(Elf)(IR(S0),El). Thus the continuation is selected by the decoded recursive field Elf, not by f alone. The δ clause of mapIH is mapIHδ(A,S)(g,(f,x))=((λa.g(f(a))),mapIHS(Elf)(g,x)). At a chosen a:A its first component computes to g(f(a)); for g=elimIR(P,m) this has type P(f(a)), exactly the recursive hypothesis consumed by the method.

Exercise 78.3.

The method has type q:(c:C(Γ))T(ext(Γ,U(Γ)),x(c,u(c)),El(Γ)). Instantiate c with elimCon(Γ). The target demanded by elimTy(El(Γ)) has context-result index elimCon(ext(Γ,U(Γ))). The preceding computation rule rewrites this judgmentally to x(elimCon(Γ),elimTy(U(Γ))), and the U computation rewrites the second argument to u(elimCon(Γ)). The resulting classifier is precisely the displayed type of q(elimCon(Γ)).

Exercise 78.4.

The solution transition applies to x=suc(y) because xFV(suc(y)); it records [suc(y)/x] and leaves the empty equation list. For suc(x)=suc(x), constructor injectivity first passes the vacuous index self-unification check for N and produces x=x. No solution transition applies because its occurs side condition fails, and deletion is absent, so the problem is stuck. Adding deletion would remove x=x and report a positive solution, which is the forbidden step.

Exercise 78.5.

Put L(n):=Vec(A,suc(n))A. Natural-number induction defines last0(ys):=head(ys),lastsuc(n)(ys):=lastn(tail(ys)). The operations head and tail are the Vec-elim terms of construction 78.2, so this construction uses no pattern principle. Their computation rules give last0(vcons(0,a,vnil))a,lastsuc(n)(vcons(suc(n),a,xs))lastn(xs). The first equation uses head computation; the second uses tail computation before the induction equation.

Exercise 78.6.

The constructor clauses are last0(vcons(0,a,vnil))=a,lastsuc(n)(vcons(suc(n),a,vcons(n,b,xs)))=lastn(vcons(n,b,xs)). The case tree first splits the vector at index suc(n). Its only root is vcons(.n,a,ys), where the dot records the index equation forced by the scrutinee. It then splits n. At zero, ys can only be vnil; at successor, its only root is vcons(.n,b,xs). Neither split deletes a reflexive equation. The tree therefore satisfies definition 78.9.

The translation of theorem 78.19 is the eliminator-only definition last0(ys):=head(ys),lastsuc(n)(ys):=lastn(tail(ys)), where head and tail are the Vec-elim terms of construction 78.2. On the first leaf, head computation gives a. On the second, tail computation exposes the successor vector. The natural-number computation rule then gives the displayed recursive call. These are exactly the two leaf calculations of definition 78.18.

Exercise 78.7.

With ys:Vec(A,n) fixed, use motive P(m,xs):=Vec(A,n+m), branch ys, and successor branch m.a.xs.q.vcons(n+m,a,q). This is the eliminator term for append; addition recurses on its second argument, so both constructor branches have the displayed types judgmentally.

For right identity, first prove lm:0+m=m by natural-number induction, with l0:=refl and lsuc(m):=ap(suc,lm). Vector elimination on xs proves transportk.Vec(A,k)(lm,append(xs,vnil))=xs. The empty case is reflexivity. The successor branch uses the transport lemma transportk.Vec(A,k)(ap(suc,r),vcons(p,a,q))=vcons(p,a,transportk.Vec(A,k)(r,q)), for r:p=p, proved by identity induction on r. Congruence of vcons with the vector induction hypothesis closes that branch. For a neutral xs, the eliminator does not contract, so append(xs,vnil)xs is not judgmental.

Search the book

Type to search the local edition.