import Mathlib /-! # Universal $k$-Pass Impartial Game Involution Theory, # Complete Classification of Normal & Misère $2$-Blocking Wythoff's Game, # and Exact Freezing Laws for $k$-Blocking Subtraction Games This file establishes a completely self-contained, fully verified Lean 4 formalization of three new theorem suites in combinatorial game theory: 1. **PART I — Universal $k$-Pass Involution Theorem for ARBITRARY Well-Founded Impartial Games:** For ANY state type `α`, ANY finite option function `opts : α → Finset α` strictly descending along a well-founded relation `r`, and ANY terminal Grundy valuation `termVal : α → ℕ` (simultaneously covering Normal play `termVal = 0`, Misère play `termVal = 1`, and arbitrary scored/grafted impartial games): - **THEOREM 1 (`passGrundy_add_two`):** `∀ k u, passGrundy opts hwf termVal (k + 2) u = passGrundy opts hwf termVal k u`! In particular: - **Even-Pass Cancellation (`passGrundy_even`):** ANY even number `2 * m` of shared passes cancels out completely to the pass-free game (`k = 0`)! - **Odd-Pass Equivalence (`passGrundy_odd`):** ANY odd number `2 * m + 1` of shared passes is Grundy-identical to a single shared pass (`k = 1`)! - **Strict Adjacent Separation (`passGrundy_succ_ne`):** For every non-terminal `u`, `passGrundy (k + 1) u ≠ passGrundy k u`. - **THEOREM 2 (`multiPileKPassNim_add_two`, `wythoffKPass_add_two`, `passGrundy_swap01_transfer`):** Immediate concrete instantiations to **arbitrary `n`-pile Normal & Misère `k`-Pass Nim** (`List ℕ` of ANY number of piles!), **Normal & Misère `k`-Pass Wythoff's Game**, and a general hereditary `0 ↔ 1` Misère-Normal transfer theorem. 2. **PART II — Complete Exact Classification of Normal & Misère $2$-Blocking Wythoff's Game (NEW!):** - **THEOREM 3 (`normBlock2Wythoff_exact`):** For ALL `x, y : ℕ`: `normBlockWythoff 2 x y = false ↔ (min x y = 0 ∧ max x y ≤ 2) ∨ (1 ≤ min x y ∧ (max x y = 2 * min x y + 1 ∨ max x y = 2 * min x y + 2))`. - **THEOREM 4 (`misBlock2Wythoff_exact` — FIRST EXACT CLOSED FORM FOR MISÈRE BLOCKING WYTHOFF!):** For ALL `x, y : ℕ`: - `min x y = 0`: `𝒫 ↔ 1 ≤ max x y ∧ max x y ≤ 3`; - `min x y = 1`: `𝒫 ↔ max x y = 1 ∨ max x y = 5`; - `min x y ≥ 2`: `𝒫 ↔ max x y = 2 * min x y ∨ max x y = 2 * min x y + 3`! Revealing that Misère play preserves the exact rational slope `2` of Normal `2`-blocking Wythoff while **splitting the parallel `𝒫`-rays from spacing `1` (`2x+1, 2x+2`) to spacing `3` (`2x, 2x+3`)** and shifting the unique diagonal `𝒫`-position from `(0, 0)` to `(1, 1)`! 3. **PART III — Complete Exact Classification & Freezing Dichotomy for Normal & Misère $k$-Blocking One-Pile Subtraction Games `S = {1, …, m}` (NEW!):** - **THEOREM 5 (`normBlockSub_exact`):** - Collapse regime (`k ≥ m`): `normBlockSub m k x = false` for ALL `x` (total collapse to `𝒫`); - Non-collapse regime (`k < m`): `normBlockSub m k x = false ↔ x % (m + 1) ≤ k`. - **THEOREM 6 (`misBlockSub_exact`, `misBlockSub_freezing_law`, `norm_vs_mis_blockSub_freezing`):** - `m = 1`: `misBlockSub 1 k x = false ↔ x % 2 = 1` for ALL `k, x` (completely independent of `k`!); - `m ≥ 2`: `misBlockSub m k x = false ↔ 1 ≤ x ∧ (x - 1) % (m + 1) ≤ min k (m - 1)` for ALL `k, x`; - **Sharp Freezing Dichotomy:** While Normal `k`-blocking subtraction collapses totally at `k = m`, Misère `k`-blocking subtraction **NEVER collapses** — it freezes permanently at `k = m - 1` for all `k ≥ m - 1`, preserving infinitely many `𝒩`-positions at `x ≡ 0 (mod m + 1)`! -/ namespace UniversalPassInvolutionAndBlockingGames /-! ### 1. Reusable `mex` & `swap01` Toolkit -/ def mex (S : Finset ℕ) : ℕ := ((Finset.range (S.card + 1)).filter (fun n => n ∉ S)).min' (by by_contra hemp rw [Finset.not_nonempty_iff_eq_empty] at hemp have hsub : Finset.range (S.card + 1) ⊆ S := by intro x hx by_contra hnot have : x ∈ (Finset.range (S.card + 1)).filter (fun n => n ∉ S) := Finset.mem_filter.mpr ⟨hx, hnot⟩ rw [hemp] at this; exact Finset.notMem_empty x this have hle := Finset.card_le_card hsub rw [Finset.card_range] at hle; omega) lemma mex_not_mem (S : Finset ℕ) : mex S ∉ S := by unfold mex have hmem := Finset.min'_mem ((Finset.range (S.card + 1)).filter (fun n => n ∉ S)) (by by_contra hemp rw [Finset.not_nonempty_iff_eq_empty] at hemp have hsub : Finset.range (S.card + 1) ⊆ S := by intro x hx; by_contra hnot have : x ∈ (Finset.range (S.card + 1)).filter (fun n => n ∉ S) := Finset.mem_filter.mpr ⟨hx, hnot⟩ rw [hemp] at this; exact Finset.notMem_empty x this have hle := Finset.card_le_card hsub rw [Finset.card_range] at hle; omega) exact (Finset.mem_filter.mp hmem).2 lemma lt_mex_mem {S : Finset ℕ} {m : ℕ} (hm : m < mex S) : m ∈ S := by by_contra hnot have hlt_range : m < S.card + 1 := by have h1 : mex S < S.card + 1 := by unfold mex exact Finset.mem_range.mp (Finset.mem_filter.mp (Finset.min'_mem _ _)).1 omega have hmem : m ∈ (Finset.range (S.card + 1)).filter (fun n => n ∉ S) := Finset.mem_filter.mpr ⟨Finset.mem_range.mpr hlt_range, hnot⟩ have hle : mex S ≤ m := by unfold mex exact Finset.min'_le _ m hmem omega lemma mex_eq_iff {S : Finset ℕ} {v : ℕ} : mex S = v ↔ v ∉ S ∧ ∀ m < v, m ∈ S := by constructor · rintro rfl; exact ⟨mex_not_mem S, fun m hm => lt_mex_mem hm⟩ · rintro ⟨hvnot, hlt⟩ rcases lt_trichotomy (mex S) v with h1 | h2 | h3 · exact absurd (hlt (mex S) h1) (mex_not_mem S) · exact h2 · exact absurd (lt_mex_mem h3) hvnot /-- Key 3-line lemma powering the Universal Even-Pass Involution Theorem: inserting any value `a ≠ mex S` into `S` leaves `mex S` completely unchanged! -/ lemma mex_insert_ne {S : Finset ℕ} {a : ℕ} (hne : a ≠ mex S) : mex (insert a S) = mex S := by rw [mex_eq_iff] refine ⟨?_, fun m hm => Finset.mem_insert_of_mem (lt_mex_mem hm)⟩ rw [Finset.mem_insert]; push Not exact ⟨hne.symm, mex_not_mem S⟩ def swap01 (n : ℕ) : ℕ := if n = 0 then 1 else if n = 1 then 0 else n @[simp] lemma swap01_zero : swap01 0 = 1 := rfl @[simp] lemma swap01_one : swap01 1 = 0 := rfl lemma swap01_ge_two {n : ℕ} (hn : 2 ≤ n) : swap01 n = n := by simp [swap01, show n ≠ 0 by omega, show n ≠ 1 by omega] lemma swap01_invol (n : ℕ) : swap01 (swap01 n) = n := by unfold swap01; split_ifs <;> simp_all lemma swap01_injective : Function.Injective swap01 := Function.LeftInverse.injective swap01_invol /-- Exact necessary and sufficient condition for `mex` to commute with `swap01`: `mex (S.image swap01) = swap01 (mex S) ↔ 0 ∈ S ∨ 1 ∈ S`! -/ theorem mex_image_swap01_iff_mem_zero_or_one (S : Finset ℕ) : mex (S.image swap01) = swap01 (mex S) ↔ 0 ∈ S ∨ 1 ∈ S := by have hmem_img : ∀ v : ℕ, v ∈ S.image swap01 ↔ swap01 v ∈ S := by intro v; constructor · intro h; rcases Finset.mem_image.mp h with ⟨u, hu, rfl⟩; rwa [swap01_invol] · intro h; exact Finset.mem_image.mpr ⟨swap01 v, h, swap01_invol v⟩ constructor · intro heq by_contra hneither; push Not at hneither rcases hneither with ⟨h0, h1⟩ have hmS : mex S = 0 := mex_eq_iff.mpr ⟨h0, fun m hm => by omega⟩ have h0_img : 0 ∉ S.image swap01 := by rw [hmem_img, swap01_zero]; exact h1 have hm_img : mex (S.image swap01) = 0 := mex_eq_iff.mpr ⟨h0_img, fun m hm => by omega⟩ rw [hmS, swap01_zero, hm_img] at heq; omega · intro hor rw [mex_eq_iff] refine ⟨by rw [hmem_img, swap01_invol]; exact mex_not_mem S, ?_⟩ intro m hm rw [hmem_img] by_cases h0 : 0 ∈ S · by_cases h1 : 1 ∈ S · have hge2 : 2 ≤ mex S := by by_contra hlt; push Not at hlt have hnot := mex_not_mem S have : mex S = 0 ∨ mex S = 1 := by omega rcases this with h | h <;> rw [h] at hnot · exact hnot h0 · exact hnot h1 rw [swap01_ge_two hge2] at hm by_cases hm0 : m = 0 · subst hm0; simpa using h1 · by_cases hm1 : m = 1 · subst hm1; simpa using h0 · rw [swap01_ge_two (by omega)]; exact lt_mex_mem hm · have hmS : mex S = 1 := mex_eq_iff.mpr ⟨h1, fun k hk => by have hk0 : k = 0 := by omega subst hk0; exact h0⟩ rw [hmS, swap01_one] at hm; omega · have h1 : 1 ∈ S := hor.resolve_left h0 have hmS : mex S = 0 := mex_eq_iff.mpr ⟨h0, fun k hk => by omega⟩ rw [hmS, swap01_zero] at hm have : m = 0 := by omega subst this; simpa using h1 /-! ### 2. PART I: Universal $k$-Pass Involution Theorem for Arbitrary Well-Founded Impartial Games -/ /-- Lexicographic descent on `(k, u)` for a well-founded game relation `r` on `α`: either `k` decreases (using a pass) or `k` stays equal and `u` descends along `r` (making a move). -/ def passLex {α : Type*} (r : α → α → Prop) : (ℕ × α) → (ℕ × α) → Prop := Prod.Lex (· < ·) r lemma wf_passLex {α : Type*} {r : α → α → Prop} (hwf : WellFounded r) : WellFounded (passLex r) := WellFounded.prod_lex Nat.lt_wfRel.wf hwf /-- Universal `k`-pass Sprague–Grundy function for ANY well-founded impartial game `(α, opts)` with ANY terminal Grundy valuation `termVal : α → ℕ` (Normal play: `termVal = fun _ => 0`; Misère play: `termVal = fun _ => 1`)! -/ noncomputable def passGrundy {α : Type*} [DecidableEq α] (r : α → α → Prop) (hwf : WellFounded r) (opts : α → Finset α) (hdesc : ∀ u, ∀ v ∈ opts u, r v u) (termVal : α → ℕ) (k : ℕ) (u : α) : ℕ := (wf_passLex hwf).fix (fun (p : ℕ × α) (rec : ∀ q, passLex r q p → ℕ) => if hne : (opts p.2).Nonempty then let moveVals : Finset ℕ := (opts p.2).attach.image (fun v => rec (p.1, v.1) (Prod.Lex.right p.1 (hdesc p.2 v.1 v.2))) match hk : p.1 with | 0 => mex moveVals | k' + 1 => mex (insert (rec (k', p.2) (Prod.Lex.left p.2 p.2 (by rw [hk]; exact Nat.lt_succ_self k'))) moveVals) else termVal p.2) (k, u) /-- Clean recursive unfolding equation for `passGrundy`! -/ lemma passGrundy_eq {α : Type*} [DecidableEq α] {r : α → α → Prop} (hwf : WellFounded r) (opts : α → Finset α) (hdesc : ∀ u, ∀ v ∈ opts u, r v u) (termVal : α → ℕ) (k : ℕ) (u : α) : passGrundy r hwf opts hdesc termVal k u = if (opts u).Nonempty then match k with | 0 => mex ((opts u).image (passGrundy r hwf opts hdesc termVal 0)) | k' + 1 => mex (insert (passGrundy r hwf opts hdesc termVal k' u) ((opts u).image (passGrundy r hwf opts hdesc termVal (k' + 1)))) else termVal u := by conv_lhs => unfold passGrundy rw [WellFounded.fix_eq] by_cases hne : (opts u).Nonempty · simp only [hne, ↓reduceDIte, ↓reduceIte] cases k with | zero => dsimp only; congr 1; ext y; simp [passGrundy] | succ k' => dsimp only; congr 1; ext y; simp [passGrundy] · simp only [hne, ↓reduceDIte, ↓reduceIte] lemma passGrundy_terminal {α : Type*} [DecidableEq α] {r : α → α → Prop} (hwf : WellFounded r) (opts : α → Finset α) (hdesc : ∀ u, ∀ v ∈ opts u, r v u) (termVal : α → ℕ) (k : ℕ) {u : α} (hterm : ¬ (opts u).Nonempty) : passGrundy r hwf opts hdesc termVal k u = termVal u := by rw [passGrundy_eq, if_neg hterm] lemma passGrundy_zero {α : Type*} [DecidableEq α] {r : α → α → Prop} (hwf : WellFounded r) (opts : α → Finset α) (hdesc : ∀ u, ∀ v ∈ opts u, r v u) (termVal : α → ℕ) {u : α} (hne : (opts u).Nonempty) : passGrundy r hwf opts hdesc termVal 0 u = mex ((opts u).image (passGrundy r hwf opts hdesc termVal 0)) := by rw [passGrundy_eq, if_pos hne] lemma passGrundy_succ {α : Type*} [DecidableEq α] {r : α → α → Prop} (hwf : WellFounded r) (opts : α → Finset α) (hdesc : ∀ u, ∀ v ∈ opts u, r v u) (termVal : α → ℕ) (k : ℕ) {u : α} (hne : (opts u).Nonempty) : passGrundy r hwf opts hdesc termVal (k + 1) u = mex (insert (passGrundy r hwf opts hdesc termVal k u) ((opts u).image (passGrundy r hwf opts hdesc termVal (k + 1)))) := by rw [passGrundy_eq, if_pos hne] /-- Strict adjacent separation: at EVERY non-terminal position `u`, adding one pass ALWAYS changes the Sprague–Grundy value! -/ theorem passGrundy_succ_ne {α : Type*} [DecidableEq α] {r : α → α → Prop} (hwf : WellFounded r) (opts : α → Finset α) (hdesc : ∀ u, ∀ v ∈ opts u, r v u) (termVal : α → ℕ) (k : ℕ) {u : α} (hne : (opts u).Nonempty) : passGrundy r hwf opts hdesc termVal (k + 1) u ≠ passGrundy r hwf opts hdesc termVal k u := by rw [passGrundy_succ hwf opts hdesc termVal k hne] intro heq exact mex_not_mem _ (by rw [heq]; exact Finset.mem_insert_self _ _) /-- **THEOREM 1 (Universal Even-Pass Involution Theorem for ALL Well-Founded Impartial Games — NEW!):** For EVERY well-founded impartial game `(α, opts)` and EVERY terminal valuation `termVal : α → ℕ` (simultaneously covering Normal play, Misère play, and arbitrary terminal valuations), and EVERY `k : ℕ` and EVERY position `u : α`: `passGrundy (k + 2) u = passGrundy k u`! -/ theorem passGrundy_add_two {α : Type*} [DecidableEq α] {r : α → α → Prop} (hwf : WellFounded r) (opts : α → Finset α) (hdesc : ∀ u, ∀ v ∈ opts u, r v u) (termVal : α → ℕ) : ∀ (u : α) (k : ℕ), passGrundy r hwf opts hdesc termVal (k + 2) u = passGrundy r hwf opts hdesc termVal k u := by intro u induction u using hwf.induction with | h u ih => intro k by_cases hne : (opts u).Nonempty · induction k with | zero => -- Base `k = 0`: `g₂(u) = mex (insert (g₁ u) (image g₂ (opts u))) = mex (insert (g₁ u) (image g₀ (opts u))) = g₀(u)`! rw [passGrundy_succ hwf opts hdesc termVal 1 hne] have himg : (opts u).image (passGrundy r hwf opts hdesc termVal 2) = (opts u).image (passGrundy r hwf opts hdesc termVal 0) := Finset.image_congr (fun v hv => ih v (hdesc u v hv) 0) rw [himg] have hne10 : passGrundy r hwf opts hdesc termVal 1 u ≠ passGrundy r hwf opts hdesc termVal 0 u := passGrundy_succ_ne hwf opts hdesc termVal 0 hne rw [passGrundy_zero hwf opts hdesc termVal hne] at hne10 ⊢ exact mex_insert_ne hne10 | succ k ihk => rw [passGrundy_succ hwf opts hdesc termVal (k + 2) hne, passGrundy_succ hwf opts hdesc termVal k hne] have himg : (opts u).image (passGrundy r hwf opts hdesc termVal (k + 3)) = (opts u).image (passGrundy r hwf opts hdesc termVal (k + 1)) := Finset.image_congr (fun v hv => ih v (hdesc u v hv) (k + 1)) rw [himg, ihk] · rw [passGrundy_terminal hwf opts hdesc termVal (k + 2) hne, passGrundy_terminal hwf opts hdesc termVal k hne] /-- **Corollary 1a (Universal Even-Pass Cancellation):** ANY even number `2 * m` of shared passes cancels out completely to the pass-free game! -/ theorem passGrundy_even {α : Type*} [DecidableEq α] {r : α → α → Prop} (hwf : WellFounded r) (opts : α → Finset α) (hdesc : ∀ u, ∀ v ∈ opts u, r v u) (termVal : α → ℕ) (m : ℕ) (u : α) : passGrundy r hwf opts hdesc termVal (2 * m) u = passGrundy r hwf opts hdesc termVal 0 u := by induction m with | zero => rfl | succ m ih => rw [show 2 * (m + 1) = 2 * m + 2 by omega, passGrundy_add_two, ih] /-- **Corollary 1b (Universal Odd-Pass Reduction):** ANY odd number `2 * m + 1` of shared passes is Grundy-identical to a single shared pass! -/ theorem passGrundy_odd {α : Type*} [DecidableEq α] {r : α → α → Prop} (hwf : WellFounded r) (opts : α → Finset α) (hdesc : ∀ u, ∀ v ∈ opts u, r v u) (termVal : α → ℕ) (m : ℕ) (u : α) : passGrundy r hwf opts hdesc termVal (2 * m + 1) u = passGrundy r hwf opts hdesc termVal 1 u := by induction m with | zero => rfl | succ m ih => rw [show 2 * (m + 1) + 1 = (2 * m + 1) + 2 by omega, passGrundy_add_two, ih] /-- **Corollary 1c (Universal Mod-2 Reduction):** `passGrundy k u = passGrundy (k % 2) u` for ALL `k : ℕ` and ALL `u : α`! -/ theorem passGrundy_mod_two {α : Type*} [DecidableEq α] {r : α → α → Prop} (hwf : WellFounded r) (opts : α → Finset α) (hdesc : ∀ u, ∀ v ∈ opts u, r v u) (termVal : α → ℕ) (k : ℕ) (u : α) : passGrundy r hwf opts hdesc termVal k u = passGrundy r hwf opts hdesc termVal (k % 2) u := by have hk : k = 2 * (k / 2) + k % 2 := (Nat.div_add_mod k 2).symm rcases Nat.mod_two_eq_zero_or_one k with h0 | h1 · rw [h0]; conv_lhs => rw [hk, h0, add_zero] exact passGrundy_even hwf opts hdesc termVal (k / 2) u · rw [h1]; conv_lhs => rw [hk, h1] exact passGrundy_odd hwf opts hdesc termVal (k / 2) u /-- **THEOREM 2a (Hereditary `swap01` Misère–Normal Transfer Theorem for Arbitrary Impartial Games):** If every non-terminal position `u` in `(α, opts)` has a Normal pass-free move to `0` or `1` (i.e. `0 ∈ image G_0 (opts u) ∨ 1 ∈ image G_0 (opts u)` — e.g. every position has a move to a `𝒫`-position or Nim-value-1 position), THEN Normal and Misère `k`-pass Grundy functions are EXACT `swap01`-duals for ALL `k : ℕ` and ALL `u : α`! -/ theorem passGrundy_swap01_transfer {α : Type*} [DecidableEq α] {r : α → α → Prop} (hwf : WellFounded r) (opts : α → Finset α) (hdesc : ∀ u, ∀ v ∈ opts u, r v u) (htame0 : ∀ u, (opts u).Nonempty → 0 ∈ (opts u).image (passGrundy r hwf opts hdesc (fun _ => 0) 0) ∨ 1 ∈ (opts u).image (passGrundy r hwf opts hdesc (fun _ => 0) 0)) (htame1 : ∀ u, (opts u).Nonempty → 0 ∈ insert (passGrundy r hwf opts hdesc (fun _ => 0) 0 u) ((opts u).image (passGrundy r hwf opts hdesc (fun _ => 0) 1)) ∨ 1 ∈ insert (passGrundy r hwf opts hdesc (fun _ => 0) 0 u) ((opts u).image (passGrundy r hwf opts hdesc (fun _ => 0) 1))) : ∀ (k : ℕ) (u : α), passGrundy r hwf opts hdesc (fun _ => 1) k u = swap01 (passGrundy r hwf opts hdesc (fun _ => 0) k u) := by have h0 : ∀ u : α, passGrundy r hwf opts hdesc (fun _ => 1) 0 u = swap01 (passGrundy r hwf opts hdesc (fun _ => 0) 0 u) := by intro u induction u using hwf.induction with | h u ih => by_cases hne : (opts u).Nonempty · rw [passGrundy_zero hwf opts hdesc (fun _ => 1) hne, passGrundy_zero hwf opts hdesc (fun _ => 0) hne] have himg : (opts u).image (passGrundy r hwf opts hdesc (fun _ => 1) 0) = ((opts u).image (passGrundy r hwf opts hdesc (fun _ => 0) 0)).image swap01 := by rw [Finset.image_image] exact Finset.image_congr (fun v hv => ih v (hdesc u v hv)) rw [himg] exact (mex_image_swap01_iff_mem_zero_or_one _).mpr (htame0 u hne) · rw [passGrundy_terminal hwf opts hdesc (fun _ => 1) 0 hne, passGrundy_terminal hwf opts hdesc (fun _ => 0) 0 hne]; rfl have h1 : ∀ u : α, passGrundy r hwf opts hdesc (fun _ => 1) 1 u = swap01 (passGrundy r hwf opts hdesc (fun _ => 0) 1 u) := by intro u induction u using hwf.induction with | h u ih => by_cases hne : (opts u).Nonempty · rw [passGrundy_succ hwf opts hdesc (fun _ => 1) 0 hne, passGrundy_succ hwf opts hdesc (fun _ => 0) 0 hne, h0 u] have himg : insert (swap01 (passGrundy r hwf opts hdesc (fun _ => 0) 0 u)) ((opts u).image (passGrundy r hwf opts hdesc (fun _ => 1) 1)) = (insert (passGrundy r hwf opts hdesc (fun _ => 0) 0 u) ((opts u).image (passGrundy r hwf opts hdesc (fun _ => 0) 1))).image swap01 := by rw [Finset.image_insert, Finset.image_image] congr 1 exact Finset.image_congr (fun v hv => ih v (hdesc u v hv)) rw [himg] exact (mex_image_swap01_iff_mem_zero_or_one _).mpr (htame1 u hne) · rw [passGrundy_terminal hwf opts hdesc (fun _ => 1) 1 hne, passGrundy_terminal hwf opts hdesc (fun _ => 0) 1 hne]; rfl intro k u rw [passGrundy_mod_two hwf opts hdesc (fun _ => 1) k u, passGrundy_mod_two hwf opts hdesc (fun _ => 0) k u] rcases Nat.mod_two_eq_zero_or_one k with hk | hk <;> rw [hk] · exact h0 u · exact h1 u /-! #### Concrete Instantiations of Theorem 1: Arbitrary `n`-Pile Nim & Wythoff's Game with `k` Passes -/ /-- All single-pile reduction moves from an arbitrary list of piles `ps : List ℕ` (ANY number of piles `n`!). -/ def multiPileMoves : List ℕ → Finset (List ℕ) | [] => ∅ | x :: xs => ((Finset.range x).image (fun a => a :: xs)) ∪ ((multiPileMoves xs).image (fun ys => x :: ys)) lemma multiPileMoves_sum_lt : ∀ (ps : List ℕ) (qs : List ℕ), qs ∈ multiPileMoves ps → qs.sum < ps.sum | [], qs, h => by simp [multiPileMoves] at h | x :: xs, qs, h => by simp only [multiPileMoves, Finset.mem_union, Finset.mem_image, Finset.mem_range] at h rcases h with ⟨a, ha, rfl⟩ | ⟨ys, hys, rfl⟩ · simp only [List.sum_cons]; omega · have := multiPileMoves_sum_lt xs ys hys simp only [List.sum_cons]; omega noncomputable def multiPileNormKPassNim (k : ℕ) (ps : List ℕ) : ℕ := passGrundy (InvImage (· < ·) List.sum) (InvImage.wf List.sum Nat.lt_wfRel.wf) multiPileMoves multiPileMoves_sum_lt (fun _ => 0) k ps noncomputable def multiPileMisKPassNim (k : ℕ) (ps : List ℕ) : ℕ := passGrundy (InvImage (· < ·) List.sum) (InvImage.wf List.sum Nat.lt_wfRel.wf) multiPileMoves multiPileMoves_sum_lt (fun _ => 1) k ps /-- **THEOREM 2b (Universal Even-Pass Cancellation for Arbitrary `n`-Pile Normal & Misère Nim!):** For EVERY finite list of piles `ps : List ℕ` (ANY number of piles `n`) and EVERY `k : ℕ`: `multiPileNormKPassNim (k + 2) ps = multiPileNormKPassNim k ps` and `multiPileMisKPassNim (k + 2) ps = multiPileMisKPassNim k ps`! -/ theorem multiPileKPassNim_add_two (k : ℕ) (ps : List ℕ) : multiPileNormKPassNim (k + 2) ps = multiPileNormKPassNim k ps ∧ multiPileMisKPassNim (k + 2) ps = multiPileMisKPassNim k ps := ⟨passGrundy_add_two _ _ _ _ ps k, passGrundy_add_two _ _ _ _ ps k⟩ /-! ### 3. PART II: Complete Exact Classification of Normal & Misère $2$-Blocking Wythoff's Game (NEW!) -/ /-- All legal Wythoff moves from `(x, y)`: horizontal left, vertical down, or diagonal down-left. -/ def wythoffMoves (x y : ℕ) : Finset (ℕ × ℕ) := ((Finset.range x).image (fun a => (a, y))) ∪ ((Finset.range y).image (fun b => (x, b))) ∪ ((Finset.range (min x y)).image (fun a => (a, a + (y - x)))) lemma wythoffMoves_mem_iff (x y : ℕ) (hxy : x ≤ y) (p : ℕ × ℕ) : p ∈ wythoffMoves x y ↔ (p.1 < x ∧ p.2 = y) ∨ (p.1 = x ∧ p.2 < y) ∨ (p.1 < x ∧ p.2 = p.1 + (y - x)) := by simp only [wythoffMoves, Nat.min_eq_left hxy, Finset.mem_union, Finset.mem_image, Finset.mem_range] constructor · rintro ((⟨a, ha, rfl⟩ | ⟨b, hb, rfl⟩) | ⟨a, ha, rfl⟩) · exact Or.inl ⟨ha, rfl⟩ · exact Or.inr (Or.inl ⟨rfl, hb⟩) · exact Or.inr (Or.inr ⟨ha, rfl⟩) · rintro (⟨h1, h2⟩ | ⟨h1, h2⟩ | ⟨h1, h2⟩) · left; left; exact ⟨p.1, h1, Prod.ext rfl h2.symm⟩ · left; right; exact ⟨p.2, h2, Prod.ext h1.symm rfl⟩ · right; exact ⟨p.1, h1, Prod.ext rfl h2.symm⟩ /-- Clean symmetric version of `wythoffMoves` for general `(x, y)` (using `d ∈ Icc 1 (min x y)`). -/ def symWythoffMoves (x y : ℕ) : Finset (ℕ × ℕ) := ((Finset.range x).image (fun a => (a, y))) ∪ ((Finset.range y).image (fun b => (x, b))) ∪ ((Finset.Icc 1 (min x y)).image (fun d => (x - d, y - d))) lemma mem_symWythoffMoves_sum_lt {x y : ℕ} {p : ℕ × ℕ} (hp : p ∈ symWythoffMoves x y) : p.1 + p.2 < x + y := by simp only [symWythoffMoves, Finset.mem_union, Finset.mem_image, Finset.mem_range, Finset.mem_Icc] at hp rcases hp with ((⟨a, ha, rfl⟩ | ⟨b, hb, rfl⟩) | ⟨d, hd, rfl⟩) <;> omega lemma symWythoffMoves_swap (x y : ℕ) : (symWythoffMoves x y).image Prod.swap = symWythoffMoves y x := by ext ⟨u, v⟩ simp only [Finset.mem_image, symWythoffMoves, Finset.mem_union, Finset.mem_range, Finset.mem_Icc] constructor · rintro ⟨⟨p1, p2⟩, ((⟨a, ha, h⟩ | ⟨b, hb, h⟩) | ⟨d, hd, h⟩), hsw⟩ · simp only [Prod.mk.injEq] at h; simp only [Prod.swap, Prod.mk.injEq] at hsw left; right; exact ⟨a, ha, Prod.ext (by omega) (by omega)⟩ · simp only [Prod.mk.injEq] at h; simp only [Prod.swap, Prod.mk.injEq] at hsw left; left; exact ⟨b, hb, Prod.ext (by omega) (by omega)⟩ · simp only [Prod.mk.injEq] at h; simp only [Prod.swap, Prod.mk.injEq] at hsw right; exact ⟨d, by omega, Prod.ext (by omega) (by omega)⟩ · rintro ((⟨b, hb, h⟩ | ⟨a, ha, h⟩) | ⟨d, hd, h⟩) · simp only [Prod.mk.injEq] at h exact ⟨(x, b), Or.inl (Or.inr ⟨b, hb, rfl⟩), Prod.ext (by simp; omega) (by simp; omega)⟩ · simp only [Prod.mk.injEq] at h exact ⟨(a, y), Or.inl (Or.inl ⟨a, ha, rfl⟩), Prod.ext (by simp; omega) (by simp; omega)⟩ · simp only [Prod.mk.injEq] at h exact ⟨(x - d, y - d), Or.inr ⟨d, by omega, rfl⟩, Prod.ext (by simp; omega) (by simp; omega)⟩ lemma card_symWythoffMoves (x y : ℕ) : (symWythoffMoves x y).card = x + y + min x y := by have hd1 : Disjoint ((Finset.range x).image (fun a => (a, y))) ((Finset.range y).image (fun b => (x, b))) := by rw [Finset.disjoint_left]; intro p h1 h2 rcases Finset.mem_image.mp h1 with ⟨a, ha, rfl⟩ rcases Finset.mem_image.mp h2 with ⟨b, hb, heq⟩ simp only [Finset.mem_range, Prod.mk.injEq] at ha hb heq; omega have hd2 : Disjoint (((Finset.range x).image (fun a => (a, y))) ∪ ((Finset.range y).image (fun b => (x, b)))) ((Finset.Icc 1 (min x y)).image (fun d => (x - d, y - d))) := by rw [Finset.disjoint_left]; intro p h1 h2 rcases Finset.mem_image.mp h2 with ⟨d, hd, rfl⟩ rw [Finset.mem_Icc] at hd rcases Finset.mem_union.mp h1 with h1 | h1 <;> rcases Finset.mem_image.mp h1 with ⟨c, hc, heq⟩ <;> simp only [Finset.mem_range, Prod.mk.injEq] at hc heq <;> omega rw [symWythoffMoves, Finset.card_union_of_disjoint hd2, Finset.card_union_of_disjoint hd1] have hc1 : ((Finset.range x).image (fun a => (a, y))).card = x := by rw [Finset.card_image_of_injective _ (fun _ _ h => (Prod.mk.inj h).1), Finset.card_range] have hc2 : ((Finset.range y).image (fun b => (x, b))).card = y := by rw [Finset.card_image_of_injective _ (fun _ _ h => (Prod.mk.inj h).2), Finset.card_range] have hc3 : ((Finset.Icc 1 (min x y)).image (fun d => (x - d, y - d))).card = min x y := by rw [Finset.card_image_of_injOn] · rw [Nat.card_Icc]; omega · intro d₁ hd₁ d₂ hd₂ heq rw [Finset.mem_coe, Finset.mem_Icc] at hd₁ hd₂ have := (Prod.mk.inj heq).1; omega rw [hc1, hc2, hc3] lemma card_filter_symWythoffMoves (P : ℕ → ℕ → Prop) [DecidableRel P] (x y : ℕ) (hxy : x ≤ y) : ((symWythoffMoves x y).filter (fun p => P p.1 p.2)).card = ((Finset.range x).filter (fun a => P a y)).card + ((Finset.range y).filter (fun b => P x b)).card + ((Finset.range x).filter (fun a => P a (a + (y - x)))).card := by have hd1 : Disjoint ((Finset.range x).image (fun a => (a, y))) ((Finset.range y).image (fun b => (x, b))) := by rw [Finset.disjoint_left]; intro p h1 h2 rcases Finset.mem_image.mp h1 with ⟨a, ha, rfl⟩ rcases Finset.mem_image.mp h2 with ⟨b, hb, heq⟩ simp only [Finset.mem_range, Prod.mk.injEq] at ha hb heq; omega have hd2 : Disjoint (((Finset.range x).image (fun a => (a, y))) ∪ ((Finset.range y).image (fun b => (x, b)))) ((Finset.Icc 1 (min x y)).image (fun d => (x - d, y - d))) := by rw [Finset.disjoint_left]; intro p h1 h2 rcases Finset.mem_image.mp h2 with ⟨d, hd, rfl⟩ rw [Finset.mem_Icc] at hd rcases Finset.mem_union.mp h1 with h1 | h1 <;> rcases Finset.mem_image.mp h1 with ⟨c, hc, heq⟩ <;> simp only [Finset.mem_range, Prod.mk.injEq] at hc heq <;> omega rw [symWythoffMoves, Finset.filter_union, Finset.card_union_of_disjoint (Finset.disjoint_filter_filter hd2), Finset.filter_union, Finset.card_union_of_disjoint (Finset.disjoint_filter_filter hd1)] congr 1 · congr 1 · rw [Finset.filter_image, Finset.card_image_of_injective _ (fun _ _ h => (Prod.mk.inj h).1)] · rw [Finset.filter_image, Finset.card_image_of_injective _ (fun _ _ h => (Prod.mk.inj h).2)] · rw [Nat.min_eq_left hxy] apply Finset.card_bij (fun p _ => p.1) · intro p hp rw [Finset.mem_filter, Finset.mem_image] at hp rcases hp with ⟨⟨d, hd, rfl⟩, hP⟩ rw [Finset.mem_Icc] at hd refine Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by omega), ?_⟩ have heq : x - d + (y - x) = y - d := by omega rwa [heq] · intro p₁ hp₁ p₂ hp₂ hfst rw [Finset.mem_filter, Finset.mem_image] at hp₁ hp₂ rcases hp₁ with ⟨⟨d₁, hd₁, rfl⟩, _⟩; rcases hp₂ with ⟨⟨d₂, hd₂, rfl⟩, _⟩ rw [Finset.mem_Icc] at hd₁ hd₂ exact Prod.ext hfst (by omega) · intro a ha rw [Finset.mem_filter, Finset.mem_range] at ha refine ⟨(a, a + (y - x)), ?_, rfl⟩ refine Finset.mem_filter.mpr ⟨Finset.mem_image.mpr ⟨x - a, Finset.mem_Icc.mpr ⟨by omega, by omega⟩, Prod.ext (by omega) (by omega)⟩, ha.2⟩ /-- Also instantiate Universal Even-Pass Involution directly to `k`-Pass Wythoff's Game! -/ noncomputable def normKPassWythoff (k : ℕ) (p : ℕ × ℕ) : ℕ := passGrundy (InvImage (· < ·) (fun q : ℕ × ℕ => q.1 + q.2)) (InvImage.wf (fun q : ℕ × ℕ => q.1 + q.2) Nat.lt_wfRel.wf) (fun q => symWythoffMoves q.1 q.2) (fun _ _ hv => mem_symWythoffMoves_sum_lt hv) (fun _ => 0) k p noncomputable def misKPassWythoff (k : ℕ) (p : ℕ × ℕ) : ℕ := passGrundy (InvImage (· < ·) (fun q : ℕ × ℕ => q.1 + q.2)) (InvImage.wf (fun q : ℕ × ℕ => q.1 + q.2) Nat.lt_wfRel.wf) (fun q => symWythoffMoves q.1 q.2) (fun _ _ hv => mem_symWythoffMoves_sum_lt hv) (fun _ => 1) k p /-- **THEOREM 2c (Universal Even-Pass Cancellation for Normal & Misère `k`-Pass Wythoff's Game!):** -/ theorem wythoffKPass_add_two (k x y : ℕ) : normKPassWythoff (k + 2) (x, y) = normKPassWythoff k (x, y) ∧ misKPassWythoff (k + 2) (x, y) = misKPassWythoff k (x, y) := ⟨passGrundy_add_two _ _ _ _ (x, y) k, passGrundy_add_two _ _ _ _ (x, y) k⟩ /-- Normal `k`-Blocking Wythoff's Game: `true = 𝒩`, `false = 𝒫`. -/ def normBlockWythoff (k : ℕ) : ℕ → ℕ → Bool := fun x y => (InvImage.wf (fun q : ℕ × ℕ => q.1 + q.2) Nat.lt_wfRel.wf).fix (fun p rec => let Pcnt := ((symWythoffMoves p.1 p.2).attach.filter (fun q => rec q.1 (mem_symWythoffMoves_sum_lt q.2) = false)).card decide (k < Pcnt)) (x, y) lemma normBlockWythoff_eq (k x y : ℕ) : normBlockWythoff k x y = decide (k < ((symWythoffMoves x y).filter (fun p => normBlockWythoff k p.1 p.2 = false)).card) := by conv_lhs => unfold normBlockWythoff rw [WellFounded.fix_eq] have hcard : ((symWythoffMoves x y).attach.filter (fun q => normBlockWythoff k q.1.1 q.1.2 = false)).card = ((symWythoffMoves x y).filter (fun p => normBlockWythoff k p.1 p.2 = false)).card := by apply Finset.card_bij (fun q _ => q.1) · intro q hq; rw [Finset.mem_filter] at hq ⊢; exact ⟨q.2, hq.2⟩ · intro q₁ _ q₂ _ h; exact Subtype.ext h · intro p hp; rw [Finset.mem_filter] at hp exact ⟨⟨p, hp.1⟩, Finset.mem_filter.mpr ⟨Finset.mem_attach _ _, hp.2⟩, rfl⟩ change decide (k < ((symWythoffMoves x y).attach.filter (fun q => normBlockWythoff k q.1.1 q.1.2 = false)).card) = _ rw [hcard] /-- Misère `k`-Blocking Wythoff's Game: `true = 𝒩`, `false = 𝒫`. Next player wins iff `k < Pcnt` (can move to an unblocked `𝒫`-position) OR `Pcnt = total` (if opponent blocks all moves, current player wins in Misère play; specifically `(0, 0)` has `0 = 0`, `𝒩`). -/ def misBlockWythoff (k : ℕ) : ℕ → ℕ → Bool := fun x y => (InvImage.wf (fun q : ℕ × ℕ => q.1 + q.2) Nat.lt_wfRel.wf).fix (fun p rec => let Pcnt := ((symWythoffMoves p.1 p.2).attach.filter (fun q => rec q.1 (mem_symWythoffMoves_sum_lt q.2) = false)).card decide (k < Pcnt ∨ Pcnt = (symWythoffMoves p.1 p.2).card)) (x, y) lemma misBlockWythoff_eq (k x y : ℕ) : misBlockWythoff k x y = decide (k < ((symWythoffMoves x y).filter (fun p => misBlockWythoff k p.1 p.2 = false)).card ∨ ((symWythoffMoves x y).filter (fun p => misBlockWythoff k p.1 p.2 = false)).card = (symWythoffMoves x y).card) := by conv_lhs => unfold misBlockWythoff rw [WellFounded.fix_eq] have hcard : ((symWythoffMoves x y).attach.filter (fun q => misBlockWythoff k q.1.1 q.1.2 = false)).card = ((symWythoffMoves x y).filter (fun p => misBlockWythoff k p.1 p.2 = false)).card := by apply Finset.card_bij (fun q _ => q.1) · intro q hq; rw [Finset.mem_filter] at hq ⊢; exact ⟨q.2, hq.2⟩ · intro q₁ _ q₂ _ h; exact Subtype.ext h · intro p hp; rw [Finset.mem_filter] at hp exact ⟨⟨p, hp.1⟩, Finset.mem_filter.mpr ⟨Finset.mem_attach _ _, hp.2⟩, rfl⟩ change decide (k < ((symWythoffMoves x y).attach.filter (fun q => misBlockWythoff k q.1.1 q.1.2 = false)).card ∨ ((symWythoffMoves x y).attach.filter (fun q => misBlockWythoff k q.1.1 q.1.2 = false)).card = (symWythoffMoves x y).card) = _ rw [hcard] theorem normBlockWythoff_comm (k x y : ℕ) : normBlockWythoff k x y = normBlockWythoff k y x := by induction hsum : x + y using Nat.strong_induction_on generalizing x y with | h s ih => rw [normBlockWythoff_eq, normBlockWythoff_eq] congr 1 have hcard : ((symWythoffMoves x y).filter (fun p => normBlockWythoff k p.1 p.2 = false)).card = ((symWythoffMoves y x).filter (fun p => normBlockWythoff k p.1 p.2 = false)).card := by apply Finset.card_bij (fun p _ => p.swap) · intro p hp; rw [Finset.mem_filter] at hp ⊢ refine ⟨?_, ?_⟩ · rw [← symWythoffMoves_swap]; exact Finset.mem_image.mpr ⟨p, hp.1, rfl⟩ · have hlt := mem_symWythoffMoves_sum_lt hp.1 simpa [Prod.swap, ih (p.1 + p.2) (by omega) p.1 p.2 rfl] using hp.2 · intro p₁ _ p₂ _ h; exact Prod.swap_injective h · intro q hq; rw [Finset.mem_filter] at hq have hq' : q.swap ∈ symWythoffMoves x y := by rw [← symWythoffMoves_swap]; exact Finset.mem_image.mpr ⟨q, hq.1, rfl⟩ refine ⟨q.swap, Finset.mem_filter.mpr ⟨hq', ?_⟩, Prod.swap_swap q⟩ have hlt := mem_symWythoffMoves_sum_lt hq' simp only [Prod.fst_swap, Prod.snd_swap] at hlt ⊢ rw [ih (q.2 + q.1) (by omega) q.2 q.1 rfl]; exact hq.2 rw [hcard] theorem misBlockWythoff_comm (k x y : ℕ) : misBlockWythoff k x y = misBlockWythoff k y x := by induction hsum : x + y using Nat.strong_induction_on generalizing x y with | h s ih => rw [misBlockWythoff_eq, misBlockWythoff_eq, card_symWythoffMoves, card_symWythoffMoves] have hcard : ((symWythoffMoves x y).filter (fun p => misBlockWythoff k p.1 p.2 = false)).card = ((symWythoffMoves y x).filter (fun p => misBlockWythoff k p.1 p.2 = false)).card := by apply Finset.card_bij (fun p _ => p.swap) · intro p hp; rw [Finset.mem_filter] at hp ⊢ refine ⟨?_, ?_⟩ · rw [← symWythoffMoves_swap]; exact Finset.mem_image.mpr ⟨p, hp.1, rfl⟩ · have hlt := mem_symWythoffMoves_sum_lt hp.1 simpa [Prod.swap, ih (p.1 + p.2) (by omega) p.1 p.2 rfl] using hp.2 · intro p₁ _ p₂ _ h; exact Prod.swap_injective h · intro q hq; rw [Finset.mem_filter] at hq have hq' : q.swap ∈ symWythoffMoves x y := by rw [← symWythoffMoves_swap]; exact Finset.mem_image.mpr ⟨q, hq.1, rfl⟩ refine ⟨q.swap, Finset.mem_filter.mpr ⟨hq', ?_⟩, Prod.swap_swap q⟩ have hlt := mem_symWythoffMoves_sum_lt hq' simp only [Prod.fst_swap, Prod.snd_swap] at hlt ⊢ rw [ih (q.2 + q.1) (by omega) q.2 q.1 rfl]; exact hq.2 rw [hcard, show y + x + min y x = x + y + min x y by omega] /-! #### Exact Closed-Form Predicate & Proof for Normal `2`-Blocking Wythoff (`THEOREM 3`) -/ def normBlock2W_P (x y : ℕ) : Prop := let a := min x y let b := max x y (a = 0 ∧ b ≤ 2) ∨ (1 ≤ a ∧ (b = 2 * a + 1 ∨ b = 2 * a + 2)) instance : DecidableRel normBlock2W_P := fun _ _ => inferInstanceAs (Decidable (_ ∨ _)) lemma normBlock2W_P_comm (x y : ℕ) : normBlock2W_P x y ↔ normBlock2W_P y x := by simp only [normBlock2W_P, Nat.min_comm, Nat.max_comm] lemma card_normBlock2W_left (x y : ℕ) (hxy : x ≤ y) : ((Finset.range x).filter (fun a => normBlock2W_P a y)).card = (if 1 ≤ x ∧ y ≤ 2 then 1 else 0) + (if 3 ≤ y ∧ (y - 1) / 2 < x then 1 else 0) := by -- Every `a ∈ range x` with `normBlock2W_P a y` is either `0` (when `y ≤ 2`) or `(y - 1) / 2` (when `y ≥ 3`)! by_cases hy2 : y ≤ 2 · rw [if_neg (by omega : ¬ (3 ≤ y ∧ (y - 1) / 2 < x)), add_zero] by_cases hx0 : x = 0 · subst hx0; simp · rw [if_pos (by omega : 1 ≤ x ∧ y ≤ 2)] have hset : (Finset.range x).filter (fun a => normBlock2W_P a y) = {0} := by ext a; simp only [Finset.mem_filter, Finset.mem_range, Finset.mem_singleton] dsimp only [normBlock2W_P] constructor · intro ⟨ha, hP⟩ rw [Nat.min_eq_left (by omega : a ≤ y), Nat.max_eq_right (by omega : a ≤ y)] at hP; omega · rintro rfl; refine ⟨by omega, ?_⟩ rw [Nat.min_eq_left (Nat.zero_le y), Nat.max_eq_right (Nat.zero_le y)]; left; exact ⟨rfl, hy2⟩ rw [hset, Finset.card_singleton] · rw [if_neg (by omega : ¬ (1 ≤ x ∧ y ≤ 2)), zero_add] by_cases hlt : (y - 1) / 2 < x · rw [if_pos (by omega : 3 ≤ y ∧ (y - 1) / 2 < x)] have hset : (Finset.range x).filter (fun a => normBlock2W_P a y) = {(y - 1) / 2} := by ext a; simp only [Finset.mem_filter, Finset.mem_range, Finset.mem_singleton] dsimp only [normBlock2W_P] constructor · intro ⟨ha, hP⟩ rw [Nat.min_eq_left (by omega : a ≤ y), Nat.max_eq_right (by omega : a ≤ y)] at hP; omega · rintro rfl; refine ⟨hlt, ?_⟩ rw [Nat.min_eq_left (by omega : (y - 1) / 2 ≤ y), Nat.max_eq_right (by omega : (y - 1) / 2 ≤ y)] right; omega rw [hset, Finset.card_singleton] · rw [if_neg (by omega : ¬ (3 ≤ y ∧ (y - 1) / 2 < x))] have hset : (Finset.range x).filter (fun a => normBlock2W_P a y) = ∅ := by ext a; simp only [Finset.mem_filter, Finset.mem_range, Finset.notMem_empty, iff_false, not_and] dsimp only [normBlock2W_P] intro ha hP rw [Nat.min_eq_left (by omega : a ≤ y), Nat.max_eq_right (by omega : a ≤ y)] at hP; omega rw [hset, Finset.card_empty] lemma card_normBlock2W_mid (x y : ℕ) (hxy : x ≤ y) : ((Finset.Ico x y).filter (fun b => normBlock2W_P x b)).card = if x = 0 then min y 3 else (if 2 * x + 1 < y then 1 else 0) + (if 2 * x + 2 < y then 1 else 0) := by by_cases hx0 : x = 0 · subst hx0; rw [if_pos rfl] have hset : (Finset.Ico 0 y).filter (fun b => normBlock2W_P 0 b) = Finset.range (min y 3) := by ext b; simp only [Finset.mem_filter, Finset.mem_Ico, Finset.mem_range, lt_min_iff] dsimp only [normBlock2W_P] rw [Nat.min_eq_left (Nat.zero_le b), Nat.max_eq_right (Nat.zero_le b)] omega rw [hset, Finset.card_range] · rw [if_neg hx0] have hsub : (Finset.Ico x y).filter (fun b => normBlock2W_P x b) = ({2 * x + 1, 2 * x + 2} : Finset ℕ).filter (fun b => b < y) := by ext b; simp only [Finset.mem_filter, Finset.mem_Ico, Finset.mem_insert, Finset.mem_singleton] dsimp only [normBlock2W_P] constructor · intro ⟨⟨hxb, hby⟩, hP⟩ rw [Nat.min_eq_left hxb, Nat.max_eq_right hxb] at hP; omega · intro ⟨hb, hby⟩ refine ⟨⟨by omega, hby⟩, ?_⟩ rw [Nat.min_eq_left (by omega : x ≤ b), Nat.max_eq_right (by omega : x ≤ b)]; right; omega rw [hsub, Finset.filter_insert, Finset.filter_singleton] by_cases h1 : 2 * x + 1 < y <;> by_cases h2 : 2 * x + 2 < y · simp only [h1, h2, ↓reduceIte] rw [Finset.card_insert_of_notMem (by simp), Finset.card_singleton] · simp [h1, h2] · omega · simp [h1, h2] lemma card_normBlock2W_diag (x y : ℕ) (hxy : x ≤ y) : ((Finset.range x).filter (fun a => normBlock2W_P a (a + (y - x)))).card = (if 1 ≤ x ∧ y - x ≤ 2 then 1 else 0) + (if 2 ≤ y - x ∧ y - x - 1 < x then 1 else 0) + (if 3 ≤ y - x ∧ y - x - 2 < x then 1 else 0) := by set Δ := y - x have hsub : (Finset.range x).filter (fun a => normBlock2W_P a (a + Δ)) = (if 1 ≤ x ∧ Δ ≤ 2 then ({0} : Finset ℕ) else ∅) ∪ (if 2 ≤ Δ ∧ Δ - 1 < x then ({Δ - 1} : Finset ℕ) else ∅) ∪ (if 3 ≤ Δ ∧ Δ - 2 < x then ({Δ - 2} : Finset ℕ) else ∅) := by ext a simp only [Finset.mem_filter, Finset.mem_range, Finset.mem_union] simp only [normBlock2W_P, Nat.min_eq_left (Nat.le_add_right a Δ), Nat.max_eq_right (Nat.le_add_right a Δ)] split_ifs <;> simp <;> omega rw [hsub] have hd1 : Disjoint (if 1 ≤ x ∧ Δ ≤ 2 then ({0} : Finset ℕ) else ∅) (if 2 ≤ Δ ∧ Δ - 1 < x then ({Δ - 1} : Finset ℕ) else ∅) := by split_ifs <;> simp; omega have hd2 : Disjoint ((if 1 ≤ x ∧ Δ ≤ 2 then ({0} : Finset ℕ) else ∅) ∪ (if 2 ≤ Δ ∧ Δ - 1 < x then ({Δ - 1} : Finset ℕ) else ∅)) (if 3 ≤ Δ ∧ Δ - 2 < x then ({Δ - 2} : Finset ℕ) else ∅) := by rw [Finset.disjoint_left]; intro a ha hb split_ifs at ha hb <;> simp at ha hb <;> omega rw [Finset.card_union_of_disjoint hd2, Finset.card_union_of_disjoint hd1] split_ifs <;> simp private lemma normBlock2W_arith (x y : ℕ) (hxy : x ≤ y) : let L := (if 1 ≤ x ∧ y ≤ 2 then 1 else 0) + (if 3 ≤ y ∧ (y - 1) / 2 < x then 1 else 0) let D1 := (if 1 ≤ x ∧ x ≤ 2 then 1 else 0) + (if 3 ≤ x ∧ (x - 1) / 2 < x then 1 else 0) let D2 := if x = 0 then min y 3 else (if 2 * x + 1 < y then 1 else 0) + (if 2 * x + 2 < y then 1 else 0) let G := (if 1 ≤ x ∧ y - x ≤ 2 then 1 else 0) + (if 2 ≤ y - x ∧ y - x - 1 < x then 1 else 0) + (if 3 ≤ y - x ∧ y - x - 2 < x then 1 else 0) 2 < L + (D1 + D2) + G ↔ ¬ ((x = 0 ∧ y ≤ 2) ∨ (1 ≤ x ∧ (y = 2 * x + 1 ∨ y = 2 * x + 2))) := by intro L D1 D2 G; dsimp only [L, D1, D2, G] by_cases hx0 : x = 0 · subst hx0; simp · have hD1 : (if 1 ≤ x ∧ x ≤ 2 then 1 else 0) + (if 3 ≤ x ∧ (x - 1) / 2 < x then 1 else 0) = 1 := by split_ifs <;> omega rw [hD1, if_neg hx0] by_cases hy2 : y ≤ 2 · rw [if_pos (by omega : 1 ≤ x ∧ y ≤ 2), if_neg (by omega : ¬ (3 ≤ y ∧ (y - 1) / 2 < x)), if_neg (by omega : ¬ (2 * x + 1 < y)), if_neg (by omega : ¬ (2 * x + 2 < y))] split_ifs <;> omega · rw [if_neg (by omega : ¬ (1 ≤ x ∧ y ≤ 2))] by_cases hy_hi : 2 * x + 2 < y · rw [if_pos (by omega : 2 * x + 1 < y), if_pos hy_hi]; split_ifs <;> omega · by_cases hy_mid : y = 2 * x + 1 ∨ y = 2 * x + 2 · split_ifs <;> omega · by_cases hx1 : x = 1 · subst hx1; split_ifs <;> omega · split_ifs <;> omega /-- **THEOREM 3 (Complete Exact Classification of Normal `2`-Blocking Wythoff's Game):** For ALL `x, y : ℕ`: `normBlockWythoff 2 x y = false ↔ (min x y = 0 ∧ max x y ≤ 2) ∨ (1 ≤ min x y ∧ (max x y = 2 * min x y + 1 ∨ max x y = 2 * min x y + 2))`! -/ theorem normBlock2Wythoff_exact (x y : ℕ) : normBlockWythoff 2 x y = decide (¬ normBlock2W_P x y) := by induction hsum : x + y using Nat.strong_induction_on generalizing x y with | h s ih => wlog hxy : x ≤ y generalizing x y · rw [normBlockWythoff_comm, this y x (by omega) (by omega)] simp [normBlock2W_P_comm] rw [normBlockWythoff_eq] have hfilt : (symWythoffMoves x y).filter (fun p => normBlockWythoff 2 p.1 p.2 = false) = (symWythoffMoves x y).filter (fun p => normBlock2W_P p.1 p.2) := by apply Finset.filter_congr; intro p hp rw [ih (p.1 + p.2) (by have := mem_symWythoffMoves_sum_lt hp; omega) p.1 p.2 rfl]; simp rw [hfilt, card_filter_symWythoffMoves normBlock2W_P x y hxy] have hsplit_y : ((Finset.range y).filter (fun b => normBlock2W_P x b)).card = ((Finset.range x).filter (fun b => normBlock2W_P x b)).card + ((Finset.Ico x y).filter (fun b => normBlock2W_P x b)).card := by have hun : Finset.range y = Finset.range x ∪ Finset.Ico x y := by ext a; simp only [Finset.mem_range, Finset.mem_union, Finset.mem_Ico]; omega have hdisj : Disjoint (Finset.range x) (Finset.Ico x y) := by rw [Finset.disjoint_left]; intro a h1 h2 simp only [Finset.mem_range, Finset.mem_Ico] at h1 h2; omega rw [hun, Finset.filter_union, Finset.card_union_of_disjoint (Finset.disjoint_filter_filter hdisj)] have hcomm_r : ((Finset.range x).filter (fun b => normBlock2W_P x b)).card = ((Finset.range x).filter (fun a => normBlock2W_P a x)).card := by congr 1; apply Finset.filter_congr; intro a _; exact normBlock2W_P_comm x a rw [hsplit_y, hcomm_r, card_normBlock2W_left x y hxy, card_normBlock2W_left x x le_rfl, card_normBlock2W_mid x y hxy, card_normBlock2W_diag x y hxy] have hP_iff : normBlock2W_P x y ↔ (x = 0 ∧ y ≤ 2) ∨ (1 ≤ x ∧ (y = 2 * x + 1 ∨ y = 2 * x + 2)) := by simp only [normBlock2W_P, Nat.min_eq_left hxy, Nat.max_eq_right hxy] simp only [hP_iff, decide_eq_decide] exact normBlock2W_arith x y hxy /-! #### Exact Closed-Form Predicate & Proof for Misère `2`-Blocking Wythoff (`THEOREM 4` — NEW!) -/ def misBlock2W_P (x y : ℕ) : Prop := let a := min x y let b := max x y (a = 0 ∧ 1 ≤ b ∧ b ≤ 3) ∨ (a = 1 ∧ (b = 1 ∨ b = 5)) ∨ (2 ≤ a ∧ (b = 2 * a ∨ b = 2 * a + 3)) instance : DecidableRel misBlock2W_P := fun _ _ => inferInstanceAs (Decidable (_ ∨ _)) lemma misBlock2W_P_comm (x y : ℕ) : misBlock2W_P x y ↔ misBlock2W_P y x := by simp only [misBlock2W_P, Nat.min_comm, Nat.max_comm] lemma card_misBlock2W_left (x y : ℕ) (hxy : x ≤ y) : ((Finset.range x).filter (fun a => misBlock2W_P a y)).card = (if 1 ≤ x ∧ 1 ≤ y ∧ y ≤ 3 then 1 else 0) + (if 2 ≤ x ∧ y = 5 then 1 else 0) + (if 4 ≤ y ∧ y % 2 = 0 ∧ y / 2 < x then 1 else 0) + (if 7 ≤ y ∧ y % 2 = 1 ∧ (y - 3) / 2 < x then 1 else 0) := by have hsub : (Finset.range x).filter (fun a => misBlock2W_P a y) = (if 1 ≤ x ∧ 1 ≤ y ∧ y ≤ 3 then ({0} : Finset ℕ) else ∅) ∪ (if 2 ≤ x ∧ y = 5 then ({1} : Finset ℕ) else ∅) ∪ (if 4 ≤ y ∧ y % 2 = 0 ∧ y / 2 < x then ({y / 2} : Finset ℕ) else ∅) ∪ (if 7 ≤ y ∧ y % 2 = 1 ∧ (y - 3) / 2 < x then ({(y - 3) / 2} : Finset ℕ) else ∅) := by ext a simp only [Finset.mem_filter, Finset.mem_range, Finset.mem_union] dsimp only [misBlock2W_P] by_cases hay : a ≤ y · rw [Nat.min_eq_left hay, Nat.max_eq_right hay] split_ifs <;> simp <;> omega · split_ifs <;> simp <;> omega rw [hsub] have hd1 : Disjoint (if 1 ≤ x ∧ 1 ≤ y ∧ y ≤ 3 then ({0} : Finset ℕ) else ∅) (if 2 ≤ x ∧ y = 5 then ({1} : Finset ℕ) else ∅) := by split_ifs <;> simp have hd2 : Disjoint ((if 1 ≤ x ∧ 1 ≤ y ∧ y ≤ 3 then ({0} : Finset ℕ) else ∅) ∪ (if 2 ≤ x ∧ y = 5 then ({1} : Finset ℕ) else ∅)) (if 4 ≤ y ∧ y % 2 = 0 ∧ y / 2 < x then ({y / 2} : Finset ℕ) else ∅) := by rw [Finset.disjoint_left]; intro a ha hb; split_ifs at ha hb <;> simp at ha hb <;> omega have hd3 : Disjoint (((if 1 ≤ x ∧ 1 ≤ y ∧ y ≤ 3 then ({0} : Finset ℕ) else ∅) ∪ (if 2 ≤ x ∧ y = 5 then ({1} : Finset ℕ) else ∅)) ∪ (if 4 ≤ y ∧ y % 2 = 0 ∧ y / 2 < x then ({y / 2} : Finset ℕ) else ∅)) (if 7 ≤ y ∧ y % 2 = 1 ∧ (y - 3) / 2 < x then ({(y - 3) / 2} : Finset ℕ) else ∅) := by rw [Finset.disjoint_left]; intro a ha hb; split_ifs at ha hb <;> simp at ha hb <;> omega rw [Finset.card_union_of_disjoint hd3, Finset.card_union_of_disjoint hd2, Finset.card_union_of_disjoint hd1] split_ifs <;> simp lemma card_misBlock2W_mid (x y : ℕ) (hxy : x ≤ y) : ((Finset.Ico x y).filter (fun b => misBlock2W_P x b)).card = if x = 0 then (if 1 < y then 1 else 0) + (if 2 < y then 1 else 0) + (if 3 < y then 1 else 0) else if x = 1 then (if 1 < y then 1 else 0) + (if 5 < y then 1 else 0) else (if 2 * x < y then 1 else 0) + (if 2 * x + 3 < y then 1 else 0) := by by_cases hx0 : x = 0 · subst hx0; rw [if_pos rfl] have hsub : (Finset.Ico 0 y).filter (fun b => misBlock2W_P 0 b) = (if 1 < y then ({1} : Finset ℕ) else ∅) ∪ (if 2 < y then ({2} : Finset ℕ) else ∅) ∪ (if 3 < y then ({3} : Finset ℕ) else ∅) := by ext b; simp only [Finset.mem_filter, Finset.mem_Ico, Finset.mem_union] simp only [misBlock2W_P, Nat.min_eq_left (Nat.zero_le b), Nat.max_eq_right (Nat.zero_le b)] split_ifs <;> simp <;> omega rw [hsub] have hd1 : Disjoint (if 1 < y then ({1} : Finset ℕ) else ∅) (if 2 < y then ({2} : Finset ℕ) else ∅) := by split_ifs <;> simp have hd2 : Disjoint ((if 1 < y then ({1} : Finset ℕ) else ∅) ∪ (if 2 < y then ({2} : Finset ℕ) else ∅)) (if 3 < y then ({3} : Finset ℕ) else ∅) := by rw [Finset.disjoint_left]; intro b hb1 hb2; split_ifs at hb1 hb2 <;> simp at hb1 hb2 <;> omega rw [Finset.card_union_of_disjoint hd2, Finset.card_union_of_disjoint hd1]; split_ifs <;> simp · rw [if_neg hx0] by_cases hx1 : x = 1 · subst hx1; rw [if_pos rfl] have hsub : (Finset.Ico 1 y).filter (fun b => misBlock2W_P 1 b) = (if 1 < y then ({1} : Finset ℕ) else ∅) ∪ (if 5 < y then ({5} : Finset ℕ) else ∅) := by ext b; simp only [Finset.mem_filter, Finset.mem_Ico, Finset.mem_union] dsimp only [misBlock2W_P] by_cases h1b : 1 ≤ b · rw [Nat.min_eq_left h1b, Nat.max_eq_right h1b]; split_ifs <;> simp <;> omega · split_ifs <;> simp <;> omega rw [hsub, Finset.card_union_of_disjoint (by split_ifs <;> simp)]; split_ifs <;> simp · rw [if_neg hx1] have hsub : (Finset.Ico x y).filter (fun b => misBlock2W_P x b) = (if 2 * x < y then ({2 * x} : Finset ℕ) else ∅) ∪ (if 2 * x + 3 < y then ({2 * x + 3} : Finset ℕ) else ∅) := by ext b; simp only [Finset.mem_filter, Finset.mem_Ico, Finset.mem_union] dsimp only [misBlock2W_P] by_cases hxb : x ≤ b · rw [Nat.min_eq_left hxb, Nat.max_eq_right hxb]; split_ifs <;> simp <;> omega · split_ifs <;> simp <;> omega rw [hsub, Finset.card_union_of_disjoint (by split_ifs <;> simp)]; split_ifs <;> simp lemma card_misBlock2W_diag (x y : ℕ) (hxy : x ≤ y) : ((Finset.range x).filter (fun a => misBlock2W_P a (a + (y - x)))).card = (if 1 ≤ x ∧ 1 ≤ y - x ∧ y - x ≤ 3 then 1 else 0) + (if 2 ≤ x ∧ (y - x = 0 ∨ y - x = 4) then 1 else 0) + (if 2 ≤ y - x ∧ y - x < x then 1 else 0) + (if 5 ≤ y - x ∧ y - x - 3 < x then 1 else 0) := by set Δ := y - x have hsub : (Finset.range x).filter (fun a => misBlock2W_P a (a + Δ)) = (if 1 ≤ x ∧ 1 ≤ Δ ∧ Δ ≤ 3 then ({0} : Finset ℕ) else ∅) ∪ (if 2 ≤ x ∧ (Δ = 0 ∨ Δ = 4) then ({1} : Finset ℕ) else ∅) ∪ (if 2 ≤ Δ ∧ Δ < x then ({Δ} : Finset ℕ) else ∅) ∪ (if 5 ≤ Δ ∧ Δ - 3 < x then ({Δ - 3} : Finset ℕ) else ∅) := by ext a simp only [Finset.mem_filter, Finset.mem_range, Finset.mem_union] simp only [misBlock2W_P, Nat.min_eq_left (Nat.le_add_right a Δ), Nat.max_eq_right (Nat.le_add_right a Δ)] split_ifs <;> simp <;> omega rw [hsub] have hd1 : Disjoint (if 1 ≤ x ∧ 1 ≤ Δ ∧ Δ ≤ 3 then ({0} : Finset ℕ) else ∅) (if 2 ≤ x ∧ (Δ = 0 ∨ Δ = 4) then ({1} : Finset ℕ) else ∅) := by split_ifs <;> simp have hd2 : Disjoint ((if 1 ≤ x ∧ 1 ≤ Δ ∧ Δ ≤ 3 then ({0} : Finset ℕ) else ∅) ∪ (if 2 ≤ x ∧ (Δ = 0 ∨ Δ = 4) then ({1} : Finset ℕ) else ∅)) (if 2 ≤ Δ ∧ Δ < x then ({Δ} : Finset ℕ) else ∅) := by rw [Finset.disjoint_left]; intro a ha hb; split_ifs at ha hb <;> simp at ha hb <;> omega have hd3 : Disjoint (((if 1 ≤ x ∧ 1 ≤ Δ ∧ Δ ≤ 3 then ({0} : Finset ℕ) else ∅) ∪ (if 2 ≤ x ∧ (Δ = 0 ∨ Δ = 4) then ({1} : Finset ℕ) else ∅)) ∪ (if 2 ≤ Δ ∧ Δ < x then ({Δ} : Finset ℕ) else ∅)) (if 5 ≤ Δ ∧ Δ - 3 < x then ({Δ - 3} : Finset ℕ) else ∅) := by rw [Finset.disjoint_left]; intro a ha hb; split_ifs at ha hb <;> simp at ha hb <;> omega rw [Finset.card_union_of_disjoint hd3, Finset.card_union_of_disjoint hd2, Finset.card_union_of_disjoint hd1] split_ifs <;> simp private lemma misBlock2W_arith (x y : ℕ) (hxy : x ≤ y) : let L := (if 1 ≤ x ∧ 1 ≤ y ∧ y ≤ 3 then 1 else 0) + (if 2 ≤ x ∧ y = 5 then 1 else 0) + (if 4 ≤ y ∧ y % 2 = 0 ∧ y / 2 < x then 1 else 0) + (if 7 ≤ y ∧ y % 2 = 1 ∧ (y - 3) / 2 < x then 1 else 0) let D1 := (if 1 ≤ x ∧ 1 ≤ x ∧ x ≤ 3 then 1 else 0) + (if 2 ≤ x ∧ x = 5 then 1 else 0) + (if 4 ≤ x ∧ x % 2 = 0 ∧ x / 2 < x then 1 else 0) + (if 7 ≤ x ∧ x % 2 = 1 ∧ (x - 3) / 2 < x then 1 else 0) let D2 := if x = 0 then (if 1 < y then 1 else 0) + (if 2 < y then 1 else 0) + (if 3 < y then 1 else 0) else if x = 1 then (if 1 < y then 1 else 0) + (if 5 < y then 1 else 0) else (if 2 * x < y then 1 else 0) + (if 2 * x + 3 < y then 1 else 0) let G := (if 1 ≤ x ∧ 1 ≤ y - x ∧ y - x ≤ 3 then 1 else 0) + (if 2 ≤ x ∧ (y - x = 0 ∨ y - x = 4) then 1 else 0) + (if 2 ≤ y - x ∧ y - x < x then 1 else 0) + (if 5 ≤ y - x ∧ y - x - 3 < x then 1 else 0) (2 < L + (D1 + D2) + G ∨ L + (D1 + D2) + G = x + y + x) ↔ ¬ ((x = 0 ∧ 1 ≤ y ∧ y ≤ 3) ∨ (x = 1 ∧ (y = 1 ∨ y = 5)) ∨ (2 ≤ x ∧ (y = 2 * x ∨ y = 2 * x + 3))) := by intro L D1 D2 G; dsimp only [L, D1, D2, G] by_cases hx0 : x = 0 · subst hx0; simp; split_ifs <;> omega · by_cases hx1 : x = 1 · subst hx1 rw [if_neg (by omega : ¬ (1 = 0)), if_pos rfl] by_cases hy6 : y ≤ 6 · have : y = 1 ∨ y = 2 ∨ y = 3 ∨ y = 4 ∨ y = 5 ∨ y = 6 := by omega rcases this with rfl | rfl | rfl | rfl | rfl | rfl <;> decide · rw [if_neg (by omega : ¬ (1 ≤ 1 ∧ 1 ≤ y ∧ y ≤ 3)), if_neg (by omega : ¬ (2 ≤ 1 ∧ y = 5)), if_neg (by omega : ¬ (4 ≤ y ∧ y % 2 = 0 ∧ y / 2 < 1)), if_neg (by omega : ¬ (7 ≤ y ∧ y % 2 = 1 ∧ (y - 3) / 2 < 1)), if_pos (by omega : 1 < y), if_pos (by omega : 5 < y)] split_ifs <;> omega · -- `2 ≤ x`: simplify `D1` first! Notice `D1 = 1` for EVERY `x ≥ 2`! have hD1 : (if 1 ≤ x ∧ 1 ≤ x ∧ x ≤ 3 then 1 else 0) + (if 2 ≤ x ∧ x = 5 then 1 else 0) + (if 4 ≤ x ∧ x % 2 = 0 ∧ x / 2 < x then 1 else 0) + (if 7 ≤ x ∧ x % 2 = 1 ∧ (x - 3) / 2 < x then 1 else 0) = 1 := by by_cases hx3 : x ≤ 3 · split_ifs <;> omega · by_cases hx5 : x = 5 · subst hx5; decide · by_cases hev : x % 2 = 0 <;> (split_ifs <;> omega) rw [hD1, if_neg hx0, if_neg hx1] -- Simplify `L` cleanly by splitting on `y ≤ 3`, `y = 5`, `y ≥ 4` even/odd! by_cases hy3 : y ≤ 3 · -- `2 ≤ x ≤ y ≤ 3` have : (x = 2 ∧ y = 2) ∨ (x = 2 ∧ y = 3) ∨ (x = 3 ∧ y = 3) := by omega rcases this with ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ <;> decide · rw [if_neg (by omega : ¬ (1 ≤ x ∧ 1 ≤ y ∧ y ≤ 3))] by_cases hy5 : y = 5 · subst hy5 have : x = 2 ∨ x = 3 ∨ x = 4 ∨ x = 5 := by omega rcases this with rfl | rfl | rfl | rfl <;> decide · rw [if_neg (by omega : ¬ (2 ≤ x ∧ y = 5))] by_cases hy_hi : 2 * x + 3 < y · rw [if_pos (by omega : 2 * x < y), if_pos hy_hi] have hL0 : 0 ≤ (if 4 ≤ y ∧ y % 2 = 0 ∧ y / 2 < x then 1 else 0) + (if 7 ≤ y ∧ y % 2 = 1 ∧ (y - 3) / 2 < x then 1 else 0) := Nat.zero_le _ have hG0 : 0 ≤ (if 1 ≤ x ∧ 1 ≤ y - x ∧ y - x ≤ 3 then 1 else 0) + (if 2 ≤ x ∧ (y - x = 0 ∨ y - x = 4) then 1 else 0) + (if 2 ≤ y - x ∧ y - x < x then 1 else 0) + (if 5 ≤ y - x ∧ y - x - 3 < x then 1 else 0) := Nat.zero_le _ omega · by_cases hy_2x : y = 2 * x · subst hy_2x rw [if_neg (by omega : ¬ (2 * x < 2 * x)), if_neg (by omega : ¬ (2 * x + 3 < 2 * x)), if_neg (by omega : ¬ (4 ≤ 2 * x ∧ 2 * x % 2 = 0 ∧ 2 * x / 2 < x)), if_neg (by omega : ¬ (7 ≤ 2 * x ∧ 2 * x % 2 = 1 ∧ (2 * x - 3) / 2 < x))] split_ifs <;> omega · by_cases hy_2x3 : y = 2 * x + 3 · subst hy_2x3 rw [if_pos (by omega : 2 * x < 2 * x + 3), if_neg (by omega : ¬ (2 * x + 3 < 2 * x + 3)), if_neg (by omega : ¬ (4 ≤ 2 * x + 3 ∧ (2 * x + 3) % 2 = 0 ∧ (2 * x + 3) / 2 < x)), if_neg (by omega : ¬ (7 ≤ 2 * x + 3 ∧ (2 * x + 3) % 2 = 1 ∧ (2 * x + 3 - 3) / 2 < x))] split_ifs <;> omega · -- Remaining `𝒩`-positions with `2 ≤ x`, `4 ≤ y`, `y ≠ 5`, `y ≤ 2*x + 2`, `y ≠ 2*x`! by_cases hgt2x : 2 * x < y · -- `y = 2 * x + 1` or `y = 2 * x + 2`! rw [if_pos hgt2x, if_neg hy_hi] have : y = 2 * x + 1 ∨ y = 2 * x + 2 := by omega rcases this with rfl | rfl · rw [if_neg (by omega : ¬ (4 ≤ 2 * x + 1 ∧ (2 * x + 1) % 2 = 0 ∧ (2 * x + 1) / 2 < x))] by_cases hx2 : x = 2 · subst hx2; decide · rw [if_pos (by omega : 7 ≤ 2 * x + 1 ∧ (2 * x + 1) % 2 = 1 ∧ (2 * x + 1 - 3) / 2 < x)] omega · rw [if_neg (by omega : ¬ (4 ≤ 2 * x + 2 ∧ (2 * x + 2) % 2 = 0 ∧ (2 * x + 2) / 2 < x)), if_neg (by omega : ¬ (7 ≤ 2 * x + 2 ∧ (2 * x + 2) % 2 = 1 ∧ (2 * x + 2 - 3) / 2 < x))] by_cases hx2 : x = 2 · subst hx2; decide · rw [if_pos (by omega : 5 ≤ 2 * x + 2 - x ∧ 2 * x + 2 - x - 3 < x)]; omega · -- `x ≤ y < 2 * x`, `y ≥ 4`, `y ≠ 5`: so `y / 2 < x` (if even) and `(y - 3) / 2 < x` (if odd, `y ≥ 7`)! have hL1 : (if 4 ≤ y ∧ y % 2 = 0 ∧ y / 2 < x then 1 else 0) + (if 7 ≤ y ∧ y % 2 = 1 ∧ (y - 3) / 2 < x then 1 else 0) = 1 := by by_cases hev : y % 2 = 0 <;> (split_ifs <;> omega) simp only [zero_add] rw [hL1, if_neg hgt2x, if_neg hy_hi] -- Need `G ≥ 1`, which holds for ALL `0 ≤ y - x < x` (`x ≥ 2`)! by_cases hd0 : y - x = 0 · rw [if_pos (by omega : 2 ≤ x ∧ (y - x = 0 ∨ y - x = 4))]; omega · by_cases hd1 : y - x = 1 · rw [if_pos (by omega : 1 ≤ x ∧ 1 ≤ y - x ∧ y - x ≤ 3)]; omega · rw [if_pos (by omega : 2 ≤ y - x ∧ y - x < x)]; omega /-- **THEOREM 4 (Complete Exact Classification of Misère `2`-Blocking Wythoff's Game — NEW!):** For ALL `x, y : ℕ`: - `min x y = 0`: `𝒫 ↔ 1 ≤ max x y ∧ max x y ≤ 3`; - `min x y = 1`: `𝒫 ↔ max x y = 1 ∨ max x y = 5`; - `min x y ≥ 2`: `𝒫 ↔ max x y = 2 * min x y ∨ max x y = 2 * min x y + 3`! -/ theorem misBlock2Wythoff_exact (x y : ℕ) : misBlockWythoff 2 x y = decide (¬ misBlock2W_P x y) := by induction hsum : x + y using Nat.strong_induction_on generalizing x y with | h s ih => wlog hxy : x ≤ y generalizing x y · rw [misBlockWythoff_comm, this y x (by omega) (by omega)] simp [misBlock2W_P_comm] rw [misBlockWythoff_eq, card_symWythoffMoves, Nat.min_eq_left hxy] have hfilt : (symWythoffMoves x y).filter (fun p => misBlockWythoff 2 p.1 p.2 = false) = (symWythoffMoves x y).filter (fun p => misBlock2W_P p.1 p.2) := by apply Finset.filter_congr; intro p hp rw [ih (p.1 + p.2) (by have := mem_symWythoffMoves_sum_lt hp; omega) p.1 p.2 rfl]; simp rw [hfilt, card_filter_symWythoffMoves misBlock2W_P x y hxy] have hsplit_y : ((Finset.range y).filter (fun b => misBlock2W_P x b)).card = ((Finset.range x).filter (fun b => misBlock2W_P x b)).card + ((Finset.Ico x y).filter (fun b => misBlock2W_P x b)).card := by have hun : Finset.range y = Finset.range x ∪ Finset.Ico x y := by ext a; simp only [Finset.mem_range, Finset.mem_union, Finset.mem_Ico]; omega have hdisj : Disjoint (Finset.range x) (Finset.Ico x y) := by rw [Finset.disjoint_left]; intro a h1 h2 simp only [Finset.mem_range, Finset.mem_Ico] at h1 h2; omega rw [hun, Finset.filter_union, Finset.card_union_of_disjoint (Finset.disjoint_filter_filter hdisj)] have hcomm_r : ((Finset.range x).filter (fun b => misBlock2W_P x b)).card = ((Finset.range x).filter (fun a => misBlock2W_P a x)).card := by congr 1; apply Finset.filter_congr; intro a _; exact misBlock2W_P_comm x a rw [hsplit_y, hcomm_r, card_misBlock2W_left x y hxy, card_misBlock2W_left x x le_rfl, card_misBlock2W_mid x y hxy, card_misBlock2W_diag x y hxy] have hP_iff : misBlock2W_P x y ↔ (x = 0 ∧ 1 ≤ y ∧ y ≤ 3) ∨ (x = 1 ∧ (y = 1 ∨ y = 5)) ∨ (2 ≤ x ∧ (y = 2 * x ∨ y = 2 * x + 3)) := by simp only [misBlock2W_P, Nat.min_eq_left hxy, Nat.max_eq_right hxy] simp only [hP_iff, decide_eq_decide] exact misBlock2W_arith x y hxy /-- **Corollary 4 (Exact Diagonal Shift & Spacing Split Between Normal and Misère `2`-Blocking Wythoff):** - Normal `2`-Blocking Wythoff has unique diagonal `𝒫`-position `(0, 0)` and ray spacing `1` (`2x+1, 2x+2`); - Misère `2`-Blocking Wythoff has unique diagonal `𝒫`-position `(1, 1)` and ray spacing `3` (`2x, 2x+3`)! -/ theorem misBlock2Wythoff_diagonal_and_ray_split : (∀ x, normBlockWythoff 2 x x = false ↔ x = 0) ∧ (∀ x, misBlockWythoff 2 x x = false ↔ x = 1) ∧ (∀ x, 2 ≤ x → ∀ y, x ≤ y → (misBlockWythoff 2 x y = false ↔ y = 2 * x ∨ y = 2 * x + 3)) := by refine ⟨?_, ?_, ?_⟩ · intro x; rw [normBlock2Wythoff_exact]; simp [normBlock2W_P]; omega · intro x; rw [misBlock2Wythoff_exact]; simp [misBlock2W_P]; omega · intro x hx y hxy; rw [misBlock2Wythoff_exact] simp only [misBlock2W_P, Nat.min_eq_left hxy, Nat.max_eq_right hxy, decide_eq_false_iff_not, not_not] omega /-! ### 4. PART III: Complete Classification & Freezing Dichotomy for Normal & Misère `k`-Blocking Subtraction Games `S = {1, …, m}` (NEW!) -/ /-- Moves of the one-pile subtraction game `S = {1, …, m}` from pile size `x`. -/ def subMoves (m x : ℕ) : Finset ℕ := (Finset.Icc 1 (min m x)).image (fun d => x - d) lemma mem_subMoves_lt {m x y : ℕ} (hy : y ∈ subMoves m x) : y < x := by rcases Finset.mem_image.mp hy with ⟨d, hd, rfl⟩ rw [Finset.mem_Icc] at hd; omega lemma subMoves_eq_Ico (m x : ℕ) : subMoves m x = Finset.Ico (x - m) x := by ext y; simp only [subMoves, Finset.mem_image, Finset.mem_Icc, Finset.mem_Ico] constructor · rintro ⟨d, hd, rfl⟩; omega · intro hy; exact ⟨x - y, by omega, by omega⟩ lemma card_subMoves (m x : ℕ) : (subMoves m x).card = min m x := by rw [subMoves_eq_Ico, Nat.card_Ico]; omega /-- Normal `k`-Blocking Subtraction Game `S = {1, …, m}`: `true = 𝒩`, `false = 𝒫`. -/ def normBlockSub (m k : ℕ) : ℕ → Bool := Nat.lt_wfRel.wf.fix (fun x rec => let Pcnt := ((subMoves m x).attach.filter (fun y => rec y.1 (mem_subMoves_lt y.2) = false)).card decide (k < Pcnt)) lemma normBlockSub_eq (m k x : ℕ) : normBlockSub m k x = decide (k < ((subMoves m x).filter (fun y => normBlockSub m k y = false)).card) := by conv_lhs => unfold normBlockSub rw [WellFounded.fix_eq] have hcard : ((subMoves m x).attach.filter (fun q => normBlockSub m k q.1 = false)).card = ((subMoves m x).filter (fun y => normBlockSub m k y = false)).card := by apply Finset.card_bij (fun q _ => q.1) · intro q hq; rw [Finset.mem_filter] at hq ⊢; exact ⟨q.2, hq.2⟩ · intro q₁ _ q₂ _ h; exact Subtype.ext h · intro p hp; rw [Finset.mem_filter] at hp exact ⟨⟨p, hp.1⟩, Finset.mem_filter.mpr ⟨Finset.mem_attach _ _, hp.2⟩, rfl⟩ change decide (k < ((subMoves m x).attach.filter (fun q => normBlockSub m k q.1 = false)).card) = _ rw [hcard] /-- Misère `k`-Blocking Subtraction Game `S = {1, …, m}`: `true = 𝒩`, `false = 𝒫`. -/ def misBlockSub (m k : ℕ) : ℕ → Bool := Nat.lt_wfRel.wf.fix (fun x rec => let Pcnt := ((subMoves m x).attach.filter (fun y => rec y.1 (mem_subMoves_lt y.2) = false)).card decide (k < Pcnt ∨ Pcnt = (subMoves m x).card)) lemma misBlockSub_eq (m k x : ℕ) : misBlockSub m k x = decide (k < ((subMoves m x).filter (fun y => misBlockSub m k y = false)).card ∨ ((subMoves m x).filter (fun y => misBlockSub m k y = false)).card = (subMoves m x).card) := by conv_lhs => unfold misBlockSub rw [WellFounded.fix_eq] have hcard : ((subMoves m x).attach.filter (fun q => misBlockSub m k q.1 = false)).card = ((subMoves m x).filter (fun p => misBlockSub m k p = false)).card := by apply Finset.card_bij (fun q _ => q.1) · intro q hq; rw [Finset.mem_filter] at hq ⊢; exact ⟨q.2, hq.2⟩ · intro q₁ _ q₂ _ h; exact Subtype.ext h · intro p hp; rw [Finset.mem_filter] at hp exact ⟨⟨p, hp.1⟩, Finset.mem_filter.mpr ⟨Finset.mem_attach _ _, hp.2⟩, rfl⟩ change decide (k < ((subMoves m x).attach.filter (fun q => misBlockSub m k q.1 = false)).card ∨ ((subMoves m x).attach.filter (fun q => misBlockSub m k q.1 = false)).card = (subMoves m x).card) = _ rw [hcard] /-- Helper: exact count of residues `y ∈ Ico (x - m) x` with `y % (m + 1) ≤ r` (for `r < m`). -/ lemma card_Ico_mod_le {m r : ℕ} (hm : 1 ≤ m) (hr : r < m) (x : ℕ) : ((Finset.Ico (x - m) x).filter (fun y => y % (m + 1) ≤ r)).card = if x ≤ m then min x (r + 1) else if x % (m + 1) ≤ r then r else r + 1 := by have hdvd_of_mod_eq : ∀ a b : ℕ, a ≤ b → a % (m + 1) = b % (m + 1) → (m + 1) ∣ (b - a) := by intro a b hab hmod have ha := Nat.div_add_mod a (m + 1) have hb := Nat.div_add_mod b (m + 1) have hq : a / (m + 1) ≤ b / (m + 1) := Nat.div_le_div_right hab refine ⟨b / (m + 1) - a / (m + 1), ?_⟩ rw [Nat.mul_sub_left_distrib]; omega by_cases hxm : x ≤ m · rw [if_pos hxm, show x - m = 0 by omega] have hset : (Finset.Ico 0 x).filter (fun y => y % (m + 1) ≤ r) = Finset.range (min x (r + 1)) := by ext y; simp only [Finset.mem_filter, Finset.mem_Ico, Finset.mem_range] constructor · intro ⟨⟨_, hyx⟩, hmod⟩ rw [Nat.mod_eq_of_lt (by omega : y < m + 1)] at hmod; omega · intro hy; refine ⟨⟨Nat.zero_le _, by omega⟩, ?_⟩ rw [Nat.mod_eq_of_lt (by omega : y < m + 1)]; omega rw [hset, Finset.card_range] · rw [if_neg hxm] have himg : ((Finset.Ico (x - m) x).filter (fun y => y % (m + 1) ≤ r)).image (fun y => y % (m + 1)) = (Finset.range (r + 1)).erase (x % (m + 1)) := by ext v simp only [Finset.mem_image, Finset.mem_filter, Finset.mem_Ico, Finset.mem_erase, Finset.mem_range] constructor · rintro ⟨y, ⟨⟨h1, h2⟩, hmod⟩, rfl⟩ refine ⟨?_, by omega⟩ intro heq have hdvd := hdvd_of_mod_eq y x (le_of_lt h2) heq have hle := Nat.le_of_dvd (by omega) hdvd; omega · rintro ⟨hne, hvr⟩ have hxmod : x % (m + 1) < m + 1 := Nat.mod_lt x (by omega) have hdiv : (m + 1) * (x / (m + 1)) + x % (m + 1) = x := Nat.div_add_mod x (m + 1) by_cases hv : v < x % (m + 1) · let y := (m + 1) * (x / (m + 1)) + v have hy_mod : y % (m + 1) = v := by dsimp only [y]; rw [Nat.mul_add_mod, Nat.mod_eq_of_lt (by omega)] refine ⟨y, ⟨⟨by omega, by omega⟩, by omega⟩, hy_mod⟩ · have hq_pos : 1 ≤ x / (m + 1) := Nat.div_pos (by omega) (by omega) let y := (m + 1) * (x / (m + 1) - 1) + v have hy_eq : y + (m + 1) = (m + 1) * (x / (m + 1)) + v := by dsimp only [y] have : x / (m + 1) = (x / (m + 1) - 1) + 1 := by omega conv_rhs => rw [this, Nat.mul_add, Nat.mul_one] omega have hy_mod : y % (m + 1) = v := by dsimp only [y]; rw [Nat.mul_add_mod, Nat.mod_eq_of_lt (by omega)] refine ⟨y, ⟨⟨by omega, by omega⟩, by omega⟩, hy_mod⟩ have hinj : Set.InjOn (fun y => y % (m + 1)) ↑((Finset.Ico (x - m) x).filter (fun y => y % (m + 1) ≤ r)) := by intro y₁ hy₁ y₂ hy₂ heq simp only [Finset.mem_coe, Finset.mem_filter, Finset.mem_Ico] at hy₁ hy₂ by_contra hne rcases lt_or_gt_of_ne hne with hlt | hgt · have hdvd := hdvd_of_mod_eq y₁ y₂ (le_of_lt hlt) heq have hle := Nat.le_of_dvd (by omega) hdvd; omega · have hdvd := hdvd_of_mod_eq y₂ y₁ (le_of_lt hgt) heq.symm have hle := Nat.le_of_dvd (by omega) hdvd; omega have hcard := Finset.card_image_of_injOn hinj rw [himg] at hcard rw [← hcard] by_cases hxr : x % (m + 1) ≤ r · rw [if_pos hxr, Finset.card_erase_of_mem (Finset.mem_range.mpr (by omega)), Finset.card_range]; omega · rw [if_neg hxr, Finset.erase_eq_of_notMem (by simp; omega), Finset.card_range] /-- **THEOREM 5 (Complete Exact Classification of Normal `k`-Blocking Subtraction `S = {1, …, m}`):** For ALL `m ≥ 1, k ≥ 0, x ≥ 0`: - If `m ≤ k`: `normBlockSub m k x = false` (total collapse to `𝒫`!); - If `k < m`: `normBlockSub m k x = false ↔ x % (m + 1) ≤ k`! -/ theorem normBlockSub_exact {m : ℕ} (hm : 1 ≤ m) (k x : ℕ) : normBlockSub m k x = decide (k < m ∧ ¬ (x % (m + 1) ≤ k)) := by induction x using Nat.strong_induction_on with | h x ih => rw [normBlockSub_eq] by_cases hkm : k < m · have hfilt : (subMoves m x).filter (fun y => normBlockSub m k y = false) = (Finset.Ico (x - m) x).filter (fun y => y % (m + 1) ≤ k) := by rw [subMoves_eq_Ico] apply Finset.filter_congr; intro y hy rw [ih y (by rw [Finset.mem_Ico] at hy; omega)] simp [hkm] rw [hfilt, card_Ico_mod_le hm hkm x] simp only [hkm, true_and, decide_eq_decide] by_cases hxm : x ≤ m · rw [if_pos hxm, Nat.mod_eq_of_lt (by omega : x < m + 1)]; omega · rw [if_neg hxm]; split_ifs <;> omega · have hle : ((subMoves m x).filter (fun y => normBlockSub m k y = false)).card ≤ k := le_trans (Finset.card_filter_le _ _) (by rw [card_subMoves]; omega) simp [hkm, not_lt.mpr hle] /-- **THEOREM 6 (Complete Exact Classification & Freezing Law of Misère `k`-Blocking Subtraction `S = {1, …, m}` — NEW!):** For ALL `m ≥ 1, k ≥ 0, x ≥ 0`: - If `m = 1`: `misBlockSub 1 k x = false ↔ x % 2 = 1` (completely independent of `k`!); - If `m ≥ 2`: `misBlockSub m k x = false ↔ 1 ≤ x ∧ (x - 1) % (m + 1) ≤ min k (m - 1)`! -/ theorem misBlockSub_exact {m : ℕ} (hm : 1 ≤ m) (k x : ℕ) : misBlockSub m k x = if m = 1 then decide (x % 2 = 0) else decide (¬ (1 ≤ x ∧ (x - 1) % (m + 1) ≤ min k (m - 1))) := by by_cases hm1 : m = 1 · subst hm1; rw [if_pos rfl] induction x using Nat.strong_induction_on with | h x ih => rw [misBlockSub_eq, card_subMoves] cases x with | zero => simp [subMoves] | succ x => have hsub : subMoves 1 (x + 1) = {x} := by rw [subMoves_eq_Ico]; ext y; simp only [Finset.mem_Ico, Finset.mem_singleton]; omega rw [hsub, Finset.filter_singleton, ih x (Nat.lt_succ_self x)] by_cases hpar : x % 2 = 0 · simp [hpar, show (x + 1) % 2 ≠ 0 by omega] · simp [hpar, show (x + 1) % 2 = 0 by omega] · rw [if_neg hm1] have hm2 : 2 ≤ m := by omega set r := min k (m - 1) with hr_def have hr_lt : r < m := by omega induction x using Nat.strong_induction_on with | h x ih => rw [misBlockSub_eq, card_subMoves] cases x with | zero => simp [subMoves] | succ x => have hfilt : (subMoves m (x + 1)).filter (fun y => misBlockSub m k y = false) = ((Finset.Ico (x + 1 - m) (x + 1)).filter (fun y => 1 ≤ y ∧ (y - 1) % (m + 1) ≤ r)) := by rw [subMoves_eq_Ico] apply Finset.filter_congr; intro y hy rw [ih y (by rw [Finset.mem_Ico] at hy; omega)] simp rw [hfilt] -- Shift `y ↦ y - 1` cleanly! have hshift : ((Finset.Ico (x + 1 - m) (x + 1)).filter (fun y => 1 ≤ y ∧ (y - 1) % (m + 1) ≤ r)).card = if x + 1 ≤ m then ((Finset.Ico 0 x).filter (fun z => z % (m + 1) ≤ r)).card else ((Finset.Ico (x - m) x).filter (fun z => z % (m + 1) ≤ r)).card := by by_cases hle : x + 1 ≤ m · rw [if_pos hle, show x + 1 - m = 0 by omega] apply Finset.card_bij (fun y _ => y - 1) · intro y hy; simp only [Finset.mem_filter, Finset.mem_Ico] at hy ⊢; omega · intro y₁ hy₁ y₂ hy₂ h; simp only [Finset.mem_filter, Finset.mem_Ico] at hy₁ hy₂; omega · intro z hz; simp only [Finset.mem_filter, Finset.mem_Ico] at hz refine ⟨z + 1, Finset.mem_filter.mpr ⟨Finset.mem_Ico.mpr ⟨by omega, by omega⟩, ?_⟩, by omega⟩ simp only [Nat.add_sub_cancel]; exact ⟨by omega, hz.2⟩ · rw [if_neg hle] apply Finset.card_bij (fun y _ => y - 1) · intro y hy; simp only [Finset.mem_filter, Finset.mem_Ico] at hy ⊢; omega · intro y₁ hy₁ y₂ hy₂ h; simp only [Finset.mem_filter, Finset.mem_Ico] at hy₁ hy₂; omega · intro z hz; simp only [Finset.mem_filter, Finset.mem_Ico] at hz refine ⟨z + 1, Finset.mem_filter.mpr ⟨Finset.mem_Ico.mpr ⟨by omega, by omega⟩, ?_⟩, by omega⟩ simp only [Nat.add_sub_cancel]; exact ⟨by omega, hz.2⟩ rw [hshift] simp only [Nat.succ_sub_one, Nat.one_le_iff_ne_zero, decide_eq_decide] by_cases hle : x + 1 ≤ m · rw [if_pos hle] have hcard0 : ((Finset.Ico 0 x).filter (fun z => z % (m + 1) ≤ r)).card = min x (r + 1) := by have h1 := card_Ico_mod_le hm hr_lt x rw [if_pos (by omega : x ≤ m), show x - m = 0 by omega] at h1 exact h1 rw [hcard0, Nat.mod_eq_of_lt (by omega : x < m + 1)] omega · rw [if_neg hle, card_Ico_mod_le hm hr_lt x] by_cases hxm : x ≤ m · have hx_eq : x = m := by omega rw [hx_eq, if_pos le_rfl, Nat.mod_eq_of_lt (Nat.lt_succ_self m)] omega · rw [if_neg hxm] split_ifs <;> omega /-- **Corollary 6 (Sharp Normal-vs-Misère Freezing Dichotomy for `k`-Blocking Subtraction — NEW!):** For EVERY `m ≥ 2` and EVERY `k ≥ m`: 1. Normal play collapses completely (`normBlockSub m k x = false` for ALL `x`); 2. Misère play NEVER collapses — it freezes permanently at `k = m - 1` (`misBlockSub m k x = misBlockSub m (m - 1) x` for ALL `x`) and retains infinitely many `𝒩`-positions (`misBlockSub m k ((m + 1) * t) = true` for ALL `t : ℕ`)! -/ theorem norm_vs_mis_blockSub_freezing {m k : ℕ} (hm : 2 ≤ m) (hkm : m ≤ k) : (∀ x, normBlockSub m k x = false) ∧ (∀ x, misBlockSub m k x = misBlockSub m (m - 1) x) ∧ (∀ t, misBlockSub m k ((m + 1) * t) = true) := by refine ⟨?_, ?_, ?_⟩ · intro x; rw [normBlockSub_exact (by omega)]; simp [show ¬ (k < m) by omega] · intro x rw [misBlockSub_exact (by omega) k x, misBlockSub_exact (by omega) (m - 1) x, if_neg (by omega), if_neg (by omega), Nat.min_eq_right (by omega), Nat.min_self] · intro t rw [misBlockSub_exact (by omega) k ((m + 1) * t), if_neg (by omega), Nat.min_eq_right (by omega)] simp only [decide_eq_true_eq, not_and] intro hpos have hmod : ((m + 1) * t - 1) % (m + 1) = m := by have ht : 1 ≤ t := by by_contra h0; push Not at h0 have ht0 : t = 0 := by omega subst ht0; simp at hpos have heq : (m + 1) * t - 1 = (m + 1) * (t - 1) + m := by have : t = (t - 1) + 1 := by omega conv_lhs => rw [this, Nat.mul_add, Nat.mul_one] omega rw [heq, Nat.mul_add_mod, Nat.mod_eq_of_lt (Nat.lt_succ_self m)] omega /-! ### 5. Axiom Audits for All Headline Theorems -/ #print axioms mex_insert_ne #print axioms mex_image_swap01_iff_mem_zero_or_one #print axioms passGrundy_succ_ne #print axioms passGrundy_add_two #print axioms passGrundy_even #print axioms passGrundy_odd #print axioms passGrundy_mod_two #print axioms passGrundy_swap01_transfer #print axioms multiPileKPassNim_add_two #print axioms wythoffKPass_add_two #print axioms normBlockWythoff_comm #print axioms misBlockWythoff_comm #print axioms normBlock2Wythoff_exact #print axioms misBlock2Wythoff_exact #print axioms misBlock2Wythoff_diagonal_and_ray_split #print axioms normBlockSub_exact #print axioms misBlockSub_exact #print axioms norm_vs_mis_blockSub_freezing end UniversalPassInvolutionAndBlockingGames