Writing Your Own Investigation
The files to create, the one registry entry to add, the rules a contract must satisfy, how to design controls that fail for the right reason, and the checks to run before trusting the result. A reference companion to Part III, chapter 9.
Chapter 28 — A Ninth Investigation (Part III, Chapter 9) builds the tutorial step by step. This is the checklist.
Files to create
| File | Content | Example |
|---|---|---|
experiments/investigations/<dir>/investigation.json |
the contract (Chapter 31) | t1-cube-tutorial/investigation.json |
experiments/investigations/<dir>/approvals.json |
{"schema": "math-proof-approvals/1", "investigation": "<id>", "rule": "…", "approvals": []} |
t1-cube-tutorial/approvals.json |
formal/lean/<File>.lean (and/or formal/rocq/<File>.v) |
the proofs, in a namespace; core-Lean files start with import Lean |
formal/lean/CubeTutorial.lean |
src/math_engine/proofs/<name>_compute.py |
an independent computation printing a JSON object with a verdict; exit 0 when it agrees, non-zero otherwise |
cube_compute.py |
The registry entry
In src/math_engine/proofs/runner.py, add "<name>": "experiments/investigations/<dir>"
to REGISTRY. For a tutorial, also add "<name>" to TUTORIALS and set
"tutorial": true in the contract; the runner refuses a mismatch. Optionally add
a label for the computation to COMPUTATION_LABELS.
Rules a contract must satisfy
Enforced when the contract is loaded (load_investigation):
schemaismath-proof-investigation/1; check and control ids are unique;- every proposition has at least one of
lean,rocq,computation,archive; evidence_kindiskernel,computationorhistorical, and ahistoricalcontract imports at least one archive;tutorialis true exactly when the name is inTUTORIALS.
Enforced by the test suite (tests/test_proofs_consolidation.py):
does_not_establish is non-empty, and every pinned file and archive matches.
Conventions the code cannot enforce:
- every
lean.statementis exactly what you mean, written in full before the proof, not copied from the proof file afterwards; toolchain_expectednames the versions you will run in the image (e.g.{"lean": "4.35.0"});establishessays no more than the checks support.
Designing controls
| Rule | Why |
|---|---|
| Each control changes one thing, chosen so that the result must change | otherwise it tests nothing |
A mutation’s find text occurs exactly once |
the run stops otherwise |
Expect the kernel’s error at the changed line; widen error_window only when the proof necessarily fails later, and say why in why |
locality guards against a file broken elsewhere |
| Include one binding control to a nearby wrong statement | tests statement identity |
| Every computation control names the exact words a real refusal prints, not just an exit code | a crash also exits non-zero |
| Think about what the control does not test | e.g. a different witness may break the proof without being a mathematical mistake |
Before trusting the result
- Run the computation on its own and read its output.
- Run
math-engine proof <name>outside the image if you can, and read every control’sobservedfield in the notebook. - Make the proof deliberately wrong (for instance
sorry) and confirm the run fails, and that controls which could no longer fail are reported as failed. - Run
pytest -q tests/test_proofs_consolidation.py: every contract in the registry is loaded and its pins checked. - Run in the image; then
--verifythe output. - Read the Lean statements against your English claim once more. That reading is the correspondence, and it is yours.
For the tutorial, steps 1 to 5 are recorded: the computation, the rehearsal,
the sorry experiment in the Part III walkthrough, the tests, and the pinned
run t1-cube-tutorial/runner-runs/2026-11-14-pinned/.
Appendices: A, solutions to the exercises; B, sources; C, the earlier edition and engine; D, notation.