/- PassSubtractionLaws.lean Universal Structural Theory of Multi-Pass and Single-Pass Subtraction Games, Injective-Phase Pass-State Rigidity, and Short-Interval Three-Element Classification Extending Richard M. Low (arXiv:2610.25829, Oct 2026; arXiv:2611.30147, Nov 23, 2026) and Urban Larsson–Hikaru Manabe–Ryohei Miyadera (arXiv:2605.14321, May 2026). Main results verified in this file (100% self-contained, Mathlib only): 1. `kPass_parity_collapse`: Universal k-pass parity collapse G_{p+2}(S, n) = G_p(S, n) for EVERY finite subtraction set S and ALL p, n ∈ ℕ. 2. `nimVal_scale` & `passNim_scale`: Universal scaling invariance for S.image (a * ·). 3. `shift_lock_in`: Universal Shift Lock-In — if h_S(n) = g_S(n - s₀) on a window of length max(S) for some s₀ ∈ S, then h_S(n) = g_S(n - s₀) for all n ≥ N₀. 4. `xor1_lock_in`: Universal XOR-1 Lock-In — if h_S(n) = g_S(n) ^^^ 1 on a window of length max(S), then h_S(n) = g_S(n) ^^^ 1 for all n ≥ N₀. 5. `passRigid_of_purePeriodic_and_injective_phase`: Universal Injective-Phase Pass-State Rigidity Theorem (strictly generalizing Low's translation rigidity to ANY injective function φ : ℕ → ℕ, including both translations and shifted XOR-1 phases), plus automatic min-preservation (`min_eq_of_passNim_eq`). 6. `short_interval_three_pass_classification` & `short_interval_three_passRigid`: Complete closed-form single-pass Sprague–Grundy classification, exact preperiod min(c + 2a, 4a), exact least period c + a, eventual translation h(n) = g(n - a), and complete pass-state rigidity for ALL 3-element sets {a, b, c} with 2 ≤ a < b ≤ 2a and b < c < a + b. -/ import Mathlib namespace PassSubtractionLaws open Finset /-! ### 1. General Finite-Set `mex` API -/ lemma exists_notMem_finset (A : Finset ℕ) : ∃ m : ℕ, m ∉ A := by by_cases h : A.Nonempty · refine ⟨A.max' h + 1, fun hmem => ?_⟩ have := Finset.le_max' A _ hmem omega · exact ⟨0, fun hmem => h ⟨0, hmem⟩⟩ /-- The minimum excluded natural number of a finite set `A : Finset ℕ`. -/ def mex (A : Finset ℕ) : ℕ := Nat.find (exists_notMem_finset A) lemma mex_notMem (A : Finset ℕ) : mex A ∉ A := Nat.find_spec (exists_notMem_finset A) lemma mem_of_lt_mex {A : Finset ℕ} {m : ℕ} (hm : m < mex A) : m ∈ A := by_contra (Nat.find_min (exists_notMem_finset A) hm) lemma mex_eq_iff {A : Finset ℕ} {v : ℕ} : mex A = v ↔ v ∉ A ∧ ∀ m < v, m ∈ A := by unfold mex rw [Nat.find_eq_iff] constructor · rintro ⟨hv, hlt⟩ exact ⟨hv, fun m hm => by_contra (hlt m hm)⟩ · rintro ⟨hv, hlt⟩ exact ⟨hv, fun m hm hnot => hnot (hlt m hm)⟩ lemma mex_empty : mex ∅ = 0 := by rw [mex_eq_iff] exact ⟨by simp, fun m hm => by omega⟩ lemma mex_le_card (A : Finset ℕ) : mex A ≤ A.card := by have hsub : Finset.range (mex A) ⊆ A := by intro m hm exact mem_of_lt_mex (Finset.mem_range.mp hm) simpa [Finset.card_range] using Finset.card_le_card hsub lemma mex_insert_of_ne {A : Finset ℕ} {x : ℕ} (hx : x ≠ mex A) : mex (insert x A) = mex A := by rw [mex_eq_iff] refine ⟨?_, fun m hm => Finset.mem_insert_of_mem (mem_of_lt_mex hm)⟩ rw [Finset.mem_insert] push Not exact ⟨hx.symm, mex_notMem A⟩ lemma mex_union_of_notMem {A B : Finset ℕ} (hB : mex A ∉ B) : mex (A ∪ B) = mex A := by rw [mex_eq_iff] refine ⟨?_, fun m hm => Finset.mem_union_left B (mem_of_lt_mex hm)⟩ rw [Finset.mem_union] push Not exact ⟨mex_notMem A, hB⟩ lemma mex_eq_of_subset_of_notMem {A B : Finset ℕ} (hsub : A ⊆ B) (hnot : mex A ∉ B) : mex B = mex A := by rw [mex_eq_iff] exact ⟨hnot, fun m hm => hsub (mem_of_lt_mex hm)⟩ /-! ### 2. Bitwise XOR-1 Arithmetic & Universal `mex_image_xor1` Lemma -/ lemma two_mul_xor_one (k : ℕ) : (2 * k) ^^^ 1 = 2 * k + 1 := by apply Nat.eq_of_testBit_eq intro i rw [Nat.testBit_xor] cases i with | zero => simp [Nat.testBit_zero] | succ i => have h1 : (1 : ℕ).testBit (i + 1) = false := by simp [Nat.testBit_succ] rw [h1, Bool.xor_false, Nat.testBit_succ, Nat.testBit_succ] congr 1; omega lemma xor_one_eq (n : ℕ) : n ^^^ 1 = if n % 2 = 0 then n + 1 else n - 1 := by rcases Nat.even_or_odd n with ⟨k, rfl⟩ | ⟨k, rfl⟩ · have hmod : (k + k) % 2 = 0 := by omega rw [if_pos hmod, show k + k = 2 * k by omega, two_mul_xor_one] · have hmod : (2 * k + 1) % 2 ≠ 0 := by omega rw [if_neg hmod, show 2 * k + 1 - 1 = 2 * k by omega, ← two_mul_xor_one k, Nat.xor_assoc, Nat.xor_self, Nat.xor_zero] lemma xor_one_involutive (n : ℕ) : (n ^^^ 1) ^^^ 1 = n := by rw [Nat.xor_assoc, Nat.xor_self, Nat.xor_zero] lemma xor_one_injective : Function.Injective (fun n : ℕ => n ^^^ 1) := fun a b h => by have := congrArg (· ^^^ 1) h simpa [xor_one_involutive] using this lemma xor_one_ne_self (n : ℕ) : n ^^^ 1 ≠ n := by rw [xor_one_eq] split_ifs <;> omega /-- **Key Algebraic Lemma:** For ANY finite set `A : Finset ℕ`, `mex (insert (mex A) (A.image (· ^^^ 1))) = mex A ^^^ 1`. -/ theorem mex_image_xor1 (A : Finset ℕ) : mex (insert (mex A) (A.image (· ^^^ 1))) = mex A ^^^ 1 := by set v := mex A rw [mex_eq_iff] constructor · rw [Finset.mem_insert, Finset.mem_image] push Not refine ⟨xor_one_ne_self v, fun x hx hEq => ?_⟩ have hxv : x = v := xor_one_injective hEq rw [hxv] at hx exact mex_notMem A hx · intro m hm rw [Finset.mem_insert, Finset.mem_image] by_cases hmv : m = v · exact Or.inl hmv · right refine ⟨m ^^^ 1, ?_, xor_one_involutive m⟩ apply mem_of_lt_mex rw [xor_one_eq] at hm ⊢ split_ifs at hm ⊢ <;> omega /-! ### 3. General Subtraction Games & `k`-Pass Sprague–Grundy Sequences -/ /-- The finite set of positive moves in `S` available from heap size `n`. -/ def availMoves (S : Finset ℕ) (n : ℕ) : Finset ℕ := S.filter (fun s => 0 < s ∧ s ≤ n) /-- Predicate asserting that every element of `S` is positive. -/ def IsPosMoveSet (S : Finset ℕ) : Prop := ∀ s ∈ S, 0 < s /-- Ordinary (pass-free) Sprague–Grundy sequence `g_S : ℕ → ℕ` for any finite `S : Finset ℕ`. -/ def nimVal (S : Finset ℕ) : ℕ → ℕ := WellFounded.fix Nat.lt_wfRel.wf fun n ih => mex ((availMoves S n).attach.image fun ⟨s, hs⟩ => ih (n - s) (by have h := (Finset.mem_filter.mp hs).2 exact Nat.sub_lt (by omega) h.1)) theorem nimVal_eq (S : Finset ℕ) (n : ℕ) : nimVal S n = mex ((availMoves S n).image (fun s => nimVal S (n - s))) := by conv_lhs => unfold nimVal rw [WellFounded.fix_eq] congr 1 ext y simp only [Finset.mem_image, Finset.mem_attach, true_and, Subtype.exists] constructor · rintro ⟨s, hs, rfl⟩; exact ⟨s, hs, rfl⟩ · rintro ⟨s, hs, rfl⟩; exact ⟨s, hs, rfl⟩ lemma nimVal_ne_sub {S : Finset ℕ} {s n : ℕ} (hs : s ∈ S) (hs0 : 0 < s) (hsn : s ≤ n) : nimVal S (n - s) ≠ nimVal S n := by intro heq have hmem : nimVal S n ∈ (availMoves S n).image (fun t => nimVal S (n - t)) := by rw [Finset.mem_image] exact ⟨s, Finset.mem_filter.mpr ⟨hs, hs0, hsn⟩, heq⟩ rw [nimVal_eq S n] at hmem exact mex_notMem _ hmem lemma nimVal_le_card (S : Finset ℕ) (n : ℕ) : nimVal S n ≤ S.card := by rw [nimVal_eq] calc mex ((availMoves S n).image (fun s => nimVal S (n - s))) ≤ ((availMoves S n).image (fun s => nimVal S (n - s))).card := mex_le_card _ _ ≤ (availMoves S n).card := Finset.card_image_le _ ≤ S.card := Finset.card_filter_le _ _ lemma nimVal_eq_zero_of_lt {S : Finset ℕ} {n : ℕ} (h : ∀ s ∈ S, 0 < s → n < s) : nimVal S n = 0 := by rw [nimVal_eq] have hemp : availMoves S n = ∅ := by rw [Finset.eq_empty_iff_forall_notMem] intro s hs have h2 := (Finset.mem_filter.mp hs).2 have := h s (Finset.mem_filter.mp hs).1 h2.1 omega rw [hemp, Finset.image_empty, mex_empty] /-- The `p`-pass Sprague–Grundy sequence `G_p(S, n)`: - `p = 0`: ordinary pass-free `nimVal S n`; - `p + 1`: players may subtract any `s ∈ S` with `0 < s ≤ n`, OR use a pass (moving to `(n, p)`) whenever `(n)` is non-terminal (i.e., `(availMoves S n).Nonempty`). -/ def kPassNim (S : Finset ℕ) : ℕ → ℕ → ℕ | 0 => nimVal S | p + 1 => WellFounded.fix Nat.lt_wfRel.wf fun n ih => let subOpts := (availMoves S n).attach.image fun ⟨s, hs⟩ => ih (n - s) (by have h := (Finset.mem_filter.mp hs).2 exact Nat.sub_lt (by omega) h.1) let opts := if (availMoves S n).Nonempty then insert (kPassNim S p n) subOpts else subOpts mex opts /-- The single-pass Sprague–Grundy sequence `h_S = G_1(S, ·)`. -/ def passNim (S : Finset ℕ) (n : ℕ) : ℕ := kPassNim S 1 n theorem kPassNim_zero (S : Finset ℕ) (n : ℕ) : kPassNim S 0 n = nimVal S n := rfl theorem kPassNim_succ_eq (S : Finset ℕ) (p n : ℕ) : kPassNim S (p + 1) n = mex (let subOpts := (availMoves S n).image (fun s => kPassNim S (p + 1) (n - s)) if (availMoves S n).Nonempty then insert (kPassNim S p n) subOpts else subOpts) := by conv_lhs => unfold kPassNim rw [WellFounded.fix_eq] have hsub : ((availMoves S n).attach.image fun ⟨s, hs⟩ => WellFounded.fix Nat.lt_wfRel.wf (fun n ih => let subOpts := (availMoves S n).attach.image fun ⟨s, hs⟩ => ih (n - s) (by have h := (Finset.mem_filter.mp hs).2; exact Nat.sub_lt (by omega) h.1) let opts := if (availMoves S n).Nonempty then insert (kPassNim S p n) subOpts else subOpts mex opts) (n - s)) = (availMoves S n).image (fun s => kPassNim S (p + 1) (n - s)) := by ext y simp only [Finset.mem_image, Finset.mem_attach, true_and, Subtype.exists] constructor · rintro ⟨s, hs, rfl⟩; exact ⟨s, hs, rfl⟩ · rintro ⟨s, hs, rfl⟩; exact ⟨s, hs, rfl⟩ dsimp only rw [hsub] theorem passNim_eq (S : Finset ℕ) (n : ℕ) : passNim S n = mex (let subOpts := (availMoves S n).image (fun s => passNim S (n - s)) if (availMoves S n).Nonempty then insert (nimVal S n) subOpts else subOpts) := kPassNim_succ_eq S 0 n lemma kPassNim_succ_ne_prev {S : Finset ℕ} {p n : ℕ} (hne : (availMoves S n).Nonempty) : kPassNim S (p + 1) n ≠ kPassNim S p n := by intro heq have hmem : kPassNim S (p + 1) n ∈ (if (availMoves S n).Nonempty then insert (kPassNim S p n) ((availMoves S n).image (fun s => kPassNim S (p + 1) (n - s))) else (availMoves S n).image (fun s => kPassNim S (p + 1) (n - s))) := by rw [if_pos hne, Finset.mem_insert] exact Or.inl heq rw [kPassNim_succ_eq S p n] at hmem exact mex_notMem _ hmem lemma passNim_ne_nimVal {S : Finset ℕ} {n : ℕ} (hne : (availMoves S n).Nonempty) : passNim S n ≠ nimVal S n := kPassNim_succ_ne_prev hne lemma passNim_ne_sub {S : Finset ℕ} {s n : ℕ} (hs : s ∈ S) (hs0 : 0 < s) (hsn : s ≤ n) : passNim S (n - s) ≠ passNim S n := by intro heq have hne : (availMoves S n).Nonempty := ⟨s, Finset.mem_filter.mpr ⟨hs, hs0, hsn⟩⟩ have hmem : passNim S n ∈ (if (availMoves S n).Nonempty then insert (nimVal S n) ((availMoves S n).image (fun t => passNim S (n - t))) else (availMoves S n).image (fun t => passNim S (n - t))) := by rw [if_pos hne, Finset.mem_insert] right rw [Finset.mem_image] exact ⟨s, Finset.mem_filter.mpr ⟨hs, hs0, hsn⟩, heq⟩ rw [passNim_eq S n] at hmem exact mex_notMem _ hmem lemma passNim_eq_zero_of_lt {S : Finset ℕ} {n : ℕ} (h : ∀ s ∈ S, 0 < s → n < s) : passNim S n = 0 := by rw [passNim_eq] have hemp : availMoves S n = ∅ := by rw [Finset.eq_empty_iff_forall_notMem] intro s hs have h2 := (Finset.mem_filter.mp hs).2 have := h s (Finset.mem_filter.mp hs).1 h2.1 omega rw [hemp, Finset.image_empty, if_neg Finset.not_nonempty_empty, mex_empty] /-! ### 4. THEOREM 1: Universal `k`-Pass Parity Collapse (`G_{p+2} = G_p`) -/ /-- **THEOREM 1 (Universal `k`-Pass Parity Collapse):** For EVERY finite subtraction set `S : Finset ℕ`, EVERY pass budget `p : ℕ`, and EVERY `n : ℕ`, $$G_{p + 2}(S, n) = G_p(S, n).$$ In particular, all even pass budgets collapse identically to ordinary play `nimVal S`, and all odd pass budgets collapse identically to single-pass play `passNim S`. -/ theorem kPass_parity_collapse (S : Finset ℕ) : ∀ p n : ℕ, kPassNim S (p + 2) n = kPassNim S p n := by intro p induction p with | zero => intro n induction n using Nat.strong_induction_on with | h n ih => rw [kPassNim_succ_eq S 1 n, kPassNim_zero, nimVal_eq S n] have himg : (availMoves S n).image (fun s => kPassNim S 2 (n - s)) = (availMoves S n).image (fun s => nimVal S (n - s)) := by refine Finset.image_congr fun s hs => ?_ have h := (Finset.mem_filter.mp hs).2 exact ih (n - s) (by omega) dsimp only rw [himg] by_cases hne : (availMoves S n).Nonempty · rw [if_pos hne] apply mex_insert_of_ne rw [← nimVal_eq S n] exact kPassNim_succ_ne_prev (p := 0) hne · rw [if_neg hne] | succ p ihp => intro n induction n using Nat.strong_induction_on with | h n ih => rw [kPassNim_succ_eq S (p + 2) n, kPassNim_succ_eq S p n] have himg : (availMoves S n).image (fun s => kPassNim S (p + 3) (n - s)) = (availMoves S n).image (fun s => kPassNim S (p + 1) (n - s)) := by refine Finset.image_congr fun s hs => ?_ have h := (Finset.mem_filter.mp hs).2 exact ih (n - s) (by omega) dsimp only rw [himg, ihp n] theorem kPass_even_eq_nimVal (S : Finset ℕ) (k n : ℕ) : kPassNim S (2 * k) n = nimVal S n := by induction k with | zero => rfl | succ k ih => have : 2 * (k + 1) = 2 * k + 2 := by ring rw [this, kPass_parity_collapse, ih] theorem kPass_odd_eq_passNim (S : Finset ℕ) (k n : ℕ) : kPassNim S (2 * k + 1) n = passNim S n := by induction k with | zero => rfl | succ k ih => have : 2 * (k + 1) + 1 = (2 * k + 1) + 2 := by ring rw [this, kPass_parity_collapse, ih] /-! ### 5. THEOREM 2: Universal Scaling Invariance (`S ↦ a · S`) -/ lemma availMoves_image_mul {S : Finset ℕ} {a n : ℕ} (ha : 0 < a) : availMoves (S.image (a * ·)) n = (availMoves S (n / a)).image (a * ·) := by ext x simp only [availMoves, Finset.mem_filter, Finset.mem_image] constructor · rintro ⟨⟨s, hs, rfl⟩, hpos, hle⟩ refine ⟨s, ⟨hs, ?_, ?_⟩, rfl⟩ · by_contra h0; push Not at h0 have : s = 0 := by omega subst this; simp at hpos · exact (Nat.le_div_iff_mul_le ha).mpr (by rw [mul_comm]; exact hle) · rintro ⟨s, ⟨hs, hs0, hsle⟩, rfl⟩ refine ⟨⟨s, hs, rfl⟩, Nat.mul_pos ha hs0, ?_⟩ have := (Nat.le_div_iff_mul_le ha).mp hsle linarith lemma sub_mul_div {a s n : ℕ} (ha : 0 < a) (hsn : a * s ≤ n) : (n - a * s) / a = n / a - s := by have h1 : (n - a * s) / a + s = n / a := by have h2 : n = (n - a * s) + s * a := by have : s * a = a * s := mul_comm s a omega conv_rhs => rw [h2] rw [Nat.add_mul_div_right _ _ ha] rw [← h1, Nat.add_sub_cancel] /-- **THEOREM 2a (Universal Scaling Invariance for Ordinary Play):** For EVERY finite `S`, `a > 0`, and `n : ℕ`, `nimVal (S.image (a * ·)) n = nimVal S (n / a)`. -/ theorem nimVal_scale (S : Finset ℕ) {a : ℕ} (ha : 0 < a) (n : ℕ) : nimVal (S.image (a * ·)) n = nimVal S (n / a) := by induction n using Nat.strong_induction_on with | h n ih => rw [nimVal_eq (S.image (a * ·)) n, nimVal_eq S (n / a), availMoves_image_mul ha] congr 1 ext y simp only [Finset.mem_image] constructor · rintro ⟨x, ⟨s, hs, rfl⟩, rfl⟩ have h2 := (Finset.mem_filter.mp hs).2 have hle : a * s ≤ n := by have := (Nat.le_div_iff_mul_le ha).mp h2.2 linarith have hpos : 0 < a * s := Nat.mul_pos ha h2.1 refine ⟨s, hs, ?_⟩ rw [ih (n - a * s) (by omega), sub_mul_div ha hle] · rintro ⟨s, hs, rfl⟩ have h2 := (Finset.mem_filter.mp hs).2 have hle : a * s ≤ n := by have := (Nat.le_div_iff_mul_le ha).mp h2.2 linarith have hpos : 0 < a * s := Nat.mul_pos ha h2.1 refine ⟨a * s, ⟨s, hs, rfl⟩, ?_⟩ rw [ih (n - a * s) (by omega), sub_mul_div ha hle] /-- **THEOREM 2b (Universal Scaling Invariance for Single-Pass Play):** For EVERY finite `S`, `a > 0`, and `n : ℕ`, `passNim (S.image (a * ·)) n = passNim S (n / a)`. -/ theorem passNim_scale (S : Finset ℕ) {a : ℕ} (ha : 0 < a) (n : ℕ) : passNim (S.image (a * ·)) n = passNim S (n / a) := by induction n using Nat.strong_induction_on with | h n ih => rw [passNim_eq (S.image (a * ·)) n, passNim_eq S (n / a), availMoves_image_mul ha, nimVal_scale S ha n] have himg : ((availMoves S (n / a)).image (a * ·)).image (fun x => passNim (S.image (a * ·)) (n - x)) = (availMoves S (n / a)).image (fun s => passNim S (n / a - s)) := by ext y simp only [Finset.mem_image] constructor · rintro ⟨x, ⟨s, hs, rfl⟩, rfl⟩ have h2 := (Finset.mem_filter.mp hs).2 have hle : a * s ≤ n := by have := (Nat.le_div_iff_mul_le ha).mp h2.2 linarith have hpos : 0 < a * s := Nat.mul_pos ha h2.1 refine ⟨s, hs, ?_⟩ rw [ih (n - a * s) (by omega), sub_mul_div ha hle] · rintro ⟨s, hs, rfl⟩ have h2 := (Finset.mem_filter.mp hs).2 have hle : a * s ≤ n := by have := (Nat.le_div_iff_mul_le ha).mp h2.2 linarith have hpos : 0 < a * s := Nat.mul_pos ha h2.1 refine ⟨a * s, ⟨s, hs, rfl⟩, ?_⟩ rw [ih (n - a * s) (by omega), sub_mul_div ha hle] dsimp only rw [himg] have hne_iff : ((availMoves S (n / a)).image (a * ·)).Nonempty ↔ (availMoves S (n / a)).Nonempty := Finset.image_nonempty by_cases hne : (availMoves S (n / a)).Nonempty · rw [if_pos (hne_iff.mpr hne), if_pos hne] · rw [if_neg (mt hne_iff.mp hne), if_neg hne] /-! ### 6. THEOREMS 3 & 4: Universal Shift Lock-In and Universal XOR-1 Lock-In -/ /-- **THEOREM 3 (Universal Shift Lock-In Theorem):** Let `S : Finset ℕ` be any finite subtraction set with positive moves bounded above by `M`, and let `s₀ ∈ S` be any positive move (`0 < s₀`). If `passNim S n = nimVal S (n - s₀)` holds across a single consecutive window `[N₀, N₀ + M)` (with `s₀ ≤ N₀`), then $$\forall n \ge N_0,\qquad \mathrm{passNim}\; S\; n = \mathrm{nimVal}\; S\; (n - s_0).$$ -/ theorem shift_lock_in {S : Finset ℕ} {s₀ M N₀ : ℕ} (hs₀ : s₀ ∈ S) (hs₀_pos : 0 < s₀) (hM : ∀ s ∈ S, s ≤ M) (hN₀ : s₀ ≤ N₀) (hwin : ∀ n, N₀ ≤ n → n < N₀ + M → passNim S n = nimVal S (n - s₀)) : ∀ n, N₀ ≤ n → passNim S n = nimVal S (n - s₀) := by intro n induction n using Nat.strong_induction_on with | h n ih => intro hn by_cases hlt : n < N₀ + M · exact hwin n hn hlt · have hge : N₀ + M ≤ n := by omega rw [passNim_eq S n, nimVal_eq S (n - s₀)] have havail : availMoves S n = availMoves S (n - s₀) := by ext s simp only [availMoves, Finset.mem_filter] constructor · rintro ⟨hs, hspos, _⟩ have hsM := hM s hs exact ⟨hs, hspos, by omega⟩ · rintro ⟨hs, hspos, hsle⟩ exact ⟨hs, hspos, by omega⟩ have hne : (availMoves S n).Nonempty := ⟨s₀, Finset.mem_filter.mpr ⟨hs₀, hs₀_pos, by omega⟩⟩ have himg : (availMoves S n).image (fun s => passNim S (n - s)) = (availMoves S (n - s₀)).image (fun s => nimVal S (n - s₀ - s)) := by rw [havail] refine Finset.image_congr fun s hs => ?_ have hmem := Finset.mem_filter.mp hs have hsM := hM s hmem.1 rw [ih (n - s) (by omega) (by omega)] congr 1 omega dsimp only rw [if_pos hne, himg] apply mex_insert_of_ne rw [← nimVal_eq S (n - s₀)] exact (nimVal_ne_sub hs₀ hs₀_pos (by omega)).symm /-- **THEOREM 4 (Universal XOR-1 Lock-In Theorem):** Let `S : Finset ℕ` be any finite subtraction set with positive moves bounded above by `M`, containing at least one positive move `a ∈ S` (`0 < a`). If `passNim S n = nimVal S n ^^^ 1` holds across a single consecutive window `[N₀, N₀ + M)` (with `a ≤ N₀`), then $$\forall n \ge N_0,\qquad \mathrm{passNim}\; S\; n = \mathrm{nimVal}\; S\; n \oplus 1.$$ -/ theorem xor1_lock_in {S : Finset ℕ} {a M N₀ : ℕ} (ha : a ∈ S) (ha_pos : 0 < a) (hM : ∀ s ∈ S, s ≤ M) (hN₀ : a ≤ N₀) (hwin : ∀ n, N₀ ≤ n → n < N₀ + M → passNim S n = nimVal S n ^^^ 1) : ∀ n, N₀ ≤ n → passNim S n = nimVal S n ^^^ 1 := by intro n induction n using Nat.strong_induction_on with | h n ih => intro hn by_cases hlt : n < N₀ + M · exact hwin n hn hlt · have hge : N₀ + M ≤ n := by omega rw [passNim_eq S n] have hne : (availMoves S n).Nonempty := ⟨a, Finset.mem_filter.mpr ⟨ha, ha_pos, by omega⟩⟩ have himg : (availMoves S n).image (fun s => passNim S (n - s)) = ((availMoves S n).image (fun s => nimVal S (n - s))).image (· ^^^ 1) := by rw [Finset.image_image] refine Finset.image_congr fun s hs => ?_ have hmem := Finset.mem_filter.mp hs have hsM := hM s hmem.1 exact ih (n - s) (by omega) (by omega) dsimp only rw [if_pos hne, himg, nimVal_eq S n] exact mex_image_xor1 _ /-! ### 7. THEOREM 5: Universal Injective-Phase Pass-State Rigidity Theorem -/ /-- Pure periodicity of a sequence `f : ℕ → α` with period `p > 0`. -/ def IsPurelyPeriodic {α : Type*} (f : ℕ → α) (p : ℕ) : Prop := 0 < p ∧ ∀ n, f (n + p) = f n /-- Least pure period of `f : ℕ → α`. -/ def IsLeastPeriod {α : Type*} (f : ℕ → α) (p : ℕ) : Prop := IsPurelyPeriodic f p ∧ ∀ q, IsPurelyPeriodic f q → p ≤ q lemma IsPurelyPeriodic.add_mul {α : Type*} {f : ℕ → α} {p : ℕ} (hp : IsPurelyPeriodic f p) (n k : ℕ) : f (n + k * p) = f n := by induction k with | zero => simp | succ k ih => rw [Nat.succ_mul, ← Nat.add_assoc, hp.2, ih] /-- Two subtraction sets `S, T` are *pass-equivalent* if `passNim T = passNim S`. -/ def IsPassEquivalent (S T : Finset ℕ) : Prop := ∀ n, passNim T n = passNim S n /-- A subtraction set `S` is *pass-rigid* (Low, arXiv:2611.30147) if every finite positive expansion `T ⊇ S` with `passNim T = passNim S` also satisfies `nimVal T = nimVal S`. -/ def IsPassRigid (S : Finset ℕ) : Prop := ∀ T : Finset ℕ, S ⊆ T → IsPosMoveSet T → IsPassEquivalent S T → ∀ n, nimVal T n = nimVal S n /-- At the minimum move `a = min S`, `passNim S a = 2` (since options are `{nimVal S 0, passNim S 0} = {0, 0}`? Wait: `nimVal S a = 1`, `passNim S 0 = 0`, so options are `{0, 1}`, giving `passNim S a = 2`!). -/ lemma passNim_min_eq_two {S : Finset ℕ} (hne : S.Nonempty) (hpos : IsPosMoveSet S) : passNim S (S.min' hne) = 2 := by set a := S.min' hne have ha_mem : a ∈ S := Finset.min'_mem S hne have ha_pos : 0 < a := hpos a ha_mem have havail : availMoves S a = {a} := by ext s simp only [availMoves, Finset.mem_filter, Finset.mem_singleton] constructor · rintro ⟨hs, _, hsa⟩ have hle : a ≤ s := Finset.min'_le S s hs omega · rintro rfl exact ⟨ha_mem, ha_pos, le_refl a⟩ have hnim0 : nimVal S 0 = 0 := nimVal_eq_zero_of_lt (fun s _ hs0 => hs0) have hpass0 : passNim S 0 = 0 := passNim_eq_zero_of_lt (fun s _ hs0 => hs0) have hnima : nimVal S a = 1 := by rw [nimVal_eq S a, havail, Finset.image_singleton, Nat.sub_self, hnim0, mex_eq_iff] refine ⟨by simp, fun m hm => ?_⟩ have : m = 0 := by omega subst this; simp rw [passNim_eq S a, havail] dsimp only rw [if_pos (Finset.singleton_nonempty a), Finset.image_singleton, Nat.sub_self, hpass0, hnima, mex_eq_iff] refine ⟨by simp, fun m hm => ?_⟩ rw [Finset.mem_insert, Finset.mem_singleton] omega /-- Any two nonempty positive subtraction sets with identical `passNim` share the exact same minimum move! -/ theorem min_eq_of_passNim_eq {S T : Finset ℕ} (hS : S.Nonempty) (hT : T.Nonempty) (hSpos : IsPosMoveSet S) (hTpos : IsPosMoveSet T) (heq : IsPassEquivalent S T) : T.min' hT = S.min' hS := by apply le_antisymm · by_contra hgt push Not at hgt have h0 : passNim T (S.min' hS) = 0 := passNim_eq_zero_of_lt (fun t ht _ => lt_of_lt_of_le hgt (Finset.min'_le T t ht)) have h2 : passNim S (S.min' hS) = 2 := passNim_min_eq_two hS hSpos have := heq (S.min' hS) omega · by_contra hgt push Not at hgt have h0 : passNim S (T.min' hT) = 0 := passNim_eq_zero_of_lt (fun s hs _ => lt_of_lt_of_le hgt (Finset.min'_le S s hs)) have h2 : passNim T (T.min' hT) = 2 := passNim_min_eq_two hT hTpos have := heq (T.min' hT) omega /-- **THEOREM 5 (Universal Functional-Phase Pass-State Rigidity Theorem):** Let `S : Finset ℕ` be any finite subtraction set whose ordinary Sprague–Grundy sequence `nimVal S` is purely periodic of period `P > 0`. Suppose there exist ANY shift `d : ℕ`, ANY threshold `N₀ : ℕ`, and **ANY function** `φ : ℕ → ℕ` (not even required to be injective!) such that $$\forall n \ge N_0,\qquad \mathrm{passNim}\; S\; n = \varphi\bigl(\mathrm{nimVal}\; S\; (n - d)\bigr).$$ Then `S` is **pass-rigid**: for EVERY positive finite expansion `T ⊇ S` with `passNim T = passNim S`, we have `nimVal T = nimVal S` everywhere on `ℕ`. This strictly generalizes Richard M. Low's translation rigidity theorem (arXiv:2611.30147, Nov 23, 2026), which is the special case `φ = id`, to arbitrary functional phases including `φ(x) = x ⊕ 1` (shifted XOR-1 phases). -/ theorem passRigid_of_purePeriodic_and_phase {S : Finset ℕ} {P d N₀ : ℕ} {φ : ℕ → ℕ} (hper : IsPurelyPeriodic (nimVal S) P) (hphase : ∀ n, N₀ ≤ n → passNim S n = φ (nimVal S (n - d))) : IsPassRigid S := by intro T hsub hTpos heq -- Key step: every move `t ∈ T` satisfies `nimVal S (m - t) ≠ nimVal S m` for all `m ≥ t`! have hcompat : ∀ t ∈ T, ∀ m, t ≤ m → nimVal S (m - t) ≠ nimVal S m := by intro t ht m htm have ht_pos : 0 < t := hTpos t ht set q := N₀ + d + t set n := m + q * P + d have hn1 : N₀ ≤ n := by have : 1 ≤ P := hper.1 have : q ≤ q * P := Nat.le_mul_of_pos_right q hper.1 omega have hn2 : N₀ ≤ n - t := by have : q ≤ q * P := Nat.le_mul_of_pos_right q hper.1 omega have hne_T : passNim T (n - t) ≠ passNim T n := passNim_ne_sub ht ht_pos (by omega) rw [heq (n - t), heq n, hphase (n - t) hn2, hphase n hn1] at hne_T have hsub1 : n - d = m + q * P := by omega have hsub2 : n - t - d = (m - t) + q * P := by omega rw [hsub1, hsub2, hper.add_mul m q, hper.add_mul (m - t) q] at hne_T intro hEq exact hne_T (congrArg φ hEq) -- Strong induction on `n`: adding moves whose values avoid `nimVal S n` never changes `mex`! intro n induction n using Nat.strong_induction_on with | h n ih => rw [nimVal_eq T n, nimVal_eq S n] have himgT : (availMoves T n).image (fun t => nimVal T (n - t)) = (availMoves T n).image (fun t => nimVal S (n - t)) := by refine Finset.image_congr fun t ht => ?_ have h2 := (Finset.mem_filter.mp ht).2 exact ih (n - t) (by omega) rw [himgT] apply mex_eq_of_subset_of_notMem · exact Finset.image_subset_image (Finset.filter_subset_filter _ hsub) · rw [Finset.mem_image] rintro ⟨t, ht, hval⟩ have h1 := Finset.mem_filter.mp ht rw [← nimVal_eq S n] at hval exact hcompat t h1.1 n h1.2.2 hval /-- Corollary 5a (Low's Translation Rigidity, `φ = id`): pure periodicity + eventual translation `passNim S n = nimVal S (n - d)` implies `IsPassRigid S`. -/ theorem passRigid_of_translation {S : Finset ℕ} {P d N₀ : ℕ} (hper : IsPurelyPeriodic (nimVal S) P) (hphase : ∀ n, N₀ ≤ n → passNim S n = nimVal S (n - d)) : IsPassRigid S := passRigid_of_purePeriodic_and_phase (φ := id) hper hphase /-- Corollary 5b (Shifted XOR-1 Rigidity, `φ(x) = x ^^^ 1`): pure periodicity + eventual shifted XOR-1 `passNim S n = nimVal S (n - d) ^^^ 1` implies `IsPassRigid S`. -/ theorem passRigid_of_xor1_shift {S : Finset ℕ} {P d N₀ : ℕ} (hper : IsPurelyPeriodic (nimVal S) P) (hphase : ∀ n, N₀ ≤ n → passNim S n = nimVal S (n - d) ^^^ 1) : IsPassRigid S := passRigid_of_purePeriodic_and_phase (φ := (· ^^^ 1)) hper hphase /-- Corollary 5c (Contrapositive): Any purely periodic set `S` that is NOT pass-rigid cannot possess ANY eventual functional phase `passNim S n = φ (nimVal S (n - d))`! -/ theorem no_functional_phase_of_not_passRigid {S : Finset ℕ} {P : ℕ} (hper : IsPurelyPeriodic (nimVal S) P) (hnr : ¬ IsPassRigid S) : ∀ (φ : ℕ → ℕ) (d N₀ : ℕ), ¬ (∀ n, N₀ ≤ n → passNim S n = φ (nimVal S (n - d))) := by intro φ d N₀ hphase exact hnr (passRigid_of_purePeriodic_and_phase hper hphase) /-! ### 8. THEOREM 6: Complete Short-Interval Three-Element Single-Pass Classification -/ /-- Closed-form ordinary Sprague–Grundy sequence for `S = {a, b, c}` with `a < b ≤ 2a`, `b < c < a + b` (period `c + a`). -/ def shortNim (a c n : ℕ) : ℕ := let u := n % (c + a) if u < a then 0 else if u < 2 * a then 1 else if u < 3 * a then 2 else 3 /-- Closed-form single-pass Sprague–Grundy sequence for `S = {a, b, c}` with `a < b ≤ 2a`, `b < c < a + b`. -/ def shortPassNim (a c n : ℕ) : ℕ := if n < a then 0 else if n < 2 * a then 2 else if n < 3 * a then 1 else if n < min (c + 2 * a) (4 * a) then if c ≤ 2 * a then 3 else if n < c + a then 4 else 3 else shortNim a c (n - a) lemma shortNim_periodic (a c n : ℕ) : shortNim a c (n + (c + a)) = shortNim a c n := by simp [shortNim] lemma mod_sub_lt {P x n : ℕ} (hP : 0 < P) (hx : x < P) (hxn : x ≤ n) : (n - x) % P = if n % P < x then n % P + P - x else n % P - x := by have hdiv : P * (n / P) + n % P = n := Nat.div_add_mod n P have hlt : n % P < P := Nat.mod_lt n hP by_cases h : n % P < x · rw [if_pos h] have hq : 1 ≤ n / P := by by_contra h0; push Not at h0 have : n / P = 0 := Nat.lt_one_iff.mp h0 rw [this, mul_zero, zero_add] at hdiv; omega have heq : n - x = (n % P + P - x) + (n / P - 1) * P := by have h1 : (n / P - 1) * P + P = P * (n / P) := by cases hq_eq : n / P with | zero => omega | succ k => simp only [Nat.add_sub_cancel]; ring omega rw [heq, Nat.add_mul_mod_self_right, Nat.mod_eq_of_lt (by omega)] · rw [if_neg h] have heq : n - x = (n % P - x) + (n / P) * P := by have : (n / P) * P = P * (n / P) := mul_comm _ _ omega rw [heq, Nat.add_mul_mod_self_right, Nat.mod_eq_of_lt (by omega)] /-- Helper: exact ordinary Sprague–Grundy formula `nimVal {a, b, c} n = shortNim a c n` for ALL `2 ≤ a < b ≤ 2a` and `b < c < a + b`. -/ theorem short_interval_nimVal {a b c : ℕ} (ha2 : 2 ≤ a) (hab : a < b) (hb2a : b ≤ 2 * a) (hbc : b < c) (hcab : c < a + b) : ∀ n, nimVal ({a, b, c} : Finset ℕ) n = shortNim a c n := by set S : Finset ℕ := {a, b, c} set P := c + a have ha : 0 < a := by omega have hb : 0 < b := by omega have hc : 0 < c := by omega have hP : 0 < P := by omega intro n induction n using Nat.strong_induction_on with | h n ih => rw [nimVal_eq S n] have himg : (availMoves S n).image (fun s => nimVal S (n - s)) = (availMoves S n).image (fun s => shortNim a c (n - s)) := by refine Finset.image_congr fun s hs => ?_ have h2 := (Finset.mem_filter.mp hs).2 exact ih (n - s) (by omega) rw [himg] have hmem_iff : ∀ y, y ∈ (availMoves S n).image (fun s => shortNim a c (n - s)) ↔ (a ≤ n ∧ shortNim a c (n - a) = y) ∨ (b ≤ n ∧ shortNim a c (n - b) = y) ∨ (c ≤ n ∧ shortNim a c (n - c) = y) := by intro y simp only [Finset.mem_image, availMoves, Finset.mem_filter, S, Finset.mem_insert, Finset.mem_singleton] constructor · rintro ⟨s, ⟨rfl | rfl | rfl, _, hle⟩, rfl⟩ · exact Or.inl ⟨hle, rfl⟩ · exact Or.inr (Or.inl ⟨hle, rfl⟩) · exact Or.inr (Or.inr ⟨hle, rfl⟩) · rintro (⟨hle, rfl⟩ | ⟨hle, rfl⟩ | ⟨hle, rfl⟩) · exact ⟨a, ⟨Or.inl rfl, ha, hle⟩, rfl⟩ · exact ⟨b, ⟨Or.inr (Or.inl rfl), hb, hle⟩, rfl⟩ · exact ⟨c, ⟨Or.inr (Or.inr rfl), hc, hle⟩, rfl⟩ set u := n % P have hu : u < P := Nat.mod_lt n hP have hna : a ≤ n → (n - a) % P = if u < a then u + c else u - a := by intro han rw [mod_sub_lt hP (by omega) han] split_ifs <;> omega have hnb : b ≤ n → (n - b) % P = if u < b then u + P - b else u - b := by intro hbn exact mod_sub_lt hP (by omega) hbn have hnc : c ≤ n → (n - c) % P = if u < c then u + a else u - c := by intro hcn rw [mod_sub_lt hP (by omega) hcn] split_ifs <;> omega rw [mex_eq_iff] have htarget_eq : shortNim a c n = if u < a then 0 else if u < 2 * a then 1 else if u < 3 * a then 2 else 3 := rfl rw [htarget_eq] by_cases h1 : u < a · rw [if_pos h1] refine ⟨?_, fun m hm => by omega⟩ rw [hmem_iff]; push Not refine ⟨fun han => ?_, fun hbn => ?_, fun hcn => ?_⟩ · have hm : (n - a) % P = u + c := by rw [hna han, if_pos h1] unfold shortNim; dsimp only; rw [hm]; split_ifs <;> omega · have hm : (n - b) % P = u + P - b := by rw [hnb hbn, if_pos (by omega)] unfold shortNim; dsimp only; rw [hm]; split_ifs <;> omega · have hm : (n - c) % P = u + a := by rw [hnc hcn, if_pos (by omega)] unfold shortNim; dsimp only; rw [hm]; split_ifs <;> omega · by_cases h2 : u < 2 * a · have han : a ≤ n := by by_contra hlt; have : u = n := Nat.mod_eq_of_lt (by omega); omega have hma_mod : (n - a) % P = u - a := by rw [hna han, if_neg h1] rw [if_neg h1, if_pos h2] constructor · rw [hmem_iff]; push Not refine ⟨fun _ => ?_, fun hbn => ?_, fun hcn => ?_⟩ · unfold shortNim; dsimp only; rw [hma_mod, if_pos (by omega)]; omega · by_cases hub : u < b · have hm : (n - b) % P = u + P - b := by rw [hnb hbn, if_pos hub] unfold shortNim; dsimp only; rw [hm]; split_ifs <;> omega · have hm : (n - b) % P = u - b := by rw [hnb hbn, if_neg hub] unfold shortNim; dsimp only; rw [hm, if_pos (by omega)]; omega · by_cases huc : u < c · have hm : (n - c) % P = u + a := by rw [hnc hcn, if_pos huc] unfold shortNim; dsimp only; rw [hm]; split_ifs <;> omega · have hm : (n - c) % P = u - c := by rw [hnc hcn, if_neg huc] unfold shortNim; dsimp only; rw [hm, if_pos (by omega)]; omega · intro m hm have hm0 : m = 0 := by omega subst hm0 rw [hmem_iff]; left refine ⟨han, ?_⟩ unfold shortNim; dsimp only; rw [hma_mod, if_pos (by omega)] · by_cases h3 : u < 3 * a · have han : a ≤ n := by by_contra hlt; have : u = n := Nat.mod_eq_of_lt (by omega); omega have hbn : b ≤ n := by by_contra hlt; have : u = n := Nat.mod_eq_of_lt (by omega); omega have hma_mod : (n - a) % P = u - a := by rw [hna han, if_neg h1] have hmb_mod : (n - b) % P = u - b := by rw [hnb hbn, if_neg (by omega)] rw [if_neg h1, if_neg h2, if_pos h3] constructor · rw [hmem_iff]; push Not refine ⟨fun _ => ?_, fun _ => ?_, fun hcn => ?_⟩ · unfold shortNim; dsimp only; rw [hma_mod, if_neg (by omega), if_pos (by omega)]; omega · unfold shortNim; dsimp only; rw [hmb_mod]; split_ifs <;> omega · by_cases huc : u < c · have hm : (n - c) % P = u + a := by rw [hnc hcn, if_pos huc] unfold shortNim; dsimp only; rw [hm, if_neg (by omega), if_neg (by omega), if_neg (by omega)]; omega · have hm : (n - c) % P = u - c := by rw [hnc hcn, if_neg huc] unfold shortNim; dsimp only; rw [hm, if_pos (by omega)]; omega · intro m hm have hm01 : m = 0 ∨ m = 1 := by omega rcases hm01 with rfl | rfl · by_cases huab : u < a + b · rw [hmem_iff]; right; left refine ⟨hbn, ?_⟩ unfold shortNim; dsimp only; rw [hmb_mod, if_pos (by omega)] · have hcn : c ≤ n := by by_contra hlt; have : u = n := Nat.mod_eq_of_lt (by omega); omega have hmc_mod : (n - c) % P = u - c := by rw [hnc hcn, if_neg (by omega)] rw [hmem_iff]; right; right refine ⟨hcn, ?_⟩ unfold shortNim; dsimp only; rw [hmc_mod, if_pos (by omega)] · rw [hmem_iff]; left refine ⟨han, ?_⟩ unfold shortNim; dsimp only; rw [hma_mod, if_neg (by omega), if_pos (by omega)] · -- `3a ≤ u < c + a` (only possible when `2a < c`)! have han : a ≤ n := by by_contra hlt; have : u = n := Nat.mod_eq_of_lt (by omega); omega have hbn : b ≤ n := by by_contra hlt; have : u = n := Nat.mod_eq_of_lt (by omega); omega have hcn : c ≤ n := by by_contra hlt; have : u = n := Nat.mod_eq_of_lt (by omega); omega have hma_mod : (n - a) % P = u - a := by rw [hna han, if_neg h1] have hmb_mod : (n - b) % P = u - b := by rw [hnb hbn, if_neg (by omega)] have hmc_mod : (n - c) % P = u - c := by rw [hnc hcn, if_neg (by omega)] rw [if_neg h1, if_neg h2, if_neg h3] constructor · rw [hmem_iff]; push Not refine ⟨fun _ => ?_, fun _ => ?_, fun _ => ?_⟩ · unfold shortNim; dsimp only; rw [hma_mod, if_neg (by omega), if_neg (by omega), if_pos (by omega)]; omega · unfold shortNim; dsimp only; rw [hmb_mod, if_neg (by omega), if_pos (by omega)]; omega · unfold shortNim; dsimp only; rw [hmc_mod, if_pos (by omega)]; omega · intro m hm have hm012 : m = 0 ∨ m = 1 ∨ m = 2 := by omega rcases hm012 with rfl | rfl | rfl · rw [hmem_iff]; right; right refine ⟨hcn, ?_⟩ unfold shortNim; dsimp only; rw [hmc_mod, if_pos (by omega)] · rw [hmem_iff]; right; left refine ⟨hbn, ?_⟩ unfold shortNim; dsimp only; rw [hmb_mod, if_neg (by omega), if_pos (by omega)] · rw [hmem_iff]; left refine ⟨han, ?_⟩ unfold shortNim; dsimp only; rw [hma_mod, if_neg (by omega), if_neg (by omega), if_pos (by omega)] set_option maxHeartbeats 600000 in /-- **THEOREM 6 (Complete Short-Interval Three-Element Single-Pass Classification):** For EVERY `2 ≤ a < b ≤ 2a` and `b < c < a + b`, setting `S = {a, b, c}` and `N₀ = min (c + 2a) (4a)`: 1. `nimVal S n = shortNim a c n` for ALL `n : ℕ` (purely periodic of exact least period `c + a`); 2. `passNim S n = shortPassNim a c n` for ALL `n : ℕ`; 3. `passNim S n = nimVal S (n - a)` for ALL `n ≥ N₀` (eventual shift by `a`); 4. `passNim S (N₀ - 1) ≠ nimVal S (N₀ - 1 - a)` (exact preperiod witness: `N₀` is sharp!); 5. `IsPassRigid S` (complete pass-state rigidity for ALL positive expansions `T ⊇ S`). -/ theorem short_interval_three_pass_classification {a b c : ℕ} (ha2 : 2 ≤ a) (hab : a < b) (hb2a : b ≤ 2 * a) (hbc : b < c) (hcab : c < a + b) : let S : Finset ℕ := {a, b, c} let N₀ := min (c + 2 * a) (4 * a) (∀ n, nimVal S n = shortNim a c n) ∧ (∀ n, passNim S n = shortPassNim a c n) ∧ (∀ n, N₀ ≤ n → passNim S n = nimVal S (n - a)) ∧ passNim S (N₀ - 1) ≠ nimVal S (N₀ - 1 - a) ∧ IsLeastPeriod (nimVal S) (c + a) ∧ IsPassRigid S := by intro S N₀ have ha : 0 < a := by omega have hb : 0 < b := by omega have hc : 0 < c := by omega have hP : 0 < c + a := by omega have hnim : ∀ n, nimVal S n = shortNim a c n := short_interval_nimVal ha2 hab hb2a hbc hcab -- Step 1: Prove `passNim S n = shortPassNim a c n` on the initial window `n < N₀ + c`! have hpass_init : ∀ n, n < N₀ + c → passNim S n = shortPassNim a c n := by intro n induction n using Nat.strong_induction_on with | h n ih => intro hn_lt rw [passNim_eq S n, hnim n] have himg : (availMoves S n).image (fun s => passNim S (n - s)) = (availMoves S n).image (fun s => shortPassNim a c (n - s)) := by refine Finset.image_congr fun s hs => ?_ have h2 := (Finset.mem_filter.mp hs).2 exact ih (n - s) (by omega) (by omega) dsimp only rw [himg] by_cases hna : n < a · have hemp : availMoves S n = ∅ := by rw [Finset.eq_empty_iff_forall_notMem] intro s hs have h1 := Finset.mem_filter.mp hs simp only [S, Finset.mem_insert, Finset.mem_singleton] at h1 rcases h1.1 with rfl | rfl | rfl <;> omega rw [hemp, if_neg Finset.not_nonempty_empty, Finset.image_empty, mex_empty] unfold shortPassNim; rw [if_pos hna] · have han : a ≤ n := by omega have hne : (availMoves S n).Nonempty := ⟨a, Finset.mem_filter.mpr ⟨by simp [S], ha, han⟩⟩ rw [if_pos hne, mex_eq_iff] have hmem_iff : ∀ y, y ∈ insert (shortNim a c n) ((availMoves S n).image (fun s => shortPassNim a c (n - s))) ↔ y = shortNim a c n ∨ shortPassNim a c (n - a) = y ∨ (b ≤ n ∧ shortPassNim a c (n - b) = y) ∨ (c ≤ n ∧ shortPassNim a c (n - c) = y) := by intro y simp only [Finset.mem_insert, Finset.mem_image, availMoves, Finset.mem_filter, S, Finset.mem_singleton] constructor · rintro (rfl | ⟨s, ⟨rfl | rfl | rfl, _, hle⟩, rfl⟩) · exact Or.inl rfl · exact Or.inr (Or.inl rfl) · exact Or.inr (Or.inr (Or.inl ⟨hle, rfl⟩)) · exact Or.inr (Or.inr (Or.inr ⟨hle, rfl⟩)) · rintro (rfl | rfl | ⟨hle, rfl⟩ | ⟨hle, rfl⟩) · exact Or.inl rfl · exact Or.inr ⟨a, ⟨Or.inl rfl, ha, han⟩, rfl⟩ · exact Or.inr ⟨b, ⟨Or.inr (Or.inl rfl), hb, hle⟩, rfl⟩ · exact Or.inr ⟨c, ⟨Or.inr (Or.inr rfl), hc, hle⟩, rfl⟩ -- Helper to compute `shortNim a c k` for `k < 2 * (c + a)` have hsn_lt : ∀ k, k < c + a → shortNim a c k = if k < a then 0 else if k < 2 * a then 1 else if k < 3 * a then 2 else 3 := by intro k hk; unfold shortNim; dsimp only; rw [Nat.mod_eq_of_lt hk] have hsn_ge : ∀ k, c + a ≤ k → k < 2 * (c + a) → shortNim a c k = shortNim a c (k - (c + a)) := by intro k hk1 hk2 have heq : k = (k - (c + a)) + (c + a) := by omega conv_lhs => rw [heq] exact shortNim_periodic a c _ -- Case split on the 5 regions of `n`! by_cases h2a : n < 2 * a · -- `a ≤ n < 2a`: `shortPassNim = 2`, options include `shortNim n = 1` and `shortPassNim (n-a) = 0`, -- and any available `-b`/`-c` lands in `[0, a)` (`0`)! have htarget : shortPassNim a c n = 2 := by unfold shortPassNim; rw [if_neg hna, if_pos h2a] have hgn : shortNim a c n = 1 := by rw [hsn_lt n (by omega), if_neg hna, if_pos h2a] have hma : shortPassNim a c (n - a) = 0 := by unfold shortPassNim; rw [if_pos (by omega)] rw [htarget] constructor · rw [hmem_iff, hgn, hma]; push Not refine ⟨by omega, by omega, fun hbn => ?_, fun hcn => ?_⟩ · unfold shortPassNim; rw [if_pos (by omega)]; omega · unfold shortPassNim; rw [if_pos (by omega)]; omega · intro m hm rw [hmem_iff, hgn, hma] have : m = 0 ∨ m = 1 := by omega rcases this with rfl | rfl · exact Or.inr (Or.inl rfl) · exact Or.inl rfl · by_cases h3a : n < 3 * a · -- `2a ≤ n < 3a`: `shortPassNim = 1`! have htarget : shortPassNim a c n = 1 := by unfold shortPassNim; rw [if_neg hna, if_neg h2a, if_pos h3a] have hgn : shortNim a c n = if n < c + a then 2 else 0 := by by_cases hltP : n < c + a · rw [if_pos hltP, hsn_lt n hltP, if_neg hna, if_neg h2a, if_pos h3a] · rw [if_neg hltP, hsn_ge n (by omega) (by omega), hsn_lt _ (by omega), if_pos (by omega)] have hma : shortPassNim a c (n - a) = 2 := by unfold shortPassNim; rw [if_neg (by omega), if_pos (by omega)] have hbn : b ≤ n := by omega have hmb : shortPassNim a c (n - b) = if n < a + b then 0 else 2 := by unfold shortPassNim by_cases hlt : n < a + b · rw [if_pos hlt, if_pos (by omega)] · rw [if_neg hlt, if_neg (by omega), if_pos (by omega)] rw [htarget] constructor · rw [hmem_iff, hgn, hma, hmb]; push Not refine ⟨?_, by omega, fun _ => ?_, fun hcn => ?_⟩ · split_ifs <;> omega · split_ifs <;> omega · unfold shortPassNim; split_ifs <;> omega · intro m hm have hm0 : m = 0 := by omega subst hm0 rw [hmem_iff, hgn, hma, hmb] by_cases hltP : n < c + a · by_cases hltab : n < a + b · exact Or.inr (Or.inr (Or.inl ⟨hbn, by rw [if_pos hltab]⟩)) · exact Or.inr (Or.inr (Or.inr ⟨by omega, by unfold shortPassNim; rw [if_pos (by omega)]⟩)) · exact Or.inl (by rw [if_neg hltP]) · by_cases hN0 : n < N₀ · -- `3a ≤ n < min(c + 2a, 4a)`! have hma : shortPassNim a c (n - a) = 1 := by unfold shortPassNim; rw [if_neg (by omega), if_neg (by omega), if_pos (by omega)] have hbn : b ≤ n := by omega have hmb_ne3 : shortPassNim a c (n - b) ≠ 3 := by unfold shortPassNim rw [if_neg (by omega)] by_cases hlt2 : n - b < 2 * a · rw [if_pos hlt2]; omega · rw [if_neg hlt2, if_pos (by omega)]; omega have hcn : c ≤ n := by omega have hmc : shortPassNim a c (n - c) = if n < c + a then 0 else 2 := by unfold shortPassNim by_cases hlt : n < c + a · rw [if_pos hlt, if_pos (by omega)] · rw [if_neg hlt, if_neg (by omega), if_pos (by omega)] by_cases hc2a : c ≤ 2 * a · -- Subcase `c ≤ 2a`: `3a ≤ n < c + 2a`, `shortPassNim = 3`! have htarget : shortPassNim a c n = 3 := by unfold shortPassNim; rw [if_neg hna, if_neg h2a, if_neg h3a, if_pos hN0, if_pos hc2a] have hgn : shortNim a c n = 0 := by rw [hsn_ge n (by omega) (by omega), hsn_lt _ (by omega), if_pos (by omega)] have hmc2 : shortPassNim a c (n - c) = 2 := by rw [hmc, if_neg (by omega)] rw [htarget] constructor · rw [hmem_iff, hgn, hma, hmc2]; push Not exact ⟨by omega, by omega, fun _ => hmb_ne3, fun _ => by omega⟩ · intro m hm rw [hmem_iff, hgn, hma, hmc2] have : m = 0 ∨ m = 1 ∨ m = 2 := by omega rcases this with rfl | rfl | rfl · exact Or.inl rfl · exact Or.inr (Or.inl rfl) · exact Or.inr (Or.inr (Or.inr ⟨hcn, rfl⟩)) · -- Subcase `2a < c`: `3a ≤ n < 4a`! by_cases hnca : n < c + a · -- `3a ≤ n < c + a`: `shortNim n = 3`, `hmc = 0`, `hma = 1`, `hmb = 2` -> `mex = 4`! have htarget : shortPassNim a c n = 4 := by unfold shortPassNim rw [if_neg hna, if_neg h2a, if_neg h3a, if_pos hN0, if_neg hc2a, if_pos hnca] have hgn : shortNim a c n = 3 := by rw [hsn_lt n hnca, if_neg hna, if_neg h2a, if_neg h3a] have hmb2 : shortPassNim a c (n - b) = 2 := by unfold shortPassNim; rw [if_neg (by omega), if_pos (by omega)] have hmc0 : shortPassNim a c (n - c) = 0 := by rw [hmc, if_pos hnca] rw [htarget] constructor · rw [hmem_iff, hgn, hma, hmb2, hmc0]; push Not exact ⟨by omega, by omega, fun _ => by omega, fun _ => by omega⟩ · intro m hm rw [hmem_iff, hgn, hma, hmb2, hmc0] have : m = 0 ∨ m = 1 ∨ m = 2 ∨ m = 3 := by omega rcases this with rfl | rfl | rfl | rfl · exact Or.inr (Or.inr (Or.inr ⟨hcn, rfl⟩)) · exact Or.inr (Or.inl rfl) · exact Or.inr (Or.inr (Or.inl ⟨hbn, rfl⟩)) · exact Or.inl rfl · -- `c + a ≤ n < 4a`: `shortNim n = 0`, `hma = 1`, `hmb ≠ 3`, `hmc = 2` -> `mex = 3`! have htarget : shortPassNim a c n = 3 := by unfold shortPassNim rw [if_neg hna, if_neg h2a, if_neg h3a, if_pos hN0, if_neg hc2a, if_neg hnca] have hgn : shortNim a c n = 0 := by rw [hsn_ge n (by omega) (by omega), hsn_lt _ (by omega), if_pos (by omega)] have hmc2 : shortPassNim a c (n - c) = 2 := by rw [hmc, if_neg hnca] rw [htarget] constructor · rw [hmem_iff, hgn, hma, hmc2]; push Not exact ⟨by omega, by omega, fun _ => hmb_ne3, fun _ => by omega⟩ · intro m hm rw [hmem_iff, hgn, hma, hmc2] have : m = 0 ∨ m = 1 ∨ m = 2 := by omega rcases this with rfl | rfl | rfl · exact Or.inl rfl · exact Or.inr (Or.inl rfl) · exact Or.inr (Or.inr (Or.inr ⟨hcn, rfl⟩)) · -- LOCK-IN WINDOW: `N₀ ≤ n < N₀ + c`! Target = `shortNim a c (n - a)`! have htarget : shortPassNim a c n = shortNim a c (n - a) := by unfold shortPassNim; rw [if_neg hna, if_neg h2a, if_neg h3a, if_neg hN0] have hbn : b ≤ n := by omega have hcn : c ≤ n := by omega -- Notice `n - a ∈ [N₀ - a, N₀ - a + c)`. What is `(n - a) % (c + a)`? -- Let `v := (n - a) % (c + a)`. Note `n - a < 2*(c + a)` since `N₀ ≤ c + 2a` and `c < 3a`, -- actually `N₀ + c - a ≤ c + 2a + c - a = 2c + a < 2(c + a)`! -- Even better: `N₀ - a ≥ c + a` when `c ≤ 2a`? Wait: -- * If `c ≤ 2a`: `N₀ = c + 2a`, so `N₀ - a = c + a`, and `n - a ∈ [c + a, 2c + a)`. -- Thus `v = n - a - (c + a) = n - c - 2a ∈ [0, c)`. -- * If `2a < c`: `N₀ = 4a`, so `N₀ - a = 3a`, and `n - a ∈ [3a, 3a + c)`. -- Note `c + a ≤ 4a` (since `c < a + b ≤ 3a`)! Wait: `3a < c + a` when `2a < c`! -- So `n - a` starts at `3a < c + a` and wraps at `c + a`! -- Compute `shortNim a c n` and `shortPassNim a c (n - s)` cleanly by splitting on `v := (n - a) % (c + a)`! set v := (n - a) % (c + a) have hv : v < c + a := Nat.mod_lt _ hP -- Prove `shortNim a c n ≠ shortNim a c (n - a)` directly from `nimVal_ne_sub`! have hgn_ne : shortNim a c n ≠ shortNim a c (n - a) := by rw [← hnim n, ← hnim (n - a)] exact (nimVal_ne_sub (S := S) (by simp [S]) ha han).symm -- Check `shortPassNim` at `n - a`, `n - b`, `n - c` vs `shortNim a c (n - a)`! rw [htarget] have hv_eq : shortNim a c (n - a) = if v < a then 0 else if v < 2 * a then 1 else if v < 3 * a then 2 else 3 := by unfold shortNim; dsimp only -- Key observation: `n - c < N₀` ALWAYS (since `n < N₀ + c`), and `n - b < N₀ + c - b`! -- Let us split cleanly on `c ≤ 2a` vs `2a < c`, and on the 4 ranges of `v`! by_cases hc2a : c ≤ 2 * a · -- `N₀ = c + 2a`, so `c + 2a ≤ n < 2c + 2a`, hence `n - a = (c + a) + v` with `v = n - c - 2a < c`! have hN0_eq : N₀ = c + 2 * a := Nat.min_eq_left (by omega) have hv_val : v = n - c - 2 * a := by have heq : n - a = (n - c - 2 * a) + (c + a) := by omega dsimp [v]; rw [heq, Nat.add_mod_right, Nat.mod_eq_of_lt (by omega)] -- Here `v < c ≤ 2a`, so `shortNim a c (n - a)` is ONLY `0` (if `v < a`) or `1` (if `a ≤ v < c`)! by_cases hva : v < a · -- `c + 2a ≤ n < c + 3a`, target = `0`! rw [hv_eq, if_pos hva] refine ⟨?_, fun m hm => by omega⟩ rw [hmem_iff]; push Not refine ⟨?_, ?_, fun _ => ?_, fun _ => ?_⟩ · rw [hv_eq, if_pos hva] at hgn_ne; exact hgn_ne.symm · -- `n - a ∈ [c + a, c + 2a)`: `shortPassNim` is `1` (if `< 3a`) or `3` (if `≥ 3a`)! unfold shortPassNim; split_ifs <;> omega · -- `n - b ∈ [c + 2a - b, c + 3a - b) ⊆ [a, 3a)`! unfold shortPassNim; split_ifs <;> omega · -- `n - c ∈ [2a, 3a)`: `shortPassNim = 1`! unfold shortPassNim; rw [if_neg (by omega), if_neg (by omega), if_pos (by omega)]; omega · -- `c + 3a ≤ n < 2c + 2a` (`a ≤ v < c ≤ 2a`), target = `1`! rw [hv_eq, if_neg hva, if_pos (by omega)] have hma0 : shortPassNim a c (n - a) = 0 := by -- `n - a ∈ [c + 2a, 2c + a) = [N₀, 2c + a)`, so `shortPassNim (n - a) = shortNim (n - 2a)`! unfold shortPassNim rw [if_neg (by omega), if_neg (by omega), if_neg (by omega), if_neg (by omega)] have hsub : n - a - a = (n - c - 3 * a) + (c + a) := by omega rw [hsub, shortNim_periodic, hsn_lt _ (by omega), if_pos (by omega)] constructor · rw [hmem_iff, hma0]; push Not refine ⟨?_, by omega, fun _ => ?_, fun _ => ?_⟩ · rw [hv_eq, if_neg hva, if_pos (by omega)] at hgn_ne; exact hgn_ne.symm · by_cases hnb_lt : n - b < N₀ · unfold shortPassNim rw [if_neg (by omega), if_neg (by omega), if_neg (by omega), if_pos hnb_lt, if_pos hc2a] omega · unfold shortPassNim rw [if_neg (by omega), if_neg (by omega), if_neg (by omega), if_neg hnb_lt] have hsub : n - b - a = (n - b - c - 2 * a) + (c + a) := by omega rw [hsub, shortNim_periodic, hsn_lt _ (by omega), if_pos (by omega)]; omega · -- `n - c ∈ [3a, c + 2a) = [3a, N₀)`: `shortPassNim = 3`! unfold shortPassNim rw [if_neg (by omega), if_neg (by omega), if_neg (by omega), if_pos (by omega), if_pos hc2a] omega · intro m hm have hm0 : m = 0 := by omega subst hm0 rw [hmem_iff, hma0]; exact Or.inr (Or.inl rfl) · -- `2a < c`: `N₀ = 4a`, so `4a ≤ n < 4a + c`, and `n - a ∈ [3a, 3a + c)`. have hN0_eq : N₀ = 4 * a := Nat.min_eq_right (by omega) by_cases hlt1 : n < c + 2 * a · -- `4a ≤ n < c + 2a`: `3a ≤ n - a < c + a`, so `v = n - a ∈ [3a, c + a)`, target = `3`! have hv_val : v = n - a := Nat.mod_eq_of_lt (by omega) rw [hv_eq, if_neg (by omega), if_neg (by omega), if_neg (by omega)] have hgn0 : shortNim a c n = 0 := by rw [hsn_ge n (by omega) (by omega), hsn_lt _ (by omega), if_pos (by omega)] have hma4 : shortPassNim a c (n - a) = 4 := by unfold shortPassNim rw [if_neg (by omega), if_neg (by omega), if_neg (by omega), if_pos (by omega), if_neg hc2a, if_pos (by omega)] have hmb1 : shortPassNim a c (n - b) = 1 := by unfold shortPassNim rw [if_neg (by omega), if_neg (by omega), if_pos (by omega)] have hmc2 : shortPassNim a c (n - c) = 2 := by unfold shortPassNim rw [if_neg (by omega), if_pos (by omega)] constructor · rw [hmem_iff, hgn0, hma4, hmb1, hmc2]; push Not exact ⟨by omega, by omega, fun _ => by omega, fun _ => by omega⟩ · intro m hm rw [hmem_iff, hgn0, hma4, hmb1, hmc2] have : m = 0 ∨ m = 1 ∨ m = 2 := by omega rcases this with rfl | rfl | rfl · exact Or.inl rfl · exact Or.inr (Or.inr (Or.inl ⟨hbn, rfl⟩)) · exact Or.inr (Or.inr (Or.inr ⟨hcn, rfl⟩)) · by_cases hlt2 : n < c + 3 * a · -- `c + 2a ≤ n < c + 3a`: `v = n - c - 2a < a`, target = `0`! have hv_val : v = n - c - 2 * a := by have heq : n - a = (n - c - 2 * a) + (c + a) := by omega dsimp [v]; rw [heq, Nat.add_mod_right, Nat.mod_eq_of_lt (by omega)] rw [hv_eq, if_pos (by omega)] refine ⟨?_, fun m hm => by omega⟩ rw [hmem_iff]; push Not refine ⟨?_, ?_, fun _ => ?_, fun _ => ?_⟩ · rw [hv_eq, if_pos (by omega)] at hgn_ne; exact hgn_ne.symm · -- `n - a ∈ [c + a, c + 2a)`: `shortPassNim` is `3` (if `< 4a`) or `shortNim (n-2a) = 3`! by_cases hna4 : n - a < 4 * a · unfold shortPassNim rw [if_neg (by omega), if_neg (by omega), if_neg (by omega), if_pos (by omega), if_neg hc2a, if_neg (by omega)]; omega · unfold shortPassNim rw [if_neg (by omega), if_neg (by omega), if_neg (by omega), if_neg (by omega)] rw [hsn_lt _ (by omega), if_neg (by omega), if_neg (by omega), if_neg (by omega)]; omega · -- `n - b ∈ [2a, 4a)` -> `shortPassNim ∈ {1, 4, 3}` (never `0`!) unfold shortPassNim rw [if_neg (by omega), if_neg (by omega)] by_cases hnb3 : n - b < 3 * a · rw [if_pos hnb3]; omega · rw [if_neg hnb3, if_pos (by omega), if_neg hc2a]; split_ifs <;> omega · -- `n - c ∈ [2a, 3a)`: `shortPassNim = 1`! unfold shortPassNim rw [if_neg (by omega), if_neg (by omega), if_pos (by omega)]; omega · -- `c + 3a ≤ n < c + 4a`: `v = n - c - 2a ∈ [a, 2a)`, target = `1`! have hv_val : v = n - c - 2 * a := by have heq : n - a = (n - c - 2 * a) + (c + a) := by omega dsimp [v]; rw [heq, Nat.add_mod_right, Nat.mod_eq_of_lt (by omega)] rw [hv_eq, if_neg (by omega), if_pos (by omega)] have hma0 : shortPassNim a c (n - a) = 0 := by unfold shortPassNim rw [if_neg (by omega), if_neg (by omega), if_neg (by omega), if_neg (by omega)] have hsub : n - a - a = (n - c - 3 * a) + (c + a) := by omega rw [hsub, shortNim_periodic, hsn_lt _ (by omega), if_pos (by omega)] constructor · rw [hmem_iff, hma0]; push Not refine ⟨?_, by omega, fun _ => ?_, fun _ => ?_⟩ · rw [hv_eq, if_neg (by omega), if_pos (by omega)] at hgn_ne; exact hgn_ne.symm · -- `n - b ∈ (3a, c + 3a)`: by_cases hnb4 : n - b < 4 * a · unfold shortPassNim rw [if_neg (by omega), if_neg (by omega), if_neg (by omega), if_pos (by omega), if_neg hc2a]; split_ifs <;> omega · unfold shortPassNim rw [if_neg (by omega), if_neg (by omega), if_neg (by omega), if_neg (by omega)] by_cases hnb_lt : n - b - a < c + a · rw [hsn_lt _ hnb_lt, if_neg (by omega), if_neg (by omega), if_neg (by omega)]; omega · rw [hsn_ge _ (by omega) (by omega), hsn_lt _ (by omega), if_pos (by omega)]; omega · -- `n - c ∈ [3a, 4a)`: `shortPassNim ∈ {4, 3}`! unfold shortPassNim rw [if_neg (by omega), if_neg (by omega), if_neg (by omega), if_pos (by omega), if_neg hc2a]; split_ifs <;> omega · intro m hm have hm0 : m = 0 := by omega subst hm0 rw [hmem_iff, hma0]; exact Or.inr (Or.inl rfl) -- Step 2: Apply Universal Shift Lock-In (`shift_lock_in`) to get `passNim S n = nimVal S (n - a)` for ALL `n ≥ N₀`! have hshift : ∀ n, N₀ ≤ n → passNim S n = nimVal S (n - a) := by apply shift_lock_in (S := S) (s₀ := a) (M := c) (N₀ := N₀) (by simp [S]) ha (fun s hs => by simp only [S, Finset.mem_insert, Finset.mem_singleton] at hs; rcases hs with rfl | rfl | rfl <;> omega) (by dsimp [N₀]; omega) intro n hn1 hn2 rw [hpass_init n hn2, hnim (n - a)] unfold shortPassNim rw [if_neg (by omega), if_neg (by omega), if_neg (by omega), if_neg (by omega)] -- Step 3: Assemble `∀ n, passNim S n = shortPassNim a c n` for ALL `n : ℕ`! have hpass_all : ∀ n, passNim S n = shortPassNim a c n := by intro n by_cases hlt : n < N₀ + c · exact hpass_init n hlt · rw [hshift n (by omega), hnim (n - a)] unfold shortPassNim rw [if_neg (by omega), if_neg (by omega), if_neg (by omega), if_neg (by omega)] -- Step 4: Sharpness witness `passNim S (N₀ - 1) ≠ nimVal S (N₀ - 1 - a)` (`3 ≠ 2`)! have hsharp : passNim S (N₀ - 1) ≠ nimVal S (N₀ - 1 - a) := by rw [hpass_all (N₀ - 1), hnim (N₀ - 1 - a)] have hpass3 : shortPassNim a c (N₀ - 1) = 3 := by unfold shortPassNim by_cases hc2a : c ≤ 2 * a · have hN0_eq : N₀ = c + 2 * a := Nat.min_eq_left (by omega) rw [if_neg (by omega), if_neg (by omega), if_neg (by omega), if_pos (by omega), if_pos hc2a] · have hN0_eq : N₀ = 4 * a := Nat.min_eq_right (by omega) rw [if_neg (by omega), if_neg (by omega), if_neg (by omega), if_pos (by omega), if_neg hc2a, if_neg (by omega)] have hnim2 : shortNim a c (N₀ - 1 - a) = 2 := by unfold shortNim; dsimp only have hlt : N₀ - 1 - a < c + a := by dsimp [N₀]; omega rw [Nat.mod_eq_of_lt hlt, if_neg (by omega), if_neg (by omega), if_pos (by omega)] omega -- Step 5: Exact least period `c + a` of `nimVal S`! have hper : IsPurelyPeriodic (nimVal S) (c + a) := ⟨hP, fun n => by rw [hnim, hnim, shortNim_periodic]⟩ have hleast : IsLeastPeriod (nimVal S) (c + a) := by refine ⟨hper, fun q hq => ?_⟩ by_contra hlt have hq_pos : 0 < q := hq.1 have hq_lt : q < c + a := by omega have h0 : nimVal S q = 0 := by have := hq.2 0; rw [zero_add] at this rw [this, hnim 0]; unfold shortNim; dsimp only rw [Nat.zero_mod, if_pos ha] have hqa : q < a := by rw [hnim q] at h0; unfold shortNim at h0; dsimp only at h0 rw [Nat.mod_eq_of_lt hq_lt] at h0 split_ifs at h0; exact ‹q < a› have h1 := hq.2 (a - q) have hsum : a - q + q = a := by omega rw [hsum, hnim a, hnim (a - q)] at h1 unfold shortNim at h1; dsimp only at h1 rw [Nat.mod_eq_of_lt (by omega), Nat.mod_eq_of_lt (by omega), if_neg (by omega), if_pos (by omega), if_pos (by omega)] at h1 omega -- Step 6: Pass-state rigidity immediately via `passRigid_of_translation`! have hrigid : IsPassRigid S := passRigid_of_translation hper hshift exact ⟨hnim, hpass_all, hshift, hsharp, hleast, hrigid⟩ end PassSubtractionLaws #print axioms PassSubtractionLaws.mex_image_xor1 #print axioms PassSubtractionLaws.kPass_parity_collapse #print axioms PassSubtractionLaws.nimVal_scale #print axioms PassSubtractionLaws.passNim_scale #print axioms PassSubtractionLaws.shift_lock_in #print axioms PassSubtractionLaws.xor1_lock_in #print axioms PassSubtractionLaws.min_eq_of_passNim_eq #print axioms PassSubtractionLaws.passRigid_of_purePeriodic_and_phase #print axioms PassSubtractionLaws.passRigid_of_translation #print axioms PassSubtractionLaws.passRigid_of_xor1_shift #print axioms PassSubtractionLaws.no_functional_phase_of_not_passRigid #print axioms PassSubtractionLaws.short_interval_three_pass_classification