Lectures onType Theory
ch:pi-sigma-unit: ch:pi-sigma-unit
appendix sectionsolutions

ch:pi-sigma-unit: ch:pi-sigma-unit

exercise 27.5.

Composition was defined by gf:=λ(x:A).g(fx). Hence the two equations are direct β-computations followed by congruence under abstraction; the second also uses app-eq, since its redex lies in the argument of g: In context Γ,z:C, constzBCfλ(x:A).(λ(y:B).z)(fx)λ(x:A).zconstzAC:AC, In context Γ,y:B, gconstyABλ(x:A).g((λ(x:A).y)x)λ(x:A).gyconstgyAC:AC. The original f and g are weakened into the displayed extended contexts. The superscript records the domain and codomain of each constant map; the freshness conditions on x,x are supplied by alpha-renaming.

exercise 27.11.

For a fresh u:1, the unit uniqueness rule gives fu and gu. Symmetry of the second equality gives fugu. Congruence for abstraction and the two Π-uniqueness equations therefore give fλ(u:1).fuλ(u:1).λ(u:1).gug. The third step uses symmetry of unit uniqueness for gu, and the last step uses symmetry of function eta for g. Taking g=id1 yields the final claim. The argument uses both 1-η, to identify the values, and Π-η, to identify the functions.

exercise 72.20.

For p:x:AB, use the positive eliminator with constant motive A and branch x: pr1(p):=indΣ(x;p):A. Its pair computation gives pr1((a,b))a. Next use the motive C(z):=B[pr1(z)/x] and branch y. The first projection equation converts y:B[x/x] to the required B[pr1((x,y))/x], so pr2(p):=indΣ(y;p):B[pr1(p)/x], and positive computation yields pr2((a,b))b after the same conversion.

Conversely define elimination by substituting the projections into the branch: indΣ(z.C;d;p):=d[pr1(p)/x,pr2(p)/y]. Projection beta proves its pair computation. Typing the displayed term first places it in C[(pr1(p),pr2(p))/z]; judgmental Σ-eta is used exactly once to convert this type to C[p/z].

exercise 72.21.

For h:p:x:ABC(p), put curry(h):=λx.λy.h(x,y); in the reverse direction put uncurry(k):=λp.k(pr1(p))(pr2(p)). Then uncurry(curry(h))=Πβλp.h(pr1(p),pr2(p))=Σηh and curry(uncurry(k))=Πβ,Σβλx.λy.kxy=Πηk. For C(p):=Idx:AB(p,p), replacing judgmental Σ-eta by a path makes the first round trip only propositionally, not judgmentally, equal to h.

exercise 72.22.

Both terms are beta-normal. The neutral form p has a variable at its head, whereas (pr1(p),pr2(p)) has a pair constructor at its head; no beta rule relates them. Consequently the uncurry–curry composite stops at λp.h((pr1(p),pr2(p))) instead of reducing judgmentally to h. A propositional Σ-eta witness permits congruence to construct a propositional equality between the two maps, followed by function extensionality if equality of functions is wanted. It does not turn the stalled normal forms into a judgmental equality, so the result is a propositional rather than definitional isomorphism.

Exercise 27.1.

The simply typed function rules, reorganized in the fourfold order, are

ΓA typeΓB type
ΓAB type
→-form
Γ,x:Ab:B
Γλx.b:AB
→-intro
Γf:ABΓa:A
Γfa:B
→-elim

If judgmental equality is added, the computation and uniqueness rules are

Γ,x:Ab:BΓa:A
Γ(λx.b)ab[a/x]:B
→-β
Γf:AB
Γfλx.fx:AB
→-η

with xFV(f). The chapter on simple typing has no judgmental-equality judgment, so these last two displays are an extension of that calculus, not a reclassification of rules already present there.

For Π-types, the codomain is no longer a fixed type B in Γ, but a family B formed in Γ,x:A. Consequently:

  • formation assumes B type in the extended context;

  • the abstraction body has the dependent type B there;

  • application to a has type B[a/x], rather than B;

  • the beta equation is likewise classified by B[a/x];

  • in eta, the generic application fx has type B in Γ,x:A.

The arrow rules are exactly the constant-family specialization in which xFV(B), so every displayed fiber B[a/x] is literally B.

Exercise 27.2.

Assume first Π-η. From Γ,x:Afxgx:B and reflexive equalities for the domain and family, abstraction congruence gives Γλ(x:A).fxλ(x:A).gx:x:AB. The two eta instances are fλ(x:A).fx,gλ(x:A).gx. Therefore, using symmetry on the second and transitivity, fλ(x:A).fxλ(x:A).gxg:x:AB. This is extensionality.

Conversely, assume the extensionality rule and take f:x:AB. Put g:=λ(x:A).fx. It is well typed by Π-intro. In the generic context Γ,x:A, choose a fresh binder y for the displayed abstraction. The beta rule gives (λ(y:A).fy)xfx:B. After symmetry this is the pointwise premise fxgx:B. Extensionality now yields fg=λ(x:A).fx:x:AB, which is precisely Π-η. Thus, with the remaining product rules fixed, eta and judgmental function extensionality are interderivable.

Exercise 27.3.

Choose x fresh for f. In context Γ,x:A, beta for the identity gives Γ,x:AidAxx:A. Application congruence, using reflexivity of f:AB, therefore gives

Γ,x:Aff:ABΓ,x:AidAxx:A
Γ,x:Af(idAx)fx:B
app-eq

Abstraction congruence lifts this equality out of the generic context:

ΓAA typeΓ,x:ABB typeΓ,x:Af(idAx)fx:B
Γλ(x:A).f(idAx)λ(x:A).fx:AB
λ-eq

By definition the left side is fidA. Eta gives fλ(x:A).fx; after symmetry, λ(x:A).fxf. Transitivity now yields ΓfidAf:AB. Thus the beta step is transported first through application and then through abstraction, while eta removes the final generic abstraction.

Exercise 27.4.

Assume first the ordinary beta rule and a derivation Γ,x:Ab:B. Rename the local declaration from x to a fresh y, obtaining Γ,y:Ab[y/x]:B[y/x]. Weakening inserts a fresh declaration x:A before y:A, and Π-β in ambient context Γ,x:A gives (λ(y:A).b[y/x])x(b[y/x])[x/y]:(B[y/x])[x/y]. The two successive fresh substitutions undo one another on a clean display, so the right side and its type are respectively b and B. This is the generic beta instance.

For the converse, assume all such generic instances. Start with Γ,x:Ab:B and Γa:A. Choose y fresh for Γ,A,B,b,a, rename the body to d:=b[y/x] in context Γ,y:A, and use the assumed generic instance there, taking the fresh abstraction binder to be x: Γ,y:A(λ(x:A).d[x/y])yd:B[y/x]. Since d[x/y]=(b[y/x])[x/y]=b, this is Γ,y:A(λ(x:A).b)yb[y/x]:B[y/x]. Substitute a for y. The left side becomes (λ(x:A).b)a. For the right side, apply proposition 26.11.4 with the successive substitutions [y/x] and [a/y]: because xy, xFV(a), and yFV(b), (b[y/x])[a/y]=b[a/y][y[a/y]/x]=b[a/x]. The identical calculation gives (B[y/x])[a/y]=B[a/x]. Hence substitution of the generic equation yields Γ(λ(x:A).b)ab[a/x]:B[a/x], the ordinary beta rule.

Exercise 27.6.

Since B is formed already in Γ, Exch applied to Γ,x:A,y:BC type gives Γ,y:B,x:AC type. Thus the same raw family can be used after swapping the two independent arguments. Put F:=x:Ay:BC,F:=y:Bx:AC, and define σ:=λ(f:F).λ(y:B).λ(x:A).fxy,σ:=λ(g:F).λ(x:A).λ(y:B).gyx. Successive applications and abstractions give σ:(x:Ay:BC)(y:Bx:AC), and σ has the reverse type. The uses of C in the body of σ are licensed by the exchanged formation judgment above.

For a generic f:F, repeated beta and congruence give σ(σf)λ(x:A).λ(y:B).fxy. In context Γ,f:F,x:A, eta for the inner product gives λ(y:B).fxyfx. Abstraction congruence yields λ(x:A).λ(y:B).fxyλ(x:A).fx, and a second eta step gives λ(x:A).fxf. Hence σ(σf)f:F. Abstracting over f shows σσ=λ(f:F).σ(σf)λ(f:F).f=idF. The symmetric calculation proves σσid on the swapped product. Each round trip uses eta once for the inner argument and once for the outer argument.

Exercise 27.7.

We list the normally suppressed judgments and indicate how the natural type of each right-hand term is moved to the common type displayed in the equality.

For pair-eq, the expanded data are Γ ctx,ΓA type,Γ,x:AB type,Γx:AB type,Γa:A,Γa:A,Γaa:A,ΓB[a/x] type,ΓB[a/x] type,Γb:B[a/x],Γb:B[a/x],Γbb:B[a/x]. Equal substitution in B gives ΓB[a/x]B[a/x] type. Consequently Conv types the same raw term b at its natural right-pair fiber B[a/x]. The two intro instances then supply (a,b):x:AB,(a,b):x:AB, which are the direct presuppositions of the pair equality. With all of these premises restored, pair-eq concludes Γ(a,b)(a,b):x:AB.

For pr1-eq, restore Γ ctx,ΓA type,Γ,x:AB type,Γx:AB type,Γp:x:AB,Γp:x:AB,Γpp:x:AB,Γpr1(p):A,Γpr1(p):A. The last line consists of the two projection-elimination instances and is the direct term presupposition of the conclusion pr1(p)pr1(p):A.

For pr2-eq, put q:=pr1(p),q:=pr1(p),r:=pr2(p),r:=pr2(p). In addition to all the context, family, sum, and package judgments listed for pr1-eq, restore Γq:A,Γq:A,Γqq:A,ΓB[q/x] type,ΓB[q/x] type,Γr:B[q/x],Γr:B[q/x]. The equality of first projections is the preceding congruence rule. The requested transport of the right-hand second projection is the literal tree

Γr:B[q/x]
Γqq:AΓ,x:AB type
ΓB[q/x]B[q/x] type
Subst-Eq-Ty
ΓB[q/x]B[q/x] type
Ty-Sym
Γr:B[q/x]
Conv

Together with r:B[q/x], this supplies the direct term presuppositions of Γrr:B[q/x]. Thus every equality is stated in one common fiber, even though the natural type of r is the fiber over q.

Exercise 27.8.

Use Subst with empty telescope and with the generic thesis B type:

Γa:AΓ,x:AB type
ΓB[a/x] type
Subst

Hence B[a/x] is a formed type before the premise Γb:B[a/x] is even considered. This is the meta-well-typedness required by convention 26.14; the structural substitution rule supplies it from the family and the first component.

Exercise 27.9.

Choose x fresh for B. Weakening forms B in Γ,x:A, and the dependent-sum rules specialize to

ΓA typeΓB type
ΓA×B type
×-form
Γa:AΓb:B
Γ(a,b):A×B
×-intro
Γp:A×B
Γpr1(p):A
×-elim_1
Γp:A×B
Γpr2(p):B
×-elim_2
Γa:AΓb:B
Γpr1((a,b))a:A
×-β_1
Γa:AΓb:B
Γpr2((a,b))b:B
×-β_2
Γp:A×B
Γp(pr1(p),pr2(p)):A×B
×-η

All fibers B[a/x] have simplified to B.

Given f:A(BC) and p:A×B, define rec×(f;p):=f(pr1(p))(pr2(p)):C. For a:A and b:B, the two projection beta equations and two uses of application congruence give rec×(f;(a,b))=f(pr1((a,b)))(pr2((a,b)))fa(pr2((a,b)))fab:C. Thus the non-dependent recursor computes by rec×(f;(a,b))fab:C.

Exercise 27.10.

Work in the positive presentation. First define pr1(p):=indΣ(x;p) using the constant motive C1:=A, formed in the package context, and branch x:A. The primitive computation rule gives pr1((a,b))a:A.

Now let z:x:AB and define the second motive C2:=B[pr1(z)/x]in context z:x:AB. It is a type because pr1(z):A and ordinary substitution forms the corresponding fiber. In the branch context Γ,x:A,y:B, the eliminator requires a term of C2[(x,y)/z]=B[pr1((x,y))/x]. The first-projection computation equation gives Γ,x:A,y:Bpr1((x,y))x:A. Applying equal substitution to the family B yields B[pr1((x,y))/x]B[x/x]=B type. After symmetry, the required branch typing is

Γ,x:A,y:By:B
Γ,x:A,y:BB[pr1((x,y))/x]B type
Γ,x:A,y:BBB[pr1((x,y))/x] type
Ty-Sym
Γ,x:A,y:By:B[pr1((x,y))/x]
Conv

We may therefore define pr2(p):=indΣ(y;p):B[pr1(p)/x].

On a displayed pair, primitive computation gives indΣ(y;(a,b))y[a/x,b/y]=b:B[pr1((a,b))/x]. The first-projection beta equation and equal substitution identify this type with B[a/x]; Conv-Eq therefore yields the familiar rule pr2((a,b))b:B[a/x]. For an arbitrary variable p, however, the primitive eliminator is neutral: its computation rule matches only a scrutinee whose outer form is (a,b). With no eta or uniqueness rule in the positive presentation, nothing derives p(pr1(p),pr2(p)).

Exercise 27.12.

Let DC:Γ,z:1C type, Dc:Γc:C[/z], and Da:Γa:1. The typing derivation is

Dc:Γc:C[/z]
Da:Γa:1
Γa:1
Γa:1
Tm-Sym
DC:Γ,z:1C type
ΓC[/z]C[a/z] type
Subst-Eq-Ty
Γc:C[a/z]
Conv

Since ind1(c;a):=c, the conclusion is exactly Γind1(c;a):C[a/z]. The computation judgment at is the reflexivity tree

Dc:Γc:C[/z]
Γind1(c;)c:C[/z]
Tm-Refl

The raw term on the left is definitionally c, so no beta rule is hidden in this last step.

Exercise 27.13.

Choose the family binder x fresh for B, so B[a/x]=B for every a. The dependent sum on the right side of theorem 27.22 then becomes an ordinary Cartesian product. The maps are F:Tm(Γ,A×B)Tm(Γ,A)×Tm(Γ,B),F([p])=([pr1(p)],[pr2(p)]),G:Tm(Γ,A)×Tm(Γ,B)Tm(Γ,A×B),G([a],[b])=[(a,b)]. Projection and pair congruence make both definitions independent of the chosen representatives.

The first round trip is F(G([a],[b]))=F([(a,b)])=([pr1((a,b))],[pr2((a,b))])=([a],[b]) by the two beta rules. The other is G(F([p]))=G([pr1(p)],[pr2(p)])=[(pr1(p),pr2(p))]=[p] by symmetry of Σ-η. Hence the two maps are inverse bijections.

Exercise 27.14.

Use the notation and hypotheses of theorem 27.21(2). The local product variable x is distinct from the context variable y. Moreover, scoping gives FV(c)dom(Γ0), while xdom(Γ0); hence xFV(c).

Choose all other displayed binders away from y and FV(c). The abstraction clause of capture-avoiding substitution then applies without freshening: Λ(b)[c/y]=(λ(x:A).b)[c/y]=λ(x:A[c/y]).b[c/y]=Λ(b[c/y]). The condition xy ensures that substitution passes through rather than replacing the binder, and xFV(c) ensures that the inserted term is not captured by that binder.

For evaluation, weakening changes the derivation of f but not its raw expression. The application clause gives E(f)[c/y]=(fx)[c/y]=f[c/y](x[c/y])=f[c/y]x=E(f[c/y]). The third line uses xy. The condition xFV(c) is what makes the substituted context still extend by the same fresh declaration x:A[c/y], and it is also the side condition for the substitution-composition identity identifying all dependent result fibers. Thus the equalities are literal equalities of clean raw displays and therefore equalities of judgmental classes.

Exercise 27.15.

Let UΓ:Tm(Γ,1){} be the unique map UΓ([a])=, with inverse VΓ()=[]. Under a context substitution [c/y]:ΓΓ[c/y], term substitution defines Sc:Tm(Γ,1)Tm(Γ[c/y],1),Sc([a])=[a[c/y]]. This is well defined because structural substitution preserves term equality. The analogue of theorem 27.21(2) is the commutative square Tm(Γ,1)UΓ{}ScidTm(Γ[c/y],1)UΓ[c/y]{}. Indeed, the two composites send a class [a] respectively to [a]and[a][a[c/y]]. They are the same unique map.

The inverse maps commute as well. From the singleton, the two composites are [][[c/y]]and[]. The nullary-operator clause of substitution gives [c/y]=, so both return []. Thus the singleton bijection is natural under context substitution in both directions.

Exercise 27.16.

Take the assumed judgment ΓP type as the formation rule. The introduction operation is Γ,x:Ab:BΓΛ(b):P. For elimination, weaken f:P to Γ,x:A, apply E, and then substitute the argument:

Γa:AΓ,x:AE(f):B
ΓE(f)[a/x]:B[a/x]
Subst

Define the resulting raw operation by fa:=E(f)[a/x].

For beta, start with the inverse equation in the generic context, E(Λ(b))b:B. Substituting a for x in this equality gives E(Λ(b))[a/x]b[a/x]:B[a/x]. The left side is Λ(b)a by definition, so this is the beta rule. Commutation of the operations with substitution ensures that this expression is independent of the chosen derivation representatives and fresh displays.

For eta, the second inverse equation says Λ(E(f))f:P. After symmetry, fΛ(E(f)):P, which is eta, since E(f) is the generic application fx.

Equality preservation by Λ gives introduction congruence directly: bb:BΛ(b)Λ(b):P. For elimination congruence, suppose ff:P and aa:A. Equality preservation by E gives, in Γ,x:A, E(f)E(f):B. Ordinary substitution with a yields E(f)[a/x]E(f)[a/x]:B[a/x]. Independently, Subst-Eq-Tm applied to aa:A and the term E(f) gives E(f)[a/x]E(f)[a/x]:B[a/x]. Transitivity produces fafa:B[a/x], with the natural type B[a/x] of the right side converted to the common fiber by equal substitution. These are exactly the fixed-family λ-eq and app-eq rules. Hence the internal bijection data reconstruct formation, introduction, elimination, beta, eta, and congruence.

Exercise 27.17.

Let y:C0 be any declaration of Γ, let Γ0c:C0, and choose the local binders x,p,q,r outside {y}FV(c). Write L and R for the left and right associated sum types in example 27.26. The fully annotated first map has the form Θ=λ(q:L).(pr1(pr1(q)),(pr2(pr1(q)),pr2(q))). Applying the operator clauses of definition 26.10 from the outside in gives Θ[c/y]=λ(q:L[c/y]).(pr1(pr1(q)),(pr2(pr1(q)),pr2(q)))=ΘA[c/y],B[c/y],C[c/y]. No occurrence of q is substituted, and no occurrence of c is captured, by the chosen freshness. Consequently, for every argument, (Θs)[c/y]=Θ[c/y]s[c/y]=ΘA[c/y],B[c/y],C[c/y]s[c/y].

The same literal recursion for Ξ=λ(r:R).((pr1(r),pr1(pr2(r))),pr2(pr2(r))) gives Ξ[c/y]=ΞA[c/y],B[c/y],C[c/y],(Ξt)[c/y]=Ξ[c/y]t[c/y]. Substitution in the dependent annotations and result fibers is governed by the same binder clause; the identity (D[a/x])[c/y]=D[c/y][a[c/y]/x] follows from the freshness assumptions. Thus both comparison maps commute with substitution in an arbitrary variable of Γ, and hence in every such variable.

Exercise 27.18.

For the sum unit law, define F:=λ(p:x:A1).pr1(p):(x:A1)A,G:=λ(a:A).(a,):Ax:A1. For a:A, beta for the first projection gives F(Ga)pr1((a,))a. For p:x:A1, unit eta gives pr2(p):1; pair congruence and sum eta give p(pr1(p),pr2(p))(pr1(p),)=G(Fp). After symmetry this is the required round trip G(Fp)p. This isomorphism uses exactly Σ-eta and 1-eta.

For the product unit law, set B:=B[/x] and define H:=λ(f:x:1B).f:(x:1B)B. For b:B, weaken b to Γ,x:1. Unit eta gives x:1, so equal substitution in B, followed by symmetry, gives BB typein Γ,x:1. Convert the unchanged raw term b along this equality; call the resulting term b¯x:B. Define K:=λ(b:B).λ(x:1).b¯x:Bx:1B. Because conversion changes typing derivations, not raw terms, beta at gives H(Kb)b¯=b:B.

For f:x:1B, unit eta in the generic context gives x. Application congruence therefore identifies fx with the converted term f:B. Abstraction congruence and product eta give K(Hf)λ(x:1).fxf. Thus the second isomorphism uses 1-eta to compare the arguments and Π-eta to remove the rebuilt abstraction. The two laws use no other eta principles.

Exercise 27.19.

Take B independent of x and C independent of the pair variable p in example 27.25. Then the two types reduce to (A×B)CandA(BC). The comparison maps specialize literally to curry:=λ(f:(A×B)C).λ(x:A).λ(y:B).f((x,y)),uncurry:=λ(g:A(BC)).λ(p:A×B).g(pr1(p))(pr2(p)), which are exactly the classical simply typed combinators displayed in the exercise. No dependent conversion remains because every substituted codomain is constant.

For f:(A×B)C, beta reduction gives uncurry(curryf)λ(p:A×B).f((pr1(p),pr2(p)))λ(p:A×B).fpf. The middle step uses symmetry of product eta under application, and the last uses function eta. For g:A(BC), curry(uncurryg)λ(x:A).λ(y:B).g(pr1((x,y)))(pr2((x,y)))λ(x:A).λ(y:B).gxyg. The second step uses the two projection beta rules; the last uses function eta first at BC and then at A(BC). Hence the specialization is a definitional isomorphism, not merely a set-theoretic bijection.

Search the book

Type to search the local edition.