Maps to: Stanford CS 257 Introduction to Automated Reasoning (Winter 2026), Lecture 15 · Tue 02/24/2026 · From decision procedures to proof automation in Lean (guest lecture by Leo de Moura, AWS and Lean FRO). Reading: none listed on the course page. Basis: de Moura’s public slides (https://leodemoura.github.io/stanford2026/; the page currently returns 404, and the deck was read from the source of his GitHub site). Further sources:
- Milner’s LCF and Gordon, Milner and Wadsworth’s Edinburgh LCF (1979): the kernel idea;
- Barendregt and Wiedijk (2005), on the de Bruijn criterion;
- Cooper (1972), Presburger quantifier elimination;
- Jovanović and de Moura (2011), cutsat;
- Leino, Merz and Shankar’s if-normalization challenge, as written up in the Lean reference manual.
Lean is not used. It is not installed, and the slides’ Lean code is quoted, not run. These notes build a small LCF-style kernel in Python (
kernel.py) and make earlier lectures’ decision procedures produce proofs for it:
- SAT resolution proofs (Lecture 5);
- congruence-closure explanations (Lecture 10);
- CDCL(T) refutations (Lecture 10);
- Farkas certificates (Lecture 11);
- branch-and-bound trees (Lecture 12).
ifexpr.pytranscribes the slides’ if-normalization challenge. The experiments were designed for these notes and do not reflect what was said in class. Code:code/lecture15/(3 scripts + 2 modules; Python standard library only; about 1 to 10 seconds of CPU time each) Reading time: 2.5 hours including running the code
0. How to read this lecture
0.1 Learning goals
After this lecture you should be able to:
- Explain the LCF approach: a small trusted kernel, theorems that only its rules can create, and untrusted automation that must drive the kernel. State the de Bruijn criterion.
- Compare proof terms (Lean, via Curry–Howard) with LCF-style theorem values, and certificate checking (LRAT) with proof reconstruction.
- Turn the certificates of earlier lectures into kernel proofs:
- resolution proofs into chains of natural-deduction steps;
- congruence-closure explanations into equality proofs;
- Farkas multipliers into sums of inequalities;
- branch and bound into a tree of integer splits.
- Estimate the cost of trust: proof size and replay time, compared with solving.
- Describe how Lean’s
bv_decide,omega,grindandlean-smtreuse the course’s algorithms, and why a failing tactic should return a countermodel. - Explain what the if-normalization challenge shows: instance checking vs a proof by induction.
0.2 Prerequisites and scope
| Assumed | Introduced here | Developed later |
|---|---|---|
| natural deduction / proof systems (Lectures 3, 8) | an LCF kernel; proof objects; re-checking | — |
| CDCL and resolution proofs (Lecture 5) | resolution replay | bit-blasting, the input of bv_decide (Lecture 16) |
| congruence closure, CDCL(T) (Lecture 10) | explanation replay; SMT proof reconstruction | E-matching (Lecture 17); theory combination (Lecture 18) |
| Farkas certificates (Lecture 11); branch and bound (Lecture 12) | linarith; branch and bound as a proof | — |
| — | Cooper’s algorithm (overview) | quantifier elimination (Lecture 17) |
0.3 Map
§1 why a proof assistant? the verification spectrum
§2 the LCF kernel: theorems as values, the trusted base ← code 01
§3 derived rules and proofs by evaluation ("decide") ← code 01
§4 SAT: resolution replay, and the cost of trust ← code 02
§5 equality and SMT: congruence closure, grind, lean-smt ← code 02
§6 arithmetic: linarith, omega/Cooper, cutsat ← code 02
§7 the if-normalization challenge ← code 03
§8 why automation is harder with dependent types (overview)
§9 summary §10 common pitfalls §11 exercises §12 further reading §13 next lecture
0.4 Notation
| Symbol | Meaning |
|---|---|
| Γ ⊢ φ | a theorem: φ follows from the hypotheses Γ |
| kernel step | one application of a kernel rule; the proof size counts distinct steps |
| certificate | data that lets a simple checker verify an answer (a model, a resolution proof, Farkas multipliers) |
| tactic | an untrusted procedure that builds a theorem by calling kernel rules |
| T, F, x0, (if c then t else e) | the IfExpr syntax of §7 |
0.5 The code of this lecture
kernel.py:
- the kernel:
Theorem, 30 rules,KernelError; - proof objects:
proof_sizeandrecheck; - derived rules:
excluded_middle,or_cases,resolve,cut,clause_by_contradiction; - tactics:
tauto,sat,cc,smt_refute,linarithandlia.
ifexpr.py: the challenge’s definitions, normalize (with two optional bugs), and check_instance.
1. Why a proof assistant?
1.1 The verification spectrum
The slides line up four approaches:
| approach | strength | limit |
|---|---|---|
| testing | finds bugs | cannot prove their absence |
| model checking (Lecture 9) | exhaustive for finite-state systems | finite state |
| SMT solving (Lectures 10–13) | automatic for decidable theories; sat / unsat / unknown | decidable fragments only |
| interactive theorem proving (Lean) | arbitrary mathematical statements; proof objects that can be checked independently | needs guidance |
The key insight: these are complementary. Decision procedures become tactics inside a proof assistant: the same algorithms, now producing proofs.
1.2 Why not just trust the solver?
An SMT solver is tens of thousands of lines of highly optimized code. Every lecture of this course has found a way to check answers instead of trusting them:
- models checked by evaluation;
- DRUP proofs (Lecture 5);
- theory lemmas re-checked by independent procedures (Lecture 10);
- Farkas certificates (Lecture 11).
A proof assistant makes that discipline systematic. Every result, however it was found, ends as a proof checked by one small program. The slides call it the common principle of LRAT checkers and Lean’s kernel:
Separate proof search (complex, untrusted) from proof checking (simple, trusted).
1.3 Will AI make decision procedures obsolete?
The slides argue no:
- Decision procedures make reasoning free. They are sound, complete and predictable on their fragment (“there is no point using AI to … do Gaussian elimination”).
- SAT solvers grind through combinatorial problems whose structure was lost in the encoding.
What changes is the orchestration. AI is good at high-level choices in undecidable territory: which lemma, which instantiation, which proof strategy. Decision procedures then close the subgoals reliably. “Better tactics → better AI”: a goal closed in one step instead of fifty shrinks the search, and compact proofs make better training data.
2. The LCF kernel
2.1 Theorems as values
Robin Milner’s LCF (1972) introduced the idea every modern proof assistant uses in some form:
Make theorem an abstract data type whose values can be created only by the inference rules.
A tactic can then be arbitrarily clever, or arbitrarily buggy. Whatever value it returns is a theorem, because the only way to make one is through the rules.
kernel.py has 30 rules:
| group | rules |
|---|---|
| propositional (classical) | assume, truth, imp_intro/elim, and_intro/elim1/elim2, or_intro1/2, or_elim, not_intro/elim, bot_elim, dne, iff_intro/elim1/elim2 |
| equality | refl, sym, trans, cong, cong_atom |
| integer linear arithmetic | le_refl, lin_add, lin_scale, lin_norm, lin_contra, lin_neg, int_strict, int_split |
Each rule checks the shape of its premises and builds the conclusion. For example, imp_elim needs and , and returns . Script 01, Part 1 builds the slides’ and_swap by hand:
p ∧ q ⊢ q ∧ p [and_intro]
p ∧ q ⊢ q [and_elim2]
p ∧ q ⊢ p ∧ q [assume]
p ∧ q ⊢ p [and_elim1]
p ∧ q ⊢ p ∧ q [assume]
In Lean the same proof is the term ⟨h.2, h.1⟩. That is Curry–Howard: propositions are types, proofs are terms, and the kernel’s type checker checks them. LCF systems (HOL, Isabelle) keep theorems as values; Lean and Coq keep proof terms. Both separate search from checking.
2.2 What the kernel refuses
Script 01, Part 2:
| attempt | kernel |
|---|---|
| forge a theorem directly | refused: a Theorem can only be created by the kernel’s rules |
| modus ponens with the wrong antecedent | refused: imp_elim: the antecedent does not match the second premise |
| transitivity through different middle terms | refused: trans: the middle terms differ |
| call x ≤ 0 a contradiction | refused: lin_contra: the atom still has variables |
| “simplify” x + x ≤ 3 to 2·x ≤ 4 | refused: lin_norm: the two atoms are not the same linear constraint |
| change a theorem after the fact | refused: theorems are immutable |
| steal the private key, forge, then recheck | refused: recheck: ‘forged’ is not a rule of the kernel |
A caveat about Python. Python cannot hide a value the way ML’s abstract types can: the key that guards Theorem could be taken by determined code. The defence is the next section’s recorded proof. Every theorem remembers the rule that made it and its premises, and recheck replays the whole proof through the rules. A theorem without a real derivation is exposed.
2.3 The trusted base and the de Bruijn criterion
The de Bruijn criterion (named after the Automath system): a proof assistant is reliable when its proofs can be checked by a small, simple program.
- How small this kernel is. It has 203 lines of code, in a module of 1,022 lines (script 01, Part 3). Everything else is outside the trusted base: derived rules, tactics, the SAT solver, congruence closure and the simplex.
- Re-checking. Lean proofs can be exported and checked by independent checkers.
recheckis the analogue: Peirce’s law has a 62-step proof, and all 62 steps are replayed.
One deliberate exception. The arithmetic rules contain a short normalizer of linear terms (about 25 lines), which decides whether and are the same constraint. That is computation inside the kernel. Lean makes the same trade for natural-number literals: its kernel does fast arithmetic on numerals, a larger trusted base in exchange for speed. The trusted base is a design choice, not a law of nature.
Run it:
python3 01_lcf_kernel.py(under a second).
3. Derived rules and proofs by evaluation
3.1 Derived rules
A derived rule is an ordinary function that calls kernel rules. It extends what is convenient without extending what is trusted. For example:
-
excluded_middle(p)proves in 8 steps:- assume ;
- derive ;
- derive , a contradiction;
- conclude with
dne.
-
resolve(th1, th2, p, R)turns (containing ) and (containing ) into . It argues by cases on :- in the case , it goes into cases on , where contradicts ;
- every other literal is introduced into the resolvent.
That costs about steps.
-
clause_by_contradictionturns a refutation of into a proof of the clause . SMT reconstruction needs exactly this step.
3.2 Proof by evaluation: tauto
tauto proves any propositional tautology:
- split on every atom with the excluded middle;
- under a complete assignment,
eval_proofbuilds, connective by connective, a proof of the formula (if true) or of its negation (if false).
This is the kernel version of Lean’s decide. A false goal yields a countermodel instead of a theorem (script 01, Part 4):
| formula | result | proof size |
|---|---|---|
| (Peirce) | proved | 62 |
| proved | 90 | |
| proved | 51 | |
| not a tautology: = false, = true | — |
The growth. On “some is true, or all are false”:
| atoms | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| proof size | 14 | 42 | 96 | 202 | 412 | 830 | 1,664 | 3,330 |
The size roughly doubles per atom. Proof by evaluation is fine for small finite problems and hopeless for large ones; for those, use a SAT solver and check its certificate (§4).
4. SAT: certificates, replay, and the cost of trust
4.1 Replaying a resolution proof
Lecture 5’s CDCL can record every learned clause as a chain of resolutions (resolution=True). The sat tactic:
- assumes each input clause it needs;
- replays every resolution with
resolve; - ends with the empty clause.
The result is the theorem whose hypotheses are exactly the input clauses. Nothing about the solver is trusted.
4.2 The cost
Script 02, Part 1, on the pigeonhole formulas ( pigeons, holes):
| formula | clauses | conflicts | resolution steps | kernel steps |
|---|---|---|---|---|
| PHP(2) | 9 | 2 | 10 | 92 |
| PHP(3) | 22 | 7 | 52 | 1,021 |
| PHP(4) | 45 | 28 | 284 | 11,363 |
| PHP(5) | 81 | 153 | 1,551 | 113,012 |
| PHP(6) | 133 | 713 | 7,375 | 1,096,917 |
Three observations.
- Proof size. Each resolution costs dozens of kernel steps: PHP(6) has about 150 kernel steps per resolution.
- Time. Replaying PHP(6) took tens of times longer than solving it (10.5 s against 0.17 s in the saved run). The wall-clock columns fluctuate with machine load; the step counts do not.
- Growth. Pigeonhole formulas have only exponentially long resolution proofs (Haken 1985), so trust gets expensive fast.
4.3 How Lean avoids the replay: verified checkers
The slides show the pipeline of bv_decide, Lean’s bit-vector decision procedure:
Simplify → Reflect → Bit-blast → AIG → CNF → SAT solver (CaDiCaL) → LRAT proof → verified checker
Instead of replaying millions of kernel steps, bv_decide checks the solver’s LRAT certificate with a checker that is itself proved correct in Lean: Josh Clune’s verified LRAT checker. This is proof by reflection. The kernel checks one theorem, “if the checker accepts this certificate, the formula is unsatisfiable”, plus one run of the checker. Lecture 16 covers the bit-blasting part.
The slides’ bv_decide? pattern separates the expensive part further:
bv_decide?runs the SAT solver once and stores the LRAT file;bv_checkreplays it on every later build, without a SAT solver.
4.4 What a buggy SAT solver can do
Nothing harmful. In script 02, Part 5, a “solver” claims the satisfiable is unsatisfiable. It resolves correctly to , then asserts that ” contradicts ”. The kernel answers: refused: not_elim: the premises are not φ and ¬φ.
5. Equality and SMT
5.1 Congruence closure explanations
Lecture 10’s congruence closure keeps a proof forest: every merge is an edge labelled with its reason, either an asserted equality or a congruence. The cc tactic replays an explanation edge by edge:
- an asserted edge becomes the hypothesis (flipped by
symif needed); - a congruence edge becomes
congover the arguments’ explanations; - consecutive edges are chained by
trans.
Script 02, Part 2:
f(f(f(a))) = a, f(f(f(f(f(a))))) = a ⊢ f(a) = a (16 kernel steps)
a = g(c), f(a) = b, f(g(c)) = c ⊢ b = c (11 kernel steps)
The second is the slides’ E-matching example: the lemma , annotated @[grind =], and the goal .
- E-matching finds the instance , because in the E-graph sits next to once . That is the subject of Lecture 17.
- Congruence closure does the rest.
5.2 grind
The slides describe grind (in Lean since v4.22, by Kim Morrison and de Moura) as an SMT-inspired tactic native to dependent type theory: “a virtual whiteboard”. Its parts:
- the central structure: an E-graph, the congruence closure of Lecture 10;
- cooperating engines: E-matching, constraint propagation and guided case analysis;
- satellite solvers: cutsat (linear integer arithmetic), commutative rings (Gröbner bases) and linear arithmetic over ordered modules.
Their combination is theory combination, Lecture 18’s topic. In the slides’ example, the ring solver derives , congruence closure concludes , and integer arithmetic refutes . Every inference produces a Lean proof term.
| DPLL(T) (this course) | grind |
|---|---|
| SAT engine: decisions + BCP | case splitting + constraint propagation |
| theory solvers check consistency | satellite solvers check consistency |
| theory propagation | E-graph propagation |
| backjumping + conflict analysis | backjumping |
| EUF, LIA, arrays, BV | congruence closure, cutsat, rings, linarith |
What grind is not for (the slides): combinatorial explosion, such as large pigeonhole instances, graph colouring and big Sudokus. Those need millions of case splits; use bv_decide.
5.3 SMT proof reconstruction: lean-smt
lean-smt (Stanford, UFMG and Iowa) translates a Lean goal to SMT-LIB, calls cvc5, and reconstructs cvc5’s proof in Lean. smt_refute does the same with this course’s CDCL(T):
- CDCL(T) refutes the formula and returns its theory lemmas (clauses valid in EUF);
- each lemma is proved in the kernel:
ccrefutes its negated literals, thenclause_by_contradiction; - plain CDCL with resolution proofs refutes the input clauses plus the lemma clauses, and the resolution proof is replayed with the lemmas as proved theorems.
On Lecture 10’s example (), script 02, Part 3 prints:
c = g(a), c ≠ d, d = g(a) ∨ f(c) ≠ f(g(a)) ⊢ ⊥
2 theory lemmas proved by cc, 4 resolution steps, 100 kernel steps; rechecked 100 steps
The hypotheses are the input clauses as the abstraction normalized them ( and are one atom there). A production tool adds the symmetry steps that connect them to the user’s text.
6. Arithmetic
6.1 linarith: Farkas certificates
The slides: “linarith finds a non-negative linear combination of hypotheses that contradicts the negation of the goal. Same idea as Farkas’ lemma.” linarith here proceeds as follows:
- negate the goal and turn into (
lin_neg); - ask Lecture 11’s simplex for a Farkas certificate, and clear its denominators;
- let the kernel scale and add the inequalities and check that the sum is a false constant (
lin_contra).
Script 02, Part 4, on the slides’ examples:
| goal | result | multipliers | kernel steps |
|---|---|---|---|
(the omega slide) | proved | 1, 1, 1 | 9 |
(the linarith slide) | proved | 2, 1 | 8 |
(a grind slide) | proved | 1, 2, 1 | 10 |
(the linarith slide) | fails | countermodel | — |
The slides’ linarith example is false. Its hypotheses bound from below and from above, but the goal needs an upper bound on , and is unbounded:
- the simplex’s countermodel satisfies the hypotheses, but ;
- so does .
No tactic can prove it, Lean’s included. Presumably a hypothesis was lost when the slide was written.
6.2 omega and Cooper’s algorithm
The slides introduce omega as “a variant of Cooper’s algorithm”, which decides quantifier-free Presburger arithmetic on Nat, Int, Fin, UInt and BitVec, and is “completely verified”.
Cooper (1972) decides Presburger arithmetic by quantifier elimination. To eliminate from , with all coefficients of normalized to and divisibility constraints allowed:
- if can be taken small enough, holds for all very negative , which is , and only finitely many residues modulo the lcm of the divisors matter;
- otherwise some lower bound is “tight”, and for a small .
So becomes a finite disjunction of instances, with no quantifier. It is related to Lecture 12’s Omega test, which eliminates variables by real and dark shadows. Lecture 17 returns to quantifier elimination.
6.3 cutsat: integers by proof
The slides’ cutsat example, , is unsatisfiable over but not over . Script 02 shows both sides:
-
over ℚ: linarith fails, with the rational model , ;
-
over ℤ:
liasucceeds. It records Lecture 12’s branch and bound as a proof:- every split is the integer axiom
int_split: ; - every leaf is a Farkas refutation;
or_elimglues the halves.
It needs 7 nodes, 4 leaves and 36 kernel steps.
- every split is the integer axiom
cutsat itself (Jovanović and de Moura 2011) is a conflict-driven procedure for integer arithmetic. In grind it is one of the satellite solvers, parametrized by a type class that embeds Int32, BitVec 64 and others into the integers.
6.4 Rings: Gröbner bases (overview)
The slides’ ring solver proves, for instance, in any commutative ring, by Gröbner bases: polynomial division generalizes Gaussian elimination. Since BitVec 8 is a commutative ring of characteristic 256, needs no bit-vector theory at all. That is a word-level shortcut that Lecture 16’s bit-blasting does not have.
Run it:
python3 02_certified_automation.py(about 10 s of CPU time).
6.5 Buggy automation, and failed goals
Script 02, Part 5:
| buggy automation | kernel |
|---|---|
| a SAT “solver” refutes the satisfiable | refused: not_elim: the premises are not φ and ¬φ |
| a simplex returns a wrong Farkas certificate for | refused: lin_contra: the constant atom is true |
| a congruence closure chains with | refused: trans: the middle terms differ |
When the goal is false, the best answer is a countermodel. The slides show grind failing on an array goal: after writes at and , with but nothing about . grind’s diagnostics show the assignment , , . Lecture 13’s array solver finds the same kind of model (), and with the missing hypothesis the formula is UNSAT, i.e. the goal holds. The slides’ advice: “often the fix is: add a [grind] annotation to the missing lemma”, or the missing hypothesis.
7. The if-normalization challenge
7.1 The problem
The slides end with a challenge posed by Leino, Merz and Shankar. IfExpr is a literal, a variable or if-then-else. Write normalize such that every result is normalized and evaluates like the input. Normalized means:
- no nested if in condition position;
- no constant condition;
- no redundant if (equal branches);
- each variable evaluated at most once on any path.
The slides’ function, transcribed in ifexpr.py:
- a nested condition
if (if a b c) t eis pulled out toif a (if b t e) (if c t e); - a constant condition picks its branch;
- a variable condition , unassigned, normalizes both branches under and , and collapses them if they are equal;
- an assigned variable is replaced by its value.
Termination is not structural. Pulling a condition out copies and , so the expression grows. The slides’ measure fixes this: normSize counts the condition twice (), and it decreases in every recursive call. Script 03, Part 1 traces one example:
| call | assignment | argument | normSize |
|---|---|---|---|
| nested | — | (if x0 then (if x1 then (if x0 then x2 else x3) else x3) else (if F …)) | 10 |
| branch | x0 := T | (if x1 then (if x0 then x2 else x3) else x3) | 7 |
| branch | x0 := T, x1 := T | (if x0 then x2 else x3) | 4 |
| assigned | x0 := T, x1 := T | (if T then x2 else x3) | 2 |
| … |
The input’s normSize is 13, and the result is (if x0 then (if x1 then x2 else x3) else x3).
7.2 Lean’s proof, and what instances can show
In Lean the whole specification is one line:
theorem normalize_spec (assign : Std.HashMap Nat Bool) (e : IfExpr) :
(normalize assign e).normalized
∧ (∀ f, (normalize assign e).eval f = e.eval fun w => assign[w]?.getD (f w))
∧ ∀ v, v ∈ vars (normalize assign e) → ¬ v ∈ assign := by
fun_induction normalize with grind +locals
fun_inductionproduces one goal per case ofnormalize, with an induction hypothesis for every recursive call.grind +localsunfolds the definitions and closes each case with congruence closure, E-matching and case splits.
The slides compare this with about 300 lines in another solution.
Without induction, we can only check instances. Script 03, Part 2 checks 200 random expressions (depth ≤ 4, 4 variables):
| normalized | measure decreases | assigned vars gone | ⊢ eval(normalize e) ⇔ eval e | recursive calls | kernel steps |
|---|---|---|---|---|---|
| 200/200 | 200/200 | 200/200 | 200/200 | 17,700 | 312,333 |
The semantic property is a kernel theorem for each instance (by tauto). It is still only 200 expressions.
7.3 Two bugs
Script 03, Part 3 runs two deliberately wrong versions on 100 expressions:
| bug | what it does | not normalized | no equivalence theorem |
|---|---|---|---|
| no-redundancy-check | keeps if x then t else t | 63/100 | 0/100 |
| swap-nested | pulls a nested condition out with swapped else-branches | 0/100 | 64/100 |
What each check catches.
- The first bug preserves meaning, so only the syntactic check sees it.
- The second preserves shape, so only the proof attempt sees it, and it returns the assignment on which the expressions differ.
- Both bugs are invisible on the expressions that never reach the faulty case.
A proof for all expressions has no such gaps.
7.4 The cost of instance proofs
| variables | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|
| mean kernel steps per expression | 514 | 953 | 1,455 | 4,223 | 9,688 |
Case analysis roughly doubles with every variable. An induction proof is written once, and its size does not depend on any input.
Robustness. The slides also show the same one-line proof surviving:
- three formulations of the variable-elimination condition;
- replacing HashMap by TreeMap.
grind works from the libraries’ annotated lemmas, not from the syntax of the definitions.
Run it:
python3 03_if_normalization.py(about 10 s of CPU time).
8. Why automation is harder with dependent types (overview)
The slides explain why SMT techniques do not transfer to Lean for free.
- Types depend on values.
Array.get as i htakes a proofh : i < as.size. Rewriting2 + i - 1toi + 1inside it makesh’s type wrong. Lean generates custom congruence theorems that “patch” the proof term: bookkeeping that is invisible in SMT, but pervasive in Lean. - Type classes. Mathlib has about 1,500 classes and 20,000 instances. Instance resolution is backward chaining on Horn clauses (tabled resolution, Lecture 8’s territory). Automation must recognize that differently synthesized instances are definitionally equal.
Our kernel has neither problem: it has no types and no instances. That is why it is small, and also why it can say so much less than Lean.
In industry, according to the slides, Lean is used for:
- AWS’s Cedar policy language;
- SampCert, verified differential privacy, also at AWS;
- Microsoft’s SymCrypt, via Aeneas for Rust;
- AWS’s Neuron compiler.
In mathematics the slides list AlphaProof (silver at IMO 2024), and Harmonic (gold) and ByteDance’s Seed Prover (silver) at IMO 2025, all in Lean. grind alone is used about 3,400 times in Mathlib.
9. Summary
- A kernel makes theorems an abstract type created only by inference rules. Automation is untrusted and must drive the kernel, so bugs make it fail, not lie (the de Bruijn criterion: a small checker).
- Derived rules add convenience, not trust: excluded middle, resolution, cut. Proof by evaluation decides propositional goals but doubles with each atom.
- Certificates become proofs:
- resolution proofs, replayed step by step;
- congruence-closure explanations, as sym, cong and trans;
- Farkas multipliers, as a sum of inequalities;
- branch and bound, as integer splits with Farkas leaves.
- Trust has a price. The kernel proof for PHP(6) has 1.1 million steps, and replaying it takes tens of times longer than solving. Lean’s
bv_decidechecks LRAT certificates with a verified checker instead, andbv_decide?stores them. - grind is DPLL(T) on an E-graph with satellite solvers; lean-smt reconstructs cvc5 proofs; omega is a variant of Cooper’s algorithm; cutsat handles integer arithmetic in grind.
- Two slide examples are not provable: the
linarithexample is false (countermodel ), and the grind diagnostics example is a deliberate failure (countermodel ). A failed proof should end in a countermodel. - Instances vs induction. Checking 200 instances of if-normalization finds no bug, and catches two planted ones, but only on the inputs that exercise them. Lean’s single proof by induction covers all inputs.
10. Common pitfalls
- “The tactic succeeded, so the solver is correct.” A kernel-checked proof says the theorem is right, not the tool. The next run may fail, but never lie.
- Counting the kernel’s size but not its computation. A normalizer inside the kernel is part of the trusted base, however short.
- Expecting replay to be cheap. Resolution replay multiplies proof size; for big SAT proofs use a verified checker.
- Reading “tactic failed” as “goal false”. linarith fails on goals that need integer reasoning (cutsat) or nonlinear facts; check the countermodel.
- Hypotheses that changed shape. A reconstructed proof may mention normalized atoms ( for ); connecting them to the user’s statement is part of the job.
- Instance testing as verification. It finds bugs only where the inputs exercise them.
11. Exercises
1. (kernel rules) Prove with the kernel’s rules by hand. How many steps?
Answer
The proof. Let and .
assume(A),assume(B),assume(p).imp_elim(A, p)gives .not_elim(B, q)gives ⊥, from .not_intro(p, ·)gives .imp_intro(B, ·), thenimp_intro(A, ·).
The count. 3 assumptions + 5 rules = 8 steps.
2. (trusted base) Which parts of kernel.py would a bug make unsound (a false theorem), and which only incomplete?
Answer
Unsound. Only a bug between the BEGIN/END markers can produce a false theorem: a rule that checks too little, or a wrong _linear normalizer.
Only incomplete. A bug in resolve, cc, linarith, the SAT solver or the simplex can only make a tactic raise an error.
3. (resolution replay) Why does replaying one resolution cost about steps, and how could a different representation of clauses make it linear?
Answer
Why quadratic. The derived rule argues by cases on every literal of , and in the pivot case by cases on every literal of . Each case introduces one literal into the resolvent, which costs a walk through the target’s nested disjunction.
Linear alternatives. Represent clauses as implications or sets with a primitive “clause” rule, or check RUP steps with a verified propagation procedure (reflection). Either needs a richer kernel or a verified checker.
4. (Farkas by hand) Find the multipliers for and write the sum.
Answer
The multipliers. All are 1.
- In the ≤ form the three inequalities are , and .
- Their sum is : the variables cancel, and .
The result. That is false, and script 02 reports the multipliers 1, 1, 1.
5. (the false slide) Find all with that satisfy the linarith slide’s hypotheses but violate its goal. Propose a hypothesis that makes the goal provable.
Answer
The counterexamples. With : we need , and . For example , , or any with .
A fix. Adding makes the goal provable: .
6. (cutsat) Verify by hand that , satisfies the cutsat constraints, and show that no integer point does.
Answer
The rational point.
- , in ;
- , in .
No integer point. The polygon’s vertices have between about 0.59 and 2.40, so only and need checking:
- : contains no integer;
- : contains no integer.
lia proves this with 7 nodes.
7. (if-normalization) Compute normSize before and after the nested-if step for if (if a b c) t e in general, and show that it decreases.
Answer
Before. , with .
After. .
The difference. .
8. (Cooper) Eliminate from over the integers using “x = lower bound + j”.
Answer
The lower bound. It is . The divisor is 3, so ranges over : .
The test points. Test at each: works. The disjunction is therefore true, and the formula holds ().
9. (programming) Add a tactic rup(clauses, lemma) that proves a clause by reverse unit propagation: assume the negated literals, propagate units by resolve-style steps, and derive ⊥. Replay a DRUP proof from Lecture 5 with it and compare kernel steps with resolution replay on PHP(4).
Answer sketch
Each propagation step. A unit clause under the current negated literals is a resolution chain: resolve the clause with each assumed negated literal. Cache derived units.
What to expect. RUP proofs are much shorter than full resolution chains in the file (no pivots recorded), but each step’s replay re-does propagation. Kernel steps are similar to or larger than resolution replay, and the search for the propagation order is untrusted.
10. (programming) Extend cc to predicates: given , and , derive ⊥ with cong_atom. Then use it to reconstruct proofs of Lecture 10’s random EUF formulas that contain predicates.
Answer sketch
The new case. If a hypothesis and a negated have and equal in the congruence closure, prove by the explanation replay. Then apply cong_atom to get , and not_elim to get ⊥.
In smt_refute. Predicate atoms become literals like any other, and the lemma proofs call the extended cc.
12. Further reading
- L. de Moura, “From Decision Procedures to Proof Automation in Lean”, Stanford CS257 guest lecture, 2026 (slides: leodemoura.github.io/stanford2026).
- M. Gordon, R. Milner, C. Wadsworth, Edinburgh LCF, LNCS 78, 1979; J. Harrison, Handbook of Practical Logic and Automated Reasoning, Chapter 6 (LCF-style kernels).
- H. Barendregt, F. Wiedijk, “The Challenge of Computer Mathematics”, Phil. Trans. R. Soc. A, 2005 (the de Bruijn criterion).
- L. de Moura, S. Ullrich, “The Lean 4 Theorem Prover and Programming Language”, CADE 2021.
- D. C. Cooper, “Theorem Proving in Arithmetic without Multiplication”, Machine Intelligence 7, 1972.
- D. Jovanović, L. de Moura, “Cutting to the Chase: Solving Linear Integer Arithmetic”, CADE 2011 (cutsat).
- N. Wetzler, M. Heule, W. Hunt, “DRAT-trim”, SAT 2014; L. Cruz-Filipe et al., “Efficient Certified RAT Verification”, CADE 2017 (LRAT).
- A. Haken, “The Intractability of Resolution”, TCS 1985.
- The Lean Reference Manual: the grind and bv_decide chapters, and the if-normalization example.
13. Next lecture
Lecture 16: bit-vectors (guest lecture by Mathias Preiner).
- The semantics. Fixed-width machine arithmetic: overflow, signed vs unsigned, shifts.
- The standard answer: bit-blasting. Circuits for addition, multiplication and comparison, turned into CNF for Lecture 5’s CDCL. It is also the core of
bv_decide. - Why it is also the bottleneck. Multiplication, and the word-level techniques (rewriting, abstraction) that avoid blasting.