Lectures 1 to 4 showed how Lean checks a proof. This lecture is about everything the kernel does not check. When Lean accepts a theorem, it certifies one fact: this term has this type. Whether the type says what you meant, whether your definitions describe the objects you had in mind, and whether the whole development rests only on the axioms you expect are questions you must answer yourself. Most of the failures of formal proofs in practice are failures of this kind, not kernel bugs.
The answer is a routine. Working formalizers (the teams behind PFR, Carleson’s theorem, Fermat’s Last Theorem and sphere packing, listed in Lecture 13) follow roughly the same eight steps, and this lecture runs them on one small example from start to finish. By the end you should be able to take a statement you know on paper, write it in Lean, convince yourself the Lean version is the right one, and then prove and audit it. The same recipe drives Lecture 7, where the subject is quantum information.
Homework and cheatsheet
Homework 2 practises steps 3 and 4: you will find and fix misformalized statements. Cheatsheet: The formalization recipe, Junk values, Does the statement say what you mean?, Blueprints and sorry-first development, Finding lemmas.
The recipe at a glance
The eight steps, in order:
- Represent. Choose the Lean types for your objects.
- Define. Write the definitions.
- Sanity-check. Test the definitions on examples, including ones that should fail.
- State. Write the theorem, and check that it says what the English says.
- Blueprint. Split the proof into lemmas and record which lemma uses which.
- Search. Find what Mathlib already has.
- Sorry-first. State every lemma with
sorry, check that the skeleton fits together, then fill the holes. - Audit. Check that the result rests on no
sorry, no extra axiom, and the statement you meant.
The list is not a straight line. A failed sanity check sends you back to the definitions; a Mathlib search often reveals that the library represents your objects differently, and it pays to adopt its choice; a lemma you cannot prove may be false, which sends you back to the blueprint. The figure shows the main path and these three loops.
To make the steps concrete, every one of them is applied below to the same small statement.
Example 5.1 (The running example).The mean of finitely many rational numbers is at most any upper bound for them: if every
, then .
Steps 1 to 3: representation, definitions, sanity checks
Step 1: choose a representation
“Finitely many numbers” can be written in Lean in several ways, and the choice decides what is
easy later. A List ℚ keeps order and repetitions and can be computed with. A Finset ℚ is a
finite set, so repeated values collapse. An indexed family Fin n → ℝ matches the
#eval does with them). For a mean, collapsing repeats is a bug, not a detail:
import Mathlib
#eval ([1, 1, 4] : List ℚ).length -- 3
#eval ({1, 1, 4} : Finset ℚ).card -- 2The list has three entries; the finset has two elements, so a mean computed from it would be
List ℚ: it represents the data faithfully and lets us test
definitions by running them. A real-valued version can come later, once the definitions are
trusted.
Step 2: write the definitions
def mean (xs : List ℚ) : ℚ := xs.sum / xs.lengthNotice what Lean did silently: xs.length is a natural number, and dividing a rational by it
needs a rational, so Lean inserted a coercion from ℕ to ℚ. Lecture 6 explains coercions; here
it is enough to know they exist and that #check and hovering in the editor reveal them.
Step 3: sanity-check the definitions
Before proving anything, run the definition on inputs whose answer you know. #eval computes;
a small example turns the expected answer into a checked fact.
#eval mean [1, 2, 3, 4] -- 5/2
#eval mean [1, 1, 4] -- 2
#eval mean [] -- 0
example : mean [2, 4] = 3 := by norm_num [mean]The third line deserves attention. The mean of an empty list is mean; it is how division works in Lean and Mathlib, and it is the subject
of step 4.
Running examples by hand finds the bugs you think of. Property-based testing finds the ones you
do not: a tool generates many random inputs and checks a conjectured property on each. Lean’s tool
is Plausible, a separate package that
Mathlib depends on, so import Mathlib provides it (import Plausible alone also works). Let us
test the running example before trying to prove it. Plausible needs a property it can evaluate,
so the hypothesis “every xs.all (· ≤ M). (The
inputs are random; fixing the seed makes the run below reproducible.)
example (xs : List ℚ) (M : ℚ) (h : xs.all (· ≤ M)) : mean xs ≤ M := by
plausible (config := { randomSeed := some 7 })Plausible reports a counterexample, which makes this block fail, as intended:
===================
Found a counter-example!
xs := []
M := -1
guard: true
issue: 0 ≤ -1 does not hold
(0 shrinks)
-------------------The empty list satisfies the hypothesis vacuously (it has no element above
A sanity check should also include an example that must fail. A definition that accepts everything passes every positive test. We will see such a definition in a moment.
Step 4: does the statement say what you mean?
This is the step where formal proofs most often go wrong, and the one the kernel cannot help with.
Definition 5.1 (Faithful statement).A Lean statement is faithful to an informal statement if a mathematician who reads both agrees that every proof of the Lean statement would count as a proof of the informal one, and conversely. Faithfulness is a judgement made by people; no algorithm decides it.
Four patterns account for most unfaithful statements.
Junk values. Lean’s functions are total: every input gets an output, because a function that could fail would need a proof of “the input is allowed” at every use.
Definition 5.2 (Junk value).A junk value is the output a total function returns on an input where the mathematical operation is undefined, chosen by convention to make the function total and its lemmas simple.
example : (5 : ℕ) - 7 = 0 := rfl -- subtraction stops at 0
example : (7 : ℕ) / 0 = 0 := rfl -- so does division
example (x : ℝ) : x / 0 = 0 := div_zero x -- x / 0 = 0 in any field
example : Real.sqrt (-1) = 0 :=
Real.sqrt_eq_zero'.mpr (by norm_num) -- √ of a negative is 0
example : Real.log 0 = 0 := Real.log_zeroJunk values (Definition 5.2) are harmless in a theorem whose hypotheses keep the inputs where
the operation makes sense, and dangerous in a statement where the junk is reachable. A
statement about a - b on ℕ means what you think only if you also know b ≤ a; Lecture 1’s
example 2 - 5 + 5 = 5 is true for exactly this reason. Mathlib’s lemmas carry the
side conditions explicitly; for instance Nat.sub_add_cancel needs m ≤ n. When you read a
statement, ask of every -, /, √ and log whether its junk case is reachable.
Vacuous truth. A universal statement over an empty collection is true, and an implication with an impossible hypothesis is true. Both are logic, not bugs, but a statement with contradictory hypotheses proves anything:
example : ∀ x ∈ ([] : List ℚ), 100 < x := by
intro x hx
cases hx
example (x : ℝ) (h1 : 1 < x) (h2 : x < 0) : x = 37 := by
linarithThe second “theorem” is a correct proof of a useless statement. In a long development, two
hypotheses that cannot both hold are rarely this easy to see. A useful check: if a statement
was suspiciously easy to prove, try proving False from its hypotheses.
Quantifier order. “For every
example : ∀ n : ℕ, ∃ m, n < m := fun n => ⟨n + 1, Nat.lt_succ_self n⟩
example : ¬ ∃ m : ℕ, ∀ n, n < m := by
rintro ⟨m, hm⟩
exact lt_irrefl m (hm m)The same swap turns continuity into uniform continuity, and pointwise convergence into uniform convergence. Read every statement from left to right and ask who chooses each variable.
A wrong definition. The statement can be faithful and the definition it uses wrong. Here is
continuity at a point with one condition missing,
def SloppyContinuousAt (f : ℝ → ℝ) (a : ℝ) : Prop :=
∀ ε > 0, ∃ δ, ∀ x, |x - a| < δ → |f x - f a| < ε
theorem every_function_sloppy (f : ℝ → ℝ) (a : ℝ) :
SloppyContinuousAt f a := by
intro ε _
refine ⟨0, fun x hx => ?_⟩
exact absurd hx (not_lt.mpr (abs_nonneg _))With SloppyContinuousAt f a is now a theorem about all functions. The negative sanity check of
step 3 catches this: try to prove that a step function is not SloppyContinuousAt at its
jump. You cannot, and that failure is the signal.
For the running example, the faithful statement adds the missing hypothesis, written the way Mathlib writes “nonempty” for lists:
theorem mean_le_of_le (xs : List ℚ) (M : ℚ) (hne : xs ≠ [])
(h : ∀ x ∈ xs, x ≤ M) : mean xs ≤ M := by
sorryThe block ends in sorry, so Lean warns that the proof is missing; filling it is the work of
steps 5 to 7. The statement is the deliverable of step 4, and it is worth reading once more against the English (Definition 5.1)
before moving on.
Steps 5 to 8: blueprint, search, sorry-first, audit
Step 5: write a blueprint
For a large project, the proof is first written as a blueprint: a LaTeX document that splits the argument into small lemmas, each tagged with the Lean name it will get, whether it is finished, and which other lemmas it uses. Patrick Massot’s leanblueprint, which was written in 2020 for the sphere-eversion project, turns these tags into a web page and a dependency graph coloured by progress. For the running example the blueprint is three items:
\begin{lemma}\label{len-pos}\lean{List.length_pos_iff}\leanok
A nonempty list has positive length.
\end{lemma}
\begin{lemma}\label{sum-le}\lean{List.sum_le_length_nsmul}\leanok
If every entry is at most $M$, the sum is at most $n \cdot M$.
\end{lemma}
\begin{theorem}\lean{mean_le_of_le}\uses{len-pos, sum-le}
The mean is at most $M$.
\end{theorem}PFR, Carleson, the Fermat project and sphere packing all ran the same loop: write the
blueprint, state everything in Lean with sorry, hand out the open nodes of the graph to
contributors, move reusable material into Mathlib, and audit at the end (Lecture 13 describes
the projects). The Lean FRO is building a successor, Verso Blueprints. A guest post on the Xena blog of 2026-10-16,
“How to Formalize All of Mathematics”,
argues that experts should write these roadmaps even when AI writes the proofs.
Step 6: search Mathlib
Most lemmas you need already exist. Four ways to find them:
exact?searches the library for a term that closes the current goal, and prints what it found.apply?also reports lemmas that would make progress.- Loogle searches by the shape of a statement, such as
List.sum, List.lengthor?a * ?b = ?b * ?a. - LeanSearch searches by a description in plain English.
- Naming conventions: a lemma about
sumandlengthis likely calledsum_le_length_…. Lecture 6 explains the rules.
The two lemmas of the blueprint, found with exact?:
example (xs : List ℚ) (hne : xs ≠ []) : 0 < xs.length := by
exact?
example (xs : List ℚ) (M : ℚ) (h : ∀ x ∈ xs, x ≤ M) :
xs.sum ≤ xs.length • M := by
exact?Lean answers with Try this: [apply] exact List.length_pos_iff.mpr hne and
Try this: [apply] exact List.sum_le_length_nsmul xs M h; click the suggestion in the editor
to paste it. Names change between Mathlib versions, and search is how you keep up. The second
lemma was called List.sum_le_card_nsmul until recently, and the old name still works, with a
warning:
example (xs : List ℚ) (M : ℚ) (h : ∀ x ∈ xs, x ≤ M) :
xs.sum ≤ xs.length • M :=
List.sum_le_card_nsmul xs M hLean reports List.sum_le_card_nsmul has been deprecated: Use List.sum_le_length_nsmul
instead. Tutorials written for older versions are full of names like this one.
Step 7: sorry-first development
Write the whole proof skeleton with every lemma left as sorry, and make sure the skeleton
compiles. This checks that the lemmas, as stated, really combine into the theorem, before you
spend time proving any of them. Then fill the holes in any order.
theorem mean_le_draft (xs : List ℚ) (M : ℚ) (hne : xs ≠ [])
(h : ∀ x ∈ xs, x ≤ M) : mean xs ≤ M := by
have hlen : (0 : ℚ) < xs.length := by
sorry
have hsum : xs.sum ≤ xs.length * M := by
sorry
rw [mean, div_le_iff₀ hlen]
linarithLean accepts this with the warning declaration uses sorry: the skeleton fits, and two
holes remain. Filled in with the search results (and one cast, explained in Lecture 6):
theorem mean_le (xs : List ℚ) (M : ℚ) (hne : xs ≠ [])
(h : ∀ x ∈ xs, x ≤ M) : mean xs ≤ M := by
have hlen : (0 : ℚ) < xs.length := by
exact_mod_cast List.length_pos_iff.mpr hne
have hsum : xs.sum ≤ xs.length * M := by
rw [← nsmul_eq_mul]
exact List.sum_le_length_nsmul xs M h
rw [mean, div_le_iff₀ hlen]
linarithStep 8: audit
#print axioms mean_le_draft
#print axioms mean_leThe first reports 'mean_le_draft' depends on axioms: [propext, sorryAx, Classical.choice, Quot.sound]; the second reports the same list without sorryAx. sorryAx is the axiom
behind every sorry, so it is the first thing an audit looks for. The other three are Lean’s
standard axioms (Lecture 1). Anything else, such as a project’s own axiom declaration or the
extra axiom that native_decide adds, is an assumption to read and justify.
Remark 5.1 (What an audit establishes).Checking can be pushed further. The Lean toolchain ships
leanchecker, which replays compiled files through the kernel (it replaced the separate lean4checker in Lean 4.28.0), and since Lean 4.35.0lake comparator(formerly Comparator). Comparator takes a trusted challenge file containing the statement and a list of permitted axioms, and certifies that a separately written solution proves the same statement, with no other axioms, accepted by the kernel. What remains after all of this is the challenge file itself: someone must read its definitions and statement, which is step 4 again.
The audit (Remark 5.1) is why the figure’s longest arrow runs from step 8 back to step 4.
A cautionary tale: Navier–Stokes
On 2026-09-08 OpenAI announced finite-time blow-up for the three-dimensional Navier–Stokes
equations with a smooth external force, together with a 166-page paper and a Lean 4
repository, openai/NavierStokesAndEuler
(DISPUTED; announcement). The claim
targets alternatives (C) and (D) of the Clay Millennium Problem, which allow a force; the
unforced problem remains open. The repository’s challenge file states the theorem for
theorem navier_stokes_breakdown_R3 (nu : ℝ) (hnu : nu > 0) :
∃ (u₀ : ℝ³ → ℝ³) (f : ℝ³ → ℝ → ℝ³),
InitialVelocityConditionDecay u₀ ∧ ForceConditionDecay f ∧
¬ (∃ v p, NavierStokesExistenceAndSmoothnessRn nu u₀ f v p)Read it with step 4 in mind. For every viscosity, the prover chooses both the initial
velocity u₀ and the force f, subject to smoothness and decay conditions; then no smooth,
finite-energy solution (v, p) exists. That is a precise statement of a forced blow-up, and
the repository asks Comparator to check it against the axioms propext, Quot.sound and
Classical.choice. The definitions even document a junk value: the divergence of a
non-differentiable field is defined to be 0, because fderiv returns the zero map there.
On 2026-10-06 Bastounis, Circelli and Hansen published an objection,
“Navier–Stokes lost in translation”. Their point is not
that the Lean proof fails to check, but that it is not a translation of the paper. Two examples
from their article: the paper’s Lemma 8.6 bounds a quantity using
The episode separates three questions that headlines merge:
- Does the Lean proof check? That is the kernel’s and Comparator’s job.
- Does the Lean statement say what alternative (C) says? That is step 4, done by reading the challenge file.
- Is the 166-page English argument correct? Lean says nothing about it, unless the Lean proof follows the English one step by step, and the objection is that it does not.
Lean answers the first question with certainty. The second needs a careful reader, and the third is still ordinary peer review. Lecture 13 sets this case beside the other recent claims.
Try this
- Do Homework 2: each problem is a statement with a bug of one of the four kinds above.
- State “the maximum of a nonempty list is at least its mean” in Lean. Look up how Mathlib
represents the maximum of a list (
List.maximumreturns anOption; why?), test the statement withplausibleonℤ, then prove it sorry-first. - Write
CorrectContinuousAtwithδ > 0, and prove thatfun x => if x < 0 then 0 else 1is not continuous at 0 in your sense. Then try the same proof forSloppyContinuousAtand note where it breaks. - Find a Mathlib lemma whose hypotheses exist only to exclude a junk value (search Loogle for
Real.sqrtorNat.sub), and explain which junk value each hypothesis excludes.
Readings
- Patrick Massot, leanblueprint, and Terence Tao’s tour of the PFR blueprint (2023), which shows the dependency graph in use.
- Kevin Buzzard, “Division by zero in type theory: a FAQ”,
Xena blog, 2020: why Mathlib chooses
x / 0 = 0. - Avigad, Massot et al., Mathematics in Lean, chapters 2 and 3: how Mathlib states things, with many search exercises.
- A. Bastounis, F. Circelli, A. C. Hansen, Navier–Stokes lost in translation, arXiv 2610.08144, 2026.
- J. Avigad, K. Buzzard, J. Commelin, R. Degenne, S. Morrison, A. Nash, A. Topaz, “How to Formalize All of Mathematics”, Xena blog, 2026-10-16.