Lectures onType Theory
ch:datatype-descriptions: ch:datatype-descriptions
appendix sectionsolutions

ch:datatype-descriptions: ch:datatype-descriptions

Exercise 80.1.

Interpretation gives [[DVec(A)(0)]](X)1,[[DVec(A)(suc(n))]](X)A×X(n). Hence the two roll maps have types roll0:1Mu(D)(0),rollsuc(n):A×Mu(D)(n)Mu(D)(suc(n)). They are the curried vector constructors after Unit introduction and product currying. For P(n,xs):=N, the zero method ignores its layer and its unit All witness and returns 0. At successor index, write the layer as (a,xs) and its All witness as (,k), where k:N is the result for xs. The successor method returns suc(k). Thus description induction computes the element count, or length, which agrees with the vector index. The generic constructor-node size of construction 80.12 would instead return suc(n).

Exercise 80.3.

For the cons branch, f:NN is successor. At output m, the Σf clause interprets as n:NIdN(suc(n),m)×(A×Mu(D)(n)). A witness contributes only together with p:suc(n)=m. At m=suc(k), successor injectivity converts p to n=k; transport reduces the payload to A×Mu(D)(k). Conversely n=k with reflexivity constructs that branch. Thus the fiber is equivalent to the regular normal form K(A)×X(k), while the principal code still records the result-index equation explicitly.

Exercise 80.2.

For f:AB, take carrier List(B) and algebra α(inl()):=nil,α(inr((a,ys))):=cons(f(a),ys). Equation (80.2) gives the usual nil and cons map equations. For identity, induct on xs. At nil, the fold equation gives map(id,nil)=nil. At cons, map(id,cons(a,xs))=cons(a,map(id,xs))=cons(a,xs), where constructor congruence uses the induction hypothesis. Fold fusion with h=id alone would only compare the same map fold with itself.

Exercise 80.4.

Add pi(A,E):Desci(I) for A:Ui and E:ADesci(I), with [[pi(A,E)]](X):=a:A[[E(a)]](X). Every recursive occurrence remains in a codomain, hence positive. The code lies in Ui+1 and its interpretation in Ui. Traversal needs an operation (a:AG(B(a)))G(a:AB(a)) for the applicative G:UiUi and every B:AUi; an ordinary applicative does not provide it for infinite A. Decidable equality requires finite enumerability of A, decidable equality in every codomain, and function extensionality to turn pointwise equality into function equality.

Exercise 80.5.

For t:Tm(B::Γ,C), the left side computes to lam(ren(lift[B](ρ),sub(lift[B](σ),t))). The induction hypothesis turns its body into substitution by rpost(lift[B](ρ),lift[B](σ)). The right side computes to substitution by lift[B](rpost(ρ,σ)). On the newest variable, both environments return var(vz). On an older variable vs(x), both return the weakening of ren(ρ,σ(x)); renaming composition proves the equality for the first expression. Environment congruence identifies the bodies, and congruence of lam closes the case. No equality between environment functions is used.

Exercise 80.6.

The mirror algebra fixes a leaf and exchanges the two recursively folded children at a fork. The counting algebra sends a leaf to 1 and a fork layer (m,n) to 1+m+n. In the leaf summand the fusion premise is 1=1. In the fork summand it is 1+m+n=1+n+m, by commutativity of natural-number addition. Fold fusion therefore gives size(mirror(t))=size(t) for every tree t.

Exercise 80.7.

At con(u), the left side of renaming after substitution expands to a constructor whose recursive-position map is renF(liftΞ(ρ),subF(liftΞ(σ),x)). The free-syntax induction hypothesis identifies this term with substitution by rpost(liftΞ(ρ),liftΞ(σ)). The lift lemma identifies that environment pointwise with liftΞ(rpost(ρ,σ)). Layer-action congruence applies these paths at every rec(Ξ,B) position of u, and constructor congruence closes the case. For lam(t) the code stores Ξ=[B], so the sole premise is exactly the body equation with both environments lifted through the new variable of type B.

Exercise 80.8.

The Sigma clause first compares the tags false and true. Boolean equality returns their disequality, so the procedure rejects before inspecting , l, or r. If equality data omit the decision procedure for 2, the algorithm cannot execute this first tag comparison. In particular it cannot obtain either a disequality for immediate rejection or a path p:b=b along which to transport the second payload into the branch code F(b).

Search the book

Type to search the local edition.