h5i

Chapter 13

Universes: Why Sort u?

Chapter 4 showed that the typing rules implement a logic, and that the system is acceptable only if it is consistent. This chapter asks a question that has been deferred since Chapter 2: what is the type of Sort 0\Sort{0}? The simplest answer, a single universe that contains itself, makes the system inconsistent. Lean's answer, a hierarchy Sort 0:Sort 1:Sort 2:⋯\Sort{0} : \Sort{1} : \Sort{2} : \cdots with an impredicative bottom universe, does not. Along the way the chapter explains the one odd-looking piece of T-Pi, the function imax\imax.

What is the type of Sort 0?

A proposition variable appears in the type theory as an assumption P:Sort 0P : \Sort{0}. It can occur in two places: in a context, as in the left judgment below, or bound by λ\lambda or Π\Pi, as in the right one:

P:Sort 0⊢λ(h:P). h:P→Pversus⊢λ(P:Sort 0). λ(h:P). h:Π(P:Sort 0). P→P.P : \Sort{0} \vdash \tLam{h}{P}{h} : P \to P \qquad\text{versus}\qquad \vdash \tLam{P}{\Sort{0}}{\tLam{h}{P}{h}} : \tPi{P}{\Sort{0}}{P \to P}.

The left judgment proves P→PP \to P for one fixed PP supplied from outside. The right one is a single closed term that proves it for every PP, and it can be applied later to any particular proposition; this is what the ∀\forall rows of Figure 4.1 need.

Both forms require Sort 0\Sort{0} to be a type. C-Ext, which adds P:Sort 0P : \Sort{0} to a context, and T-Lam and T-Pi, which bind P:Sort 0P : \Sort{0}, all have the premise Γ⊢A:Sort u\Gamma \vdash A : \Sort{u} for the type AA of the new variable. With A=Sort 0A = \Sort{0}, this premise reads Γ⊢Sort 0:Sort u\Gamma \vdash \Sort{0} : \Sort{u} for some uu: the universe of propositions must itself have a type. The question is which.

Type is not a type

Suppose we replace all universes by a single universe Type\mathsf{Type} that contains itself:

⊢Γ;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}}

Translate ∀P. φ\forall P.\,\varphi as Π(P:Type). φ∗\tPi{P}{\mathsf{Type}}{\varphi^\ast}. Then PP ranges over a collection that contains Type\mathsf{Type} itself and every type built from it. Such a collection is the type-theoretic analogue of the set of all sets, and naive set theory shows that such collections lead to contradictions. The best-known example is Russell's paradox: for R={ x∣x∉x }R = \{\, x \mid x \notin x \,\}, both R∈RR \in R and R∉RR \notin R lead to a contradiction.

Type theory has no membership test like x∉xx \notin x, so Russell's argument does not carry over word for word. Girard instead adapted a related paradox about the collection of all well-orderings, due to Burali-Forti [Girard 1972], and Hurkens simplified the resulting term [Hurkens 1995]. The result is a closed term tHt_{\mathrm{H}} with

⊢tH:Π(P:Type). P,\vdash t_{\mathrm{H}} : \tPi{P}{\mathsf{Type}}{P},

so the system is inconsistent: ⊥\bot has no proof, yet ⊥∗\bot^\ast has a term, and a kernel built on these rules accepts a proof of every statement. The essential ingredient is a type UU that quantifies over all of Type\mathsf{Type} while being a member of Type\mathsf{Type}, which lets UU contain a copy of its own double power set, something no set can do. Appendix C gives tHt_{\mathrm{H}} in full, explains how it works, and shows how to reproduce the result by changing one line of the kernel.

The damage reaches the algorithm as well. Subject reduction still holds, so if tHt_{\mathrm{H}} had a normal form, it would be a normal closed term of type Π(p:Type). p\tPi{p}{\mathsf{Type}}{p}. The part of the consistency proof in Appendix D that analyses normal terms does not use strong normalization and carries over to Type:Type\mathsf{Type} : \mathsf{Type}; it shows that no such normal term exists. Hence tHt_{\mathrm{H}} has no normal form, strong normalization fails, and Normalize\Normalize runs forever on it. A kernel with Type:Type\mathsf{Type} : \mathsf{Type} is not only unsound but also, on some inputs, non-terminating.

A hierarchy with an impredicative bottom

The second answer is that Sort 0\Sort{0} lives in a larger universe, which lives in a larger one still:

⊢Γ;okΓ⊢Sort u:Sort (u+1);(T-Sort)soSort 0:Sort 1:Sort 2:⋯ .\dfrac{\ctxok{\Gamma}}{\Gamma \vdash \Sort{u} : \Sort{(u+1)}}\rulename{T-Sort} \qquad\text{so}\qquad \Sort{0} : \Sort{1} : \Sort{2} : \cdots.

No universe contains itself. A Π\Pi-type takes an argument from one universe and returns a type in another, so T-Pi must also say which universe the Π\Pi-type itself belongs to. Lean's answer uses the function imax\imax:

Γ⊢A:Sort uΓ,x:A⊢B:Sort vΓ⊢Π(x:A). B:Sort imax(u,v);(T-Pi)imax(u,v)={0if v=0,max⁡(u,v)otherwise.\dfrac{\Gamma \vdash A : \Sort{u} \qquad \Gamma, x : A \vdash B : \Sort{v}}{\Gamma \vdash \tPi{x}{A}{B} : \Sort{\imax(u, v)}}\rulename{T-Pi} \qquad \imax(u, v) = \begin{cases} 0 & \text{if } v = 0, \\ \max(u, v) & \text{otherwise.} \end{cases}

The case split in imax\imax makes a Π\Pi-type impredicative when its body is a proposition, and predicative otherwise. Pick the universes of AA and BB below and watch where the Π\Pi-type lands.

Propositions are impredicative. If the body BB is a proposition (v=0v = 0), the whole Π\Pi is a proposition, whatever it quantifies over. In particular (∀P. φ)∗=Π(P:Sort 0). φ∗(\forall P.\,\varphi)^\ast = \tPi{P}{\Sort{0}}{\varphi^\ast} is in Sort 0\Sort{0}, although it quantifies over all of Sort 0\Sort{0}. A universe that contains types quantifying over itself is called impredicative. Because every translated formula lies in Sort 0\Sort{0}, the premise ψ∗:Sort 0\psi^\ast : \Sort{0} of ∀\forall-elim always holds, so a universal statement can be instantiated with any proposition, even with itself. For example, with id=λ(P:Sort 0). λ(h:P). h\mathit{id} = \tLam{P}{\Sort{0}}{\tLam{h}{P}{h}},

id:Π(P:Sort 0). P→PandΠ(P:Sort 0). P→P:Sort 0,\mathit{id} : \tPi{P}{\Sort{0}}{P \to P} \qquad\text{and}\qquad \tPi{P}{\Sort{0}}{P \to P} : \Sort{0},

so id  (Π(P:Sort 0). P→P)  id\mathit{id}\;(\tPi{P}{\Sort{0}}{P \to P})\;\mathit{id} is well typed, with type Π(P:Sort 0). P→P\tPi{P}{\Sort{0}}{P \to P}. The same case makes ∀n:Nat, n+0=n\forall n : \Nat,\, n + 0 = n a proposition, even though Nat\Nat lives in Sort 1\Sort{1}; Chapter 7 relied on this for induction.

# "Every proposition implies itself" is itself a proposition,
# so it can be instantiated with itself.
def id : forall (P : Sort 0), P -> P := fun (P : Sort 0) => fun (h : P) => h
def self : forall (P : Sort 0), P -> P := id (forall (P : Sort 0), P -> P) id

# The analogous statement one level up is NOT its own instance:
# forall (A : Sort 1), A -> A lives in Sort 2, not Sort 1.
def idT : forall (A : Sort 1), A -> A := fun (A : Sort 1) => fun (a : A) => a
def selfT : forall (A : Sort 1), A -> A := idT (forall (A : Sort 1), A -> A) idT

Types are predicative. If the body is not a proposition (v≥1v \ge 1), the Π\Pi lives in the larger of the two universes. A type that quantifies over Sort u\Sort{u} then lives in Sort (max⁡(u+1,v))\Sort{(\max(u+1, v))}, which is never Sort u\Sort{u}:

Γ⊢Sort u:Sort (u+1);(T-Sort)Γ,x:Sort u⊢B:Sort vΓ⊢Π(x:Sort u). B:Sort (max⁡(u+1,v));(T-Pi)\dfrac{ \dfrac{}{\Gamma \vdash \Sort{u} : \Sort{(u+1)}}\rulename{T-Sort} \qquad \Gamma, x : \Sort{u} \vdash B : \Sort{v} }{\Gamma \vdash \tPi{x}{\Sort{u}}{B} : \Sort{(\max(u+1, v))}}\rulename{T-Pi}

This property is called predicativity. For example, the identity on types λ(A:Sort 1). λ(a:A). a\tLam{A}{\Sort{1}}{\tLam{a}{A}{a}} has type Π(A:Sort 1). A→A\tPi{A}{\Sort{1}}{A \to A}, which lives in Sort 2\Sort{2}, so it cannot be applied to its own type; a copy at Sort 2\Sort{2} can. Each level holds the level beneath it, and in practice a few levels suffice; higher levels appear when one quantifies over large collections, such as the category of all small categories.

Why this is safe. Impredicativity looks like the self-reference that the previous section warned against, but it is confined: Sort 0\Sort{0} contains types that quantify over Sort 0\Sort{0}, yet Sort 0\Sort{0} is not a member of itself. Coquand showed that one impredicative universe at the bottom is consistent [Coquand 1988], whereas Girard's paradox can already be derived once two levels are impredicative [Hurkens 1995]. With these rules the system is consistent and strongly normalizing (Chapter 14).

Comparison with Lean

In Lean [de Moura and Ullrich 2021], Sort 0\Sort{0} is Prop, Sort (u+1)\Sort{(u+1)} is Type u, and Π\Pi-types are assigned universes with imax\imax as above. Two differences remain.

First, Prop in Lean has definitional proof irrelevance: any two proofs of the same proposition are definitionally equal. Our conversion does not identify proofs; adding this would make conversion depend on types, so the simple "normalize and compare" check of Chapter 12 would no longer suffice.

Second, Lean has universe polymorphism, so definitions can be stated once for all levels uu, and imax\imax then matters for level variables as well, with constraints such as imax(u,v)≤w\imax(u, v) \le w solved symbolically. In our system every level is a concrete number.

The table summarizes the design space.

Design Quantifies over Drawback
No universes values only cannot say "for every proposition"
Type:Type\mathsf{Type} : \mathsf{Type} everything inconsistent
Two sorts ∗:□\ast : \square ∗\ast only □\square itself has no type
Sort u:Sort (u+1)\Sort{u} : \Sort{(u+1)} with max⁡\max any level ∀\forall over propositions is not a proposition
Sort u:Sort (u+1)\Sort{u} : \Sort{(u+1)} with imax\imax (Lean) any level normalization is harder to prove

Exercises

Compute the universe of Π(A:Sort 1). Π(P:A→Sort 0). Π(a:A). P  a\tPi{A}{\Sort{1}}{\tPi{P}{A \to \Sort{0}}{\tPi{a}{A}{P\;a}}}, the statement "every predicate on every type holds everywhere" (which is false but well formed).

Solution

Innermost: P  a:Sort 0P\;a : \Sort{0}, so Π(a:A). P  a:Sort imax(1,0)=Sort 0\tPi{a}{A}{P\;a} : \Sort{\imax(1, 0)} = \Sort{0}. Next, A→Sort 0A \to \Sort{0} has universe imax(1,1)=1\imax(1, 1) = 1 (its body Sort 0\Sort{0} has type Sort 1\Sort{1}), so the middle Π\Pi has universe imax(1,0)=0\imax(1, 0) = 0. Finally Sort 1:Sort 2\Sort{1} : \Sort{2} and the body is in Sort 0\Sort{0}, giving imax(2,0)=0\imax(2, 0) = 0. The whole statement is a proposition. With max⁡\max instead of imax\imax it would land in Sort 2\Sort{2}.

Explain why the selfT definition in the playground is rejected, by naming the rule and the two universes involved.

Solution

idT expects an argument A:Sort 1A : \Sort{1}. The argument supplied is Π(A:Sort 1). A→A\tPi{A}{\Sort{1}}{A \to A}, whose universe by T-Pi is max⁡(2,1)=2\max(2, 1) = 2, so Check\Check compares Sort 2\Sort{2} with Sort 1\Sort{1} and fails: the kernel reports a type mismatch at the application. This is predicativity: a type that quantifies over Sort 1\Sort{1} is not in Sort 1\Sort{1}.

What to remember

  • Sort 0\Sort{0} needs a type, because proposition variables are bound by λ\lambda and Π\Pi.
  • A universe containing itself is inconsistent (Girard, Hurkens) and breaks normalization.
  • The hierarchy Sort u:Sort (u+1)\Sort{u} : \Sort{(u+1)} avoids self-containment; imax\imax makes propositions impredicative and everything else predicative.
  • One impredicative universe at the bottom is safe; two are not. Lean adds proof irrelevance and universe polymorphism on top of the same design.