Lectures onType Theory
ch:rules-of-dtt: ch:rules-of-dtt
appendix sectionsolutions

ch:rules-of-dtt: ch:rules-of-dtt

exercise 26.6.

The direct presuppositions are Γ,x:Aa:BandΓ,x:Ab:B. Each term judgment presupposes Γ,x:AB type, which in turn presupposes Γ,x:A ctx. Context formation then gives ΓA type and Γ ctx. If Γ=y1:C1,,yn:Cn, transitively this includes the formation of every prefix and the judgment that each Ck is a type in the preceding prefix. There are no further presuppositions.

exercise 26.7.

The directly expanded Var instance is

ΓA typeΓ ctxpresupposition of the premiseΓ,x:AA typepresupposition of the conclusion
Γ,x:Ax:A
Var

For the type-formation instance of weakening, direct expansion gives

ΓA typeΓ,ΔB typeΓ ctxpresupposition of the first premiseΓ,Δ ctxpresupposition of the second premiseΓ,x:A,Δ ctxpresupposition of the conclusion
Γ,x:A,ΔB type
Wk

Finally, direct expansion of equality-respecting type substitution is

Γaa:AΓ,x:A,ΔB typeΓa:Apresupposition of the first premiseΓa:Apresupposition of the first premiseΓ,x:A,Δ ctxpresupposition of the second premiseΓ,Δ[a/x]B[a/x] typepresupposition of the conclusionΓ,Δ[a/x]B[a/x] typepresupposition of the conclusion
Γ,Δ[a/x]B[a/x]B[a/x] type
Subst-Eq-Ty

The underbraces mark every omitted entry and its supplier. Deleting those entries gives exactly the three compressed rules in the chapter.

exercise 71.17.

The simultaneous context clause supplies Γ,x:A,Δ ctx. If z:C occurs in Γ, the same declaration occurs in the prefix of this enlarged context, so Assum immediately derives Γ,x:A,Δz:C. Otherwise write Δ=Δ1,z:C,Δ2. The context clause gives Γ,x:A,Δ1,z:C,Δ2 ctx; the declaration selected by the original rule is still present with the same type, and a second application of Assum gives the weakened judgment. Freshness of x ensures that neither case changes the selected declaration or its type. The required context derivation is why context weakening and judgment weakening are proved simultaneously.

exercise 71.18.

The componentwise composite is fg=(b1[c1/u,c2/v], b2[c1/u,c2/v]). The typing premises for f include Γ,Θb1:A,Γ,Θb2:B(b1). Substitution by the telescope map g in the second judgment gives Γ,Ξb2[c1/u,c2/v]:B(b1[c1/u,c2/v]), which is exactly the required type after the first composite component has been installed. Substitution in the first premise gives Γ,Ξb1[c1/u,c2/v]:A, because the target declaration A is formed over Γ and contains no variable of Θ.

For h:ΩΓΞ, either association sends a component bi to (bi[g])[h]. The structural-induction calculation in proposition 71.51 identifies this expression with bi[gh]. Hence every corresponding component is alpha-equivalent, so (fg)h=f(gh) with the same substituted target types.

Exercise 26.1.

Unpack the two hypotheses. There are fresh names, say r and s, such that er/x=αfr/y,fs/y=αgs/u. Choose one further name t occurring in none of e,f,g and distinct from x,y,u,r,s. Fresh-opening independence is used twice here: by proposition 26.7.1, the first displayed comparison remains true when its common opening r is replaced by t, and the second remains true when s is replaced by the same t. Hence et/x=αft/y=αgt/u. Transitivity for the strictly smaller opened bodies gives et/x=αgt/u. This is a common opening witnessing, by the operator clause in definition 26.6, L(x.e)=αL(u.g). Equivalently, rather than citing fresh-opening independence as a black box, one may open the first comparison successively at r and t, use (26.1), and do the same with the second comparison. The only nonformal step is again the assertion that changing a fresh common opening does not change the alpha-comparison.

Exercise 26.2.

The displayed binder y is not clean, because y is free in the term being inserted. Choose distinct fresh names r and s, both outside {x,y,z}. The two clean displays give respectively L(y.P(x;y))[P(y;z)/x]=αL(r.P(x;r))[P(y;z)/x]=L(r.P(P(y;z);r)), and L(y.P(x;y))[P(y;z)/x]=αL(s.P(x;s))[P(y;z)/x]=L(s.P(P(y;z);s)). To compare the two results, choose t fresh for both. Their common openings are literally the same expression: P(P(y;z);r)t/r=P(P(y;z);t)=P(P(y;z);s)t/s. Therefore L(r.P(P(y;z);r))=αL(s.P(P(y;z);s)). The calculation also exhibits why the naive result L(y.P(P(y;z);y)) is wrong: it captures the free y in the inserted copy of P(y;z).

Exercise 26.3.

The displayed binder must first be freshened, since the letter x is also the source variable of the substitution lemma. Choose z outside {x,y}FV(a)FV(c)FV(a[c/y]) and write the unary expression as L(z.e). Substitution passes through this clean binder, so the operator case is L(z.e)[a/x][c/y]=L(z.e[a/x])[c/y]=L(z.e[a/x][c/y])=L(z.e[c/y][a[c/y]/x])(induction hypothesis on e)=L(z.e[c/y])[a[c/y]/x]=L(z.e)[c/y][a[c/y]/x]. No binder is altered in this calculation because z was chosen clean for all substituends.

The load-bearing side condition is xFV(c). It is needed already in the variable case e=y: the two sides become c and c[a[c/y]/x], which agree precisely because substitution for x leaves c unchanged. Thus the term inserted for y cannot reintroduce a free occurrence of x that the later substitution would modify.

Exercise 26.4.

For the requested expression, choose the displayed binder u outside all FV(ai) and distinct from x1,x2. One-pass substitution gives P(x1;L(u.P(x2;u)))[a1/x1,a2/x2]=P(a1;L(u.P(a2;u))). The iterated calculation is P(x1;L(u.P(x2;u)))[a1/x1][a2/x2]=P(a1;L(u.P(x2;u)))[a2/x2]=P(a1;L(u.P(a2;u))). The second step does not alter the already inserted a1, since x2FV(a1).

For the general proof, choose one display of e whose bound names avoid all source variables xi and all free variables of the aj, and induct structurally on that display. At a variable v:

  • if v=xi, every substitution before the i-th leaves v unchanged, the i-th replaces it by ai, and every later substitution leaves ai unchanged because xjFV(ai); both operations therefore return ai;

  • if v{x1,,xn}, both operations leave v unchanged.

At an operator o(u1.e1;;uk.ek), every substitution passes through each clean binder list. Apply the induction hypothesis to every body and reattach the same operator and binder lists. This proves e[a1/x1,,an/xn]=e[a1/x1][an/xn]. The freshness assumptions are essential: without them, a later sequential substitution could rewrite a term inserted by an earlier one, whereas the simultaneous operation deliberately traverses each inserted term zero times.

Exercise 26.5.

Apply Subst first to the declaration x:A:

Γa:AΓ,x:A,y:B,ΔJ
Γ,y:B[a/x],Δ[a/x]J[a/x]
Subst

Here yFV(a), so the declaration name survives and the new declaration really is y:B[a/x]. Now use the given typing judgment for b as the first premise of a second substitution:

Γb:B[a/x]Γ,y:B[a/x],Δ[a/x]J[a/x]
Γ,Δ[a/x][b/y]J[a/x][b/y]
Subst

The declared variables of Δ were chosen outside FV(a)FV(b), so both displayed telescope substitutions are defined. The second rule instance has ambient context Γ, declaration type B[a/x], and telescope Δ[a/x], which is exactly why the premise for b has the stated dependent type.

Exercise 26.8.

Write Γ=x1:A1,,xn:An. By proposition 26.25, derivability of Γ,Δ ctx is equivalent to the collection of all prefix typings for its declarations. Split that collection into two parts: x1:A1,,xk1:Ak1Ak type(1kn) and Γ,y1:B1,,yi1:Bi1Bi type(1im). The same proposition says that the first group is equivalent to Γ ctx. Consequently the entire collection is equivalent to Γ ctx together with every displayed typing judgment for Bi, as required.

For the reverse direction one may also see the construction directly: starting with Γ ctx, apply Ctx-Ext successively using the premises for B1,,Bm. The forward direction repeatedly applies context inversion to the final context.

Exercise 26.9.

First substitute a ordinarily into the given formation judgment:

Γa:AΓ,x:A,y:CB type
Γ,y:C[a/x]B[a/x] type
Subst

The typing premise for a is a presupposition of Γaa:A.

Context inversion of the original formation judgment gives Γ,x:AC type. Equal substitution with empty telescope then gives ΓC[a/x]C[a/x] type. Use Ty-Sym to orient this equality from the current declaration type to the desired one, and apply declaration conversion:

ΓC[a/x]C[a/x] type
ΓC[a/x]C[a/x] type
Ty-Sym
Γ,y:C[a/x]B[a/x] type
Γ,y:C[a/x]B[a/x] type
Ctx-Conv

Thus B[a/x] is formed in the common context based on a. Notice that the thesis is not substituted again during Ctx-Conv; only the type of the declaration y changes.

Exercise 26.10.

Prove the following assertions simultaneously by rule induction:

  1. if x1:A1,,xn:An ctx, then FV(Ai){x1,,xi1}(1in);

  2. if ΓJ, then the preceding property holds for Γ and FV(J)dom(Γ).

Here FV(J) includes every expression displayed in the thesis.

For Ctx-Emp there is nothing to prove. In Ctx-Ext, the induction hypothesis for ΓA type gives both the property for Γ and FV(A)dom(Γ), exactly the new final declaration condition.

Each presupposition rule is immediate. A rule that keeps the context merely discards some constituents of its premise thesis, so its free-variable set can only shrink. For Presup-Ext, the context induction hypothesis for Γ,x:A directly says FV(A)dom(Γ). The reflexivity, symmetry, and transitivity rules for both equalities likewise retain or combine expressions already scoped in the same context; in transitivity the free-variable set of the conclusion is contained in the union of those of the two premises.

For Ctx-Conv, the equality premise gives FV(A),FV(A)dom(Γ). The second induction hypothesis scopes every declaration in Δ and the thesis in a context whose domain is dom(Γ){x}dom(Δ). Replacing A by A changes no declared names and no expression in Δ or J, so all the same inclusions hold in the converted context.

For Subst, the premise induction hypotheses give FV(a)dom(Γ),FV(E)dom(Γ){x}dom(Δ) for every declaration type or thesis constituent E to the right of x:A. The free-variable formula for substitution therefore yields FV(E[a/x])dom(Γ)dom(Δ), which is the domain of Γ,Δ[a/x]. Applying this argument to each declaration type in order proves the context part as well. The two equal-substitution rules are identical except that both a and a occur in the conclusion; the equality premise scopes both in Γ, so the same calculation applies to E[a/x] and E[a/x].

For Wk, the first premise scopes A in Γ. The second scopes Δ and J in Γ,Δ; inserting the fresh name x only enlarges every relevant prefix domain, while none of the old expressions acquires an occurrence of x. Hence the target context and thesis are scoped. For Var, the premise scopes A in Γ, and FV(x:A)={x}FV(A)dom(Γ,x:A). These cases exhaust the structural rules.

An added type-former rule may be included only after verifying that every free variable in its conclusion occurs in a premise expression already scoped by the induction hypotheses, or is one of its declared local binders. No theorem is possible for an arbitrary added rule: for example, a rule Γ ctxΓR(z) type with zdom(Γ) immediately derives a judgment violating the desired inclusion. Rule induction preserves properties supplied by the rules; it does not manufacture a missing scoping discipline out of optimism.

Exercise 26.11.

Let D1:Γab:A,D2:ΓAA type. Restoring presuppositions gives Γa:A,Γb:A,ΓA type,ΓA type,Γ ctx. The two term typings come from D1 and its symmetry via Presup-Eq-Tm; the two type formations come from D2 and its symmetry via Presup-Eq-Ty; the context follows by Presup-Ctx. Element conversion, already established in lemma 26.31, also supplies Γa:A,Γb:A, which are the direct presuppositions of the desired conclusion.

Choose x fresh. The generic-element branch, with its omitted premises restored, is

D2:ΓAA type
ΓAA type
Ty-Sym
ΓA typeΓ ctx
Γ,x:Ax:A
Var
Γ,x:AA typeΓ,x:A ctx
Γ,x:Ax:A
Ctx-Conv

The last two displayed premises are the direct presuppositions of the target judgment and context; they are derived respectively by the type instance of Wk from A type and A type, and by Ctx-Ext from A type. The Ctx-Conv node is the precise point at which the declaration type of the generic element is converted from A to A; the element remains classified by A.

Now apply the fully expanded equal-substitution instance with empty telescope:

D1:Γab:AΓ,x:Ax:AΓa:AΓb:AΓA typeΓ ctx
Γab:A
Subst-Eq-Tm

The last four lines are exactly the direct and transitive presuppositions that are normally suppressed by convention 26.14. Substitution computes x[a/x]=a, x[b/x]=b, and A[a/x]=A because x was fresh.

Exercise 26.12.

Let the proposed permutation be represented by contexts Γ(0)=Γ,Γ(1),,Γ(k)=Γ, where Γ(i+1) is obtained from Γ(i) by one certified adjacent swap. Induct on i. Suppose Γ(i)J has been derived and write the relevant context as Γ(i)=Γ0,x:A,y:B,Γ1. The certificate for this stage is a derivation Γ0B type. Apply Exch with telescope Γ1:

Γ0B typeΓ0,x:A,y:B,Γ1J
Γ0,y:B,x:A,Γ1J
Exch

This is the required derivation in Γ(i+1). Repeating the step k times yields ΓJ. Each intermediate context is derivable as a presupposition of its transported judgment.

The test xFV(B) is only a syntactic nonoccurrence test. It does not produce the typing derivation Γ0B type required by Exch. In particular, B could mention another undeclared name, fail to be a type for theory-specific reasons, or have been derivable in Γ0,x:A only by a context-sensitive added rule for which no strengthening theorem is available. Removing a name from a free-variable set is not the same operation as removing a declaration from a derivation.

Exercise 26.13.

Put Γm=Γ0,x:A,y1:B1,,ym:Bm and prove by induction on m that Γm ctx entails Γmx:A.

For m=0, Presup-Ext applied to Γ0,x:A ctx gives Γ0A type. Its own direct presupposition is Γ0 ctx. Hence the fully supplied Var instance is

Γ0A typeΓ0 ctxΓ0,x:A ctx
Γ0,x:Ax:A
Var

where the final context premise is Ctx-Ext applied to the type premise. The extra lines are precisely what compression normally omits.

For the step, assume the result for m and start from Γm+1 ctx, where Γm+1=Γm,ym+1:Bm+1. Then Presup-Ext gives ΓmBm+1 type, and repeated context peeling gives Γm ctx. The induction hypothesis gives Γmx:A. The relevant Wk instance, with empty telescope, is

ΓmBm+1 typeΓmx:AΓm ctxΓmA typeΓm+1 ctxΓm+1A type
Γm+1x:A
Wk

Here ΓmA type is Presup-Ty of the induction-hypothesis term judgment. The target context is Ctx-Ext applied to Bm+1 type. Finally, Γm+1A type, the direct presupposition of the target term judgment, is the type-formation instance of Wk applied to Bm+1 type and A type. Thus every premise suppressed by convention 26.14 has a derivation at each step, completing the induction.

Exercise 26.14.

A fully premised typing scheme is

Γ ctxΓC typeΓ,y:CD typeΓ,y:Cd:DΓQ(C;y.D) type
Γq(C;y.d):Q(C;y.D)
q-intro

The last premise is the direct presupposition of the conclusion; it follows from the Q-formation rule but is displayed because the exercise asks for the full scheme.

For pointwise-equal parameters, take primed data satisfying ΓCC type,Γ,y:CDD type,Γ,y:CD type, and term data satisfying Γ,y:Cdd:D,Γ,y:Cd:D. In the equality judgments containing D or d, the primed local context and classifier have first been transported to the unprimed ones using the earlier equalities. The formation congruence for Q supplies ΓQ(C;y.D)Q(C;y.D) type. The term-congruence scheme, stated at the unprimed result type, is therefore

ΓCC typeΓ,y:CDD typeΓ,y:CD typeΓ,y:Cdd:DΓ,y:Cd:DΓQ(C;y.D)Q(C;y.D) type
Γq(C;y.d)q(C;y.d):Q(C;y.D)
q-cong

The final type-equality premise converts the primed constructor term from Q(C;y.D) to the unprimed Q(C;y.D), supplying the conclusion’s second term presupposition.

Now begin with an instance over Γ,z:E, a derivation Γa:E, and choose yFV(a). Structural stability under substitution gives

Γ ctxΓC[a/z] typeΓ,y:C[a/z]D[a/z] typeΓ,y:C[a/z]d[a/z]:D[a/z]ΓQ(C[a/z];y.D[a/z]) type
Γq(C[a/z];y.d[a/z]):Q(C[a/z];y.D[a/z])
q-intro

This is exactly the result of capture-avoiding substitution in every premise and in the conclusion.

Exercise 26.15.

The primitive rules of T are handled as follows.

  1. Ctx-Emp, Ctx-Ext, all type- and term-equality equivalence rules, and every added structurally stable scheme are also rules of T. A full-premise instance of an added rule is in particular an instance of its compressed T-form; surplus derivable presuppositions may simply be left unused.

  2. Primitive Assum of T is a derived rule of T by lemma 26.34: context inversion extracts the declaration’s type, Var introduces the variable at that point, and successive Wk steps restore the suffix.

  3. Primitive Conv of T is derived in T by lemma 26.31, using a fresh generic element, Ctx-Conv, and Subst.

  4. Primitive Conv-Eq of T is derived in T by lemma 26.32, using the same converted generic element and Subst-Eq-Tm.

Thus every primitive T-rule has a finite T-derivation whose open leaves are exactly its premises.

Translate a whole T-derivation by induction on its proof tree. First translate all immediate premise subderivations. If the final rule is shared, reapply it. If it is Assum, Conv, or Conv-Eq, take the corresponding finite derived-rule tree above and graft the translated premise derivations into its open leaves. The result has the same conclusion as the original node. This explains why derivability is sufficient: proof trees are closed under such grafting, and no uniform derivation-transformation theorem beyond ordinary induction on the input tree is needed for this direction.

Exercise 26.16.

The first substitution removes x:A:

Γa:AΓ,x:A,y:BJ
Γ,y:B[a/x]J[a/x]
Subst

The second removes the transformed declaration of y:

Γb:B[a/x]Γ,y:B[a/x]J[a/x]
ΓJ[a/x][b/y]
Subst

The boxed premise is used precisely as the element premise of this second Subst instance; it could not have type B, because the first substitution has already changed the declaration. Under the freshness conditions in definition 26.45, the iterated result is the one-pass notation J[a/x,b/y].

exercise 71.19.

The identity map would have components (u,v). Its first component already violates the proposed side condition, since uFV(u) and u is a target variable. Thus that definition excludes every nonempty identity map and cannot support the claimed unit law.

The repair is to keep (u,v) as a legitimate relative map and rename only the target declarations in the derivation on which the map acts. With a fresh copy Δ^=(u^:A,v^:B(u^)), weaken the renamed derivation into the source context and substitute u for u^, then v for v^. Freshness now belongs to this auxiliary derivation, where it is obtainable by alpha-renaming, rather than to the map data, where identity makes it false.

Search the book

Type to search the local edition.