Dr. Bartosz Naskręcki · Wydział Matematyki i Informatyki UAM · 06-S1MA03-P16780
winter semester 2026/27 · course taught in Polish — dates and rooms: Harmonogram (in Polish)
conclusion · the environment · the kernel says “no”rw · calc · proofs from beginning to end · a cheating tactic · Lean · Boole Lab| The archive of November 20 | |
|---|---|
| 175,187 | Lean files |
| 17,374,215 | lines |
| 1,484,733 | declarations accepted by the independent kernel NanoDA (Rust) |
| 61.6 GB | file with the proof exported for NanoDA |
| 3 | axioms: propext, Classical.choice, Quot.sound |
Sources: the note alpo.ge/remark.pdf · status of the checks and links to the logs: nasqret.github.io/riemann-rev · A. Sutherland’s logs: math.mit.edu/~drew/grh
The statement — in the Mathlib library
def RiemannHypothesis : Prop :=
∀ (s : ℂ) (_ : riemannZeta s = 0)
(_ : ¬∃ n : ℕ, s = -2 * (n + 1)) (_ : s ≠ 1),
s.re = 1 / 2
Mathlib, file NumberTheory/LSeries/RiemannZeta.lean (line breaks ours). The proof is the constant riemannHypothesis of type RiemannHypothesis.
Three questions
Challenge.lean (Comparator program): five theorems match.#print axioms: only three standard axioms.Plan: theory → five rules → a kernel in Python (about 100 lines) → tactics → trust → search.
for the sum + | for the product * | ||
|---|---|---|---|
| H1 | x + y = y + x | H2 | x * y = y * x |
| H3 | x + y * z = (x + y) * (x + z) | H4 | x * (y + z) = x * y + x * z |
| H5 | x + 0 = x | H6 | x * 1 = x |
| H7 | x + n(x) = 1 | H8 | x * n(x) = 0 |
$n(x)$ — the complement (this is how Robbins and the program EQP wrote it). Every axiom holds for all $x, y, z$. The columns are dual: swap $+ \leftrightarrow *$, $0 \leftrightarrow 1$.
Models
An equational theory
| step | justification |
|---|---|
x + x = (x + x) * 1 | H6 |
= (x + x) * (x + n(x)) | H7 |
= x + x * n(x) | H3 |
= x + 0 | H8 |
= x | H5 |
What really happens in each step?
Step 4: x + x * n(x) = x + 0
Eq.symm (H3 x x (n x)); step 1 is H6 for x + x: Eq.symm (H6 (x + x)).| rule | premises | conclusion | in Lean |
|---|---|---|---|
Refl(t) | — | t = t | Eq.refl t (rfl) |
Symm(p) | p : a = b | b = a | Eq.symm p |
Trans(p, q) | p : a = b, q : b = c | a = c | Eq.trans p q |
CongrArg(z, C, p) | p : a = b | C[z:=a] = C[z:=b] | congrArg (fun z => C) p |
Inst(H, t₁, …, tₖ) | a fact H : ∀ x₁ … xₖ, l = r | l[x:=t] = r[x:=t] | H t₁ … tₖ |
H is an axiom or a previously proved theorem — this is how a library grows (Mathlib contains hundreds of thousands of them).| step | proof of the step (Lean-style notation) |
|---|---|
x + x = (x + x) * 1 | Eq.symm (H6 (x + x)) |
_ = (x + x) * (x + n(x)) | Eq.symm (congrArg (fun z => (x + x) * z) (H7 x)) |
_ = x + x * n(x) | Eq.symm (H3 x x (n x)) |
_ = x + 0 | congrArg (fun z => x + z) (H8 x) |
_ = x | H5 x |
We chain the steps with four Eq.trans — the whole tree has 14 nodes:
Eq.trans (Eq.trans (Eq.trans (Eq.trans (Eq.symm (H6 (x + x)))
(Eq.symm (congrArg (fun z => (x + x) * z) (H7 x)))) (Eq.symm (H3 x x (n x))))
(congrArg (fun z => x + z) (H8 x))) (H5 x)
Printed by our program (the function syntax.lean); the term from real Lean is in Part IV.
kernel.py
# term: 'x' (a variable), '0' (a constant) or a tuple ('+', 'x', ('n', 'x'))
@dataclass(frozen=True)
class Trans: # from a = b and b = c follows a = c
p: object
q: object
# … likewise Refl, Symm, CongrArg, Inst
def subst(t, s):
"""Replaces at once the variables in the dict s (variable -> term)."""
if isinstance(t, str):
return s.get(t, t)
return (t[0],) + tuple(subst(a, s) for a in t[1:])
>>> t = term("x + n(x)")
>>> t
('+', 'x', ('n', 'x'))
>>> show(subst(t, {"x": term("y * z")}))
'y * z + n(y * z)'
Refl, Symm, Trans, CongrArg, Instconclusion
def conclusion(self, d):
"""The equation (left, right) that the proof d justifies."""
match d:
case Refl(t):
return self.term(t), t
case Symm(p):
a, b = self.conclusion(p)
return b, a
case Trans(p, q):
a, b = self.conclusion(p)
b2, c = self.conclusion(q)
if b != b2:
raise ProofError(f"Trans: middles {b!r} and {b2!r}")
return a, c
case CongrArg(z, C, p):
if not self.is_var(z):
raise ProofError(f"CongrArg: {z!r} is not a variable")
self.term(C)
a, b = self.conclusion(p)
return subst(C, {z: a}), subst(C, {z: b})
case Inst(name, args):
if name not in self.facts:
raise ProofError(f"unknown fact: {name}")
variables, l, r = self.facts[name]
if len(args) != len(variables):
raise ProofError(f"{name}: wrong number of arguments")
s = dict(zip(variables, map(self.term, args)))
return subst(l, s), subst(r, s)
raise ProofError(f"not a proof: {d!r}")
Trans
def axiom(self, name, variables, l, r):
self._add(name, variables, l, r, {name})
def theorem(self, name, variables, l, r, proof):
"""Adds ∀ variables, l = r — only when the proof justifies it."""
if self.conclusion(proof) != (l, r):
raise ProofError(f"{name}: the proof justifies another equation")
used = used_facts(proof)
assumed = set().union(*(self.assumptions[n] for n in used))
self._add(name, variables, l, r, assumed)
>>> B, proofs = theory_with_theorems()
>>> sorted(B.assumptions["add_idem"]) # #print axioms
['H3', 'H5', 'H6', 'H7', 'H8']
assumptions is our #print axioms: which axioms the proof really uses
>>> B.theorem("idem", ["x"], *equation("x + x = x"),
... Inst("H5", ("x",)))
kernel.ProofError: idem: the proof justifies another equation
>>> B.conclusion(Trans(Inst("H5", ("x",)), Inst("H6", ("x",))))
kernel.ProofError: Trans: middles 'x' and ('*', 'x', '1')
>>> B.conclusion(Inst("H9", ("x",)))
kernel.ProofError: unknown fact: H9
>>> B.conclusion(Inst("H7", ("x", "y")))
kernel.ProofError: H7: wrong number of arguments
H5 x proves x + 0 = x, not x + x = xx + 0 = x cannot be followed by x * 1 = xWe show the last line of the error message.
In Lean, terms have bound variables: $\forall$, $\exists$, fun. Naive substitution changes the meaning:
(fun y => x + y)[x := y] ≠ fun y => y + y
The free y has been “captured” by fun y.
in the deep dive
fun y => x + y is λ. x + #0
def match_pattern(pattern, t, free, s):
"""A substitution s of the variables in `free` with pattern[s] == t."""
if isinstance(pattern, str) and pattern in free:
if pattern in s:
return s if s[pattern] == t else None
return {**s, pattern: t}
if isinstance(pattern, str) or isinstance(t, str):
return s if pattern == t else None
if pattern[0] != t[0] or len(pattern) != len(t):
return None
for a, b in zip(pattern[1:], t[1:]):
s = match_pattern(a, b, free, s)
if s is None:
return None
return s
In x + x * n(x), can we see the left-hand side of H3, x + y * z?
>>> match_pattern(term("x + y * z"),
... term("x + x * n(x)"),
... ("x", "y", "z"), {})
{'x': 'x', 'y': 'x', 'z': ('n', 'x')}
rw: match, cut out the context, rewritez — wherever it occursReflCongrArg + Inst (+ Trans, Symm)
>>> goal = equation("x + x * n(x) = x + 0")
>>> new, compose = rewrite(B, goal, "H8")
>>> show_equation(new)
'x + 0 = x + 0'
>>> lean(compose(Refl(new[0])))
'congrArg (fun z => x + z) (H8 x)'
rw in Lean works the same way: it cuts out a “motive” fun z => … and assembles the proof from congrArg and Eq.mpr.
prove(B, "add_idem", "x + x = x", calc(
"x + x",
("(x + x) * 1", rw("H6")),
("(x + x) * (x + n(x))", rw("H7")),
("x + x * n(x)", rw("H3")),
("x + 0", rw("H8")),
("x", rw("H5"))))
calc: a chain of equalities, each step proved by its own tactic; Trans chains them all togetherx * 1 is not on the left but on the right — rw rewrites (x + x) * 1 back into x + x and closes the goalprove: the tactic builds the tree, the kernel checks it and adds the theoremcalc chain in which every step is closed by the tactic rw — the proof looks almost identical.lean/Lecture03.lean · Lean 4.33.1
theorem add_idem (x : α) : x + x = x :=
calc x + x = (x + x) * 1 := by rw [H6]
_ = (x + x) * (x + n x) := by rw [H7]
_ = x + x * n x := by rw [H3]
_ = x + 0 := by rw [H8]
_ = x := by rw [H5]
#print axioms add_idem
'add_idem' does not depend on any axioms
HuntingtonAlgebra, that is, hypotheses of the theorem, not axioms of Leancalc and rw with one axiom#print add_idem — the term that Lean’s kernel checks
theorem add_idem : ∀ {α : Type} [inst : HuntingtonAlgebra α] (x : α), x + x = x :=
fun {α} [HuntingtonAlgebra α] x =>
trans
(trans
(trans
(trans (Eq.mpr (id (congrArg (fun _a => x + x = _a) (H6 (x + x)))) (Eq.refl (x + x)))
(Eq.mpr (id (congrArg (fun _a => (x + x) * 1 = (x + x) * _a) (H7 x))) (Eq.refl ((x + x) * 1))))
(Eq.mpr (id (congrArg (fun _a => (x + x) * (x + n x) = _a) (H3 x x (n x)))) (Eq.refl ((x + x) * (x + n x)))))
(Eq.mpr (id (congrArg (fun _a => x + _a = x + 0) (H8 x))) (Eq.refl (x + 0))))
(Eq.mpr (id (congrArg (fun _a => _a = x) (H5 x))) (Eq.refl x))
H6 (x + x), H7 x, H3 x x (n x), H8 x, H5 x. The context is congrArg with the function fun _a => …, and Eq.mpr transfers the proof to the goal.| theorem | equality | calc steps | tree nodes | axioms (as in #print axioms) |
|---|---|---|---|---|
add_idem | x + x = x | 5 | 14 | H3 H5 H6 H7 H8 |
mul_idem | x * x = x | 5 | 14 | H4 H5 H6 H7 H8 |
add_one | x + 1 = 1 | 6 | 16 | H2 H3 H6 H7 |
mul_zero | x * 0 = 0 | 6 | 16 | H1 H4 H5 H8 |
absorb | x + x * y = x | 5 | 14 | H1 H2 H3 H4 H6 H7 |
compl_compl | n(n(x)) = x | 9 | 32 | H1 H2 H4 H6 H7 H8 |
absorb uses the theorem add_one as if it were an axiom: one Inst node instead of its whole proofadd_one we also get H2, H3 and H7
>>> def cheat(): # “I will prove anything”
... def tactic(kernel, goal):
... return Refl(goal[0]) # proof: left = left
... return tactic
...
>>> prove(B, "bogus", "x + y = x", cheat())
kernel.ProofError: bogus: the proof justifies another equation
sorry: it works, but #print axioms shows sorryAx
bl> bl prove idem : x + x = x
⊢ x + x = x
bl> hint
● rw [← H6 (x + x)] solver: proof in 5 steps (x + x) * 1 = x
● rw [← H5 (x + x)] grows x + x + 0 = x
bl> rw [← H6 (x + x), ← H7 x, ← H3, H8, H5]
✓ no goals — type qed and the kernel checks the whole proof
bl> qed
✓ the kernel accepted idem : x + x = x
proof tree: 14 nodes · assumptions (like #print axioms): H3, H5, H6, H7, H8
kernel.py) in the browser, modelled on Peano Lab; qed hands the tree to the kernel{"0": "y"} is not a substitutionconclusion(d) $= (s, t)$, then $s = t$ holds in every algebra in $\mathrm{Mod}(\mathrm{ax}(d))$ — in particular in every Boolean algebra.Proof: induction on the tree $d$; fix $A \in \mathrm{Mod}(\mathrm{ax}(d))$ and a valuation $v$.
| node | the kernel checked | why $[\![s]\!]_v = [\![t]\!]_v$ |
|---|---|---|
Refl(t) | $t$ is a term | $[\![t]\!]_v = [\![t]\!]_v$ |
Symm(p) | the conclusion of $p$ is $(a, b)$ | by the induction hypothesis $[\![a]\!]_v = [\![b]\!]_v$ |
Trans(p, q) | the middles are the same term $b$ | $[\![a]\!]_v = [\![b]\!]_v = [\![c]\!]_v$ |
CongrArg(z, C, p) | $z$ is a variable, $C$ a term | the context lemma |
Inst(G, args) | $G$ is in the environment; its variables are variables | $G$ holds in $A$ (as $\mathrm{ax}(G) \subseteq \mathrm{ax}(d)$) + the instance lemma |
axiom / theorem): the assumption about the environment always holds — for theorems too, since the kernel adds them only after checking. And the list assumptions, our #print axioms, is reliable.hole 1 — the Inst case
the true x * 0 = 0 with the constant 0 declared as a variable
old kernel: Inst("zly", ("x", "y")) ⊢ x * y = y
new kernel: rejects — bad: ('x', '0') are not all variables
$x \cdot y = y$ fails in $\{0, 1\}$ for $x = 0$, $y = 1$
hole 2 — the Trans case
a subclass of str whose == always says “yes” glues x = x to 0 = 0
old kernel: accepts x = 0
new kernel: rejects — not a term: 'x'
the fix in kernel.py
def is_var(self, x):
return type(x) is str and x.isidentifier() and x not in self.signature
# in _add: the variables of a fact must be variables
if not all(map(self.is_var, variables)): # a constant is no variable
raise ProofError(f"{name}: {variables!r} are not all variables")
model: subsets of a set as bit masks
|, $*$ is &, $n(x)$ is the complement, $0$ and $1$ are the empty set and the whole set5000 random proof trees
| kernel | accepted | of which false |
|---|---|---|
| ours | 3241 | 0 |
without checking the middle term in Trans | 5000 | 1219 |
We check truth in the algebra of subsets of a 2-element set. Our kernel rejected 1759 trees.
| risk | in our kernel | in the proof of the Riemann hypothesis |
|---|---|---|
| the statement means something different from what we think (definitions, notation) | we read the axioms and the theorem; the parser is outside the kernel | comparison with the reference file Challenge.lean (Comparator); definitions from Mathlib |
| additional assumptions | assumptions | #print axioms: propext, Classical.choice, Quot.sound |
| a bug in the kernel, the compiler, the hardware | a soundness proof (half a page) and tests | two independently written kernels: Lean’s (C++) and NanoDA (Rust); checks repeated on different computers |
| understanding: why is it true? | — | here the kernel will not help: mathematicians have to read and referee the proof |
lean/KernelSoundness.lean · Lean 4.33.1
theorem soundness {α : Type} (A : Algebra α) (Γ : Env) (hΓ : Model A Γ)
(d : Proof) {l r : Term} (h : check Γ d = some (l, r)) : Holds A l r
'soundness' does not depend on any axioms
'relative_soundness' does not depend on any axioms
'invariant' does not depend on any axioms
check instead of conclusionin the deep dive
in the deep dive
| equality | limit | terms examined | result |
|---|---|---|---|
x + x = x | 8 | 135 | proof: 17 nodes |
x * x = x | 8 | 92 | proof: 17 nodes |
x + 1 = 1 | 8 | 401 | proof: 20 nodes |
n(n(x)) = x | 11 | 369,932 | no proof (about 88 s) |
n(n(x)) = x | 12 | 296,766 | proof: 32 nodes (about 44 s) |
Times from the instructor’s laptop, measured while preparing the lecture. Checking each of these proofs with the kernel: under 0.1 ms.
x + y = y + x, (x + y) + z = x + (y + z),n(n(x) + y) + n(n(x) + n(y)) = xn(n(x + y) + n(x + n(y))) = x?n(C + D) = n(C) for some C, D. By Winker’s lemma: every Robbins algebra is a Boolean algebra.W. McCune, Solution of the Robbins Problem, J. Automated Reasoning 19(3), 263–276 (1997) · www.cs.unm.edu/~mccune/papers/robbins
| searches | proof | checks | |
|---|---|---|---|
| 1996 | EQP (about 8 days) | EQP could not write out a proof object, so its proof guided the program Otter | Otter’s proof object was checked by a separate proof checker |
| 2010 | — | A. Mann’s proof (2003) formalized in Isabelle (M. Wampler-Doty, Archive of Formal Proofs) | Isabelle’s kernel |
| 2026 | L. Alpöge with the Claude model | a Lean archive: 175,187 files | Lean’s kernel and NanoDA |
| today | our solver, our tactics | a tree built from five rules | our kernel (about 100 lines) |
Sources: McCune’s page · AFP: Robbins Conjecture · riemann-rev
n(n(x + y) + n(x + n(y))) = x imply the Huntington equation?C + D = C or with n(C + D) = n(C) is enoughC = n(n(x) + x) + x + x + x, D = n(n(x) + x) + xin the deep dive
Refl, Symm, Trans, CongrArg, Inst — in Lean Eq.refl, Eq.symm, Eq.trans, congrArg and applying a theorem. Our kernel has about a hundred lines and searches for nothing.rw, calc, solver) build trees: pattern matching, context, rewriting. They can make mistakes — the kernel checks anyway.#print axioms.Date and topic of the next lecture: Harmonogram (in Polish) on the course website.
ESC slide overview · S speaker notes · ? keyboard shortcuts