← Adversarial Mathematics: From First Principles

Running an Investigation

What happens between typing one command and reading a notebook: the pinned image, the scratch copy of the book, each check in turn, the deliberate mistakes, the record of the environment, the status, and the files that make the run checkable later. And the three kinds of evidence a run can produce.

Every Part I chapter has a “Run it” section built around the same command. This chapter follows that command from start to finish on the Fermat investigation, and then looks at the three different kinds of evidence the eight investigations produce.

The command

$img = docker image inspect math-env --format '{{.Id}}'
docker run --rm --network none -e UV_OFFLINE=1 -e MATHENV_IMAGE_ID=$img `
  -v "${PWD}:/source:ro" -v "${PWD}/out:/out" `
  math-env uv run --offline math-engine proof fermat --out /out/proof-fermat

Each part has a job.

  • math-env is one Docker image holding Lean 4.35.0 with a pinned Mathlib, Rocq 9.0.1 and Python 3.13 with exact package versions. Part IV describes how it is built. Running inside it is what makes a result repeatable on another machine.
  • MATHENV_IMAGE_ID=$img passes the image’s own identifier into the run, so that the record can say exactly which image produced it.
  • --network none and UV_OFFLINE=1 cut the network. Nothing can be fetched during a run, so nothing the run depends on can change underneath it.
  • /source:ro mounts your copy of the book read-only. The run cannot modify the sources it checks.
  • /out is the only place the run writes.

What happens inside

A scratch copy. The image’s entry point copies the book from /source into /workspace and works there. Files git does not track are removed from the copy: a stray script in your folder cannot influence a run. Uncommitted edits to tracked files are kept, and the run records that they were there. The Mathlib build already inside the image is linked in, which is why a run needs no network.

The contract. The runner loads investigation.json, checks its format, and records its sha256 (Chapter 20).

The checks, one by one. For Fermat there are three.

  1. Lean. The runner compiles formal/lean/FermatEuler.lean. Then it compiles a copy with the identity footer of Chapter 20 appended: one binding for each contract statement, and #print axioms for each declaration. It reads the kernel’s output and accepts a declaration only if four things hold: the file compiled, the declaration exists, the binding to the contract’s statement was accepted, and its axioms are within the allowed list.
  2. Rocq. The same, in Rocq: the proof file is compiled, and each binding is compiled as a separate small file that imports it.
  3. Computation. python -m math_engine.proofs.fermat_compute --divisor 641 --cofactor 6700417 runs with exact integers, and must exit 0 and print the verdict refuted.

The controls. Then the nine deliberate mistakes. Each mutation copies the proof file, makes one change, compiles it, and passes only if the kernel rejects it within three lines of the change. A rejection somewhere else does not count, because it would show a broken file rather than a working check. Each binding control asks the kernel to attach a declaration to a wrong statement and must be refused. The computation control asks for 643 and must fail. Chapter 23 of this part is about controls.

The environment. The runner records the image identifier, the hash of the image’s build manifest, the Lean, Rocq, Python and SymPy versions, the source commit, whether any tracked file differed from it, and, file by file, whether the sources it checked are byte-identical to that commit.

The status. From all that, one status line (Chapter 24).

The record. Finally it writes result.json (everything above), a readable notebook.md and notebook.ipynb rendered from it, every log, and SHA256SUMS, which lists the hash of every file. The notebooks quote the sha256 of result.json, so a notebook cannot be swapped for another run’s.

A run is one pass round the book’s loop: the contract states the claim and its assumptions, the checks and controls do the verification and the challenge, and the status and record are the bounded conclusion and the evidence.

The investigation loop in seven stages: claim, assumptions, reasoning, verification, correspondence, evidence, conclusion, with a challenge-or-repair path back to the claim.

The same figure as the book index and Chapter 1. Read the run through it: contract (stages 1–2), checks and controls (stages 3–5), status and record (stages 6–7). Correspondence stays a human judgement; the run records whether one applies.

The Fermat run

The approved Fermat run is experiments/investigations/n1-fermat/kernel-runs/2026-11-13-approved/. It took 55 seconds and printed:

  Lean + Mathlib   7/7 statements accepted as written in the contract   [passed]
  Rocq             4/4 statements accepted as written in the contract   [passed]
  Python + SymPy (exact integer arithmetic): refuted   [passed]
  Failure controls 9/9 rejected as expected

Status: kernel_checked_correspondence_approved

Its directory holds:

result.json          the full record
notebook.md          the readable notebook, bound to result.json by its hash
notebook.ipynb       the same, as a Jupyter notebook
SHA256SUMS           a hash for every file listed here
runs/lean/           accept.log, export.lean (with the footer), export.log
runs/rocq/           one binding file and log per statement
runs/compute/        run.log, record.json
runs/<control>/      the mutated file and the kernel's log, one folder each

result.json records, among much else, image sha256:74006085…, Lean 4.35.0, Rocq 9.0.1, Python 3.13.9, source commit 2e6f2d42, and that every checked file matched that commit.

Checking a run later

math-engine proof fermat --verify out/proof-fermat

This recomputes every hash in SHA256SUMS, reports any file that is missing, changed or not listed, checks that both notebooks quote the hash of result.json, and checks that the claim contract in the repository is still the one the run used. It prints evidence intact or the list of problems. It reruns nothing. It is how a recorded run is checked after it is copied from the machine that produced it into the repository.

Rehearsals and partial runs

The same command works outside the image, with whatever Lean, Rocq and Python are on your machine. The run then ends checked_unpinned: every check may pass, but on tools nobody pinned, so it is a rehearsal, not evidence. The status is decided by is_pinned, which requires the image identifier and the versions the contract names.

--systems lean,python runs a subset. The status is then partial_run, which establishes nothing: a run that skipped Rocq has not shown what the contract says a full run shows.

Three kinds of evidence

The eight investigations do not all produce the same kind of evidence, and the runner does not pretend they do. Each contract declares an evidence kind, and the status begins with the kind of evidence this execution produced.

Kernel evidence: proofs checked in this run. Fermat, Abel’s finite sum, Simpson and Gabriel run Lean (and, except Gabriel, Rocq) on their proof files in the pinned image. Gabriel’s v2 run (20261113T233641Z-bf73f1ee) accepted 6 of 6 statements and rejected 5 of 5 controls. The wrong-theorem demonstration is also kernel evidence, of a smaller kind: it runs core Lean 4.35 (no Mathlib) on its four case files, and the run records that version separately. Its status is kernel_checked_… because Lean really ran. What the demonstration shows, though, is a failure of the name-only attachment gate, not of the kernel: Lean accepted each file correctly in every case.

Computed evidence: an exact computation, no proof kernel. Kempe’s investigation runs a graph search on the transcribed map, and the B3–Gout control must change its verdict. Its run (20261113T233009Z-4b4a1765) ended computed_correspondence_pending. The word computed says that no proof assistant was involved. What would make the result more than a computation is the correspondence: that the transcription is Heawood’s map.

Historical evidence: an earlier kernel run, imported and verified. Two investigations depend on kernel runs that cannot reasonably be repeated by a reader’s command.

  • Haraux. The full MATH-INV-02F procedure checks 84 declarations in Lean and Rocq through twenty stages. The reader’s run (20261113T232711Z-ca0a4a56) does not repeat it. It imports the recorded run read-only, checks all 78 of its files against the manifest pinned in the contract, and then recomputes the event ledger exactly at two speeds.
  • Grasshopper. The audited artifact needs Lean 4.28, which is not in math-env and is kept in its own image. The reader’s run (20261113T232915Z-a62abc70) imports the 2026-11-13 audit, checks its 7 files, and re-reads the five kernel logs to re-derive every finding, without using the audit’s own summary.

Both are imported records, not fresh kernel runs. The notebook says, in bold, No kernel was run in this execution. An imported run is never reported as kernel_checked: a test enforces that. The full re-execution paths still exist, and each contract names them.

Evidence kind Status prefix What it means
kernel kernel_checked… a kernel ran in this execution and accepted the formal statements
computation computed… an exact computation ran; no proof kernel was involved
historical historical_verified… an earlier kernel record was imported and verified; no kernel ran

A recorded run also says whether a correspondence record applies. The suffix changes only when a valid approval exists; the evidence kind never changes.

What a run does not do

A run does not decide what its result means. It checks the contract’s statements, records what happened, and stops. It does not decide whether the formal statement captures the claim, and it does not assess the mathematical quality of the work. A run that has passed every machine check has done everything a machine can do for that contract.

Try it yourself

  1. Run Kempe twice, once inside the image and once with plain Python (python -m math_engine proof kempe). Compare the two status lines. Which function decides the difference?
  2. After a run, add a blank line to notebook.md and run --verify. Then restore it and delete runs/compute/run.log. What does --verify report each time?
  3. Run math-engine proof fermat --systems lean,python. What status do you get, and why is that the right answer even though every check passed?
  4. Put an untracked file formal/lean/Extra.lean in your copy of the book and run Fermat in the image. Is it in /workspace during the run? Where in the image’s entry point is that decided?
  5. Look at Haraux’s run record. Which part of it was produced on 2026-11-13 by the 02F procedure, and which part by the reader’s run?

Worked answers: Chapter 35 — Appendix A: Solutions to the Exercises (Part IV, Appendix A)#chapter-2-running-an-investigation.

Evidence record

Entry point docker/mathenv (prepare_workspace)
Runner run_investigation, lean_kernel, rocq_kernel, computation, pinned_files, archive, environment, is_pinned, write_outputs, write_sums, verify_output in src/math_engine/proofs/runner.py
Fermat run n1-fermat/kernel-runs/2026-11-13-approved/, run 20261113T161233Z-9c5ae090
Reader runs (consolidation) */runner-runs/2026-11-13-pinned/ for haraux, wrong-theorem, grasshopper, kempe; p08-gabriel/runner-runs/2026-11-13-v2-pinned/
Tests tests/test_proofs_fermat.py, tests/test_proofs_consolidation.py

Further Reading

For deeper study; not sources for the chapter’s claims.

  1. Roger D. Peng. “Reproducible Research in Computational Science.” Science 334(6060) (2011), 1226–1227. DOI. Why read it: A concise statement of the reproducibility standard that the chapter’s run records and pinned environment are designed to meet.
  2. Geir Kjetil Sandve, Anton Nekrutenko, James Taylor, Eivind Hovig. “Ten Simple Rules for Reproducible Computational Research.” PLoS Computational Biology 9(10) (2013), e1003285. DOI. Why read it: Practical rules for making computational results reproducible, directly applicable to the run directory, pinned inputs and recorded environment.

Next in Part III: Chapter 22, how the laboratory knows that the theorem it checked is the theorem it meant.