# Lecture 3. How does a computer check a proof? Building a minimal kernel

**Date and room:** see [Harmonogram](https://bnaskrecki.faculty.wmi.amu.edu.pl/math-comp/book/harmonogram.html) (in Polish).

```{admonition} Lecture materials
:class: tip
* [Slides (reveal.js)](https://bnaskrecki.faculty.wmi.amu.edu.pl/math-comp/en/slides_w03.html) — the `S` key opens
  the speaker notes, `Esc` the slide overview. Slides marked “🤿 deep dive” only announce a topic and point to
  the section {doc}`w03_5_poglebienia`.
* [The kernel’s code](https://bnaskrecki.faculty.wmi.amu.edu.pl/math-comp/kernel/) — four files: `kernel.py` (the
  kernel), `syntax.py` (reading and printing terms and proofs), `tactics.py` (tactics and a small solver),
  `boolean.py` (the axioms and the first theorems). The Python 3.10+ standard library is all you need. The
  notebooks of this chapter import these files; to run a notebook on your computer, save them in the same
  folder as the notebook.
* [Boole Lab](https://bnaskrecki.faculty.wmi.amu.edu.pl/math-comp/en/applets/boole-lab.html) — a proof lab in the
  browser, modelled on Peano Lab: the same kernel, tactics written as in Lean, a library of theorems with full
  proofs (from idempotence to associativity, De Morgan’s laws and the Robbins equation), suggestions for the
  next step and export to Lean.
* [Boolean circuits](https://bnaskrecki.faculty.wmi.amu.edu.pl/math-comp/en/applets/boole-obwody.html) — an
  applet for section 3.6: Sh1 as a circuit of six NAND gates, Veroff’s model M1, swapping the order of tests in a
  decision tree, a cycle of implications.
* [The kernel’s soundness proof in Lean](https://bnaskrecki.faculty.wmi.amu.edu.pl/math-comp/lean/KernelSoundness.lean)
  — the theorem of the fourth section, checked by Lean’s kernel.
* Lecture 1, {doc}`§1.4 <w01_4_obliczenie_sprawdzenie_dowod>` — a formal proof seen from the user’s side:
  Gauss’s formula in Peano Lab and in Lean.
```

```{rubric} What this lecture is about
```

On November 20, 2026 Levent Alpöge announced a proof of the Riemann hypothesis, written with the help of the
artificial intelligence system Claude. The proof is not a paper: it is an archive of 175,187 files in the
language of the Lean proof assistant, which no human will read in full. Two independently written checking
programs accepted every step of it, but mathematicians have not refereed it yet. Hence the guiding question
of the lecture: **what exactly does a computer do when it “checks a proof”, and why can we trust it?**

Instead of describing Lean from the outside, we build our own very small checking program, a **kernel**, for
the simplest logic in which real mathematics can be done: equational logic. The theory is Boolean algebra
with Huntington’s eight axioms, and proofs are chains of equalities, just as on paper. We break such a proof
down into atoms, write a kernel that checks these atoms and tactics that build proofs for us. At the end we
ask why the kernel can be trusted and compare searching for a proof with checking it: from the Robbins
problem, solved in 1996 by the program EQP, to the proof of the Riemann hypothesis.

Quantifiers, functions and bound variables — everything that makes Lean’s kernel much larger than ours — we
leave out on purpose. We return to them among the deep dives, in {doc}`§3.5 <w03_5_poglebienia>`.

```{rubric} Outline
```

1. {doc}`w03_1_twierdzenie_i_reguly` — what the computer checked in the proof of the Riemann hypothesis;
   Boolean algebra as an equational theory and its models; the proof of $x + x = x$ on paper and one step
   broken down into atoms; the five rules of equational logic and their names in Lean; a proof as a tree.
2. {doc}`w03_2_jadro` — terms and substitution; the function that reads off the proved equation from a proof
   tree; the environment of axioms and theorems; proofs the kernel rejects; the analogue of the `#print axioms`
   command; the size of the kernel.
3. {doc}`w03_3_taktyki` — pattern matching, the tactics `rw` and `calc`; six theorems from beginning to end;
   a library of theorems; a tactic that cheats, and why the kernel catches it.
4. {doc}`w03_4_zaufanie` — the semantics of equations in algebras; the soundness theorem of the kernel with
   a full proof (three lemmas, induction on the tree, the environment invariant) and the reliability of the
   assumption list; two holes in the first version of the kernel that this proof exposed; the soundness proof
   checked by Lean; tests in models; what the kernel does not guarantee; search versus checking: a small
   solver, the Robbins problem and the program EQP, the proof of the Riemann hypothesis.
5. {doc}`w03_5_poglebienia` — the topics announced on the 🤿 slides: the Robbins problem in detail (Huntington’s
   axioms of 1933, Winker’s conditions, the EQP proof, small Robbins algebras counted by computer); de Bruijn
   indices; completeness and truth tables; associativity from Huntington’s axioms; real kernels.
6. {doc}`w03_6_aksjomaty_i_mediana` — beyond the lecture, for the parts of the Boole Lab library added after it:
   a single axiom (DN1, Sh1) and finite models (Veroff’s model M1); median algebra; Boolean algebra as a ring;
   Boolean derivatives and the product rule; decision diagrams; cycles of implications; other axioms in the Boole
   Lab.

```{rubric} After this lecture you will be able to
```

* point out, in a proof “on paper”, the axiom, the substitution and the context of every step, and write the
  step with the five rules of equational logic;
* read the code of a small kernel, explain what each of its rules checks and justify why the kernel searches
  for nothing;
* distinguish the kernel (small and trusted) from tactics and solvers (large and untrusted) and explain why
  an error in a tactic does not lead to a false theorem;
* prove the soundness theorem of the kernel by induction on the proof tree, point out which checks in the code
  the proof relies on, and test the kernel in models;
* explain what a machine check does not guarantee: the meaning of the statement, the truth of the axioms
  and the correctness of the program itself;
* tell how the Robbins problem was solved and how the announced proof of the Riemann hypothesis was checked
  by machine.

```{rubric} How to work with this chapter
```

Every section is a Jupyter notebook, and all results come from executing the code when the book is built. The
code of the kernel, the tactics and the axioms is in four files (link under “Lecture materials”). The
notebooks show the most important parts of this code with the function `inspect.getsource`, so what you read
is exactly the code that runs. Python 3.10 or newer is enough, with no additional libraries. Every section
ends with exercises; the marks ★, ★★ and ★★★ mean the same as in the lab problem sets.
