import Init /- GcdStratum.lean — machine-checked formalisation of the gcd stratum criterion at pattern level (Cycle 21, lens1/CYCLE21_PROOFS.md, Attempt (i): (α) emptiness + (β-pat) pattern-level nonemptiness). Core Lean only (`import Init`; no Mathlib, no Batteries/Std — the general `Odd` predicate and the generic `dvd_trans`/`dvd_rfl` lemmas live in Batteries, so oddness and the two dvd facts are defined/proved here directly; see `OddN` below). Faithful translation of the pilot definitions: - `N` : the pilot's `N := p - 1`, here an arbitrary natural (the Cycle 21 proof uses no per-shift feature). - forced logs : a list `F = [f₁, …, f_s]` of naturals. - `mgcd F N` : `gcd(f₁, …, f_s, N)`, with value `N` when `s = 0` (pilot convention) — the fold gives exactly that. - a pattern : a list `L = [e₁, …, e_k]` of naturals (multiset of logs, represented as a list). - `mgcd L N` : `gcd(e₁, …, e_k, N)` — the pilot's `m(L)`, the same fold as for `G`. - genuine-admissible (pilot's actual definition, containment only): every forced log occurs in `L`, and some `e ∈ L` is odd. -/ /-- Oddness, in the pilot's elementary sense: `n = 2k + 1` for some `k`. (Core Lean has no general `Odd` predicate; this is its unfolding for naturals.) -/ def OddN (n : Nat) : Prop := ∃ k, n = 2 * k + 1 /-- Evenness, companion to `OddN`. -/ def EvenN (n : Nat) : Prop := ∃ k, n = 2 * k /-- Joint gcd of a list of logs together with `N`: `mgcd [a₁, …, a_k] N = gcd(a₁, gcd(a₂, …, gcd(a_k, N)…))`. On the empty list this is `N`, matching the pilot's `G := N when s = 0` convention. -/ def mgcd (L : List Nat) (N : Nat) : Nat := L.foldr Nat.gcd N /-- Genuine-admissibility (containment only, as pinned in the pilot): every forced log occurs in the pattern, and the pattern contains an odd log (an NR residue). -/ def GenuineAdm (F L : List Nat) : Prop := (∀ f ∈ F, f ∈ L) ∧ ∃ e ∈ L, OddN e /-! ### Elementary dvd / parity helpers (core Lean lacks the generic versions; these are proved from the definitions). -/ theorem dvd_refl' (a : Nat) : a ∣ a := ⟨1, by simp⟩ theorem dvd_trans' {a b c : Nat} (h₁ : a ∣ b) (h₂ : b ∣ c) : a ∣ c := by rcases h₁ with ⟨x, hx⟩ rcases h₂ with ⟨y, hy⟩ exact ⟨x * y, by rw [hy, hx, Nat.mul_assoc]⟩ theorem even_or_oddN (n : Nat) : EvenN n ∨ OddN n := by induction n with | zero => exact Or.inl ⟨0, rfl⟩ | succ k ih => rcases ih with ⟨r, hr⟩ | ⟨r, hr⟩ · exact Or.inr ⟨r, by omega⟩ · exact Or.inl ⟨r + 1, by omega⟩ theorem even_mul_of_even {d c : Nat} (h : EvenN d) : EvenN (d * c) := by rcases h with ⟨r, hr⟩ exact ⟨r * c, by rw [hr]; exact Nat.mul_assoc 2 r c⟩ theorem oddN_of_dvd_oddN {d e : Nat} (h : d ∣ e) (he : OddN e) : OddN d := by rcases even_or_oddN d with hd | hd · -- if `d` were even, `e = d * c` would be even, contradiction rcases h with ⟨c, hc⟩ rcases even_mul_of_even hd with ⟨s, hs⟩ rcases he with ⟨k, hk⟩ have hcontra : 2 * s = 2 * k + 1 := by rw [← hs, ← hc, hk] omega · exact hd /-! ### The three gcd facts the Cycle 21 proof uses. -/ /-- The joint gcd divides every element of the list. -/ theorem mgcd_dvd_of_mem {L : List Nat} {N a : Nat} (h : a ∈ L) : mgcd L N ∣ a := by induction L with | nil => simp at h | cons b t ih => simp only [List.mem_cons] at h unfold mgcd simp only [List.foldr_cons] rcases h with rfl | h · exact Nat.gcd_dvd_left _ _ · exact dvd_trans' (Nat.gcd_dvd_right _ _) (ih h) /-- The joint gcd divides `N`. -/ theorem mgcd_dvd_base {L : List Nat} {N : Nat} : mgcd L N ∣ N := by induction L with | nil => exact dvd_refl' _ | cons b t ih => unfold mgcd simp only [List.foldr_cons] exact dvd_trans' (Nat.gcd_dvd_right _ _) ih /-- Anything dividing every element of the list and `N` divides the joint gcd. -/ theorem dvd_mgcd {L : List Nat} {N d : Nat} (hL : ∀ a ∈ L, d ∣ a) (hN : d ∣ N) : d ∣ mgcd L N := by induction L with | nil => exact hN | cons b t ih => unfold mgcd simp only [List.foldr_cons] exact Nat.dvd_gcd (hL b (by simp)) (ih (fun a ha => hL a (by simp [ha]))) /-! ### The criterion itself. -/ /-- **(α) Emptiness, divisibility part** (Cycle 21, Attempt (i)(α)): for every genuine-admissible pattern `L` at any shift, `m(L) ∣ G`. -/ theorem alpha_dvd {F L : List Nat} {N : Nat} (h : GenuineAdm F L) : mgcd L N ∣ mgcd F N := dvd_mgcd (fun f hf => mgcd_dvd_of_mem (h.1 f hf)) mgcd_dvd_base /-- **(α) Emptiness, oddness part** (Cycle 21, Attempt (i)(α)): for every genuine-admissible pattern `L`, `m(L)` is odd. Hence no genuine stratum exists outside the odd divisors of `G`. -/ theorem alpha_odd {F L : List Nat} {N : Nat} (h : GenuineAdm F L) : OddN (mgcd L N) := by rcases h.2 with ⟨e, heL, heodd⟩ exact oddN_of_dvd_oddN (mgcd_dvd_of_mem heL) heodd /-- **(β-pat) Pattern-level nonemptiness** (Cycle 21, Attempt (i)(β-pat)): for every odd `d ∣ G` there is a genuine-admissible pattern with `m = d` — namely the forced logs together with one further log equal to `d` itself. -/ theorem beta_pat {F : List Nat} {N d : Nat} (hdodd : OddN d) (hdG : d ∣ mgcd F N) : GenuineAdm F (F ++ [d]) ∧ mgcd (F ++ [d]) N = d := by constructor · constructor · intro f hf exact List.mem_append_left _ hf · exact ⟨d, by simp, hdodd⟩ · apply Nat.dvd_antisymm · -- the joint gcd divides `d`, since `d` occurs in the pattern exact mgcd_dvd_of_mem (by simp) · -- `d` divides the joint gcd: it divides every forced log -- (through `G`), it divides `d`, and it divides `N` (through `G`) apply dvd_mgcd · intro a ha simp only [List.mem_append, List.mem_singleton] at ha rcases ha with ha | rfl · exact dvd_trans' hdG (mgcd_dvd_of_mem ha) · exact dvd_refl' _ · exact dvd_trans' hdG mgcd_dvd_base /-- **The gcd stratum criterion at pattern level** (Cycle 21, Attempt (i), combined form): the strata realised by genuine-admissible patterns are exactly the odd divisors of `G = gcd(forced logs, N)`. At a no-forced shift (`F = []`) `G = N`, so these are exactly the odd divisors of `N`. -/ theorem strata_iff {F : List Nat} {N d : Nat} : (∃ L, GenuineAdm F L ∧ mgcd L N = d) ↔ OddN d ∧ d ∣ mgcd F N := by constructor · rintro ⟨L, hL, rfl⟩ exact ⟨alpha_odd hL, alpha_dvd hL⟩ · rintro ⟨hdodd, hdG⟩ exact ⟨F ++ [d], (beta_pat hdodd hdG).1, (beta_pat hdodd hdG).2⟩ #print axioms alpha_dvd #print axioms alpha_odd #print axioms beta_pat #print axioms strata_iff