10. Tactics and automation

Draft

A proof state is a term with holes

After the word by, a Lean file stops stating a proof and starts giving orders: intro h, simp, omega. Each order is a tactic, a program that looks at what is left to prove and does some of it. Nobody writes the kernel terms of Section 6 by hand; for proofs, tactics write them. This part follows what they write, from tactics that apply a single rule of logic to tactics that search for seconds, and it asks one question of each: what does it hand to the kernel? The answer is always a term, and that is the point. A tactic may guess, backtrack, call a solver outside Lean or have a bug, and none of that has to be believed, because only the term it leaves behind is checked. Search is untrusted and checking is trusted.

This is the second half of the series' third step: where the elaborator of Section 9 filled holes in a partially written expression, after by there is no expression at all until tactics build one. Small tactics apply one logical rule at a time, leaving the user to choose every step. Automated tactics discover the steps on their own and convince the kernel in one of three ways: by writing out the chain of primitive inferences explicitly, by reducing the goal to a Boolean computation that the kernel evaluates, or by searching freely outside the logic for a compact certificate whose verification is cheap. Each strategy pays a distinct price: a larger proof term, longer kernel evaluation time, or an added axiom trusting compiled code.

written    theorem and_or_distrib_tactic (p q r : Prop) : p ∧ (q ∨ r) → (p ∧ q) ∨ (p ∧ r) := by
             intro h
             apply Or.elim h.right            step 2 of 8, just run
             · intro hq
             ...

goals      ?left    p q r : Prop    h : p ∧ (q ∨ r)    ⊢ q → p ∧ q ∨ p ∧ r
           ?right   p q r : Prop    h : p ∧ (q ∨ r)    ⊢ r → p ∧ q ∨ p ∧ r
the term   fun h => [Or.elim h.right ?left ?right]      in brackets: the piece step 2 put into the hole ?m.2

step  what ran                the term after it                                        holes
0     by                      ?m.1                                                         1
1     intro h                 fun h => ?m.2                                                1
2     apply Or.elim h.right   fun h => Or.elim h.right ?left ?right                        2
...
8     exact ⟨h.left, hr⟩      fun h => Or.elim h.right (fun hq => Or.inl ⟨h.left, hq⟩)
                                fun hr => Or.inr ⟨h.left, hr⟩                              0

by hand    fun h => h.right.elim (fun hq => Or.inl ⟨h.left, hq⟩) (fun hr => Or.inr ⟨h.left, hr⟩)
kernel     119 nodes built by tactics, 119 written by hand: Lean elaborates both to the same term
(the live figure needs JavaScript and loads about 0.08 MB: three proofs as Lean 4.35.0 recorded them)
A proof by tactics, stepped as Lean 4.35.0 recorded it. Green: the piece of term the last step put into a hole. Framed: a hole, and over each goal the hole whose type it is. Underlined: the step just run. Below, the same theorem written by hand, and the term Lean elaborates that to. Lean prints the goals; the term with holes was read out of the assignments Lean stores (the tactic show_term prints one only for what it wraps, and a single ?_ for a body under fun). Step, change the proof, or point at a hole. Sizes are of the finished terms; the time is a median of seven kernel checks.

After apply Or.elim h.right the proof is the term fun h => Or.elim h.right ?left ?right: the tactic has filled one hole and opened two, and what Lean shows as two goals are the types of those two holes. When the last hole is filled the term is complete. For this first proof it is, node for node, the term that Lean elaborates from the same proof written by hand as one expression, 119 nodes either way, and the kernel is handed nothing else. It never sees a tactic.

This is Section 4 put to work. A proof of a proposition is a term of that type, so a proof in progress is a term in progress: one in which some subterms are still missing. Lean calls a missing subterm a metavariable (the holes that the elaborator of Section 9 solves for) and prints it with a question mark. A hole has a type, the proposition that whatever fills it must prove, and it stands at a place in the term where certain variables are in scope. Seen from the other side, that is the display a user of Lean watches all day: the hypotheses above the turnstile are the variables in scope at a hole, and the goal after it is the hole's type.

Every tactic, from a one-line rule to an external SAT bridge, obeys one structural constraint: a goal disappears only when a term is assigned to its metavariable.

Definition 10.1.1 (goal, proof state, tactic). A goal is a metavariable \(?m\) together with its local context \(\Gamma = x_1 : A_1, \dots, x_n : A_n\), the hypotheses, and its type \(A\), the target; Lean displays it as \(\Gamma \vdash A\). A proof state is a finite list of goals, the first of which is the main goal. A tactic is a program that is given a proof state and either fails or returns a new one. It can dispose of a goal \(?m\) in one way only: by assigning to it a term \(e\), meant to satisfy \(\Gamma \vdash e : A\), in which further metavariables may occur; those still unassigned are the new goals. A tactic proof of a proposition \(P\) starts from the single goal \(\vdash P\) (the variables of a theorem's header are its first hypotheses) and is complete when no goal is left. The proof is then the term assigned to the first metavariable, with all later assignments substituted into it.

"Meant to" is exact: no rule of the tactic language makes \(e\) have the type \(A\), and Section 10.7 has a tactic that assigns a term of another type. The definition is the reference manual's, which also says why there is a language of tactics at all, when terms would do.

The tactic language is a special-purpose programming language for constructing proofs. In Lean, propositions are represented by types, and proofs are terms that inhabit these types. While terms are designed to make it convenient to indicate a specific inhabitant of a type, tactics are designed to make it convenient to demonstrate that a type is inhabited. This distinction exists because it's important that definitions pick out the precise objects of interest and that programs return the intended results, but proof irrelevance means that there's no technical reason to prefer one proof term over another. For example, given two assumptions of a given type, a program must be carefully written to use the correct one, while a proof may use either without consequence.

—The Lean Language Reference, edition for Lean 4.35.0. The Lean Language Reference, Section 14, "Tactic Proofs", opening paragraph. Its second paragraph is the definition: a proof state "consists of an ordered sequence of goals, which are contexts of local assumptions together with types to be inhabited". That a goal is a metavariable, and that closing a goal is assigning one, is the account of "Metaprogramming in Lean 4", chapter "MetaM".

Proof irrelevance is the rule of Section 6 by which any two proofs of one proposition are equal by definition. It decides the character of everything that follows: a tactic does not have to find a good proof, or the proof a person would write, or the same proof twice. It has to find some term of the right type. What that term is made of is still open; the smallest tactics show it piece by piece.

The small tactics are the rules of natural deduction

Read the eight steps of that tactic script as rules of natural deduction. intro h is implication introduction from Section 3: to prove \(A \to B\), assume \(A\) and prove \(B\), which builds a lambda abstraction fun h => ... in the proof term. apply Or.elim h.right is disjunction elimination applied backward, leaving its two case obligations open as the subgoals ?left and ?right. exact ⟨h.left, hq⟩ is conjunction introduction with both components supplied. Stepping through tactics grows a natural-deduction tree backward from the desired conclusion at the root up toward the hypotheses at the leaves, matching the order in which a person searches for a proof; the finished lambda term records the exact same derivation from the leaves back down to the root, matching the order in which the kernel checks types. Each basic tactic corresponds to a single inference rule.

tactic the rule of Section 3 a statement, and the proof Lean stored for it
intro h introduction of → (and of ∀) p → p: fun h => h
apply f elimination of →, read upward q from f : p → q and hp : p: f hp
constructor introduction of ∧ p ∧ q from hp and hq: ⟨hp, hq⟩
left introduction of ∨ p ∨ q from hp: Or.inl hp
cases h elimination of ∨ q ∨ p from h : p ∨ q: Or.casesOn (motive := fun t => h = t → q ∨ p) h (fun hp h => Or.inr hp) (fun hq h => Or.inl hq) (Eq.refl h)
refine ⟨3, ?_⟩ introduction of ∃ ∃ n, n + 2 = 5: Exists.intro 3 (Eq.refl (3 + 2))
obtain ⟨n, hn⟩ := h elimination of ∃ ∃ m, m + 1 = 5 from h : ∃ n, n + 2 = 5: Exists.casesOn h fun n hn => Exists.intro (n + 1) hn
contradiction elimination of ⊥ q from hp : p and hnp : ¬p: False.elim (hnp hp)
have hq : q := f hp a cut: a lemma proved, then used r from f : p → q, g : q → r and hp : p: have hq := f hp; g hq
induction n induction: the recursor of Section 5 0 + n = n: Nat.recAux (Eq.refl (0 + 0)) (fun k ih => …) n
rw [h] substitution of equals a + 1 = b + 1 from h : a = b: Eq.mpr (id (congrArg (fun _a => _a + 1 = b + 1) h)) (Eq.refl (b + 1))
rfl reflexivity of equality 2 + 2 = 4: Eq.refl (2 + 2)
The basic tactics as rules of natural deduction. Each line was run on Lean 4.35.0 as a theorem proved in one to three lines; the last column is the stored proof as #print shows it, without the binders of the theorem's own variables. The step case of the induction, left out here, is the one in the stepped proof by induction.

Three terms in the rightmost column contain machinery that nobody wrote by hand. First, cases h constructs an explicit motive fun t => h = t → q ∨ p (every recursor from Section 5 requires a motive) and threads an extra equality hypothesis h = t, discharged immediately at the outer call by Eq.refl h, so that each branch retains an equation recording which constructor h matched in case other types depend on h. Second, induction n invokes the natural-number recursor via Nat.recAux, a thin wrapper that writes n + 1 in place of Nat.succ n. Third, rw [h] abstracts the target position into the context function fun _a => _a + 1 = b + 1, applies congrArg to h : a = b to obtain the propositional equality (a + 1 = b + 1) = (b + 1 = b + 1), and uses Eq.mpr to transport the trivial proof Eq.refl (b + 1) backward across that equation to prove a + 1 = b + 1. Locating where a sits inside the goal is the elaborator's job (Section 9); the kernel merely checks the resulting application of congrArg and Eq.mpr. Finally, have corresponds to the cut rule of Section 3, and it remains in the stored proof as an unreduced let/beta redex: because proof terms in Prop are only type-checked, never executed, nothing bothers to normalize cuts away.

Consequently, a tactic-generated proof term is rarely as compact as one crafted by hand. Proving 0 + n = n via the induction tactic stores 777 nodes, whereas writing the equivalent two-clause recursive function by hand takes 360 nodes across three declarations; for transitivity of divisibility, the counts are 1,307 nodes versus 732. Under proof irrelevance, that bloat has zero effect on theorems downstream. Even here, however, a recurring trade-off appears: whatever effort tactics save the human author, they pass along to the kernel, here in the form of larger terms. In these elementary scripts the user still picks every inference rule one by one; real automation begins when a tactic chooses the chain of steps itself.

Rewriting to a normal form

The first tactic that is more than a rule is the simplifier. simp holds a database of equations of the library, each read as an order to replace its left side by its right, and applies them to the goal, innermost subterms first, until none applies. In Lean 4.35.0 with the whole core library loaded the database holds 20,785 lemmas, 10,301 of them in the part every file starts from, and 341 small programs that rewrite by computing.Counted for this part on Lean 4.35.0 by asking the simplifier for its default set after import Lean: 20,785 lemmas by name, of which 10,301 are declared in Init, 5,232 in Std and 5,252 in Lean, and 341 simplification procedures.

call       theorem lists (xs ys : List Nat) :
               ((xs ++ []).reverse ++ ys).length + 0 = xs.length + ys.length := by
             simp

the goal                     ((xs ++ []).reverse ++ ys).length + 0 = xs.length + ys.length
1  List.append_nil           (xs.reverse ++ ys).length + 0 = xs.length + ys.length        xs ++ [] became xs
2  List.length_append        xs.reverse.length + ys.length + 0 = xs.length + ys.length
3  List.length_reverse       xs.length + ys.length + 0 = xs.length + ys.length
4  Nat.add_zero              xs.length + ys.length = xs.length + ys.length
5  Nat.add_left_cancel_iff   ys.length = ys.length
6  eq_self                   True
           (the whole goals come from an instrumented run of the same simplifier, which built the same term)

Lean's trace   [Meta.Tactic.simp.rewrite] List.append_nil:1000:   xs ++ []   ==>   xs
Lean's term    fun xs ys => of_eq_true (Eq.trans (Eq.trans (congrFun' (congrArg Eq ...
                 (congrArg List.reverse (List.append_nil xs)) ... List.length_append ...
                 List.length_reverse ... Nat.add_left_cancel_iff._simp_1) (eq_self ys.length))
               1,721 nodes as a tree, 167 with equal subterms shared; the kernel checks it in 0.31 ms
               Nat.add_zero left nothing in it: its two sides are equal by computation

all three      lists 6 rewrites, 1,721 nodes; logic 5, 249; arithmetic 4, 895
(the live figure needs JavaScript and loads about 0.02 MB: three calls of simp as Lean 4.35.0 recorded them)
A call of simp, as Lean 4.35.0 recorded it. A row to a goal, with the lemma or procedure that made it. Green: the subterm being rewritten; a funnel leads to what replaced it, underlined. Hatched: where simp tried a lemma and refused. The proof term is what simp handed the kernel, which checks it and never runs simp; underlined in it, each rewrite's lemma. Step, or click a row. Trace and term are Lean's own; the whole goals come from an instrumented run of the simplifier, checked to build the same term; a procedure's rewrite is named by simp?.

simp turned the goal into True in six rewrites and then handed the kernel one term for all six: 1,721 nodes written out as a tree, made of the lemmas' instances, of steps that lift an equation from a subterm to the whole, and of Eq.trans. The kernel checked it in 0.31 ms (a median of seven checks) and never ran simp.

A rewrite replaces a subterm, but what has to be proved is an equation between whole goals. The bridge is congruence: from \(a = b\) follows \(f\,a = f\,b\) (the lemma congrArg), and from \(f = g\) follows \(f\,a = g\,a\) (congrFun'), so an equation deep inside a term is lifted to the top one layer at a time. The lifted equations are chained by transitivity, and when the chain ends in True, the lemma of_eq_true : p = True → p turns it into a proof of the goal. The reference manual describes the whole in one sentence: "It performs inside-out rewriting of terms based on a database of simplification rules."The Lean Language Reference, edition for Lean 4.35.0, Section 15, "The Simplifier", opening.

Stating precisely what simp promises (and what it does not) requires distinguishing an individual rewrite rule, the active rule set, and the simplified target expression.

Definition 10.3.1 (simp lemma, simp set, normal form). A simp lemma is a theorem \(\forall \bar x,\; l = r\) or \(\forall \bar x,\; (p \leftrightarrow q)\), read as the rule that replaces an instance of \(l\) by the same instance of \(r\) (of \(p\) by \(q\)); a proposition \(p\) of another shape, such as a hypothesis passed to the call, is read as \(p = \mathrm{True}\). The simp set of a call is the collection of rules in force: the lemmas the library marks @[simp], those named in the call, the definitions marked to be unfolded, and the simplification procedures, which are programs that rewrite a term by computing. A term is in simp normal form if no rule of the set applies to any of its subterms. Given a goal \(p\), simp computes a term \(p^{\prime}\) and a proof of \(p = p^{\prime}\); if \(p^{\prime}\) is True the goal is closed, and otherwise \(p^{\prime}\) becomes the goal.

The definition names a normal form. It does not say that a goal reaches one, or only one.

Remark 10.3.2 (a normal form without a theorem). Section 1 had one rewrite rule and a theorem, confluence, which made normal forms unique. Here there are thousands of rules and no theorem. Whether rewriting stops, and whether its result depends on the order in which rules are tried, are properties of the simp set that Lean does not check: given two hypotheses that undo each other, f x = g x and g x = f x for every x, simp rewrites until a limit stops it and reports maximum recursion depth has been reached. Only the plainest case is handled by the simplifier itself: a rule like commutativity, whose two sides differ by a permutation of its variables, is applied only where the result is smaller in a fixed order on terms, and where it is not, Lean's trace says perm rejected. That the library's own rules lead somewhere, so that "simp normal form" names a thing, is a convention its authors keep by hand (Section 11).

None of that heuristic fragility threatens soundness, because the kernel still checks the finished congruence-and-transitivity term produced by each call. Two details from the recorded traces reveal how simp and the kernel divide the labor. First, not every rewrite leaves a lemma in the proof term: step 4 (Nat.add_zero, rewriting n + 0 to n) vanishes from the term completely, as does a step in another trace that simplified 2 + 3 to 5 via a built-in simplification procedure (Nat.reduceAdd, omitted from the default trace). In both cases the two sides are already definitionally equal (Section 6), so the kernel verifies their equality by reduction without needing an explicit proof step. Second, almost every simp proof depends on the axiom propext (Section 7): lifting rewrites through logical connectives via congrArg requires genuine equality = rather than logical equivalence ↔, and turning equivalences or tautologies such as eq_self : (a = a) = True into equalities between propositions invokes propositional extensionality. That first observation, letting kernel reduction verify a calculation with zero deductive steps written in the proof term, becomes a standalone proof method when applied to an entire goal.

Deciding by computing

Some statements are true because a calculation comes out right: 7 divides 91, 97 is prime. For these there is a way of proving that involves no search. The proof term says, in effect, "run the test", and the kernel runs it.

chart    seconds against n, both logarithmic: a proof that n is prime (Euclid.Prime n, decided by
         trial division), four ways, for growing primes n. Recorded from Lean 4.35.0 under load;
         every time is the median of 3 runs

         way                       proves up to   then stopped by a limit of the elaborator    at its largest n: command, kernel
         decide                    157            from 163: maximum recursion depth            99.1 ms, 33.7 ms
         decide, maxRecDepth 10⁶   12,281         from 16,381: maximum number of heartbeats    20.1 s, 9.00 s
         decide +kernel            32,749         (not run further)                            46.4 s, 44.9 s
         native_decide             1,048,573      (not run further)                            4.86 s, 60 µs

rows     at n = 191
         decide                    refused after 64.4 ms: maximum recursion depth has been reached
         decide, maxRecDepth 10⁶   proved: command 119 ms, kernel 42.2 ms, term 65 nodes
         decide +kernel            proved: command 66.9 ms, kernel 42.3 ms, term 66 nodes
         native_decide             proved: command 19.8 ms, kernel 19 µs, term 27 nodes;
                                   'prime_191' depends on axioms: [prime_191._native.native_decide.ax_1]

         By decide the kernel is handed of_decide_eq_true (id (Eq.refl true)) and evaluates the test
         itself: its time grows about as n^1.3 between n = 127 and 32,749. After native_decide it is
         handed an axiom and takes 18 to 66 µs whatever n is, about 2,300 times less at n = 191; the
         command still grows with n.
(the live figure needs JavaScript and loads about 0.2 MB of data)
Four ways to prove that n is prime by computing, for growing primes n. Green: the kernel's time to check a proof by decide, where the kernel evaluates the test itself. Ink: the kernel's time after native_decide, which has the test evaluated outside the kernel and records the answer as an axiom named after the theorem. The wash around each runs from its least check to its greatest. Dashed: the whole command. A lane shows the n a way proved; hatched: where a limit of the elaborator, not the kernel's cost, stopped the proof. Every time is the median of three runs, recorded under load.

The proof that decide hands over is the same small term whatever \(n\) is, 65 nodes. What grows is the kernel's own evaluation of the test, from 42.3 ms at \(n = 191\) to 44.9 s at \(n = 32{,}749\) (medians of three runs with decide +kernel, the form of Remark 10.4.3). And where a way of proving stops, what stops it is a limit of the elaborator, not the kernel's cost (Remark 10.4.3).

The principle is called reflection. Suppose a proposition \(p\) comes with a program that computes a Boolean and with a proof, given once, that the Boolean is true exactly when \(p\) holds. Then a proof of \(p\) need not argue anything. It can point at the program and claim that its value is true; checking the claim means evaluating the program, and evaluating is what the kernel does whenever it compares two terms up to definitional equality (Section 6). In Lean the program and its proof travel together, as an instance of a type class.

abbrev Bool.Reflects : Bool → Prop → Prop
  | false, p => Not p
  | true, p => p
-- ...
class Decidable (p : Prop) where
  -- ...
  intro ::
  -- ...
  decide : Bool
  -- ...
  reflects_decide (p) : decide.Reflects p
-- ...
theorem of_decide_eq_true [inst : Decidable p] : Eq (decide p) true → p := fun h =>
  match (generalizing := false) inst with
  | isTrue  h₁ => h₁
  | isFalse h₁ => absurd h (Bool.ne_true_of_eq_false (decide_eq_false h₁))

Definition 10.4.1 (decidable proposition). In Lean 4.35.0 an instance of Decidable p is a pair of a Boolean, decide p, and a proof of (decide p).Reflects p: a proof of \(p\) if the Boolean is true, and of \(\lnot p\) if it is false.Earlier versions of Lean, and most tutorials, define Decidable as an inductive type with two constructors, isTrue and isFalse. In 4.35.0 the two names survive as patterns, as in the last lines of the listing.

Evaluating decide p to true yields an equality between Booleans, not yet a proof of the proposition \(p\); the bridge lemma of_decide_eq_true converts one into the other without introducing any axiom.

Proposition 10.4.2 (proof by reflection). Let \(p\) be a proposition with an instance of Decidable p. Then of_decide_eq_true is a proof of decide p = true → p, and it uses no axiom. Hence, if the kernel's rules of computation reduce the term decide p to true, the term of_decide_eq_true (Eq.refl true) is a proof of \(p\).

Proof. By cases on the instance. If its Boolean is true, its second component is a proof of \(p\). If it is false, the hypothesis reads false = true, which is absurd. For the second statement, Eq.refl true has the type true = true, and the kernel accepts it at the type decide p = true when it finds the two types definitionally equal, which it does by reducing decide p. ∎

That term is all decide builds, once the search of Section 9 has found an instance: of_decide_eq_true (id (Eq.refl true)), where the id only records the type at which Eq.refl true is to be checked. The mathematics is in the instance. For the primes of this series it is the last two of these lines.

def minFac (n : Nat) : Nat :=
  search (· ∣ n) (n - 2) 2
-- ...
theorem prime_iff (n : Nat) : Prime n ↔ 2 ≤ n ∧ minFac n = n :=
-- ...
instance decPrime (n : Nat) : Decidable (Prime n) :=
  decidable_of_iff (2 ≤ n ∧ minFac n = n) (prime_iff n).symm

The Boolean is the outcome of a search for the least divisor from 2 on, and prime_iff is the proof that the outcome decides primality. Each candidate \(d\) is tried by walking up its multiples, about \(n/d\) steps, so that a prime \(n\) costs about \(n \ln n\) steps in all. That is a count of the algorithm's steps; the kernel's measured time grows faster, about as \(n^{1.3}\) between \(n = 127\) and \(n = 32{,}749\), and more steeply toward the top.

John Harrison, surveying the technique in 1995, gave its aim in one sentence: "The idea of computational reflection is not to make a formal system stronger, but rather to make its deductive process more efficient by utilizing information which avoids having to construct formal proofs in full detail." His survey sets it against the older discipline, in which every proof is expanded into the primitive inferences of the logic, and finds neither the inadequacy of that discipline nor the practical utility of reflection demonstrated.

One way to ensure correctness of the inference performed by computer theorem provers is to force all proofs to be done step by step in a simple, more or less traditional, deductive system. Using techniques pioneered in Edinburgh LCF, this can be made palatable. However, some believe such an approach will never be efficient enough for large, complex proofs. One alternative, commonly called reflection, is to analyze proofs using a second layer of logic, a metalogic, and so justify abbreviating or simplifying proofs, making the kinds of shortcuts humans often do or appealing to specialized decision algorithms. In this paper we contrast the fully-expansive LCF approach with the use of reflection. We put forward arguments to suggest that the inadequacy of the LCF approach has not been adequately demonstrated, and neither has the practical utility of reflection (notwithstanding its undoubted intellectual interest).

—John Harrison, "Metatheory and Reflection in Theorem Proving: A Survey and Critique" (1995). Report dated 15 February 1995 (the author's copy), abstract. The sentence on computational reflection stands in the report's section on that subject, under "Generalities". Edinburgh LCF, the prover from which the discipline takes its name, was developed by Robin Milner and his assistants in the mid 1970s; LCF stands for Scott's Logic of Computable Functions, a version of which the original system implemented (the report's Section 2).

Three decades on, Lean does both and adds a third. Most tactics of this part are fully expansive in Harrison's sense: they produce the derivation and the kernel replays it. decide is reflection inside the logic: nothing new is trusted, since the evaluator is the kernel's own, and the price is the kernel's time. Whether that is still a proof is a fair question, for the 65 nodes point to a computation that the kernel performs and discards and nobody reads: the old complaint against the four-color theorem in miniature, which The painted rock follows back to Wittgenstein's demand that a proof be surveyable. The formal answer is that nothing was added to the logic. Every step of the evaluation is a step of definitional equality, and another kernel can take the same steps (Section 13).

The third way moves the evaluation out of the kernel. native_decide builds the same term with one change: the equation decide p = true is not checked by reduction but asserted. Lean has the test run by the evaluator behind #eval, the second of the two evaluators of Section 8.2, and when the answer is true it adds an axiom that says so and cites it: axiom prime_89._native.native_decide.ax_1 : decide (Euclid.Prime 89) = true.The end of the name depends on how the file is processed. The recording behind the figure elaborates in one thread and shows ax_1; lean run on a file with its default settings shows ax_1_1, and ax_1 again with the option Elab.async off. The kernel is left with a term of 27 nodes, which costs it between 18 and 66 µs at every prime tried. The evaluation still has to happen, and the whole command grows with \(n\), to 4.86 s at the largest prime tried, 1,048,573.

native_decide is a synonym for decide +native. It will attempt to prove a goal of type p by synthesizing an instance of Decidable p and then evaluating it to isTrue ... Unlike decide, this uses #eval to evaluate the decidability instance.

This should be used with care because it adds the entire lean compiler to the trusted part, and a new axiom will show up in #print axioms for theorems using this method or anything that transitively depends on them. Nevertheless, because it is compiled, this can be significantly more efficient than using decide, and for very large computations this is one way to run external programs and trust the result.

—Lean 4.35.0, documentation of the tactic native_decide. Init/Tactics.lean, lines 1517 to 1532, in the sources of the release: the docstring without its one-line example. The option decide +native is documented beside it as evaluating the instance and "admitting the result via an axiom".

The trade is stated in the open. decide trusts nothing new and pays in the kernel. native_decide pays almost nothing there and adds to what must be believed the compiler, its run-time system and every definition whose compiled code is allowed to differ from what the kernel sees. The addition is visible: #print axioms lists the new axiom (within the limits of that listing that Section 7.5 measures), and a checker that holds a proof to a list of permitted axioms refuses it (Section 13). The readable edition of the Lean library released in November 2026 as a proof of the Riemann hypothesis does not make this trade, as far as its text shows: native_decide does not occur in its 803 source files, and the configuration it gives the comparator, the tool that holds a proof to its statement and to a list of permitted axioms (Section 13), permits three, propext, Quot.sound and Classical.choice (Section 12).

One practical detail in the benchmark figure explains why plain decide stopped at small primes long before the kernel itself bogged down: resource guardrails inside the elaborator trip first.

Remark 10.4.3 (which limit stops which way). None of the limits met in the recording is the kernel's cost. Plain decide evaluates the test twice, in the elaborator to learn the answer and in the kernel to check the proof: the default mode "reduces twice (once in the elaborator and again in the kernel)", as its documentation says. The elaborator's evaluation meets its limit on nested calls (maxRecDepth, 512 by default) between 157 and 163 (at 157 the kernel's part was 33.7 ms), with the message maximum recursion depth has been reached, and with that limit raised to 1,000,000 it meets its budget of work (maxHeartbeats, 200,000 by default) between 12,281 and 16,381. decide +kernel leaves the elaborator's evaluation out; it proved every prime it was given, the largest 32,749, and was not run to its end. When a declaration is added in the ordinary way the kernel has a budget too, the same option maxHeartbeats, past which Lean reports (kernel) deterministic timeout; an extrapolation from three counted points puts it near \(n = 1.4 \cdot 10^5\) for this test.

A list of axioms shows the trade of native_decide by the axiom's name, so the name matters.

Remark 10.4.4 (an axiom that no longer exists). Older accounts of native_decide name one axiom behind every use, Lean.ofReduceBool. The sources of Lean 4.33.1 still hold it, marked deprecated since February 2026 with the note "in-kernel native reduction is deprecated; assert native evaluations with axioms instead". In Lean 4.35.0 it is gone, and each use has its own axiom, stating the very equation that was evaluated.

Both decide and native_decide execute the entire decision algorithm, paying for every step of the search inside the evaluator. When an answer is expensive to discover yet cheap to verify once found, running only the verification step inside Lean avoids that cost.

Search with a certificate

Between writing a derivation out and making the kernel compute lies the most common design in automation. A program searches, by any means it likes, for a small piece of data that makes the statement easy to check, and only the check becomes a proof. The data is called a certificate, and the program that finds it an oracle.

tree     omega's certificate for  theorem three_bounds (x y : Nat) (h₁ : 2 * x + y ≤ 10) (h₂ : 3 ≤ x)
         (h₃ : 5 ≤ y) : False,  recomputed with integer arithmetic (6 facts collected, 3 used)

                        −2x − y ≥ −10  h₁
                        ───────────── tidy
            x ≥ 3  h₂    2x + y ≤ 10
            ───────────────────────── combo 2, −1
                     −y ≥ −4
                     ─────── tidy
                      y ≤ 4                y ≥ 5  h₃
                     ─────────────────────────────── combine
                              5 ≤ y ≤ 4: ∅

         7 steps, each as Lean's trace prints it; Lean's term for them has 7,098 nodes, and the kernel
         checks it in 4.95 ms. All 41 recorded steps (6 problems, 4 goals) recompute alike

chart    bv_decide: the SAT solver's certificate at the largest width proved in its default 10 s, one run each
         identity                            width   certificate   search    check     kernel
         x * y = y * x                       9       46.9 MB       3.09 s    1.69 s    1.37 ms
         x * (y + z) = x * y + x * z         7       91.6 MB       9.89 s    3.40 s    2.07 ms
         x - y = x + ~~~y + 1                64      440 kB        149 ms    12.9 ms   1.81 ms
         (x ^^^ y) + 2 * (x &&& y) = x + y   64      118 kB        53.4 ms   4.6 ms    2.67 ms
         x * y = y * x at width 10: the solver is stopped after 10.1 s; the kernel never reads a certificate
(the live figure needs JavaScript and loads about 0.1 MB of data)
Two searches and what they hand back. Left: the facts omega collected and the combination that refutes them, from Lean's trace; green lines are the steps of this certificate as the page recomputes them with integer arithmetic. Move a bound, and the same combination may refute nothing. Right: bv_decide on four bit-vector identities by width, one run a point. Green: the bytes of the SAT solver's certificate. Dashed: the time to find it. Solid: the time a verified checker, compiled, takes to check it; its answer enters the proof as an axiom, so the kernel (hairlines) never reads the certificate. Hatched: past the solver's default 10 seconds.

The certificate omega found for the three bounds is seven lines of arithmetic that a reader can redo: multiply, add, divide by a common factor and round toward the integers. Two things decide what a certificate is worth: how easily it is checked, and whether one exists whenever the goal holds. For linear arithmetic a certificate is a combination of the hypotheses, and over an ordered field there is one whenever the hypotheses cannot all hold.

Proposition 10.5.1 (a combination that refutes). Let \(F\) be an ordered field and let \(t_i = c_i + \sum_j a_{ij} x_j\), for \(i = 1, \dots, m\), be linear forms in \(x_1, \dots, x_n\) with coefficients in \(F\). If there are \(k_1, \dots, k_m \ge 0\) in \(F\) such that \(\sum_i k_i t_i\) is a negative constant, then no \(x \in F^n\) satisfies \(t_i(x) \ge 0\) for all \(i\). Conversely, if no \(x \in F^n\) satisfies them all, such \(k_i\) exist.

Proof. The first half is one line: at a solution \(\sum_i k_i t_i(x) \ge 0\), yet the sum is a negative constant. The idea of the converse is to eliminate one variable at a time. Solve each hypothesis in which \(x_n\) occurs for \(x_n\); some become lower bounds \(l \le x_n\) and some upper bounds \(x_n \le u\), with \(l\) and \(u\) linear in the other variables. Given values of the others, a value for \(x_n\) exists exactly when every \(l\) is at most every \(u\), and each inequality \(l \le u\) is a sum of positive multiples of two hypotheses. Replace the hypotheses that mention \(x_n\) by these inequalities: the new system has one variable fewer, it is satisfiable exactly when the old one was, and all its members are nonnegative combinations of the original hypotheses. After \(n\) rounds only constants are left, and if the system was unsatisfiable, one of them reads \(c \ge 0\) with \(c < 0\). The record of how it was derived is the list of the \(k_i\). ∎In linear programming the statement, over the real numbers, is a form of Farkas' lemma, and the elimination is the one that the source of Mathlib's linarith names among its oracles, Fourier-Motzkin elimination.

Over the integers that converse breaks down at the step picking \(x_n\) between \(l\) and \(u\): a real interval \([l, u]\) can be nonempty without containing any integer. Because omega works over Nat and Int, its certificates add one extra rule to exploit integrality.

Example 10.5.2 (a certificate that is one rounding). Consider the integer equation 4 * x + 6 * y = 9, which admits rational solutions (such as x = 9/4, y = 0) yet no integer solutions because the left-hand side is always even. Since rational solutions exist, no nonnegative linear combination of the hypotheses as in Proposition 10.5.1 can refute it. Running omega in Lean 4.35.0 with tracing enabled produces a two-line refutation:

/-- True over the integers only: the left side is even. -/
theorem parity (x y : Int) (h : 4 * x + 6 * y = 9) : False := by
  omega
[2, 3] ∈ ∅: tidying up:
• [4, 6] ∈ {9}: assumption 0

In omega's trace notation, [a, b] ∈ S asserts that the linear form \(a x + b y\) lies in the integer interval \(S\). Three primitive rules appear across the certificates recorded for this part: combo forms a linear combination \(a \cdot s + b \cdot t\) of two constraints; combine intersects two interval bounds on the same linear form and derives a contradiction whenever the lower bound exceeds the upper bound; and tidy ("tidying up" in the trace) flips signs if the leading coefficient is negative, divides the coefficients by their greatest common divisor \(g\), and rounds the interval bounds inward, raising a lower bound \(c\) to \(\lceil c/g \rceil\) and lowering an upper bound \(c\) to \(\lfloor c/g \rfloor\). Because an integer linear form evaluated at integers must itself be an integer, inward rounding is sound, and it is the sole step that uses integrality. Here a single tidy step finishes the proof: dividing [4, 6] ∈ [9, 9] by \(\gcd(4, 6) = 2\) forces \(2x + 3y\) to lie between \(\lceil 9/2 \rceil = 5\) and \(\lfloor 9/2 \rfloor = 4\), which is the empty interval \(\emptyset\). ◁

omega is linear arithmetic and no more: equalities, inequalities and divisibility by a literal over Nat and Int. A product of two variables is only an atom to it: for a * b = b * a it reports a possible counterexample in which the two products differ. Within its scope its documentation is candid: it is "not yet a full decision procedure".Lean 4.35.0, documentation of the tactic omega, Init/Tactics.lean, lines 1541 to 1572. The three steps are read off Lean's trace and its sources, Init/Omega/Constraint.lean.

What the kernel receives is not the certificate but a term that makes it redo the certificate. For the three bounds it has 7,098 nodes, of which these are the first lines.

fun x y h₁ h₂ h₃ =>
  Lean.Omega.Constraint.not_sat'_of_isImpossible (of_decide_eq_true (id (Eq.refl true)))
    (Lean.Omega.Constraint.combine_sat'
      (Lean.Omega.tidy_sat
        (Lean.Omega.combo_sat' { lowerBound := some 3, upperBound := none }
          { lowerBound := none, upperBound := some 10 } 2 [1] (-1) [2, 1] (Lean.Omega.Coeffs.ofList [↑x, ↑y])

The numbers 2 [1] (-1) [2, 1] are the combination: twice the constraint with coefficients [1] over the atoms [x, y], minus the one with coefficients [2, 1]. The outermost step, that a constraint with lower bound 5 and upper bound 4 is impossible, is closed by of_decide_eq_true (id (Eq.refl true)): reflection, at the root of a certificate. The kernel checks the whole in 4.95 ms (a median of seven checks).

The design has its plainest statement in the source of Mathlib's tactic for linear arithmetic, linarith, read here as text and not run.

First, the inequalities in the set S are rearranged into the form tᵢ Rᵢ 0, where Rᵢ ∈ {<, ≤, =} and each tᵢ is of the form ∑ cⱼxⱼ.

linarith uses an untrusted oracle to search for a certificate of unsatisfiability. The oracle searches for a list of natural number coefficients kᵢ such that ∑ kᵢtᵢ = 0, where for at least one i, kᵢ > 0 and Rᵢ = <.

Given a list of such coefficients, linarith verifies that ∑ kᵢtᵢ = 0 using a normalization tactic such as ring. It proves that ∑ kᵢtᵢ < 0 by transitivity, since each component of the sum is either equal to, less than or equal to, or less than zero by hypothesis. This produces a contradiction.

—Mathlib, module documentation of Mathlib/Tactic/Linarith/Frontend.lean. Lines 37 to 49 of the file at the commit of Mathlib that this series reads, 56a0058 of 13 October 2026: the section "Algorithm sketch", whole. The same documentation says when the search is complete, "When the inequalities are over a dense linear order, linarith is a decision procedure: it will prove False if and only if the inequalities are unsatisfiable", and names two oracles, Fourier-Motzkin elimination and a simplex algorithm.

For arithmetic on machine words the same design is taken further. bv_decide turns a goal about bit-vectors of fixed width into a circuit and the circuit into clauses, and gives the clauses to a solver for Boolean satisfiability (a SAT solver; here CaDiCaL, which ships with Lean). The solver returns either an assignment, which Lean prints as a counterexample, or a certificate that there is none, in a format that Lean's trace calls LRAT. For x * y = y * x at width 9 the certificate has 232,854 steps and occupies 46.9 MB of the proof term (one run).

Unlike omega, which translates its short arithmetic certificate into an explicit kernel proof term with no added axioms, bv_decide cannot ask the kernel's interpreter to step through 46.9 MB of proof clauses. Instead, Lean's library contains an LRAT certificate checker written in Lean and formally proved sound in Lean; bv_decide compiles that verified checker to native machine code, runs it on the certificate, and records a true outcome as a generated axiom such as mul_comm_9._native.bv_decide.ax_1, asserting that the checker returned true on this formula and certificate. The kernel then checks a tiny proof term combining that axiom with the checker's soundness theorem, taking between one and three milliseconds at every bit-width without ever reading the multi-megabyte certificate itself. Lean's documentation states both halves of that bargain. The reference manual notes: "All heavy search happens outside Lean; the certificate is replayed and verified inside Lean, so trust is preserved (verification time scales with certificate size)." And the tactic's own docstring adds: "Note: bv_decide trusts the correctness of the code generator and adds a axioms asserting its result."The Lean Language Reference, edition for Lean 4.35.0, Section 16, "The grind tactic", on what grind is not for; Init/Tactics.lean, lines 1935 to 1965, whose wording is kept. The paper that introduced the tactic draws the same line, a bit-blaster (the translation of a statement about machine words into one about their bits) that "comes with a complete end-to-end proof (trusting only the Lean compiler and kernel)": H. Böving, S. Bhat, L. Cicolini, A. Keizer, L. Frenot, A. Mohamed, L. Stefanesco, H. Khan, J. Clune, C. Barrett and T. Grosser, "Interactive Bitvector Reasoning using Verified Bit-Blasting", Proceedings of the ACM on Programming Languages 9 (OOPSLA2), 2025, pp. 3259 to 3285, quoted from its abstract. Verification happens inside Lean, then, though not inside the kernel: the soundness of the checker algorithm is kernel-checked once and for all, while trusting that the compiled binary executed that exact algorithm on this certificate rests on the compiler, just as in native_decide.

How far the method reaches is set by the search. For multiplication the certificate grows from about a kilobyte at width 2 to the 46.9 MB of width 9, and at width 10 the solver was stopped by its default limit of 10 seconds (one run, on a machine doing other work); for addition and subtraction it stays under half a megabyte at width 64. And no oracle reaches a goal outside its one theory.

General automation

The tactics so far each know one thing. grind, which came to the core library in 2025, is built for goals that need several at once: some reasoning with equalities, a lemma or two from the library, a case split, a little arithmetic. It can be tried beside rfl, simp, decide and omega on one set of 19 goals.

chart    19 goals, each proved by a term written by hand and tried with five tactics, called bare
         (Lean 4.35.0, recorded under load). A dot a goal, at its multiple of the baseline for that goal

         way                proves, of 19   fewest nodes written out   axioms, on some goal
         the written term   19              (the baseline: in 11 goals one library lemma, applied)
         grind              19              on 9 goals                 Classical.choice, Quot.sound, propext
         simp               11              on 7                       Quot.sound, propext
         omega              11              on none                    Quot.sound, propext
         decide              6              on none                    propext
         rfl                 4              on 3                       none

goal 4   7 ∣ 91; the statement alone 1.10 ms; medians (least to greatest of 25 checks)
         written   69 nodes   kernel 70 µs (52 to 96)                command 1.38 ms   ⟨13, rfl⟩
         simp      65         60 µs (48 to 90), no difference        1.35 ms
         decide    113        66 µs (51 to 188), no difference       1.30 ms
         grind     186        119 µs (100 to 184)                    1.69 ms
         omega     1,916      1.63 ms (1.57 to 5.01)                 3.72 ms
         rfl       refused: The left-hand side 7 is not definitionally equal to the right-hand side 91

         A tactic's term has 0.94 to 9,252 times the nodes of the written term, the most against a lemma
         cited in 5 nodes. The statement alone takes 0.58 to 2.49 ms: a floor every command shares, not a
         bound (the written term's command is below it in 10 goals). The kernel's times overlap in
         34 of the 111 pairs of ways that prove one goal.
(the live figure needs JavaScript and loads about 0.1 MB of data)
The 19 goals, each proved by a term written by hand and tried with five tactics. A row to a way, a dot to a goal it proves, at its multiple of the baseline for that goal; the hairline is the baseline, the hatched side is more. For nodes and the kernel's time the baseline is the written term, in eleven goals a library lemma applied: a citation. For the command's time it is the statement alone, a floor every way shares, not a bound. Green: the tactic whose term has the fewest nodes written out, goal by goal. Times whose ranges overlap show no difference.

On 7 ∣ 91, the hand-written witness ⟨13, rfl⟩ elaborates to 69 tree nodes; simp produces a term of 65 nodes, decide 113, grind 186, and omega 1,916, while rfl is rejected: one elementary proposition, five distinct proof terms handed to the kernel. Measured by unfolded tree size, no single tactic wins everywhere: rfl produces the smallest automated term on three of the 19 goals, simp on seven, and grind on nine, while omega and decide never finish smallest. On 11 of the 19 goals, however, the hand-written baseline simply applies an existing library theorem, so its tiny node count reflects citing a pre-proved lemma rather than proving from scratch: omega's 46,258-node proof of n % 2 = 0 ∨ n % 2 = 1 competes against a 5-node lemma citation, and its 100,710-node proof of ∀ x : Fin 8, x + 0 = x (the largest term in the run) competes against a 37-node citation. All 19 benchmark goals were selected without induction, so grind solving all 19 implies nothing about inductive theorems. Wall-clock checking times separate the tactics far less sharply than node counts: every command pays a shared baseline cost just to elaborate the theorem statement, and across 34 of the 111 pairs of tactics solving the same goal, the kernel's timing ranges overlap.

grind works, in the reference manual's image, on a whiteboard.

The grind tactic uses techniques inspired by modern SMT solvers to automatically construct proofs. It produces proofs by incrementally collecting sets of facts, deriving new facts from the existing ones using a set of cooperating techniques. Behind the scenes, all proofs are by contradiction, so there is no operational distinction between the expected conclusion and the premises; grind always attempts to derive a contradiction. Picture a virtual whiteboard. Every time grind discovers a new equality, inequality, or Boolean literal it writes that fact on the board, merges equivalent terms into buckets, and invites each engine to read from—and add back to—the shared whiteboard. In particular, because all true propositions are equal to True and all false propositions are equal to False, grind tracks a set of known facts as part of tracking equivalence classes. The cooperating engines are: congruence closure, constraint propagation, E‑matching, guided case analysis, and a suite of satellite theory solvers, including both linear integer arithmetic and commutative rings. Like other tactics, grind produces ordinary Lean proof terms for every fact it adds.

—The Lean Language Reference, edition for Lean 4.35.0. Section 16, "The grind tactic", opening paragraph. SMT stands for satisfiability modulo theories: the question whether a formula can be satisfied when its symbols are read in a background theory, such as linear arithmetic. grind came with Lean 4.22 in August 2025, developed by Leonardo de Moura and Kim Morrison (L. de Moura, "The grind Tactic: proof automation in Lean", slides of 18 September 2025); no paper by its authors was found on arXiv on 1 December 2026, and the manual's chapter and the tactic's docstring are its primary descriptions.

The whiteboard can be seen when grind fails. Asked to conclude a = b from f a = f b for an arbitrary function f, it prints what it had.

theorem wrong (f : Nat → Nat) (a b : Nat) (h : f a = f b) : a = b := by
  grind
error: `grind` failed
case grind
f : Nat → Nat
a b : Nat
h : f a = f b
h_1 : ¬a = b
⊢ False
[grind] Goal diagnostics
  [facts] Asserted facts
    [prop] f a = f b
    [prop] ¬a = b
  [eqc] False propositions
    [prop] a = b
  [eqc] Equivalence classes
    [eqc] {f a, f b}

As the manual describes, grind has negated the target a = b into the hypothesis h_1 : ¬a = b and set out to prove False; the whiteboard holds a single nontrivial equivalence class {f a, f b}, and no engine can derive a contradiction because an arbitrary function f need not be injective. Change the hypotheses to a = b and f b = c with target f a = c, and the same whiteboard closes immediately once congruence closure merges f a with f b. Because grind always works by classical refutation, its proof terms carry a characteristic axiom footprint: every single grind proof in the 19-goal benchmark depends on all three axioms of Section 7 (Classical.choice, Quot.sound, and propext), even for swapping a conjunction (p ∧ q → q ∧ p), which the two-projection term fun h => ⟨h.right, h.left⟩ proves constructively with zero axioms.

Mathlib provides domain-specific tactics built on the same patterns for the algebra and analysis of Section 11 (described here from Mathlib's source text at the series' commit rather than executed). Where simp applies an open-ended rule set with no confluence guarantee, ring proves polynomial identities in commutative rings and semirings by reducing expressions to a genuine canonical polynomial form (Section 10.3): "The basic approach to prove equalities is to normalise both sides and check for equality."

example (n : ℕ) (m : ℤ) : 2^(n+1) * m = 2 * 2^n * m := by ring
example (a b : ℤ) (n : ℕ) : (a + b)^(n + 2) = (a^2 + b^2 + a * b + b * a) * (a + b)^n := by ring

linarith is the oracle and the certificate of Section 10.5. norm_num "normalizes numerical expressions in the goal", uses simp on the goal as well, and is open to extension; among the extensions its documentation names is "a relatively simple primality prover".Mathlib at commit 56a0058: Mathlib/Tactic/Ring/Basic.lean, lines 12 to 61 (the module documentation of ring); Mathlib/Tactic/Ring/RingNF.lean, lines 193 to 208 (its docstring, with the two examples); Mathlib/Tactic/NormNum/Core.lean, lines 276 to 304.

The 19 goals have one count left, the axioms under each term, and Section 13 checks proofs against lists of them.

Remark 10.6.1 (automation and the axiom list). A term written by hand rests on the axioms of the lemmas it cites: of the 19 written terms, five rest on propext and the others on nothing. Automation is less sparing. Over the same goals rfl used no axiom; decide used propext on two of the six it proved; simp used propext on all 11 and Quot.sound on two of them; omega used both on all 11; grind used all three on all 19. For a classical mathematician this costs nothing (Section 7), but the axioms listed under a theorem proved by automation tell more about the tactic than about the theorem.

Whether any of these tactics is correct has not been asked, and the opening said it need not be.

Untrusted search, trusted check

A tactic is a program, and a program can be wrong. Here is one that is wrong on purpose: it fills whatever goal it is given with the proof of True, and reports that no goal is left.

import Lean
open Lean Elab Tactic

/-- Fills any goal with the proof of `True` and reports that no goal is left. -/
elab "trust_me" : tactic => do
  let goal ← getMainGoal
  goal.assign (mkConst ``True.intro)
  replaceMainGoal []

theorem two_eq_three : 2 = 3 := by trust_me
error: (kernel) declaration type mismatch, 'two_eq_three' has type
  True
but it is expected to have type
  2 = 3

The tactic ran without complaint, and as far as the tactic language is concerned the goal was closed. The complaint comes one stage later and from another program: the kernel was handed True.intro as a proof of 2 = 3, computed its type, and compared.Asked afterwards for the axioms of the refused theorem, Lean 4.35.0 answers 'two_eq_three' depends on axioms: [two_eq_three]: what the kernel refused is listed as its own assumption. Its sources show why (Lean/AddDecl.lean): a declaration that the kernel refuses is added as an axiom, to avoid errors further down the file, and the file as a whole still ends in an error.

One refusal is not a guarantee. The guarantee, with its conditions, is what Section 12.4 and Section 13.1 rest on.

Remark 10.7.1 (what an accepted theorem rests on). Whenever Lean accepts theorem T : P := by … in a session that neither disables kernel type-checking nor injects unchecked declarations into the environment (Section 13 catalogs those escape hatches and the fresh-kernel replay that catches them), the kernel has verified that the finished proof term \(e\) has type \(P\) in the current environment. Neither the tactics nor any external solvers or oracles they invoked need to be trusted. Soundness rests on three things alone: the correctness of the kernel, the soundness of the axioms referenced by \(e\) (which for native_decide and bv_decide include one generated axiom per call asserting the outcome of compiled code), and a human reading confirming that \(P\) states what was intended.

Lean's core type theory is expressive enough to capture very complicated mathematical objects, but simple enough to admit independent implementations, reducing the risk of bugs that affect soundness. The core type theory is implemented in a minimal kernel that does nothing other than check proof terms. This core theory and kernel are supported by advanced automation, realized in an expressive tactic language. Each tactic produces a term in the core type theory that is checked by the kernel, so bugs in tactics do not threaten the soundness of Lean as a whole. Along with many other parts of Lean, the tactic language is user-extensible, so it can be built up to meet the needs of a given formalization project. Tactics are written in Lean itself, and can be used immediately upon definition; rebuilding the prover or loading external modules is not required.

—The Lean Language Reference, edition for Lean 4.35.0. Opening page, third paragraph.

The design is older than Lean. Harrison's survey describes it for the provers descended from Edinburgh LCF, in which a theorem is a value of an abstract type that only the rules of inference can construct, and gives the consequence in terms that fit Lean once the kernel's check stands where the type discipline of the programming language ML stood: "The rules added by a user do not need to be verified; if there is an error, then the proof procedure may fail, but because of the ML type discipline, will never produce an invalid ‘theorem’." He quotes Slind's slogan for it, "The user controls the means of (theorem) production".Harrison (1995), Section 2, "The LCF approach to theorem proving", under "The advantages of LCF"; the slogan is credited there to Slind (1991). In Lean the guarantee has a further form, which Section 13 takes up as the de Bruijn criterion: the term a tactic leaves is a finite object that can be exported and checked again by another program.

What can a tactic do, then, short of proving something false? It can fail, at the cost of a message. It can be slow, or not stop, which is what the limits of Remark 10.4.3 are for. It can produce a term that the kernel refuses, as trust_me did. And it can add an axiom, because a tactic is a program with the environment in its hands (Section 8). native_decide does exactly that, and a tactic of eight lines that states its goal as an axiom and cites it makes Lean accept theorem two_eq_four : 2 = 4. The kernel has not been fooled, for it was never asked whether 2 is 4. It was asked whether the term has that type given the axiom, and #print axioms two_eq_four answers [two_eq_four.assumed]. A tactic can also do what Remark 10.7.1 sets aside: one of nine lines adds a lemma with the kernel's check switched off (the option debug.skipKernelTC) and cites it, and Lean 4.35.0 accepts theorem two_eq_five : 2 = 5 and reports no axiom under it. This is why certifying a proof means reading its axioms and having a kernel check its declarations again (Section 13). And no tactic and no kernel looks at whether \(P\) says what its author meant.

What each tactic hands the kernela row to a tactic: how it finds a proof and, in ink, what it leaves for the kernel to check

  1. 10.2intro, apply, exact, cases the basic tactics

    One rule of natural deduction each, applied from the conclusion upward. The term is written into the holes piece by piece, and when no hole is left it is the derivation.

    fun h => Or.elim h.right ?left ?right

    119 nodes when finished, as by hand

  2. 10.3simp rewriting to a normal form

    Replaces subterms by the library's equations until none applies, and joins the instances of the lemmas it used into one equation between the goal and True. Its lemmas about True rest on propext.

    of_eq_true (Eq.trans … (eq_self ys.length))

    1,721 nodes

  3. 10.4decide reflection

    Finds a program that decides the statement, with the proof that it does, and claims that the program returns true. The kernel runs the program to check the claim. Nothing new is trusted, and the kernel pays.

    of_decide_eq_true (id (Eq.refl true))

    65 nodes at every n

  4. 10.4native_decide reflection, evaluated outside

    Has the same program run outside the kernel and records the answer as an axiom named after the theorem. The kernel checks a citation. Trusted in addition: the compiler.

    prime_89._native.native_decide.ax_1

    27 nodes

  5. 10.5omega a certificate inside the term

    Searches for a combination of the hypotheses that no integers satisfy: multiply, add, divide by a common factor and round. The term makes the kernel redo that arithmetic. Not a full decision procedure.

    combo_sat' … 2 [1] (-1) [2, 1] …

    7,098 nodes

  6. 10.5bv_decide a certificate checked outside

    Turns arithmetic on machine words into clauses and has a solver refute them. A checker proved correct in Lean is compiled and run on the solver's certificate; its answer is an axiom, and the kernel never reads the certificate.

    mul_comm_9._native.bv_decide.ax_1

    46.9 MB of certificate at width 9

  7. 10.6grind several methods on one board

    Negates the goal and collects facts on a shared board: equalities closed under congruence, instances of lemmas, case splits, arithmetic. Stops at a contradiction and hands over ordinary terms, which rest on all three axioms.

    186 nodes for 7 ∣ 91

    all 19 recorded goals

  8. 10.6ring Mathlib, from its source

    Proves an equation in a commutative ring by bringing both sides to a normal form and comparing them. Read as text at the commit this series uses; not run.

    2^(n+1) * m = 2 * 2^n * m

green: adds an axiom that stands for a run of compiled code

A tactic is a search that ends in a term, and the kernel is never told how the term was found. A tactic can therefore be clever, lucky, slow or wrong, and as long as every declaration goes through the kernel, the one thing it can add to what a theorem rests on is an axiom, whose name then stands in the term for any checker to find. The rest of this series leans on that asymmetry. It is what lets a proof be written by a program nobody has verified, a tactic of a dozen lines or a language model (Section 12), and it is why the questions that remain are about the checker, the axioms and the statement (Section 13).

In Lean

Of a tactic's work only the term and its axioms remain, and Lean can be asked for both. One statement proved three ways: as a term, in two small steps, and by a decision procedure.

theorem by_hand : 7 ∣ 91 := ⟨13, rfl⟩

theorem by_steps : 7 ∣ 91 := by
  refine ⟨13, ?_⟩
  rfl

theorem by_decide : 7 ∣ 91 := by decide

#print by_hand
#print by_steps
#print by_decide
#print axioms by_steps
#print axioms by_decide
theorem by_hand : 7 ∣ 91 :=
Exists.intro 13 rfl
theorem by_steps : 7 ∣ 91 :=
Exists.intro 13 (Eq.refl 91)
theorem by_decide : 7 ∣ 91 :=
of_decide_eq_true (id (Eq.refl true))
'by_steps' does not depend on any axioms
'by_decide' depends on axioms: [propext]

The first two are one proof. On the natural numbers 7 ∣ 91 is by definition an existence statement, the witness is 13, and what remains, 91 = 7 * 13, holds by computation. The third never mentions 13: the library's decision procedure for divisibility computes 91 % 7, and the lemma that makes this a test of divisibility has propext under it, which is how an axiom comes to stand beneath a fact of arithmetic.

To read what a tactic built without leaving the proof, wrap it in show_term; to see which rules simp used, write simp?.

example (a b : Nat) (h : a = b) : a + 1 = b + 1 := by
  show_term rw [h]

example (xs : List Nat) : (xs ++ []).length = xs.length := by
  simp?
Try this:
  [apply] exact Eq.mpr (id (congrArg (fun _a => _a + 1 = b + 1) h)) (Eq.refl (b + 1))
Try this:
  [apply] simp only [List.append_nil]

While goals are open, show_term prints ?_ in their place, though under a fun it prints a single ?_ for the whole body: wrapped around the first two steps of the stepped proof that conjunction distributes over disjunction, it answers refine fun h => ?_, since Lean holds back what is assigned under a binder until that part of the term is complete. The terms between the steps of that proof were therefore read out of the assignments that Lean stores.

The refusals are worth learning to read, because each names the boundary of its method.

theorem by_rfl : 7 ∣ 91 := by rfl

theorem wrong : 7 ∣ 92 := by decide

theorem general (n : Nat) : n + 0 = n := by decide
error: Tactic `rfl` failed: The left-hand side
  7
is not definitionally equal to the right-hand side
  91

⊢ 7 ∣ 91
error: Tactic `decide` proved that the proposition
  7 ∣ 92
is false
error: Expected type must not contain free variables
  n + 0 = n

Hint: Use the `+revert` option to automatically clean up and revert free variables

In the first refusal, the rfl tactic checks any binary relation registered as reflexive (including divisibility, since x ∣ x for all x), so it tried to match 7 ∣ 91 against ?x ∣ ?x and failed because 7 is not definitionally equal to 91. In the second, decide evaluated the divisibility test on 7 ∣ 92, obtained false, and refuted the claim outright. In the third, decide on n + 0 = n cannot even start: because n is a free variable, there is no closed Boolean expression to evaluate to true or false. Where closed-term computation stops, library lemmas and mathematical definitions take over, and every tactic treats those definitions as given. Section 11 opens Mathlib to trace how those definitions climb from the natural numbers to the Riemann zeta function.

← Back to all posts