import Mathlib.Data.ZMod.Basic import Mathlib.Data.ZMod.QuotientRing import Mathlib.Data.Fintype.BigOperators import Mathlib.Tactic /-! # Rigidity for `q ∈ {1, 2}` and the Six Finite Negative Cases Formalizes the Rigidity section of `swap-displacements.md`: 1. For any `n ≥ 2` and `0 < d < n` with `Nat.gcd n d ∈ {1, 2}`, every autocorrelation-preserving opposite-sign swap at `(0, d)` is identified by the reflection `i ↦ d - i` (in particular, for normalized `d = q ∈ {1, 2}`, by `i ↦ q - i`). 2. For each of the six finite negative parameter pairs `(q, L) ∈ {(3, 2), (3, 3), (3, 4), (3, 5), (4, 2), (5, 2)}`, every autocorrelation-preserving opposite-sign swap at `(0, q)` in `ZMod (q * L)` is dihedral+complement equivalent to the original word (pure structural proofs, zero `native_decide`). -/ namespace SwapHomometry open scoped BigOperators section Core variable {n : ℕ} [NeZero n] /-- A binary sign word takes values in `{1, -1}`. -/ def SignWord (x : ZMod n → ℤ) : Prop := ∀ i : ZMod n, x i = 1 ∨ x i = -1 /-- Periodic autocorrelation of `x` at lag `k`. -/ def corr (x : ZMod n → ℤ) (k : ZMod n) : ℤ := ∑ i : ZMod n, x i * x (i + k) /-- Swap the entries of `x` at positions `0` and `d`. -/ def swapAt (d : ZMod n) (x : ZMod n → ℤ) : ZMod n → ℤ := fun i => if i = 0 then x d else if i = d then x 0 else x i /-- Dihedral + global-negation (complement) equivalence of cyclic sign words. -/ def DihedralEquiv (x y : ZMod n → ℤ) : Prop := ∃ (rev neg : Bool) (t : ZMod n), ∀ i : ZMod n, y i = (if neg then (-1 : ℤ) else 1) * x (if rev then t - i else t + i) /-- Existence of a nontrivial homometric opposite-sign swap at displacement `d` in `ZMod n`. -/ def HasNontrivialSwap (n d : ℕ) [NeZero n] : Prop := ∃ x : ZMod n → ℤ, SignWord x ∧ x 0 = 1 ∧ x (d : ZMod n) = -1 ∧ (∀ k : ZMod n, corr x k = corr (swapAt (d : ZMod n) x) k) ∧ ¬ DihedralEquiv x (swapAt (d : ZMod n) x) /-- The opposite-sign spike `(+1 at 0, -1 at d)`. -/ def swapSpike (d : ZMod n) : ZMod n → ℤ := fun i => (if i = 0 then (1 : ℤ) else 0) + (if i = d then (-1 : ℤ) else 0) /-- The zeroed background obtained by setting positions `0` and `d` to `0`. -/ def zeroBg (d : ZMod n) (x : ZMod n → ℤ) : ZMod n → ℤ := fun i => if i = 0 ∨ i = d then 0 else x i private def cross (f g : ZMod n → ℤ) (k : ZMod n) : ℤ := ∑ i : ZMod n, (f i * g (i + k) + g i * f (i + k)) private lemma cross_spike (f : ZMod n → ℤ) (a k : ZMod n) (s : ℤ) : cross f (fun i => if i = a then s else 0) k = s * (f (a - k) + f (a + k)) := by unfold cross rw [Finset.sum_add_distrib] have h1 : (∑ i : ZMod n, f i * (if i + k = a then s else 0)) = f (a - k) * s := by rw [Finset.sum_eq_single (a - k)] · simp · intro b _ hb have hne : b + k ≠ a := by intro h; apply hb; exact eq_sub_of_add_eq h simp [hne] · simp have h2 : (∑ i : ZMod n, (if i = a then s else 0) * f (i + k)) = s * f (a + k) := by rw [Finset.sum_eq_single a] · simp · intro b _ hb; simp [hb] · simp rw [h1, h2]; ring private lemma cross_add (f g h : ZMod n → ℤ) (k : ZMod n) : cross f (fun i => g i + h i) k = cross f g k + cross f h k := by unfold cross rw [← Finset.sum_add_distrib] refine Finset.sum_congr rfl fun i _ => ?_ ring theorem swap_iff_periodic_defect (f : ZMod n → ℤ) (d : ZMod n) : (∀ k : ZMod n, corr (fun i => f i + swapSpike d i) k = corr (fun i => f i - swapSpike d i) k) ↔ (∀ i : ZMod n, f (i + d) - f (d - (i + d)) = f i - f (d - i)) := by have hdiff : ∀ k : ZMod n, corr (fun i => f i + swapSpike d i) k - corr (fun i => f i - swapSpike d i) k = 2 * cross f (swapSpike d) k := by intro k unfold corr cross rw [← Finset.sum_sub_distrib, Finset.mul_sum] refine Finset.sum_congr rfl fun i _ => ?_ ring have hcross : ∀ k : ZMod n, cross f (swapSpike d) k = f (-k) + f k - (f (d - k) + f (d + k)) := by intro k change cross f (fun i => (if i = 0 then (1 : ℤ) else 0) + (if i = d then (-1 : ℤ) else 0)) k = _ rw [cross_add, cross_spike, cross_spike] simp only [zero_sub, zero_add] ring constructor · intro h i have hi := hdiff i rw [h i, sub_self, hcross i] at hi have h1 : d - (i + d) = -i := by ring have h2 : d + i = i + d := add_comm d i rw [h1]; rw [h2] at hi; omega · intro h k have hk := hdiff k rw [hcross k] at hk have hv := h k have h1 : d - (k + d) = -k := by ring have h2 : d + k = k + d := add_comm d k rw [h1] at hv; rw [h2] at hk; omega theorem swapAt_iff_periodic_defect (x : ZMod n → ℤ) (d : ZMod n) (hd : d ≠ 0) (hx0 : x 0 = 1) (hxd : x d = -1) : (∀ k : ZMod n, corr x k = corr (swapAt d x) k) ↔ (∀ i : ZMod n, zeroBg d x (i + d) - zeroBg d x (d - (i + d)) = zeroBg d x i - zeroBg d x (d - i)) := by have hx : x = fun i => zeroBg d x i + swapSpike d i := by funext i unfold zeroBg swapSpike by_cases h0 : i = 0 · subst h0; simp [hd.symm, hx0] · by_cases h1 : i = d · subst h1; simp [h0, hxd] · simp [h0, h1] have hy : swapAt d x = fun i => zeroBg d x i - swapSpike d i := by funext i unfold swapAt zeroBg swapSpike by_cases h0 : i = 0 · subst h0; simp [hd.symm, hxd] · by_cases h1 : i = d · subst h1; simp [h0, hx0] · simp [h0, h1] have h := swap_iff_periodic_defect (zeroBg d x) d rwa [← hx, ← hy] at h private lemma periodic_iff_const_on_gcd_fibers {d : ℕ} (D : ZMod n → ℤ) : (∀ i : ZMod n, D (i + (d : ZMod n)) = D i) ↔ (∀ i j : ZMod n, ZMod.castHom (Nat.gcd_dvd_left n d) (ZMod (Nat.gcd n d)) i = ZMod.castHom (Nat.gcd_dvd_left n d) (ZMod (Nat.gcd n d)) j → D i = D j) := by set q := Nat.gcd n d set π : ZMod n →+* ZMod q := ZMod.castHom (Nat.gcd_dvd_left n d) (ZMod q) have hπd : π (d : ZMod n) = 0 := by rw [map_natCast, ZMod.natCast_eq_zero_iff] exact Nat.gcd_dvd_right n d constructor · intro hper have hnat : ∀ (k : ℕ) (i : ZMod n), D (i + (k : ZMod n) * (d : ZMod n)) = D i := by intro k induction k with | zero => intro i; simp | succ k ih => intro i have heq : i + ((k + 1 : ℕ) : ZMod n) * (d : ZMod n) = (i + (k : ZMod n) * (d : ZMod n)) + (d : ZMod n) := by push_cast; ring rw [heq, hper, ih] have hint : ∀ (k : ℤ) (i : ZMod n), D (i + (k : ZMod n) * (d : ZMod n)) = D i := by intro k i cases k with | ofNat m => simpa using hnat m i | negSucc m => have h := hnat (m + 1) (i + (Int.negSucc m : ZMod n) * (d : ZMod n)) have heq : i + (Int.negSucc m : ZMod n) * (d : ZMod n) + ((m + 1 : ℕ) : ZMod n) * (d : ZMod n) = i := by push_cast [Int.negSucc_eq]; ring rw [heq] at h; exact h.symm have hq_eq : (q : ZMod n) = (Nat.gcdB n d : ZMod n) * (d : ZMod n) := by have hbez : (q : ℤ) = (n : ℤ) * Nat.gcdA n d + (d : ℤ) * Nat.gcdB n d := Nat.gcd_eq_gcd_ab n d have hbez' := congrArg (Int.cast : ℤ → ZMod n) hbez simp only [Int.cast_natCast, Int.cast_add, Int.cast_mul, ZMod.natCast_self, zero_mul, zero_add] at hbez' rw [mul_comm] at hbez' exact hbez' have hqper : ∀ (m : ℕ) (i : ZMod n), D (i + (m : ZMod n) * (q : ZMod n)) = D i := by intro m i rw [hq_eq, ← mul_assoc] simpa using hint ((m : ℤ) * Nat.gcdB n d) i intro i j hij have hsub : π (j - i) = 0 := by rw [map_sub, hij, sub_self] have hdvd : q ∣ (j - i).val := by rw [← ZMod.natCast_eq_zero_iff (a := (j - i).val) (b := q)] have hcast : (((j - i).val : ℕ) : ZMod q) = π (j - i) := by rw [← map_natCast π, ZMod.natCast_zmod_val] rw [hcast, hsub] rcases hdvd with ⟨m, hm⟩ have hj : j = i + (m : ZMod n) * (q : ZMod n) := by have hval : j - i = ((j - i).val : ZMod n) := (ZMod.natCast_zmod_val (j - i)).symm rw [hm, Nat.cast_mul, mul_comm] at hval exact eq_add_of_sub_eq' hval rw [hj, hqper] · intro hconst i apply hconst rw [map_add, hπd, add_zero] end Core section SmallGcdRigidity private lemma zmod_eq_neg_of_le_two {q : ℕ} (hq : q = 1 ∨ q = 2) (r : ZMod q) : r = -r := by rcases hq with rfl | rfl · exact Subsingleton.elim r (-r) · fin_cases r <;> rfl /-- Rigidity for `q = 1` and `q = 2`: if `Nat.gcd n d ∈ {1, 2}` and `0 < d < n`, every autocorrelation-preserving opposite-sign swap at `(0, d)` is identified by the reflection `i ↦ d - i`. -/ theorem rigid_reflection_of_gcd_le_two (n d : ℕ) [NeZero n] (hd0 : 0 < d) (hdn : d < n) (hq : Nat.gcd n d = 1 ∨ Nat.gcd n d = 2) (x : ZMod n → ℤ) (hx0 : x 0 = 1) (hxd : x (d : ZMod n) = -1) (hcorr : ∀ k : ZMod n, corr x k = corr (swapAt (d : ZMod n) x) k) : ∀ i : ZMod n, swapAt (d : ZMod n) x i = x ((d : ZMod n) - i) := by set dZ : ZMod n := (d : ZMod n) have hdZ : dZ ≠ 0 := by intro h0; rw [ZMod.natCast_eq_zero_iff] at h0 have := Nat.le_of_dvd hd0 h0; omega have hper := (swapAt_iff_periodic_defect x dZ hdZ hx0 hxd).mp hcorr have hconst := (periodic_iff_const_on_gcd_fibers (d := d) (fun i => zeroBg dZ x i - zeroBg dZ x (dZ - i))).mp hper set q := Nat.gcd n d set π : ZMod n →+* ZMod q := ZMod.castHom (Nat.gcd_dvd_left n d) (ZMod q) have hπd : π dZ = 0 := by rw [map_natCast, ZMod.natCast_eq_zero_iff] exact Nat.gcd_dvd_right n d have hself : ∀ r : ZMod q, r = -r := zmod_eq_neg_of_le_two hq have hbg_eq : ∀ i : ZMod n, zeroBg dZ x i = zeroBg dZ x (dZ - i) := by intro i have hπeq : π i = π (dZ - i) := by rw [map_sub, hπd, zero_sub] exact hself (π i) have hD := hconst i (dZ - i) hπeq rw [sub_sub_cancel] at hD omega intro i by_cases h0 : i = 0 · subst h0; simp [swapAt] · by_cases hd : i = dZ · subst hd; simp [swapAt, hdZ] · have hdi0 : dZ - i ≠ 0 := by intro h; exact hd (sub_eq_zero.mp h).symm have hdid : dZ - i ≠ dZ := by intro h; exact h0 (sub_eq_self.mp h) have hbg := hbg_eq i simp only [zeroBg, h0, hd, hdi0, hdid, or_self, ↓reduceIte] at hbg simp only [swapAt, h0, hd, ↓reduceIte] exact hbg /-- Rigidity for normalized `d = q ∈ {1, 2}`: every autocorrelation-preserving swap is identified by reflection `i ↦ q - i`. -/ theorem rigid_reflection_q1_q2 (n q : ℕ) [NeZero n] (hq : q = 1 ∨ q = 2) (hqn : q ∣ n) (hqlt : q < n) (x : ZMod n → ℤ) (hx0 : x 0 = 1) (hxq : x (q : ZMod n) = -1) (hcorr : ∀ k : ZMod n, corr x k = corr (swapAt (q : ZMod n) x) k) : ∀ i : ZMod n, swapAt (q : ZMod n) x i = x ((q : ZMod n) - i) := by have hqpos : 0 < q := by omega have hgcd : Nat.gcd n q = q := Nat.gcd_eq_right hqn exact rigid_reflection_of_gcd_le_two n q hqpos hqlt (by rwa [hgcd]) x hx0 hxq hcorr /-- No nontrivial opposite-sign swap exists when `Nat.gcd n d ∈ {1, 2}`. -/ theorem not_hasNontrivialSwap_of_gcd_le_two (n d : ℕ) [NeZero n] (hd0 : 0 < d) (hdn : d < n) (hq : Nat.gcd n d = 1 ∨ Nat.gcd n d = 2) : ¬ HasNontrivialSwap n d := by rintro ⟨x, _, hx0, hxd, hcorr, hneq⟩ apply hneq refine ⟨true, false, (d : ZMod n), ?_⟩ intro i simpa using rigid_reflection_of_gcd_le_two n d hd0 hdn hq x hx0 hxd hcorr i end SmallGcdRigidity section FiniteNegativeCases /-- Helper: if `a, b, c, d ∈ {1, -1}`, `a ≠ b`, and `c - d = a - b`, then `c = a ∧ d = b`. -/ private lemma sign_diff_eq {a b c d : ℤ} (ha : a = 1 ∨ a = -1) (hb : b = 1 ∨ b = -1) (hc : c = 1 ∨ c = -1) (hd : d = 1 ∨ d = -1) (hne : a ≠ b) (heq : c - d = a - b) : c = a ∧ d = b := by rcases ha with rfl | rfl <;> rcases hb with rfl | rfl <;> rcases hc with rfl | rfl <;> rcases hd with rfl | rfl <;> omega /-- Case `(q, L) = (3, 2)` (`n = 6, d = 3`): no nontrivial opposite-sign swap exists. -/ theorem rigid_3_2 : ¬ HasNontrivialSwap 6 3 := by rintro ⟨x, hsw, hx0, hx3, hcorr, hneq⟩ have hD := (swapAt_iff_periodic_defect x (3 : ZMod 6) (by decide) hx0 hx3).mp hcorr have h14 : x 4 - x 5 = x 1 - x 2 := hD 1 by_cases h12 : x 1 = x 2 · apply hneq refine ⟨true, false, 3, ?_⟩ have h45 : x 4 = x 5 := by omega intro i; fin_cases i <;> simp only [Bool.false_eq_true, ↓reduceIte, one_mul] all_goals first | rfl | exact h12 | exact h12.symm | exact h45 | exact h45.symm · have ⟨h41, h52⟩ := sign_diff_eq (hsw 1) (hsw 2) (hsw 4) (hsw 5) h12 h14 apply hneq refine ⟨false, false, 3, ?_⟩ intro i; fin_cases i <;> simp only [Bool.false_eq_true, ↓reduceIte, one_mul] all_goals first | rfl | exact h41 | exact h41.symm | exact h52 | exact h52.symm /-- Case `(q, L) = (3, 3)` (`n = 9, d = 3`): no nontrivial opposite-sign swap exists. -/ theorem rigid_3_3 : ¬ HasNontrivialSwap 9 3 := by rintro ⟨x, hsw, hx0, hx3, hcorr, hneq⟩ have hD := (swapAt_iff_periodic_defect x (3 : ZMod 9) (by decide) hx0 hx3).mp hcorr have h14 : x 4 - x 8 = x 1 - x 2 := hD 1 have h47 : x 7 - x 5 = x 4 - x 8 := hD 4 by_cases h12 : x 1 = x 2 · apply hneq refine ⟨true, false, 3, ?_⟩ have h48 : x 4 = x 8 := by omega have h75 : x 7 = x 5 := by omega intro i; fin_cases i <;> simp only [Bool.false_eq_true, ↓reduceIte, one_mul] all_goals first | rfl | exact h12 | exact h12.symm | exact h48 | exact h48.symm | exact h75 | exact h75.symm · have ⟨h41, h82⟩ := sign_diff_eq (hsw 1) (hsw 2) (hsw 4) (hsw 8) h12 h14 have ⟨h71, h52⟩ := sign_diff_eq (hsw 1) (hsw 2) (hsw 7) (hsw 5) h12 (h47.trans h14) have h47' : x 4 = x 7 := h41.trans h71.symm have h58' : x 5 = x 8 := h52.trans h82.symm apply hneq rcases hsw 6 with h6 | h6 · have h06 : x 0 = x 6 := hx0.trans h6.symm refine ⟨false, false, 3, ?_⟩ intro i; fin_cases i <;> simp only [Bool.false_eq_true, ↓reduceIte, one_mul] all_goals first | rfl | exact h06 | exact h06.symm | exact h41 | exact h41.symm | exact h71 | exact h71.symm | exact h47' | exact h47'.symm | exact h52 | exact h52.symm | exact h82 | exact h82.symm | exact h58' · have h36 : x 3 = x 6 := hx3.trans h6.symm refine ⟨false, false, 6, ?_⟩ intro i; fin_cases i <;> simp only [Bool.false_eq_true, ↓reduceIte, one_mul] all_goals first | rfl | exact h36 | exact h36.symm | exact h41 | exact h41.symm | exact h71 | exact h71.symm | exact h47' | exact h47'.symm | exact h52 | exact h52.symm | exact h82 | exact h82.symm | exact h58' | exact h58'.symm /-- Case `(q, L) = (3, 4)` (`n = 12, d = 3`): no nontrivial opposite-sign swap exists. -/ theorem rigid_3_4 : ¬ HasNontrivialSwap 12 3 := by rintro ⟨x, hsw, hx0, hx3, hcorr, hneq⟩ have hD := (swapAt_iff_periodic_defect x (3 : ZMod 12) (by decide) hx0 hx3).mp hcorr have h69 : x 6 = x 9 := by have h : x 6 - x 9 = 0 - 0 := hD 3 omega have h14 : x 4 - x 11 = x 1 - x 2 := hD 1 have h47 : x 7 - x 8 = x 4 - x 11 := hD 4 have h710 : x 10 - x 5 = x 7 - x 8 := hD 7 by_cases h12 : x 1 = x 2 · apply hneq refine ⟨true, false, 3, ?_⟩ have h411 : x 4 = x 11 := by omega have h78 : x 7 = x 8 := by omega have h105 : x 10 = x 5 := by omega intro i; fin_cases i <;> simp only [Bool.false_eq_true, ↓reduceIte, one_mul] all_goals first | rfl | exact h69 | exact h69.symm | exact h12 | exact h12.symm | exact h411 | exact h411.symm | exact h78 | exact h78.symm | exact h105 | exact h105.symm · have ⟨h41, h112⟩ := sign_diff_eq (hsw 1) (hsw 2) (hsw 4) (hsw 11) h12 h14 have ⟨h71, h82⟩ := sign_diff_eq (hsw 1) (hsw 2) (hsw 7) (hsw 8) h12 (h47.trans h14) have ⟨h101, h52⟩ := sign_diff_eq (hsw 1) (hsw 2) (hsw 10) (hsw 5) h12 ((h710.trans h47).trans h14) have h47' : x 4 = x 7 := h41.trans h71.symm have h710' : x 7 = x 10 := h71.trans h101.symm have h58' : x 5 = x 8 := h52.trans h82.symm have h811' : x 8 = x 11 := h82.trans h112.symm apply hneq rcases hsw 6 with h6 | h6 · have h06 : x 0 = x 6 := hx0.trans h6.symm have h90 : x 9 = x 0 := h69.symm.trans h06.symm refine ⟨false, false, 3, ?_⟩ intro i; fin_cases i <;> simp only [Bool.false_eq_true, ↓reduceIte, one_mul] all_goals first | rfl | exact h69 | exact h06 | exact h90 | exact h41 | exact h41.symm | exact h101 | exact h101.symm | exact h47' | exact h710' | exact h52 | exact h52.symm | exact h112 | exact h112.symm | exact h58' | exact h811' · have h39 : x 3 = x 9 := hx3.trans (h69.symm.trans h6).symm have h63 : x 6 = x 3 := h6.trans hx3.symm refine ⟨false, false, 9, ?_⟩ intro i; fin_cases i <;> simp only [Bool.false_eq_true, ↓reduceIte, one_mul] all_goals first | rfl | exact h69.symm | exact h39 | exact h63 | exact h41 | exact h41.symm | exact h101 | exact h101.symm | exact h47'.symm | exact h710'.symm | exact h52 | exact h52.symm | exact h112 | exact h112.symm | exact h58'.symm | exact h811'.symm /-- Case `(q, L) = (3, 5)` (`n = 15, d = 3`): no nontrivial opposite-sign swap exists. -/ theorem rigid_3_5 : ¬ HasNontrivialSwap 15 3 := by rintro ⟨x, hsw, hx0, hx3, hcorr, hneq⟩ have hD := (swapAt_iff_periodic_defect x (3 : ZMod 15) (by decide) hx0 hx3).mp hcorr have h612 : x 6 = x 12 := by have h : x 6 - x 12 = 0 - 0 := hD 3 omega have h14 : x 4 - x 14 = x 1 - x 2 := hD 1 have h47 : x 7 - x 11 = x 4 - x 14 := hD 4 have h710 : x 10 - x 8 = x 7 - x 11 := hD 7 have h1013 : x 13 - x 5 = x 10 - x 8 := hD 10 by_cases h12 : x 1 = x 2 · apply hneq refine ⟨true, false, 3, ?_⟩ have h414 : x 4 = x 14 := by omega have h711 : x 7 = x 11 := by omega have h108 : x 10 = x 8 := by omega have h135 : x 13 = x 5 := by omega intro i; fin_cases i <;> simp only [Bool.false_eq_true, ↓reduceIte, one_mul] all_goals first | rfl | exact h612 | exact h612.symm | exact h12 | exact h12.symm | exact h414 | exact h414.symm | exact h711 | exact h711.symm | exact h108 | exact h108.symm | exact h135 | exact h135.symm · have ⟨h41, h142⟩ := sign_diff_eq (hsw 1) (hsw 2) (hsw 4) (hsw 14) h12 h14 have ⟨h71, h112⟩ := sign_diff_eq (hsw 1) (hsw 2) (hsw 7) (hsw 11) h12 (h47.trans h14) have ⟨h101, h82⟩ := sign_diff_eq (hsw 1) (hsw 2) (hsw 10) (hsw 8) h12 ((h710.trans h47).trans h14) have ⟨h131, h52⟩ := sign_diff_eq (hsw 1) (hsw 2) (hsw 13) (hsw 5) h12 (((h1013.trans h710).trans h47).trans h14) have hc1 : ∀ a b : ZMod 15, a.val % 3 = 1 → b.val % 3 = 1 → x a = x b := by have h1 : ∀ a : ZMod 15, a.val % 3 = 1 → x a = x 1 := by intro a ha; fin_cases a all_goals first | rfl | exact h41 | exact h71 | exact h101 | exact h131 | cases ha intro a b ha hb; exact (h1 a ha).trans (h1 b hb).symm have hc2 : ∀ a b : ZMod 15, a.val % 3 = 2 → b.val % 3 = 2 → x a = x b := by have h2 : ∀ a : ZMod 15, a.val % 3 = 2 → x a = x 2 := by intro a ha; fin_cases a all_goals first | rfl | exact h52 | exact h82 | exact h112 | exact h142 | cases ha intro a b ha hb; exact (h2 a ha).trans (h2 b hb).symm have hx3' : x 3 = -1 := hx3 apply hneq rcases hsw 6 with h6 | h6 <;> rcases hsw 9 with h9 | h9 · have h12' : x 12 = 1 := h612.symm.trans h6 have h06 : x 0 = x 6 := hx0.trans h6.symm have h69 : x 6 = x 9 := h6.trans h9.symm have h912 : x 9 = x 12 := h9.trans h12'.symm have h120 : x 12 = x 0 := h12'.trans hx0.symm refine ⟨false, false, 3, ?_⟩ intro i; fin_cases i <;> simp only [Bool.false_eq_true, ↓reduceIte, one_mul] all_goals first | rfl | exact h06 | exact h69 | exact h912 | exact h120 | exact hc1 _ _ rfl rfl | exact hc2 _ _ rfl rfl · have h12' : x 12 = 1 := h612.symm.trans h6 have h39 : x 3 = x 9 := hx3'.trans h9.symm have h012 : x 0 = x 12 := hx0.trans h12'.symm have h60 : x 6 = x 0 := h6.trans hx0.symm have h126 : x 12 = x 6 := h12'.trans h6.symm refine ⟨false, false, 9, ?_⟩ intro i; fin_cases i <;> simp only [Bool.false_eq_true, ↓reduceIte, one_mul] all_goals first | rfl | exact h39 | exact h39.symm | exact h012 | exact h60 | exact h126 | exact hc1 _ _ rfl rfl | exact hc2 _ _ rfl rfl · have h12' : x 12 = -1 := h612.symm.trans h6 have h09 : x 0 = x 9 := hx0.trans h9.symm have h36 : x 3 = x 6 := hx3'.trans h6.symm have h612' : x 6 = x 12 := h612 have h123 : x 12 = x 3 := h12'.trans hx3'.symm refine ⟨false, false, 6, ?_⟩ intro i; fin_cases i <;> simp only [Bool.false_eq_true, ↓reduceIte, one_mul] all_goals first | rfl | exact h09 | exact h09.symm | exact h36 | exact h612' | exact h123 | exact hc1 _ _ rfl rfl | exact hc2 _ _ rfl rfl · have h12' : x 12 = -1 := h612.symm.trans h6 have h312 : x 3 = x 12 := hx3'.trans h12'.symm have h129 : x 12 = x 9 := h12'.trans h9.symm have h96 : x 9 = x 6 := h9.trans h6.symm have h63 : x 6 = x 3 := h6.trans hx3'.symm refine ⟨false, false, 12, ?_⟩ intro i; fin_cases i <;> simp only [Bool.false_eq_true, ↓reduceIte, one_mul] all_goals first | rfl | exact h312 | exact h129 | exact h96 | exact h63 | exact hc1 _ _ rfl rfl | exact hc2 _ _ rfl rfl /-- Case `(q, L) = (4, 2)` (`n = 8, d = 4`): no nontrivial opposite-sign swap exists. -/ theorem rigid_4_2 : ¬ HasNontrivialSwap 8 4 := by rintro ⟨x, hsw, hx0, hx4, hcorr, hneq⟩ have hD := (swapAt_iff_periodic_defect x (4 : ZMod 8) (by decide) hx0 hx4).mp hcorr have h15 : x 5 - x 7 = x 1 - x 3 := hD 1 have hx4' : x 4 = -1 := hx4 by_cases h13 : x 1 = x 3 · apply hneq refine ⟨true, false, 4, ?_⟩ have h57 : x 5 = x 7 := by omega intro i; fin_cases i <;> simp only [Bool.false_eq_true, ↓reduceIte, one_mul] all_goals first | rfl | exact h13 | exact h13.symm | exact h57 | exact h57.symm · have ⟨h51, h73⟩ := sign_diff_eq (hsw 1) (hsw 3) (hsw 5) (hsw 7) h13 h15 have h31 : x 3 = -x 1 := by rcases hsw 1 with h | h <;> rcases hsw 3 with h' | h' <;> omega have h13' : x 1 = -x 3 := by omega have h53 : x 5 = -x 3 := h51.trans h13' have h71 : x 7 = -x 1 := h73.trans h31 have h17 : x 1 = -x 7 := by omega have h35 : x 3 = -x 5 := by omega have h57 : x 5 = -x 7 := by omega have h75 : x 7 = -x 5 := by omega apply hneq rcases hsw 2 with h2 | h2 <;> rcases hsw 6 with h6 | h6 · have h26 : x 2 = x 6 := h2.trans h6.symm refine ⟨false, false, 4, ?_⟩ intro i; fin_cases i <;> simp only [Bool.false_eq_true, ↓reduceIte, one_mul] all_goals first | rfl | exact h51 | exact h51.symm | exact h73 | exact h73.symm | exact h26 | exact h26.symm · have h06 : x 0 = -x 6 := by omega have h42 : x 4 = -x 2 := by omega have h24 : x 2 = -x 4 := by omega have h60 : x 6 = -x 0 := by omega refine ⟨false, true, 2, ?_⟩ intro i; fin_cases i <;> simp only [Bool.false_eq_true, ↓reduceIte, neg_one_mul] all_goals first | rfl | exact h42 | exact h06 | exact h24 | exact h60 | exact h13' | exact h35 | exact h57 | exact h71 · have h02 : x 0 = -x 2 := by omega have h46 : x 4 = -x 6 := by omega have h20 : x 2 = -x 0 := by omega have h64 : x 6 = -x 4 := by omega refine ⟨false, true, 6, ?_⟩ intro i; fin_cases i <;> simp only [Bool.false_eq_true, ↓reduceIte, neg_one_mul] all_goals first | rfl | exact h46 | exact h02 | exact h20 | exact h64 | exact h17 | exact h31 | exact h53 | exact h75 · have h26 : x 2 = x 6 := h2.trans h6.symm refine ⟨false, false, 4, ?_⟩ intro i; fin_cases i <;> simp only [Bool.false_eq_true, ↓reduceIte, one_mul] all_goals first | rfl | exact h51 | exact h51.symm | exact h73 | exact h73.symm | exact h26 | exact h26.symm /-- Case `(q, L) = (5, 2)` (`n = 10, d = 5`): no nontrivial opposite-sign swap exists. -/ theorem rigid_5_2 : ¬ HasNontrivialSwap 10 5 := by rintro ⟨x, hsw, hx0, hx5, hcorr, hneq⟩ have hD := (swapAt_iff_periodic_defect x (5 : ZMod 10) (by decide) hx0 hx5).mp hcorr have h16 : x 6 - x 9 = x 1 - x 4 := hD 1 have h27 : x 7 - x 8 = x 2 - x 3 := hD 2 have hx5' : x 5 = -1 := hx5 have h05 : x 0 = -x 5 := by omega have h50 : x 5 = -x 0 := by omega by_cases h14 : x 1 = x 4 · by_cases h23 : x 2 = x 3 · apply hneq refine ⟨true, false, 5, ?_⟩ have h69 : x 6 = x 9 := by omega have h78 : x 7 = x 8 := by omega intro i; fin_cases i <;> simp only [Bool.false_eq_true, ↓reduceIte, one_mul] all_goals first | rfl | exact h14 | exact h14.symm | exact h23 | exact h23.symm | exact h69 | exact h69.symm | exact h78 | exact h78.symm · have ⟨h72, h83⟩ := sign_diff_eq (hsw 2) (hsw 3) (hsw 7) (hsw 8) h23 h27 have h32 : x 3 = -x 2 := by rcases hsw 2 with h | h <;> rcases hsw 3 with h' | h' <;> omega have h69 : x 6 = x 9 := by omega apply hneq by_cases h16eq : x 1 = x 6 · have h49 : x 4 = x 9 := (h14.symm.trans h16eq).trans h69 refine ⟨false, false, 5, ?_⟩ intro i; fin_cases i <;> simp only [Bool.false_eq_true, ↓reduceIte, one_mul] all_goals first | rfl | exact h16eq | exact h16eq.symm | exact h49 | exact h49.symm | exact h72 | exact h72.symm | exact h83 | exact h83.symm · have h61 : x 6 = -x 1 := by rcases hsw 1 with h | h <;> rcases hsw 6 with h' | h' <;> omega have h19 : x 1 = -x 9 := by omega have h91 : x 9 = -x 1 := by omega have h46 : x 4 = -x 6 := by omega have h64 : x 6 = -x 4 := by omega have h28 : x 2 = -x 8 := by omega have h82 : x 8 = -x 2 := by omega have h37 : x 3 = -x 7 := by omega have h73 : x 7 = -x 3 := by omega refine ⟨true, true, 0, ?_⟩ intro i; fin_cases i <;> simp only [↓reduceIte, neg_one_mul] all_goals first | rfl | exact h50 | exact h05 | exact h19 | exact h91 | exact h46 | exact h64 | exact h28 | exact h82 | exact h37 | exact h73 · have ⟨h61, h94⟩ := sign_diff_eq (hsw 1) (hsw 4) (hsw 6) (hsw 9) h14 h16 have h41 : x 4 = -x 1 := by rcases hsw 1 with h | h <;> rcases hsw 4 with h' | h' <;> omega by_cases h23 : x 2 = x 3 · have h78 : x 7 = x 8 := by omega apply hneq by_cases h27eq : x 2 = x 7 · have h38 : x 3 = x 8 := (h23.symm.trans h27eq).trans h78 refine ⟨false, false, 5, ?_⟩ intro i; fin_cases i <;> simp only [Bool.false_eq_true, ↓reduceIte, one_mul] all_goals first | rfl | exact h61 | exact h61.symm | exact h94 | exact h94.symm | exact h27eq | exact h27eq.symm | exact h38 | exact h38.symm · have h72 : x 7 = -x 2 := by rcases hsw 2 with h | h <;> rcases hsw 7 with h' | h' <;> omega have h19 : x 1 = -x 9 := by omega have h91 : x 9 = -x 1 := by omega have h46 : x 4 = -x 6 := by omega have h64 : x 6 = -x 4 := by omega have h28 : x 2 = -x 8 := by omega have h82 : x 8 = -x 2 := by omega have h37 : x 3 = -x 7 := by omega have h73 : x 7 = -x 3 := by omega refine ⟨true, true, 0, ?_⟩ intro i; fin_cases i <;> simp only [↓reduceIte, neg_one_mul] all_goals first | rfl | exact h50 | exact h05 | exact h19 | exact h91 | exact h46 | exact h64 | exact h28 | exact h82 | exact h37 | exact h73 · have ⟨h72, h83⟩ := sign_diff_eq (hsw 2) (hsw 3) (hsw 7) (hsw 8) h23 h27 apply hneq refine ⟨false, false, 5, ?_⟩ intro i; fin_cases i <;> simp only [Bool.false_eq_true, ↓reduceIte, one_mul] all_goals first | rfl | exact h61 | exact h61.symm | exact h94 | exact h94.symm | exact h72 | exact h72.symm | exact h83 | exact h83.symm /-- Combined rigidity theorem for all six finite negative cases `(q, L)`. -/ theorem rigid_six_finite_cases : ¬ HasNontrivialSwap 6 3 ∧ ¬ HasNontrivialSwap 9 3 ∧ ¬ HasNontrivialSwap 12 3 ∧ ¬ HasNontrivialSwap 15 3 ∧ ¬ HasNontrivialSwap 8 4 ∧ ¬ HasNontrivialSwap 10 5 := ⟨rigid_3_2, rigid_3_3, rigid_3_4, rigid_3_5, rigid_4_2, rigid_5_2⟩ #print axioms rigid_reflection_of_gcd_le_two #print axioms rigid_reflection_q1_q2 #print axioms not_hasNontrivialSwap_of_gcd_le_two #print axioms rigid_six_finite_cases end FiniteNegativeCases end SwapHomometry