6. The kernel
Draft
Twelve kinds of term
Lean's logic can be written down in full on a page. It consists of twelve kinds of term as Lean stores them, seven typing rules that determine which terms inhabit which types, and a definitional equality between terms that is checked by computation. A single program enforces them: the kernel, some eight thousand lines of C++, through which every declaration in a Lean library has to pass. A theorem in Lean is a proof term whose type, as computed by the kernel, matches the theorem's statement. Even a tiny library line like 0 + n = n, five symbols on the page, expands to 33 nodes in the kernel's store.
as written @[simp] protected theorem zero_add : ∀ (n : Nat), 0 + n = n (Lean's source, Init/Data/Nat/Basic.lean)
as stored (n : Nat) → Eq.{1} Nat (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) n) n
the tree forallE n ┬ const Nat
└ app ┬ app ┬ app ┬ const Eq.{1}
│ │ └ const Nat
│ └ app ┬ app ┬ app ┬ app ┬ app ┬ app ┬ const HAdd.hAdd.{0,0,0}
│ │ │ │ │ │ └ const Nat
│ │ │ │ │ └ const Nat
│ │ │ │ └ const Nat
│ │ │ └ app ┬ app ┬ const instHAdd.{0}
│ │ │ │ └ const Nat
│ │ │ └ const instAddNat
│ │ └ app ┬ app ┬ app ┬ const OfNat.ofNat.{0}
│ │ │ │ └ const Nat
│ │ │ └ lit 0
│ │ └ app ┬ const instOfNatNat
│ │ └ lit 0
│ └ bvar 0
└ bvar 0
counted 33 nodes, 26 distinct, of 5 of the twelve constructors: app 15, const 13, bvar 2, lit 2, forallE 1
judgment n : Nat ⊢ HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) n : Nat
(the subterm of 25 nodes that 0 + n is stored as; its type is inferred by the kernel of the page)
(the live figure needs JavaScript and loads about 0.5 MB: 0.3 MB of exported declarations and the kernel that checks them)
Sections 1 to 5 built a language in which every proposition is a type and every proof is a term of that type. This part presents the exact version that Lean runs, before Section 7 adds its three axioms. Everything else in Lean (the notation, elaboration, tactics, and automation of Sections 8 to 10) exists solely to manufacture terms in this core language and never has to be trusted, because the kernel checks every term it receives.
Making this core language exact completes the second step of the series' argument and sets up the fourth, where Section 13.1 states what checking a real proof establishes in this vocabulary. The order follows an actual check. To verify a declaration, the kernel computes the type of a term, so the twelve term constructors come first, followed by the seven typing rules. Six of those rules read straight off the shape of the term; only when an argument's inferred type does not match the expected parameter type symbol for symbol must the kernel decide on its own, with no proof term to guide it, whether the two types compute to the same thing. After computation come declarations, inductive types and propositions, and the limits of trust: what has been proved about the abstract rules, and what still rests on the C++ program that runs them.
All terms inside Lean are built from the twelve constructors of a single inductive type in Lean's sources (Lean/Expr.lean), three of which appeared in Section 1.2. The list is closed: every term that reaches the kernel is a tree of these twelve nodes, whoever or whatever produced it.
inductive Expr where
-- ...
| bvar (deBruijnIndex : Nat)
-- ...
| fvar (fvarId : FVarId)
-- ...
| mvar (mvarId : MVarId)
-- ...
| sort (u : Level)
-- ...
| const (declName : Name) (us : List Level)
-- ...
| app (fn : Expr) (arg : Expr)
-- ...
| lam (binderName : Name) (binderType : Expr) (body : Expr) (binderInfo : BinderInfo)
-- ...
| forallE (binderName : Name) (binderType : Expr) (body : Expr) (binderInfo : BinderInfo)
-- ...
| letE (declName : Name) (type : Expr) (value : Expr) (body : Expr) (nondep : Bool)
-- ...
| lit : Literal → Expr
-- ...
| mdata (data : MData) (expr : Expr)
-- ...
| proj (typeName : Name) (idx : Nat) (struct : Expr)
Six of the twelve form the logic itself. A bvar is a bound variable, stored as its de Bruijn index (Definition 1.2.3). A sort is a universe, a type whose elements are types (Section 5.5). A const is a name introduced by an earlier declaration, paired with the universe levels at which it is instantiated. And app, lam, and forallE are function application, lambda abstraction, and the dependent function type of Section 5.2, which Lean prints as (x : A) → B, or ∀ x : A, B when B is a proposition, or A → B when B does not mention x. Binder names and binderInfo are kept only for pretty-printing and elaboration; the kernel ignores them.
Four more constructors are practical conveniences for speed or readability rather than new logical primitives, as three of their doc comments note. A local definition letE stands for its body with the bound value substituted in; number and string literals "are not really needed" in the logic, since numerals could be built from zero and successor, though storing machine integers keeps arithmetic fast; metadata mdata d e carries annotations and "is definitionally equal to e"; and field projections proj out of a structure "are redundant" because a recursor could extract the same field. The last two constructors never appear in a finished declaration that the kernel accepts: an mvar, a metavariable, is an unfilled hole left for the elaborator of Section 9 to solve, and an fvar, a free variable, is a temporary stand-in that the type checker substitutes for a bound variable whenever it steps under a binder.
In the stored tree of 0 + n = n, every implicit type and typeclass record hidden by surface notation is written out in full: 25 of the 33 nodes belong to 0 + n alone, and every constant carries explicit universe levels, such as Eq.{1} because Nat lives at universe level 1.
Because four of the ten kernel-accepted constructors desugar to the core six, the formal grammar of Lean's type theory needs only those six.
Definition 6.1.1 (the terms of Lean's theory). The terms are
\[M, N, A, B \;::=\; x \;\mid\; \mathsf{Sort}\ \ell \;\mid\; c.\{\ell_1, \dots, \ell_k\} \;\mid\; M\,N \;\mid\; \lambda x{:}A.\, M \;\mid\; \Pi (x : A).\, B ,\]where \(x\) is a variable, \(\ell\) and the \(\ell_i\) are universe levels (Definition 6.1.2) and \(c\) is a constant that an earlier declaration introduced with \(k\) universe parameters. \(\mathsf{Sort}\ 0\) is written Prop, \(\mathsf{Sort}\ (\ell + 1)\) is written Type ℓ, and Type stands for Type 0.The six kinds, and the reading of the other four as shorthand, follow M. Carneiro, "Lean4Lean: Verifying a Typechecker for Lean, in Lean", arXiv 2403.14064 (version 3, 14 September 2025), §2.1 and §3.1. The projection is there "the most challenging constructor to desugar", because its translation needs the type of the term.
Among those six forms, only the universe levels have not yet been defined. Writing a separate equality type or list type for Type 0, Type 1, and every higher universe would duplicate the library, so Lean declares polymorphic constants like Eq once with universe parameters. Because a definition's output universe can depend on its input universes, a universe level in Lean/Level.lean is not a fixed integer, but a small arithmetic expression built from zero, successor, maximums, and parameters.
def Nat.imax (n m : Nat) : Nat :=
if m = 0 then 0 else Nat.max n m
-- ...
inductive Level where
| zero : Level
| succ : Level → Level
| max : Level → Level → Level
| imax : Level → Level → Level
| param : Name → Level
| mvar : LMVarId → Level
To check whether two universe sorts match across all possible instantiations of those parameters, Lean gives level expressions a numerical semantics and defines level equality over every parameter assignment.
Definition 6.1.2 (universe levels). A level is \(0\), a successor \(\ell + 1\), a maximum \(\max(\ell, \ell^{\prime})\), an \(\mathrm{imax}(\ell, \ell^{\prime})\) or a parameter \(u\). When the parameters are given natural numbers as values, a level has a value: \(0\), successor and \(\max\) mean what they say, and \(\mathrm{imax}(\ell, \ell^{\prime})\) is \(0\) if \(\ell^{\prime}\) has the value \(0\) and \(\max(\ell, \ell^{\prime})\) otherwise. Two levels are equal if they have the same value whatever values the parameters take.
The sixth constructor of Level, mvar, is like Expr.mvar a placeholder for an unknown level that the elaborator solves and eliminates before calling the kernel. The asymmetric maximum imax exists for a single typing rule, where it keeps propositions that quantify over large types inside Prop.
A grammar only specifies which trees of symbols can be formed; separating valid programs and proofs from ill-formed combinations requires typing rules.
The typing rules
Point at any node of the stored statement and the page answers with a judgment \(\Gamma \vdash M : A\): in the context \(\Gamma\), the list of the variables bound above the node with their types, the term \(M\) has the type \(A\). Seven rules say which judgments hold.
Definition 6.2.1 (typing). A context is a list \(x_1 : A_1, \dots, x_n : A_n\) in which each \(A_i\) has a sort as its type in the context before it. The judgments \(\Gamma \vdash M : A\) are those derived by the rules
\[\begin{aligned} &\text{(var)} && \Gamma \vdash x : A && \text{if } x : A \text{ stands in } \Gamma \\ &\text{(sort)} && \Gamma \vdash \mathsf{Sort}\ \ell : \mathsf{Sort}\ (\ell + 1) \\ &\text{(const)} && \Gamma \vdash c.\{\bar\ell\} : A[\bar u := \bar\ell] && \text{if } c \text{ is declared with parameters } \bar u \text{ and type } A \\ &\text{(app)} && \Gamma \vdash M : \Pi (x : A).\, B,\;\; \Gamma \vdash N : A \;\Longrightarrow\; \Gamma \vdash M\,N : B[x := N] \\ &(\lambda) && \Gamma,\, x : A \vdash M : B \;\Longrightarrow\; \Gamma \vdash \lambda x{:}A.\, M : \Pi (x : A).\, B \\ &(\Pi) && \Gamma \vdash A : \mathsf{Sort}\ \ell_1,\;\; \Gamma,\, x : A \vdash B : \mathsf{Sort}\ \ell_2 \;\Longrightarrow\; \Gamma \vdash \Pi (x : A).\, B : \mathsf{Sort}\ (\mathrm{imax}(\ell_1, \ell_2)) \\ &\text{(conv)} && \Gamma \vdash M : A,\;\; A \equiv B \;\Longrightarrow\; \Gamma \vdash M : B \end{aligned}\]in which \(\equiv\) is the definitional equality of Section 6.3 and \(B\), in (conv), is a type in \(\Gamma\).M. Carneiro, "The Type Theory of Lean", master's thesis, Carnegie Mellon University, 16 April 2019 (github.com/digama0/lean-type-theory), §2.1, and Figure 1 of the Lean4Lean paper.
Together, these seven rules form a pure type system (Definition 2.6.1) with an infinite ladder of sorts, where rule \((\Pi)\) computes the universe level of each dependent function type from the levels of its domain and codomain. Lean extends that bare framework in two ways: declared constants stored in an environment (Section 6.4), and a much richer definitional equality in (conv) than plain \(\beta\)-reduction. One might expect (conv) to matter only in subtle proofs, yet even the left-hand side 0 + n of the opening statement fails to typecheck without it.
Example 6.2.2 (the left-hand side, by the rules). Take the 25 nodes that represent 0 + n in the context n : Nat. Ten constants receive their types from (const), the variable n gets Nat from (var), the two literals have type Nat, and the 12 applications are checked by (app). In 11 of those 12 applications, the argument's inferred type matches the function's expected parameter type symbol for symbol. At the third argument of HAdd.hAdd.{0, 0, 0}, however, the function's declared type {α β : Type} → {γ : outParam.{2} Type} → [self : HAdd.{0, 0, 0} α β γ] → α → β → γ expects an argument of type outParam.{2} Type, whereas the argument supplied is Nat, of type Type. In the library, outParam is defined as the identity function fun α => α (a marker telling the elaborator in what order to solve typeclass parameters), so outParam.{2} Type and Type are equal by definition rather than as written. Only (conv) accepts the application, after the kernel unfolds outParam and reduces (fun α => α) Type to Type. Even checking the well-formedness of 0 + n = n requires computation. ◁
The C++ kernel turns these typing rules directly into a recursive procedure (src/kernel/type_checker.cpp), with a dispatch branch for each of the twelve constructors of Expr.
switch (e.kind()) {
case expr_kind::Lit: r = infer_lit(e); break;
case expr_kind::MData: r = infer_type_core(mdata_expr(e), infer_only); break;
case expr_kind::Proj: r = infer_proj(e, infer_only); break;
case expr_kind::FVar: r = infer_fvar(e); break;
case expr_kind::MVar: throw kernel_exception(env(), "kernel type checker does not support meta variables");
case expr_kind::BVar:
lean_unreachable(); // LCOV_EXCL_LINE
case expr_kind::Sort:
if (!infer_only) check_level(sort_level(e));
r = mk_sort(mk_succ(sort_level(e)));
break;
case expr_kind::Const: r = infer_constant(e, infer_only); break;
case expr_kind::Lambda: r = infer_lambda(e, infer_only); break;
case expr_kind::Pi: r = infer_pi(e, infer_only); break;
case expr_kind::App: r = infer_app(e, infer_only); break;
case expr_kind::Let: r = infer_let(e, infer_only); break;
}
For Sort, one line of C++ implements (sort) directly. Encountering a metavariable throws an exception, and a bare bound variable BVar is unreachable because whenever the checker steps under a Lambda or Pi binder, it substitutes a fresh free variable FVar for the bound index. Rule (conv) has no branch of its own: it runs inside infer_app, which infers the function's type, reduces that type until an outer Pi appears, infers the argument's type, and checks whether the argument's type and the Pi domain are definitionally equal.
Because the first six rules are completely syntax-directed and (conv) fires only when comparing an inferred type against an expected one, the kernel computes types without searching, and Lean never needs to store a bulky typing derivation alongside a proof term. The reference manual draws the consequence.
A derivation demonstrates the well-typedness of a term by explicitly indicating the precise inference rules that are used. Implicitly, well-typed terms can stand in for the derivations that demonstrate their well-typedness. Lean's type theory is explicit enough that derivations can be reconstructed from well-typed terms, which greatly reduces the overhead that would be incurred from storing a complete derivation, while still being expressive enough to represent modern research mathematics. This means that proof terms are sufficient evidence of the truth of a theorem and are amenable to independent verification.
—The Lean Language Reference, edition for Lean 4.35.0 (2026). Chapter 4, "The Type System", third paragraph (lean-lang.org/doc/reference/4.35.0). The pages of the manual name no author.
Before examining how (conv) decides equality of terms, look closely at rule \((\Pi)\), where imax earns its place. When (x : A) → B builds an ordinary type of data-returning functions (ℓ₂ > 0), that function space has to live at least as high in the universe hierarchy as both its input A and its output B, so its sort is Sort (max ℓ₁ ℓ₂). When B is a proposition (B : Prop, so ℓ₂ = 0), however, (x : A) → B is the universal statement ∀ x : A, B. If its level were max ℓ₁ 0 = ℓ₁, quantifying over Type would lift the statement out of Prop into Type, scattering universal propositions across higher universes. Defining imax ℓ₁ 0 = 0 keeps every function type ending in a proposition inside Prop.
a level is 0, a+1, max a b, imax a b or a parameter u; Sort 0 is Prop, Sort 1 is Type, Sort (u+1) is Type u
imax u v v 0 1 2 3 4 max u v v 0 1 2 3 4 imax a b is 0 when b is 0, and max a b otherwise:
u 0 0 1 2 3 4 u 0 0 1 2 3 4 the two tables differ at 4 of the 25 pairs shown,
1 0 1 2 3 4 1 1 1 2 3 4 first at u = 1, v = 0, where they are 0 and 1;
2 0 2 2 3 4 2 2 2 2 3 4 a level that is 0 names the sort Prop
3 0 3 3 3 4 3 3 3 3 3 4
4 0 4 4 4 4 4 4 4 4 4 4
where types live by the rule (x : A) → B : Sort (imax a b) the kernel builds Lean 4.35.0 prints
∀ n : Nat, n = n imax 1 0 0 Prop
∀ (α : Type 5) (x : α), x = x imax 7 (imax 6 0) 0 Prop
Nat → Prop imax 1 1 1 Type
(α : Sort u) → α → α imax (u+1) (imax u u) imax (u+1) u Sort (imax (u + 1) u)
18 identities 15 hold for every value; the kernel, which compares normal forms, accepts 10 and refuses 5 that are true:
imax u 1 = max u 1 max u (imax u v) = max u v imax u (imax v w) = imax (max u v) w
imax u (max v w) = max (imax u v) (imax u w) max (imax u v) v = imax u v
(the live figure needs JavaScript; it computes in the page and loads no data)
Because of that zero-absorbing rule, ∀ (α : Type 5) (x : α), x = x quantifies over a universe six levels up and still lands in Prop: its level evaluates to \(\mathrm{imax}(7, \mathrm{imax}(6, 0)) = 0\). That single piece of arithmetic implements the impredicativity of Prop from Section 5.7. Notice too that no typing rule automatically lifts a type from one universe into the next: Nat has type Type (Sort 1) and not Type 1 (Sort 2), so Lean's universes are not cumulative. Finally, the 18 level identities at the bottom of the figure preview a theme of Section 6.6. Rather than case-splitting on whether each universe parameter is zero or positive, the kernel compares level expressions by putting them into a simplified normal form; that conservative test never equates two levels that can differ, and of the 15 identities that hold for all parameter values it accepts 10 and refuses 5.
With universe levels settled, the seventh rule still requires definitional equality on terms.
Definitional equality
The rule (conv) asks whether two types are equal by definition, and the kernel has to answer with no proof to go by. Here the kernel of this page answers for the two sides of 2 + 2 = 4.
question 2 + 2 = 4 as Lean stores it: are the two sides the same term, by computation?
HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (OfNat.ofNat.{0} Nat 2 (instOfNatNat 2)) (OfNat.ofNat.{0} Nat 2 (instOfNatNat 2))
=?= OfNat.ofNat.{0} Nat 4 (instOfNatNat 4)
both ways 15 steps, the same either way: δ unfolds a definition, β applies a function, proj takes a field
1 δ unfold HAdd.hAdd 7 proj a field of HAdd 12 δ unfold Add.add
3 δ unfold OfNat.ofNat 11 proj a field of OfNat ↦ 4 15 proj a field of Add ↦ Nat.add
the two sides are now Nat.add on two numerals, and 4
literals 6 steps more, 21 in all: 16 to 20 unfold a numeral to the literal 2; 21 lit compute Nat.add on literals ↦ 4
unary 54 steps more, 69 in all: Nat.add runs by its definition; ι, its recursor meeting a constructor, fires 6 times
steps to decide n + n ≡ 2n n = 0 1 2 4 16 64
with literals 18 21 21 21 21 21 (and 21 at n = 2⁶⁴)
in unary 36 54 69 99 279 999 (39 + 15n from n = 1 on)
n + 0 ≡ n is found equal in 33 steps, both ways: Nat.add recurses on its second argument, the numeral 0
0 + n ≡ n is not found equal: after 17 steps Nat.rec waits on the variable n, and the kernel gives up
(the live figure needs JavaScript and loads about 0.5 MB: 0.3 MB of exported declarations and the kernel that checks them)
It takes 21 steps, of which 20 unfold notation and one adds; they are its own steps, and Lean's kernel was not asked for a count. The count is 21 at every \(n\) from 1 to 64 in \(n + n \equiv 2n\), because literals are added as exact integers. Made to run the definition of Nat.add on numerals written out with Nat.succ, the same kernel needs \(39 + 15n\) steps at each of those \(n\), which is why a kernel is given integers.
Definitional equality is the judgmental equality of Section 5.4 that requires no proof term: two expressions are definitionally equal when symbolic computation and built-in structural laws identify them. Lean's relation combines eight rules: five that evaluate expressions step by step (applying functions, unfolding definitions, substituting local let bindings, running recursors on constructors, and translating literals) and three that equate terms by their role without running a step of evaluation (\(\eta\) for functions, proof irrelevance for propositions, and \(\eta\) for single-constructor structures).
Definition 6.3.1 (definitional equality). The relation \(M \equiv N\) is the smallest equivalence relation on the well-typed terms of a context that is preserved by every way of building a term and contains the instances of eight rules. β: \((\lambda x{:}A.\, M)\,N \equiv M[x := N]\). δ: a constant declared as a definition or a theorem is equal to its value. ζ: let x := N; M is equal to \(M[x := N]\). ι: a recursor applied to a constructor is equal to its case for that constructor, applied to the fields and to the recursor's values on the recursive ones (Section 5.6); the two rules of the quotient (Section 6.4) are of this kind. η: \(\lambda x{:}A.\, M\,x \equiv M\) when \(x\) is not free in \(M\). Proof irrelevance: two terms of one type are equal if that type is a proposition. Structure η: a term of a structure type (one constructor, no indices, not recursive) is equal to the constructor applied to the term's own fields. Literals: the numeral \(0\) is Nat.zero, and \(n + 1\) is Nat.succ applied to the numeral \(n\).The thesis, §2.2 to §2.7, for the theory of Lean 3. Structure η and the literals belong to Lean 4 and are described in S. Ullrich, "An Extensible Theorem Proving Frontend", doctoral dissertation, Karlsruher Institut für Technologie, 2023 (doi 10.5445/IR/1000161074), §3.2.1 and §3.2.2. A string literal, likewise, is the list of its characters.
Each of the eight rules can be seen at work on a concrete pair of terms that the kernel of Lean 4.35.0, asked directly, finds equal.
What the kernel counts as the same terma row to a rule of definitional equality; in ink, a pair of terms that the kernel of Lean 4.35.0, asked directly, finds equal
(fun y : Nat => f y) a ≡ f a
6.3δ a reduction
Unfold a name. A definition is used by being replaced with its value; so is a theorem, when the kernel needs to. An axiom has no value, and an opaque constant is never unfolded.
Not p ≡ p → False
6.3ζ a reduction
Remove a let: the variable is replaced by the value it was given.
(let y := n; f y) ≡ f n
6.3ι a reduction
Compute a recursor on a constructor. This is how recursion and induction run, and the only way: the kernel has no recursive definitions.
Nat.rec z s (Nat.succ n) ≡ s n (Nat.rec z s n)
6.3literals a reduction
A numeral is the number built from Nat.zero by Nat.succ, and arithmetic on numerals is done with exact integers, in one step.
2 + 2 ≡ 4
Nat.succ (Nat.succ Nat.zero) ≡ 2
6.3η not a reduction
A function is the abstraction that does nothing but apply it.
(fun y => f y) ≡ f
6.5proof irrelevance not a reduction
Two proofs of one proposition are the same term, whatever they are. No reduction leads from one to the other.
h₁ ≡ h₂
for h₁ h₂ : p and p : Prop
6.3structure η not a reduction
An element of a structure is the structure built from its own fields; a recursor that waits on such an element is handed it in that form. The kernel does not use the rule on proofs: a comparison has proof irrelevance for them, and a recursor is left waiting (Section 6.6).
(x.1, x.2) ≡ x
for x : Nat × Nat
green: the rules that are not reductions: neither term of the pair shown computes to the other
Definition 6.3.1 specifies which pairs are equal as an equivalence closure, not how to test a pair in practice. Reducing both sides all the way to full normal form (as in Corollary 1.4.2) would explode every high-level mathematical definition into massive trees of primitive recursors, even when two unexpanded expressions already match. Instead, Lean's kernel reduces lazily to weak head normal form, simplifying only until an outer constructor, binder, variable, or constant appears at the head, and unfolds definitions one layer at a time only when the comparison cannot otherwise proceed.
Algorithm 6.3.2 (the kernel's comparison, in outline). To decide whether \(M \equiv N\):The function is_def_eq_core of src/kernel/type_checker.cpp at tag v4.35.0, lines 1132 to 1207, 76 lines in all, with the functions it calls. Left out here: a shortcut for comparisons with Bool.true; after step 4, two constants of one name compared by their levels, two projections of one field compared by what they project from, and a second reduction that unfolds inside projections; string literals; structures with no fields. Under ι the kernel has two more reductions, which borrow from the rules that do not compute: K-like reduction (Section 6.5) and, for a recursor that waits on a term of a structure type that is not a proof, structure η, which hands it the constructor applied to that term's fields (src/kernel/inductive.h, lines 60 to 74). The heights that order the unfolding are hints stored with each definition; by their documentation in Lean/Declaration.lean they "only affect performance".
- Accept if the two are the same term or a pair already found equal. Compare abstractions and function types part by part, sorts by their levels, literals by their values.
- Bring both to weak head normal form by β, ζ, ι and the rules for projections and quotients, unfolding no definition at the head (in what a recursor waits on, definitions are unfolded), and try step 1 again.
- If \(M\) is a proof, that is, if its type is a proposition, accept exactly when the types of \(M\) and \(N\) are equal.
- Unfold lazily. Compute arithmetic on literals. Otherwise unfold one head: of two definitions the one built on more (each has a height, one more than the greatest in its body), of two of one height both, and of two uses of one definition both, once their arguments have been compared and found unequal. Reduce what was unfolded as in step 2, try step 1, and repeat until no head is a definition.
- Compare two applications head with head and argument with argument.
- Try η and structure η.
- Refuse.
Every accepting branch of this procedure applies a valid rule of Definition 6.3.1 (with the fast integer arithmetic of step 4 relying on the library's definitions of Nat operations matching integer arithmetic, as Section 6.7 notes). By design, the procedure is sound: whenever it answers yes, \(M \equiv N\) holds, though saying so of the C++ implementation is an engineering claim rather than a proved theorem. Reaching step 7, conversely, proves nothing: two terms that are genuinely equal under Definition 6.3.1 can still be rejected if lazy comparison gets stuck, and Section 6.6 exhibits a concrete pair.
Lean's library says what this equality buys where it defines the standard proof of an equation (Init/Prelude.lean).
/--
`rfl : a = a` is the unique constructor of the equality type. This is the
same as `Eq.refl` except that it takes `a` implicitly instead of explicitly.
This is a more powerful theorem than it may appear at first, because although
the statement of the theorem is `a = a`, Lean will allow anything that is
definitionally equal to that type. So, for instance, `2 + 2 = 4` is proven in
Lean by `rfl`, because both sides are the same up to definitional equality.
-/
@[match_pattern] def rfl {α : Sort u} {a : α} : Eq a a := Eq.refl a
Two theorems of the core library are proved by it and by nothing else (Init/Core.lean).
@[simp] protected theorem Nat.add_zero (n : Nat) : n + 0 = n := rfl
-- ...
-- proof irrelevance is built in
theorem proof_irrel {a : Prop} (h₁ h₂ : a) : h₁ = h₂ := rfl
In Nat.add_zero, rfl succeeds because Nat.add recurses on its second argument: when that argument is 0 (Nat.zero), the recursor meets a constructor and \(\iota\)-reduces n + 0 directly to n. Swap the arguments to 0 + n and the recursor waits on the variable n; computation stalls, so the kernel refuses 0 + n ≡ n. Both sides still take the same value at every number n, and the library proves 0 + n = n by induction as Nat.zero_add. Definitional equality captures only what symbolic evaluation reaches on open terms, a strict subset of what is true.
What symbolic evaluation can reach depends in turn on what has been declared: \(\delta\)-reduction unfolds a constant's stored body, and \(\iota\)-reduction fires a recursor generated for a data type. Both enter through declarations.
Declarations
The kernel's world is the environment, the table of everything declared so far. It begins empty and grows by one declaration at a time, each checked against what is already there. Lean's first file, Init/Prelude.lean, puts equality into it at line 73, with the declaration that Section 5.4 listed, and the natural numbers at line 1,357, and these in between.
@[implicit_reducible] def Not (a : Prop) : Prop := a → False
-- ...
@[simp] theorem id_eq (a : α) : Eq (id a) a := rfl
-- ...
init_quot
-- ...
axiom Quot.sound : ∀ {α : Sort u} {r : α → α → Prop} {a b : α}, r a b → Eq (Quot.mk r a) (Quot.mk r b)
-- ...
inductive Nat where
-- ...
| zero : Nat
-- ...
| succ (n : Nat) : Nat
Lean's sources give a declaration seven forms (Lean/Declaration.lean). Five appear in the listing above: an inductive type, a definition, a theorem, the quotient, and an axiom. The sixth is an opaque constant, whose body is typechecked once and never unfolded afterward; the seventh, a mutual block of definitions that call one another directly, is permitted only for programs marked unsafe or partial, outside the logic. For the four non-inductive, non-quotient forms inside the logic, everything the kernel verifies fits into a short checklist.
Proposition 6.4.1 (what the kernel checks). For an axiom, a definition, a theorem and an opaque constant: its name is new; no universe parameter is named twice; its type contains no metavariable and no free variable; and its type has a type, which is a sort. For the last three, in addition: the value contains no metavariable and no free variable, and the type that the rules give the value is definitionally equal to the declared type. For a theorem, in addition: the declared type is a proposition.Read off src/kernel/environment.cpp at tag v4.35.0, lines 127 to 223. Computing a type includes two checks that Definition 6.2.1 leaves unsaid: every universe parameter that occurs is one the declaration names, and no constant marked unsafe or partial is used (src/kernel/type_checker.cpp, lines 85 to 123).
The check of a theorem, the event that this series is about, is these lines of the kernel (src/kernel/environment.cpp).
environment environment::add_theorem(declaration const & d, bool check) const {
// ...
check_constant_val(*this, v.to_constant_val(), checker);
if (!checker.is_prop(type))
throw theorem_type_is_not_prop(*this, v.get_name(), type);
check_no_metavar_no_fvar(*this, v.get_name(), val);
expr val_type = checker.check(val, v.get_lparams());
if (!checker.is_def_eq(val_type, type))
throw definition_type_mismatch_exception(*this, d, val_type);
// ...
Here checker.check is the function of Section 6.2, which computes the type of the proof, and is_def_eq the comparison of Section 6.3. An axiom has a type and no value. In Lean 4.35.0 the value of a theorem is kept, and the kernel may unfold it like a definition.
What the kernel lacks is just as telling. A definition cannot mention its own name in its body, because that name enters the environment only after the body has been checked. Consequently, the kernel has no recursive function definitions, no pattern matching, and no termination checker, nor does it perform unification: recursion and pattern matching are compiled down by the elaborator into applications of recursors before the kernel ever sees them (Sections 8.3, 9.7, and 9.8). All recursors and their \(\iota\)-reduction rules originate from inductive declarations, which the kernel must police against two consistency threats: packing a larger universe into a smaller data type (Girard's paradox, Section 5.5), and placing the type being defined to the left of an arrow in a constructor's argument, such as (Bad → Bad) → Bad, which hides untyped self-application (Sections 2.1 and 5.6).
Definition 6.4.2 (an inductive declaration). An inductive declaration gives universe parameters, a number of parameters and, for each type \(I\) of a block, its type \((\text{parameters}) \to (\text{indices}) \to \mathsf{Sort}\ \ell\) and its constructors, each of a type \((\text{parameters}) \to (\text{fields}) \to I\,\cdots\). The kernel checks that each constructor's type is well typed and ends in \(I\) applied to the parameters and some indices; that every field lives in a sort no larger than \(\mathsf{Sort}\ \ell\), unless \(\ell\) is \(0\); and that every occurrence of a type of the block in the type of a field is strictly positive: it is the final result of that type, with no occurrence in the domains before it or among its own arguments. It then adds the types, the constructors and, for each type, a recursor with its computation rules (Section 5.6), which it generates itself.src/kernel/inductive.cpp, lines 435 to 497. The manual's §4.4.3.2 states the same requirements and calls them conservative: "there exist potential inductive types that do not undermine consistency, but that these requirements nonetheless reject".
An inductive block is mutual when several types refer to one another, and nested when a type occurs inside an existing container type in its own fields, like a rose tree whose node holds a List of subtrees; the kernel checks a nested declaration by translating it into a mutual block. A type is indexed when constructors restrict the arguments of the target type they build, as Eq.refl a inhabits Eq a a rather than arbitrary Eq a b. Finally, init_quot is the smallest declaration of all: for any type α and relation r : α → α → Prop, it introduces the quotient type Quot r, the projection Quot.mk, the function lifter Quot.lift, and the induction principle Quot.ind, together with two computation rules that reduce Quot.lift and Quot.ind directly when applied to Quot.mk r a (so Quot.lift f h (Quot.mk r a) ≡ f a). Those four constants assert no new equations on their own; actually identifying Quot.mk r a = Quot.mk r b whenever r a b holds takes the axiom Quot.sound (Section 7.2).
The kernel speaks for itself when it refuses. The first of these six declarations was written as source, a type Bad whose constructor takes a function from Bad to Bad. The others are terms handed to the kernel directly (Section 6.8 shows how): a definition loop that mentions loop, a theorem notAProp of type Nat, a definition hole whose value is a metavariable, another whose value is a bound variable with no binder, and an axiom whose type is the numeral 0.
Refusals.lean:6:0: error: (kernel) arg #1 of 'Bad.bad' has a non positive occurrence of the datatypes being declared
Refusals.lean:10:0: error: (kernel) unknown constant 'loop'
Refusals.lean:17:0: error: (kernel) type of theorem 'notAProp' is not a proposition
Nat
Refusals.lean:21:0: error: (kernel) declaration has metavariables 'hole'
Refusals.lean:27:0: error: (kernel) type checker does not support loose bound variables, replace them with free variables before invoking it
Refusals.lean:32:0: error: (kernel) type expected
0
Definition 6.4.2 does not say what the generated recursor may produce, and for a proposition that takes a rule of its own.
Propositions, and when a proof may be taken apart
Two rules set Prop apart from the other sorts, and both have been stated. By \((\Pi)\) a proposition may quantify over any type, the type of propositions included: Prop is impredicative. By Definition 6.3.1 any two proofs of a proposition are equal: Prop is proof-irrelevant. A third rule is forced by the second, and it is the one that a user of Lean runs into.
nine inductive types of Lean 4.35.0: may a proof of one be taken apart into data? (decided by the kernel of the page)
type its constructors, each with its fields and what it builds recursor's motive in
False : Prop no constructor Sort u
True : Prop intro : True Sort u
And : Prop intro (left : a) (right : b) : a ∧ b Sort u
Eq : Prop refl : a = a Sort u
Acc : Prop intro (x : α) (h : ∀ (y : α), r y x → Acc r y) : Acc r x Sort u_1 †
Or : Prop inl (h : a) : a ∨ b | inr (h : b) : a ∨ b Prop /// 2 constructors
Exists : Prop intro (w : α) (h : p w) : Exists p Prop /// w is data that the type does not fix
Nonempty : Prop intro (val : α) : Nonempty α Prop /// val is data that the type does not fix
Decidable : Type intro (decide : Bool) (reflects_decide : decide.Reflects p) : Decidable p Sort u not a proposition
asked example (h : ∃ n : Nat, 0 < n) : Nat := h.1
Lean Invalid projection: Cannot project a value of non-propositional type
Nat
from the expression
h
which has propositional type
∃ n, 0 < n
here invalid projection proj Exists 0 h
of the 270 inductive propositions of the core library, 190 eliminate into every universe and 80 only into Prop:
72 with more than one constructor, 8 with a field that is data
† as of Lean 4.35.0: a change merged on Lean's master branch on 20 November 2026 takes it from recursive propositions
(the live figure needs JavaScript and loads about 0.5 MB: 0.3 MB of declarations and recorded answers, and the kernel)
A proof of ∃ n, 0 < n was built from an explicit witness n, yet Lean refuses to project that number back out as a Nat. Proof irrelevance forces this refusal. Suppose two proofs of ∃ n : Nat, 0 < n are built from n = 1 and n = 2; because ∃ n, 0 < n lives in Prop, Definition 6.3.1 makes the two proofs definitionally equal. If a recursor could unpack a proof of ∃ n, 0 < n to return its witness in Nat, applying that function to two definitionally equal proofs would yield 1 ≡ 2, proving False. The same contradiction hits Or: if Or.rec could map True ∨ True to Bool by sending Or.inl h to true and Or.inr h to false, proof irrelevance would equate the two proofs for h : True and collapse true ≡ false. Consequently, the recursor of an inductive proposition is normally restricted to building other proofs: its motive (Section 5.6) must land in Prop, where all outputs of a given type are equal anyway. Computing data in Type u from a proof is called large elimination, and Lean permits it only for subsingletons, propositions structured so that no secret choice between constructors or hidden data witnesses can ever exist (subsingleton elimination).
Checking semantically whether an arbitrary proposition has at most one witness is undecidable, so the kernel instead checks a syntactic condition directly on the inductive declaration: at most one constructor may exist, and every field of that constructor must either be a proof in Prop or already appear publicly in the proposition's return type.
Definition 6.5.1 (when a proposition eliminates into data, in Lean 4.35.0). Let \(I\) be an inductive type in \(\mathsf{Sort}\ \ell\). If \(\ell\) is not \(0\) whatever values the universe parameters take, the motive of the recursor of \(I\) ranges over \(\mathsf{Sort}\ u\) for a new parameter \(u\). Otherwise it does so exactly when \(I\) was declared neither in a mutual block nor as a nested type, which the kernel turns into one, and either has no constructor, or has one constructor each of whose fields is a proof or occurs among the arguments of the type that the constructor builds. In every other case the motive ranges over Prop alone.Read off src/kernel/inductive.cpp at tag v4.35.0, lines 521 to 577; a nested declaration reaches that test already translated (line 1252). Asked here, Lean 4.35.0 gives an inductive proposition P whose one constructor takes a proof of True ∧ P, so that P occurs inside And, a recursor whose motives range over Prop alone.
Under this test, False (zero constructors), True and And (one constructor whose fields are all proofs), and Eq (one constructor Eq.refl a : Eq a a whose data argument a appears in the type) all eliminate into any universe Sort u, whereas Or (two constructors) and Exists and Nonempty (hidden data witnesses absent from the type) eliminate only into Prop. Accessibility is the instructive borderline case: Acc r x states inductively that every y with r y x is itself accessible, meaning classically that no infinite r-chain descends from x (Definition 8.3.1). Its sole constructor Acc.intro x h : Acc r x carries a data field x, yet x is already exposed in the index of Acc r x and h is a proof, so Acc passes the test and well-founded recursion in Lean 4.35.0 computes data over Acc.rec (Section 8.3). When a proposition's single constructor takes no fields beyond the type's parameters, as in Eq, the kernel adds one further shortcut: Eq.rec on a proof of a = a reduces even when that proof is an unexpanded variable, since proof irrelevance guarantees it equals Eq.refl a (Lean's sources call this K-like reduction).
Proofs in Lean are computationally irrelevant. In other words, having been provided with some proof of a proposition, it should be impossible for a program to check which proof it has received. This is reflected in the types of recursors for inductively defined propositions or predicates. For these types, if there's more than one potential proof of the theorem then the motive may only return another Prop. If the type is structured such that there's only at most one proof anyway, then the motive may return a type in any universe. A proposition that has at most one inhabitant is called a subsingleton. Rather than obligating users to prove that there's only one possible proof, a conservative syntactic approximation is used to check whether a proposition is a subsingleton. Propositions that fulfill both of the following requirements are considered to be subsingletons:
There is at most one constructor.
Each of the constructor's parameter types is either a Prop, a parameter, or an index.
—The Lean Language Reference, edition for Lean 4.35.0 (2026). §4.4.3.1.1.1, "Subsingleton Elimination" (lean-lang.org/doc/reference/4.35.0). A "parameter" of a constructor is here what Definition 6.5.1 calls a field. The thesis words the second condition as arguments that "are either propositions or directly appear in the output type" and gives the intuition: the rules make sure "that the inductive type contains at most one element" (§2.6.2).
The kernel's own comment on the second requirement gives the reason (src/kernel/inductive.cpp).
/* We have only one constructor, the final check is, the type of each argument
that is not a parameter:
1- It must live in Prop, *OR*
2- It must occur in the return type. (this is essentially what is called a non-uniform parameter in Coq).
We can justify 2 by observing that this information is not a *secret* it is part of the type.
By eliminating to a non-proposition, we would not be revealing anything that is not already known. */
Of the 270 inductive propositions of Lean's core library, 190 eliminate into every universe and 80 into Prop alone: 72 for having more than one constructor, 8 for a field that is data and that the type does not fix.
All of this is the rule of Lean 4.35.0, and it is moving. On Lean's development branch a change merged on 20 November 2026 restricts the recursor of a recursive proposition such as Acc to motives in Prop, "to ensure the kernel never has to look at a proof term of a Prop"; on 1 December no release has it.leanprover/lean4, pull request #13851, merged on 21 November 2026 at 00:07 UTC, which in New York is 19:07 on 20 November.
Why pay this price to keep Prop impredicative in the first place? Without impredicativity, everyday mathematical definitions break across universe levels: if a group G and its subgroups (modeled as predicates on G) live in Type 0, defining the subgroup generated by a subset S as the intersection of all subgroups containing S quantifies over every subgroup in Type 0; in a predicative hierarchy that membership condition would jump up a universe, so the intersection could not be one of the subgroups it intersected.The example is J. Avigad's, in "Foundations", arXiv 2009.09541 (version 4, 2021), a draft chapter for the Handbook of Proof Assistants and Their Applications in Mathematics and Computer Science, §6.6, which adds: "To balance the strength of impredicativity, restrictions are placed on the elimination rules." Restricting large elimination is one price of impredicative Prop, and Section 6.6 reveals another.
The restriction closes one way to a proof of False. Whether there is another is a question about the rules as a whole.
What is known about this theory
Two questions remain: whether these rules can prove something false, and how far the kernel's comparison is from the equality they define. The second can be tested. Take three terms. The kernel of Lean 4.35.0 finds the first equal to the second and the second equal to the third. Asked about the first and the third, it says no.
three terms, for variables (p q : Prop) (h : p ∧ q), where
def F {p q : Prop} (h : p ∧ q) : Nat := And.rec (motive := fun _ => Nat) (fun _ _ => 0) h
b = F (And.intro h.1 h.2)
accepted / \ accepted
proof irrelevance/ \And.rec meets And.intro
a = F h ───────────── refused ───────────── c = (0 : Nat)
And.rec waits on the variable h
every program asked, a mark to a side: + accepted − refused e refused by Lean's elaborator, before its kernel
as written with def 0 ≡ 1
and quot acc and acc
ab bc ac ab bc ac ab bc ac ab bc ac ab bc ac
lean, by rfl in a source + + e + + e + + e + e e + e e e
6 programs: Lean's kernel asked two ways, leanchecker, leanchecker-paranoid, nanoda_bin, the kernel of this page
+ + − + + − + + − + + − + + − −
4 programs: con-leche and con-ron, each in its two modes
+ + [+] + + − + + − + + [+] + [−] − −
[ ] not the verdict of Lean's kernel: two groups of programs, which differ on two sides
(the live figure needs JavaScript and loads about 0.4 MB: the recorded verdicts, 28 exported declarations and the kernel that checks them)
Refusing F h ≡ 0 is neither a soundness bug nor a claim that the two sides differ: F h = 0 is a theorem of Lean, proved in two steps via the middle term b. Rather, the definitional equality that a kernel computes is sound and incomplete, and on these three triples it fails to be transitive. Different checkers draw that boundary of completeness in slightly different places, splitting into two groups on two edges of the table. Two external checkers shipped with Lean 4.35.0, con-leche and con-ron, accept the true equation F h ≡ 0 while rejecting one edge that Lean's own kernel accepts in a declaration constructed for this recording, yet both accept all 196,546 declarations of Lean's core library. The kernel of this page is no further witness, since its tests hold it to Lean's verdicts here. Nor does the top row reflect any kernel: given rfl in a source file, Lean rejects the goal inside its elaborator before the kernel is ever asked (Section 6.8).
Tracing the three sides through Algorithm 6.3.2 shows why Lean's kernel accepts two and gets stuck on the third.
Example 6.6.1 (why each side). Define F by applying And.rec with the constant branch fun _ _ => 0, let h : p ∧ q be a variable, and let \(a\), \(b\), and \(c\) be F h, F ⟨h.1, h.2⟩, and 0. Comparing \(a\) and \(b\), the kernel sees the same defined head F on both sides and compares their arguments first (step 4 of Algorithm 6.3.2); because h and ⟨h.1, h.2⟩ both inhabit the proposition p ∧ q, proof irrelevance equates them immediately. Comparing \(b\) and \(c\), the kernel unfolds F, And.rec meets the constructor And.intro (⟨h.1, h.2⟩), and \(\iota\)-reduction evaluates the term to 0. Comparing \(a\) and \(c\) directly, however, unfolding F h leaves And.rec waiting on the bare variable h: And has two fields rather than none, ruling out K-like reduction, and structure \(\eta\) (which would expand h to ⟨h.1, h.2⟩ for a data structure) is disabled on proofs. Reduction stalls on h. Stepping through \(b\) bridges the gap, yet nothing in \(a\) or \(c\) prompts the comparison to invent \(b\). ◁
Two distinct relations have gone by the name of definitional equality here. Mathematical definitional equality \(\equiv\) (Definition 6.3.1) is transitive by definition because it is defined as an equivalence closure. Algorithm 6.3.2 computes a smaller relation, written \(\Leftrightarrow\) from here on, following the 2019 thesis that wrote down the theory of Lean 3; the thesis calls type checking built on \(\Leftrightarrow\) "a decidable non-transitive underapproximation of the typing judgment".The abstract of the thesis. Since then it has been found that reduction need not end (Proposition 6.6.3), so that what ends a check today is a budget of steps, which Lean gives its kernel with each declaration added in the ordinary way (Section 8.2). Metatheorems are proved about \(\equiv\); the C++ kernel runs \(\Leftrightarrow\).
To answer the consistency question for \(\equiv\), one builds a set-theoretic model in which every type denotes a set, every well-typed closed term denotes an element of that set, and False denotes the empty set \(\emptyset\), so no closed term can inhabit False. Because each universe Type n is closed under dependent function spaces and inductive types, the set modeling Type n must itself behave like a miniature set-theoretic universe, requiring an inaccessible cardinal in ZFC for each universe level used.
Theorem 6.6.2 (Carneiro, 2019). The theory of Lean 3, with the three axioms of Section 7, has an interpretation in set theory in which a type is a set; a function type is a set of functions, or a truth value when it is a proposition; a proposition is the empty set or a one-element set \(\{\bullet\}\); every proof is \(\bullet\); and \(\mathsf{Sort}\ (n + 1)\) is \(V_{\kappa_n}\), the set of all sets of rank below \(\kappa_n\), where \(\kappa_0 < \kappa_1 < \cdots\) are inaccessible cardinals, of which a given derivation needs finitely many. If \(\Gamma \vdash M : A\), then \(M\) is interpreted as an element of the set that interprets \(A\), and if \(M \equiv N\), the two are interpreted alike. Hence no closed term has the type False, which is interpreted as the empty set: "Lean is consistent if ZFC + {there are n inaccessible cardinals | n ∈ ω} is."The thesis, §6.2 and §6.3: Theorem 6.7, and Corollary 6.8, whose first sentence is the one quoted. A derivation needs only as many of the cardinals to be inaccessible as the universes it mentions ("it is essentially just the max of all universe numbers that appear in the course of the proof"), and a fixed choice function interprets the axiom of choice.
(ZFC is Zermelo-Fraenkel set theory with the axiom of choice; an inaccessible cardinal is one that is uncountable, regular and a strong limit.)
The idea of the proof. Soundness is an induction on derivations. The two-element universe is made for the two rules of Prop: all proofs are one point, so proof irrelevance holds, and a function type into a proposition is a truth value, so it stays at the bottom however large its domain. A proof of False accepted by a kernel that keeps to these rules would be a derivation in this theory, \(\Leftrightarrow\) being contained in \(\equiv\), and so an element of the empty set.
Universes of CIC are closed under function types and inductive types, which when translated to the set theoretic language implies that they are Grothendieck universes. If we limit our attention to levels of the cumulative hierarchy Vλ, this amounts to a requirement that λ be an inaccessible cardinal. Since Lean has an infinite sequence of universes this translates to having ω many inaccessible cardinals in the ZFC universe from which to build the model, and this is the main large cardinal axiom we require. It is not difficult to see that this assumption (or something with similar consistency strength) is necessary, because with a suitably defined inductive type we can construct a model of ZFC in each universe above the first one, and moreover we can define particular inaccessible cardinals in the larger models, so that we can have models of ZFC with n inaccessible cardinals.
—Mario Carneiro, "The Type Theory of Lean" (2019). §1.2, "Set theoretic models of type theory", fourth paragraph. CIC is the calculus of inductive constructions, the type theory of Coq, to whose family Lean's belongs. The converse direction is, by the thesis's account, B. Werner's ("Sets in types, types in sets", TACS 1997): type theory with n + 2 universes proves the consistency of ZFC with n inaccessible cardinals.
By the thesis, then, the consistency of this theory is that of set theory with universes, neither more nor less, and a mathematician who has used Grothendieck universes has granted the assumption. Some assumption there must be: by Gödel's second theorem (Section 3.5), in the words of a later paper by the same author, "anything that would imply the unconditional soundness of Lean won’t be directly provable".
The theorem says less than "Lean is consistent", in three ways.
Three things that are called Lean's logicthe published proof is about the first; what checks a proof is the third
6.6the theory of 2019 Lean 3, on paper
Typing rules and an ideal equality. By the thesis, consistent if set theory with inaccessible cardinals is. Its equality is undecidable.
6.6the theory of Lean 4 described in 2023
Adds structure η, projections, literals, nested and mutual inductive types. The proof of 2019 does not cover them as it stands.
6.7the kernel a program, 8,028 lines
Decides a smaller equality: sound by design, incomplete, not transitive. The faults on record are bugs of the program, by its maintainers' accounts.
green: what checks a proof
First, it is about Lean 3. Lean 4 put structure η, projections, literals, and nested and mutual inductive types into the kernel; its theory was first described formally in a dissertation of 2023, and by the paper on Lean4Lean, a checker for Lean written in Lean, the proof of 2019 "is no longer directly applicable". What Lean 4 has is of another kind: a checker, con-leche, which by its authors' account comes with a proof, checked by Lean's own kernel, that whatever it accepts has a model in set theory (Section 13.8). Second, the proof as the thesis writes it leans on a step that has since given way. The construction has to know which types are propositions, and the thesis takes that from unique typing, the property that any two types of one term are definitionally equal. Its proof of unique typing "has an error in one of the technical lemmas", the same paper reports, and the property is a conjecture again. "The proof of soundness is not impacted", the paper goes on, "because there are alternative routes to construct the model that avoid unique typing"; Thomas Hales wrote in October 2026 that to his knowledge such a route "has never been written down, beyond a brief statement in the introduction to his thesis", and Section 13.8 takes up what he concluded.The Lean4Lean paper, §1, §2.4 and, for Gödel, §3.2.1. Ullrich's dissertation, chapter 3, gives "the first formal description of the type theory of Lean 4". T. Hales, "What mathematicians should know about the Lean Theorem Prover: questions of reliability and AI", guest post on Terence Tao's blog, 9 October 2026 (terrytao.wordpress.com), item 3 of its section "Bug extermination". Third, the theorem is about rules, and what checks a proof is a program that runs a smaller relation.
The third can be made exact.
Proposition 6.6.3 (what does not hold). (i) The relation \(\equiv\) is undecidable. (ii) The relation \(\Leftrightarrow\) is not transitive. (iii) Typing with \(\Leftrightarrow\) is not preserved by reduction: there are terms that the kernel accepts and that reduce to terms it refuses. (iv) Reduction need not end: there is a closed term, using the axiom propext of Section 7, whose reduction comes back to the term itself.(i) to (iii): the thesis, §3.1, where they are proved of the theory of Lean 3 and of the equality that its kernel ran. Of Lean 4 the reference manual says (§2.3) that its type theory "does not feature subject reduction, the definitional equality is not necessarily transitive, and it is possible to make the type checker fail to terminate". (iv): A. Abel and T. Coquand, "Failure of Normalization in Impredicative Type Theory with Proof-Irrelevant Propositional Equality", Logical Methods in Computer Science 16(2), 2020 (arXiv 1911.08174), who prove it of a type theory with an impredicative universe of propositions and a proof-irrelevant equality, and for whom "Consistency and canonicity is not at stake" (canonicity is Definition 7.4.1); the term in Lean 4 is from the Lean4Lean paper, §3.2.1.
Statements (i) to (iii) are theorems of the thesis, about Lean 3; (ii) and (iv) are observed here on the kernel of Lean 4.35.0, in Examples 6.6.1 and 6.6.4.
The ideas. For (i), assume a free variable a proving accessibility along a relation that is not actually well-founded; by proof irrelevance, a equals Acc.intro applied to sub-proofs, allowing a well-founded recursion on a to unfold indefinitely until a chosen Turing machine halts, reducing the halting problem to deciding \(\equiv\). Part (ii) is Example 6.6.1. Part (iii) follows directly from non-transitivity: when \(\alpha \Leftrightarrow \beta\) and \(\beta \Leftrightarrow \gamma\) hold while \(\alpha \Leftrightarrow \gamma\) fails, wrapping a term of type \(\gamma\) in an identity function typed at \(\beta\) lets it typecheck at \(\alpha\), yet \(\beta\)-reducing away the wrapper leaves the bare term of type \(\gamma\) checked directly against \(\alpha\), which the kernel rejects. Part (iv) brings untyped self-application (Section 2.1) back inside Prop through an equation between propositions.
Example 6.6.4 (a term that does not halt). Three short definitions from the Lean4Lean paper exhibit (iv) directly in Lean 4.35.0.
def True' := ∀ p : Prop, p → p
def om : True' := fun A a =>
@cast (True' → True') A
(propext ⟨fun _ => a, fun _ => id⟩)
(fun z => z (True' → True') id z)
def Om : True' := om (True' → True') id om
Because True' (∀ p : Prop, p → p) is impredicative, instantiating p at True' → True' turns any z : True' into a function of type True' → True' that can be applied to z itself (z (True' → True') id z). Next, for any inhabited proposition A (with witness a : A), propositional extensionality propext proves (True' → True') = A, letting @cast coerce that self-application function into type A to define om : True'. Finally, Om instantiates om at A := True' → True': the cast now has identical source and target types, so K-like reduction erases @cast even though its equality proof rests on the axiom propext, and (fun z => z (True' → True') id z) om steps right back to Om. Handed a theorem whose check had to reduce a proof built from Om, Lean's kernel hit its step budget after 29 seconds with (kernel) deterministic timeout. The loop proves nothing false, yet while every well-typed term in the calculi of Section 2 halts, in Lean a proof term need not. ◁
None of the four is a way to have a false statement accepted: they are failures to accept or to answer, and the guide that Lean's maintainers wrote for people who hunt bugs in the kernel says so of two of them.
These are known properties of the theory, not soundness bugs. They affect completeness, not soundness: the kernel may reject a term that is well-typed in the ideal theory, and two correct checkers may disagree on such corner cases. They cannot be used to produce a proof of
Falsethat passes the validation steps above. In particular, a term involvingAcc.recthat one checker accepts and another rejects is not a kernel bug, and there is no need to report it.—"Kernel bug hunt", a guide by Lean's maintainers (as served on 1 December 2026). hackmd.io/Tu2Z97xHSQilI7b91HQfAw, section "Known issues", under "Subject reduction and transitivity", second paragraph. The document is undated and can be edited; it names Lean 4.35.0. "These" are the failure of subject reduction, which is (iii), and of transitivity. The reference manual says of the same properties: "Most importantly, logical soundness is not affected."
For someone who reads a kernel's answers, all of this comes to an asymmetry.
Remark 6.6.5 (three kinds of no). A refusal by the kernel can mean three different things: a genuine type error, a true definitional equality on which lazy comparison got stuck, or an implementation limit reached (on reduction steps, recursion depth, or numeral size). Only the first indicts the term itself. Acceptance, by contrast, has one meaning: the declaration has satisfied every typing rule.
A foundation that is to be implemented has to be simple, since "the more complicated the specification is, the harder it is to get the implementation right",Avigad, "Foundations", §1.1; and The Lean Language Reference, §2.3, last paragraph. and it has to carry the mathematics that people want to write. Lean chose the second knowingly: the last three properties of Proposition 6.6.3, its manual says, "are a result of having impredicativity, quotient types that compute, definitional proof irrelevance, and propositional extensionality; these features are immensely valuable both to support ordinary mathematical practice and to enable automation". An issue opened on Lean's tracker on 31 August 2026 now proposes to change the logic itself, toward "A decidable, transitive definitional equality algorithm", and the change to Acc of Section 6.5 is one of its items.leanprover/lean4, issue #14977, "Meta issue: Lean Kernel Logic renovation". Lean 4.35.0, on which the readable edition (Section 12.3) of the Lean library published in November 2026 as a proof of the Riemann hypothesis is built, has the kernel before that renovation.
No theorem of this section is about the eight thousand lines themselves.
The kernel as a program
The program that applies all this can be measured. The directory src/kernel of Lean 4.35.0 holds 8,028 lines of C++ in 36 files, the largest the checks on inductive types (1,417 lines) and the type checker proper (1,330).Counted on the files at tag v4.35.0. In 2015 the description of the system gave "6k lines of C++ code" and "700 additional lines of code" for inductive types: L. de Moura, S. Kong, J. Avigad, F. van Doorn and J. von Raumer, "The Lean Theorem Prover (system description)", CADE 2015, §2. The count leaves out what the kernel calls: the runtime, the library for large integers, the definition of Expr. A program of this size can be written a second time, and the plainest test of two such programs is a library.
the core library of Lean 4.35.0 checked again by the kernel of the page, run by Node:
196,546 declarations, every one accepted, none refused, in 67,007,865 steps
dots a declaration at the time its check took (logarithmic, 1 µs to 1 s), a pair of strips to a kind:
above the kernel of the page, below Lean's own, each time the median of three runs
theorems 89,360 · definitions 101,254 · inductive blocks 2,901 · opaque, axioms, quotient 3,031
1,786 took over 10 ms here; the heaviest 1,736 ms here, 1,418 ms in Lean
runs two groups, each measured alike within itself; rows in the order they were run, not by time
1 the clock around each check alone, one thread, turn by turn in one session, whole library: seconds
Lean's kernel, inside Lean 81.2, 81.5, 81.3
the kernel of the page, in Node 113.0, 116.5, 115.9
the same in 6 processes at once 144.5 the checks of all summed, one run
the record gives the ratio of the page's totals to Lean's as 1.4 to 1.8: this kernel, this machine
2 the whole program from start to exit, one thread: the median of three runs of wall time
Init Init and Std Init, Std and Lean
leanchecker, Lean's own kernel 53.0 s 93.5 s 112.6 s
con-leche 60.7 s 96.5 s 121.4 s
con-ron 29.1 s 46.1 s 56.0 s
nanoda_bin 33.9 s ///// stopped by this recording at 12 GB of memory /////
(the live figure needs JavaScript and loads about 1.2 MB, 1.1 MB of it recorded times)
The kernel that runs in this page is a separate implementation in another language, written with the reference at hand: a port of Lean's C++ kernel to JavaScript, made with the source open. Run outside the browser on an export of the core library of Lean 4.35.0, a file that lists every declaration with its terms, it accepted all 196,546 declarations and refused none, in 67,007,865 steps. On 4,400 almost-right declarations, made from those of the series' Euclid example by one or two small changes at random places, its verdict was that of Lean's kernel every time: 4,312 refused by both, 88 accepted by both. A mistake in the algorithm would be in both programs; what they do not share is the language, the runtime and the integers. What the table shows of this page's kernel illustrates it on one machine and is not a measurement of kernels.
One difference is by design. Lean's kernel computes 15 functions on the natural numbers with its integers, Nat.add and Nat.gcd among them, and by the maintainers' guide it knows them by their names alone, without checking that the declarations are the library's. Replace Nat.add by some other function, the guide goes on, and "you can prove False"; the maintainers treat such a library as an adversarial input, for the comparison of statements to catch (Section 13.5, which quotes the guide). The page's kernel, like Lean4Lean, lets a function compute fast only after its definition has passed the function's equations.
Lean 4.35.0 ships programs for the purpose: leanchecker, which replays declarations through Lean's own kernel, and leanchecker-paranoid, the same built with a hardened memory allocator; and, as second opinions, lean4lean, a port of the kernel to Lean, in parts verified; nanoda_bin, an implementation in Rust; and con-leche with its port to Rust, con-ron. On the same export con-leche and con-ron accepted the whole library. nanoda_bin accepted the export of Init alone, 63,937 declarations; on the two larger exports its runs were stopped by the recording, at a limit of 12 GB of memory and in an earlier run at about 23 GB, with no verdict. Section 13.4 says what each program is and what their agreement is worth.
The kernel has a record, told by the release notes of 2026. At the end of July a proof of False that the kernel accepted was reported (issue #14576) and fixed within a day: a check was missing where the kernel translates a nested inductive type, a fault "only reachable through metaprogramming", by a program that hands the kernel a declaration no source text produces. Lean 4.33.1, of 21 August, fixed two more, one of them the gap of Section 6.6 turned into a fault: the kernel had cached successful comparisons in a union-find, a structure that merges items into classes, so that "is_def_eq(v0, v2) could return false on its own but true after is_def_eq(v0, v1) and is_def_eq(v1, v2) had succeeded", and a crafted input derived False. (The kernel of this page was first written with the same cache.)The release notes in The Lean Language Reference; the fix of the cache is pull request #14806. Lean 4.33.0 (10 August) lists 12 pull requests on the kernel, four of them marked as soundness bugs. The notes of Lean 4.34.0 (14 September) count the two faults fixed in 4.33.1, with a third in the runtime's counting of references, as three routes to a proof of False, each needing "a deliberately constructed input rather than ordinary source code". The first fault is told in L. de Moura, "Postmortem for Kernel Soundness Bug #14576", 1 August 2026 (leodemoura.github.io). None of this was reproduced here; these are the maintainers' accounts. The first was "an implementation bug, not a hole in Lean's meta-theory", says its postmortem, which also says where the line of trust runs.
One suggestion in the discussion is to remove or restrict metaprogramming so that this attack is not expressible. This is misguided. The elaborator is untrusted by design. Soundness cannot depend on an untrusted component refusing to build a bad term. An attacker who wants to submit a malicious proof can also write .olean files directly or modify memory, both of which bypass the elaborator entirely. The kernel has to reject ill-typed declarations on its own, in its own process. This separation and isolation of concerns is one of the main advantages of proof terms.
—Leonardo de Moura, "Postmortem for Kernel Soundness Bug #14576" (2026). Section "On removing metaprogramming". An
.oleanfile is the compiled form of a Lean module (Section 13.4).
The kernel is not verified. Of the ways to do better that the paper on Lean4Lean lists, "(1) testing, (2) independent reimplementation, and (3) formal verification", this section did a little of the first, the toolchain ships the second, and Section 13.8 takes up the third.
Lean's logic is twelve kinds of term as its kernel stores them, seven typing rules and an equality that is checked by computing, and its kernel is a program of eight thousand lines that applies them. What is in print, a proof of consistency relative to set theory, is about rules, about an earlier version of them, and as written it rests at one step on what is now a conjecture. What checks a proof is the program, and that is why its verdict is asked of more than one.
In Lean
All of this can be asked of Lean itself. A file that begins with import Lean has the kernel's own data at hand, and its first lines print a statement in full and a term as a value of Lean.Expr.
import Lean
open Lean Meta
set_option pp.explicit true in
#check ∀ n : Nat, 0 + n = n
def sample := fun x : Nat => ∀ y : Nat, x = y
run_meta do
logInfo (repr (← getConstInfo ``sample).value!)
∀ (n : Nat),
@Eq Nat
(@HAdd.hAdd Nat Nat Nat (@instHAdd Nat instAddNat) (@OfNat.ofNat Nat (nat_lit 0) (instOfNatNat (nat_lit 0))) n)
n : Prop
Lean.Expr.lam
`x
(Lean.Expr.const `Nat [])
(Lean.Expr.forallE
`y
(Lean.Expr.const `Nat [])
(Lean.Expr.app
(Lean.Expr.app
(Lean.Expr.app (Lean.Expr.const `Eq [Lean.Level.succ (Lean.Level.zero)]) (Lean.Expr.const `Nat []))
(Lean.Expr.bvar 1))
(Lean.Expr.bvar 0))
(Lean.BinderInfo.default))
(Lean.BinderInfo.default)
Lean 4.35.0, here as everywhere in this section, first prints the statement of Section 6.1 with every argument written (nat_lit 0 is a literal; the option pp.universes would add the levels), and then the definition sample as the environment holds it: x and y have become bvar 1 and bvar 0, and Eq is used at level 1. The next four commands show the two sides of addition.
#print Nat.add_zero
#print Nat.zero_add
#reduce fun n : Nat => n + 0
#reduce fun n : Nat => 0 + n
@[defeq] protected theorem Nat.add_zero : ∀ (n : Nat), n + 0 = n :=
fun n => rfl
protected theorem Nat.zero_add : ∀ (n : Nat), 0 + n = n :=
fun x => Nat.brecOn x Nat.zero_add._f
fun n => n
fun n => (Nat.rec ⟨fun x => x, PUnit.unit⟩ (fun n n_ih => ⟨fun x => (n_ih.1 x).succ, n_ih⟩) n).1 0
One theorem is proved by rfl and the other by structural recursion, shown as compiled for the kernel (Nat.brecOn wraps Nat.rec); #reduce, which computes a full normal form, simplifies n + 0 to n while leaving 0 + n as a recursor waiting on n. The final block tests the non-transitive triple of Section 6.6: two edges of the triangle are proved by rfl, their composition ac is proved through Eq.trans, and run_meta then bypasses the elaborator to hand the kernel F h = 0 directly with Eq.refl (F h) as its purported proof.
def F {p q : Prop} (h : p ∧ q) : Nat :=
And.rec (motive := fun _ => Nat) (fun _ _ => 0) h
theorem ab (p q : Prop) (h : p ∧ q) : F h = F ⟨h.1, h.2⟩ := rfl
theorem bc (p q : Prop) (h : p ∧ q) : F ⟨h.1, h.2⟩ = 0 := rfl
theorem ac (p q : Prop) (h : p ∧ q) : F h = 0 := (ab p q h).trans (bc p q h)
#print axioms ac
run_meta do
let stmt := (← getConstInfo ``ac).type
let proof ← forallTelescope stmt fun xs eq => do
mkLambdaFVars xs (← mkEqRefl eq.appFn!.appArg!)
addDecl (.thmDecl { name := `ac_by_rfl, levelParams := [], type := stmt, value := proof })
With the three blocks in one file, Kernel.lean, a blank line between them, the last two commands give
'ac' does not depend on any axioms
Kernel.lean:25:0: error: (kernel) declaration type mismatch, 'ac_by_rfl' has type
∀ (p q : Prop) (h : p ∧ q), F h = F h
but it is expected to have type
∀ (p q : Prop) (h : p ∧ q), F h = 0
The equation has a proof that uses no axiom, and the kernel will not find it by computing. The message is the kernel's own, marked (kernel): written with rfl in the source, the theorem would have been stopped earlier, by the elaborator, with Not a definitional equality. The last five lines are the general way to hand the kernel a term that no source text produced.
Ordinary mathematics uses more than these rules give: a proof of existence, for one, hands over no witness (Section 6.5). Section 7 states the three axioms that Lean's library adds, and what each costs.