7. Axioms and classical mathematics

Draft

What the kernel does not have

The kernel of Section 6, the small program that every proof has to pass, checks a theory in which three habits of everyday mathematics have no rule: calling two functions equal because they take the same values, arguing by cases on a statement that nobody can decide, and picking an element from a set of which one knows only that it is not empty. Lean's library gets all three from three axioms, constants that are declared with a type and no definition: propositional extensionality, the soundness of quotients, and choice. The excluded middle is not among them. It is a theorem, and what stands between it and the axioms is a handful of declarations of the core library, the library that ships with Lean, each checked here in the page.

graph    the 20 declarations of a sample of Lean's core library that rest on an axiom, a row to a layer;
         a line runs from a declaration down to each one that uses it. From choice to the excluded
         middle, a chain of 4 uses:

         propext               Quot.sound      Classical.choice                the three axioms
          │ (13 declarations     │               └ Classical.indefiniteDescription
          │  rest on it)         └ funext            └ Classical.choose
          │                          │                   └ Classical.choose_spec
          └──────────────────────────┴────────────────────────┴ Classical.em : (p : Prop) → Or p (Not p)

walk     from Classical.em the kernel of the page visits 120 constants, 17 of them resting on an
         axiom; axioms met: propext, Quot.sound, Classical.choice
dots     27 of the 41 theorems of the sample rest on no axiom (Nat.add_comm is one)
library  the 89,360 theorems of the whole core library, walked the same way: 35,231 rest on
         Classical.choice, 34,761 on all three axioms, 16,836 on none
(the live figure needs JavaScript and loads about 0.6 MB of data)
Declarations of Lean's core library that rest on an axiom, exported from Lean 4.35.0 and checked by the kernel of this page: the three axioms on top, a hairline from a declaration down to each one that uses it. Green: a longest chain of uses from the axiom chosen to the declaration in focus. Grey ground: rests on that axiom. Dots: theorems that rest on no axiom. The axioms under a declaration are found by walking the exported terms; the readout counts the whole library's 89,360 theorems the same way (45,123 written in its sources, the rest generated by Lean). Choose an axiom; click a declaration.

A walk from Classical.em, the excluded middle, through everything its term mentions ends at all three axioms, and reaches Classical.choice along a chain of four uses. Function extensionality, funext, rests on Quot.sound alone, List.reverse_reverse on propext alone, and Nat.add_comm on nothing. So whether Lean is constructive or classical is a question to ask of a theorem, not of the system: the library uses the excluded middle freely, and which axioms a given proof rests on is a fact that can be computed.

This part closes the second step of the series, in which a single formal language states ordinary mathematics: to the kernel rules of Section 6 it adds the principles that everyday mathematical reasoning still relies on. Of those three habits, only choice is postulated directly; function extensionality and the excluded middle are derived from the axioms as theorems. Because an axiom has no body to unfold, each one carries a computational price, though their prices differ sharply: the first two axioms can stall symbolic reduction inside the kernel while leaving compiled programs untouched, whereas choice produces values that no program can compute at all. Later sections turn to a second way in which a formal theorem can diverge from informal mathematics without invoking any axiom: the convention that assigns a default output where an operation like division or subtraction is mathematically undefined. In the chain of trust assembled in Section 13, axiom dependencies can be audited automatically from a proof term, whereas off-domain conventions have to be read by a human inspecting the theorem's statement.

Where the rules stop shows in three lines.

example : (fun x : Nat => x + 0) = (fun x => x) := rfl
example : (fun x : Nat => 0 + x) = (fun x => x) := rfl
example : (True ∧ True) = True := rfl

Lean 4.35.0, the version of every run in this part, accepts the first and refuses the other two.

Missing.lean:2:51: error: Type mismatch
  rfl
has type
  ?m.11 = ?m.11
but is expected to have type
  (fun x => 0 + x) = fun x => x
Missing.lean:3:34: error: Type mismatch
  rfl
has type
  ?m.3 = ?m.3
but is expected to have type
  (True ∧ True) = True

The term rfl proves an equation only when its two sides are definitionally equal, meaning that the checker's own reduction rules compute them to a common form (Section 6.3). Because Nat.add recurses on its second argument, x + 0 simplifies to x even under fun x => ..., turning both sides of the first equation into the identical lambda term. In the second equation, 0 + x stalls on the variable x; although induction proves 0 + x = x for every number x, rfl runs computation alone and never consults proved theorems. In the third, True ∧ True and True imply each other logically, yet as syntax trees they are distinct inductive propositions that never reduce to one another.

Whether an equality compares external behavior or internal presentation determines whether an algorithm can decide it.

Definition 7.1.1 (intensional and extensional). An equality is extensional if it identifies things that behave alike: functions with the same value at every argument, propositions each of which implies the other, sets with the same elements. It is intensional if it compares the way things are given.

Where Remark 5.4.4 applied these two terms to a type theory as a whole (asking whether any proved equation may be promoted into definitional equality), Definition 7.1.1 applies them to an equality relation itself, asking which objects it identifies.

Definitional equality in the kernel is intensional out of necessity: "Checking extensional equality involves proving essentially arbitrary theorems about equality of functions, and there is no clear specification for an algorithm to check it," says Lean's reference manual, for which two functions are definitionally equal, to a first approximation, "if they implement the same algorithm".The Lean Language Reference, in its edition for Lean 4.35.0 (lean-lang.org/doc/reference/4.35.0), Section 4.1.3, "Extensionality". Its pages name no author. The reference manual cited in this part is always this edition. Without extra assumptions, propositional equality (Eq from Section 5.4) is trapped in the same intensional world: its sole constructor Eq.refl proves only that a term equals itself, offering no way to lift pointwise agreement ∀ x, f x = g x to an equality f = g between the functions themselves. Everyday mathematics treats functions and propositions extensionally, so new principles have to be added.

The other two missing habits concern case splits and witnesses rather than equality. Under the constructive rules of Section 4.4, building a proof of p ∨ ¬p requires applying Or.inl to a proof of p or Or.inr to a proof of ¬p; for an undecided proposition p, neither branch is available, and Section 3.6 exhibited a model of those rules in which excluded middle fails. Likewise, a proof of ∃ x, P x lives in Prop, where subsingleton-elimination restrictions forbid unpacking it to return a witness x as data (Section 6.5).

None of the kernel rules in Section 6 closes any of these three gaps, so closing them takes axioms.

The three axioms

What is assumed can be read exactly: asked to print the three axioms, Lean answers with a line each.

#print propext
#print Quot.sound
#print Classical.choice
axiom propext : ∀ {a b : Prop}, (a ↔ b) → a = b
axiom Quot.sound.{u} : ∀ {α : Sort u} {r : α → α → Prop} {a b : α}, r a b → Quot.mk r a = Quot.mk r b
axiom Classical.choice.{u} : {α : Sort u} → Nonempty α → α

Compare their return types. Both propext and Quot.sound conclude an equation (a = b and Quot.mk r a = Quot.mk r b), which lives in Prop: everything built from them is a proof that the compiler will erase. Classical.choice, by contrast, can be instantiated at a data universe Type u, where it returns an inhabitant of α from a bare proof that α is nonempty. That boundary between producing proofs and producing data governs what each axiom costs.

Definition 7.2.1 (the three axioms). An axiom is a constant declared with a type and no value; the kernel checks that the type is a type, and nothing more. Lean's library declares three for mathematics.

  • Propositional extensionality, propext: if propositions \(a\) and \(b\) satisfy \(a \leftrightarrow b\), then \(a = b\).
  • Soundness of quotients, Quot.sound: if \(r\) is a relation on a type \(\alpha\) and \(r\,a\,b\) holds, then Quot.mk r a and Quot.mk r b, the classes of \(a\) and \(b\) in the quotient Quot r, are equal.
  • Choice, Classical.choice: for every type \(\alpha\), in any of the universes of Section 5.5, a function to \(\alpha\) from the proofs of Nonempty α, the proposition that \(\alpha\) has an element.

Logical equivalence a ↔ b lets one swap a and b inside familiar connectives like ∧ or →, yet cannot substitute b for a inside an arbitrary unknown predicate P : Prop → Prop; turning a ↔ b into an actual equality a = b via propext unlocks Eq.rec so equivalent propositions become interchangeable in every context. Despite living alongside Classical.choice, propext is not classical: its doc comment in Lean's sources notes that it is "intuitionistically valid".Init/Core.lean, lines 1603 to 1612, in the sources of Lean 4.35.0. The same comment says where the axiom is needed: "The standard logical connectives provably respect propositional extensionality. However, an axiom is needed for higher order expressions like P a where P : Prop → Prop is unknown, as well as for equality." It is also the axiom encountered most often in practice, because the simplifier tactic simp (Section 10.3) closes goals by rewriting proved propositions p to True, using the equation p = True derived from propext.

Quot.sound names none of the three missing habits directly, yet Section 7.3 derives function extensionality from it. As Section 6.4 noted, the quotient type former Quot r, constructor Quot.mk, function lifter Quot.lift, and induction principle Quot.ind are built into the kernel together with the reduction rule Quot.lift f h (Quot.mk r a) ≡ f a. On their own they assert nothing new: interpreting Quot r trivially as α itself and Quot.mk r as the identity map satisfies all four constants and their computation rule without gluing anything together, which is why, in the words of Theorem Proving in Lean, "these four constants are not viewed as additional axioms".J. Avigad, L. de Moura, S. Kong and S. Ullrich, with contributions from the Lean community, Theorem Proving in Lean 4 (lean-lang.org/theorem_proving_in_lean4), chapter 12, "Axioms and Computation", Section 12.4. The book states that it assumes Lean 4.33.0; what it says of the three axioms agrees with the sources of 4.35.0. Only Quot.sound forces Quot.mk r a = Quot.mk r b whenever r a b holds, collapsing related elements into genuine equivalence classes (along the equivalence relation generated by r, even when r itself is not an equivalence relation).

Nonempty α is an inductive proposition with one constructor, Nonempty.intro, which takes an element of α. A proof of it does not give the element back, since the kernel lets such a proof be taken apart only inside another proof (Section 6.5). Classical.choice is the elimination into data that the kernel withholds, postulated without a rule of computation. It could not have one: Nonempty.intro 0 and Nonempty.intro 1 prove the same proposition, the kernel treats two proofs of one proposition as equal (proof irrelevance, Section 6.3), and a rule that sent each proof back to its element would make 0 equal to 1. The axiom's documentation says the rest.

The axiom of choice. Nonempty α is a proof that α has an element, but the element itself is erased. The axiom choice supplies a particular element of α given only this proof.

The textbook axiom of choice normally makes a family of choices all at once, but that is implied from this formulation, because if α : ι → Type is a family of types and h : ∀ i, Nonempty (α i) is a proof that they are all nonempty, then fun i => Classical.choice (h i) : ∀ i, α i is a family of chosen elements. This is actually a bit stronger than the ZFC choice axiom; this is sometimes called "global choice".

In Lean, we use the axiom of choice to derive the law of excluded middle (see Classical.em), so it will often show up in axiom listings where you may not expect. You can use #print axioms my_thm to find out if a given theorem depends on this or other axioms.

This axiom can be used to construct "data", but obviously there is no algorithm to compute it, so Lean will require you to mark any definition that would involve executing Classical.choice or other axioms as noncomputable, and will not produce any executable code for such definitions.

—Lean 4.35.0, the documentation of the axiom Classical.choice. Init/Prelude.lean, lines 843 to 864, with the axiom on line 865; Lean 4.35.0 was released on 12 October 2026. Nonempty is declared just above it, as a proposition that "does not actually carry an element of α, only a proof that there exists such an element".

The axiom is global: one function for all types at once, where the axiom of choice of ZFC, Zermelo-Fraenkel set theory with choice, gives a function for one family of sets at a time.

Three axioms: what each says, what follows, what it costsa row to an axiom; in ink, the axiom as Lean prints it and how many theorems of the core library rest on it

  1. 7.2propext propositional extensionality

    Propositions that imply each other are equal, so one may stand for the other anywhere. It is what simp rewrites with. Cost: the kernel cannot compute through an equation proved with it; compiled programs are not touched.

    propext : ∀ {a b : Prop}, (a ↔ b) → a = b

    under 71,882 of the 89,360 theorems of the core library

  2. 7.3Quot.sound soundness of quotients

    Related elements have equal classes in the quotient. Function extensionality follows from it in eight lines. Cost: the same as for propext, terms that stop in the kernel and nothing lost in compiled code.

    Quot.sound.{u} : ∀ {α : Sort u} {r : α → α → Prop} {a b : α},

    r a b → Quot.mk r a = Quot.mk r b

    under 52,016 of the 89,360 theorems

  3. 7.4Classical.choice choice

    From a proof that a type has an element, an element. With the other two it gives the excluded middle. Cost: what it returns cannot be computed, and a definition whose value uses it must be marked noncomputable.

    Classical.choice.{u} : {α : Sort u} → Nonempty α → α

    under 35,231 of the 89,360 theorems

A list of axioms can show other names. Those that Lean itself supplies mark a proof left unfinished or one that ran compiled code.

Remark 7.2.2 (a fourth axiom, and two that are gone). The core library of Lean 4.35.0 declares four axioms. The fourth, sorryAx, gives an element of every type; it is what an unfinished proof leaves behind (Section 12.2), and no theorem of the core library rests on it. Older texts list more. Lean.ofReduceBool and Lean.trustCompiler, which stood behind proofs that run compiled code, no longer exist, and a proof by native_decide now leaves an axiom of its own, named after the theorem (Section 10.4).

Are the three safe? The reference manual calls them "three such axioms that are known to be consistent".Reference manual, chapter 8, "Axioms", second paragraph; it does not say on what the knowledge rests. The model of the next sentence is that of M. Carneiro, "The Type Theory of Lean" (thesis, Carnegie Mellon University, 16 April 2019), which shows the theory of Lean 3, these three axioms included, to be consistent if set theory with \(n\) inaccessible cardinals is consistent for every \(n\). Section 6.6 says what that leaves open for Lean 4. In the model of Section 6.6, made in set theory for the theory of Lean 3, each is plainly true: a proposition is the empty set or a set with one element, a quotient is the set of classes, and a choice function on the universe of the model picks an element of every nonempty set.

Neither function extensionality nor the excluded middle is among the three. Both have to be theorems.

What follows

Function extensionality is the first consequence, and has to be: the proof of the excluded middle uses it. Lean's library proves it in eight lines.

theorem funext {α : Sort u} {β : α → Sort v} {f g : (x : α) → β x}
    (h : ∀ x, Eq (f x) (g x)) : Eq f g :=
  let eqv (f g : (x : α) → β x) := ∀ x, Eq (f x) (g x)
  let extfunApp (f : Quot eqv) (x : α) : β x :=
    Quot.liftOn f
      (fun (f : ∀ (x : α), β x) => f x)
      (fun _ _ h => h x)
  congrArg extfunApp (Quot.sound h)

How can quotienting turn pointwise agreement ∀ x, f x = g x into actual equality f = g between the original functions? Quotienting the function space by the relation eqv (agreeing at every input x) identifies the equivalence classes [f] and [g] in Quot eqv via Quot.sound, which still lives in the quotient rather than in (x : α) → β x. To return from the quotient to ordinary functions, observe that evaluating a representative at x gives the same answer across an entire equivalence class, so evaluation lifts to a map extfunApp : Quot eqv → (x : α) → β x. Applying extfunApp to [f] = [g] equates extfunApp [f] and extfunApp [g]; the kernel's built-in quotient reduction and \(\eta\)-rule then simplify extfunApp [f] directly to f and extfunApp [g] directly to g.

Theorem 7.3.1 (function extensionality). Let f and g be of type (x : α) → β x. If f x = g x for every x, then f = g. The proof uses the axiom Quot.sound and no other.

Proof. In the listing, eqv is the relation of agreeing at every argument, and extfunApp q x is evaluation at x lifted to the quotient Quot eqv, which is allowed because related functions have the same value at x (Quot.liftOn is Quot.lift with its arguments in another order). The hypothesis h says that f and g are related, so Quot.sound h proves Quot.mk eqv f = Quot.mk eqv g, and congrArg applies extfunApp to both sides: extfunApp (Quot.mk eqv f) = extfunApp (Quot.mk eqv g). The left side unfolds to fun x => Quot.lift (fun f => f x) _ (Quot.mk eqv f). The rule of computation of the quotient reduces it, under the binder, to fun x => f x, and that is f by the rule η, which identifies a function with the function that applies it (Section 6.3); likewise on the right. The equation obtained is therefore the equation f = g up to definitional equality, and the kernel accepts the proof of the one as a proof of the other. ∎

That last step needs the rule of computation to be the kernel's own. One that held only as a provable equation "would not suffice", the reference manual explains, "because the reducible expression occurs in the body of a function and rewriting by an equality in a function would already require function extensionality".Reference manual, Section 4.5.6, "Quotients and Function Extensionality", for which function extensionality is a statement "which would need to be an axiom otherwise".

The second consequence closes the gap about cases, and it is the one that makes the logic classical.

sets     U = {x | x = True ∨ p}           V = {x | x = False ∨ p}        u, v: the members choose returns
         if p holds   { True, False, … }  =  { True, False, … }      u = v   (one set, so one member)
         if p fails   { True }            ≠  { False }               u ≠ v   (u = True, v = False)

cases    all the proof knows, without knowing p:   u = True ∨ p   and   v = False ∨ p

                        v = False         p
         u = True       u ≠ v, so ¬p      p
         p              p                 p            every case ends in p or in ¬p:  p ∨ ¬p

proof    the 32 lines of the theorem Classical.em (Init/Classical.lean, lines 36 to 67), in nine steps:
         the statement; the two sets; a witness for each; choose, which rests on Classical.choice;
         the two membership facts; their four cases; U = V when p holds, by propext and funext;
         equal sets get equal choices, by proof irrelevance; the conclusion
(the live figure needs JavaScript)
Lean's proof of the excluded middle, stepped beside the two sets of propositions it is about. Green: the member that choose returns from each set; while nothing says which, the ring runs round all of them. Underlined: the witness the proof writes down. Hatched: a case that cannot occur once p is chosen. The sets and the cases are a model computed in the page for the two truth values of p; the listing is the library's own text. Step through; set p; click a member of the first row to play the axiom; click a line of the proof to go to its step.

Notice that Classical.em never computes whether p is true or false. Instead, it builds two nonempty predicates on Prop, U x := (x = True) ∨ p and V x := (x = False) ∨ p, asks Classical.choice to pick a member u of U and a member v of V, and plays extensionality off against proof irrelevance: when p fails, U contains only True and V contains only False, forcing u ≠ v; when p holds, both predicates contain every proposition, so extensionality makes U and V the exact same predicate and proof irrelevance forces Classical.choice to pick the exact same element u = v.

Theorem 7.3.2 (the excluded middle). For every proposition \(p\), \(p \lor \lnot p\). The proof, Classical.em in Lean's library, uses Classical.choice, propext and funext, and so all three axioms.

The idea of the proof. Define the two predicates \(U(x) \;:=\; (x = \mathsf{True}) \lor p\) and \(V(x) \;:=\; (x = \mathsf{False}) \lor p\) over Prop. Without knowing anything about \(p\), True satisfies \(U\) and False satisfies \(V\), so both subtypes are nonempty and Classical.choice selects a proposition \(u\) satisfying \(U(u)\) and a proposition \(v\) satisfying \(V(v)\). Because the goal \(p \lor \lnot p\) is itself a proposition, case-splitting on the disjunctions \(U(u)\) and \(V(v)\) is permitted: in three of the four combinations \(p\) holds immediately, and in the fourth \(u = \mathsf{True}\) and \(v = \mathsf{False}\), which implies \(u \neq v\). Either way, \((u \neq v) \lor p\) holds constructively. All that remains is to prove that \(p\) implies \(u = v\), which contraposes \(u \neq v\) into \(\lnot p\). Assume \(p\) holds: then every proposition \(x\) satisfies both \(U(x)\) and \(V(x)\) via their right disjunct, giving \(U(x) \leftrightarrow V(x)\) for all \(x\). Propositional extensionality (propext) turns that equivalence into \(U(x) = V(x)\) at each \(x\), and function extensionality (funext, from Quot.sound) concludes \(U = V\) as predicates. Once \(U\) and \(V\) are identical, the two nonemptiness proofs handed to Classical.choice (one originally built from True, the other from False) inhabit the very same proposition Nonempty {x // U x}, so proof irrelevance (Section 6.3) makes them definitionally equal. Because Classical.choice is a function of the subtype and its erased nonemptiness proof, equal inputs force equal outputs: \(u = v\). Contraposing \(p \to u = v\) turns \(u \neq v\) into \(\lnot p\), converting \((u \neq v) \lor p\) into \(\lnot p \lor p\) and hence \(p \lor \lnot p\).

Every link in that chain is essential. If choice inspected how a nonemptiness proof was constructed and returned True from the first proof and False from the second, it would hand back two distinct answers on what becomes a single set when \(p\) holds, and Lean's proof would fail at rw [hpred]; intros; rfl.

Here the mathematics touches an old dispute. The excluded middle is what Brouwer's intuitionism gave up (Section 4.4; the quarrel is told in The painted rock). The constructive mathematics that came after gives it up still, and accepts choice, which the theorem seems to forbid. The Stanford Encyclopedia of Philosophy gives the answer.

The fact that the Axiom of Choice implies Excluded Middle seems at first sight to be at variance with the fact that the former is often taken as a valid principle in systems of constructive mathematics governed by intuitionistic logic, e.g. Bishop’s Constructive Analysis[16] and Martin-Löf’s Constructive Type Theory[17], in which Excluded Middle is not affirmed. In Bishop’s words, “A choice function exists in constructive mathematics because a choice is implied by the very meaning of existence.” Thus, for example, the antecedent \(\forall x \exists y \phi(x,y)\) of ACL, given a constructive construal, just means that we have a procedure which, applied to each \(x\), yields a \(y\) for which \(\phi(x, y)\). But this is precisely what is expressed by the consequent \(\exists f \forall x \phi(x,fx)\) of ACL.

To resolve the difficulty, we note that in deriving Excluded Middle from ACL1 essential use was made of the principles of Predicative Comprehension and Extensionality of Functions[18]. It follows that, in systems of constructive mathematics affirming AC (but not Excluded Middle) either the principle of Predicative Comprehension or the principle of Extensionality of Functions must fail. While the principle of Predicative Comprehension can be given a constructive justification, no such justification can be provided for the principle of Extensionality of Functions. Functions on predicates are given intensionally, and satisfy just the corresponding principle of Intensionality \(\forall X \forall Y \forall F[X = Y \rightarrow FX = FY]\). The principle of Extensionality can easily be made to fail by considering, for example, the predicates \(P\): rational featherless biped and \(Q\): human being and the function \(K\) on predicates which assigns to each predicate the number of words in its description. Then we can agree that \(P \approx Q\) but \(KP = 3\) and \(KQ = 2\).

—John L. Bell, "The Axiom of Choice" (revised 2021). Stanford Encyclopedia of Philosophy (plato.stanford.edu/entries/axiom-choice), first published 8 January 2008, substantive revision of 10 December 2021, Section 5, "The Axiom of Choice and Logic". ACL is the entry's name for the principle that if every \(x\) has a \(y\) with \(\phi(x, y)\), then a function \(f\) supplies one. The form used in its derivation, printed there as AC1L and as ACL1, says the same of a function that picks an instance of every predicate of a family. The bracketed numerals are the entry's footnote marks.

In Martin-Löf's constructive type theory, "there exists a \(y\)" is encoded as a dependent pair (y : B) × φ(x, y) in data (Section 5.2): every proof visibly carries its witness \(y\), so projecting out the first component proves a version of choice as a theorem without axioms, yet two proofs carrying True and False remain distinct terms and predicates are intensional (U ≠ V), blocking Diaconescu's collapse. Lean took the opposite fork on both counts. Its existential quantifier ∃ lives in Prop, erasing witnesses by proof irrelevance so that extracting a witness requires the axiom Classical.choice, while propext and funext make predicates extensional so U = V whenever p holds. Together, proof-irrelevant choice and extensional predicates satisfy every hypothesis of Diaconescu's argument, and excluded middle follows.The comment over Classical.em in Lean's sources calls it Diaconescu's theorem. By Bell's entry the derivation "was first given by Diaconescu (1975) in a category-theoretic setting", by way of quotients and without extensionality, and the idea of the proof with two predicates "goes back to Goodman and Myhill 1978, which was itself built on a result of Diaconescu 1975" (its note 15). Neither paper was read for this series. The entry lists them as R. Diaconescu, "Axiom of choice and complementation", Proceedings of the American Mathematical Society 51 (1975), pp. 176 to 178, and N. Goodman and J. Myhill, "Choice implies excluded middle", Zeitschrift für Mathematische Logik und Grundlagen der Mathematik 24 (1978), p. 461.

The three habits are now in the logic, through constants that do not compute. That cannot be free where equality is decided by computing.

What is lost, and what is not

A closed term of type Nat ought to be a number. Here is one made with choice, from a proof that was itself built from the number 7, and one made with function extensionality.

theorem ex : ∃ n : Nat, n * n = 49 := ⟨7, rfl⟩
def sub : {n : Nat // n * n = 49} := ⟨7, rfl⟩
noncomputable def w : Nat := Classical.choose ex
theorem w_spec : w * w = 49 := Classical.choose_spec ex

#eval sub.1
#reduce w
example : w = 7 := rfl
#eval w

def f (x : Nat) := x
def g (x : Nat) := 0 + x
theorem f_eq_g : f = g := funext fun x => (Nat.zero_add x).symm
def val : Nat := Eq.recOn (motive := fun _ _ => Nat) f_eq_g 0

#reduce val
example : val = 0 := rfl
#eval val
7
(Classical.choice ⋯).1
Stuck.lean:8:19: error: Type mismatch
  rfl
has type
  ?m.5 = ?m.5
but is expected to have type
  w = 7
Stuck.lean:9:0: error(lean.dependsOnNoncomputable): failed to compile definition, consider marking it as 'noncomputable' because it depends on 'w', which is 'noncomputable'
f_eq_g ▸ 0
Stuck.lean:17:21: error: Type mismatch
  rfl
has type
  ?m.5 = ?m.5
but is expected to have type
  val = 0
0

Classical.choose applies Classical.choice to an existential proof, so w has type Nat and w_spec proves w * w = 49 (from which arithmetic could prove w = 7). By computation alone, however, w is completely opaque: #reduce halts at Classical.choice, rfl cannot verify w = 7, and the compiler refuses to generate code for w because the witness 7 inside ex : Prop was erased. Store the very same witness and proof in the data subtype sub : {n : Nat // n * n = 49} instead, and #eval sub.1 prints 7 at once. Now compare val, which transports the number 0 along the extensionality proof f_eq_g : f = g across a constant family Nat. Inside the kernel, #reduce val gets stuck too: because f and g are not definitionally equal, Eq.recOn waits for Eq.refl and stalls on f_eq_g, which ends in the axiom Quot.sound (so rfl fails on val = 0). Yet #eval val prints 0 without complaint: the compiler (Section 8.2) erases all proofs and the type casts they justify before running what remains.

Both w and val are closed terms of type Nat (containing no free variables), yet kernel reduction brings neither one to a numeral. Every axiom sacrifices the guarantee that closed data terms compute to constructors.

Definition 7.4.1 (canonicity). A type theory has canonicity if every closed term of type Nat, one without free variables, reduces to a numeral.

Theorem Proving in Lean says of the fragment of Lean without axioms that it "guarantees that closed expressions in the system evaluate to canonical normal forms"; that is the book's claim, and a proof of it for Lean's theory was not found in the literature read for this series. With an axiom the property is gone by construction. The kernel computes with data by letting a recursor, the function that comes with an inductive type, meet a constructor (Section 6.3), and an axiom is a closed term that is no constructor and has nothing to unfold: "Axioms do not reduce to other terms."Reference manual, chapter 8, "Axioms", first paragraph, and Section 8.3, "Reduction": "The ι-reduction rule specifies the interaction of recursors and constructors; because axioms are not constructors, it does not apply to them." The claim of the book is in the opening of its chapter 12. In the kernel, then, the three axioms cost the same. In a program they do not.

The addition of propositional extensionality and function extensionality can have negative effects on computational reduction. Ideally, in a constructive type theory, every closed term of type N should reduce to a numeral. The extensionality axioms, however, can block such reductions; for example, there is generally no way to reduce an expression subst 𝑒 ℎ when 𝑒 is an instance of the extensionality axiom, even though the substitution operator subst can be interpreted as a computationally inert operation that only serves to modify the type of ℎ. But propositional and function extensionality are generally consistent with computational interpretations that ignore type information and replace subst 𝑒 ℎ by ℎ. As a result, a constructive proof assistant that incorporates extensionality can still support code extraction. In contrast, the use of the choice axiom breaks the computational interpretation entirely. With functional extensionality, propositional extensionality, and choice, dependent type theory has a fully classical flavor.

—Jeremy Avigad, "Foundations" (2021). arXiv:2009.09541, version 4 of 30 August 2021, a chapter written for the Handbook of Proof Assistants and Their Applications in Mathematics and Computer Science (edited by J. Blanchette and A. Mahboubi), Section 6.7, "Additional axioms". Here subst is the operation that carries a term along an equation, as Eq.recOn does in val, and N is the type of natural numbers.

A term made with propext or Quot.sound is a proof, and a proof leaves no trace in compiled code. A term made with Classical.choice can be data, and then Lean asks for the word noncomputable: the definition lives in the logic alone.

The excluded middle stays on the harmless side of that line as long as it stays in proofs. It crosses the line in a program that branches on a proposition. An if needs data to branch on, an instance of Decidable p: in Lean 4.35.0, a Bool with a proof that it is true exactly when p holds (Section 6.5). For a proposition such as n % 2 = 0 the library has a program that computes the Bool. For an arbitrary proposition it has this.

/-- All propositions are `Decidable`. -/
noncomputable scoped instance (priority := low) propDecidable (a : Prop) : Decidable a :=
  choice <| match em a with
    | Or.inl h => ⟨isTrue h⟩
    | Or.inr h => ⟨isFalse h⟩

By the excluded middle one of the two cases holds, and each gives an instance, so the type Decidable a is not empty; choice then returns an element of it. The Bool inside is true or false according to whether a holds, and nothing computes it.

So the excluded middle is in the library twice, as a theorem and as data, and Section 10.4 proves propositions by computing such data.

Remark 7.4.2 (a disjunction and its data). p ∨ ¬p and Decidable p say the same thing and are not the same kind of thing. The first is a proposition, and a proof of it cannot be asked which side holds, except inside another proof. The second is data: "It is this data that is needed to write an if-then-else expression," in the words of Theorem Proving in Lean.Theorem Proving in Lean 4, Section 12.6. That book, like older texts, describes Decidable as an inductive type with two constructors, isTrue and isFalse. By the release notes of Lean 4.35.0 "it is now a structure that stores a Bool together with a proof that this Bool reflects the proposition", and the two names remain as abbreviations.

What a proof of existence gives youone fact, that some natural number has square 49, held three ways; in ink, the term and what Lean answers

  1. 7.4a witness held as data

    The constructive reading: a proof of existence is a witness together with a proof that it works. Held as a pair of a number and a proof, the fact hands its number to any program.

    def sub : {n : Nat // n * n = 49} := ⟨7, rfl⟩

    #eval sub.1 prints 7

  2. 7.1a truth held as a proposition

    A proposition keeps its witness to itself, even when its proof was built from the number 7: a proof of existence can be taken apart only inside another proof. This is all that a classical proof, by contradiction, has to give.

    theorem ex : ∃ n : Nat, n * n = 49 := ⟨7, rfl⟩

  3. 7.4a witness by choice Classical.choose

    Choice turns the truth into a number that has the property. The kernel cannot reduce it, rfl cannot tell that it is 7, and the compiler will not run it.

    noncomputable def w : Nat := Classical.choose ex

    #reduce w prints (Classical.choice ⋯).1

    w * w = 49 is a theorem; w = 7 is refused by rfl

What is kept is most of what a programmer or a constructive mathematician would want kept: a program whose proofs use the axioms runs as before, a proof made without them can still compute in a kernel, as the constructive proof of Section 4.5 did in the page's, and the terms record which is which.

The axioms under a theorem

Whoever certifies a proof asks which axioms it rests on, and the terms answer. Here is every theorem of the core library of Lean 4.35.0 as a mark, by the axioms under it.

the theorems of the core library of Lean 4.35.0 by the axioms under each (the sets a walk of the exported terms finds)

library   theorems   no axiom   propext only   quotients, no choice    choice
Init        45,494      8,924         12,963                 12,819    10,788   24%
Std         34,383      3,576          5,405                  3,763    21,639   63%
Lean         9,483      4,336          1,801                    542     2,804   30%
all         89,360     16,836         20,169                 17,124    35,231   39%
                        18.8%          22.6%                  19.2%     39.4%

the map   a mark to a theorem, a block to a namespace within its library, largest first, 863 namespaces in all
          Init   List 5,685 · String 5,279 · Array 3,355 · Int 3,180 · ...
          Std    Std.DTreeMap 10,343 · Std.DHashMap 4,233 · Std.Tactic 2,068 · Std.TreeMap 2,042 · ...
          Lean   Lean.Meta 2,709 · Lean.Elab 1,615 · Lean.Compiler 878 · Lean.Lsp 767 · ...
marks     green: no axiom; ink, darker with more: propext only; quotients, no choice; choice

a theorem is what the kernel holds as one: 44,237 of the 89,360 are generated by Lean (equation lemmas, proofs split off)
Lean's own #print axioms, asked from a file that imports the library, names fewer axioms for 80 of them, never more
(the live figure needs JavaScript and loads about 0.3 MB)
Every theorem of the core library of Lean 4.35.0 as a mark, by the axioms under it, in blocks by namespace within its library. Green: theorems whose proof uses no axiom. Ink, darker with more: propext only; quotients, no choice; choice. The sets are those a walk of the exported terms finds. A theorem here is the kernel's: of the 89,360, 44,237 are generated by Lean, as equation lemmas and proofs split off. Choose a kind to see where it enters; point at a block to read its namespace, or at a library's line.

Of the 89,360 theorems of the core library, 16,836 have a proof that uses no axiom and 35,231 rest on choice: a quarter of Init and nearly two thirds of Std. propext alone stands under more theorems (20,169) than no axiom at all. A theorem here is what the kernel holds as one, and 44,237 of the 89,360 are generated by Lean, as equation lemmas and as proofs split off from definitions. Counted one axiom at a time, propext stands under 71,882 theorems, Quot.sound under 52,016 and Classical.choice under 35,231.

None of this measures how constructive the mathematics is. A mark records what the library's proof rests on, not what the statement needs. Choice is thickest among the theorems about data structures that are compiled and run (1,451 of the 1,495 theorems of Std.HashMap rest on it): the programs compute, and the proofs about them are classical.

Two programs are meant to compute the axioms under a theorem, and comparing them takes an exact definition of the set.

Definition 7.5.1 (the axioms under a constant). Draw an edge from a constant to every constant that occurs in its type, or in its value if it has one (definitions, theorems and opaque constants have a value; of axioms, constructors and recursors only the type counts), and from every inductive type to each of its constructors. The axioms under a constant are the axioms that can be reached from it along edges, itself included if it is an axiom. The four constants of the quotient have no edges.

The command #print axioms is meant to print this set: "if a proof uses another proof, which itself uses an axiom, then the axiom is reported by #print axioms for both", as the reference manual puts it.Reference manual, Section 8.5, "Displaying Axiom Dependencies". In Lean's sources the walk is one function, and these are the lines that matter.

-- Insert sentinel to prevent infinite recursion (e.g., inductives ↔ constructors).
let savedAxioms := s.axioms
modify fun s => { s with axioms := {}, seen := s.seen.insert c #[] }
let collectExpr (e : Expr) : M Unit := e.getUsedConstants.forM (collect extFind?)
-- Take constants from the kernel env, which may differ from the elab env for (async) errors.
match env.checked.get.find? c with
| some (.axiomInfo v)  =>
    modify fun s => { s with axioms := s.axioms.insert c }
    collectExpr v.type
| some (.defnInfo v)   => collectExpr v.type *> collectExpr v.value
| some (.thmInfo v)    => collectExpr v.type *> collectExpr v.value
| some (.opaqueInfo v) => collectExpr v.type *> collectExpr v.value
| some (.quotInfo _)   => pure ()
| some (.ctorInfo v)   => collectExpr v.type
| some (.recInfo v)    => collectExpr v.type
| some (.inductInfo v) => collectExpr v.type *> v.ctors.forM (collect extFind?)
| none                 => pure ()

The cases of the match are the edges of the definition. The lines before it are a guard: the type of a constructor names its inductive type, which leads back to its constructors, so a constant is entered in the table seen, with an empty list, before the walk goes below it. The lines around the listing do the rest: on the way back the empty list gives way to what was collected below (lines 68 to 74 of the file), and a constant found in seen contributes its entry and is not walked again (lines 46 to 49).

On small theorems the list shows where each axiom comes in.

theorem byRfl : 2 + 2 = 4 := rfl
theorem bySimp (xs : List Nat) : (xs ++ []).length = xs.length := by simp
theorem byOmega (a b : Nat) (h : a ≤ b) : a < b + 1 := by omega
theorem byCases (p : Prop) (h : ¬¬p) : p := by
  by_cases hp : p
  · exact hp
  · exact absurd hp h
theorem unfinished : 1 = 2 := sorry

#print axioms byRfl
#print axioms bySimp
#print axioms byOmega
#print axioms byCases
#print axioms unfinished
Axioms.lean:8:8: warning: declaration uses `sorry`
'byRfl' does not depend on any axioms
'bySimp' depends on axioms: [propext]
'byOmega' depends on axioms: [propext, Quot.sound]
'byCases' depends on axioms: [propext, Classical.choice, Quot.sound]
'unfinished' depends on axioms: [sorryAx]

rfl brings nothing, simp brings propext, omega, the tactic for linear arithmetic on integers and natural numbers (Section 10.5), adds Quot.sound, as every use of funext does, and a step by cases on a proposition that has no decision procedure brings all three, because the excluded middle is derived from choice. An unfinished proof shows as sorryAx.

In this version of Lean the list has a limit, and the census of the core library ran into it.

Example 7.5.2 (two answers). Across all 89,360 theorems of the core library of Lean 4.35.0, compare two axiom counts (one run of each): first, the set of axioms found by walking the exported terms directly (the library written out as plain data, Section 13.3); second, the set returned by Lean's own collector behind #print axioms when queried from a file that imports the library. On 1,084 of those theorems, run a third computation as well: a fresh walk inside Lean begun anew at that theorem. On 89,280 theorems the export walk and #print axioms agree. On the remaining 80, Lean's list is strictly shorter, and never longer; it reports 59 of the 80 as depending on no axiom at all. On all 1,084 re-tested theorems, the 80 discrepancies included, the fresh walk agrees with the export walk, and for each of the 80 the path to a missing axiom passes from an inductive type to its constructor. A small file exhibits the same effect: declare an axiom A alongside 24 copies of a structure whose constructor leads to A, each paired with a theorem whose statement mentions the structure and not its constructor. Asked inside the declaring file, Lean reports A for all 24. Asked from an importing file, Lean reports A for 21 and says of 3 that the theorem does not depend on any axioms (and for 7 of 40 on a second file), even though the copies differ only in their names. Wherever the two answers part ways, the longer list is what a walk of the exported terms finds. ◁

An issue opened on Lean's tracker on 19 September 2026 describes the same behavior and gives an account of its cause.

After #13117 (first released in v4.30.0), Lean.collectAxioms, and therefore #print axioms, which calls it, can report too few axioms for a declaration imported from another module. An inductive type can be reported as axiom-free while its own constructor, in the same query run, is reported as depending on Classical.choice. The under-report propagates to every declaration whose only path to the axiom goes through the inductive's name (e.g. a theorem whose statement mentions the type).

Queries made inside the defining module are correct; only queries from an importing module are wrong. The kernel is not involved. This is a false negative in the axiom-audit tooling.

—Issue 15226 of the Lean 4 repository, opened by skbaek on 19 September 2026. github.com/leanprover/lean4/issues/15226, "#print axioms / collectAxioms under-reports axioms of imported inductives (in-progress sentinel cached by exportedAxiomsExt)", section "Description"; skbaek is the name of the account. #13117, merged on 27 March 2026, is the change that stores the sets with the compiled file. A comment on the issue counts, on Lean 4.34.0, nine inductive types of Init whose list is shorter than that of their constructors: another count, of another thing, than the 80 theorems of the example. On 1 December 2026 the issue was open, and so were two pull requests that propose repairs.

Why would a cached walk miss an edge from an inductive type S to its constructor S.mk? Because S.mk's type mentions S while Definition 7.5.1 also draws an edge from S to S.mk, forming a cycle S ↔ S.mk. When a depth-first search starts at S.mk, marks S.mk as in progress with an empty placeholder, and visits S before S.mk has finished, S's only path to an axiom A runs back through the still-open S.mk; if the search permanently caches intermediate results for every node it finishes, S gets cached with an incomplete set. That behavior is a general property of memoized depth-first search on cyclic graphs.

Proposition 7.5.3 (a stored partial answer). A depth-first search of the graph of Definition 7.5.1 that collects the axioms it meets ends with all the axioms under the constant it started from. If it also stores, for each constant it leaves, the axioms met below that constant, and takes a constant that it is still inside to contribute nothing, then a stored set is contained in the axioms under its constant, and can be smaller.

Proof. What is collected was reached along edges, and each axiom under the start is handed up to it, level by level, when it is first met. For the last claim let S be an inductive type whose constructor S.mk has an argument whose type rests on an axiom A. A search that enters at S.mk comes to S, whose one way to A leads through S.mk, which the search is still inside: S is stored with the empty set, and S.mk after it with A. ∎

That Lean's listing is such a search is a reading of its source, this series' and the report's, and not a measurement. By that reading the list of an imported declaration is a stored set, since Lean 4.30.0 by the report: the axioms of all declarations of a file are computed in one search when the file is compiled, and a file that imports a declaration reads what was stored. The small file of Example 7.5.2 was written from the reading and behaved as it predicts. By the report's account the search takes the declarations in the order of a hash table of their names, so that "Adding, removing or renaming an unrelated sibling declaration can make the symptom appear or disappear." A maintainer answered on 25 September: "While arguably neither result is wrong, the inconsistency is not nice. #print axioms has been losing significance to lake check/compare and might be remodeled soon anyways". The report's table of the versions affected is its own and was not run for this series, and whether a proof can draw on an axiom that stays unreported in this way was not examined: the theorems of the small file are true without the axiom.

What, then, does a list of axioms tell whoever certifies a proof?

Remark 7.5.4 (what a list of axioms says). A list with the three axioms says that the proof assumed nothing beyond them and the rules of the kernel. It does not say that the theorem states what its name promises: for that, the reference manual asks that "its statement and all referenced definitions must be investigated carefully".Reference manual, chapter "Validating a Lean Proof", sections "Printing Axioms" and "Remaining Issues". Of the three axioms the first says: "The three axioms above are standard axioms of Lean's logic, and benign." And in Lean 4.35.0 the list for an imported theorem can be short. Every count of this part is therefore the walk's; Lean's collector gives 16,895 theorems with no axiom, 59 more than the walk. The readable edition of the Lean library published in November 2026 as a proof of the Riemann hypothesis (Section 12.3) says of itself that it "uses only the axioms propext, Classical.choice and Quot.sound", and gives the list that Lean prints for its first theorem.The README of the readable edition (github.com/lsernau/grh-lean, folder grh, at commit 72fead1), opening and sections "Build" and "Checks". The file that makes its list, scripts/PrintAxioms.lean, begins with import Main and asks #print axioms of the five theorems. The checkers it names are nanoda, con-leche and con-ron, which also ship with Lean 4.35.0. The edition is read as text in this series; nothing of it was built or run. That list is asked from a file that imports the proof, the one situation in which the listing of Example 7.5.2 came out short. This says nothing against the list, and whether it leaves an axiom out was not examined; it says what kind of evidence a list is. The same README reports an export accepted by three other checkers and a comparison of statements that permits these three axioms and no other (Section 13); on files written for this series, checkers of the same names let no axiom outside the three pass (Section 13.6). The listing is a convenience, and the walk of the exported terms is the check.

The walk checks what a proof assumed. It does not look at what the theorem says.

Totality and junk values

The second way in which a theorem of Lean can say something its reader did not expect needs no axiom. Every function of the logic has a value at every argument, even where the operation it is named after has none.

rows     14 statements of Lean's core library, each proved or refuted in Lean 4.35.0, read two ways:
         everyday     Lean accepted
         true         its negation    ∀ a b : Nat, a - b + b = a            subtraction stops at zero
         true         its negation    ∀ n : Nat, n - 1 < n                  fails at n = 0
         false        a proof         ∃ n : Nat, n - 1 = n                  n = 0
         true         its negation    ∀ a b : Nat, 0 < b → a / b * b = a    division discards the remainder
         no meaning   a proof         ∀ a : Nat, a / 0 = 0                  division by zero returns zero
         true         a proof         ∀ a b : Nat, b ≤ a → a - b + b = a    the hypothesis keeps clear of it
         6 change their truth value, 6 have no everyday meaning, 2 read the same; then 12 passages of
         Mathlib's source: a / 0 = 0 in a field, √x = 0 for x ≤ 0, log 0 = 0, a value for ζ at 1

plane    a - b for every a and b up to 9, hatched where b exceeds a (off its domain): the first
         statement fails at 45 of the 100 pairs, every one of them in the hatched half
both     at a = 0, b = 1       Lean's conventions  everyday mathematics
         a - b                 0                   −1
         a - b + b             1                   0
         a - b + b = a         false               true
(the live figure needs JavaScript and loads about 0.03 MB of data)
Statements read two ways: as everyday mathematics, and as Lean checks them, where every function is total and the library fixes a value off the domain. Green: the operation whose convention is at work. The plane holds every pair of operands of that operation up to 9, hatched where it is off its domain; a dot where the statement holds under Lean's conventions, a cross where it fails. The verdicts on the 14 statements are Lean 4.35.0's, recorded; the plane and the two computations are the page's, held to the recording. Mathlib's lines are quoted, not run. Click a row or a pair; type a statement.

Lean accepted a proof of ¬ ∀ a b : Nat, a - b + b = a. The statement fails at \(a = 0\), \(b = 1\), because 0 - 1 is 0. With the hypothesis b ≤ a it is a theorem, and that hypothesis is exactly the boundary of the region where subtraction has stopped at zero.

That 0 - 1 is 0 is a choice: the logic asks only for some value, and a reader of statements has to know who picks it.

Definition 7.6.1 (total functions and junk values). In Lean's logic a function f : α → β has a value f a at every a : α. Where f stands for an operation of mathematics that is defined on a part of α only, its values on the rest are fixed by the library that defines it. They are called junk values.

"From the perspective of Lean's logic, all functions are total," says the reference manual,Reference manual, Section 4.1.4, "Totality and Termination". and a function type has no room for "undefined". Of the ways to fit a partial operation into such a logic, two are taken up here.Avigad, "Foundations", Section 2.5, lists four, and says of the first: "This device does not change the meaning of any statement that does not mention the division symbol; it merely introduces an alternative to division with similar properties." The words on subtraction and division are from the documentation of Nat.sub and Nat.div in Init/Prelude.lean. The logarithm is in Mathlib/Analysis/SpecialFunctions/Log/Basic.lean, lines 39 to 45, at the commit of Mathlib that the readable edition is built on; Mathlib is read as text in this series and was not built. One is to choose values off the domain: in the core library subtraction of natural numbers is "truncated at 0", "Division by 0 returns 0", and List.head! of the empty list of numbers is 0. The other is to put the domain into the type, so that the function asks for a proof: List.head has the type (as : List α) → as ≠ [] → α. Lean and Mathlib mostly go the first way, and pick the values so that as many identities as possible lose their hypotheses. Mathlib extends the real logarithm to the negative numbers by the logarithm of the absolute value, so that log (x * y) = log x + log y holds for all nonzero x and y (Section 11.6 quotes its source).

The convention that frees one identity of its hypothesis makes another false, so none carries over from everyday mathematics unread.

Remark 7.6.2 (three fates of an identity). An identity of everyday mathematics that involves a partial operation becomes one of three things in Lean. It may be a theorem without hypotheses, true off the domain as well: n * (m / n) + m % n = m holds for all natural numbers, and with the conventions m / 0 = 0 and m % 0 = m it holds at n = 0 too. It may be a theorem with its hypothesis written out: m ≤ n → n - m + m = n. Or it is false, and its negation is the theorem.

A value that mathematics does not have looks like a way to prove falsehoods. The clearest answer was written for an earlier version of Lean.

It’s probably for the following reason. You are imagining that a computer proof checker will be checking your work, and in particular checking to see if you ever divided by zero, and if you did then you expect it to throw an error saying that your proof is invalid. What you need to internalise is that Lean is just using that function \(f\) above, defined by \(f(x,y)=x/y\) for \(y\not=0\) and \(f(x,0)=0\). In particular you cannot prove false things by applying \(f\) to an input of the form \((x,0)\), because the way to get a contradiction by dividing by zero and then continuing will involve invoking theorems which are true for mathematical division but which are not true for \(f\). For example perhaps a mathematician would say \(a/a=1\) is true for all \(a\), with the implicit assumption that \(a\not=0\) and that this can be inferred from the notation. Lean’s theorem that real.div a a = 1 is only proved under the assumption that \(a\not=0\), so the theorem cannot be invoked if \(a=0\). In other words, the problem simply shows up at a different point in the argument. Lean won’t accept your proof of \(1=2\) which sneakily divides by 0 on line 8, but the failure will occur at a different point in the argument. The failure will still however be the assertion that you have a denominator which you have not proved is nonzero. It will simply not occur at the point when you do the division, it will occur at the point where you invoke the theorem which is not true for real.div.

—Kevin Buzzard, "Division by zero in type theory: a FAQ" (2020). The Xena project blog, 5 July 2020 (xenaproject.wordpress.com), the answer to the question "OK so I can see that it can be made to work. Why do I still feel a bit uncomfortable about all this?". The post is written for Lean 3, where the division of real numbers was called real.div. Another of its answers has the rule of the craft: "It is in the theorems where one puts the non-negativity hypotheses."

That settles proofs, not statements.

Remark 7.6.3 (junk can change a statement, not a proof). Inside a proof, then, a junk value does no harm: every lemma that holds only on the intended domain carries an explicit hypothesis keeping its inputs there. What a junk value can change is what a theorem's statement means. ∃ n : Nat, n - 1 = n is a theorem of Lean, with 0 as its witness. Even an apparent guard does not always restrict inputs to the everyday domain: ∀ a b : Nat, b ∣ a → a / b * b = a has a true hypothesis at \(a = 0\), \(b = 0\) (since 0 ∣ 0 holds via 0 * 0 = 0), where 0 / 0 has no everyday value, and Lean's theorem covers that pair. For every partial operation appearing in a statement, a reader must check whether the hypotheses allow inputs off its domain.

The statement that this series is heading for is a case. Mathlib's zeta function is defined on all complex numbers, and the library's source proves riemannZeta 1 = (γ - log (4 * π)) / 2 under a comment that says "mathematically ζ 1 is undefined" (Section 11.6 has the passage). Its statement of the Riemann hypothesis, RiemannHypothesis, carries the hypothesis s ≠ 1, which keeps it independent of that value.riemannZeta_one is in Mathlib/NumberTheory/Harmonic/ZetaAsymp.lean, lines 418 to 420, and RiemannHypothesis in Mathlib/NumberTheory/LSeries/RiemannZeta.lean, lines 185 and 186. A floating-point evaluation, which is no result of Lean, puts the value near −0.977.

A theorem about that value is a theorem about a convention. Is that peculiar to type theory?

Sets and types as foundations

Type theory is not alone in proving things that nobody means. Set theory does it in another place.

The root of the problem is that in the framework of ZFC, the elements of a set are always sets too. Thus, given a set X, it always makes sense in ZFC to ask what the elements of the elements of X are. Now, a typical set in ordinary mathematics is R. But accost a mathematician at random and ask them ‘what are the elements of π?’, and they will probably assume they misheard you, or ask you what you’re talking about, or else tell you that your question makes no sense. If forced to answer, they might reply that real numbers have no elements. But this too is in conflict with ZFC’s usage of ‘set’: if all elements of R are sets, and they all have no elements, then they are all the empty set, from which it follows that all real numbers are equal.

—Tom Leinster, "Rethinking set theory" (2012). arXiv:1212.6543, 28 December 2012, section "Why rethink?". R is the set of real numbers. The last paragraph of the section says: "in ZFC, it is always valid to ask of a set ‘what are the elements of its elements?’, and in ordinary mathematical practice, it is not."

In ZFC everything is a set, so of any two objects one may ask whether the first is an element of the second, and the answer depends on how the objects were coded. With von Neumann's natural numbers, where \(n + 1 = n \cup \{n\}\), the statement \(1 \in 3\) is a theorem. With Zermelo's, where \(n + 1 = \{n\}\), its negation is. From the two codings Paul Benacerraf concluded in 1965, as the Stanford Encyclopedia reports him, that "the natural numbers should not be identified with any set-theoretic objects": what counts is the structure that they have together.E. Reck and G. Schiemer, "Structuralism in the Philosophy of Mathematics", Stanford Encyclopedia of Philosophy (plato.stanford.edu/entries/structuralism-mathematics), substantive revision of 17 September 2025, Section 1.1, on P. Benacerraf, "What Numbers Could Not Be" (1965), which was not read for this series. The two codings are in the entry; the example \(1 \in 3\) is worked out here.

The theorem \(1 \in 3\) and the theorem about the zeta function at 1 are of one kind, and comparing the two foundations takes a name for it.

Definition 7.7.1 (junk theorem). A junk theorem is a theorem of a formal system that states no fact of the mathematics the system is used for. It is true of the coding and of nothing else.

The two foundations keep their junk in different places. In set theory it is in membership. A type theory refuses the question: given (1 : Nat) ∈ (3 : Nat), Lean looks for something that gives the membership of a number in a number a meaning, an instance of Membership Nat Nat, and reports that it found none. In exchange every function can be applied to every argument of its type, and the junk is in the values. A list of junk theorems of Lean and Mathlib published in 2025 has the value of the zeta function at 1 as its ninth, and says of the convention behind it that it "seems to be considered best practice (classically) for dealing with the fact that division is a partial function"."Some Junk Theorems in Lean", the description of the repository github.com/James-Hanson/junk-theorems-in-lean (created 23 November 2025; the file names no author). Its Theorem 9 is Mathlib's riemannZeta_one.

Types have a price of their own, in equations that cannot be written down. "It is disappointing that we have to worry about the differences between the natural number 2, the integer 2, and the real number 2 when formalizing a theorem in type theory," writes Avigad, whose survey weighs the two foundations and finds headaches "for the set theorist and type theorist alike".Avigad, "Foundations", Section 5.6, "Sets versus types". Lean accepts (2 : Nat) = (2 : Int) only by slipping in the function from Nat to Int, and prints the equation with an arrow, ↑2 = 2 (Section 9.5).

What a mathematician means lies in neither coding. Mathematical theorems are statements about abstract structure, and a formal theorem captures that meaning only insofar as its statement avoids the coding artifacts of its foundation. Whoever relies on a theorem checked by Lean therefore has reading left that no checker performs: inspecting every definition in the statement, checking its behavior off the domain, and verifying what each coercion arrow ↑ inserts. Section 11.6 carries out that reading for the statement of the Riemann hypothesis.

In Lean

A file that imports nothing is enough to meet the axioms at work; the blocks that follow stand in one file, a blank line between them. Begin with two programs that branch on a proposition.

def isEven (n : Nat) : Bool := if n % 2 = 0 then true else false
def everTrue (f : Nat → Bool) : Bool := if ∃ n, f n = true then true else false
Bits.lean:2:40: error(lean.synthInstanceFailed): failed to synthesize instance of type class
  Decidable (∃ n, f n = true)

Hint: Type class instance resolution failures can be inspected with the `set_option trace.Meta.synthInstance true` command.

Lean accepts isEven, because the library provides an algorithm that decides n % 2 = 0, and asks for a similar decision procedure in everTrue. No general procedure can exist: if one did, passing a function f that tests whether a chosen lambda term reaches normal form within n steps would decide whether an arbitrary lambda term halts, contradicting Theorem 1.5.2. Classical logic supplies the noncomputable Decidable instance of Section 7.4 instead, and Lean immediately flags the computational cost.

open Classical in
def everTrue' (f : Nat → Bool) : Bool := if ∃ n, f n = true then true else false

open Classical in
noncomputable def everTrue'' (f : Nat → Bool) : Bool := if ∃ n, f n = true then true else false
Bits.lean:5:4: error(lean.dependsOnNoncomputable): failed to compile definition, consider marking it as 'noncomputable' because it depends on 'propDecidable', which is 'noncomputable'

The second definition is accepted, as a function of the logic alone. The theorem that goes with it is a proof by cases on a proposition that nobody can decide.

theorem allFalseOrSomeTrue (f : Nat → Bool) : (∀ n, f n = false) ∨ (∃ n, f n = true) :=
  match Classical.em (∃ n, f n = true) with
  | Or.inl h => Or.inr h
  | Or.inr h => Or.inl fun n =>
      match hf : f n with
      | false => rfl
      | true => absurd ⟨n, hf⟩ h

Read constructively, as in Section 4.4, a proof of this statement would be a method that tells of every sequence of bits which case holds. This proof is no such method: it takes the case from Classical.em. Proof by contradiction is the same principle under another name, the theorem Classical.byContradiction. Mathlib's proofs write that step as by_contra; the core library has no tactic of that name (Lean answers unknown tactic), and two lines make one.

macro "by_contra " h:ident : tactic =>
  `(tactic| refine Classical.byContradiction fun $h => ?_)

theorem notNotElim (p : Prop) (h : ¬¬p) : p := by
  by_contra hn
  exact h hn

#print axioms isEven
#print axioms everTrue''
#print axioms allFalseOrSomeTrue
#print axioms notNotElim
'isEven' does not depend on any axioms
'everTrue''' depends on axioms: [propext, Classical.choice, Quot.sound]
'allFalseOrSomeTrue' depends on axioms: [propext, Classical.choice, Quot.sound]
'notNotElim' depends on axioms: [propext, Classical.choice, Quot.sound]

Invoke the excluded middle once, and all three axioms stand under the theorem.

Three axioms turn the constructive theory that the kernel checks into ordinary mathematics: two say that things which behave alike are equal, and cost the kernel its computation; the third takes an element from a bare proof of existence, gives the excluded middle with the other two, and costs the program. Which of them a theorem rests on can be computed from its term; what its statement says where a function is off its domain can only be read.

The terms that the kernel checks are written by programs, and the programs are written in Lean. Section 8 takes up that language, beginning with the two evaluators met here: the kernel's rules, which stopped at val, and the compiler, which ran it.

← Back to all posts