h5i

Appendix C

Hurkens' Paradox

Chapter 13 claimed that a single universe containing itself makes the type theory inconsistent: there is a closed term of type Π(p:Type). p\tPi{p}{\mathsf{Type}}{p}, a proof of everything. This appendix gives that term in full, explains the idea behind it, and shows exactly where the rule Type:Type\mathsf{Type} : \mathsf{Type} is used, so that you can see why the universe hierarchy blocks it.

The setting

Throughout this appendix the universes of the kernel are replaced by one universe Type\mathsf{Type} with the two rules

⊢Γ;okΓ⊢Type:TypeΓ⊢A:TypeΓ,x:A⊢B:TypeΓ⊢Π(x:A). B:Type\dfrac{\ctxok{\Gamma}}{\Gamma \vdash \mathsf{Type} : \mathsf{Type}} \qquad \dfrac{\Gamma \vdash A : \mathsf{Type} \qquad \Gamma, x : A \vdash B : \mathsf{Type}}{\Gamma \vdash \tPi{x}{A}{B} : \mathsf{Type}}

in place of T-Sort and T-Pi. Everything else, including T-Lam, T-App, T-Conv, substitution, and β\beta-reduction, is unchanged. The goal is a closed term tHt_{\mathrm{H}} with

⊢tH:⊥,⊥=Π(p:Type). p.\vdash t_{\mathrm{H}} : \bot, \qquad \bot = \tPi{p}{\mathsf{Type}}{p}.

Such a term proves every proposition CC, because tH  C:Ct_{\mathrm{H}}\;C : C.

The construction is due to Girard, who adapted the Burali-Forti paradox of set theory to the type theory with Type:Type\mathsf{Type} : \mathsf{Type} [Girard 1972]. The term below is Hurkens' simplification [Hurkens 1995], which fits on one page and uses nothing beyond Π\Pi, λ\lambda, and application.

Power sets in type theory

Read a function p:S→Typep : S \to \mathsf{Type} as a predicate on SS, or equivalently as a subset of SS: the elements xx for which p  xp\;x has a proof are the members. The type of all such predicates is the power set of SS:

℘S  =  S→Type.\wp S \;=\; S \to \mathsf{Type}.

Applying this twice, ℘℘S=(S→Type)→Type\wp\wp S = (S \to \mathsf{Type}) \to \mathsf{Type} is the type of families of subsets of SS.

In set theory, Cantor's theorem says that no set contains a copy of its own power set, let alone of its double power set: ℘S\wp S is always strictly larger than SS. The paradox is built on a type UU that violates this. It contains a copy of ℘℘U\wp\wp U, with a function τ:℘℘U→U\tau : \wp\wp U \to U that packs a family of subsets of UU into a single element of UU, and a function σ:U→℘℘U\sigma : U \to \wp\wp U that unpacks it again. The type

U  =  Π(X:Type). ((℘℘X→X)→℘℘X)U \;=\; \tPi{X}{\mathsf{Type}}{\bigl((\wp\wp X \to X) \to \wp\wp X\bigr)}

achieves this by quantifying over all of Type\mathsf{Type}. For UU to be a member of Type\mathsf{Type} while quantifying over Type\mathsf{Type} is exactly what Type:Type\mathsf{Type} : \mathsf{Type} permits and the hierarchy of Chapter 13 forbids.

The term

The following abbreviations are expanded in place; the kernel sees only Π\Pi, λ\lambda, variables, and application. We write ¬φ\neg\varphi for φ→⊥\varphi \to \bot.

⊥=Π(p:Type). p℘S=S→TypeU=Π(X:Type). ((℘℘X→X)→℘℘X)τ=λ(t:℘℘U). λ(X:Type). λ(f:℘℘X→X). λ(p:℘X). t  (λ(x:U). p  (f  (x  X  f)))σ=λ(s:U). s  U  τΔ=λ(y:U). ¬ (Π(p:℘U). σ  y  p→p  (τ  (σ  y)))Ω=τ  (λ(p:℘U). Π(x:U). σ  x  p→p  x)\begin{array}{rcl} \bot &=& \tPi{p}{\mathsf{Type}}{p} \\[4pt] \wp S &=& S \to \mathsf{Type} \\[4pt] U &=& \tPi{X}{\mathsf{Type}}{((\wp\wp X \to X) \to \wp\wp X)} \\[4pt] \tau &=& \tLam{t}{\wp\wp U}{\tLam{X}{\mathsf{Type}}{\tLam{f}{\wp\wp X \to X}{\tLam{p}{\wp X}{t\;(\tLam{x}{U}{p\;(f\;(x\;X\;f))})}}}} \\[4pt] \sigma &=& \tLam{s}{U}{s\;U\;\tau} \\[4pt] \Delta &=& \tLam{y}{U}{\neg\,(\tPi{p}{\wp U}{\sigma\;y\;p \to p\;(\tau\;(\sigma\;y))})} \\[4pt] \Omega &=& \tau\;(\tLam{p}{\wp U}{\tPi{x}{U}{\sigma\;x\;p \to p\;x}}) \end{array}

With these abbreviations, the term of type ⊥\bot is

tH=(λ(h0:Π(p:℘U). (Π(x:U). σ  x  p→p  x)→p  Ω).  h0  Δ  (λ(x:U). λ(h2:σ  x  Δ). λ(h3:Π(p:℘U). σ  x  p→p  (τ  (σ  x))). h3  Δ  h2  (λ(p:℘U). h3  (λ(y:U). p  (τ  (σ  y)))))h0  Δ  (λ(p:℘U). h0  (λ(y:U). p  (τ  (σ  y)))))(λ(p:℘U). λ(h1:Π(x:U). σ  x  p→p  x). h1  Ω  (λ(x:U). h1  (τ  (σ  x))))\begin{array}{rcl} t_{\mathrm{H}} &=& (\lambda (h_0 : \tPi{p}{\wp U}{(\tPi{x}{U}{\sigma\;x\;p \to p\;x}) \to p\;\Omega}).\; \\ && \qquad h_0\;\Delta\;(\tLam{x}{U}{\tLam{h_2}{\sigma\;x\;\Delta}{\tLam{h_3}{\tPi{p}{\wp U}{\sigma\;x\;p \to p\;(\tau\;(\sigma\;x))}}{ h_3\;\Delta\;h_2\;(\tLam{p}{\wp U}{h_3\;(\tLam{y}{U}{p\;(\tau\;(\sigma\;y))})})}}}) \\ && \qquad\phantom{h_0\;\Delta\;}(\tLam{p}{\wp U}{h_0\;(\tLam{y}{U}{p\;(\tau\;(\sigma\;y))})})) \\ && (\tLam{p}{\wp U}{\tLam{h_1}{\tPi{x}{U}{\sigma\;x\;p \to p\;x}}{h_1\;\Omega\;(\tLam{x}{U}{h_1\;(\tau\;(\sigma\;x))})}}) \end{array}

The shape is an application: a λ\lambda binding h0h_0, applied (on the last line) to an argument of the type that h0h_0 expects. Inside, h0h_0 is applied to two arguments, Δ\Delta and a proof about Δ\Delta, and the result is applied to one more argument. Everything is explained below.

How the term works

Packing and unpacking. The two functions τ:℘℘U→U\tau : \wp\wp U \to U and σ:U→℘℘U\sigma : U \to \wp\wp U are inverse enough for the argument. Unfolding the definitions and β\beta-reducing gives, for every t:℘℘Ut : \wp\wp U and p:℘Up : \wp U,

σ  (τ  t)  p  ≡  t  (λ(x:U). p  (τ  (σ  x))).\sigma\;(\tau\;t)\;p \;\conv\; t\;(\tLam{x}{U}{p\;(\tau\;(\sigma\;x))}).

This equation is used by the kernel through T-Conv at several points in tHt_{\mathrm{H}}; it is a computation, not an axiom.

An ordering on UU. Read σ  x  p\sigma\;x\;p as "the predicate pp holds of everything below xx". This gives UU something like an order, and lets us say two things about predicates and elements.

  • A predicate p:℘Up : \wp U is inductive if whenever it holds of everything below xx, it holds of xx: that is, Π(x:U). σ  x  p→p  x\tPi{x}{U}{\sigma\;x\;p \to p\;x}.
  • An element x:Ux : U is well-founded if every inductive predicate holds of xx: that is, Π(p:℘U). (Π(x:U). σ  x  p→p  x)→p  x\tPi{p}{\wp U}{(\tPi{x}{U}{\sigma\;x\;p \to p\;x}) \to p\;x}.

The element Ω\Omega is built to play the part of "the collection of all well-founded elements": it packs the family consisting of all inductive predicates. In Burali-Forti's paradox this is the set of all ordinals, which is itself an ordinal, hence a member of itself, hence not well-founded although all ordinals are.

The three ingredients. Reading tHt_{\mathrm{H}} from the bottom up:

  1. The last line, λ(p:℘U). λ(h1:⋯ ). h1  Ω  (λ(x:U). h1  (τ  (σ  x)))\tLam{p}{\wp U}{\tLam{h_1}{\cdots}{h_1\;\Omega\;(\tLam{x}{U}{h_1\;(\tau\;(\sigma\;x))})}}, proves that Ω\Omega is well-founded. Its type is Π(p:℘U). (Π(x:U). σ  x  p→p  x)→p  Ω\tPi{p}{\wp U}{(\tPi{x}{U}{\sigma\;x\;p \to p\;x}) \to p\;\Omega}, which is the type of h0h_0. So h0h_0 stands for "Ω\Omega is well-founded".
  2. The predicate Δ  y\Delta\;y says "yy is not below itself" (strictly, it speaks of τ  (σ  y)\tau\;(\sigma\;y), which behaves like yy by the equation above). The second argument of h0h_0, the long λ\lambda beginning λ(x:U). λ(h2:⋯ ). ⋯\tLam{x}{U}{\tLam{h_2}{\cdots}{\cdots}}, proves that Δ\Delta is inductive. Hence h0  Δ  (⋯ ):Δ  Ωh_0\;\Delta\;(\cdots) : \Delta\;\Omega, that is, Ω\Omega is not below itself.
  3. The remaining argument, λ(p:℘U). h0  (λ(y:U). p  (τ  (σ  y)))\tLam{p}{\wp U}{h_0\;(\tLam{y}{U}{p\;(\tau\;(\sigma\;y))})}, proves that Ω\Omega is below itself, by applying the well-foundedness of Ω\Omega to a predicate transformed through the packing equation.

Since Δ  Ω\Delta\;\Omega is the negation of "Ω\Omega is below itself", applying the result of step 2 to the result of step 3 yields a term of type ⊥\bot.

Where Type : Type is used

Every typing step in tHt_{\mathrm{H}} is ordinary except one. In σ=λ(s:U). s  U  τ\sigma = \tLam{s}{U}{s\;U\;\tau}, the variable s:Us : U is applied to the type UU itself. The type of ss begins Π(X:Type). ⋯\tPi{X}{\mathsf{Type}}{\cdots}, so T-App requires U:TypeU : \mathsf{Type}. But UU is a Π\Pi type that quantifies over Type\mathsf{Type}, and in a system with a universe hierarchy such a type lives one level above the universe it quantifies over:

Γ⊢Sort u:Sort (u+1)Γ,X:Sort u⊢B:Sort vΓ⊢Π(X:Sort u). B:Sort max⁡(u+1,v)\dfrac{\Gamma \vdash \Sort{u} : \Sort{(u+1)} \qquad \Gamma, X : \Sort{u} \vdash B : \Sort{v}}{\Gamma \vdash \tPi{X}{\Sort{u}}{B} : \Sort{\max(u+1, v)}}

With the T-Pi rule of Chapter 13, UU is in Sort (u+1)\Sort{(u+1)} at best, never in Sort u\Sort{u}, so s  Us\;U is ill typed and σ\sigma cannot be written. The whole construction collapses at this one application. Impredicativity of Sort 0\Sort{0} does not reopen the door: UU has body (℘℘X→X)→℘℘X(\wp\wp X \to X) \to \wp\wp X, whose result ℘℘X\wp\wp X is a function type into a universe and therefore is not a proposition, so imax\mathrm{imax} does not place UU in Sort 0\Sort{0}. Coquand showed that one impredicative universe at the bottom is consistent [Coquand 1988]; Hurkens' term shows that two impredicative levels are already too many [Hurkens 1995].

Reproducing it with the kernel

You can watch the kernel accept and reject this term. The only rule to change is T-Sort, implemented by the Term::Sort(u) case of infer in src/typecheck.rs:

// T-Sort, as shipped: every universe lives in the next one.
Term::Sort(u) => Ok(Term::Sort(u.checked_add(1).ok_or("universe overflow")?)),

Replace the right-hand side by Ok(Term::Sort(*u)), so that Sort 0:Sort 0\Sort{0} : \Sort{0}, and use Sort 0\Sort{0} as Type\mathsf{Type} throughout. Nothing else needs to change: with every type in Sort 0\Sort{0}, the T-Pi rule with imax\mathrm{imax} already assigns Sort 0\Sort{0} to every Π\Pi type, which is the second rule of this appendix. With that one-line change, infer returns exactly Π(p:Sort 0). p\tPi{p}{\Sort{0}}{p} for tHt_{\mathrm{H}}. The unmodified kernel rejects the term with a type mismatch at the application s  Us\;U inside σ\sigma, as predicted above.

Why there is no normal form

Chapter 14 proves consistency of the real system by showing that no normal closed term has type Π(P:Sort 0). P\tPi{P}{\Sort{0}}{P}. The part of that proof that analyses the shapes of normal terms does not use strong normalization and goes through unchanged for Type:Type\mathsf{Type} : \mathsf{Type}. So if tHt_{\mathrm{H}} had a normal form, that normal form would be a closed normal term of type ⊥\bot, which cannot exist. Subject reduction still holds, so reduction cannot escape the type ⊥\bot either. The only remaining possibility is that tHt_{\mathrm{H}} reduces forever: strong normalization fails, and with it the termination of the type checker. Girard's paradox is therefore not only a logical defect but a computational one, and it is the reason the design of universes in Chapter 13 matters for the algorithm as much as for the logic.

What to remember

  • With Type:Type\mathsf{Type} : \mathsf{Type}, the type UU quantifies over all types while being one of them, so it contains a copy of its own double power set, which no set can do.
  • Hurkens' term tHt_{\mathrm{H}} turns this into Burali-Forti's paradox: Ω\Omega, the packed family of all inductive predicates, is both well-founded and below itself.
  • The rule Type:Type\mathsf{Type} : \mathsf{Type} is used in exactly one place, the application s  Us\;U in σ\sigma; a universe hierarchy makes that application ill typed.
  • The term has no normal form, so the paradox breaks termination of the kernel as well as consistency.