Lectures onType Theory
Chapter 71
Chapter 71Core route

The Rules of Dependent Type Theory

Consider a context x:A,y:B(x). The second declaration may use the first variable. Thus a context is not a bag of assumptions: its order carries mathematical information. Substituting an element a:A must remove the declaration x:A and simultaneously change B(x) to B(a). The syntax and rules must make both operations exact while preserving the order on which the second operation depends.

Convention 71.1 — Ambient metatheory

The metamathematics in this part is carried out in ZFC. In particular, raw expressions and derivation trees form sets, quotients are set-theoretic quotients, and induction on a least rule-closed collection is ordinary well-founded induction in the metatheory. Later model constructions state their additional size or large-cardinal hypotheses where those hypotheses are used; the syntactic arguments of this chapter use none of them.

Raw syntax

Renaming the binder in L(x.P(x;z)) must change the bound occurrences of x without changing the free occurrence of z. A syntax tree must therefore record, for each argument of an operator, which variables that operator binds. A binding tree carries exactly this per-argument binding information.

Definition 26.1 — Binding trees

Fix a countably infinite set V of variables x,y,z,. Its infinitude guarantees that a variable outside any prescribed finite set of names can always be chosen.

  1. A binding signature Σ is a set of operators, each equipped with an arity: a finite list (n1,,nk) of natural numbers. An operator of arity (n1,,nk) takes k arguments and binds ni variables in its i-th argument.

  2. The raw expressions over Σ are generated inductively: every variable xV is a raw expression; and if oΣ has arity (n1,,nk), if e1,,ek are raw expressions, and if xi=xi,1,,xi,ni is a list of ni pairwise distinct variables for each i, then o(x1.e1;;xk.ek) is a raw expression, in which the variables xi are bound in ei.

Example 26.2 — A running signature

For the calculations in this section, take a constant C of arity (), a binary operator P of arity (0,0), and a unary binder L of arity (1). Thus P(C;x) and L(x.P(x;z)) are raw expressions. The second occurrence of x in the latter expression is bound by L; the occurrence of z is free. No typing meaning is assigned to C,P,L. They are marks on which the binding operations can be seen.

Definition 26.3 — Names, size, and raw contexts

The size, displayed bound names, and free variables of a raw expression are defined by |x|:=1,|o(x1.e1;;xk.ek)|:=1+i|ei|,BN(x):=,BN(o(x1.e1;;xk.ek)):=i({xi}BN(ei)),FV(x):={x},FV(o(x1.e1;;xk.ek)):=i(FV(ei){xi}). A raw context is a finite list x1:A1,,xn:An whose declared variables are pairwise distinct and whose Ai are raw expressions. Write dom(Γ) for its set of declared variables, for the empty context, and Γ,Δ for concatenation when the domains are disjoint. A raw context used to extend another is also called a telescope, a context extension whose later declaration types may use earlier declared variables.

For the running expression, |L(x.P(x;z))|=4,BN(L(x.P(x;z)))={x},FV(L(x.P(x;z)))={z}. The list x:C,y:P(x;C) is a raw context. So is the reversed list y:P(x;C),x:C: raw syntax has not yet enforced dependency order. The first list is derivably well formed only if C is a type in the empty context and P(x;C) is a type in the prefix x:C. The reversed list fails this dependency test because x is not declared in its first prefix.

Definition 26.4 — Fresh renaming

Let y occur nowhere in the raw expression e. The fresh renaming ey/x replaces the free occurrences of x by y: xy/x:=y,uy/x:=u(ux),o(x1.e1;;xk.ek)y/x:=o(x1.e1;;xk.ek), where ei:=ei if x occurs in the binder list xi, and ei:=eiy/x otherwise. Thus renaming stops when it reaches a binder for x. Let the entries of each of x,y be pairwise distinct, let the two sets of entries be disjoint, and let every target name in y occur nowhere in e. We write ey/x for the successive renamings.

For w fresh, the two possible behaviours are L(x.P(x;z))w/z=L(x.P(x;w)),L(x.P(x;z))w/x=L(x.P(x;z)). The second renaming stops at L. By contrast, the body is a raw expression in which x is free, so P(x;z)r/x=P(r;z). This last calculation is what permits us to compare two displayed binders.

Lemma 26.5 — Free variables after fresh renaming

If y occurs nowhere in e, then FV(ey/x)={(FV(e){x}){y},xFV(e),FV(e),xFV(e). Fresh renaming also preserves size; and if xFV(e), then ey/x=e.

Proof of Lemma 26.5 — Free variables after fresh renaming

Proof. Induct on e. The two variable cases are the displayed alternatives. At o(x1.e1;;xk.ek), renaming stops in precisely those arguments whose binder list contains x. In every other argument apply the induction hypothesis, remove its binder list from the resulting free-variable set, and take the union over the arguments. Since y occurs nowhere in the original expression, it belongs to no binder list. The same induction, with the defining equation for size, proves |ey/x|=|e|. If x is not free, a variable z cannot equal x, so zy/x=z; at an operator the renaming either stops at a binder for x or the induction hypothesis leaves the body unchanged. This proves the final assertion. ◻

Definition 26.6 — α -equivalence

The alpha-equivalence relation =α on raw expressions is generated inductively by the two clauses:

  1. x=αx for every variable x;

  2. o(x1.e1;;xk.ek)=αo(y1.f1;;yk.fk) (the same operator o on both sides) whenever for each i there is a list zi of pairwise distinct variables, disjoint from xi,yi and occurring in neither ei nor fi, such that eizi/xi=αfizi/yi.

Let r occur nowhere in the displayed expressions. Opening both binders with r gives the identical body P(r;z), and hence L(x.P(x;z))=αL(y.P(y;z)). The tempting expression L(z.P(z;z)) is not alpha-equivalent to either one: their common openings are P(r;z) and P(r;r), which differ at the second variable. Renaming a binder to a free name is capture, not alpha-conversion.

Proposition 26.7

  1. In clause 2 of definition 26.6, “for some fresh zi” may equivalently be replaced by “for every fresh zi”.

  2. =α is an equivalence relation.

  3. If e=αe then FV(e)=FV(e).

  4. If e=αe and the same fresh renaming is defined on both displays, then ew/z=αew/z.

Proof of Proposition 26.7

Proof. We first record the raw calculation used in every clause. Let x,z,w have the same length, let the three lists be pairwise disjoint with distinct entries internally, and suppose z,w occur nowhere in e. Structural induction gives ez/xw/z=ew/x. The variable case is immediate. At an operator, each renaming either stops at the argument’s binder list or passes into its body; in the latter case use the induction hypothesis for that body. The free-variable calculation needed below is lemma 26.5.

The companion commutation calculation is also needed. Let z,w be distinct from one another and from the equally long, disjoint lists x,v, suppose v,w occur nowhere in e, and suppose z{x}. Structural induction gives ev/xw/z=ew/zv/x. At an operator both renamings stop or pass independently in each argument; when they pass, apply the induction hypothesis to that body.

Alpha-equivalent expressions have equal size. Indeed, rule induction on a derivation of e=αe shows |e|=|e|. The variable clause is immediate. In the operator clause, the induction hypotheses say that every pair of common opened bodies has equal size; fresh renaming preserves size by lemma 26.5, so the corresponding original bodies have equal size. Both expressions use the same operator and arity, and the defining size equation therefore gives equal total sizes.

Complete induction on this common size proves four strengthened assertions simultaneously: independence of the fresh opening, compatibility with fresh renaming, the equivalence laws, and preservation of free variables. Every induction hypothesis below concerns an alpha-equivalent pair of strictly smaller common size.

Independence of the fresh opening. Suppose a common opening with zi witnesses clause 2, and let wi be any other allowable lists. The induction hypothesis for renaming compatibility renames the smaller related bodies from zi to a third fresh list ui. Equation (26.1) gives the same expressions as opening the original bodies directly at ui. Repeat the renaming-compatibility step with ui in place of zi and wi in place of ui. Hence the comparison holds at every common fresh opening.

The later renaming step has the following exhaustive binder case split for one external name z:

z{xi} z{yi} comparison after opening
no no commute both renamings by (26.2)
yes yes both external renamings stop at the binder
yes no free-variable preservation removes z on the right after opening
no yes exchange the two displays in the preceding case

Compatibility with fresh renaming. It is enough to treat one renaming w/z; repeat the argument for a list. For an operator pair, fresh-opening independence permits common opening lists fresh for z and w. Consider one pair of corresponding arguments. If neither binder list contains z, opening and the external renaming commute by (26.2); the induction hypothesis for renaming compatibility applies to the smaller opened bodies. If both binder lists contain z, the external renaming stops on both sides, and the original common-opening comparison applies. Suppose, finally, that only one binder list contains z. After that binder is opened at the fresh common list, z is not free on that side. The induction hypothesis for free-variable preservation says it is not free on the other side either. On the side whose binder did not contain z, the fresh-renaming formula implies zFV(fi): opening at names disjoint from z neither creates nor removes a free z. Thus lemma 26.5 gives fiw/z=fi before the opening. On the first side the external renaming stops at the binder. Both results are therefore the original common openings. Clause 2 of definition 26.6 rebuilds the operator and proves renaming compatibility. This case shows why one must prove, rather than assert, that an external renaming commutes with every opening.

Equivalence laws. Reflexivity is structural induction: at an operator choose fresh common openings and use reflexivity for the smaller opened bodies. Symmetry follows by reversing the comparisons in clause 2. For transitivity, suppose o(x1.e1;;xk.ek)=αo(y1.f1;;yk.fk),o(y1.f1;;yk.fk)=αo(u1.g1;;uk.gk). Choose one list wi fresh for all three i-th bodies and disjoint from the three binder lists xi,yi,ui. Fresh-opening independence opens both hypotheses with that same list. Transitivity for the smaller opened bodies, by the induction hypothesis, gives eiwi/xi=αgiwi/ui; clause 2 rebuilds the operator.

Preservation of free variables. Variables are immediate. In the operator case, open the two i-th bodies with one fresh list zi. The induction hypothesis gives the exact equality FV(eizi/xi)=FV(fizi/yi). Remove the fresh variables zi from this equality and use the fresh-renaming formula recorded above; the result is FV(ei){xi}=FV(fi){yi}. Taking the union over i is precisely the free-variable equation for the two operator expressions. ◻

Exercise 26.1

★☆☆ For an operator L of arity (1), use two successive common openings to verify directly that L(x.e)=αL(y.f) and L(y.f)=αL(u.g) imply L(x.e)=αL(u.g). Mark where fresh-opening independence is used.

Convention 26.8

An expression is an alpha-equivalence class of raw expressions, and = between expressions means α-equivalence of representatives. To write an expression, choose a representative whose bound variables are pairwise distinct and distinct from all free variables in sight (the Barendregt convention). Raw contexts are not quotiented: the declared variables of a context are significant.

Lemma 26.9 — Synchronized fresh displays

Let e=αe and let X be a finite set of variables. There are raw representatives e¯=αe and e¯=αe such that

  1. corresponding operator arguments in e¯,e¯ use identical binder lists;

  2. every bound name in either representative lies outside X;

  3. corresponding bodies are alpha-equivalent.

In particular, every expression has a representative whose bound names avoid any prescribed finite set.

Proof of Lemma 26.9 — Synchronized fresh displays

Proof. Use complete induction on size. Alpha-equivalent variables are the same variable, so there is nothing to choose. For operator expressions, choose for each pair of corresponding arguments one common binder list zi outside X, outside every name occurring in either body, and disjoint from the two original binder lists xi,yi. This is permitted by proposition 26.7.1. The common openings eizi/xiandfizi/yi are alpha-equivalent and smaller than the original expressions. Apply the induction hypothesis to each pair, enlarging the forbidden set to include all the newly chosen zi, and rebuild the operator with those common binder lists. For this rebuilding step, suppose p¯i=αeizi/xi, open both proposed outer binders at a further fresh list ui. Then p¯iui/zi=αproposition26.7.4eizi/xiui/zi=(26.1)eiui/xi. Clause 2 of definition 26.6 now shows that the rebuilt representative is alpha-equivalent to the original. Corresponding bodies remain alpha-equivalent by construction. Taking e=e gives the final assertion. ◻

The need for a fresh representative is already visible with L and P. Replacing x by P(y;z) in L(y.P(x;y)) must not capture the inserted y. With a naive recursion one would obtain L(y.P(P(y;z);y)), where the first inserted y has become bound. With a fresh r, first choose the alpha-equivalent representative L(r.P(x;r)); capture-avoiding substitution gives L(r.P(P(y;z);r)).

Definition 26.10 — Capture-avoiding substitution

Let e,a be expressions and x a variable. Choose a representative of e whose bound variables avoid x and FV(a). The capture-avoiding substitution e[a/x] is defined by recursion: x[a/x]:=a,y[a/x]:=y(yx),o(x1.e1;)[a/x]:=o(x1.e1[a/x];). More generally, let x1,,xn be pairwise distinct. Choose a display whose bound names avoid every xi and every FV(aj). The simultaneous substitution e[a1/x1,,an/xn] is the recursion that sends a variable xi to ai, leaves every other variable fixed, and passes once through every operator argument. Thus an inserted ai is not subsequently changed by another entry of the same substitution. The synchronized-display argument in proposition 26.11.1 proves that this operation is independent of the chosen display and of the representatives of all ai. For a raw context Δ=y1:B1,,ym:Bm whose declared variables avoid x and FV(a) we write Δ[a/x]:=y1:B1[a/x],,ym:Bm[a/x].

For a deterministic named implementation one may fix x0,x1, and choose the least name outside the finite forbidden set. The mathematical operation remains the alpha-class specified above; proposition 26.11(1) proves independence from this choice.

Proposition 26.11

  1. If e=αe and a=αa then e[a/x]=αe[a/x]; substitution is well defined on expressions. More generally, simultaneous substitution is independent of the display of e and of the representatives of all its substituends.

  2. If xFV(e) then e[a/x]=e.

  3. FV(e[a/x])=(FV(e){x})FV(a) if xFV(e), and FV(e[a/x])=FV(e) otherwise.

  4. (Substitution lemma.) If xy and xFV(c), then e[a/x][c/y]=e[c/y][a[c/y]/x].

  5. If y occurs nowhere in e, then ordinary substitution by the fresh variable coincides with fresh renaming: e[y/x]=ey/x.

Proof of Proposition 26.11

Proof. For claim 1, proposition 26.7.3 gives FV(a)=FV(a). Set X={x}FV(a). Apply lemma 26.9 to e=αe with forbidden set X. We may therefore calculate with synchronized representatives whose corresponding binder lists are identical and safe for both inserted expressions. Structural induction on their common operator tree now proves e¯[a/x]=αe¯[a/x]. At a variable, the only nontrivial case is x, where the assertion is a=αa. At an operator, apply the induction hypotheses to all corresponding bodies. To rebuild the common binder lists, open the two substituted bodies with one new list. Their alpha-equivalence is preserved by this fresh renaming by proposition 26.7.4, so clause 2 of definition 26.6 applies. This proves representative and substituend independence; no commutation of an opening with substitution is being assumed.

For simultaneous substitution, forbid all source variables and the union of the free-variable sets of all substituends, and apply lemma 26.9 once. The same induction on the synchronized operator trees has variable case xiai and otherwise passes through each argument once. Reattachment is exactly the preceding argument. This proves the final assertion of claim 1.

Claims 2 and 3 are structural inductions on one clean representative. The variable cases are immediate. For o(x1.e1;;xk.ek), the binder names avoid x and FV(a), so the induction hypotheses give FV(ei[a/x])={(FV(ei){x})FV(a),xFV(ei),FV(ei),xFV(ei). Remove the argument’s binder list xi and take the union over i. Because those binders occur in neither {x} nor FV(a), this is exactly claim 3. If x is absent from the free variables of the whole operator expression, it is absent from every body after bound names are excluded; claim 2 follows from the body induction hypotheses.

For compatibility with substitution, the variable cases contain the reason for its side conditions. If e=x: the left side is x[a/x][c/y]=a[c/y], and the right side is x[c/y][a[c/y]/x]=x[a[c/y]/x]=a[c/y], using xy. If e=y: the left side is y[a/x][c/y]=y[c/y]=c, and the right side is c[a[c/y]/x]=c by claim 2, since xFV(c). If e=z with zx,y, both sides are z.

For the operator case put X={x,y}FV(a)FV(c)FV(a[c/y]). Choose one representative of the outer expression whose bound names avoid X. By lemma 26.9 and representative independence, choose representatives of a and c whose bound names also avoid X. Every substitution below therefore passes through every binder in the chosen representatives. On the i-th body the induction hypothesis gives ei[a/x][c/y]=ei[c/y][a[c/y]/x]. Reattaching the unchanged operator and binder lists makes the left and right sides of claim 4 identical argument by argument. Claim 5 is the same structural induction: both operations send x to y, fix every other free variable, and pass through the common clean binder display. This completes the induction. ◻

Remark 26.12

We do not divide raw expressions into raw types and raw terms: the judgments of section 26.2 do the sorting. In a theory with a universe, one expression may itself be classified as a type, so a two-sorted raw grammar would have to be merged again. The signature is likewise open-ended: adding an operator does not change the uniform definitions of alpha-equivalence and substitution.

Exercise 26.2

★☆☆ Let L have arity (1) and P arity (0,0). With all displayed variables distinct, calculate L(y.P(x;y))[P(y;z)/x] from two different clean binder choices and verify their alpha-equivalence by common opening.

Exercise 26.3

★☆☆ Specialize the substitution lemma to a unary binder L(x.e). Write the operator calculation in full and identify the hypothesis that prevents the term substituted for y from reintroducing a free x.

Exercise 26.4

★★☆ Suppose xiFV(aj) for all i,j. Show that e[a1/x1,,an/xn]=e[a1/x1][an/xn]. First calculate both operations on P(x1;L(u.P(x2;u))) for n=2 and clean displayed binders; then prove the general statement by induction on an alpha-equivalent representative of e whose bound variables avoid the substituted expressions.

Judgments and contexts

Raw syntax cannot yet say that an expression is a type, that a term has a type, or that two of either are equal. Each assertion is relative to a context of typed variables, so five judgment forms are needed, not one.

Definition 26.13 — The judgment forms

Dependent type theory has five judgment forms.

  1. Γ ctx — “Γ is a (well-formed) context.”

  2. ΓA type — “A is a type in context Γ.”

  3. Γa:A — “a is an element of type A in context Γ.”

  4. ΓAB type — “A and B are judgmentally equal types in context Γ.”

  5. Γab:A — “a and b are judgmentally equal elements of type A in context Γ.”

Here Γ is a raw context and A,B,a,b are expressions. These notions were fixed in definition 26.1, definition 26.3, convention 26.8. The symbol is reserved for judgmental equality throughout the book.

Convention 26.14 — Presuppositions

The presuppositions of a judgment form are the well-formedness obligations of its parts listed below:

judgment presupposes
Γ,x:A ctx Γ ctx and ΓA type
ΓA type Γ ctx
Γa:A ΓA type
ΓAB type ΓA type and ΓB type
Γab:A Γa:A and Γb:A

(and, transitively, everything these presuppose). The first row is recursive; the empty context has no presupposition. We adopt two disciplines. (i) Asserting a judgment, in prose or as the premise of a rule, implicitly asserts its presuppositions. (ii) In displayed rules we compress premises: a premise is omitted when its derivability follows from the presuppositions of the displayed premises and conclusion. This convention is cited by number whenever compression is used.

The structural rules

The five judgment forms are generated simultaneously. Context extension requires a type in the preceding context, so context formation and type formation cannot be defined independently. An extension Γ,x:A is always a raw context, so xdom(Γ).

Definition 26.15 — Contexts and presuppositions

Context formation is governed by

 ctx
Ctx-Emp
ΓA type
Γ,x:A ctx
Ctx-Ext

Each judgment also yields its direct presuppositions:

ΓA type
Γ ctx
Presup-Ctx
Γ,x:A ctx
ΓA type
Presup-Ext
Γa:A
ΓA type
Presup-Ty
ΓAB type
ΓA type
Presup-Eq-Ty
Γab:A
Γa:A
Presup-Eq-Tm

The rule Ctx-Emp is a complete derivation of  ctx. Given a derivation D of A type, Ctx-Ext forms the one-declaration context:

D:A type
x:A ctx
Ctx-Ext

Conversely, Presup-Ext extracts the same type-formation judgment from any derivation of x:A ctx. Context extension and context inversion are thus two visible operations, not two implicit side conditions.

Definition 26.16 — Equality rules

Judgmental equality is an equivalence relation, separately for types and for elements:

ΓA type
ΓAA type
Ty-Refl
ΓAB type
ΓBA type
Ty-Sym
ΓAB typeΓBC type
ΓAC type
Ty-Trans
Γa:A
Γaa:A
Tm-Refl
Γab:A
Γba:A
Tm-Sym
Γab:AΓbc:A
Γac:A
Tm-Trans

For example, from ab:A and cb:A we obtain ab:A,bc:Aac:A, first by Tm-Sym on the second judgment and then by Tm-Trans. The type-equality calculation is identical with the prefix Ty-.

Convention 26.17 — Generic judgment theses

The letter J ranges over the four judgment theses, the parts of an expression judgment that follow its context: A type,AB type,a:A,ab:A. Thus ΓJ abbreviates four judgments. Substitution in J acts on every constituent expression, and FV(J) is the union of their free-variable sets.

Definition 26.18 — Conversion of a declaration

The type of a declared variable may be replaced by a judgmentally equal type:

ΓAA typeΓ,x:A,ΔJ
Γ,x:A,ΔJ
Ctx-Conv

The rule acts on every thesis abbreviated by J. Its first premise is indispensable: changing a declaration to a merely well-formed, but unequal, type would change the mathematical assumption.

For example, if ΓAA type and Γ,x:Ax:A, context conversion followed by term conversion gives ΓAA typeΓ,x:Ax:AΓ,x:Ax:ACtxConv,Γ,x:Ax:A. Without AA, the putative conclusion could assert x:2x:N merely because both declaration types are formed; no structural rule can supply that judgment.

Definition 26.19 — Families and sections

Let ΓA type. A family of types over A is a type Γ,x:AB type, and a section is an element Γ,x:Ab:B. For Γa:A, the expression B[a/x] is the fiber at a. We also write B(x) for the family and B(a) for the fiber, and set b(a):=b[a/x].

Definition 26.20 — Substitution rules

Substitution removes a declaration by replacing its variable with an element:

Γa:AΓ,x:A,ΔJ
Γ,Δ[a/x]J[a/x]
Subst
Γaa:AΓ,x:A,ΔB type
Γ,Δ[a/x]B[a/x]B[a/x] type
Subst-Eq-Ty
Γaa:AΓ,x:A,Δb:B
Γ,Δ[a/x]b[a/x]b[a/x]:B[a/x]
Subst-Eq-Tm

In these schemes the declared names of Δ are chosen outside FV(a), and outside FV(a) in the two equality schemes, so every displayed context substitution is defined as in definition 26.10. The first rule acts on all four theses. The other two say that substituting equal elements gives equal types and equal terms in the common context obtained with a.

Here is the basic calculation. Given an element and a family,

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

derives the fiber. With a telescope y:B to the right, the same rule changes both the declaration and the thesis: Γ,x:A,y:BJΓ,y:B[a/x]J[a/x].

Exercise 26.5

★☆☆ Derive the two-variable substitution rule: from Γa:A, Γb:B[a/x], and Γ,x:A,y:B,ΔJ, conclude Γ,Δ[a/x][b/y]J[a/x][b/y]. Choose the declared names of Δ outside FV(a)FV(b) and choose yFV(a), so all displayed context substitutions are defined.

Definition 26.21 — Weakening and the generic element

Weakening inserts an unused declaration, while the variable rule gives the element named by a final declaration:

ΓA typeΓ,ΔJ
Γ,x:A,ΔJ
Wk
ΓA type
Γ,x:Ax:A
Var

Choose x fresh for B. From ΓA type and ΓB type, weakening produces the constant family

ΓA typeΓB type
Γ,x:AB type
Wk

Its fiber at a:A is B[a/x]=B. In contrast, Var produces the section Γ,x:Ax:A whose value after substituting a is the element a itself.

Remark 26.23 — Simultaneity

The five judgments are the least classes closed under all structural rules and under the chosen formation, introduction, elimination, and equality rules. They are generated simultaneously because Ctx-Ext has a type judgment as its premise and a context judgment as its conclusion. Rule induction over this simultaneous generation proves one property for each of the five judgment forms (theorem 1.15).

Proposition 26.24 — Sanity

If a judgment is derivable, so are all of its presuppositions in the sense of convention 26.14; in particular, if ΓJ is derivable then so is Γ ctx.

Proof of Proposition 26.24 — Sanity

Proof. Use the presupposition and equality rules. From Γa:A, Presup-Ty gives ΓA type, and then Presup-Ctx gives Γ ctx. From ΓAB type, Presup-Eq-Ty gives ΓA type; composing Ty-Sym with Presup-Eq-Ty gives ΓB type; and Presup-Ctx gives Γ ctx. From Γab:A, Presup-Eq-Tm gives Γa:A, composing Tm-Sym with Presup-Eq-Tm gives Γb:A, and the previous case finishes. From ΓA type, Presup-Ctx gives Γ ctx. Finally, from Γ,x:A ctx, Presup-Ext gives ΓA type and then Presup-Ctx gives Γ ctx. Iterating these five derivations establishes every transitive presupposition in convention 26.14. ◻

Proposition 26.25 — Characterization of contexts

Assume that no added rule concludes a context judgment and that every added rule has, among its full premises, the context judgment presupposed by its conclusion. Let Γ=x1:A1,,xn:An be a raw context. The judgment Γ ctx is derivable if and only if for each 1kn the judgment x1:A1,,xk1:Ak1Ak type is derivable.

Proof of Proposition 26.25 — Characterization of contexts

Proof. () For n=0 apply Ctx-Emp; for n1 apply Ctx-Ext to the k=n judgment.

() We prove two assertions simultaneously by rule induction. If Γ ctx is derivable, every declaration of Γ has a derivable type judgment in its preceding prefix. If ΓJ is derivable, the same prefix property holds for its ambient context Γ. We treat each structural rule and then the added rules.

For Ctx-Emp the assertion is empty. For Ctx-Ext, the premise is x1:A1,,xn1:An1An type; the inductive hypothesis for it yields the type judgments for all k<n, and the premise itself is the case k=n.

Every presupposition rule either keeps the context or removes its last declaration. In the first case its premise induction hypothesis is exactly the desired prefix property; in the second, Presup-Ext, take the proper prefixes established for Γ,x:A. Each equality rule has a premise in the same context as its conclusion, so its induction hypothesis applies unchanged.

For Ctx-Conv, suppose the conclusion context is Γ,x:A,Δ. From the equality premise ΓAA type, rule Ty-Sym gives ΓAA type, and Presup-Eq-Ty then gives ΓA type. Fix a prefix Δ of Δ whose following declaration is y:B. The induction hypothesis for the judgment premise gives Γ,x:A,ΔB type. Apply Ctx-Conv with the same equality premise to derive Γ,x:A,ΔB type. Prefixes wholly inside Γ come from the equality premise’s induction hypothesis.

For Subst, from Γa:A and Γ,x:A,ΔJ, prefixes of Γ come from the first induction hypothesis. For a prefix reaching into Δ[a/x], with next type B[a/x], the second induction hypothesis gives Γ,x:A,ΔB type; one application of Subst gives Γ,Δ[a/x]B[a/x] type. For Subst-Eq-Ty, apply Subst to both type premises with substitution [a/x]; for Subst-Eq-Tm, apply it to the common classifier premise. Both yield the displayed conclusion context Γ,Δ[a/x].

For Wk, from ΓA type and Γ,ΔJ to Γ,x:A,ΔJ. The prefixes of Γ are handled by the inductive hypothesis of the first premise, the prefix ending in A by the first premise itself. For a prefix reaching into Δ, say with next type B, the inductive hypothesis of the second premise gives Γ,ΔB type for the corresponding prefix Δ of Δ, and one application of Wk (with the first premise) gives Γ,x:A,ΔB type.

For Var, the type premise gives all prefixes of Γ by its inductive hypothesis and gives the final declaration type A itself. Finally, an added rule cannot conclude a context judgment. For its non-context conclusion, the hypothesis of the proposition gives a context premise for the conclusion context. Its induction hypothesis gives the prefix property. These cases exhaust the simultaneous rule set. ◻

Corollary 26.26 — Context inversion

Under the hypotheses on added rules in proposition 26.25, if Γ,x:A,Δ ctx is derivable, then so are Γ ctx and ΓA type. More generally the same follows, via proposition 26.24, from any derivable judgment Γ,x:A,ΔJ.

Proof of Corollary 26.26 — Context inversion

Proof. The prefix property of proposition 26.25 gives ΓA type directly, and Presup-Ctx gives Γ ctx. ◻

Lemma 26.27 — The common context for equal substitution

Assume both hypotheses on added rules in proposition 26.25. Let Γaa:A and let Γ,x:A,ΔJ. Then both Γ,Δ[a/x]J[a/x]andΓ,Δ[a/x]J[a/x] are derivable. In the second judgment every declared type and every constituent of J is substituted with a, but the displayed context is the one obtained with a.

Proof of Lemma 26.27 — The common context for equal substitution

Proof. The first judgment is Subst. Ordinary substitution with a gives the second thesis over Γ,Δ[a/x]; we convert that context one declaration at a time. Write Δ=y1:B1,,ym:Bm, and let Δi1 denote its first i1 declarations. Suppose those declarations have already been converted from their a-forms to their a-forms. Context inversion applied before substitution gives Γ,x:A,y1:B1,,yi1:Bi1Bi type. The rule Subst-Eq-Ty, instantiated with the telescope Δi1, gives directly Γ,Δi1[a/x]Bi[a/x]Bi[a/x] type. Apply Ty-Sym, then Ctx-Conv at the i-th declaration: the context being transported currently contains Bi[a/x], and the desired context contains Bi[a/x]. Induction on i converts the whole telescope and transports the thesis to the common context. The case m=0 requires no conversion. ◻

Remark 26.28

In the absence of type formers the structural rules generate exactly one derivable judgment, namely  ctx: every other rule has a premise requiring some type to exist. Any type-formation axiom populates the calculus.

Exercise 26.6

★☆☆ List all direct and transitive presuppositions of Γ,x:Aab:B. Include the presuppositions of the nonempty context itself.

Exercise 26.7

★★☆ Call a rule instance directly expanded when it explicitly lists the displayed premises and every direct presupposition of those premises and the conclusion; do not recursively expand the resulting context judgments. Directly expand Var, the type-formation instance of Wk, and Subst-Eq-Ty. Mark each entry omitted under convention 26.14 and the premise or conclusion that supplies it.

Exercise 26.8

★☆☆ Let Δ=y1:B1,,ym:Bm. Deduce from proposition 26.25 that Γ,Δ ctx is derivable exactly when Γ ctx and every Γ,y1:B1,,yi1:Bi1Bi type are derivable.

Exercise 26.9

★★☆ Take Δ=y:C. Starting from Γaa:A and Γ,x:A,y:CB type, write the context-conversion calculation that types B[a/x] in the common context Γ,y:C[a/x].

Exercise 26.10

★★★ Set up the simultaneous induction that will apply after type-former rules are added, and verify for each structural-rule case that ΓJ would imply FV(J)dom(Γ) and that, in a derivable context, each declared type has free variables only among earlier declarations. The empty structural theory has no non-context example, so these are induction steps rather than a nonvacuous closed theorem. An added type-former rule may be included in the induction only after checking the same scoping property for that rule; explain why no conclusion is possible for an arbitrary added rule.

Example derivations

Everyday derivations use renaming, exchange, general variables, and the two conversion rules as single steps. Each must first be derived from the primitive structural rules. Recall that a rule is derivable when its conclusion has a derivation from its premises taken as axioms (definition 1.32).

Remark 26.29

Expressions in a judgment are alpha-classes, but a judgment is not quotiented by renaming variables declared in its context: those variables occur free in the declarations and thesis to their right. Such a change is a derivation, not an identification. The following lemma constructs it.

Lemma 71.31 — Context peeling

From a hypothesis axiom Γ,x:A,ΔJ, derive both Γ,x:A,Δ ctx and ΓA type.

Proof of Lemma 71.31 — Context peeling

Proof. A type thesis uses Presup-Ctx; a term thesis uses Presup-Ty and then Presup-Ctx; a type equality uses Presup-Eq-Ty and then Presup-Ctx; and a term equality uses Presup-Eq-Tm, Presup-Ty, and Presup-Ctx. These cases derive Γ,x:A,Δ ctx. Repeatedly apply Presup-Ext followed by Presup-Ctx to peel the declarations of Δ; one final Presup-Ext derives ΓA type. Every step is a node over the original hypothesis axiom, so the calculation is valid in hypothetical derivability. ◻

Lemma 26.30 — Change of variables

Let x be a variable occurring nowhere in the judgment Γ,x:A,ΔJ. Then the rule

Γ,x:A,ΔJ
Γ,x:A,Δ[x/x]J[x/x]
Rename

is derivable.

Proof of Lemma 26.30 — Change of variables

Proof. Apply lemma 71.31 to the premise and call the resulting derivation of ΓA type by D. Then

ΓA type
Γ,x:Ax:A
Var
ΓA typeΓ,x:A,ΔJ
Γ,x:A,x:A,ΔJ
Wk
Γ,x:A,Δ[x/x]J[x/x]
Subst

where both undischarged leaves ΓA type stand for D. The final step is the instance of Subst with ambient context Γ,x:A, substituted element x, and telescope Δ; its side conditions hold since x is globally fresh. ◻

Lemma 71.33 — Substitute while retaining the source declaration

If Γa:A and Γ,x:A,ΔJ, then Γ,x:A,Δ[a/x]J[a/x]. For context formation, the corresponding conclusion is Γ,x:A,Δ[a/x] ctx whenever Γ,x:A,Δ ctx.

Proof of Lemma 71.33 — Substitute while retaining the source declaration

Proof. Apply Subst to obtain Γ,Δ[a/x]J[a/x]. Because a is typed in Γ, the result contains no free x. Apply Wk at the cut after Γ to reinsert x:A. For context formation, induct on Δ. After Subst forms the next declaration over Γ,Δ[a/x], Wk reinserts x:A at the cut after Γ, and Ctx-Ext appends that declaration to Γ,x:A,Δ[a/x]. ◻

Lemma 26.31 — Element conversion

The rule

Γa:AΓAA type
Γa:A
Conv

is derivable.

Proof of Lemma 26.31 — Element conversion

Proof. From the second premise, ΓA type is derivable by Ty-Sym and Presup-Eq-Ty. Choose x to occur nowhere in Γ,A,A,a. Then xFV(A), so A[a/x]=A, and the tree

Γa:A
ΓAA type
ΓAA type
Ty-Sym
ΓA type
Γ,x:Ax:A
Var
Γ,x:Ax:A
Ctx-Conv
Γa:A
Subst

derives the conclusion: the Ctx-Conv step converts the context entry x:A to x:A along ΓAA type, and the final Subst step substitutes a for x in the thesis x:A. Implementations usually reverse this presentation choice: Conv is a primitive kernel rule, while the more global context-conversion operation is proved admissible. ◻

Lemma 26.32 — Equality conversion

The rule

Γab:AΓAA type
Γab:A
Conv-Eq

is derivable.

Proof of Lemma 26.32 — Equality conversion

Proof. Choose x to occur nowhere in Γ,A,A,a,b. The proof repeats the useful part of element conversion. Symmetry of the second premise and Ctx-Conv turn the generic element at A into Γ,x:Ax:A. Now use the first premise in Subst-Eq-Tm, with empty telescope and with the displayed judgment as its second premise:

Γab:A
ΓAA type
ΓAA type
Ty-Sym
ΓA type
Γ,x:Ax:A
Var
Γ,x:Ax:A
Ctx-Conv
Γab:A
Subst-Eq-Tm

The omitted formation leaf ΓA type is the presupposition of ΓAA type. ◻

Exercise 26.11

★★☆ Reconstruct the derivation of lemma 26.32 with every presupposition premise restored, and mark the point at which the type of the generic element is converted.

Lemma 26.33 — Interchange

The rule

ΓB typeΓ,x:A,y:B,ΔJ
Γ,y:B,x:A,ΔJ
Exch

is derivable. (The premise ΓB type records that B does not depend on x.)

Proof of Lemma 26.33 — Interchange

Proof. Let y be globally fresh, and obtain ΓA type from the second premise by lemma 71.31. Rename y to y, weaken by y:B in the correct position, and then substitute y for y. Formally,

ΓB typeΓA type
Γ,y:BA type
Wk
ΓB type
Γ,y:By:B
Var
Γ,y:B,x:Ay:B
Wk
ΓB type
Γ,x:A,y:B,ΔJ
Γ,x:A,y:B,Δ[y/y]J[y/y]
Rename
Γ,y:B,x:A,y:B,Δ[y/y]J[y/y]
Wk
Γ,y:B,x:A,ΔJ
Subst

In the left branch, the inner Wk inserts y:B under A, and the outer Wk appends x:A; in the right branch, Wk inserts y:B between Γ and x:A. The final Subst substitutes y for y; since y is fresh, Δ[y/y][y/y]=Δ and J[y/y][y/y]=J. ◻

Exercise 26.12

★★☆ Call two adjacent declarations in Γ0,x:A,y:B,Γ1 swappable when Γ0B type is derivable. Suppose a permutation of a derivable context is presented as a sequence of adjacent swaps, and each swap is swappable in the context reached at that stage. Use Exch at every stage to transport a derivation of ΓJ to the permuted context. Why would the weaker syntactic test xFV(B) be insufficient?

Lemma 26.34 — General variable rule

The rule

Γ ctx(x:A)Γ
Γx:A
Assum

is derivable, where (x:A)Γ is the side condition that the declaration x:A occurs in Γ.

Proof of Lemma 26.34 — General variable rule

Proof. Write Γ=Γ0,x:A,y1:B1,,ym:Bm. By repeated primitive Presup-Ext and Presup-Ctx steps applied to the context premise, the judgments Γ0A type and Γ0,x:A,y1:B1,,yj1:Bj1Bj type (1jm) are all derivable. Var applied to the first gives Γ0,x:Ax:A, and m successive applications of Wk (with empty telescope), the j-th using the Bj judgment, extend the context one declaration at a time until Γx:A is reached. Formally, induction on m uses the displayed derivation as its base case; the successor case is one Wk whose type-formation premise is the next judgment extracted from context well-formedness. ◻

Exercise 26.13

★★☆ Write out the induction on m in the proof of lemma 26.34, verifying the compressed premises of each Wk step against convention 26.14.

Substitution as a rule and as an operation

Our rules perform substitution and weakening in one step. Both can instead be reconstructed by induction on derivations. That reconstruction is valid only when every added rule behaves uniformly under changes of context. We state this hypothesis exactly before beginning the proof.

Definition 26.35 — Economical presentation

The economical presentation of a type theory over the structural core consists of the rules Ctx-Emp, Ctx-Ext, the equivalence rules of definition 26.16, the rules Assum, Conv, and Conv-Eq of lemma 26.34, lemma 26.31, lemma 26.32, taken as primitive, and the added rules of the theory stated with full premises. The presupposition, context-conversion, substitution, weakening, and Var rules are omitted.

Definition 26.36 — Structurally stable rule schemes

The structural stability of an added rule scheme is the conjunction of the following conditions; a scheme satisfying them is structurally stable.

  1. It does not conclude a context judgment. Its full premises contain the context judgment and every direct presupposition of its conclusion, together with the formation or typing judgments for every expression parameter occurring in the conclusion.

  2. Its ambient contexts are schematic. If one simultaneously inserts a fresh well-formed declaration at the same position in the ambient context of every premise and the conclusion, the result is another instance. The same is true when one simultaneously substitutes an element for an ambient variable, or replaces an ambient declaration by a judgmentally equal one. Local binder names are first freshened away from the inserted or substituted expressions. Repeating the insertion clause gives the same closure for an arbitrary well-formed telescope.

  3. The expression parameters form a classified telescope, possibly with local binders. A type parameter pi has a formation judgment Γipi type; a term parameter has a typing judgment Γipi:Pi. The context Γi, and in the term case Pi, may depend on earlier parameters. The phrase pointwise equal means, respectively, pipi type or pipi:Pi, after the primed classifier and every local context in Γi have been transported along the equalities already obtained for earlier parameters. Every type-formation conclusion F(p) type has the congruence rule concluding F(p)F(p) type from this telescope of equalities. Every term-typing conclusion f(p):F(p) has a term-congruence rule at the unprimed result type; the primed result is first converted along the type congruence.

  4. Every premise and conclusion is well scoped: all of its free variables are declared in its displayed context. The scheme is equivariant under fresh renaming of ambient and local variables; in particular, it contains no distinguished free object variable.

These are syntactic closure conditions on rule instances. In particular, a nullary axiom allowed only in the empty context is not structurally stable: it fails condition 2. Indeed, for a fixed closed C the scheme Xc:Cclosedc has no inserted-context instance x:Ac:C. A weakening induction whose last rule is closed-c therefore stops: the induction hypotheses are empty, and condition 2 has no rule instance concluding x:Ac:C. This is the minimal failure test for structural stability.

Example 26.37 — A stable binding scheme

Add an operator Q of arity (0,1) and the formation scheme

ΓC typeΓ,y:CD type
ΓQ(C;y.D) type
Q-form

Its full instance also contains Γ ctx. Inserting x:A in the ambient context produces the legal instance

Γ,x:AC typeΓ,x:A,y:CD type
Γ,x:AQ(C;y.D) type
Q-form

If instead Γa:E is substituted into an instance over Γ,z:E, choose y away from a by equivariance. The resulting instance is

ΓC[a/z] typeΓ,y:C[a/z]D[a/z] type
ΓQ(C[a/z];y.D[a/z]) type
Q-form

Finally, its dependent congruence rule is

ΓCC typeΓ,y:CDD typeΓ,y:CD type
ΓQ(C;y.D)Q(C;y.D) type
Q-form-eq

The third premise forms the primed body in its own context. The second places that body in the unprimed context and compares the two bodies there, exactly the transport required by condition 3. This is the local-binder case of conditions 2 and 3.

Exercise 26.14

★★☆ Give Q a term constructor q(C;y.d):Q(C;y.D) whose parameter d has type D in Γ,y:C. Write its full typing scheme, its term-congruence scheme at the unprimed Q-type, and the instance obtained from a rule over Γ,z:E by substituting a given Γa:E for z.

Regularity and arbitrary-telescope weakening are proved mutually because the regularity case for Assum needs weakening in a different telescope. Substitution transforms a derivation and its telescope simultaneously; context conversion then compares the transformed contexts. Equal substitution combines these facts with the classified congruence condition.

Lemma 26.38 — Regularity and weakening

In an economical presentation with structurally stable added schemes, the following three assertions hold.

  1. Every direct presupposition rule is admissible.

  2. If Γ,Θ ctx and Γ,ΔJ, then Γ,Θ,ΔJ is derivable whenever the displayed context pieces have pairwise disjoint domains.

  3. Under the same context hypotheses, a derivation of Γ,Δ ctx is transformed into one of Γ,Θ,Δ ctx.

The one-declaration case of clause 2 is Wk.

Proof of Lemma 26.38 — Regularity and weakening

Proof. For each height h, prove simultaneously: (i) every direct presupposition of the conclusion of a derivation of height at most h; (ii) for every split Γ,Δ of its context and every telescope Θ satisfying the displayed hypotheses, the judgment-weakening transformation of clause 2; and (iii) the corresponding context transformation of clause 3. Thus Θ is universally quantified inside the induction hypothesis. The whole well-formed telescope Θ is fixed during one recursive transformation; it is not inserted by repeated appeals to the induction hypothesis. The regularity assertion produces every direct presupposition of the conclusion.

For a context derivation, keep the insertion point between Γ and Δ. If Δ is empty, the target is the fixed derivation of Γ,Θ ctx. If the final Ctx-Ext introduces a declaration in Δ, apply the judgment-weakening induction hypothesis to its sole type premise, inserting the entire Θ, and reapply Ctx-Ext. The regularity induction hypothesis for that same premise gives the transformed prefix context when required. The type premise is also the direct presupposition of the resulting context.

For Assum, weakening the conclusion only enlarges its well-formed context; the same declaration is still present, so Assum applies again. For regularity, write the context as Γ0,y:B,Γ1, where the selected declaration is y:B. A context derivation in the economical system ends in iterated Ctx-Ext; its subtree at this declaration contains Γ0B type. This subtree has smaller height. Apply the telescope-weakening induction hypothesis once, with telescope y:B,Γ1, to obtain Γ0,y:B,Γ1B type, the presupposition of the Assum conclusion. This is the case that forces regularity and weakening to be simultaneous.

For an equivalence rule, Conv, or Conv-Eq, transform all premises and reapply the same rule. Their presuppositions follow from the transformed typing premises, using symmetry where the right side of an equality is required. For an added scheme, condition 2 of definition 26.36 makes the weakened premises another legal instance, and condition 1 gives the direct presuppositions. Condition 4 permits an equivariant choice of local names disjoint from the inserted telescope. These are all final rules. Taking Θ=x:A gives Wk. ◻

Lemma 26.39 — Ordinary substitution in the economical presentation

In an economical presentation with structurally stable added schemes, suppose Γa:A is derivable economically. Then ordinary substitution has both of the following simultaneous clauses:

  1. if Γ,x:A,Δ ctx, then Γ,Δ[a/x] ctx;

  2. if Γ,x:A,ΔJ for any of the four judgment theses, then Γ,Δ[a/x]J[a/x].

Proof of Lemma 26.39 — Ordinary substitution in the economical presentation

Proof. Induct on the second derivation, simultaneously for contexts and all four theses. In a context derivation, a final Ctx-Ext whose declaration lies in Δ is rebuilt from its transformed type premise. If it is the distinguished declaration x:A itself, then Δ is empty: substitution deletes that final Ctx-Ext, leaving Γ ctx, a presupposition of the fixed derivation of a. The equivalence rules, Conv, and Conv-Eq are obtained by transforming their premises and reapplying the same rule. An added scheme is handled in the same way by condition 2 of definition 26.36.

Only Assum requires a calculation. If its selected variable is x, use the fixed derivation of a and weaken it along Δ[a/x] by lemma 26.38. If the variable is declared in Γ, apply Assum there and weaken along the substituted telescope. If it is declared in Δ, its declaration in the new context is precisely the old one with a substituted, so Assum applies directly. These three cases give exactly Γ,Δ[a/x]J[a/x]. A simultaneous rule induction gives the scoping invariant FV(a)dom(Γ): check the economical structural rules directly and use condition 4 for an added rule. Since raw context concatenation makes dom(Γ) and dom(Δ) disjoint, every declared name of Δ already avoids FV(a). Thus the displayed context substitution is defined; no context variable has been renamed. ◻

Lemma 26.40 — Context conversion in the economical presentation

In an economical presentation with structurally stable added schemes, if ΓAA type and Γ,x:A,ΔJ are derivable economically, then so is Γ,x:A,ΔJ. Simultaneously, a derivation of Γ,x:A,Δ ctx is transformed into one of Γ,x:A,Δ ctx.

Proof of Lemma 26.40 — Context conversion in the economical presentation

Proof. Induct simultaneously on context and judgment derivations, keeping the distinguished declaration marked. In a context derivation, a final Ctx-Ext to the left of x:A is retained. To the right, transform both the prefix context recovered from its type premise and the type premise itself before reapplying Ctx-Ext. At the distinguished declaration itself, use the right-hand type presupposition of AA and Ctx-Ext to form Γ,x:A. Transform the premises of every other nonvariable rule and reapply that rule; condition 2 of definition 26.36 gives the added-scheme instances. For Assum, variables declared in Γ or Δ are reintroduced by the same rule. For the distinguished variable, Assum gives x:A in Γ,x:A. Weaken the symmetric equality AA to that context and apply primitive Conv; then weaken along Δ. Thus the transformed variable has the original type A, as the unchanged thesis requires. This completes every final-rule case. ◻

If AA, we may therefore carry any telescope declared after x:A over to the context declaring x:A.

Lemma 26.41 — Equal substitution in the economical presentation

In an economical presentation with structurally stable added schemes, let Γaa:A. Economical derivations of Γ,x:A,ΔB type and Γ,x:A,Δb:B can be transformed respectively into Γ,Δ[a/x]B[a/x]B[a/x] type, and Γ,Δ[a/x]b[a/x]b[a/x]:B[a/x].

Proof of Lemma 26.41 — Equal substitution in the economical presentation

Proof. First form a finite presupposition-expanded derivation. At every node attach, as subsidiary trees, derivations of all direct presuppositions established by lemma 26.38; recursively attach the presuppositions of a nonempty context by peeling its last declaration. The regularity construction uses only proper premise subderivations (in the Assum case, a proper context subtree), while context peeling strictly shortens the context. Hence the expansion is finite and well founded. We induct on the height of this expanded tree, counting the attached subsidiary trees; every premise or presupposition invoked below is then a proper subtree. The telescope Δ is arbitrary and is not part of the measure.

Write Δ=y1:B1,,ym:Bm, and write Δi1 for its first i1 declarations. Simultaneously maintain a third assertion for a context derivation of Γ,x:A,Δ: for every declaration yi:Bi it constructs ()Γ,Δi1[a/x]Bi[a/x]Bi[a/x] type. Before the marked declaration, and at Ctx-Emp, the assertion is empty. At the Ctx-Ext that introduces x:A, substitution removes that declaration and still introduces no clause of (). At a later Ctx-Ext, the context and type premises have smaller height. The context induction hypothesis treats the earlier declarations, and the type induction hypothesis gives the next instance of (). Repeated use of lemma 26.40, with the symmetric orientation of each equality in (), therefore transports every right-hand substituted premise from Δ[a/x] to the common context Δ[a/x]. This explains the common context in both conclusions.

Now inspect a type-formation or term-typing derivation. In the Assum case, ordinary substitution applied to the attached context presupposition Γ,x:A,Δ ctx gives Γ,Δ[a/x] ctx. If the selected variable is x, the fixed equality aa:A is weakened along Δ[a/x]. Any other selected variable is reintroduced in this common context by Assum, and Tm-Refl gives the required equality directly; no conversion through Δ[a/x] is needed. In the Conv case, the induction hypothesis first gives equality of the two substituted terms at the old type. Ordinary substitution of the type-equality premise gives the converted type equality, and primitive Conv-Eq moves the term equality to that type.

For an added formation or typing rule, apply the induction hypotheses to the full typing premises of all expression parameters. Condition 3 of definition 26.36 then gives the displayed type or term equality. Equality premises of the rule are substituted ordinarily on each side; no “equality between equality derivations” is required. A premise under an additional local binder still has smaller derivation height, so the induction hypothesis applies with that binder appended to the arbitrary telescope. For example, a premise Γ,x:A,Δ,y:CD type produces Γ,Δ[a/x],y:C[a/x]D[a/x]D[a/x] type, after the induction hypothesis for the parameter premise has given C[a/x]C[a/x]. This is the binding case that a length-first induction would miss. All recursive calls are to proper premise subderivations, so height induction is well founded. ◻

Equal substitution is the last missing structural operation; all four derivation transformations can now be assembled.

Corollary 26.42 — Simultaneous structural admissibility

In an economical presentation with structurally stable added schemes, the presupposition, weakening, substitution, context-conversion, and equal-substitution rules are admissible.

Proof of Corollary 26.42 — Simultaneous structural admissibility

Theorem 26.43 — Equivalence of presentations

Let T be the structural rules of definition 26.22 extended by structurally stable rule schemes in the sense of definition 26.36, and let T be its economical presentation. Then a judgment is derivable in T if and only if it is derivable in T. In particular, Subst, Wk, Ctx-Conv, and the presupposition rules are admissible in T.

Proof of Theorem 26.43 — Equivalence of presentations

Proof. (TT.) Every primitive rule of T is derivable in T: Assum, Conv, and Conv-Eq by lemma 26.34, lemma 26.31, lemma 26.32; every other primitive rule is shared. Replace each use of a derived primitive by its displayed derivation. Rule induction translates the whole tree.

(TT.) By corollary 26.42, every omitted structural rule has a derivation transformation in T. Translate a T-derivation by rule induction: retain a shared rule and replace each omitted structural rule by the corresponding admissibility transformation. In the Var case, the transformed premise ΓA type first gives Γ,x:A ctx by Ctx-Ext; primitive Assum then gives Γ,x:Ax:A. The transformed premises have already been obtained by the induction hypotheses, so the result is a T-derivation of the same judgment. ◻

The structural-admissibility argument above follows the formulation surveyed by Hofmann [Hof97].

Remark 71.47

Equivalence of structural presentations is not a type-checking algorithm. For each added former a kernel still needs formation and typing generation lemmas, injectivity of type constructors, a terminating and complete conversion procedure (usually obtained from confluence and normalization), and bidirectional rules that expose the input/output modes. The concrete interface must, for example, recover the domain and codomain of a function type from its head constructor, and conversion must decide whether an inferred type agrees with an expected type. This is why a displayed declarative rule set, although complete as a specification, is not yet executable.

Exercise 26.15

★★☆ Verify the direction TT of theorem 26.43 in detail: exhibit each primitive rule of T as a derivable rule of T, and explain why derivability suffices to translate whole derivations.

Remark 26.44

In T the rules Subst and Wk are admissible but are not primitive. The construction in theorem 26.43 is a recursive transformation of an input derivation. Its final-rule case uses exactly the stability interface of definition 26.36; the closed-only axiom above shows the transformation getting stuck when that interface is absent.

Substitution by a whole context

One Subst step removes one declaration. Eliminators for pair-like data must often replace an entire dependent telescope, so we package the elements needed for all declarations and then substitute them in order.

Definition 26.45 — Context substitution

Let Γ,Δ ctx, where Δ=y1:B1,,ym:Bm is a telescope over Γ. A context substitution f:ΓΔ is a list (b1,,bm) such that no yi is free in any bj and Γbj:Bj[b1/y1,,bj1/yj1](1jm).

For example, if Γ,x:A,y:B ctx, Γa:A, and Γb:B[a/x], then (a,b):Γ(x:A,y:B). This is the two-declaration substitution used by dependent pair elimination.

Proposition 26.46 — Substitution by a context

If f:ΓΔ and Γ,ΔJ, then ΓJ[b1/y1,,bm/ym].

Proof of Proposition 26.46 — Substitution by a context

Proof. Substitute b1 for y1. The next declaration becomes y2:B2[b1/y1], exactly the type of b2 in definition 26.45; hence the next Subst applies. Continuing in order removes all m declarations and gives the iterated substitution displayed in the conclusion. Because no inserted bj contains a target variable yi, a structural induction on J identifies this iteration with the one-pass simultaneous substitution of definition 26.10. ◻

The preceding proposition is the null-source case of a more useful relative construction. Suppose that both Γ,Θ and Γ,Δ are contexts, where Δ=y1:B1,,ym:Bm. A relative telescope map f:ΘΓΔ is a list (b1,,bm) satisfying Γ,Θbj:Bj[b1/y1,,bj1/yj1](1jm), where the displayed brackets denote one-pass simultaneous substitution. Source and target telescopes are understood up to alpha-equivalence: before composing distinct maps, choose their nonshared binders disjoint. No freshness condition is imposed on the entries. In particular, when the source is the target, an entry may be the corresponding target variable. Thus f:ΓΔ in definition 26.45 is the case Θ=().

Proposition 71.51 — Identity and composition of telescope maps

Relative telescope maps have the following operations.

  1. The variable list (y1,,ym) is an identity map idΔ:ΔΓΔ.

  2. If f:ΘΓΔ has entries bi and g:ΞΓΘ has entries ck, then fg:=(b1[g],,bm[g]):ΞΓΔ, where bi[g] is simultaneous substitution of the ck for the variables of Θ.

  3. If Γ,ΔJ, then f acts on the judgment by one-pass simultaneous substitution of the entries of f for the variables of Δ. The result is derivable over Γ,Θ, and the action satisfies J[idΔ]=J,(J[f])[g]=J[fg]. Consequently composition is associative and the displayed identities are left and right units, up to alpha-equivalence of raw expressions.

Proof of Proposition 71.51 — Identity and composition of telescope maps

Proof. First choose a representative whose binders avoid every source and target variable and every free variable in the entries of f and g. Structural induction on that representative proves E[idΔ]=E,(E[f])[g]=E[fg] for every raw expression E. At a target variable the second equation is the definition bi[g]=(fg)i; at any other variable both sides leave the variable fixed or apply the same entry of g. An operator case applies the induction hypotheses to all bodies and restores its binder lists. The synchronized-display argument of proposition 26.11.1 makes the calculation independent of the chosen representative.

For the identity, repeated use of Assum gives each yj at the type required by the relative-map definition: substituting each earlier variable for itself fixes Bj. For composition, apply substitution by the whole telescope g to the typing judgment for each bj. The notation (fg)<j/y<j abbreviates substitution of the first j1 components of fg for y1,,yj1. The resulting type is Bj[(fg)<j/y<j], by the raw composition equation just proved. These are exactly the premises required for fg to be a relative telescope map.

For the action on judgments, choose a fresh alpha-copy Δ^ of Δ, disjoint from Γ,Θ and from every entry of f, and rename Γ,ΔJ to Γ,Δ^J^. General weakening now gives Γ,Θ,Δ^J^. Substitute the entries of f for the fresh variables of Δ^ in telescope order. Their typing premises are exactly the renamed telescope types after the preceding substitutions, so repeated Subst yields Γ,ΘJ^[f]; by construction this is the one-pass action J[f]. A second choice of fresh copy gives an alpha-equivalent derivation.

The two displayed action laws are the raw identity and composition equations proved above. Applying the composition equation twice gives (fg)h=f(gh) componentwise; applying the identity clause gives both unit laws. Alpha-equivalence accounts only for the fresh names chosen under binders. ◻

Exercise 26.16

★☆☆ For the two-declaration context substitution (a,b) above, write the two successive instances of Subst that transform Γ,x:A,y:BJ into ΓJ[a/x,b/y]. Indicate where the premise Γb:B[a/x] is used.

If Δ is a standalone context and ΔJ, the standalone form of context substitution follows from proposition 26.46: weaken the context and the judgment by the declarations of Γ in order, obtaining the relative source Γ,ΔJ, and then apply the proposition.

Suggested first pass.

None of these problems is a prerequisite for a later chapter. Begin with exercise 71.17, then complete exercise 71.20.

Exercise 71.17

★★☆ Reconstruct the Assum case of the induction proving general weakening. Suppose the final judgment Γ,Δz:C ends in Assum, and a fresh declaration x:A is inserted immediately after Γ. Separate the case in which the declaration z:C lies in Γ from the case in which Δ=Δ1,z:C,Δ2. In each case, identify the context-formation premise that lets Assum be replayed in the enlarged context.

Exercise 71.18

★★☆ Let Δ=(x:A,y:B(x)), Θ=(u:C,v:D(u)), and Ξ=(w:E) be telescopes over the same base Γ. For f=(b1,b2):ΘΓΔ and g=(c1,c2):ΞΓΘ, write fg componentwise. Derive the type of its second component from Subst. For a further map h:ΩΓΞ, prove associativity by comparing both composites with one-pass capture-avoiding substitution.

Exercise 71.19

★★☆ Consider the tempting definition of a relative telescope map which requires every target variable to be fresh for every component. Apply it to the identity map on Δ=(u:A,v:B(u)). Give the first component at which the definition fails, and explain why alpha-renaming the target before acting on a judgment repairs the proof without imposing this false side condition on the map itself.

Exercise 71.20

★★★ Practical project.dtt-substitution-auditor Implement named-variable capture-avoiding substitution in Agda or Kappa, together with a checker for the local scoping invariant FV(t[u/x])(FV(t){x})FV(u), where the implementation first alpha-renames binders to avoid capture. Test the binder inputs L(y.x)[y/x], L(y.P(x;y))[z/x], and a two-declaration context substitution; the first output must be alpha-equivalent to L(y.y) and every output must pass the scoping checker. Before implementing the checker, perform these three substitutions on paper and mark the binder renaming that prevents capture. These calculations are the finite specification against which the implementation is tested.

Sources. The judgment forms originate with Martin-Löf [ML98, ML84]. Abstract binding trees are developed by Harper [Har16], and the structural-admissibility and context-substitution arguments are treated by Hofmann [Hof97]. The citations record provenance and provide alternative formulations.

Search the book

Type to search the local edition.