h5i

Appendix D

Proof of Consistency

Chapter 14 states that the core system is consistent: no closed term has type Π(P:Sort 0). P\tPi{P}{\Sort{0}}{P} (Theorem 14.5). This appendix gives the full proof, including the standard facts about typing and conversion that the argument uses. It concerns the core system: the rules of Figure 3.1 with the universes of Chapter 13, without the constants of Part II.

The idea

The proof combines a deep theorem with an elementary argument. The deep theorem is strong normalization: every well-typed term reduces to a normal form. Together with subject reduction, it means that if any closed term had type Π(P:Sort 0). P\tPi{P}{\Sort{0}}{P}, a normal closed term would too. The elementary argument is a case analysis showing that no normal closed term can have that type.

The case analysis runs in two rounds. First, the normal form must be a λ\lambda, because nothing else closed and normal can have a Π\Pi type. Second, its body must be a term of type PP in the context P:Sort 0P : \Sort{0}, and no normal term can be, because the only variable in scope has type Sort 0\Sort{0}, which is neither PP nor a function type.

To make the case analysis rigorous, we need to know what the type of a term of each shape looks like (the generation lemma), and that terms of different shapes are never convertible (a consequence of confluence). Those facts are collected first.

Facts about the type system

Besides subject reduction and strong normalization from Chapter 14, the proof uses the following standard properties of Pure Type Systems [Barendregt 1992]. Subject reduction extends from one step to any number of steps by induction on the number of steps.

Lemma D.1 (Standard properties).

(a) Generation. If Γ⊢t:T\Gamma \vdash t : T, then, depending on the shape of tt:

  • if t=xt = x, then (x:A)∈Γ(x : A) \in \Gamma and T≡AT \conv A for some AA;
  • if t=Sort ut = \Sort{u}, then T≡Sort (u+1)T \conv \Sort{(u+1)};
  • if t=Π(x:A). Bt = \tPi{x}{A}{B}, then T≡Sort wT \conv \Sort{w} for some ww;
  • if t=λ(x:A). st = \tLam{x}{A}{s}, then Γ,x:A⊢s:B\Gamma, x : A \vdash s : B and T≡Π(x:A). BT \conv \tPi{x}{A}{B} for some BB;
  • if t=f  at = f\;a, then Γ⊢f:Π(x:A). B\Gamma \vdash f : \tPi{x}{A}{B} and Γ⊢a:A\Gamma \vdash a : A for some xx, AA, and BB.

(b) Confluence. If s≡ts \conv t, then ss and tt reduce to a common term. Consequently: Π(x:A). B≡Π(y:A′). B′\tPi{x}{A}{B} \conv \tPi{y}{A'}{B'} implies A≡A′A \conv A' and B[x↦z]≡B′[y↦z]\subst{B}{x}{z} \conv \subst{B'}{y}{z} for a fresh zz; and no two of a variable, a universe, and a Π\Pi are convertible.

(c) Substitution. If s≡ts \conv t, then s[z↦a]≡t[z↦a]\subst{s}{z}{a} \conv \subst{t}{z}{a}.

Generation is the typing rules read backwards: it says that the only way to type a term of a given shape is the rule for that shape, possibly followed by uses of T-Conv. That is why each case says "T≡…T \conv \ldots" rather than "T=…T = \ldots".

The consequences in (b) hold because a variable and a universe do not reduce at all, a Π\Pi reduces only to a Π\Pi (reduction happens inside its annotation or body, never at its root), and two terms with a common reduct must therefore have the same outermost shape.

Shapes of normal terms

Recall from Chapter 12 that every term is a spine h  a1⋯anh\;a_1 \cdots a_n whose head hh is not an application. The next lemma classifies normal terms by their head. Its role is to leave only four possibilities for the normal form in the main proof, each of which can then be ruled out.

Lemma D.2 (Normal forms). Let nn be a normal term with Γ⊢n:T\Gamma \vdash n : T. Then nn is a universe, a Π\Pi, a λ\lambda, or a neutral term x  a1⋯akx\;a_1 \cdots a_k with k≥0k \ge 0 whose head xx is a variable in dom(Γ)\dom(\Gamma). And if k≥1k \ge 1, then Γ⊢x:C\Gamma \vdash x : C for some CC that is convertible to a Π\Pi.

Write n=h  a1⋯akn = h\;a_1 \cdots a_k with hh not an application.

If k=0k = 0, then n=hn = h is a universe, a Π\Pi, a λ\lambda, or a variable, since those are the only shapes other than application. A variable is in dom(Γ)\dom(\Gamma) by generation.

Let k≥1k \ge 1. Applying the generation lemma for application kk times, from the outside in, shows that every prefix h  a1⋯aih\;a_1 \cdots a_i is typable, and in particular, from the innermost application h  a1h\;a_1, that Γ⊢h:Π(y:A). B\Gamma \vdash h : \tPi{y}{A}{B} for some yy, AA, and BB. Now consider the shape of hh. It is not a λ\lambda, since h  a1h\;a_1 would then be a β\beta-redex inside the normal term nn. It is not a universe or a Π\Pi either: by generation, its type would be convertible to a universe, and by confluence a universe is not convertible to Π(y:A). B\tPi{y}{A}{B}. So hh is a variable xx, which is in dom(Γ)\dom(\Gamma) by generation, and Γ⊢x:Π(y:A). B\Gamma \vdash x : \tPi{y}{A}{B}, which is the required CC.

Proof of Theorem 14.5

Theorem 14.5 (Consistency). There is no closed term tt with ⋅⊢t:Π(P:Sort 0). P\cdot \vdash t : \tPi{P}{\Sort{0}}{P}.

Suppose that ⋅⊢t:Π(P:Sort 0). P\cdot \vdash t : \tPi{P}{\Sort{0}}{P}. By strong normalization, tt reduces to a normal term nn, and by subject reduction, ⋅⊢n:Π(P:Sort 0). P\cdot \vdash n : \tPi{P}{\Sort{0}}{P}. We show that no such nn exists, using Lemma D.2 twice.

The normal form is a λ\lambda. By Lemma D.2, nn is a universe, a Π\Pi, a λ\lambda, or a neutral term.

  • It is not neutral, because its head would be a variable in the empty context, and there is none.
  • It is not a universe or a Π\Pi, because generation would make Π(P:Sort 0). P\tPi{P}{\Sort{0}}{P} convertible to a universe, which confluence rules out.

So n=λ(x:A). sn = \tLam{x}{A}{s}. By generation, x:A⊢s:Bx : A \vdash s : B and Π(P:Sort 0). P≡Π(x:A). B\tPi{P}{\Sort{0}}{P} \conv \tPi{x}{A}{B} for some BB. By confluence, A≡Sort 0A \conv \Sort{0} and P[P↦z]≡B[x↦z]\subst{P}{P}{z} \conv \subst{B}{x}{z} for a fresh zz, that is, z≡B[x↦z]z \conv \subst{B}{x}{z}. Substituting xx for zz on both sides, which preserves convertibility by part (c) of Lemma D.1, gives x≡Bx \conv B. The body ss is normal, because it is a subterm of the normal term nn. In short: x:A⊢s:Bx : A \vdash s : B with A≡Sort 0A \conv \Sort{0} and B≡xB \conv x.

The body cannot exist. Let Γ=x:A\Gamma = x : A. By Lemma D.2, ss is a universe, a Π\Pi, a λ\lambda, or a neutral term.

  • If ss is a universe or a Π\Pi, generation makes BB convertible to a universe; if ss is a λ\lambda, it makes BB convertible to a Π\Pi. But B≡xB \conv x, and by confluence a variable is convertible to neither.
  • If ss is neutral, its head is a variable in dom(Γ)={x}\dom(\Gamma) = \{x\}, so s=x  a1⋯aks = x\;a_1 \cdots a_k. If k=0k = 0, then s=xs = x, and generation gives B≡AB \conv A. Then x≡B≡A≡Sort 0x \conv B \conv A \conv \Sort{0}, but a variable is not convertible to a universe. If k≥1k \ge 1, Lemma D.2 gives Γ⊢x:C\Gamma \vdash x : C with CC convertible to a Π\Pi, and generation for the variable xx gives C≡A≡Sort 0C \conv A \conv \Sort{0}. Then a Π\Pi is convertible to a universe, which confluence rules out.

Every case leads to a contradiction, so no closed term has type Π(P:Sort 0). P\tPi{P}{\Sort{0}}{P}.

In words: the only variable available inside the λ\lambda is xx, whose type is Sort 0\Sort{0}. It can neither be returned, since Sort 0\Sort{0} is not xx, nor be applied to anything, since Sort 0\Sort{0} is not a function type. Every other normal term has a universe or a Π\Pi as its type, and xx is neither. The argument relies on strong normalization to reduce the question to normal terms; that step is where all the difficulty lies.

What to remember

  • Consistency is proved by combining strong normalization and subject reduction (to pass to a normal form) with a case analysis on the shape of normal terms.
  • The case analysis uses two standard facts: generation (the typing rules read backwards) and confluence (terms of different outermost shapes are never convertible).
  • A normal closed term of type Π(P:Sort 0). P\tPi{P}{\Sort{0}}{P} would have to be a λ\lambda whose body has type xx in the context x:Sort 0x : \Sort{0}, and no normal term does.
  • The hard part is strong normalization; the shape analysis alone also applies to Type:Type\mathsf{Type} : \mathsf{Type}, and shows that Hurkens' term has no normal form.