Lectures onType Theory
ch:normalization: ch:normalization
appendix sectionsolutions

ch:normalization: ch:normalization

Exercise 49.2.

Assume v:0. Empty elimination gives the closed term p:=abortId2(tt,ff)(v):Id2(tt,ff). Canonicity at identity types applied to p says, in particular, ttff:2, contradicting proposition 49.3. Therefore no such v exists.

Boolean canonicity alone cannot produce this contradiction. Eliminating v into 2 gives a closed Boolean, and Boolean canonicity merely says that this term is equal to one of tt or ff. Both outcomes are individually consistent; it does not force the two constructors to be equal. Identity canonicity is stronger in exactly the needed way: an inhabitant of an identity type forces its endpoints to be judgmentally equal.

Exercise 49.3.

We prove both statements simultaneously by structural induction on the raw expression t. Write E=(γ,γ),Ea=((γ,a),(γ,a)). All equalities below are equalities of the meta-level values defined in definition 49.9.

Variables. For weakening, the side condition excludes t=x. If t=y is a variable of Γ, lookup in Ea and in E returns the same component y. For substitution there are two cases: (x[a/x])(E)=a(E)=x((γ,a[γ]),(γ,a(E))), and, for yx, (y[a/x])(E)=y(E)=y((γ,a[γ]),(γ,a(E))).

Constants. The clauses for tt, ff, and 2 ignore the added component except through recursively interpreted subexpressions, so the required equations are immediate.

Application. Let t=fu. For weakening, the induction hypotheses for f and u give (fu)(Ea)=f(Ea)(u[(γ,a)],u(Ea))=f(E)(u[γ],u(E))=(fu)(E). Here ordinary syntactic weakening gives u[(γ,a)]=u[γ]. For substitution, ordinary substitution composition and the two induction hypotheses give ((fu)[a/x])(E)=(f[a/x])(E)((u[a/x])[γ],(u[a/x])(E))=f(Ea[γ])(u[(γ,a[γ])],u(Ea[γ]))=(fu)(Ea[γ]), where Ea[γ]=((γ,a[γ]),(γ,a(E))).

Abstraction. Alpha-rename so that t=λy.b with yx and y fresh for a and the displayed environments. Meta-level functions are equal extensionally. Fix an admissible argument (c,c). The weakening induction hypothesis for b, in the context also extended by y, gives b((γ,a,c),(γ,a,c))=b((γ,c),(γ,c)); therefore the two functions interpreting λy.b are equal. For substitution, the induction hypothesis for b in the extended context gives (b[a/x])((γ,c),(γ,c))=b((γ,a[γ],c),(γ,a(E),c)). Freshness identifies (b[a/x])[γ,c/y] with b[γ,a[γ]/x,c/y], so pointwise equality proves the abstraction case.

Π-types. The proof is the same binder argument, followed by extensionality of the displayed dependent products. For each closed argument c and each cA(c), apply the induction hypothesis to the codomain B in the environment extended by (c,c). The induction hypothesis for the domain identifies the sets of admissible pairs.

Boolean elimination. Apply the induction hypotheses to the scrutinee, motive, and both branches. The scrutinee evidence is the same on both sides, so both semantic eliminators select the same case, 0 or 1; the corresponding branch induction hypothesis proves equality. In the substitution case, alpha-rename the motive binder and use ordinary capture-avoiding substitution composition.

Every raw constructor is handled by one of these patterns: lookup, constant, nonbinding composition, or binding composition. This proves both clauses of lemma 49.11.

Exercise 49.4.

Fix a computable closing instantiation E=(γ,γ)Γ.

λ-congruence. Suppose the final rule is Γ,x:Abb:BΓλx.bλx.b:x:AB. The two interpretations are dependent functions. Given any admissible (a,a), induction hypothesis (d) for the premise, instantiated at ((γ,a),(γ,a)), gives b((γ,a),(γ,a))=b((γ,a),(γ,a)). Thus the functions agree pointwise, and meta-level function extensionality gives equality of the two pieces of evidence.

Congruence for Boolean elimination. Write e=ind2(x.C;c0,c1;b),e=ind2(x.C;c0,c1;b). The congruence premises give, by the simultaneous induction hypotheses, C=C,c0=c0,c1=c1,b=b. The last equality means that both semantic eliminators inspect the same scrutinee evidence. If it is 1, both select their first branch and use c0=c0; if it is 0, both select their second branch and use c1=c1. No other case is reachable for a well-typed Boolean, by part (c). The motive equality identifies the result fibers.

Part (b) for Π-congruence. Suppose the final rule has premises ΓAA type,Γ,x:ABB type (with the usual conversion if the second context is displayed using x:A). By induction hypothesis (b), A(E)=A(E). Hence both products quantify over exactly the same closed a and evidence a. For each such pair, induction hypothesis (b) for the codomain premise at the extended instantiation gives B((γ,a),(γ,a))=B((γ,a),(γ,a)). Every corresponding factor in the two dependent products is therefore equal, so the product families themselves are equal. This is exactly the claim required by part (b).

Exercise 49.5.

Extend the assignment by N(E)(n)={mNnsucm(0):N}. The constructor clauses are 0(E)=0,(suc(n))(E)=n(E)+1. They are sound because reflexivity witnesses 0suc0(0), and from nsucm(0) congruence gives suc(n)sucm+1(0).

For the eliminator, let its motive be C, its zero branch have evidence c0, and its successor branch transform evidence at m and for the recursive result into evidence at m+1. Define its semantic value by primitive recursion on the actual number m=n(E): R(0):=c0(E),R(m+1):=cs(E,sucm(0),m,R(m)). The induction hypothesis for n supplies n[γ]sucm(0). Congruence of the eliminator, followed by its zero or successor computation rule, places R(m) in the required fiber. This validates the Nat eliminator case of the fundamental lemma.

Now let n:N. Part (c) at the empty instantiation gives an actual m=n((),())N((),())(n), so, by definition, nsucm(0):N. If also nsuck(0), then the two numerals are judgmentally equal. Interpreting N as N, or using constructor disjointness and successor injectivity, yields m=k. Thus the numeral is unique.

The eliminator needs the evidence value m, not merely the proposition that the evidence set is inhabited: m determines how many successor-branch iterations define R(m). Mere inhabitation would hide the recursion index.

Exercise 49.6.

Let p:IdA(a,b). By the assumed term clause of the fundamental lemma, p belongs to the identity-evidence set displayed in remark 49.13. Hence it contains a pair (q,r) with q:ab:A,r:prefla:IdA(a,b). The derivation q is also what permits the reflexivity term, whose native type is IdA(a,a), to be viewed at the displayed type of r. Thus the endpoint equality and the canonicity equation are stored in the evidence itself; no injectivity theorem for the identity former is used.

This closed calculation is conditional on the enlarged fundamental lemma named in the exercise. The open construction of lemma 111.74 proves the corresponding identity statement for Timpl. By contrast, the local Tait proof has no identity or J case, and the Coquand construction at TCoq supplies no such clause. Neither of those two smaller arguments proves the identity result.

Exercise 49.9.

Eta-long readback expands at every negative type former.

  1. The outer lambda is already present, but its body f has function type and must itself be eta-expanded: λf.λx.fx.

  2. The variable g has two successive Π-types, so its eta-long normal form is λx.λy.gxy.

  3. The variable h has a function type, so readback first introduces an argument f:22. Because that argument is itself used at function type, its eta-long occurrence is λx.fx. Hence the fully eta-long normal form is λf.h(λx.fx). Both expansions are instances of the Π-η rule; no Σ- or Unit clause is used.

Exercise 49.13.

The eta rule for 1 is precisely Γt:1Γt:1, so every term of unit type is judgmentally .

Take the same raw term x in two contexts: x:1x:1,x:2x:2. At 1, eta-long normalization returns . At 2, the variable is a neutral normal form, so normalization returns x. Thus the same raw syntax has different normal forms depending on its typing judgment.

A function that inspects only the raw term would have to return the same answer for these two inputs. Returning x is incomplete at 1, while returning is unsound at 2. Therefore normalization and readback must be indexed by the type and context.

Exercise 49.1.

Suppose x:2xtt:2. The substitution lemma with xff gives fftt:2, contradicting Boolean separation. Dually, a derivation of x:2xff:2 and the substitution xtt would give ttff:2, the same contradiction. This proof uses substitution and the closed separation theorem; it assumes no normalization result for open terms.

Exercise 49.7.

Encode finite derivation trees by natural numbers. Enumerate those codes, decode each candidate, and check recursively whether every node is an instance of a rule of the recursive signature and whether its root is the requested judgment Γtu:A. Rule-instance checking and syntactic equality are effective, so each candidate is checked in finite time. If the judgment is derivable, its finite derivation eventually appears and the procedure halts with “yes.” Hence judgmental equality is semidecidable.

This is not a usable equality oracle. On unequal terms the search runs forever, so a type checker cannot reject a failed conversion, report an error, or continue. It also searches a vast space of irrelevant proof trees rather than computing a canonical representative. A kernel needs a total decision procedure, not merely eventual success on positive instances.

Exercise 49.8.

Fix effective enumerations of raw syntax and finite derivations. From the latter enumerate all tuples (Δ,u,U,d)withd:Δu:U. For an input derivation e:Γt:A, scan this enumeration and retain entries whose context and type are syntactically Γ and A. Use the assumed equality decision procedure to test Γtu:A. Return the first u for which the test succeeds; call it nf(e).

The search terminates constructively. The input derivation e itself is a finite derivation of a represented term equal to t by reflexivity, so its code occurs at a finite position. A successful candidate is therefore guaranteed no later than that position. This is an ordinary terminating search with an explicit termination witness, not an appeal to a classical search principle.

Because the enumeration order is fixed, nf(e) depends only on the judgmental-equality class of t. If tt:A, a candidate u that passes for t satisfies tu:A. Compose the converse tt:A of the assumed equality with that derivation to obtain tu:A. The converse implication exchanges t and t and uses the converse equality tt:A. Thus a candidate passes for t exactly when it passes for t; hence the first successful candidate is the same. Conversely, if the returned syntax trees agree, each input is judgmentally equal to that common representative, so the inputs are judgmentally equal. The successful test also supplies soundness tnf(e):A. Repeating the construction for well-formed types gives the type component. These maps, together with the stated soundness, completeness, and injectivity properties, form the normalization structure of definition 49.16.

The representatives are least derivation codes, not pleasant beta-eta normal syntax. The construction establishes existence, not efficiency.

Exercise 49.10.

We use the definitions of the Kripke domain and evaluation from definition 49.24, definition 49.25.

Restriction. First prove by induction on T that restriction on [[T]] is functorial: aΓ=a,(aΔ)Θ=aΘ(ΘΔΓ). At the base type this is composition of weakening for neutral syntax. At ST it follows pointwise from the definition of restriction of a Kripke family and the induction hypothesis for T.

Now prove (1)[[t]](ρΘ)=([[t]]ρ)Θ by structural induction on t. For a variable, (1) is the definition of restriction of an environment. For application, use the two induction hypotheses and naturality of a Kripke function. For an abstraction, compare the two semantic functions at every further extension ΞΘ and argument a. Both reduce to [[b]](ρΞ,xa), using functoriality; function extensionality concludes.

Evaluation and substitution. Prove (2)[[t[s/x]]]ρ=[[t]](ρ,x[[s]]ρ) by structural induction on t. If t=x, both sides are [[s]]ρ; if t=yx, both are ρ(y). Application follows from the two induction hypotheses. For t=λy.b, alpha-rename y fresh for s and x. At an extension Θ and argument a, both functions reduce, using the induction hypothesis for b, to [[b]](ρΘ,x[[s]](ρΘ),ya). Equation (1) identifies the restricted value of [[s]]ρ with [[s]](ρΘ).

Closure under equality on the left. Induct on T. At ι, from tt and tu, transitivity gives tu. At ST, given a future context and related argument, congruence gives tsts; the induction hypothesis at T transfers the relation to ts.

Closure under restriction. Again induct on T. At ι, weaken the equality tu to the larger context. At ST, pass to an arbitrary further extension and related argument. Functoriality identifies twice-restricted and directly restricted semantic functions, and the induction hypothesis at T supplies the result relation.

Clause by clause, (2) is lemma 49.11(2): environments are closing instantiations, variables are lookups, abstraction extends an environment, application applies semantic values, and eliminators inspect semantic constructor evidence. Equation (1) is the Kripke analogue of lemma 49.11(1). Thus the computability assignment is an evaluation into a proof-relevant semantic domain.

Exercise 49.11.

Prove simultaneously, by induction on the displayed normal and neutral derivations, N(v):ΓT([[v]]ρΓ)=v,ΓvnfT,E(u):[[u]]ρΓ=ΓT(u),ΓuneT.

For a neutral variable, E is the definition of the identity environment. For a neutral application uv, the induction hypotheses give [[u]]ρΓ=ST(u),S([[v]]ρΓ)=v. By the arrow-reflection clause, applying the first value to the second produces T(uv), proving E(uv). Neutral eliminators are identical: evaluation takes the stuck semantic clause, and the induction hypotheses reify every stored minor argument to the original normal syntax.

At a base type, a normal neutral u is handled by E(u) and the fact that base reification of reflected neutral syntax is the identity. Constructor normal forms are immediate or follow recursively on their normal arguments. For a normal abstraction λx.b, reification of its evaluated closure introduces a fresh reflected variable x. Applying the closure to that variable evaluates b in the extended identity environment; the induction hypothesis for b reifies the result to b. Thus readback returns exactly λx.b. Pair and other eta-long cases work componentwise because their readback clauses mirror their normal-form rules. This completes the mutual induction and proves nfΓT(v)=v.

Existence of a normal representative follows from normalization. For uniqueness, let v,w be normal forms of the same type with vw. Completeness gives nf(v)=nf(w), while the result just proved reduces this to v=w as alpha-equivalence classes of syntax. Soundness says every term is judgmentally equal to its normal form. Hence every judgmental-equality class contains exactly one normal form.

Exercise 49.12.

Use the disjoint-sum presentation [[2]](Γ)={ttv,ffv}+{uΓune2}, so constructor values cannot be confused with neutral syntax. Restriction fixes the two constructors and weakens a neutral. Reflection embeds a neutral into the third summand, while reification is 2(ttv)=tt,2(ffv)=ff,2(neu(u))=u. Evaluation sends the syntactic constructors to their semantic counterparts.

For a non-dependent recursor with result type T, define recTv(a0,a1,ttv)=a0,recTv(a0,a1,ffv)=a1,recTv(a0,a1,neu(u))=T(ind2(_.T;T(a0),T(a1);u)). In the last line, readback and reflection are taken in the current context; at function result types this automatically eta-expands the stuck eliminator. Evaluation of a syntactic recursor evaluates its branches and scrutinee and applies this operation. Naturality follows from naturality of reflection and reification.

The two new computation cases in completeness are definitionally true in the semantic domain. For example, [[ind2(_.T;c0,c1;tt)]]ρ=recTv([[c0]]ρ,[[c1]]ρ,ttv)=[[c0]]ρ. With ff, the same calculation returns [[c1]]ρ. Thus the two judgmental computation rules are respected by evaluation.

Exercise 49.14.

Extend the value and neutral grammars by Dpair(d1,d2)Σ^(A,F),Dnefst(e)snd(e). Define semantic projections by fstv(pair(d1,d2))=d1,sndv(pair(d1,d2))=d2,fstv(up(e))=up(fst(e)),sndv(up(e))=up(snd(e)). Evaluation acquires the clauses [[x:AB]]ρ=Σ^([[A]]ρ,d[[B]](ρ,d)),[[(a,b)]]ρ=pair([[a]]ρ,[[b]]ρ),[[pr1p]]ρ=fstv([[p]]ρ),[[pr2p]]ρ=sndv([[p]]ρ). The semantic typing relation records that the second projection has type F(d1), where d1 is the first projection.

Reflection at a Sigma type eta-expands a neutral. Put d1:=A(fst(e)),(1)Σ^(A,F)(e):=pair(d1,F(d1)(snd(e))). For an arbitrary semantic value d, let d1=fstv(d) and d2=sndv(d). Reification is (2)Σ^(A,F)n(d)=(An(d1),F(d1)n(d2)). Type-code readback gains the corresponding clause for a syntactic Sigma, using a reflected fresh variable to reify the codomain family.

For a semantic constructor pair, the projections establish both beta rules definitionally. For a reflected neutral e, equations (1) and (2) read it back as (pr1(Rne),pr2(Rne)), which is judgmentally equal to Rne by Sigma eta. Hence readback respects beta and eta and always returns eta-long Sigma normal forms.

Exercise 49.15.

Define universe equality and element equality simultaneously. Write α:cU0c@n for a proof-relevant derivation that two semantic values are related universe codes at support world n. Let Dn be the values admissible at that support and let Eln(α)Dn×Dn be the PER of their elements, defined by recursion on α. A membership derivation contains the two endpoint-admissibility premises; it is not membership in an unindexed relation on raw D.

For the closed 2^/Π^ fragment the generators are as follows.

Boolean code. There is a constructor booln:2^U02^@n. Its element PER is the least symmetric and transitive relation containing tt^Eln(booln)tt^,ff^Eln(booln)ff^, and, in open contexts, corresponding related neutral Boolean values. It contains no true–false pair.

Dependent-function code. Suppose α:AU0A@n has finite support world n. For every relational world substitution σ=(σ0,σ1;q):nm and witness ζ:dElm(σα)d, require a derivation βσ,ζ:(σ0F)(d)U0(σ1F)(d)@m. Require naturality τβσ,ζ=βτσ,τζ. Then pi(α,β):Π^(A,F)U0Π^(A,F)@n. Define its element PER by (1)fEln(pi(α,β))g for every σ:nm and d,d,ζ,dElm(σα)dσ0fdElm(βσ,ζ)σ1gd. The relational substitution carries the support evidence that an arbitrary semantic assignment would lack. Binder extension appends the supplied ζ; formation of that witness gives d,dDm. The new values may therefore contain variables from target gaps but no level outside m. Hence (1) is required at every future context extension and is stable under composition, not merely at the support world. Symmetry and transitivity of the universe relation, and of every element relation, are defined recursively on these constructors.

The ambiguity is now visible. If universe computability were merely the proposition “c is convertible to a code,” one proof might present c as 2^ and another as Π^(A,F). Recursing on those proofs would assign incompatible element PERs to El(c).

The indexed inductive family prevents this by no-confusion for code tags. A bool derivation relates only two 2^ tags, whereas a pi derivation relates only two Π^ tags; the tags are disjoint and the Pi tag is injective. Induction on two derivations with the same endpoints proves functionality: (2)α,α:cU0cEln(α)=Eln(α). In the Pi case, (2) follows recursively for the domain and every codomain relation. Equivalently, semantic codes may be records carrying a constructor tag and their element PER; universe relatedness then matches records by tag. Evidence remains proof-relevant, but the PER it carries is coherent and constructor-determined. That is the information a truth-valued predicate would lose.

Exercise 111.16.

Reflecting x:22 produces the semantic function d2(x2d); reification at the function type yields the eta-long normal form λy.xy. For the specified middle term, evaluation leaves the exact neutral spine ind2(y.2;tt,ff,x) stuck: its principal is the neutral x, its constant motive has fiber 2, and its two branch values reify to tt and ff in that fiber. Reflection at 2 stores this spine, and reification at 2 returns precisely the same displayed term. For p:(22)2, reflection and reification introduce a fresh function variable f and then eta-expand that variable at its own function type. The result is λf.p(λx.fx). The indices 22, the eliminator motive, and (22)2 select the argument reflection, branch readback, and two nested function-readback clauses. An untyped operation cannot know which eta-expansions or motive fibers to use.

Search the book

Type to search the local edition.