Build the ninth investigation: 6 divides n³ − n
The tutorial investigation's core-Lean file: the claim, its tempting generalization, the witness at k = 4, and what each rests on.
The ninth investigation is a tutorial: choose a claim and a tempting stronger one, write the contract first, prove it, check it independently, plan how it should fail. The claim is that 6 divides n³ − n for every natural number n; the tempting generalization is that k divides nᵏ − n for every k ≥ 1. This is its pinned core-Lean file, with a few reader checks added at the end.
Run it
Save this as cube_tutorial.lean and run lean cube_tutorial.lean with Lean 4.35.0 (core Lean only, no Mathlib), or paste it into the Lean 4 web editor at live.lean-lang.org
.
/-
Tutorial investigation T1 (Part III, chapter 9): not one of the book's
eight investigations. Core Lean only: no Mathlib is imported. `import Lean`
is needed by the runner's identity footer, not by the proofs.
Claim: for every natural number n, 6 divides n³ − n.
Tempting generalization: for every k ≥ 1 and every n, k divides nᵏ − n.
It holds for k = 1, 2, 3, 5, 7, … but fails at k = 4, n = 2.
-/
import Lean
namespace CubeTutorial
/-- T1-P01: 6 divides n³ − n for every natural number n. -/
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
/-- T1-P02: the witness. 2⁴ − 2 = 14, and 4 does not divide 14. -/
theorem four_not_dvd : ¬ 4 ∣ 2 ^ 4 - 2 := by decide
/-- T1-P03: the generalization is false. -/
theorem generalization_false : ¬ ∀ k n : Nat, 1 ≤ k → k ∣ n ^ k - n :=
fun h => four_not_dvd (h 4 2 (by decide))
/-- T1-P04: the prime case k = 3, one reason the generalization is tempting. -/
theorem three_dvd_cube_sub (n : Nat) : 3 ∣ 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 % 3 < 3 := Nat.mod_lt _ (by decide)
generalize n % 3 = r at h ⊢
revert r
decide
end CubeTutorial
-- Reader's additions (not part of the pinned file formal/lean/CubeTutorial.lean):
#print axioms CubeTutorial.six_dvd_cube_sub
#print axioms CubeTutorial.generalization_false
#eval (List.range 12).map (fun n => (n ^ 3 - n) % 6) -- all 0
#eval (List.range 6).map (fun k => (2 ^ k - 2) % max k 1) -- k ∣ 2^k − 2 fails first at k = 4Expected outcome
'CubeTutorial.six_dvd_cube_sub' depends on axioms: [propext]
'CubeTutorial.generalization_false' depends on axioms: [propext]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 2, 0]Lean accepts the claim, the k = 3 case and the refutation of the
generalization, whose witness is k = 4, n = 2: 2⁴ − 2 = 14 is not divisible by
4. Each rests only on propext. The two evaluations show the claim on 0–11
and the generalization failing first at k = 4.
Mechanism and limitations
Documented: Chapter 28 of the book sets out the mathematics; this program is a self-contained demonstration of it, not one of the laboratory’s recorded investigations.
Observed: the output above, produced by running the program exactly as shown.
Not shown:
- The reader checks at the end are not part of the pinned file
formal/lean/CubeTutorial.lean. - The tutorial’s runner record, controls and contract are in the repository (Part III, chapter 9); this file is only its proofs.
Challenge this result
Copy this into the AI assistant of your choice, or work through it yourself. Check any finding against the recorded evidence.
Examine the tutorial's claim and its generalization. Prove 6 ∣ n³ − n by hand,
explain why k ∣ nᵏ − n holds for prime k (Fermat's little theorem) and fails
at k = 4, and design two failure controls the investigation should include.
Then choose a claim of your own and write its contract before its proof.
Chapter: https://programmer.ie/books/math/28-chapter/
Example: https://programmer.ie/examples/math/28-chapter/
Program: https://github.com/ernanhughes/math/blob/main/notebooks/math/programs/28-ninth-investigation.lean
Distinguish what the record shows from what you infer. If you cannot open a link, ask me for the material; do not invent it.Canonical source and the program .
Understand this example
Copy this prompt into your AI tool. No code runs here.
Apply this example
Copy this prompt into your AI tool. No code runs here.