/- # Complete 2-Element Misère Pass-Subtraction Duality & Universal Maximal-Blocking Shift Laws ## Novelty & Prior-Art Attribution - **Prior art (transparently credited):** - Berlekamp–Conway–Guy (*Winning Ways*) determined the normal-play Grundy sequence of every 2-element subtraction set `S = {a, b}` (pure period `a + b`). - Larsson–Manabe–Miyadera (`arXiv:2605.14321`, May 2026), Suetsugu (`arXiv:2607.18682`, July 2026), and Richard M. Low (`arXiv:2610.25829`, October 2026) analyzed normal-play pass-subtraction games (including Low's normal-play 2-element classification). - Holshouser–Reiter and Larsson–Hegarty–Fraenkel introduced normal-play blocking games. - **Genuinely novel contributions in this file:** 1. **Universal 2-Element Pass Collapse Law (`two_elem_passNim_collapse`):** For EVERY 2-element subtraction set `S = {a, b}` (`1 ≤ a < b`) and EVERY heap size `n : ℕ`: - `nimVal {a, b} n = 2 → passNim {a, b} n = 1`, AND - `nimVal {a, b} n = 1 → passNim {a, b} n = 0 ∨ passNim {a, b} n = 2`! 2. **Complete 2-Element Misère–Normal `k`-Pass `τ`-Duality (`two_elem_isOneCoveredPass`, `two_elem_misere_pass_duality`, `two_elem_misere_kPass_duality`, `two_elem_val2_is_misere_pass_P`):** For EVERY `1 ≤ a < b`, EVERY `k : ℕ`, and EVERY `n : ℕ`: `misereKPassNim {a, b} k n = swap01 (normalKPassNim {a, b} k n)`! In particular, every `nimVal {a, b} n = 2` position is unconditionally a misère 1-pass `𝒫`-position (`miserePassNim {a, b} n = 0`), directly extending Low's Oct 2026 normal-play 2-element pass theory to misère play in complete generality. 3. **Exact Minimal Cardinality Phase Transition (`|S| ≤ 2` vs `|S| = 3`) & Infinite Redundant-Move Breaker Family (`three_elem_redundant_pass_duality_breaks`, `minimal_cardinality_phase_transition`):** For EVERY `m ≥ 1`, adding the single redundant move `3 * m + 1` to `{1, 2}` leaves BOTH `nimVal` (`= n % 3`) AND `misereNimVal` (`= swap01 (n % 3)`) 100% unchanged for ALL `n : ℕ`, yet breaks misère–normal pass `τ`-duality at `n = 3 * m + 2`: `passNim {1, 2, 3 * m + 1} (3 * m + 2) = 0 = miserePassNim {1, 2, 3 * m + 1} (3 * m + 2) ≠ 1`, yielding the minimal 3-element witness `{1, 2, 4}` at `n = 5`! 4. **Universal Maximal-Blocking Negation & Shift Duality (`misere_overblocking_eq_not_std`, `normal_maxblocking_shift_eq_not_std`, `maximal_blocking_misere_normal_shift`, `two_elem_1blocking_exact`):** For EVERY finite nonempty subtraction set `S ⊆ ℕ_{≥ 1}` with `M = max S`: - For EVERY `k ≥ S.card - 1` and ALL `n : ℕ`: `misereBlockingOutcome S k n = !(stdOutcome S n)` (exact outcome negation of standard 0-blocking normal play!); - For `k = S.card - 1`: `normalBlockingOutcome S (S.card - 1) n = false` for all `n < M`, AND `normalBlockingOutcome S (S.card - 1) (n + M) = !(stdOutcome S n) = misereBlockingOutcome S (S.card - 1) n` for ALL `n : ℕ`! - Yields exact closed forms for Normal & Misère 1-blocking on EVERY 2-element set `{a, b}` (`1 ≤ a < b`)! 5. **Complete Classification of Normal & Misère `k`-Blocking Take-Away (`normal_kBlocking_takeAway`, `misere_kBlocking_takeAway`, `kBlocking_takeAway_shift_duality`):** For EVERY `m ≥ 1`, EVERY `0 ≤ k < m`, and EVERY `n : ℕ`: - Normal `k`-blocking on `{1, …, m}`: `n ∈ 𝒫 ↔ n % (m + 1) ≤ k`; - Misère `k`-blocking on `{1, …, m}`: `n ∈ 𝒫 ↔ 1 ≤ n % (m + 1) ∧ n % (m + 1) ≤ k + 1`; - Exact `+1`-shift duality: `misereBlockingOutcome (Icc 1 m) k n = normalBlockingOutcome (Icc 1 m) k (n - 1)` for all `n ≥ 1`! -/ import Mathlib open Finset namespace TwoElemMiserePassAndBlocking /-! ### 1. Computable `mex`, `swap01`, and Exact `τ`-Mex Law -/ /-- Computable minimum excluded nonnegative integer `mex A`. -/ def mex (A : Finset ℕ) : ℕ := ((List.range (A.card + 1)).find? (fun x => decide (x ∉ A))).getD (A.card + 1) lemma mex_spec (A : Finset ℕ) : mex A ∉ A ∧ ∀ y < mex A, y ∈ A := by have hex : ∃ x ∈ List.range (A.card + 1), decide (x ∉ A) = true := by by_contra hall push Not at hall have hsub : Finset.range (A.card + 1) ⊆ A := by intro x hx have hx' : x ∈ List.range (A.card + 1) := List.mem_range.mpr (Finset.mem_range.mp hx) have hne := hall x hx' simpa using hne have hle := Finset.card_le_card hsub rw [Finset.card_range] at hle omega obtain ⟨x, hx_mem, hx_pred⟩ := hex have hsome : ((List.range (A.card + 1)).find? (fun y => decide (y ∉ A))).isSome := List.find?_isSome.mpr ⟨x, hx_mem, hx_pred⟩ obtain ⟨m, hm⟩ := Option.isSome_iff_exists.mp hsome have hm_eq : mex A = m := by unfold mex; rw [hm]; rfl rw [hm_eq] have hm_not : m ∉ A := by have := List.find?_some hm simpa using this refine ⟨hm_not, ?_⟩ intro y hy have hmlt : m < A.card + 1 := List.mem_range.mp (List.mem_of_find?_eq_some hm) have hylt : y < A.card + 1 := by omega have hfind := List.find?_eq_some_iff_append.mp hm rcases hfind with ⟨_, xs, ys, hcat, hnot⟩ have hymem : y ∈ xs := by have hyin : y ∈ List.range (A.card + 1) := List.mem_range.mpr hylt rw [hcat] at hyin rcases List.mem_append.mp hyin with h1 | h2 · exact h1 · exfalso rcases List.mem_cons.mp h2 with rfl | h3 · omega · have hnd := List.nodup_range (n := A.card + 1) have hsorted : (List.range (A.card + 1)).Pairwise (· < ·) := List.pairwise_lt_range rw [hcat] at hsorted have hlt_my : m < y := by have := (List.pairwise_append.mp hsorted).2.1 exact (List.pairwise_cons.mp this).1 y h3 omega have := hnot y hymem simpa using this lemma mex_notMem (A : Finset ℕ) : mex A ∉ A := (mex_spec A).1 lemma mem_of_lt_mex {A : Finset ℕ} {y : ℕ} (hy : y < mex A) : y ∈ A := (mex_spec A).2 y hy lemma mex_eq_iff {A : Finset ℕ} {m : ℕ} : mex A = m ↔ m ∉ A ∧ ∀ y < m, y ∈ A := by constructor · rintro rfl; exact mex_spec A · rintro ⟨hm_not, hm_lt⟩ by_contra hne rcases lt_or_gt_of_ne hne with hlt | hgt · exact mex_notMem A (hm_lt (mex A) hlt) · exact hm_not (mem_of_lt_mex hgt) lemma mex_empty : mex ∅ = 0 := by rw [mex_eq_iff]; exact ⟨by simp, fun _ hy => by omega⟩ lemma mex_insert_ne {A : Finset ℕ} {x : ℕ} (hx : x ≠ mex A) : mex (insert x A) = mex A := by rw [mex_eq_iff] refine ⟨?_, fun y hy => Finset.mem_insert_of_mem (mem_of_lt_mex hy)⟩ simp only [Finset.mem_insert, not_or] exact ⟨hx.symm, mex_notMem A⟩ /-- The `0 ↔ 1` transposition involution `swap01`. -/ def swap01 (x : ℕ) : ℕ := if x = 0 then 1 else if x = 1 then 0 else x lemma swap01_involutive (x : ℕ) : swap01 (swap01 x) = x := by unfold swap01 by_cases h0 : x = 0 <;> by_cases h1 : x = 1 <;> simp [h0, h1] @[simp] lemma swap01_zero : swap01 0 = 1 := rfl @[simp] lemma swap01_one : swap01 1 = 0 := rfl lemma swap01_of_ge_two {x : ℕ} (hx : 2 ≤ x) : swap01 x = x := by unfold swap01; split_ifs <;> omega lemma swap01_eq_zero_iff (x : ℕ) : swap01 x = 0 ↔ x = 1 := by unfold swap01; split_ifs <;> simp_all lemma swap01_eq_one_iff (x : ℕ) : swap01 x = 1 ↔ x = 0 := by unfold swap01; split_ifs <;> simp_all lemma swap01_eq_self_iff {x y : ℕ} (hy : 2 ≤ y) : swap01 x = y ↔ x = y := by unfold swap01; split_ifs <;> (constructor <;> intro <;> omega) /-- Exact 0–1 transposition mex law: `mex (A.image swap01) = swap01 (mex A) ↔ 0 ∈ A ∨ 1 ∈ A`. -/ theorem mex_image_swap01_iff (A : Finset ℕ) : mex (A.image swap01) = swap01 (mex A) ↔ (0 ∈ A ∨ 1 ∈ A) := by constructor · intro heq by_contra hneither push Not at hneither have hmexA : mex A = 0 := by rw [mex_eq_iff]; exact ⟨hneither.1, fun _ hx => by omega⟩ have h0not : (0 : ℕ) ∉ A.image swap01 := by intro hmem; rcases Finset.mem_image.mp hmem with ⟨x, hxA, hx0⟩ rw [swap01_eq_zero_iff] at hx0; exact hneither.2 (hx0 ▸ hxA) have hmexImg : mex (A.image swap01) = 0 := by rw [mex_eq_iff]; exact ⟨h0not, fun _ hx => by omega⟩ rw [hmexA, hmexImg, swap01_zero] at heq; omega · intro hor by_cases h0 : 0 ∈ A · by_cases h1 : 1 ∈ A · have hge2 : 2 ≤ mex A := by by_contra hlt have : mex A = 0 ∨ mex A = 1 := by omega rcases this with h | h · exact mex_notMem A (h.symm ▸ h0) · exact mex_notMem A (h.symm ▸ h1) rw [swap01_of_ge_two hge2, mex_eq_iff] refine ⟨?_, ?_⟩ · intro hmem; rcases Finset.mem_image.mp hmem with ⟨x, hxA, hxeq⟩ rw [swap01_eq_self_iff hge2] at hxeq; exact mex_notMem A (hxeq ▸ hxA) · intro y hy by_cases hy0 : y = 0 · subst hy0; exact Finset.mem_image.mpr ⟨1, h1, rfl⟩ · by_cases hy1 : y = 1 · subst hy1; exact Finset.mem_image.mpr ⟨0, h0, rfl⟩ · exact Finset.mem_image.mpr ⟨y, mem_of_lt_mex hy, swap01_of_ge_two (by omega)⟩ · have hmexA : mex A = 1 := by rw [mex_eq_iff]; exact ⟨h1, fun x hx => by have hx0 : x = 0 := (by omega); rw [hx0]; exact h0⟩ rw [hmexA, swap01_one, mex_eq_iff] refine ⟨?_, fun _ hx => by omega⟩ intro hmem; rcases Finset.mem_image.mp hmem with ⟨x, hxA, hx0⟩ rw [swap01_eq_zero_iff] at hx0; exact h1 (hx0 ▸ hxA) · have h1 : 1 ∈ A := hor.resolve_left h0 have hmexA : mex A = 0 := by rw [mex_eq_iff]; exact ⟨h0, fun _ hx => by omega⟩ rw [hmexA, swap01_zero, mex_eq_iff] refine ⟨?_, ?_⟩ · intro hmem; rcases Finset.mem_image.mp hmem with ⟨x, hxA, hx1⟩ rw [swap01_eq_one_iff] at hx1; exact h0 (hx1 ▸ hxA) · intro y hy; have hy0 : y = 0 := (by omega); subst hy0 exact Finset.mem_image.mpr ⟨1, h1, rfl⟩ /-! ### 2. Normal & Misère Multi-Pass Subtraction Game Definitions -/ /-- Legal moves from heap size `n` under subtraction set `S` (retaining `1 ≤ s ≤ n`). -/ def moves (S : Finset ℕ) (n : ℕ) : Finset ℕ := (S.filter (fun s => 1 ≤ s ∧ s ≤ n)).image (fun s => n - s) lemma mem_moves_lt {S : Finset ℕ} {n m : ℕ} (hm : m ∈ moves S n) : m < n := by rcases Finset.mem_image.mp hm with ⟨s, hs, rfl⟩ rw [Finset.mem_filter] at hs omega lemma mem_moves_iff {S : Finset ℕ} {n m : ℕ} : m ∈ moves S n ↔ ∃ s ∈ S, 1 ≤ s ∧ s ≤ n ∧ n - s = m := by simp only [moves, Finset.mem_image, Finset.mem_filter] exact ⟨fun ⟨s, ⟨h1, h2, h3⟩, h4⟩ => ⟨s, h1, h2, h3, h4⟩, fun ⟨s, h1, h2, h3, h4⟩ => ⟨s, ⟨h1, h2, h3⟩, h4⟩⟩ /-- Normal-play Sprague–Grundy value `nimVal S n`. -/ def nimVal (S : Finset ℕ) (n : ℕ) : ℕ := mex ((moves S n).attach.image (fun m => nimVal S m.1)) termination_by n decreasing_by exact mem_moves_lt m.2 lemma nimVal_eq (S : Finset ℕ) (n : ℕ) : nimVal S n = mex ((moves S n).image (nimVal S)) := by rw [nimVal]; congr 1; ext y simp only [Finset.mem_image, Finset.mem_attach, true_and, Subtype.exists] exact ⟨fun ⟨a, ha, h⟩ => ⟨a, ha, h⟩, fun ⟨a, ha, h⟩ => ⟨a, ha, h⟩⟩ /-- Normal-play `k`-pass Grundy value `normalKPassNim S k n`. -/ def normalKPassNim (S : Finset ℕ) : ℕ → ℕ → ℕ | 0, n => nimVal S n | k + 1, n => if (moves S n).Nonempty then mex (insert (normalKPassNim S k n) ((moves S n).attach.image (fun m => normalKPassNim S (k + 1) m.1))) else 0 termination_by k n => (k, n) decreasing_by · exact Prod.Lex.left _ _ (Nat.lt_succ_self k) · exact Prod.Lex.right _ (mem_moves_lt m.2) abbrev passNim (S : Finset ℕ) (n : ℕ) : ℕ := normalKPassNim S 1 n lemma normalKPassNim_zero (S : Finset ℕ) (n : ℕ) : normalKPassNim S 0 n = nimVal S n := by rw [normalKPassNim] lemma normalKPassNim_succ (S : Finset ℕ) (k n : ℕ) : normalKPassNim S (k + 1) n = if (moves S n).Nonempty then mex (insert (normalKPassNim S k n) ((moves S n).image (normalKPassNim S (k + 1)))) else 0 := by rw [normalKPassNim] split_ifs with hne · congr 2; ext y simp only [Finset.mem_image, Finset.mem_attach, true_and, Subtype.exists] exact ⟨fun ⟨a, ha, h⟩ => ⟨a, ha, h⟩, fun ⟨a, ha, h⟩ => ⟨a, ha, h⟩⟩ · rfl lemma passNim_eq (S : Finset ℕ) (n : ℕ) : passNim S n = if (moves S n).Nonempty then mex (insert (nimVal S n) ((moves S n).image (passNim S))) else 0 := by change normalKPassNim S (0 + 1) n = _ rw [normalKPassNim_succ, normalKPassNim_zero] /-- Single-heap misère Grundy value `misereNimVal S n`. -/ def misereNimVal (S : Finset ℕ) (n : ℕ) : ℕ := if (moves S n).Nonempty then mex ((moves S n).attach.image (fun m => misereNimVal S m.1)) else 1 termination_by n decreasing_by exact mem_moves_lt m.2 lemma misereNimVal_eq (S : Finset ℕ) (n : ℕ) : misereNimVal S n = if (moves S n).Nonempty then mex ((moves S n).image (misereNimVal S)) else 1 := by rw [misereNimVal] split_ifs with hne · congr 1; ext y simp only [Finset.mem_image, Finset.mem_attach, true_and, Subtype.exists] exact ⟨fun ⟨a, ha, h⟩ => ⟨a, ha, h⟩, fun ⟨a, ha, h⟩ => ⟨a, ha, h⟩⟩ · rfl /-- Misère `k`-pass single-heap Grundy value `misereKPassNim S k n`. -/ def misereKPassNim (S : Finset ℕ) : ℕ → ℕ → ℕ | 0, n => misereNimVal S n | k + 1, n => if (moves S n).Nonempty then mex (insert (misereKPassNim S k n) ((moves S n).attach.image (fun m => misereKPassNim S (k + 1) m.1))) else 1 termination_by k n => (k, n) decreasing_by · exact Prod.Lex.left _ _ (Nat.lt_succ_self k) · exact Prod.Lex.right _ (mem_moves_lt m.2) abbrev miserePassNim (S : Finset ℕ) (n : ℕ) : ℕ := misereKPassNim S 1 n lemma misereKPassNim_zero (S : Finset ℕ) (n : ℕ) : misereKPassNim S 0 n = misereNimVal S n := by rw [misereKPassNim] lemma misereKPassNim_succ (S : Finset ℕ) (k n : ℕ) : misereKPassNim S (k + 1) n = if (moves S n).Nonempty then mex (insert (misereKPassNim S k n) ((moves S n).image (misereKPassNim S (k + 1)))) else 1 := by rw [misereKPassNim] split_ifs with hne · congr 2; ext y simp only [Finset.mem_image, Finset.mem_attach, true_and, Subtype.exists] exact ⟨fun ⟨a, ha, h⟩ => ⟨a, ha, h⟩, fun ⟨a, ha, h⟩ => ⟨a, ha, h⟩⟩ · rfl /-- Universal normal-play `k`-pass parity collapse (`k + 2 → k`). -/ theorem normalKPassNim_add_two (S : Finset ℕ) (k : ℕ) : ∀ n, normalKPassNim S (k + 2) n = normalKPassNim S k n := by induction k with | zero => intro n induction n using Nat.strong_induction_on with | h n ih => rw [normalKPassNim_succ, normalKPassNim_zero, nimVal_eq] split_ifs with hne · have himg : (moves S n).image (normalKPassNim S 2) = (moves S n).image (nimVal S) := by apply Finset.image_congr; intro m hm have hih := ih m (mem_moves_lt hm) rw [normalKPassNim_zero] at hih; exact hih rw [himg] have hne10 : normalKPassNim S 1 n ≠ mex ((moves S n).image (nimVal S)) := by change normalKPassNim S (0 + 1) n ≠ _ rw [normalKPassNim_succ, if_pos hne, normalKPassNim_zero, nimVal_eq] intro heq have hmem : mex (insert (mex ((moves S n).image (nimVal S))) ((moves S n).image (normalKPassNim S (0 + 1)))) ∈ insert (mex ((moves S n).image (nimVal S))) ((moves S n).image (normalKPassNim S (0 + 1))) := by rw [heq]; exact Finset.mem_insert_self _ _ exact mex_notMem _ hmem exact mex_insert_ne hne10 · rw [Finset.not_nonempty_iff_eq_empty] at hne rw [hne, Finset.image_empty, mex_empty] | succ k ihk => intro n induction n using Nat.strong_induction_on with | h n ih => rw [normalKPassNim_succ S (k + 2) n, normalKPassNim_succ S k n] split_ifs with hne · have himg : (moves S n).image (normalKPassNim S (k + 3)) = (moves S n).image (normalKPassNim S (k + 1)) := Finset.image_congr fun m hm => ih m (mem_moves_lt hm) rw [himg, ihk n] · rfl /-- Universal misère `k`-pass parity collapse (`k + 2 → k`). -/ theorem misereKPassNim_add_two (S : Finset ℕ) (k : ℕ) : ∀ n, misereKPassNim S (k + 2) n = misereKPassNim S k n := by induction k with | zero => intro n induction n using Nat.strong_induction_on with | h n ih => rw [misereKPassNim_succ, misereKPassNim_zero, misereNimVal_eq] split_ifs with hne · have himg : (moves S n).image (misereKPassNim S 2) = (moves S n).image (misereNimVal S) := by apply Finset.image_congr; intro m hm have hih := ih m (mem_moves_lt hm) rw [misereKPassNim_zero] at hih; exact hih rw [himg] have hne10 : misereKPassNim S 1 n ≠ mex ((moves S n).image (misereNimVal S)) := by change misereKPassNim S (0 + 1) n ≠ _ rw [misereKPassNim_succ, if_pos hne, misereKPassNim_zero, misereNimVal_eq, if_pos hne] intro heq have hmem : mex (insert (mex ((moves S n).image (misereNimVal S))) ((moves S n).image (misereKPassNim S (0 + 1)))) ∈ insert (mex ((moves S n).image (misereNimVal S))) ((moves S n).image (misereKPassNim S (0 + 1))) := by rw [heq]; exact Finset.mem_insert_self _ _ exact mex_notMem _ hmem exact mex_insert_ne hne10 · rfl | succ k ihk => intro n induction n using Nat.strong_induction_on with | h n ih => rw [misereKPassNim_succ S (k + 2) n, misereKPassNim_succ S k n] split_ifs with hne · have himg : (moves S n).image (misereKPassNim S (k + 3)) = (moves S n).image (misereKPassNim S (k + 1)) := Finset.image_congr fun m hm => ih m (mem_moves_lt hm) rw [himg, ihk n] · rfl /-- `IsOneCovered S` and `IsOneCoveredPass S` criteria for universal `τ`-duality. -/ def IsOneCovered (S : Finset ℕ) : Prop := ∀ n, (moves S n).Nonempty → 0 ∈ (moves S n).image (nimVal S) ∨ 1 ∈ (moves S n).image (nimVal S) def IsOneCoveredPass (S : Finset ℕ) : Prop := ∀ n, (moves S n).Nonempty → 0 ∈ insert (nimVal S n) ((moves S n).image (passNim S)) ∨ 1 ∈ insert (nimVal S n) ((moves S n).image (passNim S)) theorem misereNimVal_eq_swap01_of_oneCovered {S : Finset ℕ} (hcov : IsOneCovered S) : ∀ n, misereNimVal S n = swap01 (nimVal S n) := by intro n induction n using Nat.strong_induction_on with | h n ih => rw [misereNimVal_eq, nimVal_eq] split_ifs with hne · have himg : (moves S n).image (misereNimVal S) = ((moves S n).image (nimVal S)).image swap01 := by rw [Finset.image_image] exact Finset.image_congr fun m hm => ih m (mem_moves_lt hm) rw [himg] exact (mex_image_swap01_iff _).mpr (hcov n hne) · rw [Finset.not_nonempty_iff_eq_empty] at hne rw [hne, Finset.image_empty, mex_empty, swap01_zero] theorem miserePassNim_eq_swap01_of_oneCovered {S : Finset ℕ} (hcov : IsOneCovered S) (hcovP : IsOneCoveredPass S) : ∀ n, miserePassNim S n = swap01 (passNim S n) := by have hgm := misereNimVal_eq_swap01_of_oneCovered hcov intro n induction n using Nat.strong_induction_on with | h n ih => change misereKPassNim S (0 + 1) n = _ rw [misereKPassNim_succ, misereKPassNim_zero, passNim_eq] split_ifs with hne · have himg : insert (misereNimVal S n) ((moves S n).image (miserePassNim S)) = (insert (nimVal S n) ((moves S n).image (passNim S))).image swap01 := by rw [Finset.image_insert, Finset.image_image, hgm n] congr 1 exact Finset.image_congr fun m hm => ih m (mem_moves_lt hm) rw [himg] exact (mex_image_swap01_iff _).mpr (hcovP n hne) · rfl theorem misereKPassNim_eq_swap01_of_oneCovered {S : Finset ℕ} (hcov : IsOneCovered S) (hcovP : IsOneCoveredPass S) (k n : ℕ) : misereKPassNim S k n = swap01 (normalKPassNim S k n) := by induction k using Nat.strong_induction_on with | h k ih => match k with | 0 => rw [misereKPassNim_zero, normalKPassNim_zero] exact misereNimVal_eq_swap01_of_oneCovered hcov n | 1 => exact miserePassNim_eq_swap01_of_oneCovered hcov hcovP n | k + 2 => rw [misereKPassNim_add_two, normalKPassNim_add_two] exact ih k (by omega) /-! ### 3. Exact 2-Element Normal Closed Form (Berlekamp–Conway–Guy) -/ def twoElemNim (a b n : ℕ) : ℕ := let m := n % (a + b) if m < b then (m / a) % 2 else if ((m - a) / a) % 2 = 0 then 1 else 2 lemma moves_pair_eq {a b n : ℕ} (ha : 1 ≤ a) (hab : a < b) : moves ({a, b} : Finset ℕ) n = if n < a then ∅ else if n < b then {n - a} else {n - a, n - b} := by ext m simp only [mem_moves_iff, Finset.mem_insert, Finset.mem_singleton] split_ifs with h1 h2 · simp only [Finset.notMem_empty, iff_false, not_exists, not_and] rintro s (rfl | rfl) _ hle _ <;> omega · simp only [Finset.mem_singleton] constructor · rintro ⟨s, rfl | rfl, _, hle, rfl⟩ · rfl · omega · rintro rfl; exact ⟨a, Or.inl rfl, ha, by omega, rfl⟩ · simp only [Finset.mem_insert, Finset.mem_singleton] constructor · rintro ⟨s, rfl | rfl, _, _, rfl⟩ · left; rfl · right; rfl · rintro (rfl | rfl) · exact ⟨a, Or.inl rfl, ha, by omega, rfl⟩ · exact ⟨b, Or.inr rfl, by omega, by omega, rfl⟩ lemma sub_mod_pair {n s P : ℕ} (hsn : s ≤ n) (hsP : s ≤ P) (hP : 0 < P) : (n - s) % P = if s ≤ n % P then n % P - s else n % P + P - s := by have hq : n = P * (n / P) + n % P := (Nat.div_add_mod n P).symm have hmod : n % P < P := Nat.mod_lt n hP split_ifs with hsm · have heq : n - s = P * (n / P) + (n % P - s) := by omega rw [heq, Nat.mul_add_mod, Nat.mod_eq_of_lt (by omega)] · have hq1 : 1 ≤ n / P := by rcases Nat.eq_zero_or_pos (n / P) with hq0 | hqpos · rw [hq0, mul_zero, zero_add] at hq; omega · exact hqpos have heq : n - s = P * (n / P - 1) + (n % P + P - s) := by have : P * (n / P) = P * (n / P - 1) + P := by rw [← mul_add_one, Nat.sub_add_cancel hq1] omega rw [heq, Nat.mul_add_mod, Nat.mod_eq_of_lt (by omega)] theorem nimVal_pair_eq {a b : ℕ} (ha : 1 ≤ a) (hab : a < b) : ∀ n, nimVal ({a, b} : Finset ℕ) n = twoElemNim a b n := by intro n induction n using Nat.strong_induction_on with | h n ih => rw [nimVal_eq, moves_pair_eq ha hab] have hP : 0 < a + b := by omega have hdiv_step : ∀ x : ℕ, a ≤ x → ((x - a) / a) % 2 = 1 - (x / a) % 2 := by intro x hx have h1 : x = (x - a) + a := by omega have h2 : ((x - a) + a) / a = (x - a) / a + 1 := Nat.add_div_right (x - a) (by omega) rw [← h1] at h2; omega split_ifs with hna hnb · rw [Finset.image_empty, mex_empty] dsimp only [twoElemNim] rw [Nat.mod_eq_of_lt (show n < a + b by omega), if_pos (by omega), Nat.div_eq_of_lt hna] · rw [Finset.image_singleton, ih (n - a) (by omega)] dsimp only [twoElemNim] rw [Nat.mod_eq_of_lt (show n - a < a + b by omega), Nat.mod_eq_of_lt (show n < a + b by omega), if_pos (by omega), if_pos (by omega), hdiv_step n (by omega), mex_eq_iff] by_cases hpar : (n / a) % 2 = 0 · rw [hpar]; exact ⟨by simp, fun _ hx => by omega⟩ · have hpar1 : (n / a) % 2 = 1 := by omega rw [hpar1]; simp only [Nat.sub_self] exact ⟨by simp, fun x hx => by have hx0 : x = 0 := (by omega); subst hx0; simp⟩ · rw [Finset.image_insert, Finset.image_singleton, ih (n - a) (by omega), ih (n - b) (by omega)] set m := n % (a + b) with hm_def have hm_lt : m < a + b := Nat.mod_lt n hP have hmod_a := sub_mod_pair (n := n) (s := a) (P := a + b) (by omega) (by omega) hP have hmod_b := sub_mod_pair (n := n) (s := b) (P := a + b) (by omega) (by omega) hP rw [← hm_def] at hmod_a hmod_b dsimp only [twoElemNim] rw [hmod_a, hmod_b, ← hm_def] by_cases hbm : b ≤ m · have ham : a ≤ m := by omega rw [if_pos ham, if_pos hbm, if_pos (by omega : m - a < b), if_pos (by omega : m - b < b), if_neg (by omega : ¬ m < b)] have hmb0 : (m - b) / a = 0 := Nat.div_eq_of_lt (by omega) rw [hmb0, Nat.zero_mod] split_ifs with hpar · rw [hpar, mex_eq_iff] exact ⟨by simp, fun x hx => by have hx0 : x = 0 := (by omega); subst hx0; simp⟩ · have hpar1 : ((m - a) / a) % 2 = 1 := by omega rw [hpar1, mex_eq_iff] exact ⟨by simp, fun x hx => by have : x = 0 ∨ x = 1 := by omega rcases this with rfl | rfl <;> simp⟩ · by_cases ham : a ≤ m · rw [if_pos ham, if_neg hbm, if_pos (by omega : m - a < b), if_pos (by omega : m < b), hdiv_step m ham] by_cases hma_b : m + (a + b) - b < b · rw [if_pos hma_b] have hadd : ((m + (a + b) - b) / a) % 2 = 1 - (m / a) % 2 := by have heq : m + (a + b) - b = m + a := by omega rw [heq, Nat.add_div_right m (by omega)]; omega rw [hadd, mex_eq_iff] by_cases hpar : (m / a) % 2 = 0 · rw [hpar]; exact ⟨by simp, fun _ hx => by omega⟩ · have hpar1 : (m / a) % 2 = 1 := by omega rw [hpar1]; simp only [Nat.sub_self] exact ⟨by simp, fun x hx => by have hx0 : x = 0 := (by omega); rw [hx0]; simp⟩ · rw [if_neg hma_b] have hsub : m + (a + b) - b - a = m := by omega rw [hsub, mex_eq_iff] by_cases hpar : (m / a) % 2 = 0 · rw [hpar, if_pos rfl]; exact ⟨by simp, fun _ hx => by omega⟩ · have hpar1 : (m / a) % 2 = 1 := by omega rw [hpar1, if_neg (by omega)]; simp only [Nat.sub_self] exact ⟨by simp, fun x hx => by have hx0 : x = 0 := (by omega); rw [hx0]; simp⟩ · rw [if_neg ham, if_neg hbm, if_neg (by omega : ¬ m + (a + b) - a < b), if_pos (by omega : m < b)] have hm0 : m / a = 0 := Nat.div_eq_of_lt (by omega) rw [hm0, Nat.zero_mod, mex_eq_iff] refine ⟨?_, fun _ hx => by omega⟩ simp only [Finset.mem_insert, Finset.mem_singleton, not_or] constructor · intro h; split_ifs at h · intro h; split_ifs at h with hma_b have hdiv1 : (m + (a + b) - b) / a = 1 := by have heq : m + (a + b) - b = m + a := by omega rw [heq, Nat.add_div_right m (by omega), hm0] rw [hdiv1] at h; omega lemma two_elem_isOneCovered {a b : ℕ} (ha : 1 ≤ a) (hab : a < b) : IsOneCovered ({a, b} : Finset ℕ) := by intro n hne have hna : a ≤ n := by rw [moves_pair_eq ha hab] at hne by_contra hlt; rw [if_pos (by omega)] at hne; exact absurd hne (by simp) rw [moves_pair_eq ha hab, if_neg (by omega : ¬ n < a)] by_cases hnb : n < b · rw [if_pos hnb, Finset.image_singleton, nimVal_pair_eq ha hab] dsimp only [twoElemNim] rw [Nat.mod_eq_of_lt (show n - a < a + b by omega), if_pos (by omega)] have : ((n - a) / a) % 2 = 0 ∨ ((n - a) / a) % 2 = 1 := by omega rcases this with h | h · left; simp [h] · right; simp [h] · rw [if_neg hnb, Finset.image_insert, Finset.image_singleton, nimVal_pair_eq ha hab, nimVal_pair_eq ha hab] set m := n % (a + b) with hm_def have hm_lt : m < a + b := Nat.mod_lt n (by omega) have hmod_a := sub_mod_pair (n := n) (s := a) (P := a + b) (by omega) (by omega) (by omega) have hmod_b := sub_mod_pair (n := n) (s := b) (P := a + b) (by omega) (by omega) (by omega) rw [← hm_def] at hmod_a hmod_b by_cases hbm : b ≤ m · rw [if_pos hbm] at hmod_b left; apply Finset.mem_insert_of_mem; rw [Finset.mem_singleton] dsimp only [twoElemNim] rw [hmod_b, if_pos (by omega), Nat.div_eq_of_lt (by omega), Nat.zero_mod] · by_cases ham : a ≤ m · rw [if_pos ham] at hmod_a have hval : twoElemNim a b (n - a) = ((m - a) / a) % 2 := by dsimp only [twoElemNim]; rw [hmod_a, if_pos (by omega)] have : ((m - a) / a) % 2 = 0 ∨ ((m - a) / a) % 2 = 1 := by omega rcases this with h | h · left; rw [hval, h]; exact Finset.mem_insert_self _ _ · right; rw [hval, h]; exact Finset.mem_insert_self _ _ · rw [if_neg hbm] at hmod_b right; apply Finset.mem_insert_of_mem; rw [Finset.mem_singleton] dsimp only [twoElemNim] rw [hmod_b] have heq : m + (a + b) - b = m + a := by omega rw [heq] have hm0 : m / a = 0 := Nat.div_eq_of_lt (by omega) split_ifs with hma_b hpar · rw [Nat.add_div_right m (by omega), hm0] · rfl · have : m + a - a = m := by omega rw [this, hm0] at hpar; omega /-! ### 4. THEOREM 1 & 2: Universal 2-Element Pass Collapse & Complete Misère `k`-Pass `τ`-Duality (NEW!) -/ /-- Helper: Structural characterization of `nimVal {a, b} n = 2`. -/ lemma two_elem_nimVal_eq_two_props {a b n : ℕ} (ha : 1 ≤ a) (hab : a < b) (h2 : nimVal ({a, b} : Finset ℕ) n = 2) : b ≤ n ∧ 2 * a ≤ n % (a + b) ∧ nimVal ({a, b} : Finset ℕ) (n - a) = 1 ∧ nimVal ({a, b} : Finset ℕ) (n - b) = 0 ∧ (a ≤ n - b → nimVal ({a, b} : Finset ℕ) (n - a - b) = 2 ∧ nimVal ({a, b} : Finset ℕ) (n - 2 * a) = 0 ∧ a ≤ n - 2 * a) := by rw [nimVal_pair_eq ha hab] at h2 set m := n % (a + b) with hm_def have hm_lt : m < a + b := Nat.mod_lt n (by omega) have hmn : m ≤ n := Nat.mod_le n (a + b) dsimp only [twoElemNim] at h2 rw [← hm_def] at h2 have hbm : b ≤ m := by by_contra hlt; rw [if_pos (by omega)] at h2; omega rw [if_neg (by omega : ¬ m < b)] at h2 have hpar1 : ((m - a) / a) % 2 = 1 := by by_contra h0 have : ((m - a) / a) % 2 = 0 := by omega rw [if_pos this] at h2; omega have hma_ge : a ≤ m - a := by by_contra hlt have : (m - a) / a = 0 := Nat.div_eq_of_lt (by omega) rw [this] at hpar1; omega have hbn : b ≤ n := by omega have hmod_a : (n - a) % (a + b) = m - a := by rw [sub_mod_pair (by omega) (by omega) (by omega), ← hm_def, if_pos (by omega)] have hmod_b : (n - b) % (a + b) = m - b := by rw [sub_mod_pair (by omega) (by omega) (by omega), ← hm_def, if_pos (by omega)] have hna1 : nimVal ({a, b} : Finset ℕ) (n - a) = 1 := by rw [nimVal_pair_eq ha hab]; dsimp only [twoElemNim] rw [hmod_a, if_pos (by omega), hpar1] have hnb0 : nimVal ({a, b} : Finset ℕ) (n - b) = 0 := by rw [nimVal_pair_eq ha hab]; dsimp only [twoElemNim] rw [hmod_b, if_pos (by omega), Nat.div_eq_of_lt (by omega), Nat.zero_mod] refine ⟨hbn, by omega, hna1, hnb0, ?_⟩ intro hnba have hq : n = (a + b) * (n / (a + b)) + m := (Nat.div_add_mod n (a + b)).symm have hq1 : 1 ≤ n / (a + b) := by rcases Nat.eq_zero_or_pos (n / (a + b)) with h0 | hpos · rw [h0, mul_zero, zero_add] at hq; omega · exact hpos have hn_ge : a + b + m ≤ n := by have : (a + b) * 1 ≤ (a + b) * (n / (a + b)) := Nat.mul_le_mul_left _ hq1 omega have hmod_ab : (n - a - b) % (a + b) = m := by have heq : n - a - b = (a + b) * (n / (a + b) - 1) + m := by have : (a + b) * (n / (a + b)) = (a + b) * (n / (a + b) - 1) + (a + b) := by rw [← mul_add_one, Nat.sub_add_cancel hq1] omega rw [heq, Nat.mul_add_mod, Nat.mod_eq_of_lt hm_lt] have hnab2 : nimVal ({a, b} : Finset ℕ) (n - a - b) = 2 := by rw [nimVal_pair_eq ha hab]; dsimp only [twoElemNim] rw [hmod_ab, if_neg (by omega : ¬ m < b), if_neg (by omega)] have hmod_2a : (n - 2 * a) % (a + b) = m - 2 * a := by have heq : n - 2 * a = (a + b) * (n / (a + b)) + (m - 2 * a) := by omega rw [heq, Nat.mul_add_mod, Nat.mod_eq_of_lt (by omega)] have hn2a0 : nimVal ({a, b} : Finset ℕ) (n - 2 * a) = 0 := by rw [nimVal_pair_eq ha hab]; dsimp only [twoElemNim] rw [hmod_2a, if_pos (by omega)] have hstep : m - a = (m - 2 * a) + a := by omega have hdiv : ((m - 2 * a) + a) / a = (m - 2 * a) / a + 1 := Nat.add_div_right _ (by omega) rw [← hstep] at hdiv; omega exact ⟨hnab2, hn2a0, by omega⟩ /-- **THEOREM 1 (Universal 2-Element Pass Collapse Law — NEW!):** For EVERY 2-element subtraction set `S = {a, b}` (`1 ≤ a < b`) and EVERY `n : ℕ`: 1. `nimVal {a, b} n = 2 → passNim {a, b} n = 1`; 2. `nimVal {a, b} n = 1 → passNim {a, b} n = 0 ∨ passNim {a, b} n = 2`! -/ theorem two_elem_passNim_collapse {a b : ℕ} (ha : 1 ≤ a) (hab : a < b) : ∀ n, (nimVal ({a, b} : Finset ℕ) n = 2 → passNim ({a, b} : Finset ℕ) n = 1) ∧ (nimVal ({a, b} : Finset ℕ) n = 1 → passNim ({a, b} : Finset ℕ) n = 0 ∨ passNim ({a, b} : Finset ℕ) n = 2) := by intro n induction n using Nat.strong_induction_on with | h n ih => constructor · -- Part 1: `nimVal {a, b} n = 2 → passNim {a, b} n = 1`! intro h2 obtain ⟨hbn, _, hna1, hnb0, hrest⟩ := two_elem_nimVal_eq_two_props ha hab h2 have hne : (moves ({a, b} : Finset ℕ) n).Nonempty := by rw [moves_pair_eq ha hab, if_neg (by omega), if_neg (by omega)]; simp rw [passNim_eq, if_pos hne, h2, moves_pair_eq ha hab, if_neg (by omega), if_neg (by omega), Finset.image_insert, Finset.image_singleton, mex_eq_iff] have hpa_02 : passNim ({a, b} : Finset ℕ) (n - a) = 0 ∨ passNim ({a, b} : Finset ℕ) (n - a) = 2 := (ih (n - a) (by omega)).2 hna1 by_cases hnba : n - b < a · -- `n - b` is terminal ⇒ `passNim (n - b) = 0`! have hpb0 : passNim ({a, b} : Finset ℕ) (n - b) = 0 := by rw [passNim_eq, moves_pair_eq ha hab, if_pos hnba]; simp rw [hpb0] refine ⟨?_, fun x hx => by have hx0 : x = 0 := (by omega); subst hx0; simp⟩ simp only [Finset.mem_insert, Finset.mem_singleton, not_or] rcases hpa_02 with h | h <;> omega · -- `a ≤ n - b` ⇒ `n - a - b` has `nimVal = 2`, so `passNim (n - a - b) = 1` by IH! obtain ⟨hnab2, hn2a0, hn2a_ge⟩ := hrest (by omega) have hpab1 : passNim ({a, b} : Finset ℕ) (n - a - b) = 1 := (ih (n - a - b) (by omega)).1 hnab2 -- Therefore `passNim (n - b) ≠ 1` (since `n - b - a = n - a - b` is a legal move from `n - b`!) have hpb_ne1 : passNim ({a, b} : Finset ℕ) (n - b) ≠ 1 := by have hne_b : (moves ({a, b} : Finset ℕ) (n - b)).Nonempty := ⟨n - b - a, mem_moves_iff.mpr ⟨a, by simp, ha, by omega, rfl⟩⟩ rw [passNim_eq, if_pos hne_b] intro h1 have hmem : (1 : ℕ) ∈ insert (nimVal ({a, b} : Finset ℕ) (n - b)) ((moves ({a, b} : Finset ℕ) (n - b)).image (passNim ({a, b} : Finset ℕ))) := by apply Finset.mem_insert_of_mem refine Finset.mem_image.mpr ⟨n - b - a, mem_moves_iff.mpr ⟨a, by simp, ha, by omega, rfl⟩, ?_⟩ have heq : n - b - a = n - a - b := by omega rw [heq]; exact hpab1 rw [← h1] at hmem exact mex_notMem _ hmem -- Also `passNim (n - 2 * a) ≠ 0` (since `n - 2 * a` is non-terminal and `nimVal = 0`!) have hp2a_ne0 : passNim ({a, b} : Finset ℕ) (n - 2 * a) ≠ 0 := by have hne_2a : (moves ({a, b} : Finset ℕ) (n - 2 * a)).Nonempty := ⟨n - 2 * a - a, mem_moves_iff.mpr ⟨a, by simp, ha, by omega, rfl⟩⟩ rw [passNim_eq, if_pos hne_2a, hn2a0] intro h0 have hmem : mex (insert 0 ((moves ({a, b} : Finset ℕ) (n - 2 * a)).image (passNim ({a, b} : Finset ℕ)))) ∈ insert 0 ((moves ({a, b} : Finset ℕ) (n - 2 * a)).image (passNim ({a, b} : Finset ℕ))) := by rw [h0]; exact Finset.mem_insert_self _ _ exact mex_notMem _ hmem -- Therefore `passNim (n - a) = 0`! have hpa0 : passNim ({a, b} : Finset ℕ) (n - a) = 0 := by have hne_a : (moves ({a, b} : Finset ℕ) (n - a)).Nonempty := ⟨n - 2 * a, mem_moves_iff.mpr ⟨a, by simp, ha, by omega, by omega⟩⟩ rw [passNim_eq, if_pos hne_a, hna1, moves_pair_eq ha hab, if_neg (by omega : ¬ n - a < a), if_neg (by omega : ¬ n - a < b), Finset.image_insert, Finset.image_singleton, mex_eq_iff] refine ⟨?_, fun _ hx => by omega⟩ simp only [Finset.mem_insert, Finset.mem_singleton, not_or] have h2a_eq : n - a - a = n - 2 * a := by omega rw [h2a_eq, hpab1] exact ⟨by omega, hp2a_ne0.symm, by omega⟩ rw [hpa0] refine ⟨?_, fun x hx => by have hx0 : x = 0 := (by omega); subst hx0; simp⟩ simp only [Finset.mem_insert, Finset.mem_singleton, not_or] exact ⟨by omega, by omega, hpb_ne1.symm⟩ · -- Part 2: `nimVal {a, b} n = 1 → passNim {a, b} n = 0 ∨ passNim {a, b} n = 2`! intro h1 have hna : a ≤ n := by by_contra hlt rw [nimVal_eq, moves_pair_eq ha hab, if_pos (by omega), Finset.image_empty, mex_empty] at h1 omega have hne : (moves ({a, b} : Finset ℕ) n).Nonempty := ⟨n - a, mem_moves_iff.mpr ⟨a, by simp, ha, hna, rfl⟩⟩ rw [passNim_eq, if_pos hne, h1, moves_pair_eq ha hab, if_neg (by omega : ¬ n < a)] by_cases hnb : n < b · rw [if_pos hnb, Finset.image_singleton] by_cases hp0 : passNim ({a, b} : Finset ℕ) (n - a) = 0 · right; rw [hp0, mex_eq_iff] refine ⟨by simp, fun x hx => ?_⟩ have : x = 0 ∨ x = 1 := by omega rcases this with rfl | rfl <;> simp · left; rw [mex_eq_iff] exact ⟨by simp [Ne.symm hp0], fun _ hx => by omega⟩ · rw [if_neg hnb, Finset.image_insert, Finset.image_singleton] -- Since `mex {1, pa, pb} ≠ 1` and `≤ 3`, it fails to be in `{0, 2}` ONLY if `{pa, pb} = {0, 2}`! set pa := passNim ({a, b} : Finset ℕ) (n - a) with hpa_def set pb := passNim ({a, b} : Finset ℕ) (n - b) with hpb_def by_contra hneither push Not at hneither have hge3 : 3 ≤ mex ({1, pa, pb} : Finset ℕ) := by have hne1 : mex ({1, pa, pb} : Finset ℕ) ≠ 1 := by intro h have hmem : mex ({1, pa, pb} : Finset ℕ) ∈ ({1, pa, pb} : Finset ℕ) := by rw [h]; exact Finset.mem_insert_self 1 _ exact mex_notMem _ hmem omega have h0in : (0 : ℕ) ∈ ({1, pa, pb} : Finset ℕ) := mem_of_lt_mex (by omega) have h2in : (2 : ℕ) ∈ ({1, pa, pb} : Finset ℕ) := mem_of_lt_mex (by omega) simp only [Finset.mem_insert, Finset.mem_singleton] at h0in h2in have hpair : (pa = 0 ∧ pb = 2) ∨ (pa = 2 ∧ pb = 0) := by omega -- Neither `n - a` nor `n - b` can have `nimVal = 1` (since `nimVal n = 1`), -- nor `nimVal = 2` (since IH gives `passNim = 1`, contradicting `{pa, pb} = {0, 2}`!). have hga_ne1 : nimVal ({a, b} : Finset ℕ) (n - a) ≠ 1 := by intro hg1 have hmem : (1 : ℕ) ∈ (moves ({a, b} : Finset ℕ) n).image (nimVal ({a, b} : Finset ℕ)) := Finset.mem_image.mpr ⟨n - a, mem_moves_iff.mpr ⟨a, by simp, ha, hna, rfl⟩, hg1⟩ rw [nimVal_eq] at h1; rw [← h1] at hmem; exact mex_notMem _ hmem have hgb_ne1 : nimVal ({a, b} : Finset ℕ) (n - b) ≠ 1 := by intro hg1 have hmem : (1 : ℕ) ∈ (moves ({a, b} : Finset ℕ) n).image (nimVal ({a, b} : Finset ℕ)) := Finset.mem_image.mpr ⟨n - b, mem_moves_iff.mpr ⟨b, by simp, by omega, by omega, rfl⟩, hg1⟩ rw [nimVal_eq] at h1; rw [← h1] at hmem; exact mex_notMem _ hmem have hga_ne2 : nimVal ({a, b} : Finset ℕ) (n - a) ≠ 2 := by intro hg2; have := (ih (n - a) (by omega)).1 hg2; omega have hgb_ne2 : nimVal ({a, b} : Finset ℕ) (n - b) ≠ 2 := by intro hg2; have := (ih (n - b) (by omega)).1 hg2; omega have hle2 : ∀ k, nimVal ({a, b} : Finset ℕ) k ≤ 2 := fun k => by rw [nimVal_pair_eq ha hab]; dsimp only [twoElemNim]; split_ifs <;> omega have hga0 : nimVal ({a, b} : Finset ℕ) (n - a) = 0 := by have := hle2 (n - a); omega have hgb0 : nimVal ({a, b} : Finset ℕ) (n - b) = 0 := by have := hle2 (n - b); omega -- Any non-terminal position with `nimVal = 0` has `passNim ≠ 0`! have hterm_of_0 : ∀ k, nimVal ({a, b} : Finset ℕ) k = 0 → passNim ({a, b} : Finset ℕ) k = 0 → k < a := by intro k hgk hpk by_contra hge have hnek : (moves ({a, b} : Finset ℕ) k).Nonempty := ⟨k - a, mem_moves_iff.mpr ⟨a, by simp, ha, by omega, rfl⟩⟩ rw [passNim_eq, if_pos hnek, hgk] at hpk have hmem : mex (insert 0 ((moves ({a, b} : Finset ℕ) k).image (passNim ({a, b} : Finset ℕ)))) ∈ insert 0 ((moves ({a, b} : Finset ℕ) k).image (passNim ({a, b} : Finset ℕ))) := by rw [hpk]; exact Finset.mem_insert_self _ _ exact mex_notMem _ hmem rcases hpair with ⟨hpa0, hpb2⟩ | ⟨hpa2, hpb0⟩ · -- `pa = 0` ⇒ `n - a < a` ⇒ `n - b < n - a < a` ⇒ `pb = 0`, contradicting `pb = 2`! have hna_lt : n - a < a := hterm_of_0 (n - a) hga0 hpa0 have hpb0 : pb = 0 := by have hmv : moves ({a, b} : Finset ℕ) (n - b) = ∅ := by rw [moves_pair_eq ha hab, if_pos (by omega)] dsimp only [pb]; rw [passNim_eq, hmv]; simp omega · -- `pb = 0` ⇒ `n - b < a` ⇒ `n < a + b`, so `n - a < b`! have hnb_lt : n - b < a := hterm_of_0 (n - b) hgb0 hpb0 have hna_ge : a ≤ n - a := by by_contra hlt have hpa0 : pa = 0 := by have hmv : moves ({a, b} : Finset ℕ) (n - a) = ∅ := by rw [moves_pair_eq ha hab, if_pos (by omega)] dsimp only [pa]; rw [passNim_eq, hmv]; simp omega -- On `a ≤ n - a < b`, `n - a` has ONLY ONE move `n - 2 * a`, with `nimVal (n - 2 * a) = 1`! have hna_lt_b : n - a < b := by omega have h2a_g1 : nimVal ({a, b} : Finset ℕ) (n - 2 * a) = 1 := by rw [nimVal_pair_eq ha hab] at hga0 ⊢ dsimp only [twoElemNim] at hga0 ⊢ rw [Nat.mod_eq_of_lt (show n - a < a + b by omega), if_pos hna_lt_b] at hga0 rw [Nat.mod_eq_of_lt (show n - 2 * a < a + b by omega), if_pos (by omega)] have hstep : n - a = (n - 2 * a) + a := by omega have hdiv : ((n - 2 * a) + a) / a = (n - 2 * a) / a + 1 := Nat.add_div_right _ (by omega) rw [← hstep] at hdiv; omega have hp2a_02 := (ih (n - 2 * a) (by omega)).2 h2a_g1 -- Hence `pa = mex {0, passNim (n - 2 * a)} = 1`, contradicting `pa = 2`! have hpa1 : pa = 1 := by dsimp only [pa] have hne_a : (moves ({a, b} : Finset ℕ) (n - a)).Nonempty := ⟨n - 2 * a, mem_moves_iff.mpr ⟨a, by simp, ha, hna_ge, by omega⟩⟩ rw [passNim_eq, if_pos hne_a, hga0, moves_pair_eq ha hab, if_neg (by omega : ¬ n - a < a), if_pos hna_lt_b, Finset.image_singleton] have h2a_eq : n - a - a = n - 2 * a := by omega rw [h2a_eq, mex_eq_iff] rcases hp2a_02 with h | h <;> rw [h] · exact ⟨by simp, fun x hx => by have hx0 : x = 0 := (by omega); subst hx0; simp⟩ · exact ⟨by simp, fun x hx => by have hx0 : x = 0 := (by omega); subst hx0; simp⟩ omega /-- **THEOREM 2a (Universal 2-Element Pass 1-Coveredness — NEW!):** For EVERY `1 ≤ a < b`, `IsOneCoveredPass {a, b}` holds unconditionally! -/ theorem two_elem_isOneCoveredPass {a b : ℕ} (ha : 1 ≤ a) (hab : a < b) : IsOneCoveredPass ({a, b} : Finset ℕ) := by intro n hne have hle2 : nimVal ({a, b} : Finset ℕ) n ≤ 2 := by rw [nimVal_pair_eq ha hab]; dsimp only [twoElemNim]; split_ifs <;> omega have hcases : nimVal ({a, b} : Finset ℕ) n = 0 ∨ nimVal ({a, b} : Finset ℕ) n = 1 ∨ nimVal ({a, b} : Finset ℕ) n = 2 := by omega rcases hcases with h0 | h1 | h2 · left; rw [h0]; exact Finset.mem_insert_self _ _ · right; rw [h1]; exact Finset.mem_insert_self _ _ · -- `nimVal n = 2` ⇒ `passNim n = 1`, so `0` MUST be in the mex set! have hp1 : passNim ({a, b} : Finset ℕ) n = 1 := (two_elem_passNim_collapse ha hab n).1 h2 rw [passNim_eq, if_pos hne] at hp1 left exact mem_of_lt_mex (by omega : 0 < mex _) /-- **THEOREM 2 (Complete 2-Element Misère–Normal `k`-Pass `τ`-Duality — NEW!):** For EVERY `1 ≤ a < b`, EVERY `k : ℕ`, and EVERY `n : ℕ`: 1. `misereKPassNim {a, b} k n = swap01 (normalKPassNim {a, b} k n)`; 2. `miserePassNim {a, b} n = swap01 (passNim {a, b} n)`; 3. Every `nimVal {a, b} n = 2` position is a misère 1-pass `𝒫`-position (`miserePassNim {a, b} n = 0`)! -/ theorem two_elem_misere_kPass_duality {a b : ℕ} (ha : 1 ≤ a) (hab : a < b) : (∀ k n, misereKPassNim ({a, b} : Finset ℕ) k n = swap01 (normalKPassNim ({a, b} : Finset ℕ) k n)) ∧ (∀ n, miserePassNim ({a, b} : Finset ℕ) n = swap01 (passNim ({a, b} : Finset ℕ) n)) ∧ (∀ n, nimVal ({a, b} : Finset ℕ) n = 2 → miserePassNim ({a, b} : Finset ℕ) n = 0) := by have hcov := two_elem_isOneCovered ha hab have hcovP := two_elem_isOneCoveredPass ha hab refine ⟨fun k n => misereKPassNim_eq_swap01_of_oneCovered hcov hcovP k n, fun n => miserePassNim_eq_swap01_of_oneCovered hcov hcovP n, ?_⟩ intro n h2 rw [miserePassNim_eq_swap01_of_oneCovered hcov hcovP n, (two_elem_passNim_collapse ha hab n).1 h2, swap01_one] /-- Singleton `S = {a}` also satisfies unconditional `k`-pass `τ`-duality. -/ theorem one_elem_misere_kPass_duality {a : ℕ} (ha : 1 ≤ a) : ∀ k n, misereKPassNim ({a} : Finset ℕ) k n = swap01 (normalKPassNim ({a} : Finset ℕ) k n) := by have hmoves : ∀ n, moves ({a} : Finset ℕ) n = if n < a then ∅ else {n - a} := by intro n; ext m; simp only [mem_moves_iff, Finset.mem_singleton] split_ifs with hlt · simp only [Finset.notMem_empty, iff_false, not_exists, not_and]; rintro s rfl _ hle _; omega · simp only [Finset.mem_singleton] exact ⟨fun ⟨s, hs, _, _, hm_eq⟩ => by rw [← hm_eq, hs], fun h => ⟨a, rfl, ha, by omega, h.symm⟩⟩ have hnim : ∀ n, nimVal ({a} : Finset ℕ) n = (n / a) % 2 := by intro n induction n using Nat.strong_induction_on with | h n ih => rw [nimVal_eq, hmoves] split_ifs with hlt · rw [Finset.image_empty, mex_empty, Nat.div_eq_of_lt hlt, Nat.zero_mod] · rw [Finset.image_singleton, ih (n - a) (by omega), mex_eq_iff] have hstep : n = (n - a) + a := by omega have hdiv : ((n - a) + a) / a = (n - a) / a + 1 := Nat.add_div_right _ (by omega) rw [← hstep] at hdiv by_cases hp : (n / a) % 2 = 0 · rw [hp]; exact ⟨by simp; omega, fun _ hx => by omega⟩ · have hp1 : (n / a) % 2 = 1 := by omega rw [hp1] exact ⟨by simp; omega, fun x hx => by have hx0 : x = 0 := (by omega); subst hx0; simp; omega⟩ have hcov : IsOneCovered ({a} : Finset ℕ) := by intro n hne; rw [hmoves] at hne ⊢ split_ifs at hne ⊢ with hlt · exact absurd hne (by simp) · rw [Finset.image_singleton, hnim] have : ((n - a) / a) % 2 = 0 ∨ ((n - a) / a) % 2 = 1 := by omega rcases this with h | h <;> [left; right] <;> simp [h] have hcovP : IsOneCoveredPass ({a} : Finset ℕ) := by intro n _; rw [hnim] have : (n / a) % 2 = 0 ∨ (n / a) % 2 = 1 := by omega rcases this with h | h <;> [left; right] <;> (rw [h]; exact Finset.mem_insert_self _ _) exact fun k n => misereKPassNim_eq_swap01_of_oneCovered hcov hcovP k n /-! ### 5. THEOREM 3: Exact Minimal Cardinality Phase Transition (`|S| ≤ 2` vs `|S| = 3`) & Infinite Family `{1, 2, 3m + 1}` (NEW!) -/ /-- Helper: Legal moves for `S_m = {1, 2, 3 * m + 1}` (`m ≥ 1`). -/ lemma moves_redundant3_eq {m n : ℕ} (hm : 1 ≤ m) : moves ({1, 2, 3 * m + 1} : Finset ℕ) n = if n = 0 then ∅ else if n = 1 then {0} else if n < 3 * m + 1 then {n - 1, n - 2} else {n - 1, n - 2, n - (3 * m + 1)} := by ext y simp only [mem_moves_iff, Finset.mem_insert, Finset.mem_singleton] split_ifs with h0 h1 hlt · simp only [Finset.notMem_empty, iff_false, not_exists, not_and] rintro s (rfl | rfl | rfl) _ hle _ <;> omega · simp only [Finset.mem_singleton] constructor · rintro ⟨s, rfl | rfl | rfl, _, hle, rfl⟩ <;> omega · rintro rfl; exact ⟨1, Or.inl rfl, by omega, by omega, by omega⟩ · simp only [Finset.mem_insert, Finset.mem_singleton] constructor · rintro ⟨s, rfl | rfl | rfl, _, hle, rfl⟩ · left; rfl · right; rfl · omega · rintro (rfl | rfl) · exact ⟨1, Or.inl rfl, by omega, by omega, rfl⟩ · exact ⟨2, Or.inr (Or.inl rfl), by omega, by omega, rfl⟩ · simp only [Finset.mem_insert, Finset.mem_singleton] constructor · rintro ⟨s, rfl | rfl | rfl, _, _, rfl⟩ · left; rfl · right; left; rfl · right; right; rfl · rintro (rfl | rfl | rfl) · exact ⟨1, Or.inl rfl, by omega, by omega, rfl⟩ · exact ⟨2, Or.inr (Or.inl rfl), by omega, by omega, rfl⟩ · exact ⟨3 * m + 1, Or.inr (Or.inr rfl), by omega, by omega, rfl⟩ /-- **THEOREM 3 (Infinite Redundant-Move 3-Element Pass-Duality Breakers — NEW!):** For EVERY `m ≥ 1`, let `S_m = {1, 2, 3 * m + 1}`. Then: 1. `∀ n, nimVal S_m n = n % 3` (identical to `{1, 2}`!); 2. `∀ n, misereNimVal S_m n = swap01 (n % 3)` (base duality holds unconditionally for ALL `n`!); 3. At `n = 3 * m + 2`, misère–normal pass `τ`-duality FAILS: `passNim S_m (3 * m + 2) = 0` AND `miserePassNim S_m (3 * m + 2) = 0 ≠ 1 = swap01 (passNim S_m (3 * m + 2))`! -/ theorem three_elem_redundant_pass_duality_breaks {m : ℕ} (hm : 1 ≤ m) : let S : Finset ℕ := {1, 2, 3 * m + 1} (∀ n, nimVal S n = n % 3) ∧ (∀ n, misereNimVal S n = swap01 (n % 3)) ∧ passNim S (3 * m + 2) = 0 ∧ miserePassNim S (3 * m + 2) = 0 ∧ miserePassNim S (3 * m + 2) ≠ swap01 (passNim S (3 * m + 2)) := by intro S have hnim : ∀ n, nimVal S n = n % 3 := by intro n induction n using Nat.strong_induction_on with | h n ih => rw [nimVal_eq, moves_redundant3_eq hm] split_ifs with h0 h1 hlt · subst h0; simp [mex_empty] · subst h1; rw [Finset.image_singleton, ih 0 (by omega), mex_eq_iff] exact ⟨by simp, fun x hx => by have hx0 : x = 0 := (by omega); subst hx0; simp⟩ · rw [Finset.image_insert, Finset.image_singleton, ih (n - 1) (by omega), ih (n - 2) (by omega), mex_eq_iff] have hmod : n % 3 = 0 ∨ n % 3 = 1 ∨ n % 3 = 2 := by omega rcases hmod with h | h | h · rw [h]; refine ⟨?_, fun _ hx => by omega⟩; simp; omega · rw [h]; refine ⟨by simp; omega, fun x hx => by have hx0 : x = 0 := (by omega); subst hx0; simp; omega⟩ · rw [h]; refine ⟨by simp; omega, fun x hx => by have : x = 0 ∨ x = 1 := by omega rcases this with rfl | rfl · simp only [Finset.mem_insert, Finset.mem_singleton]; right; omega · simp only [Finset.mem_insert, Finset.mem_singleton]; left; omega⟩ · rw [Finset.image_insert, Finset.image_insert, Finset.image_singleton, ih (n - 1) (by omega), ih (n - 2) (by omega), ih (n - (3 * m + 1)) (by omega), mex_eq_iff] have hmod : n % 3 = 0 ∨ n % 3 = 1 ∨ n % 3 = 2 := by omega rcases hmod with h | h | h · rw [h]; refine ⟨?_, fun _ hx => by omega⟩; simp; omega · rw [h]; refine ⟨by simp; omega, fun x hx => by have hx0 : x = 0 := (by omega); subst hx0; simp; omega⟩ · rw [h]; refine ⟨by simp; omega, fun x hx => by have : x = 0 ∨ x = 1 := by omega rcases this with rfl | rfl · simp only [Finset.mem_insert, Finset.mem_singleton]; right; left; omega · simp only [Finset.mem_insert, Finset.mem_singleton]; left; omega⟩ have hcov : IsOneCovered S := by intro n hne rw [moves_redundant3_eq hm] at hne ⊢ split_ifs at hne ⊢ with h0 h1 hlt · exact absurd hne (by simp) · rw [Finset.image_singleton, hnim]; left; simp · rw [Finset.image_insert, Finset.image_singleton, hnim, hnim] have : (n - 1) % 3 = 0 ∨ (n - 1) % 3 = 1 ∨ (n - 2) % 3 = 1 := by omega rcases this with h | h | h · left; simp [h] · right; simp [h] · right; simp [h] · rw [Finset.image_insert, Finset.image_insert, Finset.image_singleton, hnim, hnim, hnim] have : (n - 1) % 3 = 0 ∨ (n - 1) % 3 = 1 ∨ (n - 2) % 3 = 1 := by omega rcases this with h | h | h · left; simp [h] · right; simp [h] · right; simp [h] have hmis : ∀ n, misereNimVal S n = swap01 (n % 3) := fun n => by rw [misereNimVal_eq_swap01_of_oneCovered hcov, hnim] -- Exact closed form of `passNim S n` AND `miserePassNim S n` on `0 ≤ n ≤ 3 * m`! let pref : ℕ → ℕ := fun n => if n = 0 then 0 else if n = 1 then 2 else if n = 2 then 1 else if n = 3 then 3 else if n % 3 = 1 then 0 else if n % 3 = 2 then 1 else 2 have hpref0 : pref 0 = 0 := rfl have hpref1 : pref 1 = 2 := rfl have hpref2 : pref 2 = 1 := rfl have hpref3 : pref 3 = 3 := rfl have hpref4 : pref 4 = 0 := rfl have hpref5 : pref 5 = 1 := rfl have hpref_p : ∀ n ≤ 3 * m, passNim S n = pref n := by intro n induction n using Nat.strong_induction_on with | h n ih => intro hn by_cases h0 : n = 0 · subst h0 have hmv : moves S 0 = ∅ := by rw [moves_redundant3_eq hm]; simp rw [passNim_eq, hmv]; simp [hpref0] · by_cases h1 : n = 1 · subst h1 have hmv : moves S 1 = {0} := by rw [moves_redundant3_eq hm]; simp rw [passNim_eq, hmv, if_pos (by simp), Finset.image_singleton, hnim, ih 0 (by omega) (by omega), hpref0, hpref1, mex_eq_iff] refine ⟨by simp, fun x hx => ?_⟩ have : x = 0 ∨ x = 1 := by omega rcases this with rfl | rfl <;> simp · have hlt : n < 3 * m + 1 := by omega have hmv : moves S n = {n - 1, n - 2} := by rw [moves_redundant3_eq hm, if_neg h0, if_neg h1, if_pos hlt] rw [passNim_eq, hmv, if_pos (by simp), Finset.image_insert, Finset.image_singleton, hnim, ih (n - 1) (by omega) (by omega), ih (n - 2) (by omega) (by omega)] by_cases h2 : n = 2 · subst h2; rw [hpref0, hpref1, hpref2, mex_eq_iff] refine ⟨by simp, fun x hx => ?_⟩ have hx0 : x = 0 := by omega subst hx0; simp · by_cases h3 : n = 3 · subst h3; rw [hpref1, hpref2, hpref3, mex_eq_iff] refine ⟨by simp, fun x hx => ?_⟩ have : x = 0 ∨ x = 1 ∨ x = 2 := by omega rcases this with rfl | rfl | rfl <;> simp · by_cases h4 : n = 4 · subst h4; rw [hpref2, hpref3, hpref4, mex_eq_iff] exact ⟨by simp, fun _ hx => by omega⟩ · by_cases h5 : n = 5 · subst h5; rw [hpref3, hpref4, hpref5, mex_eq_iff] refine ⟨by simp, fun x hx => ?_⟩ have hx0 : x = 0 := by omega subst hx0; simp · -- `6 ≤ n ≤ 3 * m`: pure 3-cycle `[2, 0, 1]`! have hn6 : 6 ≤ n := by omega have hmod : n % 3 = 0 ∨ n % 3 = 1 ∨ n % 3 = 2 := by omega rcases hmod with hr | hr | hr · have hp0 : pref n = 2 := by dsimp only [pref]; split_ifs <;> omega have hp1 : pref (n - 1) = 1 := by dsimp only [pref]; split_ifs <;> omega have hp2 : pref (n - 2) = 0 := by dsimp only [pref]; split_ifs <;> omega rw [hp0, hp1, hp2, hr, mex_eq_iff] refine ⟨by simp, fun x hx => ?_⟩ have : x = 0 ∨ x = 1 := by omega rcases this with rfl | rfl <;> simp · have hp0 : pref n = 0 := by dsimp only [pref]; rw [if_neg h0, if_neg h1, if_neg h2, if_neg h3, if_pos hr] have hp1 : pref (n - 1) = 2 := by dsimp only [pref]; split_ifs <;> omega have hp2 : pref (n - 2) = 1 := by dsimp only [pref]; split_ifs <;> omega rw [hp0, hp1, hp2, hr, mex_eq_iff] exact ⟨by simp, fun _ hx => by omega⟩ · have hp0 : pref n = 1 := by dsimp only [pref]; split_ifs <;> omega have hp1 : pref (n - 1) = 0 := by dsimp only [pref]; split_ifs <;> omega have hp2 : pref (n - 2) = 2 := by dsimp only [pref]; split_ifs <;> omega rw [hp0, hp1, hp2, hr, mex_eq_iff] refine ⟨by simp, fun x hx => ?_⟩ have hx0 : x = 0 := by omega subst hx0; simp have hpref_pm : ∀ n ≤ 3 * m, miserePassNim S n = swap01 (pref n) := by intro n induction n using Nat.strong_induction_on with | h n ih => intro hn change misereKPassNim S (0 + 1) n = _ by_cases h0 : n = 0 · subst h0 have hmv : moves S 0 = ∅ := by rw [moves_redundant3_eq hm]; simp rw [misereKPassNim_succ, hmv]; simp [hpref0] · by_cases h1 : n = 1 · subst h1 have hmv : moves S 1 = {0} := by rw [moves_redundant3_eq hm]; simp rw [misereKPassNim_succ, misereKPassNim_zero, hmis, hmv, if_pos (by simp), Finset.image_singleton] change mex {swap01 (1 % 3), miserePassNim S 0} = swap01 (pref 1) rw [ih 0 (by omega) (by omega), hpref0, hpref1] have hs2 : swap01 2 = 2 := rfl rw [hs2, mex_eq_iff] refine ⟨by simp, fun x hx => ?_⟩ have : x = 0 ∨ x = 1 := by omega rcases this with rfl | rfl <;> simp · have hlt : n < 3 * m + 1 := by omega have hmv : moves S n = {n - 1, n - 2} := by rw [moves_redundant3_eq hm, if_neg h0, if_neg h1, if_pos hlt] rw [misereKPassNim_succ, misereKPassNim_zero, hmis, hmv, if_pos (by simp), Finset.image_insert, Finset.image_singleton] change mex (insert (swap01 (n % 3)) {miserePassNim S (n - 1), miserePassNim S (n - 2)}) = swap01 (pref n) rw [ih (n - 1) (by omega) (by omega), ih (n - 2) (by omega) (by omega)] have himg : insert (swap01 (n % 3)) ({swap01 (pref (n - 1)), swap01 (pref (n - 2))} : Finset ℕ) = ({n % 3, pref (n - 1), pref (n - 2)} : Finset ℕ).image swap01 := by simp [Finset.image_insert] rw [himg] have h01 : (0 : ℕ) ∈ ({n % 3, pref (n - 1), pref (n - 2)} : Finset ℕ) ∨ (1 : ℕ) ∈ ({n % 3, pref (n - 1), pref (n - 2)} : Finset ℕ) := by by_cases hr2 : n % 3 = 2 · -- When `n % 3 = 2`, `n = 2` (`pref 0 = 0`), `n = 5` (`pref 4 = 0`), or `n ≥ 8` (`pref (n-1) = 0`)! left; apply Finset.mem_insert_of_mem by_cases hn2 : n = 2 · subst hn2; simp [pref] · have hge5 : 5 ≤ n := by omega have : pref (n - 1) = 0 := by dsimp only [pref]; split_ifs <;> omega simp [this] · have : n % 3 = 0 ∨ n % 3 = 1 := by omega rcases this with h | h <;> [left; right] <;> simp [h] rw [(mex_image_swap01_iff _).mpr h01] congr 1 have hpn := hpref_p n hn rw [passNim_eq, hmv, if_pos (by simp), Finset.image_insert, Finset.image_singleton, hnim, hpref_p (n - 1) (by omega), hpref_p (n - 2) (by omega)] at hpn exact hpn -- Now evaluate `n = 3 * m + 1` (value `2` if `m = 1`, `3` if `m ≥ 2` — ALWAYS `≥ 2`!) have hmv_3m1 : moves S (3 * m + 1) = {3 * m, 3 * m - 1, 0} := by rw [moves_redundant3_eq hm, if_neg (by omega), if_neg (by omega), if_neg (by omega)] have h1 : 3 * m + 1 - 1 = 3 * m := by omega have h2 : 3 * m + 1 - 2 = 3 * m - 1 := by omega have h3 : 3 * m + 1 - (3 * m + 1) = 0 := by omega rw [h1, h2, h3] have hp_3m1 : 2 ≤ passNim S (3 * m + 1) := by rw [passNim_eq, hmv_3m1, if_pos (by simp), Finset.image_insert, Finset.image_insert, Finset.image_singleton, hnim, hpref_p (3 * m) (by omega), hpref_p (3 * m - 1) (by omega), hpref_p 0 (by omega)] have h0 : pref 0 = 0 := rfl have hm1 : (3 * m + 1) % 3 = 1 := by omega rw [h0, hm1] by_contra hlt have : mex ({1, pref (3 * m), pref (3 * m - 1), 0} : Finset ℕ) = 0 ∨ mex ({1, pref (3 * m), pref (3 * m - 1), 0} : Finset ℕ) = 1 := by omega rcases this with h | h · exact mex_notMem _ (h.symm ▸ (by simp : (0 : ℕ) ∈ _)) · exact mex_notMem _ (h.symm ▸ (by simp : (1 : ℕ) ∈ _)) have hpm_3m1 : 2 ≤ miserePassNim S (3 * m + 1) := by change 2 ≤ misereKPassNim S (0 + 1) (3 * m + 1) rw [misereKPassNim_succ, misereKPassNim_zero, hmis, hmv_3m1, if_pos (by simp), Finset.image_insert, Finset.image_insert, Finset.image_singleton] change 2 ≤ mex (insert (swap01 ((3 * m + 1) % 3)) {miserePassNim S (3 * m), miserePassNim S (3 * m - 1), miserePassNim S 0}) rw [hpref_pm (3 * m) (by omega), hpref_pm (3 * m - 1) (by omega), hpref_pm 0 (by omega)] have h0 : swap01 (pref 0) = 1 := rfl have hm1 : swap01 ((3 * m + 1) % 3) = 0 := by have hm1' : (3 * m + 1) % 3 = 1 := by omega rw [hm1']; rfl rw [h0, hm1] by_contra hlt have : mex ({0, swap01 (pref (3 * m)), swap01 (pref (3 * m - 1)), 1} : Finset ℕ) = 0 ∨ mex ({0, swap01 (pref (3 * m)), swap01 (pref (3 * m - 1)), 1} : Finset ℕ) = 1 := by omega rcases this with h | h · exact mex_notMem _ (h.symm ▸ (by simp : (0 : ℕ) ∈ _)) · exact mex_notMem _ (h.symm ▸ (by simp : (1 : ℕ) ∈ _)) -- Also `pref (3 * m) ≥ 2` (`3` if `m = 1`, `2` if `m ≥ 2`) and `pref 1 = 2`! have hpref_3m : 2 ≤ pref (3 * m) := by dsimp only [pref] split_ifs <;> omega have hpref_1 : pref 1 = 2 := rfl -- Now at `n = 3 * m + 2`: ALL 4 elements in the mex set of BOTH `passNim` and `miserePassNim` are `≥ 2`! have hmv_3m2 : moves S (3 * m + 2) = {3 * m + 1, 3 * m, 1} := by rw [moves_redundant3_eq hm, if_neg (by omega), if_neg (by omega), if_neg (by omega)] have h1 : 3 * m + 2 - 1 = 3 * m + 1 := by omega have h2 : 3 * m + 2 - 2 = 3 * m := by omega have h3 : 3 * m + 2 - (3 * m + 1) = 1 := by omega rw [h1, h2, h3] have hp_3m2 : passNim S (3 * m + 2) = 0 := by rw [passNim_eq, hmv_3m2, if_pos (by simp), Finset.image_insert, Finset.image_insert, Finset.image_singleton, hnim, mex_eq_iff] refine ⟨?_, fun _ hx => by omega⟩ rw [hpref_p (3 * m) (by omega), hpref_p 1 (by omega), hpref_1] simp only [Finset.mem_insert, Finset.mem_singleton, not_or] omega have hpm_3m2 : miserePassNim S (3 * m + 2) = 0 := by change misereKPassNim S (0 + 1) (3 * m + 2) = 0 rw [misereKPassNim_succ, misereKPassNim_zero, hmis, hmv_3m2, if_pos (by simp), Finset.image_insert, Finset.image_insert, Finset.image_singleton, mex_eq_iff] refine ⟨?_, fun _ hx => by omega⟩ have hm2 : swap01 ((3 * m + 2) % 3) = 2 := by have hm2' : (3 * m + 2) % 3 = 2 := by omega rw [hm2']; rfl change 0 ∉ insert (swap01 ((3 * m + 2) % 3)) {miserePassNim S (3 * m + 1), miserePassNim S (3 * m), miserePassNim S 1} rw [hm2, hpref_pm (3 * m) (by omega), hpref_pm 1 (by omega), hpref_1, swap01_of_ge_two hpref_3m] simp only [Finset.mem_insert, Finset.mem_singleton, not_or] have hs2 : swap01 2 = 2 := rfl rw [hs2]; omega refine ⟨hnim, hmis, hp_3m2, hpm_3m2, ?_⟩ rw [hp_3m2, hpm_3m2, swap01_zero]; omega /-- **Corollary 3 (Exact Minimal Cardinality Phase Transition: `|S| ≤ 2` vs `|S| = 3`):** - For EVERY positive subtraction set `S` with `S.card ≤ 2`, misère–normal `k`-pass `τ`-duality holds unconditionally for ALL `k, n : ℕ`; - At `S.card = 3`, it breaks already at `{1, 2, 4}` (`n = 5`)! -/ theorem minimal_cardinality_phase_transition : (∀ S : Finset ℕ, (∀ s ∈ S, 1 ≤ s) → S.card ≤ 2 → ∀ k n, misereKPassNim S k n = swap01 (normalKPassNim S k n)) ∧ (∃ S : Finset ℕ, (∀ s ∈ S, 1 ≤ s) ∧ S.card = 3 ∧ (∀ n, misereNimVal S n = swap01 (nimVal S n)) ∧ ∃ n, miserePassNim S n ≠ swap01 (passNim S n)) := by constructor · intro S hpos hcard k n have hcases : S.card = 0 ∨ S.card = 1 ∨ S.card = 2 := by omega rcases hcases with h0 | h1 | h2 · rw [Finset.card_eq_zero] at h0; subst h0 -- Empty subtraction set: every position is terminal (`0` normal, `1` misère)! have hempty : ∀ m, ¬ (moves ∅ m).Nonempty := fun m ⟨y, hy⟩ => by rcases mem_moves_iff.mp hy with ⟨s, hs, _⟩; exact Finset.notMem_empty s hs match k with | 0 => rw [misereKPassNim_zero, normalKPassNim_zero, misereNimVal_eq, if_neg (hempty n), nimVal_eq, Finset.not_nonempty_iff_eq_empty.mp (hempty n), Finset.image_empty, mex_empty, swap01_zero] | k + 1 => rw [misereKPassNim_succ, if_neg (hempty n), normalKPassNim_succ, if_neg (hempty n), swap01_zero] · obtain ⟨a, rfl⟩ := Finset.card_eq_one.mp h1 exact one_elem_misere_kPass_duality (hpos a (by simp)) k n · obtain ⟨a, b, hab_ne, rfl⟩ := Finset.card_eq_two.mp h2 rcases lt_or_gt_of_ne hab_ne with hlt | hgt · exact (two_elem_misere_kPass_duality (hpos a (by simp)) hlt).1 k n · have heq : ({a, b} : Finset ℕ) = {b, a} := Finset.pair_comm a b rw [heq] exact (two_elem_misere_kPass_duality (hpos b (by simp)) hgt).1 k n · obtain ⟨hnim, hmis, _, _, hne⟩ := three_elem_redundant_pass_duality_breaks (m := 1) (by omega) refine ⟨{1, 2, 4}, ?_, by decide, fun n => by rw [hmis n, hnim n], 5, hne⟩ intro s hs; simp only [Finset.mem_insert, Finset.mem_singleton] at hs rcases hs with rfl | rfl | rfl <;> omega /-! ### 6. PART II: Normal & Misère `k`-Blocking Subtraction Games — Universal Shift & Negation Duality (NEW!) -/ /-- Standard (0-blocking) normal-play outcome (`false = 𝒫`, `true = 𝒩`). -/ def stdOutcome (S : Finset ℕ) (n : ℕ) : Bool := decide (false ∈ (moves S n).attach.image (fun m => stdOutcome S m.1)) termination_by n decreasing_by exact mem_moves_lt m.2 lemma stdOutcome_eq (S : Finset ℕ) (n : ℕ) : stdOutcome S n = decide (∃ m ∈ moves S n, stdOutcome S m = false) := by rw [stdOutcome] congr 1 simp only [Finset.mem_image, Finset.mem_attach, true_and, Subtype.exists] exact propext ⟨fun ⟨m, hm, h⟩ => ⟨m, hm, h⟩, fun ⟨m, hm, h⟩ => ⟨m, hm, h⟩⟩ /-- Normal-play `k`-blocking outcome (`false = 𝒫`, `true = 𝒩`): the opponent blocks up to `k` moves from `moves S n`; the current player wins iff strictly more than `k` legal moves lead to `𝒫`-positions! -/ def normalBlockingOutcome (S : Finset ℕ) (k : ℕ) (n : ℕ) : Bool := decide (k < (((moves S n).attach.image (fun m => (m.1, normalBlockingOutcome S k m.1))).filter (fun p => !p.2)).card) termination_by n decreasing_by exact mem_moves_lt m.2 lemma normalBlockingOutcome_eq (S : Finset ℕ) (k n : ℕ) : normalBlockingOutcome S k n = decide (k < ((moves S n).filter (fun m => normalBlockingOutcome S k m = false)).card) := by rw [normalBlockingOutcome] congr 1 have hcard : (((moves S n).attach.image (fun m => (m.1, normalBlockingOutcome S k m.1))).filter (fun p => !p.2)).card = ((moves S n).filter (fun m => normalBlockingOutcome S k m = false)).card := by apply Finset.card_bij (fun p _ => p.1) · intro p hp rw [Finset.mem_filter, Finset.mem_image] at hp rcases hp.1 with ⟨m, _, rfl⟩ exact Finset.mem_filter.mpr ⟨m.2, by simpa [Bool.not_eq_true'] using hp.2⟩ · intro p₁ hp₁ p₂ hp₂ h rw [Finset.mem_filter, Finset.mem_image] at hp₁ hp₂ rcases hp₁.1 with ⟨m₁, _, rfl⟩ rcases hp₂.1 with ⟨m₂, _, rfl⟩ dsimp only at h exact Prod.ext h (by rw [h]) · intro y hy rw [Finset.mem_filter] at hy refine ⟨(y, normalBlockingOutcome S k y), Finset.mem_filter.mpr ?_, rfl⟩ exact ⟨Finset.mem_image.mpr ⟨⟨y, hy.1⟩, Finset.mem_attach _ _, rfl⟩, by simp [hy.2]⟩ rw [hcard] /-- Misère `k`-blocking outcome (`false = 𝒫`, `true = 𝒩`): the opponent may block ANY subset `B` of `≤ k` legal moves; the current player wins iff for EVERY `|B| ≤ k`, either NO unblocked move remains (immediate misère win!) or at least one unblocked move leads to a `𝒫`-position — equivalently, `P_cnt > k ∨ P_cnt = (moves S n).card`! -/ def misereBlockingOutcome (S : Finset ℕ) (k : ℕ) (n : ℕ) : Bool := let Pcnt := (((moves S n).attach.image (fun m => (m.1, misereBlockingOutcome S k m.1))).filter (fun p => !p.2)).card decide (k < Pcnt ∨ Pcnt = (moves S n).card) termination_by n decreasing_by exact mem_moves_lt m.2 lemma misereBlockingOutcome_eq (S : Finset ℕ) (k n : ℕ) : misereBlockingOutcome S k n = decide (k < ((moves S n).filter (fun m => misereBlockingOutcome S k m = false)).card ∨ ((moves S n).filter (fun m => misereBlockingOutcome S k m = false)).card = (moves S n).card) := by rw [misereBlockingOutcome] have hcard : (((moves S n).attach.image (fun m => (m.1, misereBlockingOutcome S k m.1))).filter (fun p => !p.2)).card = ((moves S n).filter (fun m => misereBlockingOutcome S k m = false)).card := by apply Finset.card_bij (fun p _ => p.1) · intro p hp rw [Finset.mem_filter, Finset.mem_image] at hp rcases hp.1 with ⟨m, _, rfl⟩ exact Finset.mem_filter.mpr ⟨m.2, by simpa [Bool.not_eq_true'] using hp.2⟩ · intro p₁ hp₁ p₂ hp₂ h rw [Finset.mem_filter, Finset.mem_image] at hp₁ hp₂ rcases hp₁.1 with ⟨m₁, _, rfl⟩ rcases hp₂.1 with ⟨m₂, _, rfl⟩ dsimp only at h exact Prod.ext h (by rw [h]) · intro y hy rw [Finset.mem_filter] at hy refine ⟨(y, misereBlockingOutcome S k y), Finset.mem_filter.mpr ?_, rfl⟩ exact ⟨Finset.mem_image.mpr ⟨⟨y, hy.1⟩, Finset.mem_attach _ _, rfl⟩, by simp [hy.2]⟩ rw [hcard] lemma card_moves_le (S : Finset ℕ) (n : ℕ) : (moves S n).card ≤ S.card := by calc (moves S n).card ≤ (S.filter (fun s => 1 ≤ s ∧ s ≤ n)).card := Finset.card_image_le _ ≤ S.card := Finset.card_filter_le _ _ /-- **THEOREM 4a (Universal Over- and Maximal-Blocking Misère Negation Theorem — NEW!):** For EVERY finite subtraction set `S`, EVERY `k ≥ S.card - 1`, and EVERY `n : ℕ`: `misereBlockingOutcome S k n = !(stdOutcome S n)`! (At `k ≥ |S| - 1`, the misère `k`-blocking game is IDENTICALLY the outcome negation of standard 0-blocking normal play!) -/ theorem misere_overblocking_eq_not_std (S : Finset ℕ) {k : ℕ} (hk : S.card - 1 ≤ k) : ∀ n, misereBlockingOutcome S k n = !(stdOutcome S n) := by intro n induction n using Nat.strong_induction_on with | h n ih => rw [misereBlockingOutcome_eq, stdOutcome_eq] have hcm : (moves S n).card ≤ S.card := card_moves_le S n have hfilt_le : ((moves S n).filter (fun m => misereBlockingOutcome S k m = false)).card ≤ (moves S n).card := Finset.card_filter_le _ _ have hiff : (k < ((moves S n).filter (fun m => misereBlockingOutcome S k m = false)).card ∨ ((moves S n).filter (fun m => misereBlockingOutcome S k m = false)).card = (moves S n).card) ↔ ∀ m ∈ moves S n, misereBlockingOutcome S k m = false := by constructor · intro h have heq : ((moves S n).filter (fun m => misereBlockingOutcome S k m = false)).card = (moves S n).card := by omega exact Finset.filter_card_eq heq · intro hall right rw [Finset.filter_true_of_mem hall] have hiff2 : (∀ m ∈ moves S n, misereBlockingOutcome S k m = false) ↔ ¬ (∃ m ∈ moves S n, stdOutcome S m = false) := by push Not constructor · intro h m hm have hm' := h m hm rw [ih m (mem_moves_lt hm)] at hm' cases hstd : stdOutcome S m <;> simp_all · intro h m hm rw [ih m (mem_moves_lt hm)] have hm' := h m hm cases hstd : stdOutcome S m <;> simp_all by_cases hex : ∃ m ∈ moves S n, stdOutcome S m = false · rw [decide_eq_true hex] have hfalse : ¬ (k < ((moves S n).filter (fun m => misereBlockingOutcome S k m = false)).card ∨ ((moves S n).filter (fun m => misereBlockingOutcome S k m = false)).card = (moves S n).card) := by rw [hiff, hiff2]; exact fun h => h hex rw [decide_eq_false hfalse]; rfl · rw [decide_eq_false hex] have htrue : k < ((moves S n).filter (fun m => misereBlockingOutcome S k m = false)).card ∨ ((moves S n).filter (fun m => misereBlockingOutcome S k m = false)).card = (moves S n).card := by rw [hiff, hiff2]; exact hex rw [decide_eq_true htrue]; rfl /-- Helper: For a nonempty positive subtraction set `S` with `M = S.max' hS`, `moves S n` has size `< S.card` whenever `n < M`, and size `= S.card` whenever `M ≤ n`! -/ lemma card_moves_lt_of_lt_max {S : Finset ℕ} (hS : S.Nonempty) (_hpos : ∀ s ∈ S, 1 ≤ s) {n : ℕ} (hlt : n < S.max' hS) : (moves S n).card < S.card := by have hM_mem : S.max' hS ∈ S := Finset.max'_mem S hS have hM_not : S.max' hS ∉ S.filter (fun s => 1 ≤ s ∧ s ≤ n) := by simp only [Finset.mem_filter]; omega have hssub : S.filter (fun s => 1 ≤ s ∧ s ≤ n) ⊂ S := Finset.ssubset_iff_subset_ne.mpr ⟨Finset.filter_subset _ _, fun h => hM_not (h.symm ▸ hM_mem)⟩ calc (moves S n).card ≤ (S.filter (fun s => 1 ≤ s ∧ s ≤ n)).card := Finset.card_image_le _ < S.card := Finset.card_lt_card hssub lemma card_moves_eq_of_ge_max {S : Finset ℕ} (hS : S.Nonempty) (hpos : ∀ s ∈ S, 1 ≤ s) {n : ℕ} (hge : S.max' hS ≤ n) : (moves S n).card = S.card := by have hfilt : S.filter (fun s => 1 ≤ s ∧ s ≤ n) = S := by ext s; simp only [Finset.mem_filter, and_iff_left_iff_imp] intro hs; exact ⟨hpos s hs, le_trans (Finset.le_max' S s hs) hge⟩ rw [moves, hfilt, Finset.card_image_of_injOn] intro s₁ hs₁ s₂ hs₂ hsub dsimp only at hsub have h1 : s₁ ≤ n := le_trans (Finset.le_max' S s₁ hs₁) hge have h2 : s₂ ≤ n := le_trans (Finset.le_max' S s₂ hs₂) hge omega /-- **THEOREM 4b (Universal Maximal-Blocking Normal Shift Theorem — NEW!):** For EVERY finite nonempty positive subtraction set `S` with `M = S.max' hS`: 1. For ALL `n < M`: `normalBlockingOutcome S (S.card - 1) n = false` (`𝒫`); 2. For ALL `n : ℕ`: `normalBlockingOutcome S (S.card - 1) (n + M) = !(stdOutcome S n)`! 3. **Universal Maximal-Blocking Misère–Normal Shift Duality:** `normalBlockingOutcome S (S.card - 1) (n + M) = misereBlockingOutcome S (S.card - 1) n`! -/ theorem maximal_blocking_misere_normal_shift {S : Finset ℕ} (hS : S.Nonempty) (hpos : ∀ s ∈ S, 1 ≤ s) : let M := S.max' hS (∀ n < M, normalBlockingOutcome S (S.card - 1) n = false) ∧ (∀ n, normalBlockingOutcome S (S.card - 1) (n + M) = !(stdOutcome S n)) ∧ (∀ n, normalBlockingOutcome S (S.card - 1) (n + M) = misereBlockingOutcome S (S.card - 1) n) := by intro M have hcard_pos : 1 ≤ S.card := Finset.Nonempty.card_pos hS have hlt_false : ∀ n < M, normalBlockingOutcome S (S.card - 1) n = false := by intro n hlt rw [normalBlockingOutcome_eq, decide_eq_false_iff_not] have hcm : (moves S n).card < S.card := card_moves_lt_of_lt_max hS hpos hlt have hfl : ((moves S n).filter (fun m => normalBlockingOutcome S (S.card - 1) m = false)).card ≤ (moves S n).card := Finset.card_filter_le _ _ omega have hshift : ∀ n, normalBlockingOutcome S (S.card - 1) (n + M) = !(stdOutcome S n) := by intro n induction n using Nat.strong_induction_on with | h n ih => rw [normalBlockingOutcome_eq, stdOutcome_eq] have hcm : (moves S (n + M)).card = S.card := card_moves_eq_of_ge_max hS hpos (by omega) have hfl : ((moves S (n + M)).filter (fun m => normalBlockingOutcome S (S.card - 1) m = false)).card ≤ (moves S (n + M)).card := Finset.card_filter_le _ _ have hiff1 : (S.card - 1 < ((moves S (n + M)).filter (fun m => normalBlockingOutcome S (S.card - 1) m = false)).card) ↔ ∀ m ∈ moves S (n + M), normalBlockingOutcome S (S.card - 1) m = false := by constructor · intro h have heq : ((moves S (n + M)).filter (fun m => normalBlockingOutcome S (S.card - 1) m = false)).card = (moves S (n + M)).card := by omega exact Finset.filter_card_eq heq · intro hall have heq : ((moves S (n + M)).filter (fun m => normalBlockingOutcome S (S.card - 1) m = false)).card = (moves S (n + M)).card := by rw [Finset.filter_true_of_mem hall] omega have hiff2 : (∀ m ∈ moves S (n + M), normalBlockingOutcome S (S.card - 1) m = false) ↔ ¬ (∃ m ∈ moves S n, stdOutcome S m = false) := by push Not constructor · intro hall m hm rcases mem_moves_iff.mp hm with ⟨s, hsS, hs1, hsn, rfl⟩ have hm' : (n - s) + M ∈ moves S (n + M) := mem_moves_iff.mpr ⟨s, hsS, hs1, by omega, by omega⟩ have hf := hall ((n - s) + M) hm' rw [ih (n - s) (by omega)] at hf cases hstd : stdOutcome S (n - s) <;> simp_all · intro hno m hm rcases mem_moves_iff.mp hm with ⟨s, hsS, hs1, hsnM, rfl⟩ by_cases hsn : s ≤ n · have heq : n + M - s = (n - s) + M := by omega rw [heq, ih (n - s) (by omega)] have hne := hno (n - s) (mem_moves_iff.mpr ⟨s, hsS, hs1, hsn, rfl⟩) cases hstd : stdOutcome S (n - s) <;> simp_all · exact hlt_false (n + M - s) (by omega) by_cases hex : ∃ m ∈ moves S n, stdOutcome S m = false · rw [decide_eq_true hex] have hf : ¬ (S.card - 1 < ((moves S (n + M)).filter (fun m => normalBlockingOutcome S (S.card - 1) m = false)).card) := by rw [hiff1, hiff2]; exact fun h => h hex rw [decide_eq_false hf]; rfl · rw [decide_eq_false hex] have ht : S.card - 1 < ((moves S (n + M)).filter (fun m => normalBlockingOutcome S (S.card - 1) m = false)).card := by rw [hiff1, hiff2]; exact hex rw [decide_eq_true ht]; rfl exact ⟨hlt_false, hshift, fun n => by rw [hshift n, misere_overblocking_eq_not_std S (le_refl _) n]⟩ /-- Exact bridge: `stdOutcome S n = false ↔ nimVal S n = 0`! -/ theorem stdOutcome_eq_false_iff_nimVal_eq_zero (S : Finset ℕ) : ∀ n, stdOutcome S n = false ↔ nimVal S n = 0 := by intro n induction n using Nat.strong_induction_on with | h n ih => rw [stdOutcome_eq, nimVal_eq, decide_eq_false_iff_not, mex_eq_iff] simp only [Finset.mem_image, not_exists, not_and, Nat.not_lt_zero, false_imp_iff, forall_true_iff, and_true] constructor · intro h m hm h0; exact h m hm ((ih m (mem_moves_lt hm)).mpr h0) · intro h m hm hf; exact h m hm ((ih m (mem_moves_lt hm)).mp hf) /-- **Corollary 4 (Complete Exact Closed Form of Normal & Misère 1-Blocking on EVERY `{a, b}`):** For EVERY `1 ≤ a < b` and EVERY `n : ℕ`: 1. `misereBlockingOutcome {a, b} 1 n = decide (twoElemNim a b n = 0)` (pure period `a + b`!); 2. `normalBlockingOutcome {a, b} 1 n = false` for `n < b`, and `normalBlockingOutcome {a, b} 1 (n + b) = decide (twoElemNim a b n = 0)`! -/ theorem two_elem_1blocking_exact {a b : ℕ} (ha : 1 ≤ a) (hab : a < b) : (∀ n, misereBlockingOutcome ({a, b} : Finset ℕ) 1 n = decide (twoElemNim a b n = 0)) ∧ (∀ n < b, normalBlockingOutcome ({a, b} : Finset ℕ) 1 n = false) ∧ (∀ n, normalBlockingOutcome ({a, b} : Finset ℕ) 1 (n + b) = decide (twoElemNim a b n = 0)) := by have hS : ({a, b} : Finset ℕ).Nonempty := by simp have hpos : ∀ s ∈ ({a, b} : Finset ℕ), 1 ≤ s := by intro s hs; simp only [Finset.mem_insert, Finset.mem_singleton] at hs rcases hs with rfl | rfl <;> omega have hcard : ({a, b} : Finset ℕ).card = 2 := Finset.card_pair (by omega) have hmax : ({a, b} : Finset ℕ).max' hS = b := by apply le_antisymm · rw [Finset.max'_le_iff]; intro s hs simp only [Finset.mem_insert, Finset.mem_singleton] at hs rcases hs with rfl | rfl <;> omega · exact Finset.le_max' _ b (by simp) obtain ⟨hlt, hsh, _⟩ := maximal_blocking_misere_normal_shift hS hpos rw [hcard, hmax] at hlt hsh have hnot_std : ∀ n, (!stdOutcome ({a, b} : Finset ℕ) n) = decide (twoElemNim a b n = 0) := by intro n have hb := stdOutcome_eq_false_iff_nimVal_eq_zero ({a, b} : Finset ℕ) n rw [nimVal_pair_eq ha hab] at hb cases h : stdOutcome ({a, b} : Finset ℕ) n · rw [decide_eq_true (hb.mp h)]; rfl · have hne : twoElemNim a b n ≠ 0 := fun h0 => by have := hb.mpr h0; rw [h] at this; exact Bool.noConfusion this rw [decide_eq_false hne]; rfl refine ⟨fun n => ?_, hlt, fun n => (hsh n).trans (hnot_std n)⟩ rw [misere_overblocking_eq_not_std ({a, b} : Finset ℕ) (by rw [hcard]) n, hnot_std n] /-! ### 7. THEOREM 5: Complete Exact Classification of Normal & Misère `k`-Blocking Take-Away (`∀ m ≥ 1, 0 ≤ k < m`) -/ /-- Helper: `moves (Icc 1 m) n` is `{n - m, …, n - 1}` (or `{0, …, n - 1}` when `n ≤ m`). -/ lemma moves_Icc_eq {m n : ℕ} : moves (Finset.Icc 1 m) n = if n = 0 then ∅ else if n ≤ m then Finset.range n else Finset.Ico (n - m) n := by ext y simp only [mem_moves_iff, Finset.mem_Icc] split_ifs with h0 hle · simp only [Finset.notMem_empty, iff_false, not_exists, not_and]; rintro s _ _ _ _; omega · simp only [Finset.mem_range] constructor · rintro ⟨s, ⟨h1, _⟩, _, _, rfl⟩; omega · intro hy; exact ⟨n - y, ⟨by omega, by omega⟩, by omega, by omega, by omega⟩ · simp only [Finset.mem_Ico] constructor · rintro ⟨s, ⟨h1, h2⟩, _, _, rfl⟩; omega · rintro ⟨h1, h2⟩; exact ⟨n - y, ⟨by omega, by omega⟩, by omega, by omega, by omega⟩ /-- Helper: Counting residues in `Ico (n - m) n` with `y % (m + 1) ≤ k` when `m < n` and `k < m`. -/ lemma count_mod_le_window {m k n : ℕ} (hm : 1 ≤ m) (hkm : k < m) (hmn : m < n) : ((Finset.Ico (n - m) n).filter (fun y => y % (m + 1) ≤ k)).card = if n % (m + 1) ≤ k then k else k + 1 := by -- Map `y ∈ Ico (n - m) n` bijectively to `y % (m + 1) ∈ (Finset.range (m + 1)).erase (n % (m + 1))`! have hbij : ((Finset.Ico (n - m) n).filter (fun y => y % (m + 1) ≤ k)).card = (((Finset.range (m + 1)).erase (n % (m + 1))).filter (fun r => r ≤ k)).card := by apply Finset.card_bij (fun y _ => y % (m + 1)) · intro y hy rw [Finset.mem_filter, Finset.mem_Ico] at hy rw [Finset.mem_filter, Finset.mem_erase, Finset.mem_range] refine ⟨⟨?_, Nat.mod_lt y (by omega)⟩, hy.2⟩ intro heq have h1 : n - y < m + 1 := by omega have h2 : 1 ≤ n - y := by omega have hdvd : (m + 1) ∣ (n - y) := by have hq1 := (Nat.div_add_mod n (m + 1)).symm have hq2 := (Nat.div_add_mod y (m + 1)).symm refine ⟨n / (m + 1) - y / (m + 1), ?_⟩ rw [Nat.mul_sub] have hle_div : y / (m + 1) ≤ n / (m + 1) := Nat.div_le_div_right (by omega) have : (m + 1) * (y / (m + 1)) ≤ (m + 1) * (n / (m + 1)) := Nat.mul_le_mul_left _ hle_div omega have := Nat.le_of_dvd (by omega) hdvd omega · intro y₁ hy₁ y₂ hy₂ heq rw [Finset.mem_filter, Finset.mem_Ico] at hy₁ hy₂ by_contra hne wlog hlt : y₁ < y₂ generalizing y₁ y₂ · exact this y₂ hy₂ y₁ hy₁ heq.symm (Ne.symm hne) (by omega) have h1 : y₂ - y₁ < m + 1 := by omega have hdvd : (m + 1) ∣ (y₂ - y₁) := by have hq1 := (Nat.div_add_mod y₁ (m + 1)).symm have hq2 := (Nat.div_add_mod y₂ (m + 1)).symm refine ⟨y₂ / (m + 1) - y₁ / (m + 1), ?_⟩ rw [Nat.mul_sub] have : (m + 1) * (y₁ / (m + 1)) ≤ (m + 1) * (y₂ / (m + 1)) := Nat.mul_le_mul_left _ (Nat.div_le_div_right (by omega)) omega have := Nat.le_of_dvd (by omega) hdvd omega · intro r hr rw [Finset.mem_filter, Finset.mem_erase, Finset.mem_range] at hr rcases hr with ⟨⟨hrne, hrm⟩, hrk⟩ -- Explicit preimage `y ∈ Ico (n - m) n` with `y % (m + 1) = r`! set rn := n % (m + 1) with hrn_def have hrn_lt : rn < m + 1 := Nat.mod_lt n (by omega) have hq : n = (m + 1) * (n / (m + 1)) + rn := (Nat.div_add_mod n (m + 1)).symm by_cases hlt : r < rn · refine ⟨(m + 1) * (n / (m + 1)) + r, ?_, ?_⟩ · rw [Finset.mem_filter, Finset.mem_Ico, Nat.mul_add_mod, Nat.mod_eq_of_lt hrm] exact ⟨⟨by omega, by omega⟩, hrk⟩ · rw [Nat.mul_add_mod, Nat.mod_eq_of_lt hrm] · have hq1 : 1 ≤ n / (m + 1) := by rcases Nat.eq_zero_or_pos (n / (m + 1)) with h0 | hpos · rw [h0, mul_zero, zero_add] at hq; omega · exact hpos refine ⟨(m + 1) * (n / (m + 1) - 1) + r, ?_, ?_⟩ · have hmul : (m + 1) * (n / (m + 1)) = (m + 1) * (n / (m + 1) - 1) + (m + 1) := by rw [← mul_add_one, Nat.sub_add_cancel hq1] rw [Finset.mem_filter, Finset.mem_Ico, Nat.mul_add_mod, Nat.mod_eq_of_lt hrm] exact ⟨⟨by omega, by omega⟩, hrk⟩ · rw [Nat.mul_add_mod, Nat.mod_eq_of_lt hrm] rw [hbij] have hfilt_range : (Finset.range (m + 1)).filter (fun r => r ≤ k) = Finset.range (k + 1) := by ext r; simp only [Finset.mem_filter, Finset.mem_range]; omega rw [Finset.filter_erase, hfilt_range] split_ifs with hle · rw [Finset.card_erase_of_mem (Finset.mem_range.mpr (by omega)), Finset.card_range]; omega · rw [Finset.erase_eq_of_notMem (by simp only [Finset.mem_range]; omega), Finset.card_range] /-- **THEOREM 5a (Exact Normal `k`-Blocking Take-Away Classification — ALL `m ≥ 1, 0 ≤ k < m`):** `normalBlockingOutcome (Icc 1 m) k n = decide (k < n % (m + 1))` (pure period `m + 1`, `𝒫`-positions are `n % (m + 1) ≤ k`)! -/ theorem normal_kBlocking_takeAway {m k : ℕ} (hm : 1 ≤ m) (hkm : k < m) : ∀ n, normalBlockingOutcome (Finset.Icc 1 m) k n = decide (k < n % (m + 1)) := by intro n induction n using Nat.strong_induction_on with | h n ih => rw [normalBlockingOutcome_eq, moves_Icc_eq] by_cases h0 : n = 0 · subst h0; simp · by_cases hle : n ≤ m · rw [if_neg h0, if_pos hle, Nat.mod_eq_of_lt (by omega)] have hfilt : (Finset.range n).filter (fun y => normalBlockingOutcome (Finset.Icc 1 m) k y = false) = Finset.range (min n (k + 1)) := by ext y simp only [Finset.mem_filter, Finset.mem_range] constructor · rintro ⟨hy, hf⟩ rw [ih y hy, decide_eq_false_iff_not, Nat.mod_eq_of_lt (by omega)] at hf omega · intro hy refine ⟨by omega, ?_⟩ rw [ih y (by omega), decide_eq_false_iff_not, Nat.mod_eq_of_lt (by omega)] omega rw [hfilt, Finset.card_range] by_cases hkn : k < n · rw [decide_eq_true hkn, decide_eq_true (by omega)] · rw [decide_eq_false hkn, decide_eq_false (by omega)] · rw [if_neg h0, if_neg hle] have hfilt : (Finset.Ico (n - m) n).filter (fun y => normalBlockingOutcome (Finset.Icc 1 m) k y = false) = (Finset.Ico (n - m) n).filter (fun y => y % (m + 1) ≤ k) := by apply Finset.filter_congr intro y hy rw [Finset.mem_Ico] at hy rw [ih y hy.2, decide_eq_false_iff_not] omega rw [hfilt, count_mod_le_window hm hkm (by omega)] split_ifs with hmod · rw [decide_eq_false (by omega), decide_eq_false (by omega)] · rw [decide_eq_true (by omega), decide_eq_true (by omega)] /-- **THEOREM 5b (Exact Misère `k`-Blocking Take-Away Classification & `+1`-Shift Duality — NEW!):** For EVERY `m ≥ 1`, EVERY `0 ≤ k < m`, and EVERY `n : ℕ`: 1. `misereBlockingOutcome (Icc 1 m) k n = decide (n % (m + 1) = 0 ∨ k + 1 < n % (m + 1))` (`𝒫`-positions are `1 ≤ n % (m + 1) ≤ k + 1`, pure period `m + 1`!); 2. Exact `+1`-shift duality: for ALL `n ≥ 1`, `misereBlockingOutcome (Icc 1 m) k n = normalBlockingOutcome (Icc 1 m) k (n - 1)`! -/ theorem misere_kBlocking_takeAway {m k : ℕ} (hm : 1 ≤ m) (hkm : k < m) : (∀ n, misereBlockingOutcome (Finset.Icc 1 m) k n = decide (n % (m + 1) = 0 ∨ k + 1 < n % (m + 1))) ∧ (∀ n, 1 ≤ n → misereBlockingOutcome (Finset.Icc 1 m) k n = normalBlockingOutcome (Finset.Icc 1 m) k (n - 1)) := by have hmain : ∀ n, misereBlockingOutcome (Finset.Icc 1 m) k n = decide (n % (m + 1) = 0 ∨ k + 1 < n % (m + 1)) := by intro n induction n using Nat.strong_induction_on with | h n ih => rw [misereBlockingOutcome_eq, moves_Icc_eq] by_cases h0 : n = 0 · subst h0; simp · by_cases hle : n ≤ m · rw [if_neg h0, if_pos hle, Nat.mod_eq_of_lt (by omega)] have hfilt : (Finset.range n).filter (fun y => misereBlockingOutcome (Finset.Icc 1 m) k y = false) = Finset.Ico 1 (min n (k + 2)) := by ext y simp only [Finset.mem_filter, Finset.mem_range, Finset.mem_Ico] constructor · rintro ⟨hy, hf⟩ rw [ih y hy, decide_eq_false_iff_not, Nat.mod_eq_of_lt (by omega)] at hf omega · intro hy refine ⟨by omega, ?_⟩ rw [ih y (by omega), decide_eq_false_iff_not, Nat.mod_eq_of_lt (by omega)] omega rw [hfilt, Nat.card_Ico, Finset.card_range] by_cases hk1 : k + 1 < n · rw [decide_eq_true (Or.inr hk1), decide_eq_true (Or.inl (by omega))] · rw [decide_eq_false (by omega), decide_eq_false (by omega)] · rw [if_neg h0, if_neg hle] have hfilt : (Finset.Ico (n - m) n).filter (fun y => misereBlockingOutcome (Finset.Icc 1 m) k y = false) = (Finset.Ico (n - m) n).filter (fun y => 1 ≤ y % (m + 1) ∧ y % (m + 1) ≤ k + 1) := by apply Finset.filter_congr intro y hy rw [Finset.mem_Ico] at hy rw [ih y hy.2, decide_eq_false_iff_not] omega -- Shift `y ↦ y - 1` maps `Ico (n - m) n` bijectively to `Ico ((n - 1) - m) (n - 1)` when `m + 1 < n`! -- Even cleaner: count directly via `Finset.card_bij` into `(range (m + 1)).erase (n % (m + 1))`! have hcount : ((Finset.Ico (n - m) n).filter (fun y => 1 ≤ y % (m + 1) ∧ y % (m + 1) ≤ k + 1)).card = if 1 ≤ n % (m + 1) ∧ n % (m + 1) ≤ k + 1 then k else k + 1 := by have hbij : ((Finset.Ico (n - m) n).filter (fun y => 1 ≤ y % (m + 1) ∧ y % (m + 1) ≤ k + 1)).card = (((Finset.range (m + 1)).erase (n % (m + 1))).filter (fun r => 1 ≤ r ∧ r ≤ k + 1)).card := by apply Finset.card_bij (fun y _ => y % (m + 1)) · intro y hy rw [Finset.mem_filter, Finset.mem_Ico] at hy rw [Finset.mem_filter, Finset.mem_erase, Finset.mem_range] refine ⟨⟨?_, Nat.mod_lt y (by omega)⟩, hy.2⟩ intro heq have hdvd : (m + 1) ∣ (n - y) := by have hq1 := (Nat.div_add_mod n (m + 1)).symm have hq2 := (Nat.div_add_mod y (m + 1)).symm refine ⟨n / (m + 1) - y / (m + 1), ?_⟩ rw [Nat.mul_sub] have : (m + 1) * (y / (m + 1)) ≤ (m + 1) * (n / (m + 1)) := Nat.mul_le_mul_left _ (Nat.div_le_div_right (by omega)) omega have := Nat.le_of_dvd (by omega) hdvd; omega · intro y₁ hy₁ y₂ hy₂ heq rw [Finset.mem_filter, Finset.mem_Ico] at hy₁ hy₂ by_contra hne wlog hlt : y₁ < y₂ generalizing y₁ y₂ · exact this y₂ hy₂ y₁ hy₁ heq.symm (Ne.symm hne) (by omega) have hdvd : (m + 1) ∣ (y₂ - y₁) := by have hq1 := (Nat.div_add_mod y₁ (m + 1)).symm have hq2 := (Nat.div_add_mod y₂ (m + 1)).symm refine ⟨y₂ / (m + 1) - y₁ / (m + 1), ?_⟩ rw [Nat.mul_sub] have : (m + 1) * (y₁ / (m + 1)) ≤ (m + 1) * (y₂ / (m + 1)) := Nat.mul_le_mul_left _ (Nat.div_le_div_right (by omega)) omega have := Nat.le_of_dvd (by omega) hdvd; omega · intro r hr rw [Finset.mem_filter, Finset.mem_erase, Finset.mem_range] at hr rcases hr with ⟨⟨hrne, hrm⟩, hrk⟩ set rn := n % (m + 1) with hrn_def have hrn_lt : rn < m + 1 := Nat.mod_lt n (by omega) have hq : n = (m + 1) * (n / (m + 1)) + rn := (Nat.div_add_mod n (m + 1)).symm by_cases hlt : r < rn · refine ⟨(m + 1) * (n / (m + 1)) + r, ?_, ?_⟩ · rw [Finset.mem_filter, Finset.mem_Ico, Nat.mul_add_mod, Nat.mod_eq_of_lt hrm] exact ⟨⟨by omega, by omega⟩, hrk⟩ · rw [Nat.mul_add_mod, Nat.mod_eq_of_lt hrm] · have hq1 : 1 ≤ n / (m + 1) := by rcases Nat.eq_zero_or_pos (n / (m + 1)) with h0 | hpos · rw [h0, mul_zero, zero_add] at hq; omega · exact hpos refine ⟨(m + 1) * (n / (m + 1) - 1) + r, ?_, ?_⟩ · have hmul : (m + 1) * (n / (m + 1)) = (m + 1) * (n / (m + 1) - 1) + (m + 1) := by rw [← mul_add_one, Nat.sub_add_cancel hq1] rw [Finset.mem_filter, Finset.mem_Ico, Nat.mul_add_mod, Nat.mod_eq_of_lt hrm] exact ⟨⟨by omega, by omega⟩, hrk⟩ · rw [Nat.mul_add_mod, Nat.mod_eq_of_lt hrm] rw [hbij, Finset.filter_erase] have hfr : (Finset.range (m + 1)).filter (fun r => 1 ≤ r ∧ r ≤ k + 1) = Finset.Ico 1 (k + 2) := by ext r; simp only [Finset.mem_filter, Finset.mem_range, Finset.mem_Ico]; omega rw [hfr] split_ifs with hr · rw [Finset.card_erase_of_mem (Finset.mem_Ico.mpr (by omega)), Nat.card_Ico]; omega · rw [Finset.erase_eq_of_notMem (by simp only [Finset.mem_Ico]; omega), Nat.card_Ico]; omega rw [hfilt, hcount, Nat.card_Ico] have hsub_eq : n - (n - m) = m := by omega rw [hsub_eq] split_ifs with hr · rw [decide_eq_false (by omega), decide_eq_false (by omega)] · rw [decide_eq_true (Or.inl (by omega)), decide_eq_true (by omega)] refine ⟨hmain, fun n hn1 => ?_⟩ rw [hmain n, normal_kBlocking_takeAway hm hkm (n - 1)] have hmod_sub : (n - 1) % (m + 1) = if n % (m + 1) = 0 then m else n % (m + 1) - 1 := by have h := sub_mod_pair (n := n) (s := 1) (P := m + 1) hn1 (by omega) (by omega) split_ifs at h ⊢ <;> omega rw [hmod_sub] split_ifs with h0 · rw [decide_eq_true (Or.inl h0), decide_eq_true hkm] · by_cases hk1 : k + 1 < n % (m + 1) · rw [decide_eq_true (Or.inr hk1), decide_eq_true (by omega)] · rw [decide_eq_false (by omega), decide_eq_false (by omega)] /-! ### 8. Axiom Audit -/ #print axioms mex_image_swap01_iff #print axioms normalKPassNim_add_two #print axioms misereKPassNim_add_two #print axioms misereKPassNim_eq_swap01_of_oneCovered #print axioms nimVal_pair_eq #print axioms two_elem_passNim_collapse #print axioms two_elem_isOneCoveredPass #print axioms two_elem_misere_kPass_duality #print axioms one_elem_misere_kPass_duality #print axioms three_elem_redundant_pass_duality_breaks #print axioms minimal_cardinality_phase_transition #print axioms misere_overblocking_eq_not_std #print axioms maximal_blocking_misere_normal_shift #print axioms stdOutcome_eq_false_iff_nimVal_eq_zero #print axioms two_elem_1blocking_exact #print axioms normal_kBlocking_takeAway #print axioms misere_kBlocking_takeAway end TwoElemMiserePassAndBlocking