Lectures onType Theory
ch:logical-frameworks: ch:logical-frameworks
appendix sectionsolutions

ch:logical-frameworks: ch:logical-frameworks

Exercise 61.1.

The eta-long form is λ(x:A).λ(y:B).fxy. Here B and C are read in the context extended by x:A. For canonical M:A and N:B[M/x], the two contractions, with the dependent annotation made visible, are (λ(x:A).λ(y:B).fxy)MNbeta(λ(y:B[M/x]).fMy)NbetafMN. The final type is C[M/x][N/y].

Exercise 61.2.

For the specialized redex, the unreduced proof has representation supEPP(supIPP(λ(u:dedP).u))e. It is LF beta-normal because its head is the constant supE; LF has no rewrite rule relating supE and supI. The reduct is represented by the assumption e. These two canonical LF objects are not beta-eta equal: their heads are respectively supE and the context variable e. In general, compositionality gives D[E/u]=βηD[E/u]; its right side is the beta-result of applying the represented hypothetical body to E. That calculation proves compositionality of substitution, not completeness; completeness still requires canonical-head inversion.

Exercise 61.3.

For canonical M:tmA, the extension creates the canonical atomic object inspectAM:tmA. It is fully applied and its LF type is sound, but its head is neither a represented variable nor lam nor app. The inverse in the adequacy proof has no object constructor to return, so the encoding is not surjective onto canonical LF inhabitants.

Exercise 61.4.

With newest de Bruijn declarations at the left, the redex is (λAλB1)u. The outer substitution maps 0 to u. Its lift under the B-binder maps 0 to 0 and i+1 to the weakening of the old component; therefore (λAλB1)ubetaλB(1[σ])=λB(rename(+1)u).

Locally nameless syntax gives (λAλB1)u. Choose zFV(u). Opening the outer binder under the inner one leaves the inner index 0 fixed and inserts the free term u; closing again gives λBu. Translation under the new binder weakens the free context, yielding the displayed de Bruijn result.

In open PHOAS, let U:PTerm(Γ,A) represent u and evaluate the redex at V and γ:Env(V,Γ). The substitution environment maps the outer binder to U(V)(γ). Flattening returns abs(y.U(V)(γ)). For related environments γ,δ, parametricity of U relates U(V)(γ) and U(W)(δ); beneath the second binder, extend that relation by the fresh pair (yV,yW). The relation-extension clause prevents the body from inspecting y and choosing a different result.

For contextual syntax, let σ:[Γx:A] map x to u:[ΓA]. Under y:B, its lift is σ=(yy,xweak(u)). Hence the body x becomes weak(u) and the result is [ΓλBweak(u):BA]. Erasure of all four results is λB(rename(+1)u).

Exercise 61.5.

Take M=supIPQPQ(λ(h:dedPQ).h). Canonical-head inversion first selects supI and decodes its two proposition arguments as PQ. Eta-long inversion exposes the LF lambda, extends the represented context by h:PQ, and decodes its body h by the assumption case. The result is supI(h.h):(PQ)(PQ). Re-encoding applies the same constructor and returns the displayed LF lambda; only its bound name may differ, so the result is alpha-equivalent to M.

Exercise 61.6.

The new k is a closed canonical atomic LF object of family tm(arrii). Checking and canonicalization stop successfully at that declared head, but the inverse has only variable, lam, and app cases. The weakest object extension adds one constant constructor κ:ιι with typing axiom stκ:ιι and sets κ=k. The new head case decodes k to κ; its inverse equation is definitional. No other adequacy case changes.

Exercise 61.7.

Let the target context contain one free variable q:C, and substitute the de Bruijn variable 0:C for the outer free variable of λAλB2. Without lifting under either binder, the result is λAλB0; index 0 denotes the B-bound variable, so the free C-variable was captured. Two lifts give λAλB2, which denotes q and has the required type.

For locally nameless syntax, take the body λBp and substitute the free atom y for p. If the cofinite proof opens the binder at the same atom y, opening and free substitution collide. Enlarging the exclusion set by {p,y} chooses an atom zp,y and gives λBy with y free.

For PHOAS, omit relation extension beneath abs and use a body that tests its host argument, returning a variable at one related input and an abstraction at the other. The two outputs have different heads and therefore violate TermRel(R). Quantifying over every extension R that contains the bound pair forces equal heads and restores the abstraction case.

For contextual syntax, package the closed identity once as [AA] and once as [x:BAA]. Erasing the domain would admit the second package where the first is required. Retaining the exact domain rejects that substitution; weakening first gives a contextual substitution from the larger domain and restores the typing judgment. These four repairs yield the two-binder results computed in exercise 61.4.

Practical route.

The canonical-head checker of exercise 61.8 is developed in appendix F; its run is recorded in appendix E.

Search the book

Type to search the local edition.