A Ninth Investigation
Build an investigation from nothing, with the laboratory the book has described: a small theorem (6 divides n³ − n), a plausible generalization that fails (k divides nᵏ − n), a claim contract, a Lean proof, an independent computation, five deliberate mistakes, one command, a notebook and a verification. A tutorial, kept apart from the book's eight investigations.
The previous eight chapters took the laboratory apart. This one puts it together, by building a small investigation from the beginning. It is a tutorial: it is registered and run exactly like the book’s eight investigations, but it is listed apart from them, marked as a tutorial in every record, and no approval of it is sought. Its job is to show the whole process on mathematics small enough to hold in your head.
1. Choose a claim, and a tempting stronger one
A good first investigation has a true claim with a short proof, and a plausible stronger claim that is false. The refutation is then as much a part of the investigation as the proof.
The claim. For every natural number n, 6 divides n³ − n.
The reason is short. n³ − n = (n − 1) · n · (n + 1) is a product of three consecutive numbers. One of any two consecutive numbers is even, and one of any three is a multiple of 3, so the product is divisible by 2 and by 3, hence by 6.
The temptation. 2 divides n² − n, and 3 divides n³ − n. Perhaps k divides nᵏ − n for every k? It is true for k = 5 and k = 7 as well. It is false for k = 4: 2⁴ − 2 = 14, and 4 does not divide 14. (The pattern that does hold is Fermat’s little theorem: it is true whenever k is prime. Some composite k satisfy it too, the Carmichael numbers, the smallest being 561. None of that is checked here.)
Chapter 10 — Every, Some, None (Part II, Chapter 1) is the reason to write down the temptation at all. A universal claim that has passed five cases is still only a conjecture, and one witness ends it.
2. Write the contract first
Before any proof exists, write
experiments/investigations/t1-cube-tutorial/investigation.json. The essential
parts, as the file has them:
"tutorial": true,
"contract_status": "tutorial_demonstration",
"evidence_kind": "kernel",
"claim": {
"mathematical_statement": "For every natural number n, 6 divides n³ − n. The
tempting generalization, that k divides nᵏ − n for every k ≥ 1 and every n,
is false.",
"reading": [
"n and k range over the natural numbers 0, 1, 2, …; n³ − n is never
negative, since n³ ≥ n.", …
]
}
The reading’s first sentence is not decoration. In Lean, subtraction on
natural numbers is truncated (Chapter 15 — What a Formal Proposition Says (Part II, Chapter 6)), so n ^ 3 - n would be
the wrong formula if n³ could be smaller than n. It cannot, and the contract
says so.
Then the propositions, each with the exact Lean statement it stands for:
| Id | Role | Lean statement |
|---|---|---|
| T1-P01 | main | ∀ n : Nat, 6 ∣ n ^ 3 - n |
| T1-P02 | witness | ¬ 4 ∣ 2 ^ 4 - 2 |
| T1-P03 | refutation | ¬ ∀ k n : Nat, 1 ≤ k → k ∣ n ^ k - n |
| T1-P04 | context | ∀ n : Nat, 3 ∣ n ^ 3 - n |
and the limits:
- Establishes: the claim, kernel-checked; the generalization false, with k = 4, n = 2 kernel-checked and found independently by computation.
- Does not establish: for which k the generalization does hold; anything beyond a tutorial.
3. Prove it
The proof file is formal/lean/CubeTutorial.lean. It uses core Lean only, no
Mathlib. The main theorem:
theorem six_dvd_cube_sub (n : Nat) : 6 ∣ n ^ 3 - n := by
apply Nat.dvd_of_mod_eq_zero
apply Nat.sub_mod_eq_zero_of_mod_eq
rw [Nat.pow_mod]
have h : n % 6 < 6 := Nat.mod_lt _ (by decide)
generalize n % 6 = r at h ⊢
revert r
decide
Read it as mathematics. To show 6 divides n³ − n it is enough to show that n³ and n leave the same remainder on division by 6. The remainder of n³ depends only on the remainder r of n. So it is enough to check that r³ and r leave the same remainder for each of the six values r = 0, …, 5, and the last line checks exactly those six cases. The refutation is shorter still:
theorem four_not_dvd : ¬ 4 ∣ 2 ^ 4 - 2 := by decide
theorem generalization_false : ¬ ∀ k n : Nat, 1 ≤ k → k ∣ n ^ k - n :=
fun h => four_not_dvd (h 4 2 (by decide))
If the generalization held, it would hold at k = 4, n = 2, contradicting the witness.
4. Check it independently
The computation, src/math_engine/proofs/cube_compute.py, uses Python’s exact
integers and nothing else. It checks the claim for n = 0 to 10 000, and tests
the generalization for k = 1 to 12 and n = 0 to 12. It finds that k = 4, 6, 8,
9, 10 and 12 fail, and that the first counterexample is k = 4, n = 2.
The computation proves nothing about all n. Its value is that it is a different method, written separately, that would disagree with the kernel if the formal statement or the proof had gone wrong in a way the kernel could not see, for instance by proving the right theorem about the wrong expression.
5. Plan how it should fail
Five controls, each with the reason it must fail:
| Control | The mistake | Why it must be refused |
|---|---|---|
lean-wrong-modulus |
6 ∣ becomes 12 ∣ |
12 does not divide 2³ − 2 = 6 |
lean-wrong-witness |
¬ 4 ∣ 14 becomes ¬ 7 ∣ 14 |
7 does divide 14 |
lean-prime-witness |
the counterexample k = 4 becomes k = 3 | 3 is prime and divides 6 |
lean-binding-wrong-statement |
the theorem bound to 12 ∣ n ^ 3 - n |
a stronger statement is not the claim |
compute-claim-all-k |
the computation asked to assert the generalization | it must refuse and name k = 4, n = 2 |
The first control needs care. When the modulus is changed, Lean does not complain at the statement. It complains seven lines later, where the case analysis no longer fits. So that control’s window is widened to 8 lines, and the contract says why (Chapter 23).
6. Register it, and run it
The runner finds investigations through a registry. A tutorial is added in two
places in src/math_engine/proofs/runner.py: the REGISTRY, which maps the
name to its directory, and the TUTORIALS list, which keeps it apart from the
book’s eight. A contract that says "tutorial": true without being in that
list, or the reverse, is refused when it is loaded.
Then the same command as every other chapter:
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 cube-tutorial --out /out/proof-cube-tutorial
Because the file needs only core Lean, it also runs outside the image. In the
book’s repository, after pip install -e . (Part I’s introduction), set
MATH_PROOF_LEAN to a Lean 4.35 lean command and run
math-engine proof cube-tutorial --out out/proof-cube-tutorial. That is how it
was rehearsed while this chapter was written, and again on a fresh clone of the
repository as a reader would:
Tutorial: n³ − n is divisible by 6, and a generalization that fails (T1-CUBE-TUTORIAL)
TUTORIAL: a worked example, not one of the book's eight investigations.
...
Lean (core) 4/4 statements accepted as written in the contract [passed]
Python (exact integer arithmetic): claim_holds_generalization_refuted [passed]
Failure controls 5/5 rejected as expected
Status: checked_unpinned
checked_unpinned is the honest status for a rehearsal: everything passed, on
tools nobody pinned. Inside the image the same run (20261114T001509Z-429adb22)
ended kernel_checked_correspondence_pending, with the same counts. The
correspondence is left for you to judge; the tutorial does not claim it.
7. Read the notebook, and verify it
The notebook opens with a banner saying it is a tutorial. Its identity record shows each declaration and what it rests on:
| System | Declaration | Axioms |
|---|---|---|
| Lean (core) | CubeTutorial.six_dvd_cube_sub |
propext |
| Lean (core) | CubeTutorial.four_not_dvd |
propext |
| Lean (core) | CubeTutorial.generalization_false |
propext |
| Lean (core) | CubeTutorial.three_dvd_cube_sub |
propext |
Only propext appears: the proofs use no classical choice at all. Then check
the record:
math-engine proof cube-tutorial --verify out/proof-cube-tutorial
evidence intact
8. What the investigation establishes
That 6 divides n³ − n for every natural number n, as checked by Lean’s kernel, bound to the statement written in the contract, with a separate computation agreeing on the first ten thousand cases. That the generalization is false, with a witness checked both ways. And, from the controls, that on this occasion the laboratory could have said no to five specific mistakes.
It does not establish which k satisfy the generalization, or anything a reader has not checked about whether the Lean statements say what the English does. That last judgement is the correspondence, and in your own investigations it will be yours.
Try it yourself
- Add a proposition
∀ n : Nat, 30 ∣ n ^ 5 - nto the contract and prove it with the same method. How many cases doesdecidecheck? - Add a control that changes the witness to k = 6, n = 2. Should the refutation still go through? Run it and explain.
- Change the contract’s reading so that it no longer mentions truncated subtraction, and run again. What changes in the status or the record, and what does not? What does that tell you about what the kernel checks?
- Replace the main proof with one that ends in
sorry. What does the run report, and at which check? - Choose your own small claim with a tempting false generalization, and build its contract before writing any proof. Which control was hardest to design?
Worked answers: Chapter 35 — Appendix A: Solutions to the Exercises (Part IV, Appendix A)#chapter-9-a-ninth-investigation.
Evidence record
| Contract | experiments/investigations/t1-cube-tutorial/investigation.json (tutorial: true, tutorial_demonstration); approvals.json empty by design |
| Proof | formal/lean/CubeTutorial.lean (core Lean 4.35.0) |
| Computation | src/math_engine/proofs/cube_compute.py |
| Registration | REGISTRY and TUTORIALS in src/math_engine/proofs/runner.py |
| Tests | tests/test_proofs_consolidation.py (tutorial tests) |
| Run | pinned: 20261114T001509Z-429adb22 in math-env (sha256:74006085…), source commit 17d01d5, kernel_checked_correspondence_pending, filed under t1-cube-tutorial/runner-runs/2026-11-14-pinned/; also rehearsed with core Lean 4.35.0 outside the image |
Further Reading
For deeper study; not sources for the chapter’s claims.
- Greg Wilson, Jennifer Bryan, Karen Cranston, Justin Kitzes, Lex Nederbragt, Tracy K. Teal. “Good enough practices in scientific computing.” PLoS Computational Biology 13(6) (2017), e1005510. DOI. Why read it: Practical, lightweight practices for computational projects, useful when building and documenting a first investigation without turning it into an engineering project.
End of Part III. Part IV is the reference: the environments, the commands, the record formats, the sources, and the solutions to every exercise.