import Mathlib /-! # Exact Sprague–Grundy Theory, Graph-Theoretic Duality, and Misère Collapse of Circular Nim This file formalizes **Circular Nim** $\mathrm{CN}(n, k)$ (Dufour–Heubach, *Electron. J. Combin.* 2013; Dufour–Heubach–Vo, *Integers* 2021; Suetsugu, arXiv:2501.12045) in full generality on $\mathbb{N}^n$, together with its normal-play Sprague–Grundy function $\mathcal{G}_{\mathrm{CN}(n,k)}$, its normal-play $\mathcal{P}$-positions, and its misère-play $\mathcal{P}^-$-positions. ## Main Results 1. **Full $\mathbb{N}^n$ Foundations & Downward Closure**: - `move_sub_iff_untouched_arc`: For $d \le n$, a legal move in $\mathrm{CN}(n, n - d)$ is equivalent to decreasing at least one pile while leaving some $d$ consecutive cyclic piles untouched. - `embedBin_move_iff`: The unit hypercube $\{0, 1\}^n \hookrightarrow \mathbb{N}^n$ is a downward-closed subgame of full $\mathbb{N}^n$ Circular Nim $\mathrm{CN}(n, k)$, so its Sprague–Grundy values and normal/misère $\mathcal{P}$-positions coincide identically with those of the full $\mathbb{N}^n$ game. - `isNormalP_antipodal`: **Antipodal Mirroring Theorem** — for all $m \ge 1$ and $1 \le k \le m$, every antipodally symmetric configuration $p \in \mathbb{N}^{2m}$ ($p_{i+m} = p_i$) is a normal $\mathcal{P}$-position of full $\mathbb{N}^{2m}$ $\mathrm{CN}(2m, k)$. - `isNormalP_sub_one_iff` & `isMisereP_sub_one_iff`: Complete full-$\mathbb{N}^n$ classification of normal and misère $\mathrm{CN}(n, n-1)$ for all $n \ge 2$. 2. **Universal Minimal $d$-Transversal Theorem & Sharp $d = 4$ Breakdown**: - `isNormalP_of_isMinArcTransversal`: For all $2 \le d < n$, every minimal $d$-arc transversal $S$ of $C_n$ gives a normal $\mathcal{P}$-position of $\mathrm{CN}(n, n - d)$. - `sharp_breakdown_ge_four`: For every $d \ge 4$, the antipodal binary state $S = \mathbb{Z}/(2d)\mathbb{Z} \setminus \{0, d\}$ in $\mathrm{CN}(2d, d)$ is a normal $\mathcal{P}$-position that is neither $\emptyset$, nor $\mathrm{univ}$, nor a minimal $d$-arc transversal. 3. **Exact Sprague–Grundy, Perrin Enumeration, and Misère Collapse for $d = 2$ ($\mathrm{CN}(n, n-2)$)**: - `grundy_sub_two_exact`: For all $n \ge 5$ and all $S \subseteq \mathbb{Z}/n\mathbb{Z}$, $$\mathcal{G}_{\mathrm{CN}(n, n-2)}(\mathbf{1}_S) = \begin{cases} 0 & \text{if } S = \emptyset \text{ or } S \in \mathrm{MinVertexCover}(C_n), \\ 1 & \text{if } S = \mathrm{univ}, \\ |S| & \text{otherwise.} \end{cases}$$ - `grundy_four_two_exact`: Exact boundary law for $n = 4$ (where $\mathcal{G}(\mathbf{1}_{\mathrm{univ}}) = 0$). - `card_normalP_sub_two_eq_one_add_perrin`: For all $n \ge 5$, the number of binary normal $\mathcal{P}$-positions of $\mathrm{CN}(n, n - 2)$ is **exactly $1 + P(n)$**, where $P(n)$ is the $n$-th Perrin number (OEIS A001608). - `isMisereP_sub_two_iff` & `card_misereP_sub_two`: For all $n \ge 4$, misère $\mathcal{P}^-$-positions collapse exponentially from $1 + P(n)$ to **exactly $n + 1$** states: $\{e_i\} \cup \{\mathbf{1}_{\mathrm{univ}}\}$. 4. **Exact Sprague–Grundy & Normal/Misère Duality for $d = 3$ ($\mathrm{CN}(n, n-3)$)**: - `grundy_sub_three_exact`: For all $n \ge 7$ and all $S \subseteq \mathbb{Z}/n\mathbb{Z}$, $$\mathcal{G}_{\mathrm{CN}(n, n-3)}(\mathbf{1}_S) = \begin{cases} 0 & \text{if } S = \emptyset \text{ or } S = \mathrm{univ} \text{ or } S \in \mathrm{MinDom}(C_n), \\ 1 & \text{if } S^c \in \mathrm{MIS}(C_n^2), \\ |S| & \text{otherwise.} \end{cases}$$ - `isMisereP_sub_three_iff` & `normal_grundy_one_iff_misereP_sub_three`: For all $n \ge 7$, a binary state $S$ is a misère $\mathcal{P}^-$-position of $\mathrm{CN}^-(n, n-3)$ **if and only if** its normal-play Sprague–Grundy value is $1$ (i.e. $|S| = 1$ or $S^c \in \mathrm{MIS}(C_n^2)$). - `six_three_exception`: Sharpness of $n \ge 7$ — in $\mathrm{CN}(6, 3)$, $S = \{1, 2, 4, 5\}$ is an exceptional normal $\mathcal{P}$-position outside $\{\emptyset, \mathrm{univ}\} \cup \mathrm{MinDom}(C_6)$. -/ open scoped Classical open Finset namespace CircularNim /-! ### Section 0: Modular Arithmetic & Finset Helpers -/ lemma zmod_natCast_ne_zero {n a : ℕ} [NeZero n] (hpos : 0 < a) (hlt : a < n) : (a : ZMod n) ≠ 0 := by intro h have hdvd : n ∣ a := (ZMod.natCast_eq_zero_iff a n).mp h exact Nat.not_dvd_of_pos_of_lt hpos hlt hdvd lemma zmod_add_natCast_ne {n a b : ℕ} [NeZero n] (x : ZMod n) (h : a < b) (hbn : b - a < n) : x + (a : ZMod n) ≠ x + (b : ZMod n) := by intro heq have h1 : (b : ZMod n) - (a : ZMod n) = 0 := by linear_combination -heq have h2 : ((b - a : ℕ) : ZMod n) = 0 := by rw [Nat.cast_sub (le_of_lt h)] exact h1 exact zmod_natCast_ne_zero (by omega) hbn h2 lemma zmod_add_sub_natCast_ne {n a b : ℕ} [NeZero n] (x : ZMod n) (hpos : 0 < a + b) (hlt : a + b < n) : x - (a : ZMod n) ≠ x + (b : ZMod n) := by intro heq have h1 : ((a + b : ℕ) : ZMod n) = 0 := by rw [Nat.cast_add]; linear_combination -heq exact zmod_natCast_ne_zero hpos hlt h1 lemma ne_univ_of_ssubset {α : Type*} [Fintype α] {S T : Finset α} (h : T ⊂ S) : T ≠ Finset.univ := by intro hu; subst hu exact h.2 (Finset.subset_univ S) lemma exists_not_mem_finset (s : Finset ℕ) : ∃ v : ℕ, v ∉ s := by refine ⟨s.sup id + 1, fun h => ?_⟩ have hle : s.sup id + 1 ≤ s.sup id := Finset.le_sup (f := id) h omega /-- Minimum excluded natural number (`mex`) of a finite set of natural numbers. -/ noncomputable def mexFinset (s : Finset ℕ) : ℕ := Nat.find (exists_not_mem_finset s) lemma mexFinset_not_mem (s : Finset ℕ) : mexFinset s ∉ s := Nat.find_spec (exists_not_mem_finset s) lemma mem_of_lt_mexFinset {s : Finset ℕ} {u : ℕ} (hu : u < mexFinset s) : u ∈ s := by_contra fun h => Nat.find_min (exists_not_mem_finset s) hu h lemma mexFinset_eq_of_spec {s : Finset ℕ} {v : ℕ} (hv : v ∉ s) (hlt : ∀ u < v, u ∈ s) : mexFinset s = v := by apply le_antisymm · exact Nat.find_min' (exists_not_mem_finset s) hv · by_contra h push Not at h exact mexFinset_not_mem s (hlt _ h) /-- Helper: picking a subset of exact cardinality `r` from a finset of size `≥ r`. -/ lemma exists_subset_card {α : Type*} (A : Finset α) {r : ℕ} (hr : r ≤ A.card) : ∃ R ⊆ A, R.card = r := Finset.exists_subset_card_eq hr /-- Cyclic walk helper: if `S ⊆ ZMod n` is nonempty and `S ≠ univ`, then there is a `0` followed immediately by a `1`, and a `1` followed immediately by a `0`. -/ lemma exists_zero_one_edge {n : ℕ} [NeZero n] {S : Finset (ZMod n)} (hne : S.Nonempty) (hnu : S ≠ Finset.univ) : ∃ z : ZMod n, z ∉ S ∧ z + 1 ∈ S := by by_contra hall push Not at hall have hnotuniv : ∃ z₀ : ZMod n, z₀ ∉ S := by by_contra h push Not at h exact hnu (Finset.eq_univ_iff_forall.mpr h) obtain ⟨z₀, hz₀⟩ := hnotuniv have hind : ∀ t : ℕ, z₀ + (t : ZMod n) ∉ S := by intro t induction t with | zero => simpa using hz₀ | succ t ih => rw [Nat.cast_succ, ← add_assoc] exact hall _ ih obtain ⟨x, hx⟩ := hne have hrepr : x = z₀ + (((x - z₀).val : ℕ) : ZMod n) := by rw [ZMod.natCast_zmod_val]; ring rw [hrepr] at hx exact hind (x - z₀).val hx lemma exists_zero_zero_one {n : ℕ} [NeZero n] {S : Finset (ZMod n)} (hne : S.Nonempty) (h00 : ∃ z : ZMod n, z ∉ S ∧ z + 1 ∉ S) : ∃ z : ZMod n, z ∉ S ∧ z + 1 ∉ S ∧ z + 2 ∈ S := by obtain ⟨z₀, hz₀, hz₁⟩ := h00 obtain ⟨x, hx⟩ := hne have hex : ∃ t : ℕ, z₀ + (t : ZMod n) ∈ S := by refine ⟨(x - z₀).val, ?_⟩ have : z₀ + (((x - z₀).val : ℕ) : ZMod n) = x := by rw [ZMod.natCast_zmod_val]; ring rwa [this] let t := Nat.find hex have ht_mem : z₀ + (t : ZMod n) ∈ S := Nat.find_spec hex have ht_ne0 : t ≠ 0 := by intro h0; rw [h0] at ht_mem; simp only [Nat.cast_zero, add_zero] at ht_mem; exact hz₀ ht_mem have ht_ne1 : t ≠ 1 := by intro h1; rw [h1] at ht_mem; simp only [Nat.cast_one] at ht_mem; exact hz₁ ht_mem have ht_ge2 : 2 ≤ t := by omega refine ⟨z₀ + ((t - 2 : ℕ) : ZMod n), ?_, ?_, ?_⟩ · exact Nat.find_min hex (by omega) · have h1 : z₀ + ((t - 2 : ℕ) : ZMod n) + 1 = z₀ + ((t - 1 : ℕ) : ZMod n) := by have : (t - 2 : ℕ) + 1 = t - 1 := by omega rw [add_assoc, ← Nat.cast_one, ← Nat.cast_add, this] rw [h1] exact Nat.find_min hex (by omega) · have h2 : z₀ + ((t - 2 : ℕ) : ZMod n) + 2 = z₀ + (t : ZMod n) := by have : (t - 2 : ℕ) + 2 = t := by omega rw [add_assoc, show (2 : ZMod n) = ((2 : ℕ) : ZMod n) by norm_num, ← Nat.cast_add, this] rw [h2] exact ht_mem /-- If `S ≠ univ` has 5 consecutive `1`s, then there is a `0` preceded by 5 consecutive `1`s. -/ lemma exists_five_ones_before_zero {n : ℕ} [NeZero n] {S : Finset (ZMod n)} (hnu : S ≠ Finset.univ) (h5 : ∃ a : ZMod n, a ∈ S ∧ a + 1 ∈ S ∧ a + 2 ∈ S ∧ a + 3 ∈ S ∧ a + 4 ∈ S) : ∃ z : ZMod n, z ∉ S ∧ z - 1 ∈ S ∧ z - 2 ∈ S ∧ z - 3 ∈ S ∧ z - 4 ∈ S ∧ z - 5 ∈ S := by obtain ⟨a, ha0, ha1, ha2, ha3, ha4⟩ := h5 have hex0 : ∃ z₀ : ZMod n, z₀ ∉ S := by by_contra h; push Not at h; exact hnu (Finset.eq_univ_iff_forall.mpr h) obtain ⟨z₀, hz₀⟩ := hex0 have hex : ∃ t : ℕ, a + (t : ZMod n) ∉ S := by refine ⟨(z₀ - a).val, ?_⟩ have : a + (((z₀ - a).val : ℕ) : ZMod n) = z₀ := by rw [ZMod.natCast_zmod_val]; ring rwa [this] let t := Nat.find hex have ht_nmem : a + (t : ZMod n) ∉ S := Nat.find_spec hex have ht_ge5 : 5 ≤ t := by by_contra hlt push Not at hlt interval_cases t · exact ht_nmem (by simpa using ha0) · exact ht_nmem (by simpa using ha1) · exact ht_nmem (by simpa using ha2) · exact ht_nmem (by simpa using ha3) · exact ht_nmem (by simpa using ha4) refine ⟨a + (t : ZMod n), ht_nmem, ?_, ?_, ?_, ?_, ?_⟩ · have hmem : a + ((t - 1 : ℕ) : ZMod n) ∈ S := by by_contra h; exact Nat.find_min hex (by omega) h have heq : a + (t : ZMod n) - 1 = a + ((t - 1 : ℕ) : ZMod n) := by rw [Nat.cast_sub (by omega), Nat.cast_one]; ring rwa [heq] · have hmem : a + ((t - 2 : ℕ) : ZMod n) ∈ S := by by_contra h; exact Nat.find_min hex (by omega) h have heq : a + (t : ZMod n) - 2 = a + ((t - 2 : ℕ) : ZMod n) := by rw [Nat.cast_sub (by omega), Nat.cast_ofNat]; ring rwa [heq] · have hmem : a + ((t - 3 : ℕ) : ZMod n) ∈ S := by by_contra h; exact Nat.find_min hex (by omega) h have heq : a + (t : ZMod n) - 3 = a + ((t - 3 : ℕ) : ZMod n) := by rw [Nat.cast_sub (by omega), Nat.cast_ofNat]; ring rwa [heq] · have hmem : a + ((t - 4 : ℕ) : ZMod n) ∈ S := by by_contra h; exact Nat.find_min hex (by omega) h have heq : a + (t : ZMod n) - 4 = a + ((t - 4 : ℕ) : ZMod n) := by rw [Nat.cast_sub (by omega), Nat.cast_ofNat]; ring rwa [heq] · have hmem : a + ((t - 5 : ℕ) : ZMod n) ∈ S := by by_contra h; exact Nat.find_min hex (by omega) h have heq : a + (t : ZMod n) - 5 = a + ((t - 5 : ℕ) : ZMod n) := by rw [Nat.cast_sub (by omega), Nat.cast_ofNat]; ring rwa [heq] /-! ### Section 1: Full $\mathbb{N}^n$ Circular Nim $\mathrm{CN}(n, k)$ Foundation -/ /-- A legal move in Circular Nim $\mathrm{CN}(n, k)$: choose $k$ consecutive piles starting at $s \in \mathbb{Z}/n\mathbb{Z}$ and remove at least one token in total from those $k$ piles. -/ def Move (n k : ℕ) [NeZero n] (p q : ZMod n → ℕ) : Prop := (∀ i, q i ≤ p i) ∧ (∃ i, q i < p i) ∧ (∃ s : ZMod n, ∀ i, q i < p i → ∃ j : Fin k, i = s + (j : ℕ)) /-- Total number of tokens across all $n$ piles. -/ def totalTokens {n : ℕ} [NeZero n] (p : ZMod n → ℕ) : ℕ := ∑ i : ZMod n, p i lemma totalTokens_lt_of_move {n k : ℕ} [NeZero n] {p q : ZMod n → ℕ} (h : Move n k p q) : totalTokens q < totalTokens p := by obtain ⟨hle, ⟨i, hi⟩, _⟩ := h exact Finset.sum_lt_sum (fun x _ => hle x) ⟨i, Finset.mem_univ i, hi⟩ /-- Normal-play $\mathcal{P}$-position (previous player wins) in $\mathrm{CN}(n, k)$. -/ def IsNormalP (n k : ℕ) [NeZero n] (p : ZMod n → ℕ) : Prop := ∀ q, Move n k p q → ¬ IsNormalP n k q termination_by totalTokens p decreasing_by exact totalTokens_lt_of_move ‹_› /-- Misère-play $\mathcal{P}^-$-position (previous player wins when last mover loses). -/ def IsMisereP (n k : ℕ) [NeZero n] (p : ZMod n → ℕ) : Prop := (∃ q, Move n k p q) ∧ ∀ q, Move n k p q → ¬ IsMisereP n k q termination_by totalTokens p decreasing_by exact totalTokens_lt_of_move ‹_› lemma isNormalP_iff (n k : ℕ) [NeZero n] (p : ZMod n → ℕ) : IsNormalP n k p ↔ ∀ q, Move n k p q → ¬ IsNormalP n k q := by rw [IsNormalP] lemma isMisereP_iff (n k : ℕ) [NeZero n] (p : ZMod n → ℕ) : IsMisereP n k p ↔ (∃ q, Move n k p q) ∧ ∀ q, Move n k p q → ¬ IsMisereP n k q := by rw [IsMisereP] lemma isNormalP_zero (n k : ℕ) [NeZero n] : IsNormalP n k (fun _ => 0) := by rw [isNormalP_iff] intro q ⟨_, ⟨i, hi⟩, _⟩ exact absurd hi (Nat.not_lt_zero _) lemma not_isMisereP_zero (n k : ℕ) [NeZero n] : ¬ IsMisereP n k (fun _ => 0) := by rw [isMisereP_iff] rintro ⟨⟨q, _, ⟨i, hi⟩, _⟩, _⟩ exact Nat.not_lt_zero _ hi /-- Finite set of all legal options from state `p` in $\mathrm{CN}(n, k)$. -/ noncomputable def optionFinset (n k : ℕ) [NeZero n] (p : ZMod n → ℕ) : Finset (ZMod n → ℕ) := (Fintype.piFinset (fun i : ZMod n => Finset.range (p i + 1))).filter (fun q => Move n k p q) lemma mem_optionFinset {n k : ℕ} [NeZero n] {p q : ZMod n → ℕ} : q ∈ optionFinset n k p ↔ Move n k p q := by simp only [optionFinset, Finset.mem_filter, Fintype.mem_piFinset, Finset.mem_range, Nat.lt_succ_iff, and_iff_right_iff_imp] intro h exact h.1 /-- The exact **Sprague–Grundy (nim) value** of a position `p : ZMod n → ℕ` in full $\mathbb{N}^n$ Circular Nim $\mathrm{CN}(n, k)$. -/ noncomputable def grundy (n k : ℕ) [NeZero n] (p : ZMod n → ℕ) : ℕ := mexFinset ((optionFinset n k p).attach.image (fun x => grundy n k x.1)) termination_by totalTokens p decreasing_by exact totalTokens_lt_of_move (mem_optionFinset.mp x.2) lemma grundy_ne_of_move {n k : ℕ} [NeZero n] {p q : ZMod n → ℕ} (h : Move n k p q) : grundy n k q ≠ grundy n k p := by intro heq have hmem : grundy n k p ∈ (optionFinset n k p).attach.image (fun x => grundy n k x.1) := by rw [Finset.mem_image] exact ⟨⟨q, mem_optionFinset.mpr h⟩, Finset.mem_attach _ _, heq⟩ have hnot := mexFinset_not_mem ((optionFinset n k p).attach.image (fun x => grundy n k x.1)) rw [← grundy] at hnot exact hnot hmem lemma exists_move_grundy_eq_of_lt {n k : ℕ} [NeZero n] {p : ZMod n → ℕ} {u : ℕ} (hu : u < grundy n k p) : ∃ q, Move n k p q ∧ grundy n k q = u := by rw [grundy] at hu have hmem := mem_of_lt_mexFinset hu rw [Finset.mem_image] at hmem obtain ⟨⟨q, hq⟩, _, hval⟩ := hmem exact ⟨q, mem_optionFinset.mp hq, hval⟩ /-- Fundamental characterization of the Sprague–Grundy value at `p`. -/ lemma grundy_eq_of_spec {n k : ℕ} [NeZero n] {p : ZMod n → ℕ} {v : ℕ} (hne : ∀ q, Move n k p q → grundy n k q ≠ v) (hlt : ∀ u < v, ∃ q, Move n k p q ∧ grundy n k q = u) : grundy n k p = v := by rw [grundy] apply mexFinset_eq_of_spec · intro hmem rw [Finset.mem_image] at hmem obtain ⟨⟨q, hq⟩, _, hval⟩ := hmem exact hne q (mem_optionFinset.mp hq) hval · intro u hu obtain ⟨q, hq, hval⟩ := hlt u hu rw [Finset.mem_image] exact ⟨⟨q, mem_optionFinset.mpr hq⟩, Finset.mem_attach _ _, hval⟩ /-- A position has Sprague–Grundy value $0$ if and only if it is a normal $\mathcal{P}$-position. -/ theorem grundy_eq_zero_iff_isNormalP (n k : ℕ) [NeZero n] (p : ZMod n → ℕ) : grundy n k p = 0 ↔ IsNormalP n k p := by suffices ∀ m (p : ZMod n → ℕ), totalTokens p = m → (grundy n k p = 0 ↔ IsNormalP n k p) from this (totalTokens p) p rfl intro m induction m using Nat.strong_induction_on with | h m ih => intro p hp rw [isNormalP_iff] constructor · intro hg q hq have hne := grundy_ne_of_move hq rw [hg] at hne exact fun hP => hne ((ih (totalTokens q) (hp ▸ totalTokens_lt_of_move hq) q rfl).mpr hP) · intro hP apply grundy_eq_of_spec · intro q hq hg0 exact hP q hq ((ih (totalTokens q) (hp ▸ totalTokens_lt_of_move hq) q rfl).mp hg0) · intro u hu; omega /-- **Untouched-Arc Duality**: For $d \le n$, a legal move in $\mathrm{CN}(n, n - d)$ is equivalent to decreasing at least one pile while leaving $d$ consecutive cyclic piles completely untouched. -/ theorem move_sub_iff_untouched_arc {n d : ℕ} [NeZero n] (hd : d ≤ n) (p q : ZMod n → ℕ) : Move n (n - d) p q ↔ (∀ i, q i ≤ p i) ∧ (∃ i, q i < p i) ∧ (∃ s : ZMod n, ∀ j : Fin d, q (s + (j : ℕ)) = p (s + (j : ℕ))) := by constructor · rintro ⟨hle, hex, s, harc⟩ refine ⟨hle, hex, s + ((n - d : ℕ) : ZMod n), ?_⟩ intro j apply le_antisymm (hle _) by_contra hlt push Not at hlt obtain ⟨j', hj'⟩ := harc _ hlt have hdiff : ((n - d + j.val : ℕ) : ZMod n) = (j'.val : ZMod n) := by have := congrArg (fun t => t - s) hj' simpa [Nat.cast_add, add_assoc] using this have h1 : (n - d + j.val) % n = j'.val % n := by have hv := congrArg ZMod.val hdiff rwa [ZMod.val_natCast, ZMod.val_natCast] at hv rw [Nat.mod_eq_of_lt (by omega), Nat.mod_eq_of_lt (by omega)] at h1 omega · rintro ⟨hle, hex, s, hunt⟩ refine ⟨hle, hex, s + (d : ZMod n), ?_⟩ intro i hi let r := (i - s).val have hr_lt : r < n := ZMod.val_lt _ have hr_ge : d ≤ r := by by_contra hlt push Not at hlt have heq : s + (r : ZMod n) = i := by simp only [r, ZMod.natCast_zmod_val]; ring have hsame := hunt ⟨r, hlt⟩ rw [heq] at hsame omega refine ⟨⟨r - d, by omega⟩, ?_⟩ have hsum : (d : ZMod n) + ((r - d : ℕ) : ZMod n) = (r : ZMod n) := by rw [← Nat.cast_add, Nat.add_sub_of_le hr_ge] rw [add_assoc, hsum] simp only [r, ZMod.natCast_zmod_val]; ring /-- **Universal Full-$\mathbb{N}^n$ Normal-Play $\mathcal{P}$-position Criterion**: If `P` is a predicate on `ZMod n → ℕ` such that (1) no move stays inside `P`, and (2) every state outside `P` has a move into `P`, then `IsNormalP n k = P`. -/ theorem isNormalP_eq_of_spec {n k : ℕ} [NeZero n] (P : (ZMod n → ℕ) → Prop) (hclosed : ∀ p, P p → ∀ q, Move n k p q → ¬ P q) (hescape : ∀ p, ¬ P p → ∃ q, Move n k p q ∧ P q) : ∀ p, IsNormalP n k p ↔ P p := by suffices ∀ m p, totalTokens p = m → (IsNormalP n k p ↔ P p) from fun p => this (totalTokens p) p rfl intro m induction m using Nat.strong_induction_on with | h m ih => intro p hp rw [isNormalP_iff] constructor · intro hN by_contra hnotP obtain ⟨q, hq, hPq⟩ := hescape p hnotP exact hN q hq ((ih (totalTokens q) (hp ▸ totalTokens_lt_of_move hq) q rfl).mpr hPq) · intro hPp q hq hNq have hPq := (ih (totalTokens q) (hp ▸ totalTokens_lt_of_move hq) q rfl).mp hNq exact hclosed p hPp q hq hPq /-- **Universal Full-$\mathbb{N}^n$ Misère $\mathcal{P}^-$-position Criterion**. -/ theorem isMisereP_eq_of_spec {n k : ℕ} [NeZero n] (P : (ZMod n → ℕ) → Prop) (hnonterm : ∀ p, P p → ∃ q, Move n k p q) (hclosed : ∀ p, P p → ∀ q, Move n k p q → ¬ P q) (hescape : ∀ p, ¬ P p → (∃ q, Move n k p q) → ∃ q, Move n k p q ∧ P q) : ∀ p, IsMisereP n k p ↔ P p := by suffices ∀ m p, totalTokens p = m → (IsMisereP n k p ↔ P p) from fun p => this (totalTokens p) p rfl intro m induction m using Nat.strong_induction_on with | h m ih => intro p hp rw [isMisereP_iff] constructor · rintro ⟨hmov, hno⟩ by_contra hnotP obtain ⟨q, hq, hPq⟩ := hescape p hnotP hmov exact hno q hq ((ih (totalTokens q) (hp ▸ totalTokens_lt_of_move hq) q rfl).mpr hPq) · intro hPp refine ⟨hnonterm p hPp, fun q hq hNq => ?_⟩ have hPq := (ih (totalTokens q) (hp ▸ totalTokens_lt_of_move hq) q rfl).mp hNq exact hclosed p hPp q hq hPq /-- **Antipodal Mirroring Theorem (Full $\mathbb{N}^{2m}$)**: For every $m \ge 1$ and $1 \le k \le m$, every antipodally symmetric configuration $p : \mathbb{Z}/(2m)\mathbb{Z} \to \mathbb{N}$ ($p(i + m) = p(i)$) is a normal $\mathcal{P}$-position of $\mathrm{CN}(2m, k)$. -/ theorem isNormalP_antipodal {m k : ℕ} (hm : 1 ≤ m) (hk : k ≤ m) : letI : NeZero (2 * m) := ⟨by omega⟩ ∀ p : ZMod (2 * m) → ℕ, (∀ i, p (i + (m : ZMod (2 * m))) = p i) → IsNormalP (2 * m) k p := by let : NeZero (2 * m) := ⟨by omega⟩ suffices ∀ t (p : ZMod (2 * m) → ℕ), totalTokens p = t → (∀ i, p (i + (m : ZMod (2 * m))) = p i) → IsNormalP (2 * m) k p from fun p hp => this (totalTokens p) p rfl hp intro t induction t using Nat.strong_induction_on with | h t ih => intro p ht hsym rw [isNormalP_iff] intro q hq hNq obtain ⟨hle, ⟨i₀, hi₀⟩, s, harc⟩ := hq -- Define the mirrored state r: apply the exact same reductions on the antipodal arc s + m let r : ZMod (2 * m) → ℕ := fun i => if q i < p i then q i else q (i + (m : ZMod (2 * m))) -- First note that the arc {s + j | j < k} and its antipodal shift {s + m + j | j < k} are disjoint! have hdisj : ∀ i, q i < p i → ¬ (q (i + (m : ZMod (2 * m))) < p (i + (m : ZMod (2 * m)))) := by intro i hi1 hi2 obtain ⟨j1, hj1⟩ := harc i hi1 obtain ⟨j2, hj2⟩ := harc (i + (m : ZMod (2 * m))) hi2 have hdiff : ((m + j1.val : ℕ) : ZMod (2 * m)) = (j2.val : ZMod (2 * m)) := by have h' : s + (j1.val : ZMod (2 * m)) + (m : ZMod (2 * m)) = s + (j2.val : ZMod (2 * m)) := by rw [← hj1, hj2] have := congrArg (fun x => x - s) h' simpa [Nat.cast_add, add_assoc, add_left_comm, add_comm] using this have hv := congrArg ZMod.val hdiff simp only [ZMod.val_natCast] at hv rw [Nat.mod_eq_of_lt (by omega), Nat.mod_eq_of_lt (by omega)] at hv omega have hm2 : (m : ZMod (2 * m)) + (m : ZMod (2 * m)) = 0 := by rw [← Nat.cast_add, show m + m = 2 * m by omega, ZMod.natCast_self] have hinv : ∀ i : ZMod (2 * m), i + (m : ZMod (2 * m)) + (m : ZMod (2 * m)) = i := by intro i; rw [add_assoc, hm2, add_zero] -- Show r is antipodally symmetric have hrsym : ∀ i, r (i + (m : ZMod (2 * m))) = r i := by intro i dsimp only [r] rw [hinv i] by_cases h1 : q i < p i · rw [if_pos h1, if_neg (hdisj i h1)] · by_cases h2 : q (i + (m : ZMod (2 * m))) < p (i + (m : ZMod (2 * m))) · rw [if_pos h2, if_neg h1] · rw [if_neg h2, if_neg h1] have e1 : q i = p i := le_antisymm (hle i) (not_lt.mp h1) have e2 : q (i + (m : ZMod (2 * m))) = p (i + (m : ZMod (2 * m))) := le_antisymm (hle _) (not_lt.mp h2) rw [e1, e2, hsym i] -- Show Move (2*m) k q r have hqr : Move (2 * m) k q r := by refine ⟨?_, ?_, s + (m : ZMod (2 * m)), ?_⟩ · intro i dsimp only [r] by_cases h1 : q i < p i · rw [if_pos h1] · rw [if_neg h1] have e1 : q i = p i := le_antisymm (hle i) (not_lt.mp h1) rw [e1, ← hsym i] exact hle (i + (m : ZMod (2 * m))) · refine ⟨i₀ + (m : ZMod (2 * m)), ?_⟩ dsimp only [r] rw [if_neg (hdisj i₀ hi₀), hinv i₀] have e2 : q (i₀ + (m : ZMod (2 * m))) = p (i₀ + (m : ZMod (2 * m))) := le_antisymm (hle _) (not_lt.mp (hdisj i₀ hi₀)) rw [e2, hsym i₀] exact hi₀ · intro i hi dsimp only [r] at hi by_cases h1 : q i < p i · rw [if_pos h1] at hi; exact absurd hi (lt_irrefl _) · rw [if_neg h1] at hi have e1 : q i = p i := le_antisymm (hle i) (not_lt.mp h1) rw [e1, ← hsym i] at hi obtain ⟨j, hj⟩ := harc (i + (m : ZMod (2 * m))) hi refine ⟨j, ?_⟩ have := congrArg (fun x => x + (m : ZMod (2 * m))) hj rw [hinv i] at this rw [this]; ring have hlt_t : totalTokens r < t := by rw [← ht] exact lt_trans (totalTokens_lt_of_move hqr) (totalTokens_lt_of_move ⟨hle, ⟨i₀, hi₀⟩, s, harc⟩) have hrP : IsNormalP (2 * m) k r := ih (totalTokens r) hlt_t r rfl hrsym rw [isNormalP_iff] at hNq exact hNq r hqr hrP /-- **Full $\mathbb{N}^n$ Normal $\mathrm{CN}(n, n - 1)$ Classification** ($n \ge 2$): $p$ is a normal $\mathcal{P}$-position iff all $n$ piles are equal. -/ theorem isNormalP_sub_one_iff {n : ℕ} [NeZero n] (hn : 2 ≤ n) (p : ZMod n → ℕ) : IsNormalP n (n - 1) p ↔ ∀ i j : ZMod n, p i = p j := by apply isNormalP_eq_of_spec (fun p => ∀ i j, p i = p j) · intro p hconst q hq hqconst rw [move_sub_iff_untouched_arc (by omega)] at hq obtain ⟨_, ⟨i, hi⟩, s, hunt⟩ := hq have hs : q s = p s := by simpa using hunt ⟨0, by omega⟩ have h1 : q i = q s := hqconst i s have h2 : p i = p s := hconst i s omega · intro p hnot push Not at hnot obtain ⟨i₁, i₂, hne⟩ := hnot -- Let m = min_{i} p i, achieved at some s have hne_u : (Finset.univ : Finset (ZMod n)).Nonempty := Finset.univ_nonempty obtain ⟨s, _, hs_min⟩ := Finset.exists_min_image Finset.univ p hne_u let q : ZMod n → ℕ := fun _ => p s refine ⟨q, ?_, fun _ _ => rfl⟩ rw [move_sub_iff_untouched_arc (by omega)] refine ⟨fun i => hs_min i (Finset.mem_univ i), ?_, s, fun j => by simp [q]⟩ by_cases h1 : p s < p i₁ · exact ⟨i₁, h1⟩ · have heq1 : p i₁ = p s := le_antisymm (not_lt.mp h1) (hs_min i₁ (Finset.mem_univ _)) have h2 : p s < p i₂ := lt_of_le_of_ne (hs_min i₂ (Finset.mem_univ _)) (by omega) exact ⟨i₂, h2⟩ /-- Helper: singleton unit vector $e_a : \mathbb{Z}/n\mathbb{Z} \to \mathbb{N}$. -/ def unitPile {n : ℕ} (a : ZMod n) : ZMod n → ℕ := fun i => if i = a then 1 else 0 /-- **Full $\mathbb{N}^n$ Misère $\mathrm{CN}^-(n, n - 1)$ Classification** ($n \ge 2$): $p$ is a misère $\mathcal{P}^-$-position iff either $p$ is a single token on one pile ($e_a$), or all $n$ piles are equal and $\ge 2$. -/ theorem isMisereP_sub_one_iff {n : ℕ} [NeZero n] (hn : 2 ≤ n) (p : ZMod n → ℕ) : IsMisereP n (n - 1) p ↔ (∃ a : ZMod n, p = unitPile a) ∨ (∃ c ≥ 2, ∀ i : ZMod n, p i = c) := by let P : (ZMod n → ℕ) → Prop := fun p => (∃ a : ZMod n, p = unitPile a) ∨ (∃ c ≥ 2, ∀ i : ZMod n, p i = c) apply isMisereP_eq_of_spec P · -- Nonterminal intro p hP rcases hP with ⟨a, rfl⟩ | ⟨c, hc, hconst⟩ · refine ⟨fun _ => 0, ?_⟩ rw [move_sub_iff_untouched_arc (by omega)] refine ⟨fun _ => Nat.zero_le _, ⟨a, by simp [unitPile]⟩, a + 1, fun j => ?_⟩ have hne : a + 1 ≠ a := by intro h; have := congrArg (fun x => x - a) h simp only [add_sub_cancel_left, sub_self] at this exact zmod_natCast_ne_zero (n := n) (a := 1) (by omega) (by omega) (by simpa using this) simp [unitPile, hne] · refine ⟨fun i => if i = 0 then c else 0, ?_⟩ rw [move_sub_iff_untouched_arc (by omega)] refine ⟨fun i => by split_ifs <;> simp [hconst], ⟨1, ?_⟩, 0, fun j => by simp [hconst]⟩ have h10 : (1 : ZMod n) ≠ 0 := by simpa using zmod_natCast_ne_zero (n := n) (a := 1) (by omega) (by omega) simp [h10, hconst]; omega · -- Closed: no move from P stays in P intro p hP q hq hPq rw [move_sub_iff_untouched_arc (by omega)] at hq obtain ⟨hle, ⟨i₀, hi₀⟩, s, hunt⟩ := hq have hs : q s = p s := by simpa using hunt ⟨0, by omega⟩ rcases hP with ⟨a, rfl⟩ | ⟨c, hc, hconst⟩ · -- p = unitPile a, so q must be all zeros! have hq0 : ∀ i, q i = 0 := by intro i by_cases hia : i = a · subst hia have hi0a : i₀ = i := by by_contra hne; simp [unitPile, hne] at hi₀ subst hi0a; simp [unitPile] at hi₀; omega · have := hle i; simp [unitPile, hia] at this; exact this rcases hPq with ⟨b, rfl⟩ | ⟨d, hd, hqd⟩ · have := hq0 b; simp [unitPile] at this · have := hq0 0; rw [hqd 0] at this; omega · -- p is constant c >= 2 rcases hPq with ⟨b, rfl⟩ | ⟨d, hd, hqd⟩ · -- q = unitPile b, but q s = p s = c >= 2, contradiction since unitPile b s <= 1! rw [hconst s] at hs have : unitPile b s ≤ 1 := by dsimp [unitPile]; split_ifs <;> omega omega · rw [hqd s, hconst s] at hs rw [hqd i₀, hconst i₀] at hi₀ omega · -- Escape: every nonterminal p ∉ P has a move into P intro p hnotP hmov obtain ⟨q₀, hq₀⟩ := hmov have hex_pos : ∃ i, 0 < p i := by obtain ⟨_, ⟨i, hi⟩, _⟩ := hq₀; exact ⟨i, by omega⟩ obtain ⟨s, _, hs_min⟩ := Finset.exists_min_image Finset.univ p Finset.univ_nonempty by_cases hmin2 : 2 ≤ p s · -- Move to constant p s >= 2 (since p ∉ P, p is not already constant!) have hnotconst : ∃ i, p s < p i := by by_contra h; push Not at h exact hnotP (Or.inr ⟨p s, hmin2, fun i => le_antisymm (h i) (hs_min i (Finset.mem_univ _))⟩) obtain ⟨i₀, hi₀⟩ := hnotconst refine ⟨fun _ => p s, ?_, Or.inr ⟨p s, hmin2, fun _ => rfl⟩⟩ rw [move_sub_iff_untouched_arc (by omega)] refine ⟨fun i => hs_min i (Finset.mem_univ _), ⟨i₀, hi₀⟩, s, fun j => by simp⟩ · -- p s ≤ 1 by_cases hmin1 : p s = 1 · -- Some pile has value 1 (at s); since p ∉ P, p ≠ unitPile s, so some OTHER pile > 0! have hother : ∃ i, i ≠ s ∧ 0 < p i := by obtain ⟨i, hi⟩ : ∃ i : ZMod n, i ≠ s := ⟨s + 1, by intro h; have := congrArg (fun x => x - s) h simp only [add_sub_cancel_left, sub_self] at this exact zmod_natCast_ne_zero (n := n) (a := 1) (by omega) (by omega) (by simpa using this)⟩ exact ⟨i, hi, by have := hs_min i (Finset.mem_univ _); omega⟩ obtain ⟨i₀, hi₀ne, hi₀pos⟩ := hother refine ⟨unitPile s, ?_, Or.inl ⟨s, rfl⟩⟩ rw [move_sub_iff_untouched_arc (by omega)] refine ⟨fun i => ?_, ⟨i₀, by simp [unitPile, hi₀ne, hi₀pos]⟩, s, fun j => by simp [unitPile, hmin1]⟩ dsimp [unitPile] split_ifs with h · subst h; omega · exact Nat.zero_le _ · -- p s = 0, and some pile a has p a ≥ 1 have hps0 : p s = 0 := by omega obtain ⟨a, ha⟩ := hex_pos -- Move to unitPile a leaving s untouched (since p s = 0 = unitPile a s!) have has : a ≠ s := by intro h; subst h; omega have hstrict : ∃ i, unitPile a i < p i := by by_contra h; push Not at h have heq : p = unitPile a := by funext i by_cases hia : i = a · subst hia by_cases hgt : 1 < p i · exfalso; exact absurd (h i) (by simp [unitPile]; omega) · simp [unitPile]; omega · have := h i; simp [unitPile, hia] at this by_cases hpos : 0 < p i · exfalso; exact absurd (h i) (by simp [unitPile, hia]; omega) · simp [unitPile, hia]; omega exact hnotP (Or.inl ⟨a, heq⟩) refine ⟨unitPile a, ?_, Or.inl ⟨a, rfl⟩⟩ rw [move_sub_iff_untouched_arc (by omega)] refine ⟨fun i => ?_, hstrict, s, fun j => by simp [unitPile, has.symm, hps0]⟩ dsimp [unitPile] split_ifs with h · subst h; omega · exact Nat.zero_le _ /-! ### Section 2: Unit Hypercube Embedding $\{0, 1\}^n \hookrightarrow \mathbb{N}^n$ & Downward Closure -/ /-- Embed a subset `S : Finset (ZMod n)` as its indicator binary pile configuration in `ZMod n → ℕ`. -/ def embedBin {n : ℕ} (S : Finset (ZMod n)) : ZMod n → ℕ := fun i => if i ∈ S then 1 else 0 /-- Binary Circular Nim move on subsets of `ZMod n`: `T ⊂ S` with modified elements inside a `k`-arc. -/ def BinMove (n k : ℕ) [NeZero n] (S T : Finset (ZMod n)) : Prop := T ⊂ S ∧ ∃ s : ZMod n, ∀ i ∈ S \ T, ∃ j : Fin k, i = s + (j : ℕ) lemma embedBin_inj {n : ℕ} {S T : Finset (ZMod n)} (h : embedBin S = embedBin T) : S = T := by ext i have hi := congrFun h i simp only [embedBin] at hi by_cases hS : i ∈ S <;> by_cases hT : i ∈ T <;> simp_all lemma totalTokens_embedBin {n : ℕ} [NeZero n] (S : Finset (ZMod n)) : totalTokens (embedBin S) = S.card := by simp [totalTokens, embedBin] /-- **Downward Closure Theorem**: Every legal move in full $\mathbb{N}^n$ Circular Nim from a binary state `embedBin S` lands on another binary state `embedBin T`, and corresponds bijectively to `BinMove n k S T`. -/ theorem move_embedBin_iff {n k : ℕ} [NeZero n] (S : Finset (ZMod n)) (q : ZMod n → ℕ) : Move n k (embedBin S) q ↔ ∃ T : Finset (ZMod n), q = embedBin T ∧ BinMove n k S T := by constructor · intro ⟨hle, ⟨i₀, hi₀⟩, s, harc⟩ let T : Finset (ZMod n) := Finset.univ.filter (fun i => q i = 1) have hq_eq : q = embedBin T := by funext i have hli := hle i dsimp only [embedBin] at hli ⊢ split_ifs at hli with hS · by_cases hq1 : q i = 1 · simp [T, hq1] · have hq0 : q i = 0 := by omega simp [T, hq0] · have hq0 : q i = 0 := by omega simp [T, hq0] refine ⟨T, hq_eq, ?_, s, ?_⟩ · rw [Finset.ssubset_iff_subset_ne] refine ⟨fun i hi => ?_, fun heq => ?_⟩ · simp only [T, Finset.mem_filter, Finset.mem_univ, true_and] at hi have hli := hle i; dsimp only [embedBin] at hli by_contra hni; rw [if_neg hni] at hli; omega · subst heq; rw [hq_eq] at hi₀; exact lt_irrefl _ hi₀ · intro i hi rw [Finset.mem_sdiff] at hi have hlt : q i < embedBin S i := by rw [hq_eq]; simp [embedBin, hi.1, hi.2] exact harc i hlt · rintro ⟨T, rfl, hsub, s, harc⟩ refine ⟨fun i => ?_, ?_, s, fun i hi => ?_⟩ · dsimp only [embedBin] by_cases hT : i ∈ T · rw [if_pos hT, if_pos (hsub.1 hT)] · rw [if_neg hT]; omega · obtain ⟨i₀, hi₀S, hi₀T⟩ := Finset.exists_of_ssubset hsub exact ⟨i₀, by simp [embedBin, hi₀S, hi₀T]⟩ · have hiS : i ∈ S := by by_contra h; simp [embedBin, h] at hi have hiT : i ∉ T := by intro h; simp [embedBin, hiS, h] at hi exact harc i (Finset.mem_sdiff.mpr ⟨hiS, hiT⟩) /-- Binary untouched-arc characterization of `BinMove n (n - d) S T`. -/ theorem binMove_sub_iff {n d : ℕ} [NeZero n] (hd : d ≤ n) (S T : Finset (ZMod n)) : BinMove n (n - d) S T ↔ T ⊂ S ∧ ∃ s : ZMod n, ∀ j : Fin d, (s + (j : ℕ) ∈ T ↔ s + (j : ℕ) ∈ S) := by have h1 := move_embedBin_iff (k := n - d) S (embedBin T) have h2 := move_sub_iff_untouched_arc hd (embedBin S) (embedBin T) constructor · intro hbm have hm : Move n (n - d) (embedBin S) (embedBin T) := h1.mpr ⟨T, rfl, hbm⟩ obtain ⟨_, _, s, hunt⟩ := h2.mp hm refine ⟨hbm.1, s, fun j => ?_⟩ have hj := hunt j simp only [embedBin] at hj by_cases hT : s + (j : ℕ) ∈ T <;> by_cases hS : s + (j : ℕ) ∈ S <;> simp_all · rintro ⟨hsub, s, hunt⟩ have hm : Move n (n - d) (embedBin S) (embedBin T) := by rw [h2] refine ⟨fun i => ?_, ?_, s, fun j => ?_⟩ · dsimp only [embedBin] by_cases hT : i ∈ T · rw [if_pos hT, if_pos (hsub.1 hT)] · rw [if_neg hT]; omega · obtain ⟨i₀, hi₀S, hi₀T⟩ := Finset.exists_of_ssubset hsub exact ⟨i₀, by simp [embedBin, hi₀S, hi₀T]⟩ · simp only [embedBin, hunt j] obtain ⟨T', hT'eq, hT'm⟩ := h1.mp hm have hTT' : T = T' := embedBin_inj hT'eq rwa [hTT'] /-- Binary Sprague–Grundy specification theorem (works directly on `Finset (ZMod n)` while proving an identity for the FULL $\mathbb{N}^n$ function `grundy n k (embedBin S)`!). -/ theorem grundy_embedBin_eq_of_spec {n k : ℕ} [NeZero n] (f : Finset (ZMod n) → ℕ) (hne : ∀ S T, BinMove n k S T → f T ≠ f S) (hlt : ∀ S u, u < f S → ∃ T, BinMove n k S T ∧ f T = u) : ∀ S : Finset (ZMod n), grundy n k (embedBin S) = f S := by suffices ∀ m (S : Finset (ZMod n)), S.card = m → grundy n k (embedBin S) = f S from fun S => this S.card S rfl intro m induction m using Nat.strong_induction_on with | h m ih => intro S hS apply grundy_eq_of_spec · intro q hq obtain ⟨T, rfl, hbm⟩ := (move_embedBin_iff S q).mp hq have hcard : T.card < m := hS ▸ Finset.card_lt_card hbm.1 rw [ih T.card hcard T rfl] exact hne S T hbm · intro u hu obtain ⟨T, hbm, hval⟩ := hlt S u hu have hcard : T.card < m := hS ▸ Finset.card_lt_card hbm.1 refine ⟨embedBin T, (move_embedBin_iff S (embedBin T)).mpr ⟨T, rfl, hbm⟩, ?_⟩ rw [ih T.card hcard T rfl, hval] /-- Binary misère $\mathcal{P}^-$-position specification theorem (directly on full $\mathbb{N}^n$ `IsMisereP`). -/ theorem isMisereP_embedBin_eq_of_spec {n k : ℕ} [NeZero n] (P : Finset (ZMod n) → Prop) (hnonterm : ∀ S, P S → ∃ T, BinMove n k S T) (hclosed : ∀ S, P S → ∀ T, BinMove n k S T → ¬ P T) (hescape : ∀ S, ¬ P S → (∃ T, BinMove n k S T) → ∃ T, BinMove n k S T ∧ P T) : ∀ S : Finset (ZMod n), IsMisereP n k (embedBin S) ↔ P S := by suffices ∀ m (S : Finset (ZMod n)), S.card = m → (IsMisereP n k (embedBin S) ↔ P S) from fun S => this S.card S rfl intro m induction m using Nat.strong_induction_on with | h m ih => intro S hS rw [isMisereP_iff] constructor · rintro ⟨⟨q₀, hq₀⟩, hno⟩ obtain ⟨T₀, _, hbm₀⟩ := (move_embedBin_iff S q₀).mp hq₀ by_contra hnotP obtain ⟨T, hbm, hPT⟩ := hescape S hnotP ⟨T₀, hbm₀⟩ have hcard : T.card < m := hS ▸ Finset.card_lt_card hbm.1 exact hno (embedBin T) ((move_embedBin_iff S (embedBin T)).mpr ⟨T, rfl, hbm⟩) ((ih T.card hcard T rfl).mpr hPT) · intro hPS obtain ⟨T₀, hbm₀⟩ := hnonterm S hPS refine ⟨⟨embedBin T₀, (move_embedBin_iff S (embedBin T₀)).mpr ⟨T₀, rfl, hbm₀⟩⟩, ?_⟩ intro q hq hMq obtain ⟨T, rfl, hbm⟩ := (move_embedBin_iff S q).mp hq have hcard : T.card < m := hS ▸ Finset.card_lt_card hbm.1 have hPT := (ih T.card hcard T rfl).mp hMq exact hclosed S hPS T hbm hPT /-! ### Section 3: Universal Minimal $d$-Arc Transversal Theorem & Sharp $d = 4$ Breakdown -/ /-- `S` is a **$d$-arc transversal** of $C_n$ if every cyclic arc of length $d$ intersects `S` (equivalently, the zero-set $S^c$ contains no $d$ consecutive zeros). -/ def IsArcTransversal (n d : ℕ) [NeZero n] (S : Finset (ZMod n)) : Prop := ∀ s : ZMod n, ∃ j : Fin d, s + (j : ℕ) ∈ S /-- `S` is a **minimal $d$-arc transversal** of $C_n$ if it hits every $d$-arc and removing any single element leaves some $d$-arc uncovered. -/ def IsMinArcTransversal (n d : ℕ) [NeZero n] (S : Finset (ZMod n)) : Prop := IsArcTransversal n d S ∧ ∀ i ∈ S, ¬ IsArcTransversal n d (S.erase i) /-- Every $d$-arc transversal contains a minimal $d$-arc transversal. -/ lemma exists_minArcTransversal_subset {n d : ℕ} [NeZero n] {A : Finset (ZMod n)} (hA : IsArcTransversal n d A) : ∃ T ⊆ A, IsMinArcTransversal n d T := by let F := A.powerset.filter (fun T => IsArcTransversal n d T) have hne : F.Nonempty := ⟨A, Finset.mem_filter.mpr ⟨Finset.mem_powerset_self A, hA⟩⟩ obtain ⟨T, hTF, hTmin⟩ := Finset.exists_min_image F Finset.card hne rw [Finset.mem_filter, Finset.mem_powerset] at hTF refine ⟨T, hTF.1, hTF.2, fun i hi hdom => ?_⟩ have hmem : T.erase i ∈ F := Finset.mem_filter.mpr ⟨Finset.mem_powerset.mpr (Finset.Subset.trans (Finset.erase_subset i T) hTF.1), hdom⟩ have hle := hTmin (T.erase i) hmem have hlt := Finset.card_erase_lt_of_mem hi omega /-- If `T` is NOT a $d$-arc transversal (i.e., has $d$ consecutive zeros) and is nonempty, then `T` can move directly to `∅` in $\mathrm{CN}(n, n - d)$, so `T` is an $\mathcal{N}$-position. -/ lemma not_isNormalP_of_not_transversal {n d : ℕ} [NeZero n] (hd : d ≤ n) {T : Finset (ZMod n)} (hne : T.Nonempty) (hnot : ¬ IsArcTransversal n d T) : ¬ IsNormalP n (n - d) (embedBin T) := by simp only [IsArcTransversal, not_forall, not_exists] at hnot obtain ⟨s, hs⟩ := hnot intro hP rw [isNormalP_iff] at hP have hbm : BinMove n (n - d) T ∅ := by rw [binMove_sub_iff hd] refine ⟨Finset.empty_ssubset.mpr hne, s, fun j => ?_⟩ simp [hs j] have hm : Move n (n - d) (embedBin T) (embedBin (∅ : Finset (ZMod n))) := (move_embedBin_iff T _).mpr ⟨∅, rfl, hbm⟩ have h0 : embedBin (∅ : Finset (ZMod n)) = fun _ => 0 := by funext i; simp [embedBin] rw [h0] at hm exact hP _ hm (isNormalP_zero n (n - d)) /-- **Universal Minimal $d$-Transversal Theorem**: For ALL $2 \le d < n$, every minimal $d$-arc transversal $S$ of $C_n$ is a normal $\mathcal{P}$-position of Circular Nim $\mathrm{CN}(n, n - d)$ (in full $\mathbb{N}^n$). -/ theorem isNormalP_of_isMinArcTransversal {n d : ℕ} [NeZero n] (hd : d ≤ n) {S : Finset (ZMod n)} (hS : IsMinArcTransversal n d S) : IsNormalP n (n - d) (embedBin S) := by rw [isNormalP_iff] intro q hq obtain ⟨T, rfl, hbm⟩ := (move_embedBin_iff S q).mp hq rw [binMove_sub_iff hd] at hbm obtain ⟨hsub, s, hunt⟩ := hbm -- T is nonempty because the untouched d-arc intersects S have hTne : T.Nonempty := by obtain ⟨j, hj⟩ := hS.1 s exact ⟨s + (j : ℕ), (hunt j).mpr hj⟩ -- T is NOT a d-arc transversal because removing any i ∈ S \ T breaks transversality obtain ⟨i, hiS, hiT⟩ := Finset.exists_of_ssubset hsub have hTnot : ¬ IsArcTransversal n d T := by intro hTtr apply hS.2 i hiS intro s' obtain ⟨j, hj⟩ := hTtr s' refine ⟨j, Finset.mem_erase.mpr ⟨?_, hsub.1 hj⟩⟩ intro heq; rw [heq] at hj; exact hiT hj exact not_isNormalP_of_not_transversal hd hTne hTnot /-- **Sharp $d = 4$ Breakdown Theorem (Infinite Family)**: For EVERY $d \ge 4$, the antipodal binary state $S = \mathbb{Z}/(2d)\mathbb{Z} \setminus \{0, d\}$ in $\mathrm{CN}(2d, d)$ is a normal $\mathcal{P}$-position that is **neither $\emptyset$, nor $\mathrm{univ}$, nor a minimal $d$-arc transversal**. -/ theorem sharp_breakdown_ge_four {d : ℕ} (hd : 4 ≤ d) : letI : NeZero (2 * d) := ⟨by omega⟩ let S : Finset (ZMod (2 * d)) := (Finset.univ.erase 0).erase (d : ZMod (2 * d)) IsNormalP (2 * d) (2 * d - d) (embedBin S) ∧ S ≠ ∅ ∧ S ≠ Finset.univ ∧ ¬ IsMinArcTransversal (2 * d) d S := by let : NeZero (2 * d) := ⟨by omega⟩ dsimp only set S : Finset (ZMod (2 * d)) := (Finset.univ.erase 0).erase (d : ZMod (2 * d)) with hS_def have hd_eq : 2 * d - d = d := by omega have hd2 : (d : ZMod (2 * d)) + (d : ZMod (2 * d)) = 0 := by rw [← Nat.cast_add, show d + d = 2 * d by omega, ZMod.natCast_self] have hd_ne0 : (d : ZMod (2 * d)) ≠ 0 := zmod_natCast_ne_zero (a := d) (by omega) (by omega) have h2_ne0 : (2 : ZMod (2 * d)) ≠ 0 := by simpa using zmod_natCast_ne_zero (n := 2 * d) (a := 2) (by omega) (by omega) have h2_ned : (2 : ZMod (2 * d)) ≠ (d : ZMod (2 * d)) := by intro h have := zmod_add_natCast_ne (n := 2 * d) (0 : ZMod (2 * d)) (a := 2) (b := d) (by omega) (by omega) simp at this exact this h refine ⟨?_, ?_, ?_, ?_⟩ · -- Antipodal symmetry => Normal P-position! rw [hd_eq] apply isNormalP_antipodal (m := d) (k := d) (by omega) (le_refl d) intro i dsimp only [embedBin] have hiff : i + (d : ZMod (2 * d)) ∈ S ↔ i ∈ S := by rw [hS_def] simp only [Finset.mem_erase, Finset.mem_univ, and_true] constructor · rintro ⟨h1, h2⟩ refine ⟨fun hi => h2 ?_, fun hi => h1 ?_⟩ · rw [hi, hd2] · rw [hi, zero_add] · rintro ⟨h1, h2⟩ refine ⟨fun hi => h2 ?_, fun hi => h1 ?_⟩ · have := congrArg (fun x => x - (d : ZMod (2 * d))) hi simpa using this · have := congrArg (fun x => x + (d : ZMod (2 * d))) hi rw [add_assoc, hd2, add_zero, zero_add] at this exact this by_cases hi : i ∈ S · rw [if_pos (hiff.mpr hi), if_pos hi] · rw [if_neg (fun h => hi (hiff.mp h)), if_neg hi] · -- S ≠ ∅ because 2 ∈ S intro h0 have h2S : (2 : ZMod (2 * d)) ∈ S := by rw [hS_def]; simp [h2_ne0, h2_ned] rw [h0] at h2S; exact Finset.notMem_empty _ h2S · -- S ≠ univ because 0 ∉ S intro hu have h0S : (0 : ZMod (2 * d)) ∈ S := hu ▸ Finset.mem_univ 0 rw [hS_def] at h0S; simp at h0S · -- ¬ IsMinArcTransversal (2 * d) d S because erasing 2 still leaves only 3 zeros < d! intro hmin have h2S : (2 : ZMod (2 * d)) ∈ S := by rw [hS_def]; simp [h2_ne0, h2_ned] apply hmin.2 (2 : ZMod (2 * d)) h2S intro s -- The d elements {s + 0, ..., s + (d - 1)} are distinct, so at most 3 can be in {0, d, 2} let arc : Finset (ZMod (2 * d)) := Finset.univ.image (fun j : Fin d => s + (j : ℕ)) have harc_card : arc.card = d := by rw [Finset.card_image_of_injective] · simp · intro j1 j2 hj have h1 : (j1.val : ZMod (2 * d)) = (j2.val : ZMod (2 * d)) := by have := congrArg (fun x => x - s) hj simpa using this have hv := congrArg ZMod.val h1 simp only [ZMod.val_natCast, Nat.mod_eq_of_lt (show j1.val < 2 * d by omega), Nat.mod_eq_of_lt (show j2.val < 2 * d by omega)] at hv exact Fin.ext hv let bad : Finset (ZMod (2 * d)) := {0, (d : ZMod (2 * d)), 2} have hbad_card : bad.card ≤ 3 := by calc bad.card ≤ ({(d : ZMod (2 * d)), 2} : Finset (ZMod (2 * d))).card + 1 := Finset.card_insert_le _ _ _ ≤ ({2} : Finset (ZMod (2 * d))).card + 1 + 1 := by linarith [Finset.card_insert_le (d : ZMod (2 * d)) {2}] _ = 3 := by simp have hne_diff : (arc \ bad).Nonempty := by rw [Finset.nonempty_iff_ne_empty] intro hemp have hsub : arc ⊆ bad := Finset.sdiff_eq_empty_iff_subset.mp hemp have := Finset.card_le_card hsub omega obtain ⟨x, hx⟩ := hne_diff rw [Finset.mem_sdiff, Finset.mem_image] at hx obtain ⟨⟨j, _, rfl⟩, hxbad⟩ := hx refine ⟨j, ?_⟩ simp only [bad, Finset.mem_insert, Finset.mem_singleton, not_or] at hxbad rw [hS_def]; simp [hxbad.1, hxbad.2.1, hxbad.2.2] /-! ### Section 4: Exact Sprague–Grundy & Misère Collapse for $d = 2$ ($\mathrm{CN}(n, n - 2)$) -/ /-- `S` is a **vertex cover** of $C_n$ (equivalently a $2$-arc transversal: no `00`). -/ def IsVertexCover (n : ℕ) [NeZero n] (S : Finset (ZMod n)) : Prop := ∀ i : ZMod n, i ∈ S ∨ i + 1 ∈ S /-- `S` is a **minimal vertex cover** of $C_n$ (equivalently $S^c \in \mathrm{MIS}(C_n)$: no `00` and no `111`). -/ def IsMinVertexCover (n : ℕ) [NeZero n] (S : Finset (ZMod n)) : Prop := IsVertexCover n S ∧ ∀ i : ZMod n, ¬ (i - 1 ∈ S ∧ i ∈ S ∧ i + 1 ∈ S) lemma isVertexCover_iff_arcTransversal (n : ℕ) [NeZero n] (S : Finset (ZMod n)) : IsVertexCover n S ↔ IsArcTransversal n 2 S := by constructor · intro h s rcases h s with h0 | h1 · exact ⟨⟨0, by omega⟩, by simpa using h0⟩ · exact ⟨⟨1, by omega⟩, by simpa using h1⟩ · intro h s obtain ⟨⟨j, hj⟩, hmem⟩ := h s interval_cases j · left; simpa using hmem · right; simpa using hmem lemma isMinVertexCover_iff_minArcTransversal {n : ℕ} [NeZero n] (hn : 3 ≤ n) (S : Finset (ZMod n)) : IsMinVertexCover n S ↔ IsMinArcTransversal n 2 S := by have h10 : (1 : ZMod n) ≠ 0 := by simpa using zmod_natCast_ne_zero (n := n) (a := 1) (by omega) (by omega) constructor · rintro ⟨hvc, hno3⟩ refine ⟨(isVertexCover_iff_arcTransversal n S).mp hvc, fun i hi hdom => ?_⟩ rw [← isVertexCover_iff_arcTransversal] at hdom have hL : i - 1 ∈ S := by rcases hdom (i - 1) with h | h · exact Finset.mem_of_mem_erase h · simp only [sub_add_cancel] at h; exact absurd h (Finset.notMem_erase i S) have hR : i + 1 ∈ S := by rcases hdom i with h | h · exact absurd h (Finset.notMem_erase i S) · exact Finset.mem_of_mem_erase h exact hno3 i ⟨hL, hi, hR⟩ · rintro ⟨hvc, hmin⟩ rw [← isVertexCover_iff_arcTransversal] at hvc refine ⟨hvc, fun i ⟨hL, hi, hR⟩ => ?_⟩ apply hmin i hi rw [← isVertexCover_iff_arcTransversal] intro s by_cases hsi : s = i · subst hsi; right exact Finset.mem_erase.mpr ⟨by intro h; apply h10; linear_combination h, hR⟩ · by_cases hs1 : s + 1 = i · left have hs : s = i - 1 := eq_sub_of_add_eq hs1 rw [hs] exact Finset.mem_erase.mpr ⟨by intro h; apply h10; linear_combination -h, hL⟩ · rcases hvc s with h | h · left; exact Finset.mem_erase.mpr ⟨hsi, h⟩ · right; exact Finset.mem_erase.mpr ⟨hs1, h⟩ lemma isMinVertexCover_not_empty {n : ℕ} [NeZero n] {S : Finset (ZMod n)} (h : IsMinVertexCover n S) : S ≠ ∅ := by intro h0; subst h0; rcases h.1 0 with h1 | h1 <;> simp at h1 lemma isMinVertexCover_not_univ {n : ℕ} [NeZero n] {S : Finset (ZMod n)} (h : IsMinVertexCover n S) : S ≠ Finset.univ := by intro hu; subst hu; exact h.2 0 ⟨Finset.mem_univ _, Finset.mem_univ _, Finset.mem_univ _⟩ lemma isMinVertexCover_card_ge_two {n : ℕ} [NeZero n] (hn : 4 ≤ n) {S : Finset (ZMod n)} (h : IsMinVertexCover n S) : 2 ≤ S.card := by by_contra hlt; push Not at hlt have hne := isMinVertexCover_not_empty h have hc1 : S.card = 1 := by have := Finset.card_pos.mpr (Finset.nonempty_iff_ne_empty.mpr hne); omega obtain ⟨a, rfl⟩ := Finset.card_eq_one.mp hc1 rcases h.1 (a + 1) with h1 | h1 · simp only [Finset.mem_singleton] at h1 exact zmod_add_natCast_ne a (a := 0) (b := 1) (by omega) (by omega) (by simpa using h1.symm) · simp only [Finset.mem_singleton] at h1 have h2 : a + (2 : ZMod n) = a := by have : a + 1 + 1 = a + (2 : ZMod n) := by ring rwa [← this] exact zmod_add_natCast_ne a (a := 0) (b := 2) (by omega) (by omega) (by simpa using h2.symm) /-- Closed-form Sprague–Grundy formula for binary $\mathrm{CN}(n, n - 2)$ ($n \ge 5$). -/ noncomputable def grundySubTwoFormula (n : ℕ) [NeZero n] (S : Finset (ZMod n)) : ℕ := if S = ∅ ∨ IsMinVertexCover n S then 0 else if S = Finset.univ then 1 else S.card /-- **THEOREM 1 (Exact Sprague–Grundy Function of $\mathrm{CN}(n, n - 2)$ on $\{0, 1\}^n$)**: For every $n \ge 5$ and every $S \subseteq \mathbb{Z}/n\mathbb{Z}$, the exact Sprague–Grundy value in full $\mathbb{N}^n$ Circular Nim $\mathrm{CN}(n, n - 2)$ is `grundySubTwoFormula n S`. -/ theorem grundy_sub_two_exact {n : ℕ} [NeZero n] (hn : 5 ≤ n) (S : Finset (ZMod n)) : grundy n (n - 2) (embedBin S) = grundySubTwoFormula n S := by apply grundy_embedBin_eq_of_spec (grundySubTwoFormula n) · -- (1) No move preserves grundySubTwoFormula intro S T hbm heq rw [binMove_sub_iff (by omega)] at hbm obtain ⟨hsub, s, hunt⟩ := hbm have hTlt : T.card < S.card := Finset.card_lt_card hsub have hTnu : T ≠ Finset.univ := ne_univ_of_ssubset hsub dsimp only [grundySubTwoFormula] at heq rw [if_neg hTnu] at heq by_cases hT0 : T = ∅ ∨ IsMinVertexCover n T · rw [if_pos hT0] at heq by_cases hS0 : S = ∅ ∨ IsMinVertexCover n S · rcases hS0 with rfl | hSmvc · exact Finset.not_ssubset_empty T hsub · rcases hT0 with rfl | hTmvc · rcases hSmvc.1 s with h0 | h1 · exact Finset.notMem_empty s (by simpa using (hunt ⟨0, by omega⟩).mpr (by simpa using h0)) · exact Finset.notMem_empty (s + 1) (by simpa using (hunt ⟨1, by omega⟩).mpr (by simpa using h1)) · obtain ⟨i, hiS, hiT⟩ := Finset.exists_of_ssubset hsub have hTmin := (isMinVertexCover_iff_minArcTransversal (by omega) S).mp hSmvc apply hTmin.2 i hiS rw [← isVertexCover_iff_arcTransversal] intro x rcases hTmvc.1 x with hx | hx · left; exact Finset.mem_erase.mpr ⟨fun h => hiT (h ▸ hx), hsub.1 hx⟩ · right; exact Finset.mem_erase.mpr ⟨fun h => hiT (h ▸ hx), hsub.1 hx⟩ · rw [if_neg hS0] at heq by_cases hSu : S = Finset.univ · rw [if_pos hSu] at heq; omega · rw [if_neg hSu] at heq have hSne : S.Nonempty := Finset.nonempty_iff_ne_empty.mpr (fun h => hS0 (Or.inl h)) have := Finset.card_pos.mpr hSne; omega · rw [if_neg hT0] at heq by_cases hS0 : S = ∅ ∨ IsMinVertexCover n S · rw [if_pos hS0] at heq have hTne : T.Nonempty := Finset.nonempty_iff_ne_empty.mpr (fun h => hT0 (Or.inl h)) have := Finset.card_pos.mpr hTne; omega · rw [if_neg hS0] at heq by_cases hSu : S = Finset.univ · rw [if_pos hSu] at heq subst hSu have hs0 : s ∈ T := by simpa using (hunt ⟨0, by omega⟩).mpr (Finset.mem_univ _) have hs1 : s + 1 ∈ T := by simpa using (hunt ⟨1, by omega⟩).mpr (Finset.mem_univ _) have hne01 : s ≠ s + 1 := by simpa using zmod_add_natCast_ne s (a := 0) (b := 1) (by omega) (by omega) have h2le : 2 ≤ T.card := by have hsub2 : ({s, s + 1} : Finset (ZMod n)) ⊆ T := by intro x hx; simp only [Finset.mem_insert, Finset.mem_singleton] at hx rcases hx with rfl | rfl <;> assumption have hc2 : ({s, s + 1} : Finset (ZMod n)).card = 2 := Finset.card_pair hne01 linarith [Finset.card_le_card hsub2] omega · rw [if_neg hSu] at heq; omega · -- (2) Every u < grundySubTwoFormula n S is achieved by some legal move intro S u hu dsimp only [grundySubTwoFormula] at hu split_ifs at hu with hS0 hSu · omega · -- S = univ, u < 1 => u = 0: take minimal vertex cover inside univ \ {2, n-1} subst hSu have hu0 : u = 0 := by omega subst hu0 let A₀ : Finset (ZMod n) := (Finset.univ.erase (2 : ZMod n)).erase (-1 : ZMod n) have hA₀vc : IsVertexCover n A₀ := by intro i by_cases h2 : i = (2 : ZMod n) · right; subst h2 simp only [A₀, Finset.mem_erase, Finset.mem_univ, and_true] refine ⟨?_, ?_⟩ · -- 2 + 1 ≠ -1, i.e., 4 ≠ 0 in ZMod n (n >= 5) intro h have h4 : ((4 : ℕ) : ZMod n) = 0 := by have : (2 : ZMod n) + 1 + 1 = ((4 : ℕ) : ZMod n) := by norm_num rw [← this, h]; ring exact zmod_natCast_ne_zero (by omega) (by omega) h4 · intro h; apply zmod_natCast_ne_zero (n := n) (a := 1) (by omega) (by omega) linear_combination h · by_cases hm1 : i = (-1 : ZMod n) · right; subst hm1 simp only [A₀, Finset.mem_erase, Finset.mem_univ, and_true] refine ⟨?_, ?_⟩ · intro h apply zmod_natCast_ne_zero (n := n) (a := 1) (by omega) (by omega) have : (1 : ZMod n) = ((1 : ℕ) : ZMod n) := by norm_num rw [← this]; linear_combination h · intro h apply zmod_natCast_ne_zero (n := n) (a := 2) (by omega) (by omega) have : (2 : ZMod n) = ((2 : ℕ) : ZMod n) := by norm_num rw [← this]; linear_combination -h · left; simp [A₀, h2, hm1] obtain ⟨T, hTA, hTmin⟩ := exists_minArcTransversal_subset ((isVertexCover_iff_arcTransversal n A₀).mp hA₀vc) have hTmvc : IsMinVertexCover n T := (isMinVertexCover_iff_minArcTransversal (by omega) T).mpr hTmin have hTvc : IsVertexCover n T := hTmvc.1 have h0T : (0 : ZMod n) ∈ T := by rcases hTvc (-1 : ZMod n) with hm1 | h0 · exfalso; have := hTA hm1; simp [A₀] at this · simpa using h0 have h1T : (1 : ZMod n) ∈ T := by rcases hTvc (1 : ZMod n) with h1 | h2 · exact h1 · exfalso have h2A : (2 : ZMod n) ∈ A₀ := by have : (1 : ZMod n) + 1 = (2 : ZMod n) := by norm_num rw [← this]; exact hTA h2 simp [A₀] at h2A refine ⟨T, ?_, ?_⟩ · rw [binMove_sub_iff (by omega)] refine ⟨Finset.ssubset_univ_iff.mpr (isMinVertexCover_not_univ hTmvc), 0, fun j => ?_⟩ fin_cases j · simp [h0T] · simp [h1T] · simp [grundySubTwoFormula, hTmvc] · -- General case: S ≠ ∅, ¬ IsMinVertexCover n S, S ≠ univ, u < S.card push Not at hS0 obtain ⟨hSne, hSnotmvc⟩ := hS0 by_cases hu0 : u = 0 · -- Target u = 0 subst hu0 by_cases hvc : IsVertexCover n S · -- S is a non-minimal vertex cover; pick minimal VC T ⊂ S; untouched {z, z+1} for any z ∉ S! obtain ⟨T, hTS, hTmin⟩ := exists_minArcTransversal_subset ((isVertexCover_iff_arcTransversal n S).mp hvc) have hTmvc := (isMinVertexCover_iff_minArcTransversal (by omega) T).mpr hTmin have hTss : T ⊂ S := Finset.ssubset_iff_subset_ne.mpr ⟨hTS, fun h => hSnotmvc (h ▸ hTmvc)⟩ have hz_ex : ∃ z : ZMod n, z ∉ S := by by_contra h; push Not at h; exact hSu (Finset.eq_univ_iff_forall.mpr h) obtain ⟨z, hzS⟩ := hz_ex have hzT : z ∉ T := fun h => hzS (hTS h) have hz1T : z + 1 ∈ T := by rcases hTmvc.1 z with h | h · exact absurd h hzT · exact h refine ⟨T, ?_, by simp [grundySubTwoFormula, hTmvc]⟩ rw [binMove_sub_iff (by omega)] refine ⟨hTss, z, fun j => ?_⟩ fin_cases j · simp [hzS, hzT] · simp [hz1T, hTS hz1T] · -- S has a 00: clear everything to ∅ simp only [IsVertexCover, not_forall, not_or] at hvc obtain ⟨z, hz0, hz1⟩ := hvc refine ⟨∅, ?_, by simp [grundySubTwoFormula]⟩ rw [binMove_sub_iff (by omega)] refine ⟨Finset.empty_ssubset.mpr hSne, z, fun j => ?_⟩ fin_cases j <;> simp [hz0, hz1] · -- Target 1 ≤ u < S.card: build T ⊂ S of size u WITH a 00 (hence f T = u)! have hu1 : 1 ≤ u := by omega by_cases hvc : IsVertexCover n S · -- S has no 00, S ≠ univ: pick z ∉ S; then z - 1 ∈ S and z + 1 ∈ S (distinct since n >= 5)! have hz_ex : ∃ z : ZMod n, z ∉ S := by by_contra h; push Not at h; exact hSu (Finset.eq_univ_iff_forall.mpr h) obtain ⟨z, hzS⟩ := hz_ex have hzm1 : z - 1 ∈ S := by rcases hvc (z - 1) with h | h · exact h · simp only [sub_add_cancel] at h; exact absurd h hzS have hzp1 : z + 1 ∈ S := by rcases hvc z with h | h · exact absurd h hzS · exact h have hne_pm : z - 1 ≠ z + 1 := by simpa using zmod_add_sub_natCast_ne z (a := 1) (b := 1) (by omega) (by omega) let pool := (S.erase (z + 1)).erase (z - 1) have hpool_card : pool.card = S.card - 2 := by have h1 : (S.erase (z + 1)).card = S.card - 1 := Finset.card_erase_of_mem hzp1 have h2 : z - 1 ∈ S.erase (z + 1) := Finset.mem_erase.mpr ⟨hne_pm, hzm1⟩ rw [Finset.card_erase_of_mem h2, h1]; omega obtain ⟨R, hRsub, hRcard⟩ := exists_subset_card pool (r := u - 1) (by omega) let T := insert (z + 1) R have hzp1_nR : z + 1 ∉ R := fun h => (Finset.mem_erase.mp (Finset.mem_erase.mp (hRsub h)).2).1 rfl have hzm1_nT : z - 1 ∉ T := by simp only [T, Finset.mem_insert, not_or] exact ⟨hne_pm, fun h => (Finset.mem_erase.mp (hRsub h)).1 rfl⟩ have hTsub : T ⊆ S := by intro x hx simp only [T, Finset.mem_insert] at hx rcases hx with rfl | hxR · exact hzp1 · exact Finset.mem_of_mem_erase (Finset.mem_of_mem_erase (hRsub hxR)) have hTcard : T.card = u := by rw [Finset.card_insert_of_notMem hzp1_nR, hRcard]; omega have hTss : T ⊂ S := Finset.ssubset_iff_subset_ne.mpr ⟨hTsub, fun h => by rw [h] at hTcard; omega⟩ have hzT : z ∉ T := fun h => hzS (hTsub h) have hTnotmvc : ¬ IsMinVertexCover n T := by intro hTm rcases hTm.1 (z - 1) with h | h · exact hzm1_nT h · simp only [sub_add_cancel] at h; exact hzT h have hTne : T ≠ ∅ := by intro h; rw [h] at hTcard; simp at hTcard; omega have hTnu : T ≠ Finset.univ := by intro h; exact hzT (h ▸ Finset.mem_univ z) refine ⟨T, ?_, ?_⟩ · rw [binMove_sub_iff (by omega)] refine ⟨hTss, z, fun j => ?_⟩ fin_cases j · simp [hzS, hzT] · simp [hzp1, T] · simp [grundySubTwoFormula, hTne, hTnotmvc, hTnu, hTcard] · -- S already has a 00 at {z, z+1}: keep any u elements of S! simp only [IsVertexCover, not_forall, not_or] at hvc obtain ⟨z, hz0, hz1⟩ := hvc obtain ⟨T, hTS, hTcard⟩ := exists_subset_card S (r := u) (by omega) have hTss : T ⊂ S := Finset.ssubset_iff_subset_ne.mpr ⟨hTS, fun h => by rw [h] at hTcard; omega⟩ have hz0T : z ∉ T := fun h => hz0 (hTS h) have hz1T : z + 1 ∉ T := fun h => hz1 (hTS h) have hTnotmvc : ¬ IsMinVertexCover n T := by intro hTm rcases hTm.1 z with h | h · exact hz0T h · exact hz1T h have hTne : T ≠ ∅ := by intro h; rw [h] at hTcard; simp at hTcard; omega have hTnu : T ≠ Finset.univ := fun h => hz0T (h ▸ Finset.mem_univ z) refine ⟨T, ?_, ?_⟩ · rw [binMove_sub_iff (by omega)] refine ⟨hTss, z, fun j => ?_⟩ fin_cases j <;> simp [hz0, hz1, hz0T, hz1T] · simp [grundySubTwoFormula, hTne, hTnotmvc, hTnu, hTcard] /-- **Corollary 1A (Exact Normal $\mathcal{P}$-position Classification of Binary $\mathrm{CN}(n, n-2)$)**: For all $n \ge 5$, a binary configuration $\mathbf{1}_S$ is a normal $\mathcal{P}$-position of $\mathrm{CN}(n, n - 2)$ iff $S = \emptyset$ or $S$ is a minimal vertex cover of $C_n$. -/ theorem isNormalP_sub_two_iff {n : ℕ} [NeZero n] (hn : 5 ≤ n) (S : Finset (ZMod n)) : IsNormalP n (n - 2) (embedBin S) ↔ S = ∅ ∨ IsMinVertexCover n S := by rw [← grundy_eq_zero_iff_isNormalP, grundy_sub_two_exact hn] dsimp only [grundySubTwoFormula] split_ifs with h0 hu · simp [h0] · simp [h0] · push Not at h0 have hpos := Finset.card_pos.mpr h0.1 constructor · intro hc; omega · rintro (h | h) · exact absurd h (Finset.nonempty_iff_ne_empty.mp h0.1) · exact absurd h h0.2 /-- **Boundary Law ($n = 4$, $\mathrm{CN}(4, 2)$)**: Unlike $n \ge 5$, at $n = 4$ the all-ones state $\mathbf{1}_{\mathrm{univ}}$ has Sprague–Grundy value $0$ (by antipodal symmetry). -/ theorem grundy_four_two_exact (S : Finset (ZMod 4)) : grundy 4 2 (embedBin S) = if S = ∅ ∨ S = Finset.univ ∨ IsMinVertexCover 4 S then 0 else S.card := by let f : Finset (ZMod 4) → ℕ := fun S => if S = ∅ ∨ S = Finset.univ ∨ IsMinVertexCover 4 S then 0 else S.card change grundy 4 (4 - 2) (embedBin S) = f S apply grundy_embedBin_eq_of_spec f · intro S T hbm heq rw [binMove_sub_iff (by omega)] at hbm obtain ⟨hsub, s, hunt⟩ := hbm have hTlt : T.card < S.card := Finset.card_lt_card hsub have hTnu : T ≠ Finset.univ := ne_univ_of_ssubset hsub dsimp only [f] at heq by_cases hT0 : T = ∅ ∨ T = Finset.univ ∨ IsMinVertexCover 4 T · rw [if_pos hT0] at heq by_cases hS0 : S = ∅ ∨ S = Finset.univ ∨ IsMinVertexCover 4 S · rcases hS0 with rfl | rfl | hSmvc · exact Finset.not_ssubset_empty T hsub · rcases hT0 with rfl | hTu | hTmvc · exact Finset.notMem_empty s (by simpa using (hunt ⟨0, by omega⟩).mpr (Finset.mem_univ _)) · exact hTnu hTu · have hs0 : s ∈ T := by simpa using (hunt ⟨0, by omega⟩).mpr (Finset.mem_univ _) have hs1 : s + 1 ∈ T := by simpa using (hunt ⟨1, by omega⟩).mpr (Finset.mem_univ _) have hs2 : s + 2 ∉ T := fun h2 => hTmvc.2 (s + 1) ⟨by simpa using hs0, hs1, by convert h2 using 1; ring⟩ have hs3 : s + 3 ∉ T := fun h3 => hTmvc.2 s ⟨by have : s - 1 = s + 3 := by have : (4 : ZMod 4) = 0 := rfl; linear_combination -this rwa [this], hs0, hs1⟩ rcases hTmvc.1 (s + 2) with h2 | h3 · exact hs2 h2 · exact hs3 (by convert h3 using 1; ring) · rcases hT0 with rfl | hTu | hTmvc · rcases hSmvc.1 s with h0 | h1 · exact Finset.notMem_empty s (by simpa using (hunt ⟨0, by omega⟩).mpr (by simpa using h0)) · exact Finset.notMem_empty (s + 1) (by simpa using (hunt ⟨1, by omega⟩).mpr (by simpa using h1)) · exact hTnu hTu · obtain ⟨i, hiS, hiT⟩ := Finset.exists_of_ssubset hsub have hTmin := (isMinVertexCover_iff_minArcTransversal (by omega) S).mp hSmvc apply hTmin.2 i hiS rw [← isVertexCover_iff_arcTransversal] intro x rcases hTmvc.1 x with hx | hx · left; exact Finset.mem_erase.mpr ⟨fun h => hiT (h ▸ hx), hsub.1 hx⟩ · right; exact Finset.mem_erase.mpr ⟨fun h => hiT (h ▸ hx), hsub.1 hx⟩ · rw [if_neg hS0] at heq have hSne : S.Nonempty := Finset.nonempty_iff_ne_empty.mpr (fun h => hS0 (Or.inl h)) have := Finset.card_pos.mpr hSne; omega · rw [if_neg hT0] at heq by_cases hS0 : S = ∅ ∨ S = Finset.univ ∨ IsMinVertexCover 4 S · rw [if_pos hS0] at heq have hTne : T.Nonempty := Finset.nonempty_iff_ne_empty.mpr (fun h => hT0 (Or.inl h)) have := Finset.card_pos.mpr hTne; omega · rw [if_neg hS0] at heq; omega · intro S u hu dsimp only [f] at hu split_ifs at hu with hS0 · omega · push Not at hS0 obtain ⟨hSne, hSnu, hSnotmvc⟩ := hS0 -- In ZMod 4, if S ≠ univ and ¬ IsMinVC 4 S, check if S is a VC (must be size 3) or has 00 by_cases hu0 : u = 0 · subst hu0 by_cases hvc : IsVertexCover 4 S · obtain ⟨T, hTS, hTmin⟩ := exists_minArcTransversal_subset ((isVertexCover_iff_arcTransversal 4 S).mp hvc) have hTmvc := (isMinVertexCover_iff_minArcTransversal (by omega) T).mpr hTmin have hTss : T ⊂ S := Finset.ssubset_iff_subset_ne.mpr ⟨hTS, fun h => hSnotmvc (h ▸ hTmvc)⟩ have hz_ex : ∃ z : ZMod 4, z ∉ S := by by_contra h; push Not at h; exact hSnu (Finset.eq_univ_iff_forall.mpr h) obtain ⟨z, hzS⟩ := hz_ex have hzT : z ∉ T := fun h => hzS (hTS h) have hz1T : z + 1 ∈ T := by rcases hTmvc.1 z with h | h · exact absurd h hzT · exact h refine ⟨T, ?_, by simp [f, hTmvc]⟩ rw [binMove_sub_iff (by omega)] refine ⟨hTss, z, fun j => ?_⟩ fin_cases j <;> simp [hzS, hzT, hz1T, hTS hz1T] · simp only [IsVertexCover, not_forall, not_or] at hvc obtain ⟨z, hz0, hz1⟩ := hvc refine ⟨∅, ?_, by simp [f]⟩ rw [binMove_sub_iff (by omega)] refine ⟨Finset.empty_ssubset.mpr hSne, z, fun j => ?_⟩ fin_cases j <;> simp [hz0, hz1] · -- 1 ≤ u < S.card ≤ 3 have hu1 : 1 ≤ u := by omega by_cases hvc : IsVertexCover 4 S · -- S has size 3 (unique z ∉ S): leave {z, z+1} untouched, drop z-1 (= z+3)! have hz_ex : ∃ z : ZMod 4, z ∉ S := by by_contra h; push Not at h; exact hSnu (Finset.eq_univ_iff_forall.mpr h) obtain ⟨z, hzS⟩ := hz_ex have hzm1 : z - 1 ∈ S := by rcases hvc (z - 1) with h | h · exact h · simp only [sub_add_cancel] at h; exact absurd h hzS have hzp1 : z + 1 ∈ S := by rcases hvc z with h | h · exact absurd h hzS · exact h have hne_pm : z - 1 ≠ z + 1 := by simpa using zmod_add_sub_natCast_ne z (a := 1) (b := 1) (by omega) (by omega) let pool := (S.erase (z + 1)).erase (z - 1) have hpool_card : pool.card = S.card - 2 := by have h1 := Finset.card_erase_of_mem hzp1 have h2 : z - 1 ∈ S.erase (z + 1) := Finset.mem_erase.mpr ⟨hne_pm, hzm1⟩ rw [Finset.card_erase_of_mem h2, h1]; omega obtain ⟨R, hRsub, hRcard⟩ := exists_subset_card pool (r := u - 1) (by omega) let T := insert (z + 1) R have hzp1_nR : z + 1 ∉ R := fun h => (Finset.mem_erase.mp (Finset.mem_erase.mp (hRsub h)).2).1 rfl have hzm1_nT : z - 1 ∉ T := by simp only [T, Finset.mem_insert, not_or] exact ⟨hne_pm, fun h => (Finset.mem_erase.mp (hRsub h)).1 rfl⟩ have hTsub : T ⊆ S := by intro x hx; simp only [T, Finset.mem_insert] at hx rcases hx with rfl | hxR · exact hzp1 · exact Finset.mem_of_mem_erase (Finset.mem_of_mem_erase (hRsub hxR)) have hTcard : T.card = u := by rw [Finset.card_insert_of_notMem hzp1_nR, hRcard]; omega have hTss : T ⊂ S := Finset.ssubset_iff_subset_ne.mpr ⟨hTsub, fun h => by rw [h] at hTcard; omega⟩ have hzT : z ∉ T := fun h => hzS (hTsub h) have hTnotmvc : ¬ IsMinVertexCover 4 T := by intro hTm; rcases hTm.1 (z - 1) with h | h · exact hzm1_nT h · simp only [sub_add_cancel] at h; exact hzT h have hTne : T ≠ ∅ := by intro h; rw [h] at hTcard; simp at hTcard; omega have hTnu : T ≠ Finset.univ := fun h => hzT (h ▸ Finset.mem_univ z) refine ⟨T, ?_, ?_⟩ · rw [binMove_sub_iff (by omega)] refine ⟨hTss, z, fun j => ?_⟩ fin_cases j <;> simp [hzS, hzT, hzp1, T] · simp [f, hTne, hTnu, hTnotmvc, hTcard] · simp only [IsVertexCover, not_forall, not_or] at hvc obtain ⟨z, hz0, hz1⟩ := hvc obtain ⟨T, hTS, hTcard⟩ := exists_subset_card S (r := u) (by omega) have hTss : T ⊂ S := Finset.ssubset_iff_subset_ne.mpr ⟨hTS, fun h => by rw [h] at hTcard; omega⟩ have hz0T : z ∉ T := fun h => hz0 (hTS h) have hz1T : z + 1 ∉ T := fun h => hz1 (hTS h) have hTnotmvc : ¬ IsMinVertexCover 4 T := by intro hTm rcases hTm.1 z with h | h · exact hz0T h · exact hz1T h have hTne : T ≠ ∅ := by intro h; rw [h] at hTcard; simp at hTcard; omega have hTnu : T ≠ Finset.univ := fun h => hz0T (h ▸ Finset.mem_univ z) refine ⟨T, ?_, ?_⟩ · rw [binMove_sub_iff (by omega)] refine ⟨hTss, z, fun j => ?_⟩ fin_cases j <;> simp [hz0, hz1, hz0T, hz1T] · simp [f, hTne, hTnu, hTnotmvc, hTcard] /-- **THEOREM 2 (Misère Collapse of Binary $\mathrm{CN}^-(n, n - 2)$)**: For every $n \ge 4$, a binary configuration $\mathbf{1}_S$ is a misère $\mathcal{P}^-$-position of $\mathrm{CN}^-(n, n - 2)$ **if and only if** $|S| = 1$ or $S = \mathrm{univ}$. -/ theorem isMisereP_sub_two_iff {n : ℕ} [NeZero n] (hn : 4 ≤ n) (S : Finset (ZMod n)) : IsMisereP n (n - 2) (embedBin S) ↔ S.card = 1 ∨ S = Finset.univ := by apply isMisereP_embedBin_eq_of_spec (fun S => S.card = 1 ∨ S = Finset.univ) · -- Nonterminal intro S hS rcases hS with hc1 | rfl · obtain ⟨a, rfl⟩ := Finset.card_eq_one.mp hc1 refine ⟨∅, ?_⟩ rw [binMove_sub_iff (by omega)] refine ⟨Finset.empty_ssubset.mpr (Finset.singleton_nonempty a), a + 1, fun j => ?_⟩ fin_cases j · have hne : a + 1 ≠ a := by simpa using (zmod_add_natCast_ne a (a := 0) (b := 1) (by omega) (by omega)).symm simp [hne] · have hne : a + 1 + 1 ≠ a := by have : a + 1 + 1 = a + (2 : ZMod n) := by ring rw [this] simpa using (zmod_add_natCast_ne a (a := 0) (b := 2) (by omega) (by omega)).symm simp [hne] · refine ⟨Finset.univ.erase 0, ?_⟩ rw [binMove_sub_iff (by omega)] refine ⟨Finset.erase_ssubset (Finset.mem_univ 0), 1, fun j => ?_⟩ fin_cases j · have h10 : (1 : ZMod n) ≠ 0 := by simpa using zmod_natCast_ne_zero (n := n) (a := 1) (by omega) (by omega) simp [h10] · have h20 : (2 : ZMod n) ≠ 0 := by simpa using zmod_natCast_ne_zero (n := n) (a := 2) (by omega) (by omega) have h11 : (1 : ZMod n) + 1 = (2 : ZMod n) := by norm_num simp [h11, h20] · -- Closed intro S hS T hbm hT rw [binMove_sub_iff (by omega)] at hbm obtain ⟨hsub, s, hunt⟩ := hbm have hTnu : T ≠ Finset.univ := ne_univ_of_ssubset hsub rcases hS with hc1 | rfl · have hTlt := Finset.card_lt_card hsub rcases hT with hT1 | hTu · omega · exact hTnu hTu · rcases hT with hT1 | hTu · have hs0 : s ∈ T := by simpa using (hunt ⟨0, by omega⟩).mpr (Finset.mem_univ _) have hs1 : s + 1 ∈ T := by simpa using (hunt ⟨1, by omega⟩).mpr (Finset.mem_univ _) have hne : s ≠ s + 1 := by simpa using zmod_add_natCast_ne s (a := 0) (b := 1) (by omega) (by omega) have hle : ({s, s + 1} : Finset (ZMod n)).card ≤ T.card := Finset.card_le_card (by intro x hx; simp only [Finset.mem_insert, Finset.mem_singleton] at hx rcases hx with rfl | rfl <;> assumption) rw [Finset.card_pair hne] at hle; omega · exact hTnu hTu · -- Escape: any non-empty S with 2 ≤ |S| < n has a 0-1 edge {z, z+1}; clear all else to {z+1}! intro S hnotP ⟨T₀, hbm₀⟩ push Not at hnotP obtain ⟨hne1, hnu⟩ := hnotP have hSne : S.Nonempty := by rw [Finset.nonempty_iff_ne_empty]; intro h0; subst h0 exact Finset.not_ssubset_empty T₀ hbm₀.1 obtain ⟨z, hz0, hz1⟩ := exists_zero_one_edge hSne hnu have hSge2 : 2 ≤ S.card := by have := Finset.card_pos.mpr hSne; omega have hss : ({z + 1} : Finset (ZMod n)) ⊂ S := by rw [Finset.ssubset_iff_subset_ne] refine ⟨Finset.singleton_subset_iff.mpr hz1, fun h => ?_⟩ rw [← h] at hSge2; simp at hSge2 refine ⟨{z + 1}, ?_, Or.inl (Finset.card_singleton _)⟩ rw [binMove_sub_iff (by omega)] refine ⟨hss, z, fun j => ?_⟩ fin_cases j · have hne : z ≠ z + 1 := by simpa using zmod_add_natCast_ne z (a := 0) (b := 1) (by omega) (by omega) simp [hz0, hne] · simp [hz1] /-- **Corollary 2A (Linear Misère Cardinality)**: For every $n \ge 4$, the exact number of binary misère $\mathcal{P}^-$-positions of $\mathrm{CN}^-(n, n - 2)$ is $n + 1$. -/ theorem card_misereP_sub_two {n : ℕ} [NeZero n] (hn : 4 ≤ n) : (Finset.univ.filter (fun S : Finset (ZMod n) => IsMisereP n (n - 2) (embedBin S))).card = n + 1 := by have heq : Finset.univ.filter (fun S : Finset (ZMod n) => IsMisereP n (n - 2) (embedBin S)) = insert (Finset.univ : Finset (ZMod n)) (Finset.univ.image (fun a : ZMod n => ({a} : Finset (ZMod n)))) := by ext S simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_insert, Finset.mem_image] rw [isMisereP_sub_two_iff hn, or_comm] constructor · rintro (rfl | hc1) · exact Or.inl rfl · obtain ⟨a, rfl⟩ := Finset.card_eq_one.mp hc1 exact Or.inr ⟨a, rfl⟩ · rintro (rfl | ⟨a, rfl⟩) · exact Or.inl rfl · exact Or.inr (Finset.card_singleton a) rw [heq, Finset.card_insert_of_notMem] · rw [Finset.card_image_of_injective _ (fun a b h => Finset.singleton_injective h)] simp [ZMod.card] · simp only [Finset.mem_image, Finset.mem_univ, true_and, not_exists] intro a ha have hc := congrArg Finset.card ha simp [ZMod.card] at hc omega /-! ### Section 5: Exact Perrin Enumeration Theorem ($|\mathcal{P}_{\mathrm{bin}}(\mathrm{CN}(n, n-2))| = 1 + P(n)$) -/ /-- The **Perrin sequence** (OEIS A001608): $P(0)=3, P(1)=0, P(2)=2$, $P(n+3) = P(n+1) + P(n)$. -/ def perrin : ℕ → ℕ | 0 => 3 | 1 => 0 | 2 => 2 | n + 3 => perrin (n + 1) + perrin n /-- The **Padovan-composition sequence** $L(k)$ counting linear subsets of $\{0, \dots, k\}$ containing $0$ and $k$ with all consecutive gaps in $\{2, 3\}$. -/ def padovanComp : ℕ → ℕ | 0 => 1 | 1 => 0 | 2 => 1 | k + 3 => padovanComp (k + 1) + padovanComp k /-- Fundamental linear identity linking Perrin and Padovan-composition numbers: $P(n + 3) = 2 L(n + 1) + 3 L(n)$ for all $n \ge 0$. -/ lemma perrin_eq_padovanComp (n : ℕ) : perrin (n + 3) = 2 * padovanComp (n + 1) + 3 * padovanComp n := by induction n using Nat.strong_induction_on with | h n ih => match n with | 0 => rfl | 1 => rfl | 2 => rfl | m + 3 => have h1 := ih (m + 1) (by omega) have h2 := ih m (by omega) simp only [perrin, padovanComp] at h1 h2 ⊢ omega /-- Predicate for a linear subset `A ⊆ Fin (k + 1)` representing a composition of `k` into parts `{2, 3}`: `0 ∈ A`, `k ∈ A`, no adjacent elements, and no 3 consecutive non-elements. -/ def IsLinearGap23 (k : ℕ) (A : Finset (Fin (k + 1))) : Prop := ⟨0, by omega⟩ ∈ A ∧ ⟨k, by omega⟩ ∈ A ∧ (∀ i : ℕ, (hi : i + 1 ≤ k) → ¬ (⟨i, by omega⟩ ∈ A ∧ ⟨i + 1, by omega⟩ ∈ A)) ∧ (∀ i : ℕ, (hi : i + 2 ≤ k) → ⟨i, by omega⟩ ∈ A ∨ ⟨i + 1, by omega⟩ ∈ A ∨ ⟨i + 2, by omega⟩ ∈ A) /-- The finite set of all `IsLinearGap23 k` subsets of `Fin (k + 1)`. -/ noncomputable def linearGap23Set (k : ℕ) : Finset (Finset (Fin (k + 1))) := Finset.univ.filter (fun A => IsLinearGap23 k A) lemma mem_linearGap23Set {k : ℕ} {A : Finset (Fin (k + 1))} : A ∈ linearGap23Set k ↔ IsLinearGap23 k A := by simp [linearGap23Set] lemma card_linearGap23Set (k : ℕ) : (linearGap23Set k).card = padovanComp k := by induction k using Nat.strong_induction_on with | h k ih => match k with | 0 => have h : linearGap23Set 0 = {{⟨0, by omega⟩}} := by ext A rw [mem_linearGap23Set, Finset.mem_singleton] constructor · rintro ⟨h0, _, _, _⟩ ext x; fin_cases x; simpa using h0 · rintro rfl refine ⟨by simp, by simp, fun i hi => by omega, fun i hi => by omega⟩ rw [h, Finset.card_singleton]; rfl | 1 => have h : linearGap23Set 1 = ∅ := by ext A rw [mem_linearGap23Set] simp only [Finset.notMem_empty, iff_false] intro hA exact hA.2.2.1 0 (by omega) ⟨hA.1, hA.2.1⟩ rw [h, Finset.card_empty]; rfl | 2 => have h : linearGap23Set 2 = {{⟨0, by omega⟩, ⟨2, by omega⟩}} := by ext A rw [mem_linearGap23Set, Finset.mem_singleton] constructor · rintro ⟨h0, h2, hno2, _⟩ have h1 : ⟨1, by omega⟩ ∉ A := fun h1 => hno2 0 (by omega) ⟨h0, h1⟩ ext x; fin_cases x · exact ⟨fun _ => by decide, fun _ => h0⟩ · exact ⟨fun h => absurd h h1, fun h => by simp at h⟩ · exact ⟨fun _ => by decide, fun _ => h2⟩ · rintro rfl refine ⟨by simp, by simp, fun i hi => ?_, fun i hi => ?_⟩ · have hi' : i ≤ 1 := by omega interval_cases i <;> simp · have hi' : i = 0 := by omega subst hi'; left; simp rw [h, Finset.card_singleton]; rfl | m + 3 => let S2 := (linearGap23Set (m + 3)).filter (fun A => ⟨2, by omega⟩ ∈ A) let S3 := (linearGap23Set (m + 3)).filter (fun A => ⟨2, by omega⟩ ∉ A) have hpart : (linearGap23Set (m + 3)).card = S2.card + S3.card := by exact (Finset.card_filter_add_card_filter_not (s := linearGap23Set (m + 3)) (p := fun A => ⟨2, by omega⟩ ∈ A)).symm let lift2 : Finset (Fin (m + 2)) → Finset (Fin (m + 4)) := fun B => insert ⟨0, by omega⟩ (B.image (fun x => ⟨x.val + 2, by omega⟩)) have hS2 : S2 = (linearGap23Set (m + 1)).image lift2 := by ext A rw [Finset.mem_filter, mem_linearGap23Set, Finset.mem_image] constructor · rintro ⟨⟨h0, hlast, hno2, hno3⟩, h2⟩ have h1 : ⟨1, by omega⟩ ∉ A := fun h => hno2 0 (by omega) ⟨h0, h⟩ let B : Finset (Fin (m + 2)) := Finset.univ.filter (fun x => ⟨x.val + 2, by omega⟩ ∈ A) refine ⟨B, ?_, ?_⟩ · rw [mem_linearGap23Set] refine ⟨by simp [B, h2], by simp [B, hlast], fun i hi ⟨ha, hb⟩ => ?_, fun i hi => ?_⟩ · simp only [B, Finset.mem_filter, Finset.mem_univ, true_and] at ha hb exact hno2 (i + 2) (by omega) ⟨ha, hb⟩ · simpa [B] using hno3 (i + 2) (by omega) · ext ⟨v, hv⟩ dsimp only [lift2] rw [Finset.mem_insert, Finset.mem_image] by_cases hv0 : v = 0 · subst hv0 exact ⟨fun _ => h0, fun _ => Or.inl rfl⟩ · by_cases hv1 : v = 1 · subst hv1 simp only [B, Finset.mem_filter, Finset.mem_univ, true_and, h1, iff_false, not_or, not_exists, not_and] refine ⟨fun h => by simp only [Fin.mk.injEq] at h; omega, fun x _ hx => by simp only [Fin.mk.injEq] at hx; omega⟩ · constructor · rintro (heq | ⟨⟨w, hw⟩, hmem, heq⟩) · simp only [Fin.mk.injEq] at heq; omega · simp only [B, Finset.mem_filter, Finset.mem_univ, true_and] at hmem have hwv : (⟨w + 2, by omega⟩ : Fin (m + 4)) = ⟨v, hv⟩ := heq rwa [← hwv] · intro hmem right refine ⟨⟨v - 2, by omega⟩, ?_, Fin.ext (by dsimp; omega)⟩ simp only [B, Finset.mem_filter, Finset.mem_univ, true_and] have hv_eq : (⟨v - 2 + 2, by omega⟩ : Fin (m + 4)) = ⟨v, hv⟩ := Fin.ext (by dsimp; omega) rwa [hv_eq] · rintro ⟨B, hB, rfl⟩ rw [mem_linearGap23Set] at hB obtain ⟨hB0, hBlast, hBno2, hBno3⟩ := hB dsimp only [lift2] refine ⟨⟨Finset.mem_insert_self _ _, ?_, ?_, ?_⟩, ?_⟩ · exact Finset.mem_insert_of_mem (Finset.mem_image.mpr ⟨⟨m + 1, by omega⟩, hBlast, rfl⟩) · intro i hi ⟨ha, hb⟩ rw [Finset.mem_insert, Finset.mem_image] at ha hb by_cases hi0 : i = 0 · subst hi0 rcases hb with h | ⟨x, _, hx⟩ · simp only [Fin.mk.injEq] at h; omega · simp only [Fin.mk.injEq] at hx; omega · rcases ha with h | ⟨x, hxB, hx⟩ · simp only [Fin.mk.injEq] at h; omega · rcases hb with h | ⟨y, hyB, hy⟩ · simp only [Fin.mk.injEq] at h; omega · have hxv : x.val + 2 = i := by simp only [Fin.mk.injEq] at hx; exact hx have hyv : y.val + 2 = i + 1 := by simp only [Fin.mk.injEq] at hy; exact hy have hy_eq : (⟨x.val + 1, by omega⟩ : Fin (m + 2)) = y := Fin.ext (by dsimp; omega) have hx_eq : (⟨x.val, by omega⟩ : Fin (m + 2)) = x := Fin.ext rfl exact hBno2 x.val (by omega) ⟨hx_eq.symm ▸ hxB, hy_eq.symm ▸ hyB⟩ · intro i hi by_cases hi0 : i = 0 · subst hi0; left; exact Finset.mem_insert_self _ _ · by_cases hi1 : i = 1 · subst hi1; right; left exact Finset.mem_insert_of_mem (Finset.mem_image.mpr ⟨⟨0, by omega⟩, hB0, rfl⟩) · rcases hBno3 (i - 2) (by omega) with h | h | h · left; exact Finset.mem_insert_of_mem (Finset.mem_image.mpr ⟨_, h, Fin.ext (by dsimp; omega)⟩) · right; left; exact Finset.mem_insert_of_mem (Finset.mem_image.mpr ⟨_, h, Fin.ext (by dsimp; omega)⟩) · right; right; exact Finset.mem_insert_of_mem (Finset.mem_image.mpr ⟨_, h, Fin.ext (by dsimp; omega)⟩) · exact Finset.mem_insert_of_mem (Finset.mem_image.mpr ⟨⟨0, by omega⟩, hB0, rfl⟩) have hlift2_inj : Function.Injective lift2 := by intro B1 B2 heq ext ⟨v, hv⟩ have hmem := Finset.ext_iff.mp heq ⟨v + 2, by omega⟩ simp only [lift2, Finset.mem_insert, Finset.mem_image] at hmem constructor · intro h1 rcases hmem.mp (Or.inr ⟨⟨v, hv⟩, h1, rfl⟩) with h0 | ⟨x, hx2, hx⟩ · simp only [Fin.mk.injEq] at h0; omega · have hxv : x = ⟨v, hv⟩ := Fin.ext (by simp only [Fin.mk.injEq] at hx; dsimp; omega) rwa [← hxv] · intro h2 rcases hmem.mpr (Or.inr ⟨⟨v, hv⟩, h2, rfl⟩) with h0 | ⟨x, hx1, hx⟩ · simp only [Fin.mk.injEq] at h0; omega · have hxv : x = ⟨v, hv⟩ := Fin.ext (by simp only [Fin.mk.injEq] at hx; dsimp; omega) rwa [← hxv] let lift3 : Finset (Fin (m + 1)) → Finset (Fin (m + 4)) := fun B => insert ⟨0, by omega⟩ (B.image (fun x => ⟨x.val + 3, by omega⟩)) have hS3 : S3 = (linearGap23Set m).image lift3 := by ext A rw [Finset.mem_filter, mem_linearGap23Set, Finset.mem_image] constructor · rintro ⟨⟨h0, hlast, hno2, hno3⟩, h2⟩ have h1 : ⟨1, by omega⟩ ∉ A := fun h => hno2 0 (by omega) ⟨h0, h⟩ have h3 : ⟨3, by omega⟩ ∈ A := by rcases hno3 1 (by omega) with h | h | h · exact absurd h h1 · exact absurd h h2 · exact h let B : Finset (Fin (m + 1)) := Finset.univ.filter (fun x => ⟨x.val + 3, by omega⟩ ∈ A) refine ⟨B, ?_, ?_⟩ · rw [mem_linearGap23Set] refine ⟨by simp [B, h3], by simp [B, hlast], fun i hi ⟨ha, hb⟩ => ?_, fun i hi => ?_⟩ · simp only [B, Finset.mem_filter, Finset.mem_univ, true_and] at ha hb exact hno2 (i + 3) (by omega) ⟨ha, hb⟩ · simpa [B] using hno3 (i + 3) (by omega) · ext ⟨v, hv⟩ dsimp only [lift3] rw [Finset.mem_insert, Finset.mem_image] by_cases hv0 : v = 0 · subst hv0 exact ⟨fun _ => h0, fun _ => Or.inl rfl⟩ · by_cases hv1 : v = 1 · subst hv1 simp only [B, Finset.mem_filter, Finset.mem_univ, true_and, h1, iff_false, not_or, not_exists, not_and] refine ⟨fun h => by simp only [Fin.mk.injEq] at h; omega, fun x _ hx => by simp only [Fin.mk.injEq] at hx; omega⟩ · by_cases hv2 : v = 2 · subst hv2 simp only [B, Finset.mem_filter, Finset.mem_univ, true_and, h2, iff_false, not_or, not_exists, not_and] refine ⟨fun h => by simp only [Fin.mk.injEq] at h; omega, fun x _ hx => by simp only [Fin.mk.injEq] at hx; omega⟩ · constructor · rintro (heq | ⟨⟨w, hw⟩, hmem, heq⟩) · simp only [Fin.mk.injEq] at heq; omega · simp only [B, Finset.mem_filter, Finset.mem_univ, true_and] at hmem have hwv : (⟨w + 3, by omega⟩ : Fin (m + 4)) = ⟨v, hv⟩ := heq rwa [← hwv] · intro hmem right refine ⟨⟨v - 3, by omega⟩, ?_, Fin.ext (by dsimp; omega)⟩ simp only [B, Finset.mem_filter, Finset.mem_univ, true_and] have hv_eq : (⟨v - 3 + 3, by omega⟩ : Fin (m + 4)) = ⟨v, hv⟩ := Fin.ext (by dsimp; omega) rwa [hv_eq] · rintro ⟨B, hB, rfl⟩ rw [mem_linearGap23Set] at hB obtain ⟨hB0, hBlast, hBno2, hBno3⟩ := hB dsimp only [lift3] refine ⟨⟨Finset.mem_insert_self _ _, ?_, ?_, ?_⟩, ?_⟩ · exact Finset.mem_insert_of_mem (Finset.mem_image.mpr ⟨⟨m, by omega⟩, hBlast, rfl⟩) · intro i hi ⟨ha, hb⟩ rw [Finset.mem_insert, Finset.mem_image] at ha hb by_cases hi0 : i = 0 · subst hi0 rcases hb with h | ⟨x, _, hx⟩ · simp only [Fin.mk.injEq] at h; omega · simp only [Fin.mk.injEq] at hx; omega · rcases ha with h | ⟨x, hxB, hx⟩ · simp only [Fin.mk.injEq] at h; omega · rcases hb with h | ⟨y, hyB, hy⟩ · simp only [Fin.mk.injEq] at h; omega · have hxv : x.val + 3 = i := by simp only [Fin.mk.injEq] at hx; exact hx have hyv : y.val + 3 = i + 1 := by simp only [Fin.mk.injEq] at hy; exact hy have hy_eq : (⟨x.val + 1, by omega⟩ : Fin (m + 1)) = y := Fin.ext (by dsimp; omega) have hx_eq : (⟨x.val, by omega⟩ : Fin (m + 1)) = x := Fin.ext rfl exact hBno2 x.val (by omega) ⟨hx_eq.symm ▸ hxB, hy_eq.symm ▸ hyB⟩ · intro i hi by_cases hi0 : i = 0 · subst hi0; left; exact Finset.mem_insert_self _ _ · by_cases hi1 : i = 1 · subst hi1; right; right exact Finset.mem_insert_of_mem (Finset.mem_image.mpr ⟨⟨0, by omega⟩, hB0, rfl⟩) · by_cases hi2 : i = 2 · subst hi2; right; left exact Finset.mem_insert_of_mem (Finset.mem_image.mpr ⟨⟨0, by omega⟩, hB0, rfl⟩) · rcases hBno3 (i - 3) (by omega) with h | h | h · left; exact Finset.mem_insert_of_mem (Finset.mem_image.mpr ⟨_, h, Fin.ext (by dsimp; omega)⟩) · right; left; exact Finset.mem_insert_of_mem (Finset.mem_image.mpr ⟨_, h, Fin.ext (by dsimp; omega)⟩) · right; right; exact Finset.mem_insert_of_mem (Finset.mem_image.mpr ⟨_, h, Fin.ext (by dsimp; omega)⟩) · simp only [Finset.mem_insert, Finset.mem_image, not_or, not_exists, not_and] refine ⟨fun h => by simp only [Fin.mk.injEq] at h; omega, fun x _ hx => by simp only [Fin.mk.injEq] at hx; omega⟩ have hlift3_inj : Function.Injective lift3 := by intro B1 B2 heq ext ⟨v, hv⟩ have hmem := Finset.ext_iff.mp heq ⟨v + 3, by omega⟩ simp only [lift3, Finset.mem_insert, Finset.mem_image] at hmem constructor · intro h1 rcases hmem.mp (Or.inr ⟨⟨v, hv⟩, h1, rfl⟩) with h0 | ⟨x, hx2, hx⟩ · simp only [Fin.mk.injEq] at h0; omega · have hxv : x = ⟨v, hv⟩ := Fin.ext (by simp only [Fin.mk.injEq] at hx; dsimp; omega) rwa [← hxv] · intro h2 rcases hmem.mpr (Or.inr ⟨⟨v, hv⟩, h2, rfl⟩) with h0 | ⟨x, hx1, hx⟩ · simp only [Fin.mk.injEq] at h0; omega · have hxv : x = ⟨v, hv⟩ := Fin.ext (by simp only [Fin.mk.injEq] at hx; dsimp; omega) rwa [← hxv] rw [hpart, hS2, hS3, Finset.card_image_of_injective _ hlift2_inj, Finset.card_image_of_injective _ hlift3_inj, ih (m + 1) (by omega), ih m (by omega)] rfl /-- Maximal independent set of $C_n$ (complement of a minimal vertex cover): no adjacent vertices in `Z`, and no 3 consecutive vertices outside `Z`. -/ def IsMISCycle (n : ℕ) [NeZero n] (Z : Finset (ZMod n)) : Prop := (∀ i : ZMod n, ¬ (i ∈ Z ∧ i + 1 ∈ Z)) ∧ (∀ i : ZMod n, i ∈ Z ∨ i + 1 ∈ Z ∨ i + 2 ∈ Z) lemma isMinVertexCover_iff_compl_isMISCycle (n : ℕ) [NeZero n] (S : Finset (ZMod n)) : IsMinVertexCover n S ↔ IsMISCycle n Sᶜ := by simp only [IsMinVertexCover, IsVertexCover, IsMISCycle, Finset.mem_compl] constructor · rintro ⟨h1, h2⟩ refine ⟨fun i ⟨hi, hi1⟩ => ?_, fun i => ?_⟩ · rcases h1 i with h | h · exact hi h · exact hi1 h · by_contra hall; push Not at hall exact h2 (i + 1) ⟨by simpa using hall.1, hall.2.1, by convert hall.2.2 using 1; ring⟩ · rintro ⟨h1, h2⟩ refine ⟨fun i => ?_, fun i ⟨hL, hi, hR⟩ => ?_⟩ · by_contra hall; push Not at hall; exact h1 i hall · rcases h2 (i - 1) with h | h | h · exact h hL · simp only [sub_add_cancel] at h; exact h hi · have : i - 1 + 2 = i + 1 := by ring rw [this] at h; exact h hR /-- Embedding a `LinearGap23 k` subset into `ZMod n` shifted by `off : ℕ` (when `off + k < n`). -/ def embedLinear {n k : ℕ} [NeZero n] (off : ℕ) (A : Finset (Fin (k + 1))) : Finset (ZMod n) := A.image (fun x => ((off + x.val : ℕ) : ZMod n)) lemma embedLinear_inj {n k off : ℕ} [NeZero n] (hbound : off + k < n) : Function.Injective (embedLinear (n := n) (k := k) off) := by intro A B heq ext ⟨v, hv⟩ have hmem := Finset.ext_iff.mp heq ((off + v : ℕ) : ZMod n) simp only [embedLinear, Finset.mem_image] at hmem have hcast : ∀ x : Fin (k + 1), (((off + x.val : ℕ) : ZMod n) = ((off + v : ℕ) : ZMod n)) → x.val = v := by intro x hx have hval := congrArg ZMod.val hx simp only [ZMod.val_natCast, Nat.mod_eq_of_lt (show off + x.val < n by omega), Nat.mod_eq_of_lt (show off + v < n by omega)] at hval omega constructor · intro hA obtain ⟨x, hxB, hx⟩ := hmem.mp ⟨⟨v, hv⟩, hA, rfl⟩ have hxv : x = ⟨v, hv⟩ := Fin.ext (hcast x hx) rwa [← hxv] · intro hB obtain ⟨x, hxA, hx⟩ := hmem.mpr ⟨⟨v, hv⟩, hB, rfl⟩ have hxv : x = ⟨v, hv⟩ := Fin.ext (hcast x hx) rwa [← hxv] /-- Helper: characterizing membership in `embedLinear off A` via `ZMod.val`. -/ lemma mem_embedLinear_iff {n k off : ℕ} [NeZero n] (hbound : off + k < n) {A : Finset (Fin (k + 1))} {z : ZMod n} : z ∈ embedLinear (n := n) off A ↔ ∃ (h1 : off ≤ z.val) (h2 : z.val ≤ off + k), ⟨z.val - off, by omega⟩ ∈ A := by simp only [embedLinear, Finset.mem_image] constructor · rintro ⟨⟨v, hv⟩, hvA, rfl⟩ have hval : ((off + v : ℕ) : ZMod n).val = off + v := by rw [ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)] refine ⟨by dsimp; omega, by dsimp; omega, ?_⟩ convert hvA using 1 exact Fin.ext (by dsimp; omega) · rintro ⟨h1, h2, hmem⟩ refine ⟨⟨z.val - off, by omega⟩, hmem, ?_⟩ have : off + (z.val - off) = z.val := by omega rw [this, ZMod.natCast_zmod_val] /-- **THEOREM 3 (Exact Perrin Enumeration of Maximal Independent Sets of $C_n$)**: For every $n \ge 3$, the number of minimal vertex covers of $C_n$ (equivalently maximal independent sets of $C_n$) is **exactly `perrin n`**. -/ theorem card_minVertexCover_eq_perrin {n : ℕ} [NeZero n] (hn : 3 ≤ n) : (Finset.univ.filter (fun S : Finset (ZMod n) => IsMinVertexCover n S)).card = perrin n := by -- First pass to complements (MIS of C_n) via involutive bijection S ↦ Sᶜ let M := Finset.univ.filter (fun Z : Finset (ZMod n) => IsMISCycle n Z) have hcompl : (Finset.univ.filter (fun S : Finset (ZMod n) => IsMinVertexCover n S)).card = M.card := by apply Finset.card_bij (fun S _ => Sᶜ) · intro S hS simp only [M, Finset.mem_filter, Finset.mem_univ, true_and] at hS ⊢ exact (isMinVertexCover_iff_compl_isMISCycle n S).mp hS · intro S₁ _ S₂ _ h; exact compl_injective h · intro Z hZ refine ⟨Zᶜ, ?_, compl_compl Z⟩ simp only [M, Finset.mem_filter, Finset.mem_univ, true_and] at hZ ⊢ rwa [isMinVertexCover_iff_compl_isMISCycle, compl_compl] rw [hcompl] -- Partition M into 5 disjoint classes corresponding to the 5 gap-2/3 boundary crossings! let C1 := (linearGap23Set (n - 2)).image (embedLinear (n := n) (k := n - 2) 0) let C2 := (linearGap23Set (n - 2)).image (embedLinear (n := n) (k := n - 2) 1) let C3 := (linearGap23Set (n - 3)).image (embedLinear (n := n) (k := n - 3) 0) let C4 := (linearGap23Set (n - 3)).image (embedLinear (n := n) (k := n - 3) 1) let C5 := (linearGap23Set (n - 3)).image (embedLinear (n := n) (k := n - 3) 2) -- Helper: val of 1 in ZMod n for n >= 3 have hval1 : (1 : ZMod n).val = 1 := by rw [← Nat.cast_one, ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)] -- Helper: check that every Z ∈ embedLinear off A (for gap-2/3 of right length) is in M have hmem_M_of_gap2 : ∀ (off : ℕ), off ≤ 1 → ∀ A ∈ linearGap23Set (n - 2), embedLinear (n := n) off A ∈ M := by intro off hoff A hA rw [mem_linearGap23Set] at hA obtain ⟨hA0, hAlast, hAno2, hAno3⟩ := hA rw [Finset.mem_filter] refine ⟨Finset.mem_univ _, ?_, ?_⟩ · intro i ⟨hi, hi1⟩ have hb : off + (n - 2) < n := by omega rw [mem_embedLinear_iff hb] at hi hi1 obtain ⟨h1, h2, hm1⟩ := hi obtain ⟨h3, h4, hm2⟩ := hi1 by_cases hwrap : i.val + 1 < n · have hv1 : (i + 1).val = i.val + 1 := by rw [ZMod.val_add, hval1, Nat.mod_eq_of_lt hwrap] have := hAno2 (i.val - off) (by omega) exact this ⟨hm1, by convert hm2 using 1; exact Fin.ext (by dsimp; omega)⟩ · have hiv : i.val = n - 1 := by have := ZMod.val_lt i; omega have hi1v : (i + 1).val = 0 := by rw [ZMod.val_add, hval1, hiv, Nat.sub_add_cancel (by omega), Nat.mod_self] omega · intro i have hb : off + (n - 2) < n := by omega have hiv := ZMod.val_lt i by_cases hin : off ≤ i.val ∧ i.val + 2 ≤ off + (n - 2) · have hv1 : (i + 1).val = i.val + 1 := by rw [ZMod.val_add, hval1, Nat.mod_eq_of_lt (by omega)] have hv2 : (i + 2).val = i.val + 2 := by rw [ZMod.val_add, show (2 : ZMod n).val = 2 by rw [← Nat.cast_ofNat, ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)], Nat.mod_eq_of_lt (by omega)] rcases hAno3 (i.val - off) (by omega) with h | h | h · left; exact (mem_embedLinear_iff hb).mpr ⟨by omega, by omega, h⟩ · right; left; exact (mem_embedLinear_iff hb).mpr ⟨by omega, by omega, by convert h using 1; exact Fin.ext (by dsimp; omega)⟩ · right; right; exact (mem_embedLinear_iff hb).mpr ⟨by omega, by omega, by convert h using 1; exact Fin.ext (by dsimp; omega)⟩ · have heq_start : ((off : ℕ) : ZMod n) ∈ embedLinear (n := n) off A := (mem_embedLinear_iff hb).mpr ⟨by rw [ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)], by rw [ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)]; omega, by convert hA0 using 1; exact Fin.ext (by dsimp; rw [ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)]; omega)⟩ have heq_end : ((off + (n - 2) : ℕ) : ZMod n) ∈ embedLinear (n := n) off A := (mem_embedLinear_iff hb).mpr ⟨by rw [ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)]; omega, by rw [ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)], by convert hAlast using 1; exact Fin.ext (by dsimp; rw [ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)]; omega)⟩ by_cases hlt_off : i.val < off · right; left have hi0 : i = 0 := by have : i.val = 0 := by omega rw [← ZMod.natCast_zmod_val i, this]; simp have hoff1 : off = 1 := by omega rw [hi0, zero_add, hoff1] rw [hoff1] at heq_start simpa using heq_start · by_cases h1 : i.val = off + (n - 2) · left; rw [← ZMod.natCast_zmod_val i, h1]; exact heq_end · by_cases h2 : i.val + 1 = off + (n - 2) · right; left have : i + 1 = ((off + (n - 2) : ℕ) : ZMod n) := by rw [← ZMod.natCast_zmod_val i, ← Nat.cast_one, ← Nat.cast_add, h2] rw [this]; exact heq_end · right; left have hi_last : i.val = n - 1 ∧ off = 0 := by omega have : i + 1 = ((off : ℕ) : ZMod n) := by rw [← ZMod.natCast_zmod_val i, hi_last.1, hi_last.2, Nat.cast_zero, show (1 : ZMod n) = ((1 : ℕ) : ZMod n) from Nat.cast_one.symm, ← Nat.cast_add, Nat.sub_add_cancel (by omega), ZMod.natCast_self] rw [this]; exact heq_start have hmem_M_of_gap3 : ∀ (off : ℕ), off ≤ 2 → ∀ A ∈ linearGap23Set (n - 3), embedLinear (n := n) off A ∈ M := by intro off hoff A hA rw [mem_linearGap23Set] at hA obtain ⟨hA0, hAlast, hAno2, hAno3⟩ := hA rw [Finset.mem_filter] refine ⟨Finset.mem_univ _, ?_, ?_⟩ · intro i ⟨hi, hi1⟩ have hb : off + (n - 3) < n := by omega rw [mem_embedLinear_iff hb] at hi hi1 obtain ⟨h1, h2, hm1⟩ := hi obtain ⟨h3, h4, hm2⟩ := hi1 by_cases hwrap : i.val + 1 < n · have hv1 : (i + 1).val = i.val + 1 := by rw [ZMod.val_add, hval1, Nat.mod_eq_of_lt hwrap] exact hAno2 (i.val - off) (by omega) ⟨hm1, by convert hm2 using 1; exact Fin.ext (by dsimp; omega)⟩ · have hiv : i.val = n - 1 := by have := ZMod.val_lt i; omega have hi1v : (i + 1).val = 0 := by rw [ZMod.val_add, hval1, hiv, Nat.sub_add_cancel (by omega), Nat.mod_self] omega · intro i have hb : off + (n - 3) < n := by omega have hiv := ZMod.val_lt i by_cases hin : off ≤ i.val ∧ i.val + 2 ≤ off + (n - 3) · have hv1 : (i + 1).val = i.val + 1 := by rw [ZMod.val_add, hval1, Nat.mod_eq_of_lt (by omega)] have hv2 : (i + 2).val = i.val + 2 := by rw [ZMod.val_add, show (2 : ZMod n).val = 2 by rw [← Nat.cast_ofNat, ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)], Nat.mod_eq_of_lt (by omega)] rcases hAno3 (i.val - off) (by omega) with h | h | h · left; exact (mem_embedLinear_iff hb).mpr ⟨by omega, by omega, h⟩ · right; left; exact (mem_embedLinear_iff hb).mpr ⟨by omega, by omega, by convert h using 1; exact Fin.ext (by dsimp; omega)⟩ · right; right; exact (mem_embedLinear_iff hb).mpr ⟨by omega, by omega, by convert h using 1; exact Fin.ext (by dsimp; omega)⟩ · have heq_start : ((off : ℕ) : ZMod n) ∈ embedLinear (n := n) off A := (mem_embedLinear_iff hb).mpr ⟨by rw [ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)], by rw [ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)]; omega, by convert hA0 using 1; exact Fin.ext (by dsimp; rw [ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)]; omega)⟩ have heq_end : ((off + (n - 3) : ℕ) : ZMod n) ∈ embedLinear (n := n) off A := (mem_embedLinear_iff hb).mpr ⟨by rw [ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)]; omega, by rw [ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)], by convert hAlast using 1; exact Fin.ext (by dsimp; rw [ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)]; omega)⟩ by_cases h1 : i.val = off + (n - 3) · left; rw [← ZMod.natCast_zmod_val i, h1]; exact heq_end · by_cases h2 : i.val + 1 = off + (n - 3) · right; left have : i + 1 = ((off + (n - 3) : ℕ) : ZMod n) := by rw [← ZMod.natCast_zmod_val i, ← Nat.cast_one, ← Nat.cast_add, h2] rw [this]; exact heq_end · by_cases h3 : i.val + 1 = off · right; left have : i + 1 = ((off : ℕ) : ZMod n) := by rw [← ZMod.natCast_zmod_val i, ← Nat.cast_one, ← Nat.cast_add, h3] rw [this]; exact heq_start · by_cases h4 : i.val + 2 = off · right; right have : i + 2 = ((off : ℕ) : ZMod n) := by rw [← ZMod.natCast_zmod_val i, show (2 : ZMod n) = ((2 : ℕ) : ZMod n) by norm_num, ← Nat.cast_add, h4] rw [this]; exact heq_start · by_cases h5 : i.val + 1 = n + off · right; left have : i + 1 = ((off : ℕ) : ZMod n) := by rw [← ZMod.natCast_zmod_val i, ← Nat.cast_one, ← Nat.cast_add, h5, Nat.cast_add, ZMod.natCast_self, zero_add] rw [this]; exact heq_start · right; right have h6 : i.val + 2 = n + off := by omega have : i + 2 = ((off : ℕ) : ZMod n) := by rw [← ZMod.natCast_zmod_val i, show (2 : ZMod n) = ((2 : ℕ) : ZMod n) by norm_num, ← Nat.cast_add, h6, Nat.cast_add, ZMod.natCast_self, zero_add] rw [this]; exact heq_start -- Characterize membership in C1..C5 inside M by the boundary bits {0, 1, n-2, n-1}! have hextract : ∀ (off k : ℕ), off + k < n → ∀ Z ∈ M, ((off : ℕ) : ZMod n) ∈ Z → ((off + k : ℕ) : ZMod n) ∈ Z → (∀ z ∈ Z, off ≤ z.val ∧ z.val ≤ off + k) → Z ∈ (linearGap23Set k).image (embedLinear (n := n) off) := by intro off k hb Z hZM hs he hrange have hZM_spec : IsMISCycle n Z := (Finset.mem_filter.mp hZM).2 obtain ⟨hno2, hno3⟩ := hZM_spec let A : Finset (Fin (k + 1)) := Finset.univ.filter (fun x => ((off + x.val : ℕ) : ZMod n) ∈ Z) rw [Finset.mem_image] refine ⟨A, ?_, ?_⟩ · rw [mem_linearGap23Set] refine ⟨by simp only [A, Finset.mem_filter, Finset.mem_univ, true_and, add_zero]; exact hs, by simp only [A, Finset.mem_filter, Finset.mem_univ, true_and]; exact he, fun i hi ⟨h1, h2⟩ => ?_, fun i hi => ?_⟩ · simp only [A, Finset.mem_filter, Finset.mem_univ, true_and] at h1 h2 apply hno2 ((off + i : ℕ) : ZMod n) refine ⟨h1, ?_⟩ have : ((off + i : ℕ) : ZMod n) + 1 = ((off + (i + 1) : ℕ) : ZMod n) := by push_cast; ring rwa [this] · simp only [A, Finset.mem_filter, Finset.mem_univ, true_and] rcases hno3 ((off + i : ℕ) : ZMod n) with h | h | h · left; exact h · right; left have : ((off + i : ℕ) : ZMod n) + 1 = ((off + (i + 1) : ℕ) : ZMod n) := by push_cast; ring rwa [← this] · right; right have : ((off + i : ℕ) : ZMod n) + 2 = ((off + (i + 2) : ℕ) : ZMod n) := by push_cast; ring rwa [← this] · ext z rw [mem_embedLinear_iff hb] simp only [A, Finset.mem_filter, Finset.mem_univ, true_and] constructor · rintro ⟨h1, h2, hz⟩ have : off + (z.val - off) = z.val := by omega rwa [this, ZMod.natCast_zmod_val] at hz · intro hz obtain ⟨h1, h2⟩ := hrange z hz refine ⟨h1, h2, ?_⟩ have : off + (z.val - off) = z.val := by omega rwa [this, ZMod.natCast_zmod_val] -- Now prove M = C1 ∪ C2 ∪ C3 ∪ C4 ∪ C5 and pairwise disjointness! have hM_eq : M = C1 ∪ C2 ∪ C3 ∪ C4 ∪ C5 := by ext Z simp only [Finset.mem_union] constructor · intro hZM have hZM' : IsMISCycle n Z := (Finset.mem_filter.mp hZM).2 obtain ⟨hno2, hno3⟩ := hZM' by_cases h0 : (0 : ZMod n) ∈ Z · have hnm1 : ((n - 1 : ℕ) : ZMod n) ∉ Z := fun h => hno2 ((n - 1 : ℕ) : ZMod n) ⟨h, by have : ((n - 1 : ℕ) : ZMod n) + 1 = 0 := by rw [show (1 : ZMod n) = ((1 : ℕ) : ZMod n) from Nat.cast_one.symm, ← Nat.cast_add, Nat.sub_add_cancel (by omega), ZMod.natCast_self] rwa [this]⟩ by_cases hnm2 : ((n - 2 : ℕ) : ZMod n) ∈ Z · left; left; left; left exact hextract 0 (n - 2) (by omega) Z hZM (by simpa using h0) (by simpa using hnm2) (fun z hz => ⟨Nat.zero_le _, by have hlt := ZMod.val_lt z by_contra hgt; push Not at hgt have hzv : z.val = n - 1 := by omega rw [← ZMod.natCast_zmod_val z, hzv] at hz; exact hnm1 hz⟩) · have hnm3 : ((n - 3 : ℕ) : ZMod n) ∈ Z := by rcases hno3 ((n - 3 : ℕ) : ZMod n) with h | h | h · exact h · exfalso; apply hnm2 have : ((n - 3 : ℕ) : ZMod n) + 1 = ((n - 2 : ℕ) : ZMod n) := by rw [← Nat.cast_one, ← Nat.cast_add, show n - 3 + 1 = n - 2 by omega] rwa [← this] · exfalso; apply hnm1 have : ((n - 3 : ℕ) : ZMod n) + 2 = ((n - 1 : ℕ) : ZMod n) := by rw [show (2 : ZMod n) = ((2 : ℕ) : ZMod n) by norm_num, ← Nat.cast_add, show n - 3 + 2 = n - 1 by omega] rwa [← this] left; left; right exact hextract 0 (n - 3) (by omega) Z hZM (by simpa using h0) (by simpa using hnm3) (fun z hz => ⟨Nat.zero_le _, by have hlt := ZMod.val_lt z by_contra hgt; push Not at hgt have hcases : z.val = n - 2 ∨ z.val = n - 1 := by omega rcases hcases with hv | hv · rw [← ZMod.natCast_zmod_val z, hv] at hz; exact hnm2 hz · rw [← ZMod.natCast_zmod_val z, hv] at hz; exact hnm1 hz⟩) · by_cases h1 : (1 : ZMod n) ∈ Z · by_cases hnm1 : ((n - 1 : ℕ) : ZMod n) ∈ Z · left; left; left; right exact hextract 1 (n - 2) (by omega) Z hZM (by simpa using h1) (by simpa [show 1 + (n - 2) = n - 1 by omega] using hnm1) (fun z hz => ⟨by by_contra hlt; push Not at hlt have hv : z.val = 0 := by omega rw [← ZMod.natCast_zmod_val z, hv] at hz; exact h0 (by simpa using hz), by have := ZMod.val_lt z; omega⟩) · have hnm2 : ((n - 2 : ℕ) : ZMod n) ∈ Z := by rcases hno3 ((n - 2 : ℕ) : ZMod n) with h | h | h · exact h · exfalso; apply hnm1 have : ((n - 2 : ℕ) : ZMod n) + 1 = ((n - 1 : ℕ) : ZMod n) := by rw [← Nat.cast_one, ← Nat.cast_add, show n - 2 + 1 = n - 1 by omega] rwa [← this] · exfalso; apply h0 have : ((n - 2 : ℕ) : ZMod n) + 2 = 0 := by rw [show (2 : ZMod n) = ((2 : ℕ) : ZMod n) by norm_num, ← Nat.cast_add, show n - 2 + 2 = n by omega, ZMod.natCast_self] rwa [← this] left; right exact hextract 1 (n - 3) (by omega) Z hZM (by simpa using h1) (by simpa [show 1 + (n - 3) = n - 2 by omega] using hnm2) (fun z hz => ⟨by by_contra hlt; push Not at hlt have hv : z.val = 0 := by omega rw [← ZMod.natCast_zmod_val z, hv] at hz; exact h0 (by simpa using hz), by have hlt := ZMod.val_lt z by_contra hgt; push Not at hgt have hv : z.val = n - 1 := by omega rw [← ZMod.natCast_zmod_val z, hv] at hz; exact hnm1 hz⟩) · have h2 : (2 : ZMod n) ∈ Z := by rcases hno3 0 with h | h | h · exact absurd h h0 · exact absurd (by simpa using h) h1 · simpa using h have hnm1 : ((n - 1 : ℕ) : ZMod n) ∈ Z := by rcases hno3 ((n - 1 : ℕ) : ZMod n) with h | h | h · exact h · exfalso; apply h0 have : ((n - 1 : ℕ) : ZMod n) + 1 = 0 := by rw [show (1 : ZMod n) = ((1 : ℕ) : ZMod n) from Nat.cast_one.symm, ← Nat.cast_add, Nat.sub_add_cancel (by omega), ZMod.natCast_self] rwa [← this] · exfalso; apply h1 have : ((n - 1 : ℕ) : ZMod n) + 2 = 1 := by rw [show (2 : ZMod n) = ((2 : ℕ) : ZMod n) by norm_num, ← Nat.cast_add, show n - 1 + 2 = n + 1 by omega, Nat.cast_add, ZMod.natCast_self, zero_add, Nat.cast_one] rwa [← this] right exact hextract 2 (n - 3) (by omega) Z hZM (by simpa using h2) (by simpa [show 2 + (n - 3) = n - 1 by omega] using hnm1) (fun z hz => ⟨by by_contra hlt; push Not at hlt have hcases : z.val = 0 ∨ z.val = 1 := by omega rcases hcases with hv | hv · rw [← ZMod.natCast_zmod_val z, hv] at hz; exact h0 (by simpa using hz) · rw [← ZMod.natCast_zmod_val z, hv] at hz; exact h1 (by simpa using hz), by have := ZMod.val_lt z; omega⟩) · rintro ((((h | h) | h) | h) | h) · obtain ⟨A, hA, rfl⟩ := Finset.mem_image.mp h; exact hmem_M_of_gap2 0 (by omega) A hA · obtain ⟨A, hA, rfl⟩ := Finset.mem_image.mp h; exact hmem_M_of_gap2 1 (by omega) A hA · obtain ⟨A, hA, rfl⟩ := Finset.mem_image.mp h; exact hmem_M_of_gap3 0 (by omega) A hA · obtain ⟨A, hA, rfl⟩ := Finset.mem_image.mp h; exact hmem_M_of_gap3 1 (by omega) A hA · obtain ⟨A, hA, rfl⟩ := Finset.mem_image.mp h; exact hmem_M_of_gap3 2 (by omega) A hA -- Helper lemmas on boundary membership of C1..C5 to prove pairwise disjointness cleanly have hC_prop : (∀ Z ∈ C1, (0 : ZMod n) ∈ Z ∧ ((n - 2 : ℕ) : ZMod n) ∈ Z) ∧ (∀ Z ∈ C2, (0 : ZMod n) ∉ Z ∧ (1 : ZMod n) ∈ Z ∧ ((n - 1 : ℕ) : ZMod n) ∈ Z) ∧ (∀ Z ∈ C3, (0 : ZMod n) ∈ Z ∧ ((n - 2 : ℕ) : ZMod n) ∉ Z) ∧ (∀ Z ∈ C4, (0 : ZMod n) ∉ Z ∧ (1 : ZMod n) ∈ Z ∧ ((n - 1 : ℕ) : ZMod n) ∉ Z) ∧ (∀ Z ∈ C5, (0 : ZMod n) ∉ Z ∧ (1 : ZMod n) ∉ Z) := by refine ⟨?_, ?_, ?_, ?_, ?_⟩ · intro Z hZ; obtain ⟨A, hA, rfl⟩ := Finset.mem_image.mp hZ rw [mem_linearGap23Set] at hA refine ⟨(mem_embedLinear_iff (by omega)).mpr ⟨by simp, by simp, by simpa using hA.1⟩, (mem_embedLinear_iff (by omega)).mpr ⟨by simp, by rw [ZMod.val_natCast, Nat.mod_eq_of_lt (by omega), zero_add], by convert hA.2.1 using 1; exact Fin.ext (by dsimp; rw [ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)])⟩⟩ · intro Z hZ; obtain ⟨A, hA, rfl⟩ := Finset.mem_image.mp hZ rw [mem_linearGap23Set] at hA refine ⟨fun h => by rw [mem_embedLinear_iff (by omega)] at h; obtain ⟨h1, _, _⟩ := h; simp at h1, (mem_embedLinear_iff (by omega)).mpr ⟨by rw [hval1], by rw [hval1]; omega, by convert hA.1 using 1; exact Fin.ext (by dsimp; rw [hval1])⟩, (mem_embedLinear_iff (by omega)).mpr ⟨by rw [ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)]; omega, by rw [ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)]; omega, by convert hA.2.1 using 1; exact Fin.ext (by dsimp; rw [ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)]; omega)⟩⟩ · intro Z hZ; obtain ⟨A, hA, rfl⟩ := Finset.mem_image.mp hZ rw [mem_linearGap23Set] at hA refine ⟨(mem_embedLinear_iff (by omega)).mpr ⟨by simp, by simp, by simpa using hA.1⟩, fun h => by rw [mem_embedLinear_iff (by omega)] at h obtain ⟨_, h2, _⟩ := h rw [ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)] at h2; omega⟩ · intro Z hZ; obtain ⟨A, hA, rfl⟩ := Finset.mem_image.mp hZ rw [mem_linearGap23Set] at hA refine ⟨fun h => by rw [mem_embedLinear_iff (by omega)] at h; obtain ⟨h1, _, _⟩ := h; simp at h1, (mem_embedLinear_iff (by omega)).mpr ⟨by rw [hval1], by rw [hval1]; omega, by convert hA.1 using 1; exact Fin.ext (by dsimp; rw [hval1])⟩, fun h => by rw [mem_embedLinear_iff (by omega)] at h obtain ⟨_, h2, _⟩ := h rw [ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)] at h2; omega⟩ · intro Z hZ; obtain ⟨A, hA, rfl⟩ := Finset.mem_image.mp hZ refine ⟨fun h => by rw [mem_embedLinear_iff (by omega)] at h; obtain ⟨h1, _, _⟩ := h; simp at h1, fun h => by rw [mem_embedLinear_iff (by omega)] at h obtain ⟨h1, _, _⟩ := h rw [hval1] at h1; omega⟩ obtain ⟨hP1, hP2, hP3, hP4, hP5⟩ := hC_prop have hd12 : Disjoint C1 C2 := Finset.disjoint_left.mpr fun Z h1 h2 => (hP2 Z h2).1 (hP1 Z h1).1 have hd12_3 : Disjoint (C1 ∪ C2) C3 := Finset.disjoint_left.mpr fun Z h12 h3 => by rcases Finset.mem_union.mp h12 with h1 | h2 · exact (hP3 Z h3).2 (hP1 Z h1).2 · exact (hP2 Z h2).1 (hP3 Z h3).1 have hd123_4 : Disjoint (C1 ∪ C2 ∪ C3) C4 := Finset.disjoint_left.mpr fun Z h123 h4 => by rcases Finset.mem_union.mp h123 with h12 | h3 · rcases Finset.mem_union.mp h12 with h1 | h2 · exact (hP4 Z h4).1 (hP1 Z h1).1 · exact (hP4 Z h4).2.2 (hP2 Z h2).2.2 · exact (hP4 Z h4).1 (hP3 Z h3).1 have hd1234_5 : Disjoint (C1 ∪ C2 ∪ C3 ∪ C4) C5 := Finset.disjoint_left.mpr fun Z h1234 h5 => by rcases Finset.mem_union.mp h1234 with h123 | h4 · rcases Finset.mem_union.mp h123 with h12 | h3 · rcases Finset.mem_union.mp h12 with h1 | h2 · exact (hP5 Z h5).1 (hP1 Z h1).1 · exact (hP5 Z h5).2 (hP2 Z h2).2.1 · exact (hP5 Z h5).1 (hP3 Z h3).1 · exact (hP5 Z h5).2 (hP4 Z h4).2.1 rw [hM_eq, Finset.card_union_of_disjoint hd1234_5, Finset.card_union_of_disjoint hd123_4, Finset.card_union_of_disjoint hd12_3, Finset.card_union_of_disjoint hd12] rw [Finset.card_image_of_injective _ (embedLinear_inj (by omega)), Finset.card_image_of_injective _ (embedLinear_inj (by omega)), Finset.card_image_of_injective _ (embedLinear_inj (by omega)), Finset.card_image_of_injective _ (embedLinear_inj (by omega)), Finset.card_image_of_injective _ (embedLinear_inj (by omega))] rw [card_linearGap23Set, card_linearGap23Set] have hn3 : n = (n - 3) + 3 := by omega have h1 : n - 2 = (n - 3) + 1 := by omega rw [h1] conv_rhs => rw [hn3, perrin_eq_padovanComp] omega /-- **Corollary 3A (Exact Perrin Count of Binary Normal $\mathcal{P}$-positions of $\mathrm{CN}(n, n-2)$)**: For every $n \ge 5$, the number of binary normal $\mathcal{P}$-positions of $\mathrm{CN}(n, n - 2)$ is **exactly $1 + P(n)$**. -/ theorem card_normalP_sub_two_eq_one_add_perrin {n : ℕ} [NeZero n] (hn : 5 ≤ n) : (Finset.univ.filter (fun S : Finset (ZMod n) => IsNormalP n (n - 2) (embedBin S))).card = 1 + perrin n := by have heq : Finset.univ.filter (fun S : Finset (ZMod n) => IsNormalP n (n - 2) (embedBin S)) = insert ∅ (Finset.univ.filter (fun S : Finset (ZMod n) => IsMinVertexCover n S)) := by ext S simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_insert] exact isNormalP_sub_two_iff hn S rw [heq, Finset.card_insert_of_notMem] · rw [card_minVertexCover_eq_perrin (by omega)]; omega · simp only [Finset.mem_filter, Finset.mem_univ, true_and] intro h; exact isMinVertexCover_not_empty h rfl /-! ### Section 6: Exact Sprague–Grundy & Normal/Misère Duality for $d = 3$ ($\mathrm{CN}(n, n - 3)$) -/ /-- `S` is a **dominating set** of $C_n$ (equivalently a $3$-arc transversal: no `000`). -/ def IsDomSet (n : ℕ) [NeZero n] (S : Finset (ZMod n)) : Prop := ∀ i : ZMod n, i ∈ S ∨ i + 1 ∈ S ∨ i + 2 ∈ S /-- `S` is a **minimal dominating set** of $C_n$ (OEIS A253413). -/ def IsMinDomSet (n : ℕ) [NeZero n] (S : Finset (ZMod n)) : Prop := IsDomSet n S ∧ ∀ i ∈ S, ¬ IsDomSet n (S.erase i) /-- `S^c` is an **independent set of $C_n^2$** (no `00` and no `010`; every $3$-arc has $\ge 2$ ones). -/ def IsIndepCycleSqCompl (n : ℕ) [NeZero n] (S : Finset (ZMod n)) : Prop := ∀ i : ZMod n, i ∉ S → i + 1 ∈ S ∧ i + 2 ∈ S /-- `S^c` is a **maximal independent set of $C_n^2$** (no `00`, no `010`, and no `11111`). -/ def IsMISCycleSqCompl (n : ℕ) [NeZero n] (S : Finset (ZMod n)) : Prop := IsIndepCycleSqCompl n S ∧ ∀ a : ZMod n, ¬ (a ∈ S ∧ a + 1 ∈ S ∧ a + 2 ∈ S ∧ a + 3 ∈ S ∧ a + 4 ∈ S) lemma isDomSet_iff_arcTransversal (n : ℕ) [NeZero n] (S : Finset (ZMod n)) : IsDomSet n S ↔ IsArcTransversal n 3 S := by constructor · intro h s rcases h s with h0 | h1 | h2 · exact ⟨⟨0, by omega⟩, by simpa using h0⟩ · exact ⟨⟨1, by omega⟩, by simpa using h1⟩ · exact ⟨⟨2, by omega⟩, by simpa using h2⟩ · intro h s obtain ⟨⟨j, hj⟩, hmem⟩ := h s interval_cases j · left; simpa using hmem · right; left; simpa using hmem · right; right; simpa using hmem lemma isMinDomSet_iff_minArcTransversal (n : ℕ) [NeZero n] (S : Finset (ZMod n)) : IsMinDomSet n S ↔ IsMinArcTransversal n 3 S := by simp only [IsMinDomSet, IsMinArcTransversal, isDomSet_iff_arcTransversal] /-- No minimal dominating set of $C_n$ ($n \ge 4$) can contain three consecutive vertices (`111`). -/ lemma isMinDomSet_no_three_ones {n : ℕ} [NeZero n] (hn : 4 ≤ n) {S : Finset (ZMod n)} (h : IsMinDomSet n S) (a : ZMod n) : ¬ (a ∈ S ∧ a + 1 ∈ S ∧ a + 2 ∈ S) := by rintro ⟨h0, h1, h2⟩ apply h.2 (a + 1) h1 intro s by_cases hs : s = a + 1 · subst hs; right; left refine Finset.mem_erase.mpr ⟨?_, by convert h2 using 1; ring⟩ intro heq apply zmod_add_natCast_ne a (a := 1) (b := 2) (by omega) (by omega) have : a + (1 : ℕ) = a + 1 := by simp have : a + (2 : ℕ) = a + 2 := by simp linear_combination -heq · by_cases hs1 : s + 1 = a + 1 · left have hsa : s = a := add_right_cancel hs1 subst hsa refine Finset.mem_erase.mpr ⟨?_, h0⟩ simpa using zmod_add_natCast_ne s (a := 0) (b := 1) (by omega) (by omega) · by_cases hs2 : s + 2 = a + 1 · right; left have hs1a : s + 1 = a := by linear_combination hs2 rw [hs1a] refine Finset.mem_erase.mpr ⟨?_, h0⟩ simpa using zmod_add_natCast_ne a (a := 0) (b := 1) (by omega) (by omega) · rcases h.1 s with hm | hm | hm · left; exact Finset.mem_erase.mpr ⟨hs, hm⟩ · right; left; exact Finset.mem_erase.mpr ⟨hs1, hm⟩ · right; right; exact Finset.mem_erase.mpr ⟨hs2, hm⟩ lemma isMinDomSet_not_empty {n : ℕ} [NeZero n] {S : Finset (ZMod n)} (h : IsMinDomSet n S) : S ≠ ∅ := by intro h0; subst h0; rcases h.1 0 with h1 | h1 | h1 <;> simp at h1 lemma isMinDomSet_not_univ {n : ℕ} [NeZero n] (hn : 4 ≤ n) {S : Finset (ZMod n)} (h : IsMinDomSet n S) : S ≠ Finset.univ := by intro hu; subst hu exact isMinDomSet_no_three_ones hn h 0 ⟨Finset.mem_univ _, Finset.mem_univ _, Finset.mem_univ _⟩ /-- Every $3$-arc of an `IsIndepCycleSqCompl` set contains at least two elements of `S`. -/ lemma isIndepCycleSqCompl_two_in_arc {n : ℕ} [NeZero n] (_hn : 5 ≤ n) {S : Finset (ZMod n)} (h : IsIndepCycleSqCompl n S) (s : ZMod n) : (s ∈ S ∧ s + 1 ∈ S) ∨ (s ∈ S ∧ s + 2 ∈ S) ∨ (s + 1 ∈ S ∧ s + 2 ∈ S) := by by_cases hs : s ∈ S · by_cases hs1 : s + 1 ∈ S · exact Or.inl ⟨hs, hs1⟩ · right; left; exact ⟨hs, by convert (h (s + 1) hs1).1 using 1; ring⟩ · right; right; exact h s hs /-- Backward neighbors of a zero in `IsIndepCycleSqCompl` are also in `S`. -/ lemma isIndepCycleSqCompl_prev {n : ℕ} [NeZero n] {S : Finset (ZMod n)} (h : IsIndepCycleSqCompl n S) {z : ZMod n} (hz : z ∉ S) : z - 1 ∈ S ∧ z - 2 ∈ S := by constructor · by_contra hm1 have := (h (z - 1) hm1).1 simp only [sub_add_cancel] at this; exact hz this · by_contra hm2 have := (h (z - 2) hm2).2 have : z - 2 + 2 = z := by ring rw [this] at this; exact hz (by convert (h (z - 2) hm2).2 using 1; ring) /-- `IsMISCycleSqCompl` is always disjoint from `IsMinDomSet` and has `|S| ≥ 2` and `S ≠ univ`. -/ lemma isMISCycleSqCompl_disjoint_minDom {n : ℕ} [NeZero n] (hn : 5 ≤ n) {S : Finset (ZMod n)} (h : IsMISCycleSqCompl n S) : ¬ IsMinDomSet n S := by intro hmd have hne := isMinDomSet_not_empty hmd obtain ⟨i, hi⟩ := Finset.nonempty_iff_ne_empty.mpr hne apply hmd.2 i hi intro s -- Every 3-arc has ≥ 2 elements of S, so removing i leaves at least one! rcases isIndepCycleSqCompl_two_in_arc hn h.1 s with ⟨h0, h1⟩ | ⟨h0, h2⟩ | ⟨h1, h2⟩ · by_cases hsi : s = i · right; left; refine Finset.mem_erase.mpr ⟨?_, h1⟩ subst hsi; simpa using (zmod_add_natCast_ne s (a := 0) (b := 1) (by omega) (by omega)).symm · left; exact Finset.mem_erase.mpr ⟨hsi, h0⟩ · by_cases hsi : s = i · right; right; refine Finset.mem_erase.mpr ⟨?_, h2⟩ subst hsi; simpa using (zmod_add_natCast_ne s (a := 0) (b := 2) (by omega) (by omega)).symm · left; exact Finset.mem_erase.mpr ⟨hsi, h0⟩ · by_cases hs1 : s + 1 = i · right; right; refine Finset.mem_erase.mpr ⟨?_, h2⟩ have : s + 2 ≠ s + 1 := by simpa using (zmod_add_natCast_ne s (a := 1) (b := 2) (by omega) (by omega)).symm rwa [← hs1] · right; left; exact Finset.mem_erase.mpr ⟨hs1, h1⟩ lemma isMISCycleSqCompl_card_ge_two {n : ℕ} [NeZero n] (hn : 5 ≤ n) {S : Finset (ZMod n)} (h : IsMISCycleSqCompl n S) : 2 ≤ S.card := by rcases isIndepCycleSqCompl_two_in_arc hn h.1 0 with ⟨h0, h1⟩ | ⟨h0, h2⟩ | ⟨h1, h2⟩ · have hne : (0 : ZMod n) ≠ 1 := by simpa using zmod_add_natCast_ne (0 : ZMod n) (a := 0) (b := 1) (by omega) (by omega) have : ({0, 1} : Finset (ZMod n)) ⊆ S := by intro x hx; simp only [Finset.mem_insert, Finset.mem_singleton] at hx rcases hx with rfl | rfl · exact h0 · simpa using h1 linarith [Finset.card_le_card this, Finset.card_pair hne] · have hne : (0 : ZMod n) ≠ 2 := by simpa using zmod_add_natCast_ne (0 : ZMod n) (a := 0) (b := 2) (by omega) (by omega) have : ({0, 2} : Finset (ZMod n)) ⊆ S := by intro x hx; simp only [Finset.mem_insert, Finset.mem_singleton] at hx rcases hx with rfl | rfl · exact h0 · simpa using h2 linarith [Finset.card_le_card this, Finset.card_pair hne] · have hne : (1 : ZMod n) ≠ 2 := by simpa using zmod_add_natCast_ne (0 : ZMod n) (a := 1) (b := 2) (by omega) (by omega) have : ({1, 2} : Finset (ZMod n)) ⊆ S := by intro x hx; simp only [Finset.mem_insert, Finset.mem_singleton] at hx rcases hx with rfl | rfl · simpa using h1 · simpa using h2 linarith [Finset.card_le_card this, Finset.card_pair hne] lemma isMISCycleSqCompl_not_univ {n : ℕ} [NeZero n] {S : Finset (ZMod n)} (h : IsMISCycleSqCompl n S) : S ≠ Finset.univ := by intro hu; subst hu exact h.2 0 ⟨Finset.mem_univ _, Finset.mem_univ _, Finset.mem_univ _, Finset.mem_univ _, Finset.mem_univ _⟩ /-- Every proper subset of an `IsMISCycleSqCompl` set fails `IsIndepCycleSqCompl` (maximality in $C_n^2$). -/ lemma isMISCycleSqCompl_not_indep_of_ssubset {n : ℕ} [NeZero n] (_hn : 5 ≤ n) {S T : Finset (ZMod n)} (hS : IsMISCycleSqCompl n S) (hsub : T ⊂ S) : ¬ IsIndepCycleSqCompl n T := by intro hT obtain ⟨i, hiS, hiT⟩ := Finset.exists_of_ssubset hsub -- Since i ∉ T and hT, i+1, i+2, i-1, i-2 are all in T ⊆ S, giving 11111 in S! have hp := hT i hiT have hm := isIndepCycleSqCompl_prev hT hiT exact hS.2 (i - 2) ⟨hsub.1 hm.2, by convert hsub.1 hm.1 using 1; ring, by convert hiS using 1; ring, by convert hsub.1 hp.1 using 1; ring, by convert hsub.1 hp.2 using 1; ring⟩ /-- Every `IsIndepCycleSqCompl` set `S` contains an `IsMISCycleSqCompl` subset `T ⊆ S`. -/ lemma exists_isMISCycleSqCompl_subset {n : ℕ} [NeZero n] (hn : 5 ≤ n) {S : Finset (ZMod n)} (hS : IsIndepCycleSqCompl n S) : ∃ T ⊆ S, IsMISCycleSqCompl n T := by let F := S.powerset.filter (fun T => IsIndepCycleSqCompl n T) have hne : F.Nonempty := ⟨S, Finset.mem_filter.mpr ⟨Finset.mem_powerset_self S, hS⟩⟩ obtain ⟨T, hTF, hTmin⟩ := Finset.exists_min_image F Finset.card hne rw [Finset.mem_filter, Finset.mem_powerset] at hTF refine ⟨T, hTF.1, hTF.2, fun a ⟨h0, h1, h2, h3, h4⟩ => ?_⟩ -- If T has 11111 at a..a+4, erasing a+2 keeps IsIndepCycleSqCompl! let T' := T.erase (a + 2) have hT'ind : IsIndepCycleSqCompl n T' := by intro i hi by_cases hia : i = a + 2 · subst hia refine ⟨Finset.mem_erase.mpr ⟨?_, by convert h3 using 1; ring⟩, Finset.mem_erase.mpr ⟨?_, by convert h4 using 1; ring⟩⟩ · intro heq; apply zmod_add_natCast_ne a (a := 2) (b := 3) (by omega) (by omega) have : a + ((2 : ℕ) : ZMod n) = a + 2 := by norm_num have : a + ((3 : ℕ) : ZMod n) = a + 3 := by norm_num linear_combination -heq · intro heq; apply zmod_add_natCast_ne a (a := 2) (b := 4) (by omega) (by omega) have : a + ((2 : ℕ) : ZMod n) = a + 2 := by norm_num have : a + ((4 : ℕ) : ZMod n) = a + 4 := by norm_num linear_combination -heq · have hiT : i ∉ T := fun h => hi (Finset.mem_erase.mpr ⟨hia, h⟩) have h1' := (hTF.2 i hiT).1 have h2' := (hTF.2 i hiT).2 have hne1 : i + 1 ≠ a + 2 := by intro heq have hia1 : i = a + 1 := by linear_combination heq rw [hia1] at hiT; exact hiT h1 have hne2 : i + 2 ≠ a + 2 := by intro heq have hia0 : i = a := add_right_cancel heq rw [hia0] at hiT; exact hiT h0 exact ⟨Finset.mem_erase.mpr ⟨hne1, h1'⟩, Finset.mem_erase.mpr ⟨hne2, h2'⟩⟩ have hmem : T' ∈ F := Finset.mem_filter.mpr ⟨Finset.mem_powerset.mpr (Finset.Subset.trans (Finset.erase_subset _ T) hTF.1), hT'ind⟩ have hle : T.card ≤ T'.card := hTmin T' hmem have hlt : T'.card < T.card := Finset.card_erase_lt_of_mem h2 omega /-- Key `n ≥ 7` Structural Lemma: From ANY non-universal `IsIndepCycleSqCompl` set `S`, erasing `z - 2` and `z + 2` around any `z ∉ S` still yields a dominating set `A₀`, so ANY minimal dominating set `T ⊆ A₀` leaves `{z - 1, z, z + 1}` untouched and gives a legal move `BinMove n (n - 3) S T`! -/ lemma exists_binMove_to_minDom_of_indep {n : ℕ} [NeZero n] (hn : 7 ≤ n) {S : Finset (ZMod n)} (hS : IsIndepCycleSqCompl n S) (hnu : S ≠ Finset.univ) : ∃ T, BinMove n (n - 3) S T ∧ IsMinDomSet n T := by have hz_ex : ∃ z : ZMod n, z ∉ S := by by_contra h; push Not at h; exact hnu (Finset.eq_univ_iff_forall.mpr h) obtain ⟨z, hzS⟩ := hz_ex have hzm := isIndepCycleSqCompl_prev hS hzS have hzp := hS z hzS let A₀ := (S.erase (z - 2)).erase (z + 2) have hA₀dom : IsDomSet n A₀ := by intro s -- Check if any element of {s, s+1, s+2} is in A₀; equivalently not all three are outside A₀ by_contra hall push Not at hall obtain ⟨h0, h1, h2⟩ := hall -- Notice: A₀^c = S^c ∪ {z - 2, z + 2}! -- If two of {s, s+1, s+2} were in S^c, that violates IsIndepCycleSqCompl S! -- If {s, s+1, s+2} contains BOTH z - 2 and z + 2, then dist(z-2, z+2) ≤ 2, impossible since n ≥ 7! have hnot_both : ¬ ((s = z - 2 ∨ s + 1 = z - 2 ∨ s + 2 = z - 2) ∧ (s = z + 2 ∨ s + 1 = z + 2 ∨ s + 2 = z + 2)) := by rintro ⟨hl, hr⟩ rcases hl with rfl | h | h <;> rcases hr with h' | h' | h' · exact zmod_natCast_ne_zero (n := n) (a := 4) (by omega) (by omega) (by rw [Nat.cast_ofNat]; linear_combination -h') · exact zmod_natCast_ne_zero (n := n) (a := 3) (by omega) (by omega) (by rw [Nat.cast_ofNat]; linear_combination -h') · exact zmod_natCast_ne_zero (n := n) (a := 2) (by omega) (by omega) (by rw [Nat.cast_ofNat]; linear_combination -h') · exact zmod_natCast_ne_zero (n := n) (a := 5) (by omega) (by omega) (by rw [Nat.cast_ofNat]; linear_combination h - h') · exact zmod_natCast_ne_zero (n := n) (a := 4) (by omega) (by omega) (by rw [Nat.cast_ofNat]; linear_combination h - h') · exact zmod_natCast_ne_zero (n := n) (a := 3) (by omega) (by omega) (by rw [Nat.cast_ofNat]; linear_combination h - h') · exact zmod_natCast_ne_zero (n := n) (a := 6) (by omega) (by omega) (by rw [Nat.cast_ofNat]; linear_combination h - h') · exact zmod_natCast_ne_zero (n := n) (a := 5) (by omega) (by omega) (by rw [Nat.cast_ofNat]; linear_combination h - h') · exact zmod_natCast_ne_zero (n := n) (a := 4) (by omega) (by omega) (by rw [Nat.cast_ofNat]; linear_combination h - h') -- Therefore at most ONE of {s, s+1, s+2} is in {z - 2, z + 2}, so at least TWO are in S^c! have hmem_out : ∀ x, x ∉ A₀ → x ∉ S ∨ x = z - 2 ∨ x = z + 2 := by intro x hx by_cases h1 : x = z + 2; · exact Or.inr (Or.inr h1) · by_cases h2 : x = z - 2; · exact Or.inr (Or.inl h2) · left; intro hxS; exact hx (Finset.mem_erase.mpr ⟨h1, Finset.mem_erase.mpr ⟨h2, hxS⟩⟩) -- Also z-2 and z+2 are distinct from each other, and s, s+1, s+2 are distinct! have hd01 : s ≠ s + 1 := by simpa using zmod_add_natCast_ne s (a := 0) (b := 1) (by omega) (by omega) have hd12 : s + 1 ≠ s + 2 := by simpa using zmod_add_natCast_ne s (a := 1) (b := 2) (by omega) (by omega) have hd02 : s ≠ s + 2 := by simpa using zmod_add_natCast_ne s (a := 0) (b := 2) (by omega) (by omega) rcases hmem_out s h0 with hs0 | hs0 | hs0 <;> rcases hmem_out (s + 1) h1 with hs1 | hs1 | hs1 <;> rcases hmem_out (s + 2) h2 with hs2 | hs2 | hs2 · exact hs1 (hS s hs0).1 · exact hs1 (hS s hs0).1 · exact hs1 (hS s hs0).1 · exact hs2 (hS s hs0).2 · exact hd12 (hs1.trans hs2.symm) · exact hnot_both ⟨Or.inr (Or.inl hs1), Or.inr (Or.inr hs2)⟩ · exact hs2 (hS s hs0).2 · exact hnot_both ⟨Or.inr (Or.inr hs2), Or.inr (Or.inl hs1)⟩ · exact hd12 (hs1.trans hs2.symm) · exact hs2 (by convert (hS (s + 1) hs1).1 using 1; ring) · exact hd02 (hs0.trans hs2.symm) · exact hnot_both ⟨Or.inl hs0, Or.inr (Or.inr hs2)⟩ · exact hd01 (hs0.trans hs1.symm) · exact hd01 (hs0.trans hs1.symm) · exact hd01 (hs0.trans hs1.symm) · exact hnot_both ⟨Or.inl hs0, Or.inr (Or.inl hs1)⟩ · exact hnot_both ⟨Or.inl hs0, Or.inr (Or.inl hs1)⟩ · exact hnot_both ⟨Or.inl hs0, Or.inr (Or.inl hs1)⟩ · exact hs2 (by convert (hS (s + 1) hs1).1 using 1; ring) · exact hnot_both ⟨Or.inr (Or.inr hs2), Or.inl hs0⟩ · exact hd02 (hs0.trans hs2.symm) · exact hnot_both ⟨Or.inr (Or.inl hs1), Or.inl hs0⟩ · exact hnot_both ⟨Or.inr (Or.inl hs1), Or.inl hs0⟩ · exact hnot_both ⟨Or.inr (Or.inl hs1), Or.inl hs0⟩ · exact hd01 (hs0.trans hs1.symm) · exact hd01 (hs0.trans hs1.symm) · exact hd01 (hs0.trans hs1.symm) obtain ⟨T, hTA, hTmin⟩ := exists_minArcTransversal_subset ((isDomSet_iff_arcTransversal n A₀).mp hA₀dom) have hTmd : IsMinDomSet n T := (isMinDomSet_iff_minArcTransversal n T).mpr hTmin have hTS : T ⊆ S := Finset.Subset.trans hTA (Finset.Subset.trans (Finset.erase_subset _ _) (Finset.erase_subset _ _)) have hTss : T ⊂ S := by rw [Finset.ssubset_iff_subset_ne] refine ⟨hTS, fun heq => ?_⟩ have hz2T : z + 2 ∈ T := heq ▸ hzp.2 have := hTA hz2T; simp [A₀] at this -- Untouched 3-arc is {z - 1, z, z + 1}! have hzT : z ∉ T := fun h => hzS (hTS h) have hzm2T : z - 2 ∉ T := fun h => by have := hTA h; simp [A₀] at this have hzp2T : z + 2 ∉ T := fun h => by have := hTA h; simp [A₀] at this have hzm1T : z - 1 ∈ T := by rcases hTmd.1 (z - 2) with h | h | h · exact absurd h hzm2T · convert h using 1; ring · exfalso; exact hzT (by convert h using 1; ring) have hzp1T : z + 1 ∈ T := by rcases hTmd.1 z with h | h | h · exact absurd h hzT · exact h · exact absurd h hzp2T refine ⟨T, ?_, hTmd⟩ rw [binMove_sub_iff (by omega)] refine ⟨hTss, z - 1, fun j => ?_⟩ fin_cases j · simp [hzm.1, hzm1T] · simp [hzS, hzT] · have : z - 1 + (2 : ZMod n) = z + 1 := by ring simp [this, hzp.1, hzp1T] /-- Closed-form Sprague–Grundy formula for binary $\mathrm{CN}(n, n - 3)$ ($n \ge 7$). -/ noncomputable def grundySubThreeFormula (n : ℕ) [NeZero n] (S : Finset (ZMod n)) : ℕ := if S = ∅ ∨ S = Finset.univ ∨ IsMinDomSet n S then 0 else if IsMISCycleSqCompl n S then 1 else S.card /-- **THEOREM 4 (Exact Sprague–Grundy Function of $\mathrm{CN}(n, n - 3)$ on $\{0, 1\}^n$)**: For every $n \ge 7$ and every $S \subseteq \mathbb{Z}/n\mathbb{Z}$, the exact Sprague–Grundy value in full $\mathbb{N}^n$ Circular Nim $\mathrm{CN}(n, n - 3)$ is `grundySubThreeFormula n S`. -/ theorem grundy_sub_three_exact {n : ℕ} [NeZero n] (hn : 7 ≤ n) (S : Finset (ZMod n)) : grundy n (n - 3) (embedBin S) = grundySubThreeFormula n S := by apply grundy_embedBin_eq_of_spec (grundySubThreeFormula n) · -- (1) No move preserves grundySubThreeFormula intro S T hbm heq rw [binMove_sub_iff (by omega)] at hbm obtain ⟨hsub, s, hunt⟩ := hbm have hTlt : T.card < S.card := Finset.card_lt_card hsub have hTnu : T ≠ Finset.univ := ne_univ_of_ssubset hsub dsimp only [grundySubThreeFormula] at heq by_cases hT0 : T = ∅ ∨ T = Finset.univ ∨ IsMinDomSet n T · rw [if_pos hT0] at heq by_cases hS0 : S = ∅ ∨ S = Finset.univ ∨ IsMinDomSet n S · rcases hS0 with rfl | rfl | hSmd · exact Finset.not_ssubset_empty T hsub · rcases hT0 with rfl | hTu | hTmd · exact Finset.notMem_empty s (by simpa using (hunt ⟨0, by omega⟩).mpr (Finset.mem_univ _)) · exact hTnu hTu · exact isMinDomSet_no_three_ones (by omega) hTmd s ⟨by simpa using (hunt ⟨0, by omega⟩).mpr (Finset.mem_univ _), by simpa using (hunt ⟨1, by omega⟩).mpr (Finset.mem_univ _), by simpa using (hunt ⟨2, by omega⟩).mpr (Finset.mem_univ _)⟩ · rcases hT0 with rfl | hTu | hTmd · rcases hSmd.1 s with h0 | h1 | h2 · exact Finset.notMem_empty s (by simpa using (hunt ⟨0, by omega⟩).mpr (by simpa using h0)) · exact Finset.notMem_empty (s + 1) (by simpa using (hunt ⟨1, by omega⟩).mpr (by simpa using h1)) · exact Finset.notMem_empty (s + 2) (by simpa using (hunt ⟨2, by omega⟩).mpr (by simpa using h2)) · exact hTnu hTu · obtain ⟨i, hiS, hiT⟩ := Finset.exists_of_ssubset hsub apply hSmd.2 i hiS intro x rcases hTmd.1 x with hx | hx | hx · left; exact Finset.mem_erase.mpr ⟨fun h => hiT (h ▸ hx), hsub.1 hx⟩ · right; left; exact Finset.mem_erase.mpr ⟨fun h => hiT (h ▸ hx), hsub.1 hx⟩ · right; right; exact Finset.mem_erase.mpr ⟨fun h => hiT (h ▸ hx), hsub.1 hx⟩ · rw [if_neg hS0] at heq by_cases hSmis : IsMISCycleSqCompl n S · rw [if_pos hSmis] at heq; omega · rw [if_neg hSmis] at heq have hSne : S.Nonempty := Finset.nonempty_iff_ne_empty.mpr (fun h => hS0 (Or.inl h)) have := Finset.card_pos.mpr hSne; omega · rw [if_neg hT0] at heq by_cases hTmis : IsMISCycleSqCompl n T · rw [if_pos hTmis] at heq by_cases hS0 : S = ∅ ∨ S = Finset.univ ∨ IsMinDomSet n S · rw [if_pos hS0] at heq; omega · rw [if_neg hS0] at heq by_cases hSmis : IsMISCycleSqCompl n S · exact isMISCycleSqCompl_not_indep_of_ssubset (by omega) hSmis hsub hTmis.1 · rw [if_neg hSmis] at heq have hTge2 := isMISCycleSqCompl_card_ge_two (by omega) hTmis omega · rw [if_neg hTmis] at heq by_cases hS0 : S = ∅ ∨ S = Finset.univ ∨ IsMinDomSet n S · rw [if_pos hS0] at heq have hTne : T.Nonempty := Finset.nonempty_iff_ne_empty.mpr (fun h => hT0 (Or.inl h)) have := Finset.card_pos.mpr hTne; omega · rw [if_neg hS0] at heq by_cases hSmis : IsMISCycleSqCompl n S · rw [if_pos hSmis] at heq rcases isIndepCycleSqCompl_two_in_arc (by omega) hSmis.1 s with ⟨h0, h1⟩ | ⟨h0, h2⟩ | ⟨h1, h2⟩ · have h0T : s ∈ T := by simpa using (hunt ⟨0, by omega⟩).mpr (by simpa using h0) have h1T : s + 1 ∈ T := by simpa using (hunt ⟨1, by omega⟩).mpr (by simpa using h1) have hne : s ≠ s + 1 := by simpa using zmod_add_natCast_ne s (a := 0) (b := 1) (by omega) (by omega) have : ({s, s + 1} : Finset (ZMod n)).card ≤ T.card := Finset.card_le_card (by intro x hx; simp only [Finset.mem_insert, Finset.mem_singleton] at hx rcases hx with rfl | rfl <;> assumption) rw [Finset.card_pair hne] at this; omega · have h0T : s ∈ T := by simpa using (hunt ⟨0, by omega⟩).mpr (by simpa using h0) have h2T : s + 2 ∈ T := by simpa using (hunt ⟨2, by omega⟩).mpr (by simpa using h2) have hne : s ≠ s + 2 := by simpa using zmod_add_natCast_ne s (a := 0) (b := 2) (by omega) (by omega) have : ({s, s + 2} : Finset (ZMod n)).card ≤ T.card := Finset.card_le_card (by intro x hx; simp only [Finset.mem_insert, Finset.mem_singleton] at hx rcases hx with rfl | rfl <;> assumption) rw [Finset.card_pair hne] at this; omega · have h1T : s + 1 ∈ T := by simpa using (hunt ⟨1, by omega⟩).mpr (by simpa using h1) have h2T : s + 2 ∈ T := by simpa using (hunt ⟨2, by omega⟩).mpr (by simpa using h2) have hne : s + 1 ≠ s + 2 := by simpa using zmod_add_natCast_ne s (a := 1) (b := 2) (by omega) (by omega) have : ({s + 1, s + 2} : Finset (ZMod n)).card ≤ T.card := Finset.card_le_card (by intro x hx; simp only [Finset.mem_insert, Finset.mem_singleton] at hx rcases hx with rfl | rfl <;> assumption) rw [Finset.card_pair hne] at this; omega · rw [if_neg hSmis] at heq; omega · -- (2) Every u < grundySubThreeFormula n S is achieved by some legal move intro S u hu dsimp only [grundySubThreeFormula] at hu split_ifs at hu with hS0 hSmis · omega · -- IsMISCycleSqCompl S, u = 0: use our n ≥ 7 key lemma! have hu0 : u = 0 := by omega subst hu0 obtain ⟨T, hbm, hTmd⟩ := exists_binMove_to_minDom_of_indep hn hSmis.1 (isMISCycleSqCompl_not_univ hSmis) exact ⟨T, hbm, by simp [grundySubThreeFormula, hTmd]⟩ · -- General case: S ≠ ∅, S ≠ univ, ¬ IsMinDomSet S, ¬ IsMISCycleSqCompl S, u < S.card push Not at hS0 obtain ⟨hSne, hSnu, hSnotmd⟩ := hS0 by_cases hu0 : u = 0 · -- Target u = 0 subst hu0 by_cases hdom : IsDomSet n S · by_cases h00 : ∃ z : ZMod n, z ∉ S ∧ z + 1 ∉ S · obtain ⟨z, hz0, hz1⟩ := h00 obtain ⟨T, hTS, hTmin⟩ := exists_minArcTransversal_subset ((isDomSet_iff_arcTransversal n S).mp hdom) have hTmd := (isMinDomSet_iff_minArcTransversal n T).mpr hTmin have hTss : T ⊂ S := Finset.ssubset_iff_subset_ne.mpr ⟨hTS, fun h => hSnotmd (h ▸ hTmd)⟩ have hz0T : z ∉ T := fun h => hz0 (hTS h) have hz1T : z + 1 ∉ T := fun h => hz1 (hTS h) have hz2T : z + 2 ∈ T := by rcases hTmd.1 z with h | h | h · exact absurd h hz0T · exact absurd h hz1T · exact h refine ⟨T, ?_, by simp [grundySubThreeFormula, hTmd]⟩ rw [binMove_sub_iff (by omega)] refine ⟨hTss, z, fun j => ?_⟩ fin_cases j · simp [hz0, hz0T] · simp [hz1, hz1T] · simp [hz2T, hTS hz2T] · by_cases h010 : ∃ z : ZMod n, z ∉ S ∧ z + 1 ∈ S ∧ z + 2 ∉ S · obtain ⟨z, hz0, hz1, hz2⟩ := h010 obtain ⟨T, hTS, hTmin⟩ := exists_minArcTransversal_subset ((isDomSet_iff_arcTransversal n S).mp hdom) have hTmd := (isMinDomSet_iff_minArcTransversal n T).mpr hTmin have hTss : T ⊂ S := Finset.ssubset_iff_subset_ne.mpr ⟨hTS, fun h => hSnotmd (h ▸ hTmd)⟩ have hz0T : z ∉ T := fun h => hz0 (hTS h) have hz2T : z + 2 ∉ T := fun h => hz2 (hTS h) have hz1T : z + 1 ∈ T := by rcases hTmd.1 z with h | h | h · exact absurd h hz0T · exact h · exact absurd h hz2T refine ⟨T, ?_, by simp [grundySubThreeFormula, hTmd]⟩ rw [binMove_sub_iff (by omega)] refine ⟨hTss, z, fun j => ?_⟩ fin_cases j · simp [hz0, hz0T] · simp [hz1, hz1T] · simp [hz2, hz2T] · -- No 00 and no 010 => IsIndepCycleSqCompl S! Use key lemma! have hind : IsIndepCycleSqCompl n S := by intro z hz push Not at h00 h010 have hz1 : z + 1 ∈ S := h00 z hz exact ⟨hz1, h010 z hz hz1⟩ obtain ⟨T, hbm, hTmd⟩ := exists_binMove_to_minDom_of_indep hn hind hSnu exact ⟨T, hbm, by simp [grundySubThreeFormula, hTmd]⟩ · -- S has a 000: clear everything to ∅ simp only [IsDomSet, not_forall, not_or] at hdom obtain ⟨z, hz0, hz1, hz2⟩ := hdom refine ⟨∅, ?_, by simp [grundySubThreeFormula]⟩ rw [binMove_sub_iff (by omega)] refine ⟨Finset.empty_ssubset.mpr hSne, z, fun j => ?_⟩ fin_cases j <;> simp [hz0, hz1, hz2] · by_cases hu1 : u = 1 · -- Target u = 1 (note S.card ≥ 2 since 1 < S.card) subst hu1 have hSge2 : 2 ≤ S.card := by omega by_cases h00 : ∃ z : ZMod n, z ∉ S ∧ z + 1 ∉ S · obtain ⟨z, hz0, hz1, hz2⟩ := exists_zero_zero_one hSne h00 have hss : ({z + 2} : Finset (ZMod n)) ⊂ S := by rw [Finset.ssubset_iff_subset_ne] refine ⟨Finset.singleton_subset_iff.mpr hz2, fun h => ?_⟩ rw [← h] at hSge2; simp at hSge2 have h1_not_md : ¬ IsMinDomSet n ({z + 2} : Finset (ZMod n)) := by intro hmd; rcases hmd.1 z with h | h | h · simp only [Finset.mem_singleton] at h exact zmod_add_natCast_ne z (a := 0) (b := 2) (by omega) (by omega) (by simpa using h) · simp only [Finset.mem_singleton] at h exact zmod_add_natCast_ne z (a := 1) (b := 2) (by omega) (by omega) (by simpa using h) · rcases hmd.1 (z + 3) with ha | ha | ha <;> simp only [Finset.mem_singleton] at ha · exact zmod_add_natCast_ne z (a := 2) (b := 3) (by omega) (by omega) (by simpa using ha.symm) · exact zmod_add_natCast_ne z (a := 2) (b := 4) (by omega) (by omega) (by convert ha.symm using 1 <;> (push_cast; ring)) · exact zmod_add_natCast_ne z (a := 2) (b := 5) (by omega) (by omega) (by convert ha.symm using 1 <;> (push_cast; ring)) have h1_nu : ({z + 2} : Finset (ZMod n)) ≠ Finset.univ := by intro h; have := congrArg Finset.card h; simp [ZMod.card] at this; omega refine ⟨{z + 2}, ?_, ?_⟩ · rw [binMove_sub_iff (by omega)] refine ⟨hss, z, fun j => ?_⟩ fin_cases j · have hne : z ≠ z + 2 := by simpa using zmod_add_natCast_ne z (a := 0) (b := 2) (by omega) (by omega) simp [hz0, hne] · have hne : z + 1 ≠ z + 2 := by simpa using zmod_add_natCast_ne z (a := 1) (b := 2) (by omega) (by omega) simp [hz1, hne] · simp [hz2] · simp only [grundySubThreeFormula, Finset.singleton_ne_empty, h1_nu, h1_not_md, or_self, if_false, Finset.card_singleton] split_ifs <;> rfl · by_cases h010 : ∃ z : ZMod n, z ∉ S ∧ z + 1 ∈ S ∧ z + 2 ∉ S · obtain ⟨z, hz0, hz1, hz2⟩ := h010 have hss : ({z + 1} : Finset (ZMod n)) ⊂ S := by rw [Finset.ssubset_iff_subset_ne] refine ⟨Finset.singleton_subset_iff.mpr hz1, fun h => ?_⟩ rw [← h] at hSge2; simp at hSge2 have h1_not_md : ¬ IsMinDomSet n ({z + 1} : Finset (ZMod n)) := by intro hmd rcases hmd.1 (z + 2) with ha | ha | ha <;> simp only [Finset.mem_singleton] at ha · exact zmod_add_natCast_ne z (a := 1) (b := 2) (by omega) (by omega) (by simpa using ha.symm) · exact zmod_add_natCast_ne z (a := 1) (b := 3) (by omega) (by omega) (by convert ha.symm using 1 <;> (push_cast; ring)) · exact zmod_add_natCast_ne z (a := 1) (b := 4) (by omega) (by omega) (by convert ha.symm using 1 <;> (push_cast; ring)) have h1_nu : ({z + 1} : Finset (ZMod n)) ≠ Finset.univ := by intro h; have := congrArg Finset.card h; simp [ZMod.card] at this; omega refine ⟨{z + 1}, ?_, ?_⟩ · rw [binMove_sub_iff (by omega)] refine ⟨hss, z, fun j => ?_⟩ fin_cases j · have hne : z ≠ z + 1 := by simpa using zmod_add_natCast_ne z (a := 0) (b := 1) (by omega) (by omega) simp [hz0, hne] · simp [hz1] · have hne : z + 2 ≠ z + 1 := by simpa using (zmod_add_natCast_ne z (a := 1) (b := 2) (by omega) (by omega)).symm simp [hz2, hne] · simp only [grundySubThreeFormula, Finset.singleton_ne_empty, h1_nu, h1_not_md, or_self, if_false, Finset.card_singleton] split_ifs <;> rfl · -- No 00 and no 010, ¬ IsMISCycleSqCompl S => extend Z(S) to T ⊂ S with IsMISCycleSqCompl T! have hind : IsIndepCycleSqCompl n S := by intro z hz push Not at h00 h010 have hz1 := h00 z hz exact ⟨hz1, h010 z hz hz1⟩ obtain ⟨T, hTS, hTmis⟩ := exists_isMISCycleSqCompl_subset (by omega) hind have hTss : T ⊂ S := Finset.ssubset_iff_subset_ne.mpr ⟨hTS, fun h => hSmis (h ▸ hTmis)⟩ have hz_ex : ∃ z : ZMod n, z ∉ S := by by_contra h; push Not at h; exact hSnu (Finset.eq_univ_iff_forall.mpr h) obtain ⟨z, hzS⟩ := hz_ex have hzT : z ∉ T := fun h => hzS (hTS h) have hzpT := hTmis.1 z hzT have hTne : T ≠ ∅ := by intro h; have := isMISCycleSqCompl_card_ge_two (by omega) hTmis; rw [h] at this; simp at this have hTnu := isMISCycleSqCompl_not_univ hTmis have hTnotmd := isMISCycleSqCompl_disjoint_minDom (by omega) hTmis refine ⟨T, ?_, ?_⟩ · rw [binMove_sub_iff (by omega)] refine ⟨hTss, z, fun j => ?_⟩ fin_cases j · simp [hzS, hzT] · simp [hzpT.1, hTS hzpT.1] · simp [hzpT.2, hTS hzpT.2] · simp [grundySubThreeFormula, hTne, hTnu, hTnotmd, hTmis] · -- Target 2 ≤ u < S.card! have hu2 : 2 ≤ u := by omega by_cases hdom : IsDomSet n S · by_cases h00 : ∃ z : ZMod n, z ∉ S ∧ z + 1 ∉ S · -- Case 2: S has 00 but no 000 => z, z+1 ∉ S, z+2 ∈ S, z-1 ∈ S; keep {z, z+1, z+2}, drop z-1! obtain ⟨z, hz0, hz1, hz2⟩ := exists_zero_zero_one hSne h00 have hzm1 : z - 1 ∈ S := by rcases hdom (z - 1) with h | h | h · exact h · simp only [sub_add_cancel] at h; exact absurd h hz0 · have : z - 1 + 2 = z + 1 := by ring rw [this] at h; exact absurd h hz1 have hne : z - 1 ≠ z + 2 := by simpa using zmod_add_sub_natCast_ne z (a := 1) (b := 2) (by omega) (by omega) let pool := (S.erase (z + 2)).erase (z - 1) have hpool_card : pool.card = S.card - 2 := by have h1 := Finset.card_erase_of_mem hz2 have h2 : z - 1 ∈ S.erase (z + 2) := Finset.mem_erase.mpr ⟨hne, hzm1⟩ rw [Finset.card_erase_of_mem h2, h1]; omega obtain ⟨R, hRsub, hRcard⟩ := exists_subset_card pool (r := u - 1) (by omega) let T := insert (z + 2) R have hz2_nR : z + 2 ∉ R := fun h => (Finset.mem_erase.mp (Finset.mem_erase.mp (hRsub h)).2).1 rfl have hzm1_nT : z - 1 ∉ T := by simp only [T, Finset.mem_insert, not_or] exact ⟨hne, fun h => (Finset.mem_erase.mp (hRsub h)).1 rfl⟩ have hTsub : T ⊆ S := by intro x hx; simp only [T, Finset.mem_insert] at hx rcases hx with rfl | hxR · exact hz2 · exact Finset.mem_of_mem_erase (Finset.mem_of_mem_erase (hRsub hxR)) have hTcard : T.card = u := by rw [Finset.card_insert_of_notMem hz2_nR, hRcard]; omega have hTss : T ⊂ S := Finset.ssubset_iff_subset_ne.mpr ⟨hTsub, fun h => by rw [h] at hTcard; omega⟩ have hz0T : z ∉ T := fun h => hz0 (hTsub h) have hz1T : z + 1 ∉ T := fun h => hz1 (hTsub h) have hTnotmd : ¬ IsMinDomSet n T := fun hTmd => by rcases hTmd.1 (z - 1) with h | h | h · exact hzm1_nT h · simp only [sub_add_cancel] at h; exact hz0T h · have h_eq : z - 1 + 2 = z + 1 := by ring rw [h_eq] at h; exact hz1T h have hTnotmis : ¬ IsMISCycleSqCompl n T := fun hTm => hz1T (hTm.1 z hz0T).1 have hTne : T ≠ ∅ := by intro h; rw [h] at hTcard; simp at hTcard; omega have hTnu : T ≠ Finset.univ := fun h => hz0T (h ▸ Finset.mem_univ z) refine ⟨T, ?_, ?_⟩ · rw [binMove_sub_iff (by omega)] refine ⟨hTss, z, fun j => ?_⟩ fin_cases j · simp [hz0, hz0T] · simp [hz1, hz1T] · simp [hz2, T] · simp [grundySubThreeFormula, hTne, hTnu, hTnotmd, hTnotmis, hTcard] · by_cases h010 : ∃ z : ZMod n, z ∉ S ∧ z + 1 ∈ S ∧ z + 2 ∉ S · -- Case 3: S has 010 at {z, z+1, z+2}; keep {z+2, z+3, z+4} untouched (≤ 2 ones ≤ u!), drop z+1! obtain ⟨z, hz0, hz1, hz2⟩ := h010 let K : Finset (ZMod n) := S ∩ {z + 2, z + 3, z + 4} have hKsub : K ⊆ S := Finset.inter_subset_left have hz2_nK : z + 2 ∉ K := fun h => hz2 (Finset.mem_inter.mp h).1 have hKsub2 : K ⊆ {z + 3, z + 4} := by intro x hx have hx2 := (Finset.mem_inter.mp hx).2 simp only [Finset.mem_insert, Finset.mem_singleton] at hx2 ⊢ rcases hx2 with rfl | h | h · exact absurd hx hz2_nK · exact Or.inl h · exact Or.inr h have hKcard : K.card ≤ 2 := by calc K.card ≤ ({z + 3, z + 4} : Finset (ZMod n)).card := Finset.card_le_card hKsub2 _ ≤ 2 := Finset.card_le_two have hz1_nK : z + 1 ∉ K := by intro h have h2 := hKsub2 h simp only [Finset.mem_insert, Finset.mem_singleton] at h2 rcases h2 with heq | heq · exact zmod_add_natCast_ne z (a := 1) (b := 3) (by omega) (by omega) (by simpa using heq) · exact zmod_add_natCast_ne z (a := 1) (b := 4) (by omega) (by omega) (by simpa using heq) let pool := (S \ K).erase (z + 1) have hpool_card : pool.card = S.card - K.card - 1 := by have h1 : (S \ K).card = S.card - K.card := Finset.card_sdiff_of_subset hKsub have h2 : z + 1 ∈ S \ K := Finset.mem_sdiff.mpr ⟨hz1, hz1_nK⟩ rw [Finset.card_erase_of_mem h2, h1] obtain ⟨R, hRsub, hRcard⟩ := exists_subset_card pool (r := u - K.card) (by omega) let T := K ∪ R have hdisj : Disjoint K R := Finset.disjoint_left.mpr fun x hxK hxR => (Finset.mem_sdiff.mp (Finset.mem_erase.mp (hRsub hxR)).2).2 hxK have hTsub : T ⊆ S := Finset.union_subset hKsub (Finset.Subset.trans hRsub (Finset.Subset.trans (Finset.erase_subset _ _) Finset.sdiff_subset)) have hTcard : T.card = u := by rw [Finset.card_union_of_disjoint hdisj, hRcard]; omega have hTss : T ⊂ S := Finset.ssubset_iff_subset_ne.mpr ⟨hTsub, fun h => by rw [h] at hTcard; omega⟩ have hz0T : z ∉ T := fun h => hz0 (hTsub h) have hz1T : z + 1 ∉ T := by intro h; rcases Finset.mem_union.mp h with hK | hR · exact hz1_nK hK · exact (Finset.mem_erase.mp (hRsub hR)).1 rfl have hz2T : z + 2 ∉ T := fun h => hz2 (hTsub h) have hTnotmd : ¬ IsMinDomSet n T := fun hTmd => by rcases hTmd.1 z with h | h | h · exact hz0T h · exact hz1T h · exact hz2T h have hTnotmis : ¬ IsMISCycleSqCompl n T := fun hTm => hz1T (hTm.1 z hz0T).1 have hTne : T ≠ ∅ := by intro h; rw [h] at hTcard; simp at hTcard; omega have hTnu : T ≠ Finset.univ := fun h => hz0T (h ▸ Finset.mem_univ z) refine ⟨T, ?_, ?_⟩ · rw [binMove_sub_iff (by omega)] refine ⟨hTss, z + 2, fun j => ?_⟩ fin_cases j · simp [hz2, hz2T] · constructor · intro h; exact hTsub h · intro h exact Finset.mem_union_left R (Finset.mem_inter.mpr ⟨h, by have : z + 2 + 1 = z + 3 := by ring simp [this]⟩) · constructor · intro h; exact hTsub h · intro h exact Finset.mem_union_left R (Finset.mem_inter.mpr ⟨h, by have : z + 2 + (2 : ZMod n) = z + 4 := by ring simp [this]⟩) · simp [grundySubThreeFormula, hTne, hTnu, hTnotmd, hTnotmis, hTcard] · -- Case 4: No 00, no 010, and ¬ IsMISCycleSqCompl S => S has 11111! have hind : IsIndepCycleSqCompl n S := by intro z hz; push Not at h00 h010 have hz1 := h00 z hz; exact ⟨hz1, h010 z hz hz1⟩ have h5 : ∃ a : ZMod n, a ∈ S ∧ a + 1 ∈ S ∧ a + 2 ∈ S ∧ a + 3 ∈ S ∧ a + 4 ∈ S := by by_contra hno5; push Not at hno5 exact hSmis ⟨hind, fun a h => hno5 a h.1 h.2.1 h.2.2.1 h.2.2.2.1 h.2.2.2.2⟩ obtain ⟨z, hz0, hzm1, hzm2, hzm3, hzm4, _⟩ := exists_five_ones_before_zero hSnu h5 have hzp := hind z hz0 by_cases hu_top : u = S.card - 1 · -- Subcase 4b (u = S.card - 1): drop z - 1! Leaves 00 at {z-1, z} and 111 at {z-4, z-3, z-2}! let T := S.erase (z - 1) have hTss : T ⊂ S := Finset.erase_ssubset hzm1 have hTcard : T.card = u := by rw [Finset.card_erase_of_mem hzm1, hu_top] have hz0T : z ∉ T := fun h => hz0 (Finset.mem_of_mem_erase h) have hzm1T : z - 1 ∉ T := Finset.notMem_erase _ _ have hzm2T : z - 2 ∈ T := Finset.mem_erase.mpr ⟨by intro h have := zmod_add_natCast_ne (z - 2) (a := 0) (b := 1) (by omega) (by omega) apply this; linear_combination h, hzm2⟩ have hzm3T : z - 3 ∈ T := Finset.mem_erase.mpr ⟨by intro h have := zmod_add_natCast_ne (z - 3) (a := 0) (b := 2) (by omega) (by omega) apply this; linear_combination h, hzm3⟩ have hzm4T : z - 4 ∈ T := Finset.mem_erase.mpr ⟨by intro h have := zmod_add_natCast_ne (z - 4) (a := 0) (b := 3) (by omega) (by omega) apply this; linear_combination h, hzm4⟩ have hTnotmd : ¬ IsMinDomSet n T := fun hTmd => isMinDomSet_no_three_ones (by omega) hTmd (z - 4) ⟨hzm4T, by convert hzm3T using 1; ring, by convert hzm2T using 1; ring⟩ have hTnotmis : ¬ IsMISCycleSqCompl n T := fun hTm => by have := (hTm.1 (z - 1) hzm1T).1 simp only [sub_add_cancel] at this; exact hz0T this have hTne : T ≠ ∅ := by intro h; rw [h] at hTcard; simp at hTcard; omega have hTnu : T ≠ Finset.univ := fun h => hz0T (h ▸ Finset.mem_univ z) refine ⟨T, ?_, ?_⟩ · rw [binMove_sub_iff (by omega)] refine ⟨hTss, z, fun j => ?_⟩ fin_cases j · simp [hz0, hz0T] · have hne : z + 1 ≠ z - 1 := by simpa using (zmod_add_sub_natCast_ne z (a := 1) (b := 1) (by omega) (by omega)).symm simp [T, hne] · have hne : z + 2 ≠ z - 1 := by simpa using (zmod_add_sub_natCast_ne z (a := 1) (b := 2) (by omega) (by omega)).symm simp [T, hne] · simp [grundySubThreeFormula, hTne, hTnu, hTnotmd, hTnotmis, hTcard] · -- Subcase 4a (2 ≤ u ≤ S.card - 2): keep {z, z+1, z+2} untouched, drop z-1 AND z-2! have hu_le : u ≤ S.card - 2 := by omega have hdisj_p : z + 1 ≠ z + 2 := by simpa using zmod_add_natCast_ne z (a := 1) (b := 2) (by omega) (by omega) have hne_m1_p1 : z - 1 ≠ z + 1 := by simpa using zmod_add_sub_natCast_ne z (a := 1) (b := 1) (by omega) (by omega) have hne_m1_p2 : z - 1 ≠ z + 2 := by simpa using zmod_add_sub_natCast_ne z (a := 1) (b := 2) (by omega) (by omega) have hne_m2_p1 : z - 2 ≠ z + 1 := by simpa using zmod_add_sub_natCast_ne z (a := 2) (b := 1) (by omega) (by omega) have hne_m2_p2 : z - 2 ≠ z + 2 := by simpa using zmod_add_sub_natCast_ne z (a := 2) (b := 2) (by omega) (by omega) have hne_m2_m1 : z - 2 ≠ z - 1 := by intro h; apply zmod_add_natCast_ne (z - 2) (a := 0) (b := 1) (by omega) (by omega) linear_combination h let pool := (((S.erase (z + 1)).erase (z + 2)).erase (z - 1)).erase (z - 2) have hpool_card : pool.card = S.card - 4 := by have c1 := Finset.card_erase_of_mem hzp.1 have m2 : z + 2 ∈ S.erase (z + 1) := Finset.mem_erase.mpr ⟨hdisj_p.symm, hzp.2⟩ have c2 := Finset.card_erase_of_mem m2 have m3 : z - 1 ∈ (S.erase (z + 1)).erase (z + 2) := Finset.mem_erase.mpr ⟨hne_m1_p2, Finset.mem_erase.mpr ⟨hne_m1_p1, hzm1⟩⟩ have c3 := Finset.card_erase_of_mem m3 have m4 : z - 2 ∈ ((S.erase (z + 1)).erase (z + 2)).erase (z - 1) := Finset.mem_erase.mpr ⟨hne_m2_m1, Finset.mem_erase.mpr ⟨hne_m2_p2, Finset.mem_erase.mpr ⟨hne_m2_p1, hzm2⟩⟩⟩ have c4 := Finset.card_erase_of_mem m4 dsimp only [pool]; omega obtain ⟨R, hRsub, hRcard⟩ := exists_subset_card pool (r := u - 2) (by omega) let T := insert (z + 1) (insert (z + 2) R) have hp2_nR : z + 2 ∉ R := fun h => (Finset.mem_erase.mp (Finset.mem_erase.mp (Finset.mem_erase.mp (hRsub h)).2).2).1 rfl have hp1_nR : z + 1 ∉ R := fun h => (Finset.mem_erase.mp (Finset.mem_erase.mp (Finset.mem_erase.mp (Finset.mem_erase.mp (hRsub h)).2).2).2).1 rfl have hTsub : T ⊆ S := by intro x hx; simp only [T, Finset.mem_insert] at hx rcases hx with rfl | rfl | hxR · exact hzp.1 · exact hzp.2 · exact Finset.mem_of_mem_erase (Finset.mem_of_mem_erase (Finset.mem_of_mem_erase (Finset.mem_of_mem_erase (hRsub hxR)))) have hTcard : T.card = u := by rw [Finset.card_insert_of_notMem (by simp [hdisj_p, hp1_nR]), Finset.card_insert_of_notMem hp2_nR, hRcard]; omega have hTss : T ⊂ S := Finset.ssubset_iff_subset_ne.mpr ⟨hTsub, fun h => by rw [h] at hTcard; omega⟩ have hz0T : z ∉ T := fun h => hz0 (hTsub h) have hzm1T : z - 1 ∉ T := by simp only [T, Finset.mem_insert, not_or] exact ⟨hne_m1_p1, hne_m1_p2, fun h => (Finset.mem_erase.mp (Finset.mem_erase.mp (hRsub h)).2).1 rfl⟩ have hzm2T : z - 2 ∉ T := by simp only [T, Finset.mem_insert, not_or] exact ⟨hne_m2_p1, hne_m2_p2, fun h => (Finset.mem_erase.mp (hRsub h)).1 rfl⟩ have hTnotmd : ¬ IsMinDomSet n T := fun hTmd => by rcases hTmd.1 (z - 2) with h | h | h · exact hzm2T h · exact hzm1T (by convert h using 1; ring) · exact hz0T (by convert h using 1; ring) have hTnotmis : ¬ IsMISCycleSqCompl n T := fun hTm => hzm1T (by convert (hTm.1 (z - 2) hzm2T).1 using 1; ring) have hTne : T ≠ ∅ := by intro h; rw [h] at hTcard; simp at hTcard; omega have hTnu : T ≠ Finset.univ := fun h => hz0T (h ▸ Finset.mem_univ z) refine ⟨T, ?_, ?_⟩ · rw [binMove_sub_iff (by omega)] refine ⟨hTss, z, fun j => ?_⟩ fin_cases j · simp [hz0, hz0T] · simp [hzp.1, T] · simp [hzp.2, T] · simp [grundySubThreeFormula, hTne, hTnu, hTnotmd, hTnotmis, hTcard] · -- Case 1: S already has 000 at {z, z+1, z+2}: keep any u elements! simp only [IsDomSet, not_forall, not_or] at hdom obtain ⟨z, hz0, hz1, hz2⟩ := hdom obtain ⟨T, hTS, hTcard⟩ := exists_subset_card S (r := u) (by omega) have hTss : T ⊂ S := Finset.ssubset_iff_subset_ne.mpr ⟨hTS, fun h => by rw [h] at hTcard; omega⟩ have hz0T : z ∉ T := fun h => hz0 (hTS h) have hz1T : z + 1 ∉ T := fun h => hz1 (hTS h) have hz2T : z + 2 ∉ T := fun h => hz2 (hTS h) have hTnotmd : ¬ IsMinDomSet n T := fun hTmd => by rcases hTmd.1 z with h | h | h · exact hz0T h · exact hz1T h · exact hz2T h have hTnotmis : ¬ IsMISCycleSqCompl n T := fun hTm => hz1T (hTm.1 z hz0T).1 have hTne : T ≠ ∅ := by intro h; rw [h] at hTcard; simp at hTcard; omega have hTnu : T ≠ Finset.univ := fun h => hz0T (h ▸ Finset.mem_univ z) refine ⟨T, ?_, ?_⟩ · rw [binMove_sub_iff (by omega)] refine ⟨hTss, z, fun j => ?_⟩ fin_cases j <;> simp [hz0, hz1, hz2, hz0T, hz1T, hz2T] · simp [grundySubThreeFormula, hTne, hTnu, hTnotmd, hTnotmis, hTcard] /-- **Corollary 4A (Exact Normal $\mathcal{P}$-position Classification of Binary $\mathrm{CN}(n, n-3)$)**: For all $n \ge 7$, a binary state $\mathbf{1}_S$ is a normal $\mathcal{P}$-position of $\mathrm{CN}(n, n - 3)$ iff $S = \emptyset$, $S = \mathrm{univ}$, or $S$ is a minimal dominating set of $C_n$ (OEIS A253413). -/ theorem isNormalP_sub_three_iff {n : ℕ} [NeZero n] (hn : 7 ≤ n) (S : Finset (ZMod n)) : IsNormalP n (n - 3) (embedBin S) ↔ S = ∅ ∨ S = Finset.univ ∨ IsMinDomSet n S := by rw [← grundy_eq_zero_iff_isNormalP, grundy_sub_three_exact hn] dsimp only [grundySubThreeFormula] split_ifs with h0 hmis · simp [h0] · simp [h0] · push Not at h0 have hpos := Finset.card_pos.mpr h0.1 constructor · intro hc; omega · rintro (h | h | h) · exact absurd h (Finset.nonempty_iff_ne_empty.mp h0.1) · exact absurd h h0.2.1 · exact absurd h h0.2.2 /-- **THEOREM 5 (Exact Misère $\mathcal{P}^-$-position Classification of Binary $\mathrm{CN}^-(n, n-3)$)**: For every $n \ge 7$, a binary state $\mathbf{1}_S$ is a misère $\mathcal{P}^-$-position of $\mathrm{CN}^-(n, n - 3)$ **if and only if** $|S| = 1$ or $S^c \in \mathrm{MIS}(C_n^2)$. -/ theorem isMisereP_sub_three_iff {n : ℕ} [NeZero n] (hn : 7 ≤ n) (S : Finset (ZMod n)) : IsMisereP n (n - 3) (embedBin S) ↔ S.card = 1 ∨ IsMISCycleSqCompl n S := by apply isMisereP_embedBin_eq_of_spec (fun S => S.card = 1 ∨ IsMISCycleSqCompl n S) · -- Nonterminal intro S hS rcases hS with hc1 | hmis · obtain ⟨a, rfl⟩ := Finset.card_eq_one.mp hc1 refine ⟨∅, ?_⟩ rw [binMove_sub_iff (by omega)] refine ⟨Finset.empty_ssubset.mpr (Finset.singleton_nonempty a), a + 1, fun j => ?_⟩ fin_cases j · have hne : a + 1 ≠ a := by simpa using (zmod_add_natCast_ne a (a := 0) (b := 1) (by omega) (by omega)).symm simp [hne] · have hne : a + 1 + 1 ≠ a := by have : a + 1 + 1 = a + (2 : ZMod n) := by ring rw [this]; simpa using (zmod_add_natCast_ne a (a := 0) (b := 2) (by omega) (by omega)).symm simp [hne] · have hne : a + 1 + (2 : ZMod n) ≠ a := by have : a + 1 + (2 : ZMod n) = a + (3 : ZMod n) := by ring rw [this]; simpa using (zmod_add_natCast_ne a (a := 0) (b := 3) (by omega) (by omega)).symm simp [hne] · obtain ⟨T, hbm, _⟩ := exists_binMove_to_minDom_of_indep hn hmis.1 (isMISCycleSqCompl_not_univ hmis) exact ⟨T, hbm⟩ · -- Closed intro S hS T hbm hT rw [binMove_sub_iff (by omega)] at hbm obtain ⟨hsub, s, hunt⟩ := hbm rcases hS with hc1 | hSmis · have hTlt := Finset.card_lt_card hsub rcases hT with hT1 | hTmis · omega · have := isMISCycleSqCompl_card_ge_two (by omega) hTmis; omega · rcases hT with hT1 | hTmis · rcases isIndepCycleSqCompl_two_in_arc (by omega) hSmis.1 s with ⟨h0, h1⟩ | ⟨h0, h2⟩ | ⟨h1, h2⟩ · have h0T : s ∈ T := by simpa using (hunt ⟨0, by omega⟩).mpr (by simpa using h0) have h1T : s + 1 ∈ T := by simpa using (hunt ⟨1, by omega⟩).mpr (by simpa using h1) have hne : s ≠ s + 1 := by simpa using zmod_add_natCast_ne s (a := 0) (b := 1) (by omega) (by omega) have : ({s, s + 1} : Finset (ZMod n)).card ≤ T.card := Finset.card_le_card (by intro x hx; simp only [Finset.mem_insert, Finset.mem_singleton] at hx rcases hx with rfl | rfl <;> assumption) rw [Finset.card_pair hne] at this; omega · have h0T : s ∈ T := by simpa using (hunt ⟨0, by omega⟩).mpr (by simpa using h0) have h2T : s + 2 ∈ T := by simpa using (hunt ⟨2, by omega⟩).mpr (by simpa using h2) have hne : s ≠ s + 2 := by simpa using zmod_add_natCast_ne s (a := 0) (b := 2) (by omega) (by omega) have : ({s, s + 2} : Finset (ZMod n)).card ≤ T.card := Finset.card_le_card (by intro x hx; simp only [Finset.mem_insert, Finset.mem_singleton] at hx rcases hx with rfl | rfl <;> assumption) rw [Finset.card_pair hne] at this; omega · have h1T : s + 1 ∈ T := by simpa using (hunt ⟨1, by omega⟩).mpr (by simpa using h1) have h2T : s + 2 ∈ T := by simpa using (hunt ⟨2, by omega⟩).mpr (by simpa using h2) have hne : s + 1 ≠ s + 2 := by simpa using zmod_add_natCast_ne s (a := 1) (b := 2) (by omega) (by omega) have : ({s + 1, s + 2} : Finset (ZMod n)).card ≤ T.card := Finset.card_le_card (by intro x hx; simp only [Finset.mem_insert, Finset.mem_singleton] at hx rcases hx with rfl | rfl <;> assumption) rw [Finset.card_pair hne] at this; omega · exact isMISCycleSqCompl_not_indep_of_ssubset (by omega) hSmis hsub hTmis.1 · -- Escape: every nonempty S with |S| ≠ 1 and ¬ IsMISCycleSqCompl S can reach a singleton or IsMISCycleSqCompl! intro S hnotP ⟨T₀, hbm₀⟩ push Not at hnotP obtain ⟨hne1, hnotmis⟩ := hnotP have hSne : S.Nonempty := by rw [Finset.nonempty_iff_ne_empty]; intro h0; subst h0 exact Finset.not_ssubset_empty T₀ hbm₀.1 have hSge2 : 2 ≤ S.card := by have := Finset.card_pos.mpr hSne; omega by_cases h00 : ∃ z : ZMod n, z ∉ S ∧ z + 1 ∉ S · obtain ⟨z, hz0, hz1, hz2⟩ := exists_zero_zero_one hSne h00 have hss : ({z + 2} : Finset (ZMod n)) ⊂ S := by rw [Finset.ssubset_iff_subset_ne] refine ⟨Finset.singleton_subset_iff.mpr hz2, fun h => ?_⟩ rw [← h] at hSge2; simp at hSge2 refine ⟨{z + 2}, ?_, Or.inl (Finset.card_singleton _)⟩ rw [binMove_sub_iff (by omega)] refine ⟨hss, z, fun j => ?_⟩ fin_cases j · have hne : z ≠ z + 2 := by simpa using zmod_add_natCast_ne z (a := 0) (b := 2) (by omega) (by omega) simp [hz0, hne] · have hne : z + 1 ≠ z + 2 := by simpa using zmod_add_natCast_ne z (a := 1) (b := 2) (by omega) (by omega) simp [hz1, hne] · simp [hz2] · by_cases h010 : ∃ z : ZMod n, z ∉ S ∧ z + 1 ∈ S ∧ z + 2 ∉ S · obtain ⟨z, hz0, hz1, hz2⟩ := h010 have hss : ({z + 1} : Finset (ZMod n)) ⊂ S := by rw [Finset.ssubset_iff_subset_ne] refine ⟨Finset.singleton_subset_iff.mpr hz1, fun h => ?_⟩ rw [← h] at hSge2; simp at hSge2 refine ⟨{z + 1}, ?_, Or.inl (Finset.card_singleton _)⟩ rw [binMove_sub_iff (by omega)] refine ⟨hss, z, fun j => ?_⟩ fin_cases j · have hne : z ≠ z + 1 := by simpa using zmod_add_natCast_ne z (a := 0) (b := 1) (by omega) (by omega) simp [hz0, hne] · simp [hz1] · have hne : z + 2 ≠ z + 1 := by simpa using (zmod_add_natCast_ne z (a := 1) (b := 2) (by omega) (by omega)).symm simp [hz2, hne] · -- No 00 and no 010 => IsIndepCycleSqCompl S! have hind : IsIndepCycleSqCompl n S := by intro z hz; push Not at h00 h010 have hz1 := h00 z hz; exact ⟨hz1, h010 z hz hz1⟩ by_cases hSu : S = Finset.univ · -- S = univ (n >= 7): put zeros at {3, -1} (distance 4 mod n, valid for n >= 7!) and minimize! subst hSu let A₀ : Finset (ZMod n) := (Finset.univ.erase (3 : ZMod n)).erase (-1 : ZMod n) have hA₀ind : IsIndepCycleSqCompl n A₀ := by intro i hi have hi_cases : i = (3 : ZMod n) ∨ i = (-1 : ZMod n) := by by_contra h; push Not at h exact hi (Finset.mem_erase.mpr ⟨h.2, Finset.mem_erase.mpr ⟨h.1, Finset.mem_univ _⟩⟩) rcases hi_cases with rfl | rfl · refine ⟨Finset.mem_erase.mpr ⟨?_, Finset.mem_erase.mpr ⟨?_, Finset.mem_univ _⟩⟩, Finset.mem_erase.mpr ⟨?_, Finset.mem_erase.mpr ⟨?_, Finset.mem_univ _⟩⟩⟩ · intro h; apply zmod_natCast_ne_zero (n := n) (a := 5) (by omega) (by omega) have : (3 : ZMod n) + 1 + 1 = ((5 : ℕ) : ZMod n) := by norm_num rw [← this, h]; ring · intro h; apply zmod_natCast_ne_zero (n := n) (a := 1) (by omega) (by omega) linear_combination h · intro h; apply zmod_natCast_ne_zero (n := n) (a := 6) (by omega) (by omega) have : (3 : ZMod n) + 2 + 1 = ((6 : ℕ) : ZMod n) := by norm_num rw [← this, h]; ring · intro h; apply zmod_natCast_ne_zero (n := n) (a := 2) (by omega) (by omega) linear_combination h · refine ⟨Finset.mem_erase.mpr ⟨?_, Finset.mem_erase.mpr ⟨?_, Finset.mem_univ _⟩⟩, Finset.mem_erase.mpr ⟨?_, Finset.mem_erase.mpr ⟨?_, Finset.mem_univ _⟩⟩⟩ · intro h; apply zmod_natCast_ne_zero (n := n) (a := 1) (by omega) (by omega) have : ((1 : ℕ) : ZMod n) = 1 := by norm_num rw [this]; linear_combination h · intro h; apply zmod_natCast_ne_zero (n := n) (a := 3) (by omega) (by omega) have : ((3 : ℕ) : ZMod n) = 3 := by norm_num rw [this]; linear_combination -h · intro h; apply zmod_natCast_ne_zero (n := n) (a := 2) (by omega) (by omega) have : ((2 : ℕ) : ZMod n) = 2 := by norm_num rw [this]; linear_combination h · intro h; apply zmod_natCast_ne_zero (n := n) (a := 2) (by omega) (by omega) have : ((2 : ℕ) : ZMod n) = 2 := by norm_num rw [this]; linear_combination -h obtain ⟨T, hTA, hTmis⟩ := exists_isMISCycleSqCompl_subset (by omega) hA₀ind have hm1T : (-1 : ZMod n) ∉ T := fun h => by have := hTA h; simp [A₀] at this have h3T : (3 : ZMod n) ∉ T := fun h => by have := hTA h; simp [A₀] at this have h0T : (0 : ZMod n) ∈ T := by simpa using (hTmis.1 (-1) hm1T).1 have h1T : (1 : ZMod n) ∈ T := by have := (hTmis.1 (-1) hm1T).2 convert this using 1; ring have h2T : (2 : ZMod n) ∈ T := by have := (isIndepCycleSqCompl_prev hTmis.1 h3T).1 convert this using 1; norm_num refine ⟨T, ?_, Or.inr hTmis⟩ rw [binMove_sub_iff (by omega)] refine ⟨Finset.ssubset_univ_iff.mpr (isMISCycleSqCompl_not_univ hTmis), 0, fun j => ?_⟩ fin_cases j · simp [h0T] · simp [h1T] · simp [h2T] · -- S ≠ univ: pick z ∉ S and extend Z(S) to IsMISCycleSqCompl T ⊂ S leaving {z, z+1, z+2} untouched! obtain ⟨T, hTS, hTmis⟩ := exists_isMISCycleSqCompl_subset (by omega) hind have hTss : T ⊂ S := Finset.ssubset_iff_subset_ne.mpr ⟨hTS, fun h => hnotmis (h ▸ hTmis)⟩ have hz_ex : ∃ z : ZMod n, z ∉ S := by by_contra h; push Not at h; exact hSu (Finset.eq_univ_iff_forall.mpr h) obtain ⟨z, hzS⟩ := hz_ex have hzT : z ∉ T := fun h => hzS (hTS h) have hzpT := hTmis.1 z hzT refine ⟨T, ?_, Or.inr hTmis⟩ rw [binMove_sub_iff (by omega)] refine ⟨hTss, z, fun j => ?_⟩ fin_cases j · simp [hzS, hzT] · simp [hzpT.1, hTS hzpT.1] · simp [hzpT.2, hTS hzpT.2] /-- **THEOREM 6 (Exact Normal $\mathcal{G}=1$ / Misère $\mathcal{P}^-$ Duality for $\mathrm{CN}(n, n-3)$)**: For every $n \ge 7$ and every binary state $S \subseteq \mathbb{Z}/n\mathbb{Z}$, $$\mathcal{G}_{\mathrm{CN}(n, n-3)}(\mathbf{1}_S) = 1 \iff \mathrm{IsMisereP}(n, n-3, \mathbf{1}_S).$$ -/ theorem normal_grundy_one_iff_misereP_sub_three {n : ℕ} [NeZero n] (hn : 7 ≤ n) (S : Finset (ZMod n)) : grundy n (n - 3) (embedBin S) = 1 ↔ IsMisereP n (n - 3) (embedBin S) := by rw [grundy_sub_three_exact hn, isMisereP_sub_three_iff hn] dsimp only [grundySubThreeFormula] split_ifs with h0 hmis · constructor · intro h; exact h.elim · rintro (hc1 | hm) · rcases h0 with rfl | rfl | hmd · simp at hc1 · rw [Finset.card_univ, ZMod.card] at hc1; omega · obtain ⟨a, rfl⟩ := Finset.card_eq_one.mp hc1 rcases hmd.1 (a + 1) with h | h | h <;> simp only [Finset.mem_singleton] at h · exact zmod_add_natCast_ne a (a := 0) (b := 1) (by omega) (by omega) (by simpa using h.symm) · exact zmod_add_natCast_ne a (a := 0) (b := 2) (by omega) (by omega) (by convert h.symm using 1 <;> (push_cast; ring)) · exact zmod_add_natCast_ne a (a := 0) (b := 3) (by omega) (by omega) (by convert h.symm using 1 <;> (push_cast; ring)) · rcases h0 with rfl | rfl | hmd · have := isMISCycleSqCompl_card_ge_two (by omega) hm; simp at this · exact isMISCycleSqCompl_not_univ hm rfl · exact isMISCycleSqCompl_disjoint_minDom (by omega) hm hmd · simp [hmis] · constructor · intro hc1; exact Or.inl hc1 · rintro (hc1 | hm) · exact hc1 · exact absurd hm hmis /-- **Sharpness of $n \ge 7$ for $d = 3$**: In $\mathrm{CN}(6, 3)$, the antipodal state $S = \{1, 2, 4, 5\} \subset \mathbb{Z}/6\mathbb{Z}$ (`011011`) is a normal $\mathcal{P}$-position that is neither $\emptyset$, nor $\mathrm{univ}$, nor a minimal dominating set of $C_6$. -/ theorem six_three_exception : let S : Finset (ZMod 6) := {1, 2, 4, 5} IsNormalP 6 3 (embedBin S) ∧ S ≠ ∅ ∧ S ≠ Finset.univ ∧ ¬ IsMinDomSet 6 S := by let S : Finset (ZMod 6) := {1, 2, 4, 5} have hmem : ∀ x : ZMod 6, x ∈ S ↔ x.val = 1 ∨ x.val = 2 ∨ x.val = 4 ∨ x.val = 5 := by intro x simp only [S, Finset.mem_insert, Finset.mem_singleton] constructor · rintro (rfl | rfl | rfl | rfl) · left; rfl · right; left; rfl · right; right; left; rfl · right; right; right; rfl · rintro (h | h | h | h) · left; exact ZMod.val_injective 6 h · right; left; exact ZMod.val_injective 6 h · right; right; left; exact ZMod.val_injective 6 h · right; right; right; exact ZMod.val_injective 6 h have hne1 : ∀ x : ZMod 6, x.val ≠ 1 → x ≠ 1 := fun x hx h => hx (by rw [h]; rfl) refine ⟨?_, ?_, ?_, ?_⟩ · -- Antipodal symmetry in CN(6, 3) (m = 3, k = 3) apply isNormalP_antipodal (m := 3) (k := 3) (by omega) (le_refl 3) intro i dsimp only [embedBin] have hiff : (i + 3) ∈ S ↔ i ∈ S := by rw [hmem, hmem] fin_cases i · exact iff_of_false (by change ¬ (3 = 1 ∨ 3 = 2 ∨ 3 = 4 ∨ 3 = 5); omega) (by change ¬ (0 = 1 ∨ 0 = 2 ∨ 0 = 4 ∨ 0 = 5); omega) · exact iff_of_true (Or.inr (Or.inr (Or.inl rfl))) (Or.inl rfl) · exact iff_of_true (Or.inr (Or.inr (Or.inr rfl))) (Or.inr (Or.inl rfl)) · exact iff_of_false (by change ¬ (0 = 1 ∨ 0 = 2 ∨ 0 = 4 ∨ 0 = 5); omega) (by change ¬ (3 = 1 ∨ 3 = 2 ∨ 3 = 4 ∨ 3 = 5); omega) · exact iff_of_true (Or.inl rfl) (Or.inr (Or.inr (Or.inl rfl))) · exact iff_of_true (Or.inr (Or.inl rfl)) (Or.inr (Or.inr (Or.inr rfl))) exact if_congr hiff rfl rfl · intro h have h1 : (1 : ZMod 6) ∈ S := (hmem 1).mpr (Or.inl rfl) change (1 : ZMod 6) ∈ ({1, 2, 4, 5} : Finset (ZMod 6)) at h1 rw [h] at h1 exact Finset.notMem_empty 1 h1 · intro h have h0 : (0 : ZMod 6) ∈ S := by change (0 : ZMod 6) ∈ ({1, 2, 4, 5} : Finset (ZMod 6)) rw [h]; exact Finset.mem_univ 0 have h0' := (hmem 0).mp h0 change 0 = 1 ∨ 0 = 2 ∨ 0 = 4 ∨ 0 = 5 at h0' omega · intro hmd have h1S : (1 : ZMod 6) ∈ S := (hmem 1).mpr (Or.inl rfl) apply hmd.2 1 h1S intro i fin_cases i · right; right; exact Finset.mem_erase.mpr ⟨hne1 _ (by change 2 ≠ 1; omega), (hmem _).mpr (by right; left; rfl)⟩ · right; left; exact Finset.mem_erase.mpr ⟨hne1 _ (by change 2 ≠ 1; omega), (hmem _).mpr (by right; left; rfl)⟩ · left; exact Finset.mem_erase.mpr ⟨hne1 _ (by change 2 ≠ 1; omega), (hmem _).mpr (by right; left; rfl)⟩ · right; left; exact Finset.mem_erase.mpr ⟨hne1 _ (by change 4 ≠ 1; omega), (hmem _).mpr (by right; right; left; rfl)⟩ · left; exact Finset.mem_erase.mpr ⟨hne1 _ (by change 4 ≠ 1; omega), (hmem _).mpr (by right; right; left; rfl)⟩ · left; exact Finset.mem_erase.mpr ⟨hne1 _ (by change 5 ≠ 1; omega), (hmem _).mpr (by right; right; right; rfl)⟩ /-! ### Section 7: Axiom Audits -/ #print axioms move_sub_iff_untouched_arc #print axioms move_embedBin_iff #print axioms grundy_eq_zero_iff_isNormalP #print axioms isNormalP_antipodal #print axioms isNormalP_sub_one_iff #print axioms isMisereP_sub_one_iff #print axioms isNormalP_of_isMinArcTransversal #print axioms sharp_breakdown_ge_four #print axioms grundy_sub_two_exact #print axioms isNormalP_sub_two_iff #print axioms grundy_four_two_exact #print axioms isMisereP_sub_two_iff #print axioms card_misereP_sub_two #print axioms card_minVertexCover_eq_perrin #print axioms card_normalP_sub_two_eq_one_add_perrin #print axioms grundy_sub_three_exact #print axioms isNormalP_sub_three_iff #print axioms isMisereP_sub_three_iff #print axioms normal_grundy_one_iff_misereP_sub_three #print axioms six_three_exception end CircularNim