Lectures onType Theory
ch:extensional: ch:extensional
appendix sectionsolutions

ch:extensional: ch:extensional

exercise 35.4.

Both operations ignore their proof arguments: sym:=λp.refl,trans:=λp.λq.refl. In the first context, Eq-Reflect applied to p gives ab:A, so refl:EqA(a,a) converts to an element of EqA(b,a). In the second, reflection applied to p,q and transitivity give ac:A, so refl converts to the required type. Every application β-reduces judgmentally to refl; the rule Eq-Uniq gives the same conclusion for any extensionally equal implementation.

exercise 35.7.

Define happly:=λp.λx.refl. Reflection sends p:Eqx:AB(f,g) to fg; application congruence then gives f(x)g(x), so the displayed refl converts to the required pointwise equality.

Now funext(h):=refl. Hence happly(funext(h))λx.refl, while Eq-Uniq gives h(x)refl for every x. Congruence and Π-η yield hλx.refl. Conversely, funext(happly(p))reflp, the last equality again being Eq-Uniq. Abstracting these equations shows that both composites are judgmentally the corresponding identity functions.

exercise 90.19.

For the K step, the typed encoding supplies an extensional equality term eKxy:EqX(Kxy,x) in ΓSK. The two applications of eK check the endpoints at X; Eq-Reflect then concludes Kxyx. Thus the derivation has two separable stages: construct and check the extensional equality evidence, then reflect it. Erasing that evidence leaves no procedure for finding a witness among arbitrary conversion goals; equality reflection checks supplied evidence but does not decide its existence.

Exercise 35.1.

Let Θ:=(A type;a:A;b:A) be the parameter telescope of the raw former Eq(A,a,b). Two substitutions from Γ into Θ are precisely triples σ=(A,a,b),σ=(A,a,b), and an equality σσ:Θ consists, from left to right, of ΓAA type,Γaa:A,Γbb:A. The classified congruence scheme for the type-valued operator ΘEqA(a,b) type therefore has the instance ΓAA typeΓaa:AΓbb:AΓEqA(a,b)EqA(a,b) typeEqFeq. The fact that the third component is compared in the fiber over the unprimed A is exactly the left-to-right convention for equality of classified substitutions; context conversion places the primed component in that same fiber.

Now suppose Γab:A. Rule Eq-I gives Γrefl:EqA(a,a). Apply the displayed congruence rule to AA, aa, and ab. It yields ΓEqA(a,a)EqA(a,b) type, so Conv concludes Γrefl:EqA(a,b).

Exercise 35.2.

The additional eliminator has the same shape as primitive identity elimination:

Γ,x:A,y:A,q:EqA(x,y)C typeΓ,z:Ac:C[z/x,z/y,refl/q]Γp:EqA(a,b)
ΓJ(x.y.q.C;z.c;p):C[a/x,b/y,p/q]
Eq-J

and its computation rule is J(x.y.q.C;z.c;refla)c[a/z]:C[a/x,a/y,refla/q]. No uniqueness rule is assumed.

In the generic eliminator context, reflection applied to the variable q:EqA(x,y) gives xy:A. Hence reflx:EqA(x,x) converts to an element of EqA(x,y), and the family C(x,y,q):=EqEqA(x,y)(q,reflx) is well formed. Its diagonal fiber is C(z,z,reflz)EqEqA(z,z)(reflz,reflz), which has the branch reflreflz. Thus Eq-J constructs r(p):=J(x.y.q.EqEqA(x,y)(q,reflx);z.reflreflz;p):EqEqA(a,b)(p,refla). Finally apply Eq-Reflect to r(p). Its conclusion is exactly Γprefla:EqA(a,b), where the classifier of refla has already been converted along the endpoint equality reflected from p. This is Eq-Uniq. The argument used only formation, introduction, reflection, and the stated J-eliminator.

Exercise 35.3.

Work in the extended context Γ,u:B[a/x]. Weakening preserves p:EqA(a,b), so reflection gives ab:A there. Equal substitution into the family B gives Γ,u:B[a/x]B[a/x]B[b/x] type. Consequently the variable u:B[a/x] converts to an element of B[b/x], and Π-introduction discharges it:

Γ,u:B[a/x]u:B[a/x]
Var
Γ,u:B[a/x]p:EqA(a,b)
Γ,u:B[a/x]ab:A
Eq-Reflect
Γ,u:B[a/x],x:AB type
Γ,u:B[a/x]B[a/x]B[b/x] type
Subst-Eq-Ty
Γ,u:B[a/x]u:B[b/x]
Conv
Γλu.u:B[a/x]B[b/x]
Π-I

The occurrences of the family and of p in the tree are obtained by weakening and exchange; these structural steps are suppressed exactly as in the book’s compressed rule convention.

Exercise 35.5.

Fix a:A and p:EqA(a,a), and put D(x,q):=EqEqA(x,x)(q,reflx). At reflexivity the diagonal fiber is D(x,reflx)=EqEqA(x,x)(reflx,reflx), with canonical inhabitant d(x):=reflreflx. The derived K-operator of theorem 35.9(3) therefore gives kp:=K(x.q.D;x.d;a,p):D(a,p)=EqEqA(a,a)(p,refla). By its definition in that theorem, kpd(a)reflrefla; the classifier is changed from D(a,refla) to D(a,p) using Eq-Uniq on p.

There is also the direct construction. Rule Eq-Uniq gives prefla:EqA(a,a); hence Eq-I followed by conversion gives dp:=reflp:EqEqA(a,a)(p,refla)=D(a,p). The annotation on the printed reflexivity term is immaterial after the conversion: both kp and dp are judgmentally equal to the unique reflexivity inhabitant of D(a,p). Thus Γkpdp:D(a,p). Applying theorem 35.7(1) at the ambient type D(a,p) internalizes this comparison: Γrefl:EqD(a,p)(kp,dp). So the K-construction and the direct uniqueness construction agree both judgmentally and internally.

Exercise 35.6.

Let p:IdA(a,b), q:IdA(b,c), and u:B(a). By proposition 35.10, after the corresponding endpoint conversions, prefla,qrefla. Congruence therefore reduces the left-hand side of the transport law as follows: trpqB(u)trreflreflB(u)trreflB(u)by the J-computation rule defining compositionuby the J-computation rule defining transport. The right-hand side has the parallel calculation trqB(trpB(u))trreflB(trreflB(u))trreflB(u)u, where the last two lines are the inner and outer instances of the transport computation rule. Transitivity gives the displayed law.

For inverse and composition, the same replacement gives (pq)1(reflrefl)1refl1refl,q1p1refl1refl1reflreflrefl. Here reflreflrefl is the computation rule for path composition and refl1refl is the computation rule for inverse. Both sides are consequently judgmentally the same reflexivity term.

Exercise 35.8.

Suppose first that A is a proposition. Every fiber B(x) is a proposition by hypothesis, so x:AB is a proposition by lemma 35.15(4).

Conversely, assume S:=x:AB is a proposition. In the generic context Γ,x:A,y:A, the section gives (x,s(x)):S,(y,s(y)):S. Proposition-hood of S yields (x,s(x))(y,s(y)):S. Apply congruence of the first projection and then the two Σ-beta rules: xpr1((x,s(x)))pr1((y,s(y)))y:A. This is precisely the generic judgment asserting that A is a proposition. The section is essential for this direction: it embeds every x:A into the dependent sum.

Exercise 35.9.

If N were a proposition, substitution into its generic equality would give 0suc(0):N. In the set interpretation of proposition 35.4, these terms denote 0 and 1, respectively. Soundness would force 0=1, a contradiction. Hence N is not a proposition.

More generally, let A be closed and let a:A be closed. If A+A were a proposition, then its two closed inhabitants would be judgmentally equal: inl(a)inr(a):A+A. The set interpretation of a coproduct is a tagged disjoint union. The first term denotes the left-tagged element (0,[[a]]), while the second denotes the right-tagged element (1,[[a]]); these are unequal regardless of the value of [[a]]. Soundness rules out the displayed judgment, so A+A is not a proposition.

Exercise 35.10.

Write ηA:=λa.|a|:AA. Assume first that A is a proposition. Since Tr-E permits elimination into propositions, define rA:=λt.recA(a.a,t):AA. For every a:A, both rA(ηA(a)) and a inhabit the proposition A, hence rA(ηA(a))a. Lambda congruence and Π-eta give rAηAλa.a. Likewise, for every t:A, the terms ηA(rA(t)) and t inhabit the proposition A, so ηArAλt.t. Thus the retraction is automatically a judgmental two-sided inverse; no computation rule for truncation is needed.

Conversely, suppose there is r:AA with rηAλa.a. In context x:A,y:A, rule Tr-Uniq gives ηA(x)ηA(y). Application congruence and the retraction equation then give xr(ηA(x))r(ηA(y))y:A. Therefore A is a proposition.

Finally A is always a proposition. Applying the first part to it gives the judgmental isomorphism ηA:AA,μA:=λT.recA(t.t,T):AA, with both composites judgmentally equal to the corresponding identity functions.

Exercise 35.11.

For f:AB, define f:=λt.recA(x.|f(x)|,t):AB. The branch has type B, and this target is a proposition by Tr-Uniq, so Tr-E applies.

For every t:A, the terms (λx.x)(t) and t are two inhabitants of A. Proposition-hood gives their judgmental equality; lambda congruence followed by eta therefore gives λx.xλt.t. Now let f:AB and g:BC. For each t:A, both (gf)(t)and(g)((f)(t)) inhabit the proposition C. Hence they are judgmentally equal, and extensional congruence for lambdas plus eta yields gf(g)(f). These functor laws use only uniqueness of inhabitants of the codomain truncations, not a primitive beta rule for Tr-E.

Exercise 35.12.

Recall AB:=A+B. Define the symmetry map by swapA,B(t):=recA+B(z.ind+(a.|inr(a)|,b.|inl(b)|,z),t). Its codomain is BA=B+A, hence a proposition, so the truncation elimination is valid. The reverse is swapB,A. Both composites are endomaps of a proposition; therefore, pointwise by Tr-Uniq and then by lambda congruence and eta, swapB,AswapA,BidAB,swapA,BswapB,AidBA.

For associativity abbreviate L:=(AB)C=A+B+C,R:=A(BC)=A+B+C. First define a helper h:A+BR by h(w):=recA+B(z.ind+(a.|inl(a)|,b.|inr(|inl(b)|)|,z),w). Then set α(t):=recA+B+C(z.ind+(w.h(w),c.|inr(|inr(c)|)|,z),t):R. All recursors eliminate into the proposition R.

For the reverse map define k:B+CL by k(w):=recB+C(z.ind+(b.|inl(|inr(b)|)|,c.|inr(c)|,z),w), and put β(t):=recA+B+C(z.ind+(a.|inl(|inl(a)|)|,w.k(w),z),t):L. Again every truncation elimination has propositional target. Since both L and R are propositions, for every input the corresponding composite and identity value are judgmentally equal. Function congruence and eta therefore give βαidL,αβidR. No nested computation calculation is required: truncation uniqueness makes all maps between the same proposition-valued source and target agree pointwise.

Exercise 35.13.

An element of Prop0=X:U0isProp(X) is a small type together with a term witnessing that any two of its elements are extensionally equal. Put q1:=λx.λy.refl,q0:=λx.λy.abortEq0(x,y)(x). For q1, unit eta gives xy, so the printed reflexivity term converts to the required equality type. Hence the codes for truth and falsehood are 0:=(1,q1),0:=(0,q0).

Let φ,ψ:Prop0, and abbreviate P:=φ,Q:=ψ,qP:=pr2(φ),qQ:=pr2(ψ). For generic u,v:P×Q, reflection applies to qP(pr1u)(pr1v)andqQ(pr2u)(pr2v). Pair congruence and Σ-eta then give uv. Thus qPQ:=λu.λv.refl:isProp(P×Q). For generic f,g:PQ, reflection applied to qQ(f(x))(g(x)) gives f(x)g(x); lambda congruence and Π-eta give fg. Hence qPQ:=λf.λg.refl:isProp(PQ). The required elements are therefore φ0ψ:=(P×Q,qPQ),φ0ψ:=(PQ,qPQ). Universe closure under Σ and Π places both first components in U0.

More generally, suppose A:U0, x:AB:U0, and q:x:AisProp(B). Rule U-Pi gives x:AB:U0. Define qΠ:=λf.λg.refl. Indeed, in context x:A, reflection applied to q(x)(f(x))(g(x)) gives f(x)g(x):B; lambda congruence and eta give fg. Thus (x:AB,qΠ):Prop0 has the requested underlying type.

Now let A:U0 and a,b:A. Rule Eq-Form-U gives ΓEqA(a,b):U0. For generic p,r:EqA(a,b), two applications of Eq-Uniq give preflr. Consequently q=:=λp.λr.refl:isProp(EqA(a,b)), and the desired equality proposition is represented by (EqA(a,b),q=):Prop0.

Finally assume a small truncation code, so that T:U0 implies T:U0 with the stated decoding equation. Universe closure first gives x:AB:U0 and P+Q:U0. Rule Tr-Uniq makes each truncation a proposition; explicit witnesses are q:=λu.λv.refl,q:=λu.λv.refl, where the displayed reflexivity terms typecheck after the corresponding Tr-Uniq judgment uv. Hence (x:AB,q),(P+Q,q):Prop0 are the universe-coded existential and disjunction.

Exercise 35.14.

In TI, define the motive M(x,y,q):=r:IdA(x,y)IdIdA(x,y)(r,q). At the diagonal it becomes M(z,z,reflz)=r:IdA(z,z)IdIdA(z,z)(r,reflz), so the required branch is exactly z.λr.uip(r). The full primitive two-endpoint J-term is therefore U(q):=J(x.y.q.r:IdA(x,y)IdIdA(x,y)(r,q);z.λr.uip(r);q). For arbitrary a,b:A and q:IdA(a,b), rule Id-elim gives U(q):r:IdA(a,b)IdIdA(a,b)(r,q). Consequently, for p,q:IdA(a,b), U(q)(p):IdIdA(a,b)(p,q), which is the required general UIP inhabitant. At q=refla, the primitive computation rule verifies U(refla)λr.uip(r):M(a,a,refla), so the diagonal clause and the arbitrary-endpoint classifier both agree literally with the statement of the exercise.

Exercise 35.15.

For Conv, suppose the final source rule is Γa:AΓAA typeΓa:AConv. The induction hypotheses give strip(Γ)strip(a):strip(A),strip(Γ)strip(A)strip(A) type. Applying Conv in TE gives strip(Γ)strip(a):strip(A), which is exactly the stripping of the source conclusion. No special equation about the two new constants is needed in this case.

For Subst-Eq-Ty, suppose the source derivation ends in Γaa:AΓ,x:A,ΔB typeΓ,Δ[a/x]B[a/x]B[a/x] typeSubstEqTy. For compactness in this case put G:=strip(Γ),D:=strip(Δ),As:=strip(A),as:=strip(a),as:=strip(a),Bs:=strip(B). The induction hypotheses are Gasas:As,G,x:As,DBs type. Apply Subst-Eq-Ty in TE: G,D[as/x]Bs[as/x]Bs[as/x] type. By lemma 35.28, componentwise also for telescopes, strip(Δ[a/x])=D[as/x],strip(B[a/x])=Bs[as/x],strip(B[a/x])=Bs[as/x]. Substituting these literal equalities into the last judgment gives the componentwise stripping of the source conclusion: its context is strip(Γ,Δ[a/x]), and its two types are strip(B[a/x]) and strip(B[a/x]). This is the point at which commutation of stripping with capture-avoiding substitution is load-bearing rather than cosmetic.

Exercise 35.16.

Define the iterate i:NN by primitive recursion: i(0)0,i(sucn)suc(i(n)). This is the term denoted sucx(0) when evaluated at x. Use the motive C(x):=IdN(x,i(x)). The base case is c0:=refl0:C(0), since i(0)0. For the step, assume n:N and p:C(n). Congruence of successor gives apsuc(p):IdN(sucn,suc(i(n))). Because i(sucn)suc(i(n)), conversion gives apsuc(p):C(sucn). Hence Nat elimination constructs P:=λx.indN(x.C(x);c0,n.p.apsuc(p);x):x:NIdN(x,i(x)). In particular, in context x:N, x:NP(x):IdN(x,sucx(0)). Applying Id-Reflect in TE yields x:Nxsucx(0):N. This is only a derivability claim in the extensional theory. The construction supplies no converse theorem asserting that the displayed judgmental equation is underivable in TI.

Exercise 35.17.

Every code t has type X in ΓSK. The closure cases in the induction proving lemma 35.46 are therefore as follows.

For encoded reflexivity, term reflexivity gives ΓSKt:XΓSKtt:XTmRefl. If the induction hypothesis for tu is tu:X, term symmetry gives ut:X. If the hypotheses for tu and uv give tu:X,uv:X, term transitivity gives tv:X.

For SK-App, suppose tt:X,uu:X. Since app:x:Xy:XX, application congruence first gives apptappt:y:XX, and a second application-congruence step gives apptuapptu:X. By the recursive definition of coding, this is tutu:X.

The two generating conversion cases are the only places where an equation hypothesis from the context is consumed. Specifically, eKtu:EqX(Ktu,t) and eStuv:EqX(Stuv,(tv)(uv)) are reflected by Eq-Reflect. All remaining steps are typing, structural rules, or the reflexive, symmetric, transitive, and congruence closure of judgmental equality. Thus eK and eS are exactly the nonstructural equation families used by the soundness proof.

Exercise 35.18.

Let Γ:=X:U0, p:EqU0(X,XX). First, Var gives X:U0. Weakening this judgment to Γ,x:X, followed by U-Pi, gives ΓXX:U0. Consequently Eq-F forms the declared type of p, and Var gives Γp:EqU0(X,XX). There is exactly one use of equality reflection in the derivation: Γp:EqU0(X,XX)ΓXXX:U0EqReflect. Rule U-El-Eq converts this equality between universe elements into an equality of types: E:ΓXXX type. Every later use of the identification is an ordinary conversion along E or its weakening, not another use of Eq-Reflect.

In context Γ,x:X, variable formation gives x:X. Converting that same variable along E gives x:XX. Hence Π-elimination derives Γ,x:Xx:XΓ,x:XXXX typeΓ,x:Xx:XXConvΓ,x:Xx:XΓ,x:Xxx:XΠE. Discharging x gives ω:=λx.xx:XX. Symmetry of E and Conv also give ω:X. The final application therefore has the complete typing step Γω:XXΓω:XXΓXXX typeΓω:XConvΓωω:XΠE. Thus Ω:=ωω:X, and ordinary beta reduction gives Ωβ(λx.xx)(λx.xx)=Ω. The sole reflection step is the one displayed above; its consequence is reused structurally throughout the derivation.

Search the book

Type to search the local edition.