Automation and its limits
| Lean theorem prover: map |
|---|
| Reading the edition Three levels of reading Glossary Notation Chronology |
| Reading by level Start here: What a proof assistant does The type theory: Terms, types and judgments How Lean works: Elaboration The history: Automath The applications: Research mathematics |
| Sources Sources Bibliography Further reading |
| Related The move to Lean |
Some tactics do not wait to be told each step. Given a goal, they search for a proof themselves. This page describes four such tactics, says what each one searches, explains why no procedure can settle every question, and shows why a proof found by search is checked like any other.
Four searching tactics
theorem by_simp (xs : List Nat) : (xs ++ []).length = xs.length := by simp
theorem by_omega (x y : Nat) (h1 : x + 2 * y = 10) (h2 : 3 ≤ y) : x ≤ 4 := by omega
theorem by_decide : ∀ n : Fin 8, n.val * n.val % 8 ≠ 2 := by decide
theorem by_grind (f : Nat → Nat) (a b : Nat) (h1 : a = b) (h2 : f a = 3) :
f b = 3 := by grind
#print axioms by_simp
#print axioms by_omega
#print axioms by_decide
#print axioms by_grind
Each theorem is proved by a single word, and Lean accepts all four.
simp, the simplifier, rewrites the goal with a large stock of equations marked as simplification rules, working from the inside of an expression outwards, until no rule applies.[1] Here it knows that appending the empty list changes nothing, and the two sides become the same. It searches for places where a known equation applies. It cannot prove what does not follow by such rewriting.
omega settles problems of linear arithmetic over whole numbers: equations and inequalities built from unknowns, addition, and multiplication by fixed numbers, with division and remainder by fixed numbers. The reference manual calls it not yet a full decision procedure, but effective on many problems.[2] In the example, x + 2y = 10 and y of at least 3 force x to be at most 4.
decide computes. It finds a procedure that decides the statement, runs it, and if the answer is "true", the run is the proof.[2] The example checks the eight numbers from 0 to 7 and finds that none has a square leaving remainder 2 on division by 8. It works only when the statement contains no unknowns and a deciding procedure is available; computation inside proofs says more.
grind gathers facts and works on them with several methods at once. The reference manual pictures a shared whiteboard: each new equation or inequality is written on it, terms known to be equal are grouped together, and each method reads from the board and adds to it. The methods include merging equals (if a = b, then f a = f b), using known theorems that fit, splitting into cases, and solvers for linear arithmetic over the integers and for algebra. It always argues by contradiction: it assumes the goal is false and looks for an impossibility. It is not designed for problems whose cases multiply out of control, such as large instances of the pigeonhole principle.[3]
When the search fails
example (x y : Nat) (h : x * y = 6) : y ≤ 6 := by omega
The statement is true: if x times y is 6, then y divides 6, so y is at most 6. But a product
of two unknowns lies outside linear arithmetic. Lean 4.34.1 answers omega could not
prove the goal: and offers "a possible counterexample" in which y is at
least 7. The counterexample is only possible. It solves the simplified problem that omega
could see, in which the product says nothing about y, not the real one. A failed search is
information, not a verdict: the statement may still be true, and this procedure cannot see
why.
Why no procedure does everything
Two results from the 1930s mark the limit, and they are different results.
The first concerns what can be proved at all. Kurt Gödel showed in 1931, in a form that J. Barkley Rosser strengthened in 1936, that any consistent formal system in which a certain amount of elementary arithmetic can be carried out contains statements that it can neither prove nor disprove.[4][5]
The second concerns what a machine can decide. Alonzo Church and Alan Turing showed
independently in 1936 that there is no mechanical method which decides, for every formula of
first-order logic, whether it can be proved.[6][7][8] The same holds for every consistent
system that contains, or can interpret, a weak theory of arithmetic called Robinson
arithmetic: there is no mechanical way to tell its theorems from its other
statements.[5] Robinson arithmetic has seven axioms, simple facts about
zero, the next number, addition and multiplication.[5] Every statement
of arithmetic can be read as a Lean statement about Lean's natural numbers, and read that way
all seven axioms are theorems of Lean; the block below proves each in one line, where
Nat.succ x is the number after x and the last four hold by calculation:
-- 1. Zero is not the number after any number. theorem q1 (x : Nat) : Nat.succ x ≠ 0 := Nat.succ_ne_zero x -- 2. Different numbers have different numbers after them. theorem q2 (x y : Nat) (h : Nat.succ x = Nat.succ y) : x = y := Nat.succ.inj h -- 3. Every number other than zero is the number after some number. theorem q3 (x : Nat) (h : x ≠ 0) : ∃ y, x = Nat.succ y := Nat.exists_eq_succ_of_ne_zero h -- 4 to 7. Addition and multiplication, by recursion on the second number. theorem q4 (x : Nat) : x + 0 = x := rfl theorem q5 (x y : Nat) : x + Nat.succ y = Nat.succ (x + y) := rfl theorem q6 (x : Nat) : x * 0 = 0 := rfl theorem q7 (x y : Nat) : x * Nat.succ y = x * y + x := rfl
Lean 4.34.1 accepts all seven. A procedure that decided provability in Lean would therefore also decide which statements of arithmetic Lean proves. Those statements form a system that contains Robinson arithmetic and is consistent if Lean's logic is, so the result just stated rules such a procedure out. If Lean's logic is consistent, then, no tactic, however clever, can decide for every statement whether Lean can prove it.
The word "undecidable" is used for both results, in two senses: a single statement that a
system can neither prove nor disprove, and a whole class of questions that no machine can
answer.[5] In practice the limit means that some procedures in Lean
work within a class of statements chosen so that a method exists, as decide
does for finite checks, while others, such as simp and grind, are
searches that often succeed and sometimes give up. Beyond them, a person still has to find
the idea.
Found by search, checked by the Lean kernel
However a tactic finds its proof, what it hands over is an ordinary proof term, and the Lean
kernel checks that term like any other. The manual says of grind that it
produces ordinary proof terms for every fact it adds.[3] A bug in
automation can therefore cost time or produce a confusing message; it cannot make Lean accept
a false theorem.[9] Keeping the search for a
proof apart from its checking is an established technique in the LCF tradition from which tactics
come.[10]
The #print axioms lines above show what the four proofs rest on. Lean 4.34.1
answers that by_decide does not depend on any axioms, that
by_simp depends on propext, that by_omega depends on
propext and Quot.sound, and that by_grind depends on
those two and Classical.choice. These are Lean's three standard axioms,
described in what the axioms are.
Nothing was added by the search.
Next
- When Lean says no: reading the messages of a failed check.
- Decision procedures: the technical treatment.
References
- ↑ The Lean Language Reference, version for Lean 4.34.0 (lean-lang.org, 2026), chapter 15, "The Simplifier". https://lean-lang.org/doc/reference/4.34.0/The-Simplifier/
- ↑ 2.0 2.1 The Lean
Language Reference, version for Lean 4.34.0 (lean-lang.org, 2026), section 14.5, "Tactic
Reference": entries for
omegaanddecide. https://lean-lang.org/doc/reference/4.34.0/Tactic-Proofs/Tactic-Reference/ - ↑ 3.0 3.1 The Lean Language Reference, version for Lean 4.34.0 (lean-lang.org, 2026), chapter 16, "The grind tactic". https://lean-lang.org/doc/reference/4.34.0/The--grind--tactic/
- ↑ Kurt Gödel, "Über formal unentscheidbare Sätze der Principia Mathematica und verwandter Systeme I", Monatshefte für Mathematik und Physik 38 (1931), pp. 173–198. doi:10.1007/BF01700692
- ↑ 5.0 5.1 5.2 5.3 Panu Raatikainen, "Gödel's Incompleteness Theorems", The Stanford Encyclopedia of Philosophy (first published 2013, substantive revision 8 October 2025), sections 1 and 4.2. https://plato.stanford.edu/entries/goedel-incompleteness/
- ↑ Alonzo Church, "A note on the Entscheidungsproblem", Journal of Symbolic Logic 1 (1936), pp. 40–41. doi:10.2307/2269326
- ↑ A. M. Turing, "On Computable Numbers, with an Application to the Entscheidungsproblem", Proceedings of the London Mathematical Society, series 2, vol. 42 (1936–37), pp. 230–265. doi:10.1112/plms/s2-42.1.230
- ↑ B. Jack Copeland, "The Church-Turing Thesis", The Stanford Encyclopedia of Philosophy (first published 1997, substantive revision 18 December 2023), section 1.7. https://plato.stanford.edu/entries/church-turing/
- ↑ The Lean Language Reference, version for Lean 4.34.0 (lean-lang.org, 2026), chapter 14, "Tactic Proofs". https://lean-lang.org/doc/reference/4.34.0/Tactic-Proofs/
- ↑ Michael J. C. Gordon, "From LCF to HOL: a short history", in Gordon Plotkin, Colin Stirling and Mads Tofte (eds), Proof, Language, and Interaction: Essays in Honour of Robin Milner, MIT Press, 2000. https://www.cl.cam.ac.uk/~mjcg/papers/HolHistory.html