Lecture 1 ended with a promise and a debt. The promise: a proof is a term, and the kernel checks it by type checking. The debt: three phrases were left vague. Types “compute to the same thing”; the kernel is “small”; classical logic is “added by axioms”. This lecture pays the debt. It describes the type theory that Lean’s kernel implements, a dependent type theory with universes and inductive types, closely related to the calculus of inductive constructions behind Rocq.
By the end you should be able to say what Prop, Type and Sort are and why Type : Type is
refused; read the type of a recursor; predict whether rfl will work, by naming the reduction
it needs; say what rw actually builds; and list everything you trust when Lean accepts a
theorem. All code below runs in core Lean, with no imports.
Notebook and cheatsheet
Notebook 2: The kernel and definitional equality runs each reduction, builds addition from the recursor by hand, and audits axioms, including a
native_decideproof. Cheatsheet: Universes, Inductive types and recursors, Definitional equality, Equality, Axioms and the trusted base, The elaborator.
Universes and dependent functions
Every term has a type, and types are terms, so types have types too. A type whose terms are types is called a universe. Lean has one sequence of them:
Definition 2.1 (Universes).For each universe level
there is a universe , and . Two names are abbreviations: , the universe of propositions, and , the universes of data; alone means .
Lean confirms the abbreviations of the universes definition (Definition 2.1) by printing
Sort 0 as Prop:
#check Prop -- Prop : Type
#check Type -- Type : Type 1
#check Type 1 -- Type 1 : Type 2
#check Sort 0 -- Prop : Type
#check Sort 1 -- Type : Type 1Why a ladder, and not one universe that contains itself? Because Type : Type makes the logic
inconsistent. Jean-Yves Girard showed in 1972 that a type theory with a type of all types can
encode a version of the Burali-Forti paradox about the ordinal of all ordinals, and so build a
term of type False; Hurkens later found a short version
(1995). Lean refuses the judgment outright:
#check (Type : Type)The error reads Type mismatch: Type has type Type 1 of sort Type 2 but is expected to
have type Type of sort Type 1. To avoid writing every definition once per level, Lean lets a
definition take a universe variable. @id below has type {α : Sort u_1} → α → α: one
identity function for every level at once.
The second ingredient is the dependent function type. In (x : A) → B, the result type B may
mention the argument x. When B does not mention x, this is the ordinary arrow A → B.
When B is a proposition, Lean writes it ∀ x : A, B. These are not three constructions but
one, which the type theory calls a Π-type, and Lean will confirm that the two spellings are the
same term:
#check ∀ (p : Prop), p -- ∀ (p : Prop), p : Prop
#check (α : Type) → α → α -- (α : Type) → α → α : Type 1
#check @id -- @id : {α : Sort u_1} → α → α
example : (∀ n : Nat, n = n) = ((n : Nat) → n = n) := rflLook at the universes in the first two lines. The type of a Π-type is computed from the universes of its parts:
Definition 2.2 (The universe of a Π-type).If
and (where may mention ), then , where if , and otherwise.
The rule for the universe of a Π-type (Definition 2.2) says that a ∀ whose body is a
proposition is itself a proposition, however large the domain. So ∀ (p : Prop), p is in Prop
even though it quantifies over all of Prop, including itself. This is called impredicativity,
and it is what lets you state ∀ p : Prop, p ∨ ¬p as an ordinary proposition. For data the rule
is predicative: quantifying over Type produces something in Type 1, one level up. The
figure shows both.
Impredicativity is safe because Prop is kept separate from data. The key rule is
restricted elimination: you may not, in general, use a proof to compute data. Without it, an
impredicative Prop makes Girard’s paradox provable (Coquand, 1986). The recursor of Exists
(recursors are next) shows the restriction in its type: its motive must land in Prop. Lean
adds a second rule, proof irrelevance: any two proofs of the same proposition are
definitionally equal, so a proof carries no information beyond the fact that it exists. That
rule is a design choice, not a safety condition (Rocq’s Prop is impredicative without it),
and together with impredicativity it is behind the undecidability of definitional equality
mentioned in Lecture 1.
#check @Exists.rec@Exists.rec : ∀ {α : Sort u_1} {p : α → Prop} {motive : Exists p → Prop},
(∀ (w : α) (h : p w), motive ⋯) → ∀ (t : Exists p), motive tThat is why Lecture 1 could not extract the witness of an ∃ as a number. (The ⋯ stands for
a proof term that Lean’s printer hides.)
Inductive types and recursors
Apart from universes, Π-types and the quotient types met below, every type in Lean is
inductive: declared by listing its constructors. Nat, List, And, Or, Exists,
False and Eq are all ordinary inductive declarations. (For Nat the kernel also has fast
arithmetic on numerals, but the type is declared like any other.) When the kernel accepts one, it checks
that the declaration is well formed (for example, that the type being defined never appears to
the left of an arrow in a constructor’s argument, a condition called strict positivity) and
then generates a recursor: the single principle for using a term of that type.
#print Nat
#check @Nat.recinductive Nat : Type
number of parameters: 0
constructors:
Nat.zero : Nat
Nat.succ : Nat → Nat
@Nat.rec : {motive : Nat → Sort u_1} → motive Nat.zero →
((n : Nat) → motive n → motive n.succ) → (t : Nat) → motive t(The second-to-last line was wrapped here to fit the page.)
Definition 2.3 (Recursor and motive).The recursor of an inductive type
takes a motive , one minor premise per constructor saying how to build of that constructor from of its recursive arguments, and a target ; it returns a term of type . Applied to a constructor, it reduces to the matching minor premise (this is ι-reduction).
In plain words, the motive of the recursor (Definition 2.3) is what you want to build for each
n, and it may depend on n. For Nat.rec, you supply a value for zero and a way to turn a
value for n into one for n + 1; the recursor then delivers a value for every n.
The same recursor is both primitive recursion and induction. With a motive into Type it
defines functions. Here is addition, written with no pattern matching at all:
def my_add (m n : Nat) : Nat :=
Nat.rec (motive := fun _ => Nat) m (fun _ acc => acc + 1) n
example : my_add 2 3 = 5 := rflThe motive is constantly Nat; the zero case returns m; the step adds one to the previous
result. rfl works because the kernel unfolds my_add 2 3 and lets the recursor meet the
constructors of 3, three times.
With a motive into Prop, the same recursor proves things, and then it is the induction
principle. The motive below is the statement 0 + k = k; the zero case is rfl, and the step
turns a proof for k into one for k + 1:
theorem my_zero_add (n : Nat) : 0 + n = n :=
Nat.rec (motive := fun k => 0 + k = k) rfl
(fun _ ih => congrArg Nat.succ ih) nThe induction tactic of Lecture 4 writes exactly this kind of term for you, and match and
recursive definitions are compiled down to recursors before the kernel sees them.
Definitional equality
Lecture 1 said the kernel accepts rfl : 2 + 2 = 4 because both sides “compute to the same
thing”. Here is what computing means.
Definition 2.4 (Definitional equality).Two terms are definitionally equal when the kernel can make them identical (up to renaming bound variables) mainly by these steps, applied anywhere inside a term:
- β (beta): apply a function to its argument,
; - δ (delta): unfold a definition to its body;
- ι (iota): a recursor applied to a constructor takes the matching minor premise;
- ζ (zeta): replace a local
letby its value;- η (eta):
is equal to , and a structure value pis equal to its fields put back together,⟨p.1, p.2⟩;- proof irrelevance: any two proofs of the same proposition are equal.
The kernel also treats any two values of a one-value type such as
Unitas equal, reducesQuot.liftapplied toQuot.mk, and computes with numerals directly instead of unfoldingNat.succ.
rfl : a = b type-checks exactly when a and b are definitionally equal (Definition 2.4). Each
line below needs one step (plus δ to unfold notation such as +):
-- β: apply the function
example : (fun x : Nat => x + 1) 2 = 3 := rfl
-- δ: unfold a definition
def double (n : Nat) : Nat := n + n
example : double 3 = 6 := rfl
-- ι: the recursor in my_add meets the constructor zero
example (m : Nat) : my_add m 0 = m := rfl
-- ζ: substitute the let
example : (let x := 2; x + x) = 4 := rfl
-- η: a function equals its own wrapper
example (f : Nat → Nat) : (fun x => f x) = f := rfl
-- proof irrelevance
example (p : Prop) (h1 h2 : p) : h1 = h2 := rflNow the example that every Lean user meets in the first week. Core Lean defines addition by
recursion on the second argument: n + 0 = n and n + (m + 1) = (n + m) + 1. So n + 0
reduces to n even when n is a variable, by δ and ι:
example (n : Nat) : n + 0 = n := rflBut 0 + n does not reduce. The recursor inside + is waiting for the second argument to be a
constructor, and here it is the variable n. The computation is stuck, so rfl fails:
example (n : Nat) : 0 + n = n := rflLean reports Type mismatch: rfl has type ?m.9 = ?m.9 but is expected to have type
0 + n = n. The statement is true; it simply needs induction (my_zero_add above), not
computation. Definitional equality is a fact about the definitions, not about the
mathematics: change how + is defined and the two examples trade places. (As Lecture 1 noted,
the full relation is undecidable, so the kernel’s check is sound but incomplete.)
The tactic decide uses the same machinery for closed statements. If a proposition P has a
Decidable instance, a small program that computes whether P holds, decide asks the kernel
to evaluate it to true by reduction. We return to it in the section on trust.
Equality and the axioms
Equality itself is an inductive type with one constructor:
#print Eqinductive Eq.{u_1} : {α : Sort u_1} → α → α → Prop
number of parameters: 2
constructors:
Eq.refl : ∀ {α : Sort u_1} (a : α), a = aThe only constructor of Eq is Eq.refl a, which has type a = a, so rfl checks exactly
when b is definitionally equal to a. (The axioms propext and Quot.sound, below, are the
only other sources of equations.) The recursor of Eq is substitution: from
h : a = b and a proof of motive a, get a proof of motive b. In Lean that is Eq.subst,
written h ▸ e. Rewriting is built on it. Here is what the rw tactic writes:
theorem rw_demo (a b : Nat) (h : a = b) : a + 1 = b + 1 := by
rw [h]
#print rw_demotheorem rw_demo : ∀ (a b : Nat), a = b → a + 1 = b + 1 :=
fun a b h ↦ Eq.mpr (id (congrArg (fun _a ↦ _a + 1 = b + 1) h)) (Eq.refl (b + 1))Read it from the inside. congrArg turns h : a = b into an equation between the goals
(a + 1 = b + 1) = (b + 1 = b + 1); Eq.mpr uses that to reduce the original goal to the
rewritten one; and the rewritten goal is closed by Eq.refl (b + 1), because rw tries rfl
at the end. A tactic proof is still just a term, built from the recursor of an ordinary
inductive type.
Everything so far is the core theory. Lean adds exactly three axioms, which Mathlib uses freely:
#check @propext
#check @Quot.sound
#check @Classical.choice@propext : ∀ {a b : Prop}, (a ↔ b) → a = b
@Quot.sound : ∀ {α : Sort u_1} {r : α → α → Prop} {a b : α},
r a b → Quot.mk r a = Quot.mk r b
@Classical.choice : {α : Sort u_1} → Nonempty α → α(The Quot.sound line is wrapped here to fit the page.) In words: propositional extensionality says that logically equivalent propositions are
equal. Quot.sound says that related elements become equal in a quotient; the quotient
type Quot itself is built into the kernel, one of its few extensions beyond inductive types.
Choice turns a mere proof that a type is nonempty into an element of it, with no
computational content. Two theorems show how they spread:
#print axioms funext -- 'funext' depends on axioms: [Quot.sound]
#print axioms my_zero_add -- 'my_zero_add' does not depend on any axiomsFunction extensionality, (∀ x, f x = g x) → f = g, is not an axiom in Lean; it is a theorem,
proved from quotients. And excluded middle is a theorem too: core Lean proves Classical.em
from all three axioms by an argument of Diaconescu, so #print axioms Classical.em lists
propext, Classical.choice and Quot.sound.
Remark 2.1 (Why these three are trusted).Mario Carneiro’s thesis builds a set-theoretic model of Lean’s type theory with these axioms and derives its consistency relative to ZFC plus, for each
, inaccessible cardinals (2019). That argument is on paper, for Lean 3; in later work Carneiro reports an error in one lemma it relies on, unique typing, which is now stated as a conjecture (Lean4Lean, TYPES 2025). No one expects a problem, but “the logic is sound” is an assumption, not a checked fact.
Why the standard axioms are trusted (Remark 2.1) also tells you what to look for in
an audit: any axiom other than these three, and sorryAx, which marks an unfinished proof.
The elaborator, the kernel, and what you trust
What you type is not what the kernel checks. Between them sits the elaborator, a large
program that turns surface syntax into a fully explicit term. It inserts implicit arguments as
metavariables (placeholders such as ?m.9 in the error above) and solves them by
unification, matching types against each other. It finds type-class instances, which is how
+ on Nat comes to mean Nat.add. It runs every tactic, and compiles match and recursion
into recursors. When it cannot fill a hole, it says so:
example (n : Nat) : Nat := n + _Lean reports don’t know how to synthesize placeholder, and shows the context n : Nat ⊢ Nat
the hole needed. The option pp.all prints a term the way the kernel receives it, with every
implicit argument, instance and universe level written out:
#synth Add Nat -- instAddNat
set_option pp.all true in
#check (2 : Nat) + 2 = 4@Eq.{1} Nat
(@HAdd.hAdd.{0, 0, 0} Nat Nat Nat (@instHAdd.{0} Nat instAddNat)
(@OfNat.ofNat.{0} Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))
(@OfNat.ofNat.{0} Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))
(@OfNat.ofNat.{0} Nat (nat_lit 4) (instOfNatNat (nat_lit 4))) : PropThe kernel knows nothing about tactics, notation, unification or type classes. It infers types
with one rule per term former, decides definitional equality, and checks new inductive
declarations. If the elaborator produces a wrong term t, the kernel rejects it, so a bug in
how a proof is elaborated can make Lean refuse a correct proof, but not accept a false one.
Two things escape this check. First, the elaborator also builds the statement T from your
text. If notation, a macro or a bug gives T a different meaning, the kernel checks a proof of
that other statement. Here a local macro turns = into ≤:
section
local macro_rules | `($a = $b) => `($a ≤ $b)
theorem looks_false : 2 + 2 = 5 := by decide
end
#check looks_falseThe file says 2 + 2 = 5, there is no error, and #check prints
looks_false : 2 + 2 ≤ 5: the kernel checked a true statement about ≤. Here the printer gives
it away, but an unexpander (Lecture 11) can make it print = as well; then only
set_option pp.notation false shows LE.le (HAdd.hAdd 2 2) 5. This is why the statement is
in the trusted computing base as Lean elaborated it, not as you typed it. Second, Lean code
that runs during elaboration can add a declaration without sending it to the kernel at all.
Lecture 11 shows this, and leanchecker, below, catches it.
Definition 2.5 (Trusted computing base).The trusted computing base of a Lean theorem is what must be right for “Lean accepted it” to mean “it is true”: the soundness of the type theory and its axioms, the kernel’s implementation, the software and hardware running the kernel, and the statement as Lean elaborated it, including its notation and coercions, which only a human can compare with what was meant.
Each part of the trusted computing base (Definition 2.5) can be checked further. The Lean reference
manual sets out an escalating sequence (Validating a Lean
Proof): the editor’s check
marks; #print axioms; replaying the compiled files through the kernel with leanchecker,
which ships with every Lean toolchain since v4.28.0
(lean4checker README); and, as the “gold
standard”, building the proof in a sandbox and re-checking it against a trusted statement with
lake comparator. Comparator can replay the proof through Lean’s own kernel and through
nanoda, an independent checker written in Rust by Chris Bailey
(repo). Another is Lean4Lean, a kernel written in Lean
by Carneiro (repo; its README warns that it follows the
C++ kernel closely and may share its bugs). The Lean 4.35.0 toolchain used in this course ships
both, and on Linux lake check --paranoid runs them. A real case: when Anthropic’s Fermat’s
Last Theorem proof appeared on 2026-09-04, Kevin Buzzard compiled it and ran Comparator himself
(VERIFIED; Xena blog).
Remark 2.2 (The native_decide caveat).
decidemakes the kernel evaluate a decision procedure, so the kernel checks the answer.native_decidecompiles the procedure to machine code, runs it, and, if the answer istrue, adds a new axiom asserting that answer. The compiler, the runtime and any code they call join the trusted computing base, and the kernel never sees the computation.
The native_decide caveat (Remark 2.2) is visible to #print axioms:
theorem small_dec : 10 < 20 := by decide
theorem small_native : 10 < 20 := by native_decide
#print axioms small_dec
#print axioms small_nativeThe first proof does not depend on any axioms. The second depends on
small_native._native.native_decide.ax_1, an axiom whose statement is
decide (10 < 20) = true. The reference manual’s rule of thumb: an axiom with _native in its
name means native evaluation was used. lake check rejects any such non-standard axiom (it runs
only on Linux, because it sandboxes the build with bubblewrap; on macOS, read #print axioms).
Try this
- Predict, then check with
rfl:my_add 0 0 = 0,my_add 0 5 = 5,∀ n, my_add n 0 = nand∀ n, my_add 0 n = n. Name the reduction behind each one that works, and prove the one that fails withNat.rec, as inmy_zero_add. rflproves(fun n : Nat => n + 0) = (fun n => n)but not the same equation with0 + n. Which reductions make the first work under thefun, and what does the second need instead?- Run
#check @List.recand#check @Or.rec, and read off the motive and the minor premises. Why can the motive ofOr.reconly land inProp? - The audit table in Notebook 2 shows that the
omegaproof ofa + b = b + ausespropextandQuot.sound. Write a proof of the same statement that uses no axioms, and confirm it with#print axioms.
Readings
- Avigad, de Moura, Kong and Ullrich, Theorem Proving in Lean 4: Dependent Type Theory, Inductive Types and Axioms and Computation.
- The Lean Language Reference: The Type System and Validating a Lean Proof.
- Chris Bailey, Type Checking in Lean 4 (2024). What the kernel does, step by step, written for people building external checkers.
- Mario Carneiro, The Type Theory of Lean, MSc thesis, 2019, and Lean4Lean: Verifying a Typechecker for Lean, in Lean, 2024.
- Antonius J. C. Hurkens, A simplification of Girard’s paradox,
TLCA 1995. Why
Type : Typeis inconsistent.