import Mathlib.Analysis.Fourier.FiniteAbelian.PontryaginDuality import Mathlib.Analysis.Fourier.FiniteAbelian.Orthogonality import Mathlib.Data.ZMod.Basic import Mathlib.FieldTheory.Finite.Basic import Mathlib.Data.Finset.Card import Mathlib.Data.Fintype.Pi import Mathlib.Data.Fin.VecNotation import Mathlib.LinearAlgebra.Dimension.Finrank import Mathlib.LinearAlgebra.Dual.Lemmas import Mathlib.LinearAlgebra.LinearIndependent.Lemmas import Mathlib.Tactic.Linarith import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.FinCases /-! # Exact Rank-3 Rigidity and Complete Fiber-Size Spectrum over `(ZMod p)^3` For every odd prime `p ≥ 3`, we completely determine the exact set of attainable single-point autocorrelation fiber cardinalities for aperiodic supports in `(ZMod p)^3`: 1. **Exact Rank-3 Rigidity (`rank3_fiber_card_le_four`)**: For every odd prime `p ≥ 3`, every aperiodic `C : Finset (Fin 3 → ZMod p)`, and every `x₀ ∉ C`, `(Fiber C x₀).card ≤ 4`. *Proof*: Active characters span `(ZMod p)^3`; picking an active basis, shifting `x₀ ↦ 0`, and rescaling embeds `Fiber C₂ 0 ⊆ {0, 1}^3`. If `|Fiber| ≥ 5`, then under the hyperoctahedral group `B₃ = S₃ ⋉ (ℤ/2)^3` (which preserves `IsAperiodic`, `Fiber`, and `{0, 1}^3`), a 5-element subset maps to one of three canonical orbits (`SA`, `SB`, `SC`), each restricting active characters to at most 5 lines and yielding a `{0, 1}`-valued additive decomposition killed by our symmetric unit-difference obstruction. 2. **Sharp Witnesses for `k = 1, 2, 3, 4`**: - `k = 1` (`exists_fiber_card_one`): `C₁ = {0, e₀, e₁, e₂}`, `x₀ = ![1, 1, 1]`. - `k = 2` (`exists_fiber_card_two`): `C₂ = {0}`, `x₀ = ![1, 0, 0]`. - `k = 3` (`exists_fiber_card_three`): 5-slice core (`p ≥ 5`) and 9-element core (`p = 3`). - `k = 4` (`exists_fiber_card_four`): 4-slice core (`p ≥ 5`) and 12-element core (`p = 3`). 3. **Exact Fiber-Size Spectrum Theorem (`rank3_fiber_size_spectrum`)**: For every odd prime `p ≥ 3` and every `k : ℕ`: `(∃ C x₀, IsAperiodic C ∧ x₀ ∉ C ∧ (Fiber C x₀).card = k) ↔ k ∈ ({1, 2, 3, 4} : Finset ℕ)`. -/ namespace OpenAlgebraTopology.Rank3Spectrum open scoped BigOperators ComplexConjugate section Core variable {G : Type*} [AddCommGroup G] [Fintype G] [DecidableEq G] /-- Periodic autocorrelation of a support `S : Finset G` at lag `t : G`. -/ def autocorr (S : Finset G) (t : G) : ℕ := (S.filter fun u => u + t ∈ S).card /-- A support `C : Finset G` is aperiodic if its only translational period is `0`. -/ def IsAperiodic (C : Finset G) : Prop := ∀ g : G, C.image (· + g) = C → g = 0 /-- The single-point insertion fiber of `x₀` with fixed core `C`. -/ noncomputable def Fiber (C : Finset G) (x₀ : G) : Finset G := by classical exact (Finset.univ \ C).filter fun x => autocorr (insert x C) = autocorr (insert x₀ C) /-- Indicator function `1_C : G → ℕ`. -/ def indC (C : Finset G) (u : G) : ℕ := if u ∈ C then 1 else 0 /-- Complex Fourier coefficient `f_hat(χ) = ∑ u ∈ C, χ (-u)`. -/ def fourierCoeff (C : Finset G) (χ : AddChar G ℂ) : ℂ := ∑ u ∈ C, χ (-u) omit [Fintype G] in private lemma autocorr_insert_eq (C : Finset G) {x : G} (hx : x ∉ C) (t : G) : autocorr (insert x C) t = autocorr C t + (if t = 0 then 1 else 0) + indC C (x + t) + indC C (x - t) := by unfold autocorr indC rw [Finset.card_filter, Finset.card_filter, Finset.sum_insert hx] have h1 : (if x + t ∈ insert x C then (1 : ℕ) else 0) = (if t = 0 then 1 else 0) + (if x + t ∈ C then 1 else 0) := by by_cases ht : t = 0 · subst ht; simp [hx] · have hne : x + t ≠ x := fun h => ht (add_left_cancel (h.trans (add_zero x).symm)) simp [ht, hne] have h2 : ∑ u ∈ C, (if u + t ∈ insert x C then (1 : ℕ) else 0) = (∑ u ∈ C, if u + t ∈ C then 1 else 0) + (if x - t ∈ C then 1 else 0) := by have hsplit : ∀ u ∈ C, (if u + t ∈ insert x C then (1 : ℕ) else 0) = (if u + t ∈ C then 1 else 0) + (if u = x - t then 1 else 0) := by intro u _ by_cases hux : u + t = x · have hueq : u = x - t := eq_sub_of_add_eq hux simp [hx, hueq] · have huneq : u ≠ x - t := fun h => hux (by rw [h, sub_add_cancel]) simp [hux, huneq] rw [Finset.sum_congr rfl hsplit, Finset.sum_add_distrib] congr 1; simp [Finset.sum_ite_eq'] rw [h1, h2]; omega omit [Fintype G] in private lemma autocorr_insert_eq_iff (C : Finset G) {x x₀ : G} (hx : x ∉ C) (hx₀ : x₀ ∉ C) : autocorr (insert x C) = autocorr (insert x₀ C) ↔ ∀ t : G, indC C (x + t) + indC C (x - t) = indC C (x₀ + t) + indC C (x₀ - t) := by constructor · intro h t have ht := congr_fun h t rw [autocorr_insert_eq C hx t, autocorr_insert_eq C hx₀ t] at ht omega · intro h funext t rw [autocorr_insert_eq C hx t, autocorr_insert_eq C hx₀ t] have ht := h t; omega private lemma sum_addChar_apply (a : G) : ∑ χ : AddChar G ℂ, χ a = if a = 0 then (Fintype.card G : ℂ) else 0 := by have h1 : (∑ χ : AddChar G ℂ, χ a) = ∑ χ : AddChar G ℂ, (AddChar.doubleDualEmb a : AddChar (AddChar G ℂ) ℂ) χ := rfl rw [h1, AddChar.sum_eq_ite] simp [AddChar.doubleDualEmb_eq_zero, AddChar.card_eq] private lemma fourier_inversion (g : G → ℂ) (s : G) : ∑ χ : AddChar G ℂ, (∑ t : G, g t * χ (-t)) * χ s = (Fintype.card G : ℂ) * g s := by calc ∑ χ : AddChar G ℂ, (∑ t : G, g t * χ (-t)) * χ s = ∑ χ : AddChar G ℂ, ∑ t : G, g t * (χ (-t) * χ s) := by refine Finset.sum_congr rfl fun χ _ => ?_ rw [Finset.sum_mul]; refine Finset.sum_congr rfl fun t _ => by ring _ = ∑ t : G, ∑ χ : AddChar G ℂ, g t * χ (s - t) := by rw [Finset.sum_comm] refine Finset.sum_congr rfl fun t _ => Finset.sum_congr rfl fun χ _ => ?_ rw [← AddChar.map_add_eq_mul, neg_add_eq_sub] _ = ∑ t : G, g t * ∑ χ : AddChar G ℂ, χ (s - t) := by refine Finset.sum_congr rfl fun t _ => (Finset.mul_sum ..).symm _ = ∑ t : G, g t * (if s - t = 0 then (Fintype.card G : ℂ) else 0) := by refine Finset.sum_congr rfl fun t _ => by rw [sum_addChar_apply] _ = (Fintype.card G : ℂ) * g s := by have hsub : ∀ t : G, (s - t = 0) ↔ t = s := fun t => ⟨fun h => (sub_eq_zero.1 h).symm, fun h => by rw [h, sub_self]⟩ simp_rw [hsub]; simp [mul_comm] omit [DecidableEq G] in private lemma addChar_conj_eq_neg (χ : AddChar G ℂ) (a : G) : star (χ a) = χ (-a) := by rw [AddChar.map_neg_eq_inv, AddChar.inv_apply_eq_conj, Complex.star_def] omit [DecidableEq G] in private lemma addChar_apply_ne_zero (χ : AddChar G ℂ) (a : G) : χ a ≠ 0 := by intro h have hn := χ.norm_apply a rw [h, norm_zero] at hn exact zero_ne_one hn private lemma fourier_profile_eq (C : Finset G) (x : G) (χ : AddChar G ℂ) : ∑ t : G, ((indC C (x + t) + indC C (x - t) : ℕ) : ℂ) * χ (-t) = 2 * ((fourierCoeff C χ * χ x).re : ℂ) := by have hcast : ∀ t : G, ((indC C (x + t) + indC C (x - t) : ℕ) : ℂ) * χ (-t) = (indC C (x + t) : ℂ) * χ (-t) + (indC C (x - t) : ℂ) * χ (-t) := fun t => by push_cast; ring simp_rw [hcast, Finset.sum_add_distrib] have hplus : ∑ t : G, (indC C (x + t) : ℂ) * χ (-t) = fourierCoeff C χ * χ x := by let e : G ≃ G := Equiv.addLeft x rw [← Equiv.sum_comp e.symm] have hterm : ∀ u : G, (indC C (x + e.symm u) : ℂ) * χ (-(e.symm u)) = (indC C u : ℂ) * (χ (-u) * χ x) := by intro u have h1 : x + e.symm u = u := by simp [e] have h2 : -(e.symm u) = -u + x := by simp [e] rw [h1, h2, AddChar.map_add_eq_mul] simp_rw [hterm, ← mul_assoc] rw [← Finset.sum_mul]; congr 1; unfold fourierCoeff indC; simp have hminus : ∑ t : G, (indC C (x - t) : ℂ) * χ (-t) = star (fourierCoeff C χ * χ x) := by let e : G ≃ G := Equiv.subLeft x rw [← Equiv.sum_comp e.symm] have hterm : ∀ u : G, (indC C (x - e.symm u) : ℂ) * χ (-(e.symm u)) = (indC C u : ℂ) * (χ u * χ (-x)) := by intro u have h1 : x - e.symm u = u := by simp [e] have h2 : -(e.symm u) = u + -x := by simp [e]; abel rw [h1, h2, AddChar.map_add_eq_mul] simp_rw [hterm, ← mul_assoc] rw [← Finset.sum_mul] have hstar : star (fourierCoeff C χ * χ x) = (∑ u ∈ C, χ u) * χ (-x) := by rw [star_mul', addChar_conj_eq_neg] congr 1; unfold fourierCoeff; rw [star_sum] refine Finset.sum_congr rfl fun u _ => ?_ rw [addChar_conj_eq_neg, neg_neg] rw [hstar]; congr 1; unfold indC; simp rw [hplus, hminus] have hadd : ∀ z : ℂ, z + star z = 2 * (z.re : ℂ) := fun z => by rw [Complex.star_def, Complex.add_conj]; push_cast; ring exact hadd _ private lemma mem_fiber_fourier {C : Finset G} {x₀ x : G} (hx₀ : x₀ ∉ C) (hx : x ∈ Fiber C x₀) (χ : AddChar G ℂ) : (fourierCoeff C χ * χ x).re = (fourierCoeff C χ * χ x₀).re := by classical simp only [Fiber, Finset.mem_filter, Finset.mem_sdiff, Finset.mem_univ, true_and] at hx have hprof := (autocorr_insert_eq_iff C hx.1 hx₀).1 hx.2 have hsum : ∑ t : G, ((indC C (x + t) + indC C (x - t) : ℕ) : ℂ) * χ (-t) = ∑ t : G, ((indC C (x₀ + t) + indC C (x₀ - t) : ℕ) : ℂ) * χ (-t) := Finset.sum_congr rfl fun t _ => by rw [hprof t] rw [fourier_profile_eq, fourier_profile_eq] at hsum exact Complex.ofReal_injective (mul_left_cancel₀ (two_ne_zero : (2 : ℂ) ≠ 0) hsum) private lemma fourier_inversion_indC (C : Finset G) (s : G) : ∑ χ : AddChar G ℂ, fourierCoeff C χ * χ s = (Fintype.card G : ℂ) * (indC C s : ℂ) := by have h := fourier_inversion (fun t => (indC C t : ℂ)) s have hcoef : ∀ χ : AddChar G ℂ, ∑ t : G, (indC C t : ℂ) * χ (-t) = fourierCoeff C χ := by intro χ; unfold fourierCoeff indC; simp simp_rw [hcoef] at h exact h private lemma mem_fiber_self (C : Finset G) {x₀ : G} (hx₀ : x₀ ∉ C) : x₀ ∈ Fiber C x₀ := by classical simp [Fiber, hx₀] private lemma fiber_eq_of_mem {C : Finset G} {x₀ y : G} (hy : y ∈ Fiber C x₀) : Fiber C y = Fiber C x₀ := by classical simp only [Fiber, Finset.mem_filter, Finset.mem_sdiff, Finset.mem_univ, true_and] at hy ext z simp only [Fiber, Finset.mem_filter, Finset.mem_sdiff, Finset.mem_univ, true_and] exact ⟨fun ⟨hz, h⟩ => ⟨hz, h.trans hy.2⟩, fun ⟨hz, h⟩ => ⟨hz, h.trans hy.2.symm⟩⟩ omit [Fintype G] in private lemma isAperiodic_image_addEquiv {C : Finset G} (hC : IsAperiodic C) (φ : G ≃+ G) : IsAperiodic (C.image φ) := by intro g hg have himg : C.image (· + φ.symm g) = C := by ext u have hmem : φ u ∈ (C.image φ).image (· + g) ↔ φ u ∈ C.image φ := by rw [hg] simp only [Finset.mem_image] at hmem ⊢ constructor · rintro ⟨v, hv, rfl⟩ have : φ (v + φ.symm g) ∈ C.image φ := by rw [← hg] refine Finset.mem_image.2 ⟨φ v, Finset.mem_image_of_mem φ hv, ?_⟩ simp [map_add] obtain ⟨w, hw, hweq⟩ := Finset.mem_image.1 this rwa [← φ.injective hweq] · intro hu obtain ⟨b, hb, hbeq⟩ := hmem.2 ⟨u, hu, rfl⟩ obtain ⟨a, ha, rfl⟩ := hb refine ⟨a, ha, φ.injective ?_⟩ simp [map_add, hbeq] have hzero := hC (φ.symm g) himg simpa using congr_arg φ hzero omit [Fintype G] in private lemma autocorr_image_addEquiv (S : Finset G) (φ : G ≃+ G) (t : G) : autocorr (S.image φ) (φ t) = autocorr S t := by unfold autocorr have h : (S.image φ).filter (fun u => u + φ t ∈ S.image φ) = (S.filter (fun u => u + t ∈ S)).image φ := by ext v simp only [Finset.mem_filter, Finset.mem_image] constructor · rintro ⟨⟨u, hu, rfl⟩, ⟨w, hw, hweq⟩⟩ refine ⟨u, ⟨hu, ?_⟩, rfl⟩ have : w = u + t := φ.injective (by rw [map_add, hweq]) rwa [← this] · rintro ⟨u, ⟨hu, hut⟩, rfl⟩ exact ⟨⟨u, hu, rfl⟩, ⟨u + t, hut, map_add φ u t⟩⟩ rw [h, Finset.card_image_of_injective _ φ.injective] private lemma fiber_image_addEquiv (C : Finset G) (x₀ : G) (φ : G ≃+ G) : Fiber (C.image φ) (φ x₀) = (Fiber C x₀).image φ := by classical ext y simp only [Fiber, Finset.mem_filter, Finset.mem_sdiff, Finset.mem_univ, true_and, Finset.mem_image] constructor · rintro ⟨hyC, hauto⟩ refine ⟨φ.symm y, ⟨?_, ?_⟩, by simp⟩ · intro h; exact hyC ⟨φ.symm y, h, by simp⟩ · funext t have ht := congr_fun hauto (φ t) have h1 : insert y (C.image φ) = (insert (φ.symm y) C).image φ := by rw [Finset.image_insert, φ.apply_symm_apply] have h2 : insert (φ x₀) (C.image φ) = (insert x₀ C).image φ := by rw [Finset.image_insert] rw [h1, h2, autocorr_image_addEquiv, autocorr_image_addEquiv] at ht exact ht · rintro ⟨x, ⟨hxC, hauto⟩, rfl⟩ refine ⟨?_, ?_⟩ · intro h; obtain ⟨u, hu, hueq⟩ := h; exact hxC (φ.injective hueq ▸ hu) · funext t have h1 : insert (φ x) (C.image φ) = (insert x C).image φ := by rw [Finset.image_insert] have h2 : insert (φ x₀) (C.image φ) = (insert x₀ C).image φ := by rw [Finset.image_insert] rw [h1, h2, ← φ.apply_symm_apply t, autocorr_image_addEquiv, autocorr_image_addEquiv] exact congr_fun hauto (φ.symm t) omit [Fintype G] in private lemma isAperiodic_image_add {C : Finset G} (hC : IsAperiodic C) (a : G) : IsAperiodic (C.image (· + a)) := by intro g hg have himg : C.image (· + g) = C := by ext u have hmem : u + a ∈ (C.image (· + a)).image (· + g) ↔ u + a ∈ C.image (· + a) := by rw [hg] simp only [Finset.mem_image] at hmem ⊢ constructor · rintro ⟨v, hv, rfl⟩ have : (v + g) + a ∈ C.image (· + a) := by rw [← hg] refine Finset.mem_image.2 ⟨v + a, Finset.mem_image_of_mem _ hv, by abel⟩ obtain ⟨w, hw, hweq⟩ := Finset.mem_image.1 this have : w = v + g := add_right_cancel hweq rwa [← this] · intro hu obtain ⟨b, hb, hbeq⟩ := hmem.2 ⟨u, hu, rfl⟩ obtain ⟨v, hv, rfl⟩ := hb refine ⟨v, hv, add_right_cancel (b := a) ?_⟩ calc v + g + a = v + a + g := by abel _ = u + a := hbeq exact hC g himg omit [Fintype G] in private lemma autocorr_image_add (S : Finset G) (a t : G) : autocorr (S.image (· + a)) t = autocorr S t := by unfold autocorr have h : (S.image (· + a)).filter (fun u => u + t ∈ S.image (· + a)) = (S.filter (fun u => u + t ∈ S)).image (· + a) := by ext v simp only [Finset.mem_filter, Finset.mem_image] constructor · rintro ⟨⟨u, hu, rfl⟩, ⟨w, hw, hweq⟩⟩ refine ⟨u, ⟨hu, ?_⟩, rfl⟩ have hwa : w + a = u + t + a := by rw [hweq]; abel have : w = u + t := add_right_cancel hwa rwa [← this] · rintro ⟨u, ⟨hu, hut⟩, rfl⟩ exact ⟨⟨u, hu, rfl⟩, ⟨u + t, hut, by abel⟩⟩ rw [h, Finset.card_image_of_injective _ (add_left_injective a)] private lemma fiber_image_add (C : Finset G) (x₀ a : G) : Fiber (C.image (· + a)) (x₀ + a) = (Fiber C x₀).image (· + a) := by classical ext y simp only [Fiber, Finset.mem_filter, Finset.mem_sdiff, Finset.mem_univ, true_and, Finset.mem_image] constructor · rintro ⟨hyC, hauto⟩ refine ⟨y - a, ⟨?_, ?_⟩, sub_add_cancel y a⟩ · intro h; exact hyC ⟨y - a, h, sub_add_cancel y a⟩ · funext t have ht := congr_fun hauto t have h1 : insert y (C.image (· + a)) = (insert (y - a) C).image (· + a) := by rw [Finset.image_insert, sub_add_cancel] have h2 : insert (x₀ + a) (C.image (· + a)) = (insert x₀ C).image (· + a) := by rw [Finset.image_insert] rw [h1, h2, autocorr_image_add, autocorr_image_add] at ht exact ht · rintro ⟨x, ⟨hxC, hauto⟩, rfl⟩ refine ⟨?_, ?_⟩ · intro h; obtain ⟨u, hu, hueq⟩ := h; exact hxC (add_right_cancel hueq ▸ hu) · funext t have h1 : insert (x + a) (C.image (· + a)) = (insert x C).image (· + a) := by rw [Finset.image_insert] have h2 : insert (x₀ + a) (C.image (· + a)) = (insert x₀ C).image (· + a) := by rw [Finset.image_insert] rw [h1, h2, autocorr_image_add, autocorr_image_add] exact congr_fun hauto t private lemma unit_circle_re_eq_at_most_two {z w₁ w₂ w₃ : ℂ} (hz : z ≠ 0) (hw₁ : ‖w₁‖ = 1) (hw₂ : ‖w₂‖ = 1) (hw₃ : ‖w₃‖ = 1) (h12 : (z * w₁).re = (z * w₂).re) (h13 : (z * w₁).re = (z * w₃).re) : w₁ = w₂ ∨ w₁ = w₃ ∨ w₂ = w₃ := by have hns : ∀ w : ℂ, ‖w‖ = 1 → Complex.normSq (z * w) = Complex.normSq z := fun w hw => by rw [map_mul, Complex.normSq_eq_norm_sq w, hw, one_pow, mul_one] have him : ∀ w : ℂ, ‖w‖ = 1 → (z * w₁).re = (z * w).re → (z * w).im = (z * w₁).im ∨ (z * w).im = -(z * w₁).im := fun w hw hre => by have hq1 := hns w₁ hw₁ have hq2 := hns w hw have hsq : (z * w).im ^ 2 = (z * w₁).im ^ 2 := by have h := hq2.trans hq1.symm rw [Complex.normSq_apply, Complex.normSq_apply, ← hre] at h nlinarith exact sq_eq_sq_iff_eq_or_eq_neg.1 hsq rcases him w₂ hw₂ h12 with h2 | h2 · left; exact mul_left_cancel₀ hz (Complex.ext h12 h2.symm) · rcases him w₃ hw₃ h13 with h3 | h3 · right; left; exact mul_left_cancel₀ hz (Complex.ext h13 h3.symm) · right; right; exact mul_left_cancel₀ hz (Complex.ext (h12.symm.trans h13) (h2.trans h3.symm)) private lemma mul_eq_star_of_re_eq {z w : ℂ} (hw : ‖w‖ = 1) (hw1 : w ≠ 1) (hre : (z * w).re = z.re) : z * w = star z := by have hns : Complex.normSq (z * w) = Complex.normSq z := by rw [map_mul, Complex.normSq_eq_norm_sq w, hw, one_pow, mul_one] have hsq : (z * w).im ^ 2 = z.im ^ 2 := by rw [Complex.normSq_apply, Complex.normSq_apply, hre] at hns nlinarith rcases sq_eq_sq_iff_eq_or_eq_neg.1 hsq with him | him · have hzw : z * w = z := Complex.ext hre him have hz : z = 0 := by have hsub : z * (w - 1) = 0 := by linear_combination hzw exact (mul_eq_zero.1 hsub).resolve_right (sub_ne_zero.2 hw1) simp [hz] · exact Complex.ext (by simpa using hre) (by simpa using him) end Core section CubeOrbits /-- The hyperoctahedral group `B₃ = S₃ ⋉ (ℤ/2)^3` acting on `{false, true}^3`. -/ private def actBool (σ : Equiv.Perm (Fin 3)) (flips : Fin 3 → Bool) (v : Fin 3 → Bool) : Fin 3 → Bool := fun i => xor (v (σ i)) (flips i) private def SA_bool : Finset (Fin 3 → Bool) := {![false, false, false], ![false, false, true], ![false, true, false], ![false, true, true], ![true, false, false]} private def SB_bool : Finset (Fin 3 → Bool) := {![false, false, false], ![false, true, false], ![false, true, true], ![true, false, false], ![true, false, true]} private def SC_bool : Finset (Fin 3 → Bool) := {![false, false, false], ![false, false, true], ![false, true, false], ![true, false, false], ![true, true, true]} /-- Every 5-element subset of `{false, true}^3` (specified by its 3-element complement `{t₁, t₂, t₃}`) is equivalent under `B₃` to `SA_bool`, `SB_bool`, or `SC_bool`. -/ private lemma cube5_orbit_classification : ∀ t₁ t₂ t₃ : Fin 3 → Bool, t₁ ≠ t₂ → t₁ ≠ t₃ → t₂ ≠ t₃ → ∃ (σ : Equiv.Perm (Fin 3)) (flips : Fin 3 → Bool), let S : Finset (Fin 3 → Bool) := Finset.univ \ {t₁, t₂, t₃} S.image (actBool σ flips) = SA_bool ∨ S.image (actBool σ flips) = SB_bool ∨ S.image (actBool σ flips) = SC_bool := by decide end CubeOrbits section CharactersAndObstruction variable {p : ℕ} [Fact p.Prime] private noncomputable def e1 (p : ℕ) [NeZero p] : AddChar (ZMod p) ℂ := AddChar.zmodAddEquiv (1 : ZMod p) private lemma e1_apply_comm (p : ℕ) [NeZero p] (a : ZMod p) : e1 p a = (AddChar.zmodAddEquiv a : AddChar (ZMod p) ℂ) 1 := by unfold e1 rw [AddChar.zmodAddEquiv_apply, AddChar.zmodAddEquiv_apply] obtain ⟨k, rfl⟩ := ZMod.intCast_surjective a have h1 : (1 : ZMod p) = ((1 : ℤ) : ZMod p) := by simp rw [h1] change ((AddChar.zmod p ((1 : ℤ) : ZMod p) ((k : ℤ) : ZMod p) : Circle) : ℂ) = ((AddChar.zmod p ((k : ℤ) : ZMod p) ((1 : ℤ) : ZMod p) : Circle) : ℂ) rw [AddChar.zmod_intCast, AddChar.zmod_intCast] congr 2; ring private lemma e1_injective (p : ℕ) [NeZero p] : Function.Injective (e1 p) := by intro a b hab have hsub : e1 p (a - b) = 1 := by rw [AddChar.map_sub_eq_div, hab, div_self (addChar_apply_ne_zero (e1 p) b)] have h1 : (AddChar.zmodAddEquiv (a - b) : AddChar (ZMod p) ℂ) 1 = 1 := by rw [← e1_apply_comm, hsub] have hall : (AddChar.zmodAddEquiv (a - b) : AddChar (ZMod p) ℂ) = 0 := by ext y have hy : y = y.val • (1 : ZMod p) := by simp rw [hy, AddChar.map_nsmul_eq_pow, h1, one_pow] rfl exact sub_eq_zero.1 (AddChar.zmodAddEquiv.injective (hall.trans (map_zero _).symm)) private def dotHom3 (p : ℕ) (ξ : Fin 3 → ZMod p) : (Fin 3 → ZMod p) →+ ZMod p where toFun u := ∑ i : Fin 3, ξ i * u i map_zero' := by simp map_add' u v := by simp only [Pi.add_apply, mul_add, Finset.sum_add_distrib] private noncomputable def char3 (p : ℕ) [NeZero p] (ξ : Fin 3 → ZMod p) : AddChar (Fin 3 → ZMod p) ℂ := (e1 p).compAddMonoidHom (dotHom3 p ξ) private lemma char3_apply (p : ℕ) [NeZero p] (ξ u : Fin 3 → ZMod p) : char3 p ξ u = e1 p (ξ 0 * u 0 + ξ 1 * u 1 + ξ 2 * u 2) := by simp [char3, dotHom3, Fin.sum_univ_three] private lemma char3_injective (p : ℕ) [NeZero p] : Function.Injective (char3 p) := by intro ξ η h funext i have hi := DFunLike.congr_fun h (Pi.single i (1 : ZMod p)) fin_cases i · exact e1_injective p (by simpa [char3_apply] using hi) · exact e1_injective p (by simpa [char3_apply] using hi) · exact e1_injective p (by simpa [char3_apply] using hi) private lemma char3_bijective (p : ℕ) [NeZero p] : Function.Bijective (char3 p) := by rw [Fintype.bijective_iff_injective_and_card, AddChar.card_eq] exact ⟨char3_injective p, rfl⟩ private noncomputable def F3 (C : Finset (Fin 3 → ZMod p)) (ξ : Fin 3 → ZMod p) : ℂ := fourierCoeff C (char3 p ξ) private lemma fourier_inversion_zmod3 (C : Finset (Fin 3 → ZMod p)) (u : Fin 3 → ZMod p) : ∑ ξ : Fin 3 → ZMod p, F3 C ξ * char3 p ξ u = ((p ^ 3 : ℕ) : ℂ) * (indC C u : ℂ) := by have h := fourier_inversion_indC C u have hbij := Fintype.sum_bijective (char3 p) (char3_bijective p) (fun ξ => F3 C ξ * char3 p ξ u) (fun χ => fourierCoeff C χ * χ u) (fun _ => rfl) rw [hbij, h] simp [Fintype.card_pi, ZMod.card] private lemma F3_neg (C : Finset (Fin 3 → ZMod p)) (ξ : Fin 3 → ZMod p) : F3 C (-ξ) = star (F3 C ξ) := by unfold F3 fourierCoeff rw [star_sum] refine Finset.sum_congr rfl fun u _ => ?_ rw [addChar_conj_eq_neg, neg_neg, char3_apply, char3_apply] congr 1; simp only [Pi.neg_apply]; ring private lemma isAperiodic_of_orthog_zero3 {C : Finset (Fin 3 → ZMod p)} (hC : IsAperiodic C) {g : Fin 3 → ZMod p} (hg : ∀ ξ : Fin 3 → ZMod p, F3 C ξ ≠ 0 → ∑ i : Fin 3, ξ i * g i = 0) : g = 0 := by have hind : ∀ u : Fin 3 → ZMod p, indC C (u + g) = indC C u := by intro u have h1 := fourier_inversion_zmod3 C (u + g) have h2 := fourier_inversion_zmod3 C u have hsum : ∑ ξ : Fin 3 → ZMod p, F3 C ξ * char3 p ξ (u + g) = ∑ ξ : Fin 3 → ZMod p, F3 C ξ * char3 p ξ u := by refine Finset.sum_congr rfl fun ξ _ => ?_ by_cases hF : F3 C ξ = 0 · simp [hF] · have hdot := hg ξ hF have hch : char3 p ξ (u + g) = char3 p ξ u := by have hd : ξ 0 * g 0 + ξ 1 * g 1 + ξ 2 * g 2 = 0 := by simpa [Fin.sum_univ_three] using hdot have hg1 : char3 p ξ g = 1 := by rw [char3_apply, hd, AddChar.map_zero_eq_one] rw [AddChar.map_add_eq_mul, hg1, mul_one] rw [hch] rw [h1, h2] at hsum have hp3 : ((p ^ 3 : ℕ) : ℂ) ≠ 0 := Nat.cast_ne_zero.2 (pow_ne_zero 3 (Fact.out : p.Prime).ne_zero) exact Nat.cast_injective (mul_left_cancel₀ hp3 hsum) have himg : C.image (· + (-g)) = C := by ext u simp only [Finset.mem_image] constructor · rintro ⟨v, hv, rfl⟩ have h := hind (v + -g) have hsub : v + -g + g = v := by abel rw [hsub] at h unfold indC at h by_cases h1 : v ∈ C <;> by_cases h2 : v + -g ∈ C <;> simp_all · intro hu refine ⟨u + g, ?_, by abel⟩ have h := hind u unfold indC at h by_cases h1 : u + g ∈ C <;> by_cases h2 : u ∈ C <;> simp_all have hneg : -g = 0 := hC (-g) himg simpa using congr_arg Neg.neg hneg private lemma active_span_top3 {C : Finset (Fin 3 → ZMod p)} (hC : IsAperiodic C) : Submodule.span (ZMod p) {ξ : Fin 3 → ZMod p | F3 C ξ ≠ 0} = ⊤ := by set W : Submodule (ZMod p) (Fin 3 → ZMod p) := Submodule.span (ZMod p) {ξ : Fin 3 → ZMod p | F3 C ξ ≠ 0} by_contra hne have hfin_lt : Module.finrank (ZMod p) W < Module.finrank (ZMod p) (Fin 3 → ZMod p) := Submodule.finrank_lt hne let Φ : (Fin 3 → ZMod p) →ₗ[ZMod p] Module.Dual (ZMod p) W := { toFun := fun g => { toFun := fun w => ∑ i : Fin 3, w.1 i * g i map_add' := fun w₁ w₂ => by simp only [Submodule.coe_add, Pi.add_apply, add_mul, Finset.sum_add_distrib] map_smul' := fun c w => by simp only [Submodule.coe_smul, Pi.smul_apply, smul_eq_mul, RingHom.id_apply, mul_assoc, Finset.mul_sum] } map_add' := fun g₁ g₂ => by ext w; simp [mul_add, Finset.sum_add_distrib] map_smul' := fun c g => by ext w; simp only [LinearMap.coe_mk, AddHom.coe_mk, Pi.smul_apply, smul_eq_mul, LinearMap.smul_apply, RingHom.id_apply, Finset.mul_sum] refine Finset.sum_congr rfl fun i _ => by ring } have hdual_lt : Module.finrank (ZMod p) (Module.Dual (ZMod p) W) < Module.finrank (ZMod p) (Fin 3 → ZMod p) := by rw [Subspace.dual_finrank_eq]; exact hfin_lt have hker_pos : 0 < Module.finrank (ZMod p) (LinearMap.ker Φ) := by have hrn := LinearMap.finrank_range_add_finrank_ker Φ have hrange_le : Module.finrank (ZMod p) (LinearMap.range Φ) ≤ Module.finrank (ZMod p) (Module.Dual (ZMod p) W) := Submodule.finrank_le _ omega obtain ⟨⟨g, hg_ker⟩, hg_ne⟩ := Module.finrank_pos_iff_exists_ne_zero.1 hker_pos have hg0 : g ≠ 0 := fun h => hg_ne (Subtype.ext h) apply hg0 apply isAperiodic_of_orthog_zero3 hC intro ξ hF have h0 : Φ g ⟨ξ, Submodule.subset_span hF⟩ = 0 := by rw [LinearMap.mem_ker.1 hg_ker]; rfl exact h0 /-- Unit-difference obstruction: if `f₁ x + f₂ y + f₃ (x + y) ∈ {0, 1}` with `f₁ 1 = f₁ 0`, then either `f₁` is constant or `f₂` is constant. -/ private lemma const_or_const_of_symmetric_sum {f₁ f₂ f₃ : ZMod p → ℝ} (hbin : ∀ x y : ZMod p, f₁ x + f₂ y + f₃ (x + y) = 0 ∨ f₁ x + f₂ y + f₃ (x + y) = 1) (hsym : f₁ 1 = f₁ 0) : (∀ x₁ x₂ : ZMod p, f₁ x₁ = f₁ x₂) ∨ (∀ y₁ y₂ : ZMod p, f₂ y₁ = f₂ y₂) := by by_contra hnc push Not at hnc obtain ⟨hf₁_nc, hf₂_nc⟩ := hnc let u : ZMod p → ℝ := fun x => f₁ (x + 1) - f₁ x let v : ZMod p → ℝ := fun y => f₂ (y + 1) - f₂ y have hsum_zero : ∀ g : ZMod p → ℝ, ∑ x : ZMod p, (g (x + 1) - g x) = 0 := fun g => by have hsh : ∑ x : ZMod p, g (x + 1) = ∑ x : ZMod p, g x := Equiv.sum_comp (Equiv.addRight (1 : ZMod p)) g rw [Finset.sum_sub_distrib, hsh, sub_self] have hne_zero_of_nc : ∀ g : ZMod p → ℝ, (∃ a b : ZMod p, g a ≠ g b) → ∃ x : ZMod p, g (x + 1) - g x ≠ 0 := by intro g ⟨a, b, hab⟩ by_contra h; push Not at h have hstep : ∀ x : ZMod p, g (x + 1) = g x := fun x => sub_eq_zero.1 (h x) have hconst : ∀ n : ℕ, g (n : ZMod p) = g 0 := by intro n; induction n with | zero => simp | succ n ih => rw [Nat.cast_succ, hstep, ih] have ha : g a = g 0 := by rw [← ZMod.natCast_zmod_val a]; exact hconst a.val have hb : g b = g 0 := by rw [← ZMod.natCast_zmod_val b]; exact hconst b.val exact hab (ha.trans hb.symm) have hex_pos_neg : ∀ w : ZMod p → ℝ, ∑ x : ZMod p, w x = 0 → (∃ x, w x ≠ 0) → (∃ x, 0 < w x) ∧ (∃ x, w x < 0) := by intro w hsum ⟨x₀, hx₀⟩ constructor · by_contra hle; push Not at hle have hnegsum : ∑ x ∈ (Finset.univ : Finset (ZMod p)), (-w x) = 0 := by rw [Finset.sum_neg_distrib, hsum, neg_zero] have hnn : ∀ x ∈ (Finset.univ : Finset (ZMod p)), 0 ≤ -w x := fun x _ => neg_nonneg.2 (hle x) have := (Finset.sum_eq_zero_iff_of_nonneg hnn).1 hnegsum x₀ (Finset.mem_univ _) exact hx₀ (neg_eq_zero.1 this) · by_contra hge; push Not at hge have := (Finset.sum_eq_zero_iff_of_nonneg (fun x _ => hge x)).1 hsum x₀ (Finset.mem_univ _) exact hx₀ this obtain ⟨⟨xp, hxp⟩, ⟨xm, hxm⟩⟩ := hex_pos_neg u (hsum_zero f₁) (hne_zero_of_nc f₁ hf₁_nc) obtain ⟨⟨yp, hyp⟩, ⟨ym, hym⟩⟩ := hex_pos_neg v (hsum_zero f₂) (hne_zero_of_nc f₂ hf₂_nc) have hdiff : ∀ x y : ZMod p, u x - v y = -1 ∨ u x - v y = 0 ∨ u x - v y = 1 := by intro x y have h1 := hbin (x + 1) y have h2 := hbin x (y + 1) have hsum_eq : (x + 1) + y = x + (y + 1) := by ring rw [hsum_eq] at h1 have hsub : u x - v y = (f₁ (x + 1) + f₂ y + f₃ (x + (y + 1))) - (f₁ x + f₂ (y + 1) + f₃ (x + (y + 1))) := by dsimp only [u, v]; ring rcases h1 with h1 | h1 <;> rcases h2 with h2 | h2 · right; left; linarith · left; linarith · right; right; linarith · right; left; linarith have h1 : u xp - v ym = 1 := by rcases hdiff xp ym with h | h | h <;> linarith have h2 : u xm - v yp = -1 := by rcases hdiff xm yp with h | h | h <;> linarith have h3 : u xp - v yp = 0 := by rcases hdiff xp yp with h | h | h <;> linarith have hu0 : u 0 = 0 := by dsimp only [u]; rw [zero_add, hsym, sub_self] have h0y := hdiff 0 ym rw [hu0] at h0y rcases h0y with h | h | h <;> linarith /-- Disjoint-variable binary sum lemma: if `g₁ a + g₂ b ∈ {0, 1}` for all `a, b`, then one is constant. -/ private lemma const_or_const_of_disjoint_sum {α β : Type*} {g₁ : α → ℝ} {g₂ : β → ℝ} (hbin : ∀ a b, g₁ a + g₂ b = 0 ∨ g₁ a + g₂ b = 1) : (∀ a₁ a₂, g₁ a₁ = g₁ a₂) ∨ (∀ b₁ b₂, g₂ b₁ = g₂ b₂) := by by_contra hnc; push Not at hnc obtain ⟨⟨a₁, a₂, ha⟩, ⟨b₁, b₂, hb⟩⟩ := hnc have hlt1 : ∃ x₁ x₂, g₁ x₁ < g₁ x₂ := by rcases lt_or_gt_of_ne ha with h | h; exact ⟨a₁, a₂, h⟩; exact ⟨a₂, a₁, h⟩ have hlt2 : ∃ y₁ y₂, g₂ y₁ < g₂ y₂ := by rcases lt_or_gt_of_ne hb with h | h; exact ⟨b₁, b₂, h⟩; exact ⟨b₂, b₁, h⟩ obtain ⟨x₁, x₂, hx⟩ := hlt1 obtain ⟨y₁, y₂, hy⟩ := hlt2 rcases hbin x₁ y₁ with h11 | h11 <;> rcases hbin x₂ y₁ with h21 | h21 <;> rcases hbin x₂ y₂ with h22 | h22 <;> linarith /-- Helper: if `g : ZMod p → ℝ` satisfies `g (x + 1) = g x` for all `x`, then `g` is constant. -/ private lemma const_of_step_one {g : ZMod p → ℝ} (hstep : ∀ x : ZMod p, g (x + 1) = g x) : ∀ a b : ZMod p, g a = g b := by have hconst : ∀ n : ℕ, g (n : ZMod p) = g 0 := by intro n; induction n with | zero => simp | succ n ih => rw [Nat.cast_succ, hstep, ih] intro a b rw [← ZMod.natCast_zmod_val a, ← ZMod.natCast_zmod_val b, hconst, hconst] /-- Helper: aperiodicity contradicts any nonzero period of `indC C`. -/ private lemma absurd_of_indC_period {C : Finset (Fin 3 → ZMod p)} (hC : IsAperiodic C) {g : Fin 3 → ZMod p} (hg : g ≠ 0) (hind : ∀ u : Fin 3 → ZMod p, indC C (u + g) = indC C u) : False := by have himg : C.image (· + (-g)) = C := by ext u simp only [Finset.mem_image] constructor · rintro ⟨v, hv, rfl⟩ have h := hind (v + -g) have hsub : v + -g + g = v := by abel rw [hsub] at h unfold indC at h by_cases h1 : v ∈ C <;> by_cases h2 : v + -g ∈ C <;> simp_all · intro hu refine ⟨u + g, ?_, by abel⟩ have h := hind u unfold indC at h by_cases h1 : u + g ∈ C <;> by_cases h2 : u ∈ C <;> simp_all have hneg0 := hC (-g) himg exact hg (by simpa using congr_arg Neg.neg hneg0) /-- Helper: if `0, Pi.single k 1 ∈ Fiber C 0`, then the 1D coordinate Fourier summand `f_k` satisfies `f_k 1 = f_k 0`. -/ private lemma coord_summand_sym {C : Finset (Fin 3 → ZMod p)} (h0C : (0 : Fin 3 → ZMod p) ∉ C) (k : Fin 3) (hek : Pi.single k (1 : ZMod p) ∈ Fiber C 0) : (∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C (Pi.single k c) * e1 p (c * 1)).re = (∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C (Pi.single k c) * e1 p (c * 0)).re := by congr 1 have hterm : ∀ c ∈ Finset.univ.erase (0 : ZMod p), F3 C (Pi.single k c) * e1 p (c * 1) = F3 C (Pi.single k (-c)) * e1 p ((-c) * 0) := by intro c hc have hc0 : c ≠ 0 := (Finset.mem_erase.1 hc).1 have hre := mem_fiber_fourier h0C hek (char3 p (Pi.single k c)) have hch1 : char3 p (Pi.single k c) (Pi.single k 1) = e1 p c := by fin_cases k <;> simp [char3_apply] have hch0 : char3 p (Pi.single k c) 0 = 1 := by simp rw [hch1, hch0, mul_one] at hre have hw : ‖(e1 p c : ℂ)‖ = 1 := (e1 p).norm_apply c have hw1 : e1 p c ≠ 1 := fun h => hc0 (e1_injective p (h.trans (AddChar.map_zero_eq_one (e1 p)).symm)) have hmul := mul_eq_star_of_re_eq hw hw1 hre have hneg : star (F3 C (Pi.single k c)) = F3 C (Pi.single k (-c)) := by have h1 := (F3_neg C (Pi.single k c)).symm have h2 : -(Pi.single k c : Fin 3 → ZMod p) = Pi.single k (-c) := by funext i; by_cases hik : i = k <;> simp [hik] rwa [h2] at h1 rw [mul_one, mul_zero, AddChar.map_zero_eq_one, mul_one, ← hneg] exact hmul rw [Finset.sum_congr rfl hterm] refine Finset.sum_bij (fun c _ => -c) ?_ ?_ ?_ ?_ · intro c hc; exact Finset.mem_erase.2 ⟨neg_ne_zero.2 (Finset.mem_erase.1 hc).1, Finset.mem_univ _⟩ · intro a _ b _ h; exact neg_inj.1 h · intro b hb exact ⟨-b, Finset.mem_erase.2 ⟨neg_ne_zero.2 (Finset.mem_erase.1 hb).1, Finset.mem_univ _⟩, neg_neg b⟩ · intro c _; rfl /-- Helper: given any `u₁, u₂, u₃ ∈ Fiber C 0` and active `ξ`, two of `ξ · u₁, ξ · u₂, ξ · u₃` coincide. -/ private lemma active_dot_at_most_two {C : Finset (Fin 3 → ZMod p)} (h0C : (0 : Fin 3 → ZMod p) ∉ C) {ξ : Fin 3 → ZMod p} (hF : F3 C ξ ≠ 0) {u₁ u₂ u₃ : Fin 3 → ZMod p} (h1 : u₁ ∈ Fiber C 0) (h2 : u₂ ∈ Fiber C 0) (h3 : u₃ ∈ Fiber C 0) : (ξ 0 * u₁ 0 + ξ 1 * u₁ 1 + ξ 2 * u₁ 2) = (ξ 0 * u₂ 0 + ξ 1 * u₂ 1 + ξ 2 * u₂ 2) ∨ (ξ 0 * u₁ 0 + ξ 1 * u₁ 1 + ξ 2 * u₁ 2) = (ξ 0 * u₃ 0 + ξ 1 * u₃ 1 + ξ 2 * u₃ 2) ∨ (ξ 0 * u₂ 0 + ξ 1 * u₂ 1 + ξ 2 * u₂ 2) = (ξ 0 * u₃ 0 + ξ 1 * u₃ 1 + ξ 2 * u₃ 2) := by have hr1 := mem_fiber_fourier h0C h1 (char3 p ξ) have hr2 := mem_fiber_fourier h0C h2 (char3 p ξ) have hr3 := mem_fiber_fourier h0C h3 (char3 p ξ) have htri := unit_circle_re_eq_at_most_two hF ((char3 p ξ).norm_apply u₁) ((char3 p ξ).norm_apply u₂) ((char3 p ξ).norm_apply u₃) (hr1.trans hr2.symm) (hr1.trans hr3.symm) simp only [char3_apply] at htri rcases htri with h | h | h · left; exact e1_injective p h · right; left; exact e1_injective p h · right; right; exact e1_injective p h end CharactersAndObstruction section ThreeCanonicalOrbits variable {p : ℕ} [Fact p.Prime] /-- **Orbit A**: `SA = {000, 001, 010, 011, 100} ⊆ Fiber C 0` is impossible for aperiodic `C`. -/ private lemma absurd_orbit_A (hp3 : 3 ≤ p) {C : Finset (Fin 3 → ZMod p)} (hC : IsAperiodic C) (h0C : (0 : Fin 3 → ZMod p) ∉ C) (h001 : (![0, 0, 1] : Fin 3 → ZMod p) ∈ Fiber C 0) (h010 : (![0, 1, 0] : Fin 3 → ZMod p) ∈ Fiber C 0) (h011 : (![0, 1, 1] : Fin 3 → ZMod p) ∈ Fiber C 0) (h100 : (![1, 0, 0] : Fin 3 → ZMod p) ∈ Fiber C 0) : False := by have h2ne0 : (2 : ZMod p) ≠ 0 := by intro h have hdvd : p ∣ 2 := (ZMod.natCast_eq_zero_iff 2 p).1 (by simpa using h) have hle : p ≤ 2 := Nat.le_of_dvd (by omega) hdvd; omega have h000 : (0 : Fin 3 → ZMod p) ∈ Fiber C 0 := mem_fiber_self C h0C -- Every active `ξ` lies in `{c₁=c₂=0} ∪ {c₀=c₂=0} ∪ {c₀=c₁=0} ∪ {c₀=c₁, c₂=0} ∪ {c₀=c₂, c₁=0}`. have hactive : ∀ ξ : Fin 3 → ZMod p, F3 C ξ ≠ 0 → (ξ 1 = 0 ∧ ξ 2 = 0) ∨ (ξ 0 = 0 ∧ ξ 2 = 0) ∨ (ξ 0 = 0 ∧ ξ 1 = 0) ∨ (ξ 0 = ξ 1 ∧ ξ 2 = 0) ∨ (ξ 0 = ξ 2 ∧ ξ 1 = 0) := by intro ξ hF -- First show `ξ 1 = 0 ∨ ξ 2 = 0` from the 2-face `{000, 010, 001, 011}`! have h12 : ξ 1 = 0 ∨ ξ 2 = 0 := by by_contra hboth; push Not at hboth obtain ⟨h1, h2⟩ := hboth have ht1 := active_dot_at_most_two h0C hF h000 h010 h001 simp only [Pi.zero_apply, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.cons_val_two, Matrix.head_cons, Matrix.tail_cons, mul_zero, mul_one, add_zero, zero_add] at ht1 have heq : ξ 1 = ξ 2 := by rcases ht1 with h | h | h · exact absurd h.symm h1 · exact absurd h.symm h2 · exact h have ht2 := active_dot_at_most_two h0C hF h000 h010 h011 simp only [Pi.zero_apply, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.cons_val_two, Matrix.head_cons, Matrix.tail_cons, mul_zero, mul_one, add_zero, zero_add] at ht2 rcases ht2 with h | h | h · exact h1 h.symm · have h2x : 2 * ξ 1 = 0 := by linear_combination -h + heq exact (mul_eq_zero.1 h2x).elim h2ne0 h1 · exact h2 (by linear_combination -h) rcases h12 with h1z | h2z · -- `ξ 1 = 0`: check `{000, 100, 001}`! have ht := active_dot_at_most_two h0C hF h000 h100 h001 simp only [Pi.zero_apply, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.cons_val_two, Matrix.head_cons, Matrix.tail_cons, mul_zero, mul_one, add_zero, zero_add] at ht rcases ht with h | h | h · right; right; left; exact ⟨h.symm, h1z⟩ · left; exact ⟨h1z, h.symm⟩ · right; right; right; right; exact ⟨h, h1z⟩ · -- `ξ 2 = 0`: check `{000, 100, 010}`! have ht := active_dot_at_most_two h0C hF h000 h100 h010 simp only [Pi.zero_apply, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.cons_val_two, Matrix.head_cons, Matrix.tail_cons, mul_zero, mul_one, add_zero, zero_add] at ht rcases ht with h | h | h · right; left; exact ⟨h.symm, h2z⟩ · left; exact ⟨h.symm, h2z⟩ · right; right; right; left; exact ⟨h, h2z⟩ -- Partition active characters into 5 disjoint sets + `{0}`. let S0 : Finset (Fin 3 → ZMod p) := {0} let S1 : Finset (Fin 3 → ZMod p) := (Finset.univ.erase (0 : ZMod p)).image (fun c => ![c, 0, 0]) let S2 : Finset (Fin 3 → ZMod p) := (Finset.univ.erase (0 : ZMod p)).image (fun c => ![0, c, 0]) let S3 : Finset (Fin 3 → ZMod p) := (Finset.univ.erase (0 : ZMod p)).image (fun c => ![0, 0, c]) let S4 : Finset (Fin 3 → ZMod p) := (Finset.univ.erase (0 : ZMod p)).image (fun c => ![c, c, 0]) let S5 : Finset (Fin 3 → ZMod p) := (Finset.univ.erase (0 : ZMod p)).image (fun c => ![c, 0, c]) -- Helper: check disjointness by coordinate witnesses. have hd01 : Disjoint S0 S1 := by rw [Finset.disjoint_left]; intro ξ h0 h1 rw [Finset.mem_singleton] at h0; subst h0 obtain ⟨c, hc, hce⟩ := Finset.mem_image.1 h1 exact (Finset.mem_erase.1 hc).1 (by simpa using congr_fun hce 0) have hd02 : Disjoint S0 S2 := by rw [Finset.disjoint_left]; intro ξ h0 h2 rw [Finset.mem_singleton] at h0; subst h0 obtain ⟨c, hc, hce⟩ := Finset.mem_image.1 h2 exact (Finset.mem_erase.1 hc).1 (by simpa using congr_fun hce 1) have hd03 : Disjoint S0 S3 := by rw [Finset.disjoint_left]; intro ξ h0 h3 rw [Finset.mem_singleton] at h0; subst h0 obtain ⟨c, hc, hce⟩ := Finset.mem_image.1 h3 exact (Finset.mem_erase.1 hc).1 (by simpa using congr_fun hce 2) have hd04 : Disjoint S0 S4 := by rw [Finset.disjoint_left]; intro ξ h0 h4 rw [Finset.mem_singleton] at h0; subst h0 obtain ⟨c, hc, hce⟩ := Finset.mem_image.1 h4 exact (Finset.mem_erase.1 hc).1 (by simpa using congr_fun hce 0) have hd05 : Disjoint S0 S5 := by rw [Finset.disjoint_left]; intro ξ h0 h5 rw [Finset.mem_singleton] at h0; subst h0 obtain ⟨c, hc, hce⟩ := Finset.mem_image.1 h5 exact (Finset.mem_erase.1 hc).1 (by simpa using congr_fun hce 0) have hd12 : Disjoint S1 S2 := by rw [Finset.disjoint_left]; intro ξ h1 h2 obtain ⟨c₁, hc₁, rfl⟩ := Finset.mem_image.1 h1 obtain ⟨c₂, _, h2'⟩ := Finset.mem_image.1 h2 exact (Finset.mem_erase.1 hc₁).1 (by simpa using (congr_fun h2' 0).symm) have hd13 : Disjoint S1 S3 := by rw [Finset.disjoint_left]; intro ξ h1 h3 obtain ⟨c₁, hc₁, rfl⟩ := Finset.mem_image.1 h1 obtain ⟨c₃, _, h3'⟩ := Finset.mem_image.1 h3 exact (Finset.mem_erase.1 hc₁).1 (by simpa using (congr_fun h3' 0).symm) have hd14 : Disjoint S1 S4 := by rw [Finset.disjoint_left]; intro ξ h1 h4 obtain ⟨c₁, _, rfl⟩ := Finset.mem_image.1 h1 obtain ⟨c₄, hc₄, h4'⟩ := Finset.mem_image.1 h4 exact (Finset.mem_erase.1 hc₄).1 (by simpa using congr_fun h4' 1) have hd15 : Disjoint S1 S5 := by rw [Finset.disjoint_left]; intro ξ h1 h5 obtain ⟨c₁, _, rfl⟩ := Finset.mem_image.1 h1 obtain ⟨c₅, hc₅, h5'⟩ := Finset.mem_image.1 h5 exact (Finset.mem_erase.1 hc₅).1 (by simpa using congr_fun h5' 2) have hd23 : Disjoint S2 S3 := by rw [Finset.disjoint_left]; intro ξ h2 h3 obtain ⟨c₂, hc₂, rfl⟩ := Finset.mem_image.1 h2 obtain ⟨c₃, _, h3'⟩ := Finset.mem_image.1 h3 exact (Finset.mem_erase.1 hc₂).1 (by simpa using (congr_fun h3' 1).symm) have hd24 : Disjoint S2 S4 := by rw [Finset.disjoint_left]; intro ξ h2 h4 obtain ⟨c₂, _, rfl⟩ := Finset.mem_image.1 h2 obtain ⟨c₄, hc₄, h4'⟩ := Finset.mem_image.1 h4 exact (Finset.mem_erase.1 hc₄).1 (by simpa using congr_fun h4' 0) have hd25 : Disjoint S2 S5 := by rw [Finset.disjoint_left]; intro ξ h2 h5 obtain ⟨c₂, _, rfl⟩ := Finset.mem_image.1 h2 obtain ⟨c₅, hc₅, h5'⟩ := Finset.mem_image.1 h5 exact (Finset.mem_erase.1 hc₅).1 (by simpa using congr_fun h5' 0) have hd34 : Disjoint S3 S4 := by rw [Finset.disjoint_left]; intro ξ h3 h4 obtain ⟨c₃, _, rfl⟩ := Finset.mem_image.1 h3 obtain ⟨c₄, hc₄, h4'⟩ := Finset.mem_image.1 h4 exact (Finset.mem_erase.1 hc₄).1 (by simpa using congr_fun h4' 0) have hd35 : Disjoint S3 S5 := by rw [Finset.disjoint_left]; intro ξ h3 h5 obtain ⟨c₃, _, rfl⟩ := Finset.mem_image.1 h3 obtain ⟨c₅, hc₅, h5'⟩ := Finset.mem_image.1 h5 exact (Finset.mem_erase.1 hc₅).1 (by simpa using congr_fun h5' 0) have hd45 : Disjoint S4 S5 := by rw [Finset.disjoint_left]; intro ξ h4 h5 obtain ⟨c₄, hc₄, rfl⟩ := Finset.mem_image.1 h4 obtain ⟨c₅, _, h5'⟩ := Finset.mem_image.1 h5 exact (Finset.mem_erase.1 hc₄).1 (by simpa using (congr_fun h5' 1).symm) let U := S0 ∪ S1 ∪ S2 ∪ S3 ∪ S4 ∪ S5 have hcover : ∀ ξ : Fin 3 → ZMod p, F3 C ξ ≠ 0 → ξ ∈ U := by intro ξ hF have hmem0 : ∀ a b c : ZMod p, ξ = ![a, b, c] → (a = 0 ∧ b = 0 ∧ c = 0) → ξ ∈ U := by rintro a b c rfl ⟨rfl, rfl, rfl⟩ have h0eq : (![0, 0, 0] : Fin 3 → ZMod p) = 0 := by funext i; fin_cases i <;> rfl rw [h0eq]; simp [U, S0] have hξeq : ξ = ![ξ 0, ξ 1, ξ 2] := by funext i; fin_cases i <;> rfl rcases hactive ξ hF with ⟨h1, h2⟩ | ⟨h0, h2⟩ | ⟨h0, h1⟩ | ⟨h01, h2⟩ | ⟨h02, h1⟩ · by_cases h0 : ξ 0 = 0 · exact hmem0 _ _ _ hξeq ⟨h0, h1, h2⟩ · have : ξ ∈ S1 := Finset.mem_image.2 ⟨ξ 0, Finset.mem_erase.2 ⟨h0, Finset.mem_univ _⟩, by funext i; fin_cases i <;> simp [h1, h2]⟩ simp [U, this] · by_cases h1 : ξ 1 = 0 · exact hmem0 _ _ _ hξeq ⟨h0, h1, h2⟩ · have : ξ ∈ S2 := Finset.mem_image.2 ⟨ξ 1, Finset.mem_erase.2 ⟨h1, Finset.mem_univ _⟩, by funext i; fin_cases i <;> simp [h0, h2]⟩ simp [U, this] · by_cases h2 : ξ 2 = 0 · exact hmem0 _ _ _ hξeq ⟨h0, h1, h2⟩ · have : ξ ∈ S3 := Finset.mem_image.2 ⟨ξ 2, Finset.mem_erase.2 ⟨h2, Finset.mem_univ _⟩, by funext i; fin_cases i <;> simp [h0, h1]⟩ simp [U, this] · by_cases h0 : ξ 0 = 0 · exact hmem0 _ _ _ hξeq ⟨h0, h01.symm.trans h0, h2⟩ · have : ξ ∈ S4 := Finset.mem_image.2 ⟨ξ 0, Finset.mem_erase.2 ⟨h0, Finset.mem_univ _⟩, by funext i; fin_cases i <;> simp [h01, h2]⟩ simp [U, this] · by_cases h0 : ξ 0 = 0 · exact hmem0 _ _ _ hξeq ⟨h0, h1, h02.symm.trans h0⟩ · have : ξ ∈ S5 := Finset.mem_image.2 ⟨ξ 0, Finset.mem_erase.2 ⟨h0, Finset.mem_univ _⟩, by funext i; fin_cases i <;> simp [h1, h02]⟩ simp [U, this] let N : ℝ := (p ^ 3 : ℕ) have hNpos : (0 : ℝ) < N := Nat.cast_pos.2 (pow_pos (Fact.out : p.Prime).pos 3) let c₀ : ℝ := N⁻¹ * (F3 C 0).re let f₁ : ZMod p → ℝ := fun x => N⁻¹ * (∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![c, 0, 0] * e1 p (c * x)).re let f₂ : ZMod p → ℝ := fun y => N⁻¹ * (∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![0, c, 0] * e1 p (c * y)).re let f₃ : ZMod p → ℝ := fun z => N⁻¹ * (∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![0, 0, c] * e1 p (c * z)).re let f₄ : ZMod p → ℝ := fun s => N⁻¹ * (∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![c, c, 0] * e1 p (c * s)).re let f₅ : ZMod p → ℝ := fun s => N⁻¹ * (∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![c, 0, c] * e1 p (c * s)).re have hdecomp : ∀ x y z : ZMod p, (indC C ![x, y, z] : ℝ) = c₀ + f₁ x + f₂ y + f₃ z + f₄ (x + y) + f₅ (x + z) := by intro x y z have hinv := fourier_inversion_zmod3 C ![x, y, z] have hsub : ∑ ξ : Fin 3 → ZMod p, F3 C ξ * char3 p ξ ![x, y, z] = ∑ ξ ∈ U, F3 C ξ * char3 p ξ ![x, y, z] := by symm refine Finset.sum_subset (Finset.subset_univ _) fun ξ _ hnot => ?_ have hF0 : F3 C ξ = 0 := by by_contra hne; exact hnot (hcover ξ hne) simp [hF0] rw [hsub] at hinv have hdisj5 : Disjoint (S0 ∪ S1 ∪ S2 ∪ S3 ∪ S4) S5 := by simp only [Finset.disjoint_union_left]; exact ⟨⟨⟨⟨hd05, hd15⟩, hd25⟩, hd35⟩, hd45⟩ have hdisj4 : Disjoint (S0 ∪ S1 ∪ S2 ∪ S3) S4 := by simp only [Finset.disjoint_union_left]; exact ⟨⟨⟨hd04, hd14⟩, hd24⟩, hd34⟩ have hdisj3 : Disjoint (S0 ∪ S1 ∪ S2) S3 := by simp only [Finset.disjoint_union_left]; exact ⟨⟨hd03, hd13⟩, hd23⟩ have hdisj2 : Disjoint (S0 ∪ S1) S2 := by simp only [Finset.disjoint_union_left]; exact ⟨hd02, hd12⟩ dsimp only [U] at hinv rw [Finset.sum_union hdisj5, Finset.sum_union hdisj4, Finset.sum_union hdisj3, Finset.sum_union hdisj2, Finset.sum_union hd01] at hinv have hs0 : ∑ ξ ∈ S0, F3 C ξ * char3 p ξ ![x, y, z] = F3 C 0 := by simp [S0, char3_apply] have hs1 : ∑ ξ ∈ S1, F3 C ξ * char3 p ξ ![x, y, z] = ∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![c, 0, 0] * e1 p (c * x) := by rw [Finset.sum_image (fun a _ b _ h => by simpa using congr_fun h 0)] refine Finset.sum_congr rfl fun c _ => by simp [char3_apply] have hs2 : ∑ ξ ∈ S2, F3 C ξ * char3 p ξ ![x, y, z] = ∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![0, c, 0] * e1 p (c * y) := by rw [Finset.sum_image (fun a _ b _ h => by simpa using congr_fun h 1)] refine Finset.sum_congr rfl fun c _ => by simp [char3_apply] have hs3 : ∑ ξ ∈ S3, F3 C ξ * char3 p ξ ![x, y, z] = ∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![0, 0, c] * e1 p (c * z) := by rw [Finset.sum_image (fun a _ b _ h => by simpa using congr_fun h 2)] refine Finset.sum_congr rfl fun c _ => by simp [char3_apply] have hs4 : ∑ ξ ∈ S4, F3 C ξ * char3 p ξ ![x, y, z] = ∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![c, c, 0] * e1 p (c * (x + y)) := by rw [Finset.sum_image (fun a _ b _ h => by simpa using congr_fun h 0)] refine Finset.sum_congr rfl fun c _ => by simp [char3_apply, mul_add] have hs5 : ∑ ξ ∈ S5, F3 C ξ * char3 p ξ ![x, y, z] = ∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![c, 0, c] * e1 p (c * (x + z)) := by rw [Finset.sum_image (fun a _ b _ h => by simpa using congr_fun h 0)] refine Finset.sum_congr rfl fun c _ => by simp [char3_apply, mul_add] rw [hs0, hs1, hs2, hs3, hs4, hs5] at hinv have hre := congr_arg Complex.re hinv rw [Complex.add_re, Complex.add_re, Complex.add_re, Complex.add_re, Complex.add_re, Complex.mul_re, Complex.natCast_re, Complex.natCast_im, zero_mul, sub_zero, Complex.natCast_re] at hre have hN0 : N ≠ 0 := ne_of_gt hNpos dsimp only [c₀, f₁, f₂, f₃, f₄, f₅] field_simp [hN0] linarith [hre] have hbin : ∀ x y z : ZMod p, c₀ + f₁ x + f₂ y + f₃ z + f₄ (x + y) + f₅ (x + z) = 0 ∨ c₀ + f₁ x + f₂ y + f₃ z + f₄ (x + y) + f₅ (x + z) = 1 := by intro x y z; rw [← hdecomp x y z]; unfold indC; split_ifs <;> simp -- Symmetries `f₁ 1 = f₁ 0`, `f₂ 1 = f₂ 0`, `f₃ 1 = f₃ 0`. have hsym1 : f₁ 1 = f₁ 0 := by have hsing : ∀ c : ZMod p, Pi.single (0 : Fin 3) c = ![c, 0, 0] := fun c => by funext i; fin_cases i <;> rfl have he0 : Pi.single (0 : Fin 3) (1 : ZMod p) ∈ Fiber C 0 := by rw [hsing 1]; exact h100 dsimp only [f₁]; congr 1 simpa only [hsing] using coord_summand_sym h0C 0 he0 have hsym2 : f₂ 1 = f₂ 0 := by have hsing : ∀ c : ZMod p, Pi.single (1 : Fin 3) c = ![0, c, 0] := fun c => by funext i; fin_cases i <;> rfl have he1 : Pi.single (1 : Fin 3) (1 : ZMod p) ∈ Fiber C 0 := by rw [hsing 1]; exact h010 dsimp only [f₂]; congr 1 simpa only [hsing] using coord_summand_sym h0C 1 he1 have hsym3 : f₃ 1 = f₃ 0 := by have hsing : ∀ c : ZMod p, Pi.single (2 : Fin 3) c = ![0, 0, c] := fun c => by funext i; fin_cases i <;> rfl have he2 : Pi.single (2 : Fin 3) (1 : ZMod p) ∈ Fiber C 0 := by rw [hsing 1]; exact h001 dsimp only [f₃]; congr 1 simpa only [hsing] using coord_summand_sym h0C 2 he2 -- Now kill Orbit A cleanly! -- For every `z`, apply `const_or_const_of_symmetric_sum` to `f₂(y) + (f₁(x) + f₅(x + z) + c₀ + f₃(z)) + f₄(y + x)`. by_cases hf2c : ∀ y₁ y₂ : ZMod p, f₂ y₁ = f₂ y₂ · -- Case 1: `f₂` is constant. For fixed `x`, `(y, z) ↦ f₄(x + y) + (f₃(z) + f₅(x + z)) + const ∈ {0, 1}`. by_cases hf4c : ∀ s₁ s₂ : ZMod p, f₄ s₁ = f₄ s₂ · -- Both `f₂` and `f₄` constant ⇒ `(0, 1, 0)` is a period! apply absurd_of_indC_period hC (g := ![0, 1, 0]) (fun h => one_ne_zero (congr_fun h 1)) intro u have hu : u = ![u 0, u 1, u 2] := by funext i; fin_cases i <;> rfl have hug : u + ![0, 1, 0] = ![u 0, u 1 + 1, u 2] := by funext i; fin_cases i <;> simp rw [hug]; conv_rhs => rw [hu] have h1 := hdecomp (u 0) (u 1 + 1) (u 2) have h2 := hdecomp (u 0) (u 1) (u 2) rw [hf2c (u 1 + 1) (u 1), hf4c (u 0 + (u 1 + 1)) (u 0 + u 1)] at h1 exact Nat.cast_injective (h1.trans h2.symm) · -- `f₄` is nonconstant ⇒ for every `x`, `z ↦ f₃(z) + f₅(x + z)` is constant! have hf35 : ∀ x z₁ z₂ : ZMod p, f₃ z₁ + f₅ (x + z₁) = f₃ z₂ + f₅ (x + z₂) := by intro x have hdisj : ∀ y z : ZMod p, f₄ (x + y) + (f₃ z + f₅ (x + z) + c₀ + f₁ x + f₂ 0) = 0 ∨ f₄ (x + y) + (f₃ z + f₅ (x + z) + c₀ + f₁ x + f₂ 0) = 1 := by intro y z rcases hbin x y z with h | h <;> rw [hf2c y 0] at h · left; linarith · right; linarith rcases const_or_const_of_disjoint_sum hdisj with hc4 | hc35 · exfalso; apply hf4c; intro s₁ s₂ have := hc4 (s₁ - x) (s₂ - x); simpa [add_sub_cancel] using this · intro z₁ z₂; have := hc35 z₁ z₂; linarith -- Set `z₁ = 1, z₂ = 0` and use `hsym3 : f₃ 1 = f₃ 0` ⇒ `f₅ (x + 1) = f₅ x`! have hf5c : ∀ s₁ s₂ : ZMod p, f₅ s₁ = f₅ s₂ := const_of_step_one fun x => by have := hf35 x 1 0; rw [hsym3, add_zero] at this; linarith have hf3c : ∀ z₁ z₂ : ZMod p, f₃ z₁ = f₃ z₂ := fun z₁ z₂ => by have := hf35 0 z₁ z₂; rw [hf5c (0 + z₁) (0 + z₂)] at this; linarith -- Both `f₃` and `f₅` constant ⇒ `(0, 0, 1)` is a period! apply absurd_of_indC_period hC (g := ![0, 0, 1]) (fun h => one_ne_zero (congr_fun h 2)) intro u have hu : u = ![u 0, u 1, u 2] := by funext i; fin_cases i <;> rfl have hug : u + ![0, 0, 1] = ![u 0, u 1, u 2 + 1] := by funext i; fin_cases i <;> simp rw [hug]; conv_rhs => rw [hu] have h1 := hdecomp (u 0) (u 1) (u 2 + 1) have h2 := hdecomp (u 0) (u 1) (u 2) rw [hf3c (u 2 + 1) (u 2), hf5c (u 0 + (u 2 + 1)) (u 0 + u 2)] at h1 exact Nat.cast_injective (h1.trans h2.symm) · -- Case 2: `f₂` is nonconstant! Then for every `z`, `x ↦ f₁ x + f₅ (x + z)` is constant! have hf15 : ∀ z x₁ x₂ : ZMod p, f₁ x₁ + f₅ (x₁ + z) = f₁ x₂ + f₅ (x₂ + z) := by intro z have hsym_bin : ∀ y x : ZMod p, f₂ y + (f₁ x + f₅ (x + z) + c₀ + f₃ z) + f₄ (y + x) = 0 ∨ f₂ y + (f₁ x + f₅ (x + z) + c₀ + f₃ z) + f₄ (y + x) = 1 := by intro y x have h := hbin x y z rw [add_comm x y] at h rcases h with h | h <;> [left; right] <;> linarith rcases const_or_const_of_symmetric_sum hsym_bin hsym2 with hc2 | hc15 · exact absurd hc2 hf2c · intro x₁ x₂; have := hc15 x₁ x₂; linarith -- Set `x₁ = 1, x₂ = 0` and use `hsym1 : f₁ 1 = f₁ 0` ⇒ `f₅ (z + 1) = f₅ z`! have hf5c : ∀ s₁ s₂ : ZMod p, f₅ s₁ = f₅ s₂ := const_of_step_one fun z => by have := hf15 z 1 0; rw [hsym1, zero_add, add_comm 1 z] at this; linarith have hf1c : ∀ x₁ x₂ : ZMod p, f₁ x₁ = f₁ x₂ := fun x₁ x₂ => by have := hf15 0 x₁ x₂; rw [hf5c (x₁ + 0) (x₂ + 0)] at this; linarith -- Now `1_C(x, y, z) = f₂ y + f₄ (x + y) + f₃ z + const`! Fix `y = 0`: `f₄ x + f₃ z + const ∈ {0, 1}`. have h43 : ∀ x z : ZMod p, f₄ x + (f₃ z + c₀ + f₁ 0 + f₂ 0 + f₅ 0) = 0 ∨ f₄ x + (f₃ z + c₀ + f₁ 0 + f₂ 0 + f₅ 0) = 1 := by intro x z rcases hbin x 0 z with h | h · rw [hf1c x 0, hf5c (x + z) 0, add_zero] at h; left; linarith · rw [hf1c x 0, hf5c (x + z) 0, add_zero] at h; right; linarith rcases const_or_const_of_disjoint_sum h43 with hf4c | hf3c' · -- `f₁, f₄, f₅` constant ⇒ `(1, 0, 0)` is a period! apply absurd_of_indC_period hC (g := ![1, 0, 0]) (fun h => one_ne_zero (congr_fun h 0)) intro u have hu : u = ![u 0, u 1, u 2] := by funext i; fin_cases i <;> rfl have hug : u + ![1, 0, 0] = ![u 0 + 1, u 1, u 2] := by funext i; fin_cases i <;> simp rw [hug]; conv_rhs => rw [hu] have h1 := hdecomp (u 0 + 1) (u 1) (u 2) have h2 := hdecomp (u 0) (u 1) (u 2) rw [hf1c (u 0 + 1) (u 0), hf4c (u 0 + 1 + u 1) (u 0 + u 1), hf5c (u 0 + 1 + u 2) (u 0 + u 2)] at h1 exact Nat.cast_injective (h1.trans h2.symm) · -- `f₃, f₅` constant ⇒ `(0, 0, 1)` is a period! have hf3c : ∀ z₁ z₂ : ZMod p, f₃ z₁ = f₃ z₂ := fun z₁ z₂ => by have := hf3c' z₁ z₂; linarith apply absurd_of_indC_period hC (g := ![0, 0, 1]) (fun h => one_ne_zero (congr_fun h 2)) intro u have hu : u = ![u 0, u 1, u 2] := by funext i; fin_cases i <;> rfl have hug : u + ![0, 0, 1] = ![u 0, u 1, u 2 + 1] := by funext i; fin_cases i <;> simp rw [hug]; conv_rhs => rw [hu] have h1 := hdecomp (u 0) (u 1) (u 2 + 1) have h2 := hdecomp (u 0) (u 1) (u 2) rw [hf3c (u 2 + 1) (u 2), hf5c (u 0 + (u 2 + 1)) (u 0 + u 2)] at h1 exact Nat.cast_injective (h1.trans h2.symm) /-- **Orbit B**: `SB = {000, 010, 011, 100, 101} ⊆ Fiber C 0` is impossible for aperiodic `C`. -/ private lemma absurd_orbit_B (hp3 : 3 ≤ p) {C : Finset (Fin 3 → ZMod p)} (hC : IsAperiodic C) (h0C : (0 : Fin 3 → ZMod p) ∉ C) (h010 : (![0, 1, 0] : Fin 3 → ZMod p) ∈ Fiber C 0) (h011 : (![0, 1, 1] : Fin 3 → ZMod p) ∈ Fiber C 0) (h100 : (![1, 0, 0] : Fin 3 → ZMod p) ∈ Fiber C 0) (h101 : (![1, 0, 1] : Fin 3 → ZMod p) ∈ Fiber C 0) : False := by have h2ne0 : (2 : ZMod p) ≠ 0 := by intro h have hdvd : p ∣ 2 := (ZMod.natCast_eq_zero_iff 2 p).1 (by simpa using h) have hle : p ≤ 2 := Nat.le_of_dvd (by omega) hdvd; omega have h000 : (0 : Fin 3 → ZMod p) ∈ Fiber C 0 := mem_fiber_self C h0C -- Every active `ξ` lies in `{c₁=c₂=0} ∪ {c₀=c₂=0} ∪ {c₀=c₁=0} ∪ {c₀=c₁, c₂=0} ∪ {c₀=c₁, c₂=-c₀}`. have hactive : ∀ ξ : Fin 3 → ZMod p, F3 C ξ ≠ 0 → (ξ 1 = 0 ∧ ξ 2 = 0) ∨ (ξ 0 = 0 ∧ ξ 2 = 0) ∨ (ξ 0 = 0 ∧ ξ 1 = 0) ∨ (ξ 0 = ξ 1 ∧ ξ 2 = 0) ∨ (ξ 0 = ξ 1 ∧ ξ 2 = -ξ 0) := by intro ξ hF have h01 := active_dot_at_most_two h0C hF h000 h100 h010 simp only [Pi.zero_apply, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.cons_val_two, Matrix.head_cons, Matrix.tail_cons, mul_zero, mul_one, add_zero, zero_add] at h01 rcases h01 with h0z | h1z | h01eq · -- `ξ 0 = 0`: check `{000, 010, 101, 011}` (dot values `0, ξ 1, ξ 2, ξ 1 + ξ 2`)! have h0z' : ξ 0 = 0 := h0z.symm by_cases h1 : ξ 1 = 0 · right; right; left; exact ⟨h0z', h1⟩ · by_cases h2 : ξ 2 = 0 · right; left; exact ⟨h0z', h2⟩ · exfalso have ht1 := active_dot_at_most_two h0C hF h000 h010 h101 simp [h0z'] at ht1 have heq : ξ 1 = ξ 2 := by rcases ht1 with h | h | h · exact absurd h.symm h1 · exact absurd h.symm h2 · exact h have ht2 := active_dot_at_most_two h0C hF h000 h010 h011 simp [h0z'] at ht2 rcases ht2 with h | h | h · exact h1 h.symm · have h2x : 2 * ξ 1 = 0 := by linear_combination -h + heq exact (mul_eq_zero.1 h2x).elim h2ne0 h1 · exact h2 h · -- `ξ 1 = 0`: symmetric using `{000, 100, 011, 101}`! have h1z' : ξ 1 = 0 := h1z.symm by_cases h0 : ξ 0 = 0 · right; right; left; exact ⟨h0, h1z'⟩ · by_cases h2 : ξ 2 = 0 · left; exact ⟨h1z', h2⟩ · exfalso have ht1 := active_dot_at_most_two h0C hF h000 h100 h011 simp [h1z'] at ht1 have heq : ξ 0 = ξ 2 := by rcases ht1 with h | h | h · exact absurd h.symm h0 · exact absurd h.symm h2 · exact h have ht2 := active_dot_at_most_two h0C hF h000 h100 h101 simp [h1z'] at ht2 rcases ht2 with h | h | h · exact h0 h.symm · have h2x : 2 * ξ 0 = 0 := by linear_combination -h + heq exact (mul_eq_zero.1 h2x).elim h2ne0 h0 · exact h2 h · -- `ξ 0 = ξ 1`: check `{000, 100, 101}` (dot values `0, ξ 0, ξ 0 + ξ 2`)! by_cases h0 : ξ 0 = 0 · right; right; left; exact ⟨h0, h01eq.symm.trans h0⟩ · have ht := active_dot_at_most_two h0C hF h000 h100 h101 simp at ht rcases ht with h | h | h · exact absurd h.symm h0 · right; right; right; right; exact ⟨h01eq, by linear_combination -h⟩ · right; right; right; left; exact ⟨h01eq, h⟩ -- Partition into `{0}` and 5 disjoint sets `S1..S5`. let S0 : Finset (Fin 3 → ZMod p) := {0} let S1 : Finset (Fin 3 → ZMod p) := (Finset.univ.erase (0 : ZMod p)).image (fun c => ![c, 0, 0]) let S2 : Finset (Fin 3 → ZMod p) := (Finset.univ.erase (0 : ZMod p)).image (fun c => ![0, c, 0]) let S3 : Finset (Fin 3 → ZMod p) := (Finset.univ.erase (0 : ZMod p)).image (fun c => ![0, 0, c]) let S4 : Finset (Fin 3 → ZMod p) := (Finset.univ.erase (0 : ZMod p)).image (fun c => ![c, c, 0]) let S5 : Finset (Fin 3 → ZMod p) := (Finset.univ.erase (0 : ZMod p)).image (fun c => ![c, c, -c]) have hd01 : Disjoint S0 S1 := by rw [Finset.disjoint_left]; intro ξ h0 h1; rw [Finset.mem_singleton] at h0; subst h0 obtain ⟨c, hc, hce⟩ := Finset.mem_image.1 h1 exact (Finset.mem_erase.1 hc).1 (by simpa using congr_fun hce 0) have hd02 : Disjoint S0 S2 := by rw [Finset.disjoint_left]; intro ξ h0 h2; rw [Finset.mem_singleton] at h0; subst h0 obtain ⟨c, hc, hce⟩ := Finset.mem_image.1 h2 exact (Finset.mem_erase.1 hc).1 (by simpa using congr_fun hce 1) have hd03 : Disjoint S0 S3 := by rw [Finset.disjoint_left]; intro ξ h0 h3; rw [Finset.mem_singleton] at h0; subst h0 obtain ⟨c, hc, hce⟩ := Finset.mem_image.1 h3 exact (Finset.mem_erase.1 hc).1 (by simpa using congr_fun hce 2) have hd04 : Disjoint S0 S4 := by rw [Finset.disjoint_left]; intro ξ h0 h4; rw [Finset.mem_singleton] at h0; subst h0 obtain ⟨c, hc, hce⟩ := Finset.mem_image.1 h4 exact (Finset.mem_erase.1 hc).1 (by simpa using congr_fun hce 0) have hd05 : Disjoint S0 S5 := by rw [Finset.disjoint_left]; intro ξ h0 h5; rw [Finset.mem_singleton] at h0; subst h0 obtain ⟨c, hc, hce⟩ := Finset.mem_image.1 h5 exact (Finset.mem_erase.1 hc).1 (by simpa using congr_fun hce 0) have hd12 : Disjoint S1 S2 := by rw [Finset.disjoint_left]; intro ξ h1 h2 obtain ⟨c₁, hc₁, rfl⟩ := Finset.mem_image.1 h1 obtain ⟨c₂, _, h2'⟩ := Finset.mem_image.1 h2 exact (Finset.mem_erase.1 hc₁).1 (by simpa using (congr_fun h2' 0).symm) have hd13 : Disjoint S1 S3 := by rw [Finset.disjoint_left]; intro ξ h1 h3 obtain ⟨c₁, hc₁, rfl⟩ := Finset.mem_image.1 h1 obtain ⟨c₃, _, h3'⟩ := Finset.mem_image.1 h3 exact (Finset.mem_erase.1 hc₁).1 (by simpa using (congr_fun h3' 0).symm) have hd14 : Disjoint S1 S4 := by rw [Finset.disjoint_left]; intro ξ h1 h4 obtain ⟨c₁, _, rfl⟩ := Finset.mem_image.1 h1 obtain ⟨c₄, hc₄, h4'⟩ := Finset.mem_image.1 h4 exact (Finset.mem_erase.1 hc₄).1 (by simpa using congr_fun h4' 1) have hd15 : Disjoint S1 S5 := by rw [Finset.disjoint_left]; intro ξ h1 h5 obtain ⟨c₁, _, rfl⟩ := Finset.mem_image.1 h1 obtain ⟨c₅, hc₅, h5'⟩ := Finset.mem_image.1 h5 exact (Finset.mem_erase.1 hc₅).1 (by simpa using congr_fun h5' 1) have hd23 : Disjoint S2 S3 := by rw [Finset.disjoint_left]; intro ξ h2 h3 obtain ⟨c₂, hc₂, rfl⟩ := Finset.mem_image.1 h2 obtain ⟨c₃, _, h3'⟩ := Finset.mem_image.1 h3 exact (Finset.mem_erase.1 hc₂).1 (by simpa using (congr_fun h3' 1).symm) have hd24 : Disjoint S2 S4 := by rw [Finset.disjoint_left]; intro ξ h2 h4 obtain ⟨c₂, _, rfl⟩ := Finset.mem_image.1 h2 obtain ⟨c₄, hc₄, h4'⟩ := Finset.mem_image.1 h4 exact (Finset.mem_erase.1 hc₄).1 (by simpa using congr_fun h4' 0) have hd25 : Disjoint S2 S5 := by rw [Finset.disjoint_left]; intro ξ h2 h5 obtain ⟨c₂, _, rfl⟩ := Finset.mem_image.1 h2 obtain ⟨c₅, hc₅, h5'⟩ := Finset.mem_image.1 h5 exact (Finset.mem_erase.1 hc₅).1 (by simpa using congr_fun h5' 0) have hd34 : Disjoint S3 S4 := by rw [Finset.disjoint_left]; intro ξ h3 h4 obtain ⟨c₃, _, rfl⟩ := Finset.mem_image.1 h3 obtain ⟨c₄, hc₄, h4'⟩ := Finset.mem_image.1 h4 exact (Finset.mem_erase.1 hc₄).1 (by simpa using congr_fun h4' 0) have hd35 : Disjoint S3 S5 := by rw [Finset.disjoint_left]; intro ξ h3 h5 obtain ⟨c₃, _, rfl⟩ := Finset.mem_image.1 h3 obtain ⟨c₅, hc₅, h5'⟩ := Finset.mem_image.1 h5 exact (Finset.mem_erase.1 hc₅).1 (by simpa using congr_fun h5' 0) have hd45 : Disjoint S4 S5 := by rw [Finset.disjoint_left]; intro ξ h4 h5 obtain ⟨c₄, _, rfl⟩ := Finset.mem_image.1 h4 obtain ⟨c₅, hc₅, h5'⟩ := Finset.mem_image.1 h5 exact (Finset.mem_erase.1 hc₅).1 (neg_eq_zero.1 (by simpa using congr_fun h5' 2)) let U := S0 ∪ S1 ∪ S2 ∪ S3 ∪ S4 ∪ S5 have hcover : ∀ ξ : Fin 3 → ZMod p, F3 C ξ ≠ 0 → ξ ∈ U := by intro ξ hF have hmem0 : ∀ a b c : ZMod p, ξ = ![a, b, c] → (a = 0 ∧ b = 0 ∧ c = 0) → ξ ∈ U := by rintro a b c rfl ⟨rfl, rfl, rfl⟩ have h0eq : (![0, 0, 0] : Fin 3 → ZMod p) = 0 := by funext i; fin_cases i <;> rfl rw [h0eq]; simp [U, S0] have hξeq : ξ = ![ξ 0, ξ 1, ξ 2] := by funext i; fin_cases i <;> rfl rcases hactive ξ hF with ⟨h1, h2⟩ | ⟨h0, h2⟩ | ⟨h0, h1⟩ | ⟨h01, h2⟩ | ⟨h01, h2⟩ · by_cases h0 : ξ 0 = 0 · exact hmem0 _ _ _ hξeq ⟨h0, h1, h2⟩ · have : ξ ∈ S1 := Finset.mem_image.2 ⟨ξ 0, Finset.mem_erase.2 ⟨h0, Finset.mem_univ _⟩, by funext i; fin_cases i <;> simp [h1, h2]⟩ simp [U, this] · by_cases h1 : ξ 1 = 0 · exact hmem0 _ _ _ hξeq ⟨h0, h1, h2⟩ · have : ξ ∈ S2 := Finset.mem_image.2 ⟨ξ 1, Finset.mem_erase.2 ⟨h1, Finset.mem_univ _⟩, by funext i; fin_cases i <;> simp [h0, h2]⟩ simp [U, this] · by_cases h2 : ξ 2 = 0 · exact hmem0 _ _ _ hξeq ⟨h0, h1, h2⟩ · have : ξ ∈ S3 := Finset.mem_image.2 ⟨ξ 2, Finset.mem_erase.2 ⟨h2, Finset.mem_univ _⟩, by funext i; fin_cases i <;> simp [h0, h1]⟩ simp [U, this] · by_cases h0 : ξ 0 = 0 · exact hmem0 _ _ _ hξeq ⟨h0, h01.symm.trans h0, h2⟩ · have : ξ ∈ S4 := Finset.mem_image.2 ⟨ξ 0, Finset.mem_erase.2 ⟨h0, Finset.mem_univ _⟩, by funext i; fin_cases i <;> simp [h01, h2]⟩ simp [U, this] · by_cases h0 : ξ 0 = 0 · exact hmem0 _ _ _ hξeq ⟨h0, h01.symm.trans h0, by rw [h2, h0, neg_zero]⟩ · have : ξ ∈ S5 := Finset.mem_image.2 ⟨ξ 0, Finset.mem_erase.2 ⟨h0, Finset.mem_univ _⟩, by funext i; fin_cases i <;> simp [h01, h2]⟩ simp [U, this] let N : ℝ := (p ^ 3 : ℕ) have hNpos : (0 : ℝ) < N := Nat.cast_pos.2 (pow_pos (Fact.out : p.Prime).pos 3) let c₀ : ℝ := N⁻¹ * (F3 C 0).re let f₁ : ZMod p → ℝ := fun x => N⁻¹ * (∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![c, 0, 0] * e1 p (c * x)).re let f₂ : ZMod p → ℝ := fun y => N⁻¹ * (∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![0, c, 0] * e1 p (c * y)).re let f₃ : ZMod p → ℝ := fun z => N⁻¹ * (∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![0, 0, c] * e1 p (c * z)).re let f₄ : ZMod p → ℝ := fun s => N⁻¹ * (∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![c, c, 0] * e1 p (c * s)).re let f₅ : ZMod p → ℝ := fun s => N⁻¹ * (∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![c, c, -c] * e1 p (c * s)).re have hdecomp : ∀ x y z : ZMod p, (indC C ![x, y, z] : ℝ) = c₀ + f₁ x + f₂ y + f₃ z + f₄ (x + y) + f₅ (x + y - z) := by intro x y z have hinv := fourier_inversion_zmod3 C ![x, y, z] have hsub : ∑ ξ : Fin 3 → ZMod p, F3 C ξ * char3 p ξ ![x, y, z] = ∑ ξ ∈ U, F3 C ξ * char3 p ξ ![x, y, z] := by symm refine Finset.sum_subset (Finset.subset_univ _) fun ξ _ hnot => ?_ have hF0 : F3 C ξ = 0 := by by_contra hne; exact hnot (hcover ξ hne) simp [hF0] rw [hsub] at hinv have hdisj5 : Disjoint (S0 ∪ S1 ∪ S2 ∪ S3 ∪ S4) S5 := by simp only [Finset.disjoint_union_left]; exact ⟨⟨⟨⟨hd05, hd15⟩, hd25⟩, hd35⟩, hd45⟩ have hdisj4 : Disjoint (S0 ∪ S1 ∪ S2 ∪ S3) S4 := by simp only [Finset.disjoint_union_left]; exact ⟨⟨⟨hd04, hd14⟩, hd24⟩, hd34⟩ have hdisj3 : Disjoint (S0 ∪ S1 ∪ S2) S3 := by simp only [Finset.disjoint_union_left]; exact ⟨⟨hd03, hd13⟩, hd23⟩ have hdisj2 : Disjoint (S0 ∪ S1) S2 := by simp only [Finset.disjoint_union_left]; exact ⟨hd02, hd12⟩ dsimp only [U] at hinv rw [Finset.sum_union hdisj5, Finset.sum_union hdisj4, Finset.sum_union hdisj3, Finset.sum_union hdisj2, Finset.sum_union hd01] at hinv have hs0 : ∑ ξ ∈ S0, F3 C ξ * char3 p ξ ![x, y, z] = F3 C 0 := by simp [S0, char3_apply] have hs1 : ∑ ξ ∈ S1, F3 C ξ * char3 p ξ ![x, y, z] = ∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![c, 0, 0] * e1 p (c * x) := by rw [Finset.sum_image (fun a _ b _ h => by simpa using congr_fun h 0)] refine Finset.sum_congr rfl fun c _ => by simp [char3_apply] have hs2 : ∑ ξ ∈ S2, F3 C ξ * char3 p ξ ![x, y, z] = ∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![0, c, 0] * e1 p (c * y) := by rw [Finset.sum_image (fun a _ b _ h => by simpa using congr_fun h 1)] refine Finset.sum_congr rfl fun c _ => by simp [char3_apply] have hs3 : ∑ ξ ∈ S3, F3 C ξ * char3 p ξ ![x, y, z] = ∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![0, 0, c] * e1 p (c * z) := by rw [Finset.sum_image (fun a _ b _ h => by simpa using congr_fun h 2)] refine Finset.sum_congr rfl fun c _ => by simp [char3_apply] have hs4 : ∑ ξ ∈ S4, F3 C ξ * char3 p ξ ![x, y, z] = ∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![c, c, 0] * e1 p (c * (x + y)) := by rw [Finset.sum_image (fun a _ b _ h => by simpa using congr_fun h 0)] refine Finset.sum_congr rfl fun c _ => by simp [char3_apply, mul_add] have hs5 : ∑ ξ ∈ S5, F3 C ξ * char3 p ξ ![x, y, z] = ∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![c, c, -c] * e1 p (c * (x + y - z)) := by rw [Finset.sum_image (fun a _ b _ h => by simpa using congr_fun h 0)] refine Finset.sum_congr rfl fun c _ => by simp only [char3_apply, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.cons_val_two, Matrix.head_cons, Matrix.tail_cons] congr 2; ring rw [hs0, hs1, hs2, hs3, hs4, hs5] at hinv have hre := congr_arg Complex.re hinv rw [Complex.add_re, Complex.add_re, Complex.add_re, Complex.add_re, Complex.add_re, Complex.mul_re, Complex.natCast_re, Complex.natCast_im, zero_mul, sub_zero, Complex.natCast_re] at hre have hN0 : N ≠ 0 := ne_of_gt hNpos dsimp only [c₀, f₁, f₂, f₃, f₄, f₅] field_simp [hN0] linarith [hre] have hbin : ∀ x y z : ZMod p, c₀ + f₁ x + f₂ y + f₃ z + f₄ (x + y) + f₅ (x + y - z) = 0 ∨ c₀ + f₁ x + f₂ y + f₃ z + f₄ (x + y) + f₅ (x + y - z) = 1 := by intro x y z; rw [← hdecomp x y z]; unfold indC; split_ifs <;> simp have hsym1 : f₁ 1 = f₁ 0 := by have hsing : ∀ c : ZMod p, Pi.single (0 : Fin 3) c = ![c, 0, 0] := fun c => by funext i; fin_cases i <;> rfl have he0 : Pi.single (0 : Fin 3) (1 : ZMod p) ∈ Fiber C 0 := by rw [hsing 1]; exact h100 dsimp only [f₁]; congr 1 simpa only [hsing] using coord_summand_sym h0C 0 he0 -- Fix `z = 0`: `f₁ x + f₂ y + (c₀ + f₃ 0 + f₄ (x + y) + f₅ (x + y)) ∈ {0, 1}` with `f₁ 1 = f₁ 0`! have h12_const : (∀ x₁ x₂, f₁ x₁ = f₁ x₂) ∨ (∀ y₁ y₂, f₂ y₁ = f₂ y₂) := by apply const_or_const_of_symmetric_sum (f₃ := fun s => c₀ + f₃ 0 + f₄ s + f₅ s) _ hsym1 intro x y rcases hbin x y 0 with h | h <;> rw [sub_zero] at h <;> [left; right] <;> linarith rcases h12_const with hf1c | hf2c · -- `f₁` constant ⇒ substitute `x = s - y`: `f₂ y + [c₀ + f₁ 0 + f₃ z + f₄ s + f₅ (s - z)] ∈ {0, 1}`! have hdisj : ∀ (y : ZMod p) (sz : ZMod p × ZMod p), f₂ y + (c₀ + f₁ 0 + f₃ sz.2 + f₄ sz.1 + f₅ (sz.1 - sz.2)) = 0 ∨ f₂ y + (c₀ + f₁ 0 + f₃ sz.2 + f₄ sz.1 + f₅ (sz.1 - sz.2)) = 1 := by intro y ⟨s, z⟩ have h := hbin (s - y) y z rw [hf1c (s - y) 0, sub_add_cancel] at h rcases h with h | h <;> [left; right] <;> linarith rcases const_or_const_of_disjoint_sum hdisj with hf2c | hrest · -- Both `f₁` and `f₂` constant ⇒ `(1, -1, 0)` is a period! apply absurd_of_indC_period hC (g := ![1, -1, 0]) (fun h => one_ne_zero (congr_fun h 0)) intro u have hu : u = ![u 0, u 1, u 2] := by funext i; fin_cases i <;> rfl have hug : u + ![1, -1, 0] = ![u 0 + 1, u 1 + -1, u 2] := by funext i; fin_cases i <;> simp rw [hug]; conv_rhs => rw [hu] have h1 := hdecomp (u 0 + 1) (u 1 + -1) (u 2) have h2 := hdecomp (u 0) (u 1) (u 2) have hsum : u 0 + 1 + (u 1 + -1) = u 0 + u 1 := by ring rw [hsum, hf1c (u 0 + 1) (u 0), hf2c (u 1 + -1) (u 1)] at h1 exact Nat.cast_injective (h1.trans h2.symm) · -- Rest constant ⇒ `1_C(x, y, z) = f₂ y + const`, so `(1, 0, 0)` is a period! apply absurd_of_indC_period hC (g := ![1, 0, 0]) (fun h => one_ne_zero (congr_fun h 0)) intro u have hu : u = ![u 0, u 1, u 2] := by funext i; fin_cases i <;> rfl have hug : u + ![1, 0, 0] = ![u 0 + 1, u 1, u 2] := by funext i; fin_cases i <;> simp rw [hug]; conv_rhs => rw [hu] have h1 := hdecomp (u 0 + 1) (u 1) (u 2) have h2 := hdecomp (u 0) (u 1) (u 2) have hr := hrest (u 0 + 1 + u 1, u 2) (u 0 + u 1, u 2) rw [hf1c (u 0 + 1) (u 0)] at h1 have h12 : (indC C ![u 0 + 1, u 1, u 2] : ℝ) = (indC C ![u 0, u 1, u 2] : ℝ) := by linarith exact Nat.cast_injective h12 · -- `f₂` constant: symmetric! Substitute `y = s - x`! have hdisj : ∀ (x : ZMod p) (sz : ZMod p × ZMod p), f₁ x + (c₀ + f₂ 0 + f₃ sz.2 + f₄ sz.1 + f₅ (sz.1 - sz.2)) = 0 ∨ f₁ x + (c₀ + f₂ 0 + f₃ sz.2 + f₄ sz.1 + f₅ (sz.1 - sz.2)) = 1 := by intro x ⟨s, z⟩ have h := hbin x (s - x) z rw [hf2c (s - x) 0, add_sub_cancel] at h rcases h with h | h <;> [left; right] <;> linarith rcases const_or_const_of_disjoint_sum hdisj with hf1c | hrest · apply absurd_of_indC_period hC (g := ![1, -1, 0]) (fun h => one_ne_zero (congr_fun h 0)) intro u have hu : u = ![u 0, u 1, u 2] := by funext i; fin_cases i <;> rfl have hug : u + ![1, -1, 0] = ![u 0 + 1, u 1 + -1, u 2] := by funext i; fin_cases i <;> simp rw [hug]; conv_rhs => rw [hu] have h1 := hdecomp (u 0 + 1) (u 1 + -1) (u 2) have h2 := hdecomp (u 0) (u 1) (u 2) have hsum : u 0 + 1 + (u 1 + -1) = u 0 + u 1 := by ring rw [hsum, hf1c (u 0 + 1) (u 0), hf2c (u 1 + -1) (u 1)] at h1 exact Nat.cast_injective (h1.trans h2.symm) · apply absurd_of_indC_period hC (g := ![0, 1, 0]) (fun h => one_ne_zero (congr_fun h 1)) intro u have hu : u = ![u 0, u 1, u 2] := by funext i; fin_cases i <;> rfl have hug : u + ![0, 1, 0] = ![u 0, u 1 + 1, u 2] := by funext i; fin_cases i <;> simp rw [hug]; conv_rhs => rw [hu] have h1 := hdecomp (u 0) (u 1 + 1) (u 2) have h2 := hdecomp (u 0) (u 1) (u 2) have hr := hrest (u 0 + (u 1 + 1), u 2) (u 0 + u 1, u 2) rw [hf2c (u 1 + 1) (u 1)] at h1 have h12 : (indC C ![u 0, u 1 + 1, u 2] : ℝ) = (indC C ![u 0, u 1, u 2] : ℝ) := by linarith exact Nat.cast_injective h12 /-- **Orbit C**: `SC = {000, 001, 010, 100, 111} ⊆ Fiber C 0` is impossible for aperiodic `C`. -/ private lemma absurd_orbit_C (hp3 : 3 ≤ p) {C : Finset (Fin 3 → ZMod p)} (hC : IsAperiodic C) (h0C : (0 : Fin 3 → ZMod p) ∉ C) (h001 : (![0, 0, 1] : Fin 3 → ZMod p) ∈ Fiber C 0) (h010 : (![0, 1, 0] : Fin 3 → ZMod p) ∈ Fiber C 0) (h100 : (![1, 0, 0] : Fin 3 → ZMod p) ∈ Fiber C 0) (h111 : (![1, 1, 1] : Fin 3 → ZMod p) ∈ Fiber C 0) : False := by have h2ne0 : (2 : ZMod p) ≠ 0 := by intro h have hdvd : p ∣ 2 := (ZMod.natCast_eq_zero_iff 2 p).1 (by simpa using h) have hle : p ≤ 2 := Nat.le_of_dvd (by omega) hdvd; omega have h000 : (0 : Fin 3 → ZMod p) ∈ Fiber C 0 := mem_fiber_self C h0C -- Every active `ξ` lies in `{c₁=c₂=0} ∪ {c₀=c₂=0} ∪ {c₀=c₁=0} ∪ {c₀=c₁=c₂}`. have hactive : ∀ ξ : Fin 3 → ZMod p, F3 C ξ ≠ 0 → (ξ 1 = 0 ∧ ξ 2 = 0) ∨ (ξ 0 = 0 ∧ ξ 2 = 0) ∨ (ξ 0 = 0 ∧ ξ 1 = 0) ∨ (ξ 0 = ξ 1 ∧ ξ 0 = ξ 2) := by intro ξ hF have h01 := active_dot_at_most_two h0C hF h000 h100 h010 have h02 := active_dot_at_most_two h0C hF h000 h100 h001 have h12 := active_dot_at_most_two h0C hF h000 h010 h001 simp only [Pi.zero_apply, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.cons_val_two, Matrix.head_cons, Matrix.tail_cons, mul_zero, mul_one, add_zero, zero_add] at h01 h02 h12 by_cases h0 : ξ 0 = 0 · by_cases h1 : ξ 1 = 0 · right; right; left; exact ⟨h0, h1⟩ · by_cases h2 : ξ 2 = 0 · right; left; exact ⟨h0, h2⟩ · exfalso have h12eq : ξ 1 = ξ 2 := by rcases h12 with h | h | h · exact absurd h.symm h1 · exact absurd h.symm h2 · exact h have ht := active_dot_at_most_two h0C hF h000 h010 h111 simp [h0] at ht rcases ht with h | h | h · exact h1 h.symm · exact (mul_eq_zero.1 (by linear_combination -h + h12eq : 2 * ξ 1 = 0)).elim h2ne0 h1 · exact h2 h · by_cases h1 : ξ 1 = 0 · by_cases h2 : ξ 2 = 0 · left; exact ⟨h1, h2⟩ · exfalso have h02eq : ξ 0 = ξ 2 := by rcases h02 with h | h | h · exact absurd h.symm h0 · exact absurd h.symm h2 · exact h have ht := active_dot_at_most_two h0C hF h000 h100 h111 simp [h1] at ht rcases ht with h | h | h · exact h0 h.symm · exact (mul_eq_zero.1 (by linear_combination -h + h02eq : 2 * ξ 0 = 0)).elim h2ne0 h0 · exact h2 h · have h01eq : ξ 0 = ξ 1 := by rcases h01 with h | h | h · exact absurd h.symm h0 · exact absurd h.symm h1 · exact h by_cases h2 : ξ 2 = 0 · exfalso have ht := active_dot_at_most_two h0C hF h000 h100 h111 simp [h2] at ht rcases ht with h | h | h · exact h0 h.symm · exact (mul_eq_zero.1 (by linear_combination -h + h01eq : 2 * ξ 0 = 0)).elim h2ne0 h0 · exact h1 h · have h02eq : ξ 0 = ξ 2 := by rcases h02 with h | h | h · exact absurd h.symm h0 · exact absurd h.symm h2 · exact h right; right; right; exact ⟨h01eq, h02eq⟩ let S0 : Finset (Fin 3 → ZMod p) := {0} let S1 : Finset (Fin 3 → ZMod p) := (Finset.univ.erase (0 : ZMod p)).image (fun c => ![c, 0, 0]) let S2 : Finset (Fin 3 → ZMod p) := (Finset.univ.erase (0 : ZMod p)).image (fun c => ![0, c, 0]) let S3 : Finset (Fin 3 → ZMod p) := (Finset.univ.erase (0 : ZMod p)).image (fun c => ![0, 0, c]) let S4 : Finset (Fin 3 → ZMod p) := (Finset.univ.erase (0 : ZMod p)).image (fun c => ![c, c, c]) have hd01 : Disjoint S0 S1 := by rw [Finset.disjoint_left]; intro ξ h0 h1; rw [Finset.mem_singleton] at h0; subst h0 obtain ⟨c, hc, hce⟩ := Finset.mem_image.1 h1 exact (Finset.mem_erase.1 hc).1 (by simpa using congr_fun hce 0) have hd02 : Disjoint S0 S2 := by rw [Finset.disjoint_left]; intro ξ h0 h2; rw [Finset.mem_singleton] at h0; subst h0 obtain ⟨c, hc, hce⟩ := Finset.mem_image.1 h2 exact (Finset.mem_erase.1 hc).1 (by simpa using congr_fun hce 1) have hd03 : Disjoint S0 S3 := by rw [Finset.disjoint_left]; intro ξ h0 h3; rw [Finset.mem_singleton] at h0; subst h0 obtain ⟨c, hc, hce⟩ := Finset.mem_image.1 h3 exact (Finset.mem_erase.1 hc).1 (by simpa using congr_fun hce 2) have hd04 : Disjoint S0 S4 := by rw [Finset.disjoint_left]; intro ξ h0 h4; rw [Finset.mem_singleton] at h0; subst h0 obtain ⟨c, hc, hce⟩ := Finset.mem_image.1 h4 exact (Finset.mem_erase.1 hc).1 (by simpa using congr_fun hce 0) have hd12 : Disjoint S1 S2 := by rw [Finset.disjoint_left]; intro ξ h1 h2 obtain ⟨c₁, hc₁, rfl⟩ := Finset.mem_image.1 h1 obtain ⟨c₂, _, h2'⟩ := Finset.mem_image.1 h2 exact (Finset.mem_erase.1 hc₁).1 (by simpa using (congr_fun h2' 0).symm) have hd13 : Disjoint S1 S3 := by rw [Finset.disjoint_left]; intro ξ h1 h3 obtain ⟨c₁, hc₁, rfl⟩ := Finset.mem_image.1 h1 obtain ⟨c₃, _, h3'⟩ := Finset.mem_image.1 h3 exact (Finset.mem_erase.1 hc₁).1 (by simpa using (congr_fun h3' 0).symm) have hd14 : Disjoint S1 S4 := by rw [Finset.disjoint_left]; intro ξ h1 h4 obtain ⟨c₁, _, rfl⟩ := Finset.mem_image.1 h1 obtain ⟨c₄, hc₄, h4'⟩ := Finset.mem_image.1 h4 exact (Finset.mem_erase.1 hc₄).1 (by simpa using congr_fun h4' 1) have hd23 : Disjoint S2 S3 := by rw [Finset.disjoint_left]; intro ξ h2 h3 obtain ⟨c₂, hc₂, rfl⟩ := Finset.mem_image.1 h2 obtain ⟨c₃, _, h3'⟩ := Finset.mem_image.1 h3 exact (Finset.mem_erase.1 hc₂).1 (by simpa using (congr_fun h3' 1).symm) have hd24 : Disjoint S2 S4 := by rw [Finset.disjoint_left]; intro ξ h2 h4 obtain ⟨c₂, _, rfl⟩ := Finset.mem_image.1 h2 obtain ⟨c₄, hc₄, h4'⟩ := Finset.mem_image.1 h4 exact (Finset.mem_erase.1 hc₄).1 (by simpa using congr_fun h4' 0) have hd34 : Disjoint S3 S4 := by rw [Finset.disjoint_left]; intro ξ h3 h4 obtain ⟨c₃, _, rfl⟩ := Finset.mem_image.1 h3 obtain ⟨c₄, hc₄, h4'⟩ := Finset.mem_image.1 h4 exact (Finset.mem_erase.1 hc₄).1 (by simpa using congr_fun h4' 0) let U := S0 ∪ S1 ∪ S2 ∪ S3 ∪ S4 have hcover : ∀ ξ : Fin 3 → ZMod p, F3 C ξ ≠ 0 → ξ ∈ U := by intro ξ hF have hmem0 : ∀ a b c : ZMod p, ξ = ![a, b, c] → (a = 0 ∧ b = 0 ∧ c = 0) → ξ ∈ U := by rintro a b c rfl ⟨rfl, rfl, rfl⟩ have h0eq : (![0, 0, 0] : Fin 3 → ZMod p) = 0 := by funext i; fin_cases i <;> rfl rw [h0eq]; simp [U, S0] have hξeq : ξ = ![ξ 0, ξ 1, ξ 2] := by funext i; fin_cases i <;> rfl rcases hactive ξ hF with ⟨h1, h2⟩ | ⟨h0, h2⟩ | ⟨h0, h1⟩ | ⟨h01, h02⟩ · by_cases h0 : ξ 0 = 0 · exact hmem0 _ _ _ hξeq ⟨h0, h1, h2⟩ · have : ξ ∈ S1 := Finset.mem_image.2 ⟨ξ 0, Finset.mem_erase.2 ⟨h0, Finset.mem_univ _⟩, by funext i; fin_cases i <;> simp [h1, h2]⟩ simp [U, this] · by_cases h1 : ξ 1 = 0 · exact hmem0 _ _ _ hξeq ⟨h0, h1, h2⟩ · have : ξ ∈ S2 := Finset.mem_image.2 ⟨ξ 1, Finset.mem_erase.2 ⟨h1, Finset.mem_univ _⟩, by funext i; fin_cases i <;> simp [h0, h2]⟩ simp [U, this] · by_cases h2 : ξ 2 = 0 · exact hmem0 _ _ _ hξeq ⟨h0, h1, h2⟩ · have : ξ ∈ S3 := Finset.mem_image.2 ⟨ξ 2, Finset.mem_erase.2 ⟨h2, Finset.mem_univ _⟩, by funext i; fin_cases i <;> simp [h0, h1]⟩ simp [U, this] · by_cases h0 : ξ 0 = 0 · exact hmem0 _ _ _ hξeq ⟨h0, h01.symm.trans h0, h02.symm.trans h0⟩ · have : ξ ∈ S4 := Finset.mem_image.2 ⟨ξ 0, Finset.mem_erase.2 ⟨h0, Finset.mem_univ _⟩, by funext i; fin_cases i <;> simp [← h01, ← h02]⟩ simp [U, this] let N : ℝ := (p ^ 3 : ℕ) have hNpos : (0 : ℝ) < N := Nat.cast_pos.2 (pow_pos (Fact.out : p.Prime).pos 3) let c₀ : ℝ := N⁻¹ * (F3 C 0).re let f₁ : ZMod p → ℝ := fun x => N⁻¹ * (∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![c, 0, 0] * e1 p (c * x)).re let f₂ : ZMod p → ℝ := fun y => N⁻¹ * (∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![0, c, 0] * e1 p (c * y)).re let f₃ : ZMod p → ℝ := fun z => N⁻¹ * (∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![0, 0, c] * e1 p (c * z)).re let f₄ : ZMod p → ℝ := fun s => N⁻¹ * (∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![c, c, c] * e1 p (c * s)).re have hdecomp : ∀ x y z : ZMod p, (indC C ![x, y, z] : ℝ) = c₀ + f₁ x + f₂ y + f₃ z + f₄ (x + y + z) := by intro x y z have hinv := fourier_inversion_zmod3 C ![x, y, z] have hsub : ∑ ξ : Fin 3 → ZMod p, F3 C ξ * char3 p ξ ![x, y, z] = ∑ ξ ∈ U, F3 C ξ * char3 p ξ ![x, y, z] := by symm refine Finset.sum_subset (Finset.subset_univ _) fun ξ _ hnot => ?_ have hF0 : F3 C ξ = 0 := by by_contra hne; exact hnot (hcover ξ hne) simp [hF0] rw [hsub] at hinv have hdisj4 : Disjoint (S0 ∪ S1 ∪ S2 ∪ S3) S4 := by simp only [Finset.disjoint_union_left]; exact ⟨⟨⟨hd04, hd14⟩, hd24⟩, hd34⟩ have hdisj3 : Disjoint (S0 ∪ S1 ∪ S2) S3 := by simp only [Finset.disjoint_union_left]; exact ⟨⟨hd03, hd13⟩, hd23⟩ have hdisj2 : Disjoint (S0 ∪ S1) S2 := by simp only [Finset.disjoint_union_left]; exact ⟨hd02, hd12⟩ dsimp only [U] at hinv rw [Finset.sum_union hdisj4, Finset.sum_union hdisj3, Finset.sum_union hdisj2, Finset.sum_union hd01] at hinv have hs0 : ∑ ξ ∈ S0, F3 C ξ * char3 p ξ ![x, y, z] = F3 C 0 := by simp [S0, char3_apply] have hs1 : ∑ ξ ∈ S1, F3 C ξ * char3 p ξ ![x, y, z] = ∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![c, 0, 0] * e1 p (c * x) := by rw [Finset.sum_image (fun a _ b _ h => by simpa using congr_fun h 0)] refine Finset.sum_congr rfl fun c _ => by simp [char3_apply] have hs2 : ∑ ξ ∈ S2, F3 C ξ * char3 p ξ ![x, y, z] = ∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![0, c, 0] * e1 p (c * y) := by rw [Finset.sum_image (fun a _ b _ h => by simpa using congr_fun h 1)] refine Finset.sum_congr rfl fun c _ => by simp [char3_apply] have hs3 : ∑ ξ ∈ S3, F3 C ξ * char3 p ξ ![x, y, z] = ∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![0, 0, c] * e1 p (c * z) := by rw [Finset.sum_image (fun a _ b _ h => by simpa using congr_fun h 2)] refine Finset.sum_congr rfl fun c _ => by simp [char3_apply] have hs4 : ∑ ξ ∈ S4, F3 C ξ * char3 p ξ ![x, y, z] = ∑ c ∈ Finset.univ.erase (0 : ZMod p), F3 C ![c, c, c] * e1 p (c * (x + y + z)) := by rw [Finset.sum_image (fun a _ b _ h => by simpa using congr_fun h 0)] refine Finset.sum_congr rfl fun c _ => by simp only [char3_apply, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.cons_val_two, Matrix.head_cons, Matrix.tail_cons] congr 2; ring rw [hs0, hs1, hs2, hs3, hs4] at hinv have hre := congr_arg Complex.re hinv rw [Complex.add_re, Complex.add_re, Complex.add_re, Complex.add_re, Complex.mul_re, Complex.natCast_re, Complex.natCast_im, zero_mul, sub_zero, Complex.natCast_re] at hre have hN0 : N ≠ 0 := ne_of_gt hNpos dsimp only [c₀, f₁, f₂, f₃, f₄] field_simp [hN0] linarith [hre] have hbin : ∀ x y z : ZMod p, c₀ + f₁ x + f₂ y + f₃ z + f₄ (x + y + z) = 0 ∨ c₀ + f₁ x + f₂ y + f₃ z + f₄ (x + y + z) = 1 := by intro x y z; rw [← hdecomp x y z]; unfold indC; split_ifs <;> simp have hsym1 : f₁ 1 = f₁ 0 := by have hsing : ∀ c : ZMod p, Pi.single (0 : Fin 3) c = ![c, 0, 0] := fun c => by funext i; fin_cases i <;> rfl have he0 : Pi.single (0 : Fin 3) (1 : ZMod p) ∈ Fiber C 0 := by rw [hsing 1]; exact h100 dsimp only [f₁]; congr 1 simpa only [hsing] using coord_summand_sym h0C 0 he0 have hsym2 : f₂ 1 = f₂ 0 := by have hsing : ∀ c : ZMod p, Pi.single (1 : Fin 3) c = ![0, c, 0] := fun c => by funext i; fin_cases i <;> rfl have he1 : Pi.single (1 : Fin 3) (1 : ZMod p) ∈ Fiber C 0 := by rw [hsing 1]; exact h010 dsimp only [f₂]; congr 1 simpa only [hsing] using coord_summand_sym h0C 1 he1 -- Apply `const_or_const_of_symmetric_sum` to `(x, y)` at `z = 0`, then to remaining pair! have h12_c : (∀ x₁ x₂, f₁ x₁ = f₁ x₂) ∨ (∀ y₁ y₂, f₂ y₁ = f₂ y₂) := by apply const_or_const_of_symmetric_sum (f₃ := fun s => c₀ + f₃ 0 + f₄ s) _ hsym1 intro x y; rcases hbin x y 0 with h | h <;> rw [add_zero] at h <;> [left; right] <;> linarith rcases h12_c with hf1c | hf2c · have h23_c : (∀ y₁ y₂, f₂ y₁ = f₂ y₂) ∨ (∀ z₁ z₂, f₃ z₁ = f₃ z₂) := by apply const_or_const_of_symmetric_sum (f₃ := fun s => c₀ + f₁ 0 + f₄ s) _ hsym2 intro y z; rcases hbin 0 y z with h | h <;> rw [zero_add] at h <;> [left; right] <;> linarith rcases h23_c with hf2c | hf3c · -- `f₁, f₂` constant ⇒ `(1, -1, 0)` is a period! apply absurd_of_indC_period hC (g := ![1, -1, 0]) (fun h => one_ne_zero (congr_fun h 0)) intro u have hu : u = ![u 0, u 1, u 2] := by funext i; fin_cases i <;> rfl have hug : u + ![1, -1, 0] = ![u 0 + 1, u 1 + -1, u 2] := by funext i; fin_cases i <;> simp rw [hug]; conv_rhs => rw [hu] have h1 := hdecomp (u 0 + 1) (u 1 + -1) (u 2) have h2 := hdecomp (u 0) (u 1) (u 2) have hsum : u 0 + 1 + (u 1 + -1) + u 2 = u 0 + u 1 + u 2 := by ring rw [hsum, hf1c (u 0 + 1) (u 0), hf2c (u 1 + -1) (u 1)] at h1 exact Nat.cast_injective (h1.trans h2.symm) · -- `f₁, f₃` constant ⇒ `(1, 0, -1)` is a period! apply absurd_of_indC_period hC (g := ![1, 0, -1]) (fun h => one_ne_zero (congr_fun h 0)) intro u have hu : u = ![u 0, u 1, u 2] := by funext i; fin_cases i <;> rfl have hug : u + ![1, 0, -1] = ![u 0 + 1, u 1, u 2 + -1] := by funext i; fin_cases i <;> simp rw [hug]; conv_rhs => rw [hu] have h1 := hdecomp (u 0 + 1) (u 1) (u 2 + -1) have h2 := hdecomp (u 0) (u 1) (u 2) have hsum : u 0 + 1 + u 1 + (u 2 + -1) = u 0 + u 1 + u 2 := by ring rw [hsum, hf1c (u 0 + 1) (u 0), hf3c (u 2 + -1) (u 2)] at h1 exact Nat.cast_injective (h1.trans h2.symm) · have h13_c : (∀ x₁ x₂, f₁ x₁ = f₁ x₂) ∨ (∀ z₁ z₂, f₃ z₁ = f₃ z₂) := by apply const_or_const_of_symmetric_sum (f₃ := fun s => c₀ + f₂ 0 + f₄ s) _ hsym1 intro x z; rcases hbin x 0 z with h | h <;> rw [add_zero] at h <;> [left; right] <;> linarith rcases h13_c with hf1c | hf3c · apply absurd_of_indC_period hC (g := ![1, -1, 0]) (fun h => one_ne_zero (congr_fun h 0)) intro u have hu : u = ![u 0, u 1, u 2] := by funext i; fin_cases i <;> rfl have hug : u + ![1, -1, 0] = ![u 0 + 1, u 1 + -1, u 2] := by funext i; fin_cases i <;> simp rw [hug]; conv_rhs => rw [hu] have h1 := hdecomp (u 0 + 1) (u 1 + -1) (u 2) have h2 := hdecomp (u 0) (u 1) (u 2) have hsum : u 0 + 1 + (u 1 + -1) + u 2 = u 0 + u 1 + u 2 := by ring rw [hsum, hf1c (u 0 + 1) (u 0), hf2c (u 1 + -1) (u 1)] at h1 exact Nat.cast_injective (h1.trans h2.symm) · apply absurd_of_indC_period hC (g := ![0, 1, -1]) (fun h => one_ne_zero (congr_fun h 1)) intro u have hu : u = ![u 0, u 1, u 2] := by funext i; fin_cases i <;> rfl have hug : u + ![0, 1, -1] = ![u 0, u 1 + 1, u 2 + -1] := by funext i; fin_cases i <;> simp rw [hug]; conv_rhs => rw [hu] have h1 := hdecomp (u 0) (u 1 + 1) (u 2 + -1) have h2 := hdecomp (u 0) (u 1) (u 2) have hsum : u 0 + (u 1 + 1) + (u 2 + -1) = u 0 + u 1 + u 2 := by ring rw [hsum, hf2c (u 1 + 1) (u 1), hf3c (u 2 + -1) (u 2)] at h1 exact Nat.cast_injective (h1.trans h2.symm) end ThreeCanonicalOrbits section MainTheorem /-- **Exact Rank-3 Rigidity Theorem**: For every odd prime `p ≥ 3`, every aperiodic support `C : Finset (Fin 3 → ZMod p)`, and every `x₀ ∉ C`, the single-point insertion fiber satisfies `(Fiber C x₀).card ≤ 4`. -/ theorem rank3_fiber_card_le_four {p : ℕ} [Fact p.Prime] (hp3 : 3 ≤ p) (C : Finset (Fin 3 → ZMod p)) (hC : IsAperiodic C) {x₀ : Fin 3 → ZMod p} (hx₀ : x₀ ∉ C) : (Fiber C x₀).card ≤ 4 := by by_contra hgt have hge5 : 5 ≤ (Fiber C x₀).card := by omega -- Step 1: Pick an active basis `b : Fin 3 → (Fin 3 → ZMod p)` and change coordinates. have hspan := active_span_top3 hC obtain ⟨t, ht_sub, ht_span, ht_li⟩ := exists_linearIndependent (ZMod p) {ξ : Fin 3 → ZMod p | F3 C ξ ≠ 0} rw [hspan] at ht_span let : Fintype t := Fintype.ofFinite t let B : Module.Basis t (ZMod p) (Fin 3 → ZMod p) := Module.Basis.mk ht_li (by rw [Subtype.range_coe_subtype]; exact le_of_eq ht_span.symm) have hcard_t : Fintype.card t = 3 := by have h1 := Module.finrank_eq_card_basis B rw [Module.finrank_fin_fun] at h1 exact h1.symm let e : Fin 3 ≃ t := (Fintype.equivFinOfCardEq hcard_t).symm let b : Fin 3 → (Fin 3 → ZMod p) := fun i => (e i).1 have hb_active : ∀ i : Fin 3, F3 C (b i) ≠ 0 := fun i => ht_sub (e i).2 have hb_span : Submodule.span (ZMod p) (Set.range b) = ⊤ := by have hrng : Set.range b = t := by ext ξ; simp only [Set.mem_range, b] exact ⟨fun ⟨i, hi⟩ => hi ▸ (e i).2, fun hξ => ⟨e.symm ⟨ξ, hξ⟩, by simp⟩⟩ rw [hrng, ht_span] let Llin : (Fin 3 → ZMod p) →ₗ[ZMod p] (Fin 3 → ZMod p) := { toFun := fun u i => ∑ j : Fin 3, b i j * u j map_add' := fun u v => by funext i; simp [mul_add, Finset.sum_add_distrib] map_smul' := fun c u => by funext i; simp only [Pi.smul_apply, smul_eq_mul, RingHom.id_apply, Finset.mul_sum] refine Finset.sum_congr rfl fun j _ => by ring } have hL_inj : Function.Injective Llin := by rw [injective_iff_map_eq_zero]; intro u hu let ψ : (Fin 3 → ZMod p) →ₗ[ZMod p] ZMod p := { toFun := fun ξ => ∑ j : Fin 3, ξ j * u j map_add' := fun ξ η => by simp [add_mul, Finset.sum_add_distrib] map_smul' := fun c ξ => by simp only [Pi.smul_apply, smul_eq_mul, RingHom.id_apply, mul_assoc, Finset.mul_sum] } have hker : Submodule.span (ZMod p) (Set.range b) ≤ LinearMap.ker ψ := by rw [Submodule.span_le]; rintro ξ ⟨i, rfl⟩; exact congr_fun hu i rw [hb_span, top_le_iff] at hker funext j have hj : ψ (Pi.single j 1) = 0 := by have : Pi.single j (1 : ZMod p) ∈ LinearMap.ker ψ := by rw [hker]; trivial exact this simpa [ψ, Pi.single_apply] using hj let L : (Fin 3 → ZMod p) ≃+ (Fin 3 → ZMod p) := AddEquiv.ofBijective Llin.toAddMonoidHom ((Finite.injective_iff_bijective).1 hL_inj) let a := -L x₀ let C₁ := (C.image L).image (· + a) have hC₁ : IsAperiodic C₁ := isAperiodic_image_add (isAperiodic_image_addEquiv hC L) a have h0C₁ : (0 : Fin 3 → ZMod p) ∉ C₁ := by intro h obtain ⟨w, hw, hweq⟩ := Finset.mem_image.1 h obtain ⟨u, hu, rfl⟩ := Finset.mem_image.1 hw have : L u = L x₀ := sub_eq_zero.1 (by simpa [a, sub_eq_add_neg] using hweq) exact hx₀ (L.injective this ▸ hu) have hcard₁ : (Fiber C₁ 0).card = (Fiber C x₀).card := by have ha0 : L x₀ + a = 0 := add_neg_cancel (L x₀) rw [← ha0, fiber_image_add, Finset.card_image_of_injective _ (add_left_injective a), fiber_image_addEquiv, Finset.card_image_of_injective _ L.injective] have hactive_coord : ∀ i : Fin 3, F3 C₁ (Pi.single i 1) ≠ 0 := by intro i have hcalc : F3 C₁ (Pi.single i 1) = F3 C (b i) * e1 p ((L x₀) i) := by unfold F3 fourierCoeff rw [Finset.sum_image (fun _ _ _ _ h => add_left_injective a h), Finset.sum_image (fun _ _ _ _ h => L.injective h), Finset.sum_mul] refine Finset.sum_congr rfl fun u _ => ?_ have hch : char3 p (Pi.single i 1) (-(L u + a)) = e1 p (-(L u + a) i) := by fin_cases i <;> simp [char3_apply] have hchb : char3 p (b i) (-u) = e1 p (-(∑ j : Fin 3, b i j * u j)) := by simp only [char3_apply, Pi.neg_apply, Fin.sum_univ_three] congr 1; ring rw [hch, hchb, ← AddChar.map_add_eq_mul] congr 1 have hLu : (L u) i = ∑ j : Fin 3, b i j * u j := rfl simp only [a, Pi.add_apply, Pi.neg_apply, hLu] ring rw [hcalc] exact mul_ne_zero (hb_active i) (addChar_apply_ne_zero (e1 p) _) -- Step 2: Each coordinate projection `S i` has size `≤ 2`; since `|Fiber| ≥ 5`, every `|S i| = 2`. let S : Fin 3 → Finset (ZMod p) := fun i => (Fiber C₁ 0).image (fun u => u i) have hS_le2 : ∀ i : Fin 3, (S i).card ≤ 2 := by intro i by_contra hgt2 have hge3 : 3 ≤ (S i).card := by omega obtain ⟨t3, ht3_sub, ht3_card⟩ := Finset.exists_subset_card_eq hge3 obtain ⟨v₁, v₂, v₃, h12, h13, h23, ht3_eq⟩ := Finset.card_eq_three.1 ht3_card subst ht3_eq obtain ⟨u₁, hu₁, hu₁v⟩ := Finset.mem_image.1 (ht3_sub (by simp : v₁ ∈ ({v₁, v₂, v₃} : Finset (ZMod p)))) obtain ⟨u₂, hu₂, hu₂v⟩ := Finset.mem_image.1 (ht3_sub (by simp : v₂ ∈ ({v₁, v₂, v₃} : Finset (ZMod p)))) obtain ⟨u₃, hu₃, hu₃v⟩ := Finset.mem_image.1 (ht3_sub (by simp : v₃ ∈ ({v₁, v₂, v₃} : Finset (ZMod p)))) have htri := active_dot_at_most_two h0C₁ (hactive_coord i) hu₁ hu₂ hu₃ have hdot : ∀ u : Fin 3 → ZMod p, (Pi.single i (1 : ZMod p) : Fin 3 → ZMod p) 0 * u 0 + (Pi.single i (1 : ZMod p) : Fin 3 → ZMod p) 1 * u 1 + (Pi.single i (1 : ZMod p) : Fin 3 → ZMod p) 2 * u 2 = u i := fun u => by have hsum : (Pi.single i (1 : ZMod p) : Fin 3 → ZMod p) 0 * u 0 + (Pi.single i (1 : ZMod p) : Fin 3 → ZMod p) 1 * u 1 + (Pi.single i (1 : ZMod p) : Fin 3 → ZMod p) 2 * u 2 = ∑ j : Fin 3, (Pi.single i (1 : ZMod p) : Fin 3 → ZMod p) j * u j := by rw [Fin.sum_univ_three] rw [hsum] simp [Pi.single_apply] simp only [hdot] at htri rcases htri with h | h | h · exact h12 (hu₁v.symm.trans (h.trans hu₂v)) · exact h13 (hu₁v.symm.trans (h.trans hu₃v)) · exact h23 (hu₂v.symm.trans (h.trans hu₃v)) have hsub_pi : Fiber C₁ 0 ⊆ Fintype.piFinset S := fun u hu => Fintype.mem_piFinset.2 fun i => Finset.mem_image_of_mem _ hu have hS_eq2 : ∀ i : Fin 3, (S i).card = 2 := by intro i have hle := hS_le2 i by_contra hne2 have hle1 : (S i).card ≤ 1 := by omega have hprod_le : ∏ j : Fin 3, (S j).card ≤ 4 := by rw [← Finset.mul_prod_erase Finset.univ (fun j => (S j).card) (Finset.mem_univ i)] calc (S i).card * ∏ j ∈ Finset.univ.erase i, (S j).card ≤ 1 * ∏ _j ∈ Finset.univ.erase i, 2 := Nat.mul_le_mul hle1 (Finset.prod_le_prod (fun _ _ => Nat.zero_le _) (fun j _ => hS_le2 j)) _ = 4 := by simp have hcard_prod : (Fiber C₁ 0).card ≤ ∏ j : Fin 3, (S j).card := by rw [← Fintype.card_piFinset]; exact Finset.card_le_card hsub_pi omega -- Rescale so `Fiber C₂ 0 ⊆ {0, 1}^3`. have h0_in_S : ∀ i : Fin 3, (0 : ZMod p) ∈ S i := fun i => Finset.mem_image.2 ⟨0, mem_fiber_self C₁ h0C₁, rfl⟩ have hex_sc : ∀ i : Fin 3, ∃ c : ZMod p, c ≠ 0 ∧ S i = {0, c} := by intro i obtain ⟨c, hcS, hcne⟩ := Finset.exists_mem_ne (by rw [hS_eq2 i]; omega : 1 < (S i).card) 0 refine ⟨c, hcne, ?_⟩ symm refine Finset.eq_of_subset_of_card_le ?_ ?_ · intro x hx; simp only [Finset.mem_insert, Finset.mem_singleton] at hx rcases hx with rfl | rfl; exact h0_in_S i; exact hcS · rw [hS_eq2 i, Finset.card_pair hcne.symm] choose sc hsc_ne hsc_eq using hex_sc let D : (Fin 3 → ZMod p) ≃+ (Fin 3 → ZMod p) := { toFun := fun u i => (sc i)⁻¹ * u i invFun := fun v i => sc i * v i left_inv := fun u => by funext i; exact mul_inv_cancel_left₀ (hsc_ne i) (u i) right_inv := fun v => by funext i; exact inv_mul_cancel_left₀ (hsc_ne i) (v i) map_add' := fun u v => by funext i; simp [mul_add] } let C₂ := C₁.image D have hC₂ : IsAperiodic C₂ := isAperiodic_image_addEquiv hC₁ D have hF2_eq : Fiber C₂ 0 = (Fiber C₁ 0).image D := by have hD0 : D 0 = 0 := map_zero D simpa only [hD0] using fiber_image_addEquiv C₁ 0 D have hF2_card : 5 ≤ (Fiber C₂ 0).card := by rw [hF2_eq, Finset.card_image_of_injective _ D.injective, hcard₁]; exact hge5 have hF2_cube : ∀ u ∈ Fiber C₂ 0, ∀ k : Fin 3, u k = 0 ∨ u k = 1 := by intro u hu k rw [hF2_eq] at hu obtain ⟨v, hv, rfl⟩ := Finset.mem_image.1 hu have hvk : v k ∈ S k := Finset.mem_image_of_mem _ hv rw [hsc_eq k] at hvk simp only [Finset.mem_insert, Finset.mem_singleton] at hvk rcases hvk with h0 | hsc · left; simp [D, h0] · right; simp [D, hsc, inv_mul_cancel₀ (hsc_ne k)] -- Step 3: Pick a 5-element subset `F5 ⊆ Fiber C₂ 0`, encode it in `Finset (Fin 3 → Bool)`, -- and apply `cube5_orbit_classification`! obtain ⟨F5, hF5_sub, hF5_card⟩ := Finset.exists_subset_card_eq hF2_card let toZ : (Fin 3 → Bool) → (Fin 3 → ZMod p) := fun v i => if v i then 1 else 0 have htoZ_inj : Function.Injective toZ := by intro v₁ v₂ h; funext i have hi := congr_fun h i cases hb1 : v₁ i <;> cases hb2 : v₂ i · rfl · dsimp only [toZ] at hi; rw [hb1, hb2] at hi; simp at hi · dsimp only [toZ] at hi; rw [hb1, hb2] at hi; simp at hi · rfl let B5 : Finset (Fin 3 → Bool) := F5.image (fun u i => decide (u i = 1)) have hB5_toZ : ∀ v ∈ B5, toZ v ∈ F5 := by intro v hv obtain ⟨u, hu, rfl⟩ := Finset.mem_image.1 hv have heq : toZ (fun i => decide (u i = 1)) = u := by funext i rcases hF2_cube u (hF5_sub hu) i with h0 | h1 · simp [toZ, h0] · simp [toZ, h1] rwa [heq] have hB5_card : B5.card = 5 := by have hinj : Set.InjOn (fun u : Fin 3 → ZMod p => fun i => decide (u i = 1)) F5 := by intro u₁ hu₁ u₂ hu₂ heq funext i have hi := congr_fun heq i rcases hF2_cube u₁ (hF5_sub hu₁) i with h1 | h1 <;> rcases hF2_cube u₂ (hF5_sub hu₂) i with h2 | h2 · rw [h1, h2] · simp [h1, h2] at hi · simp [h1, h2] at hi · rw [h1, h2] rw [Finset.card_image_of_injOn hinj, hF5_card] have hcomp_card : (Finset.univ \ B5).card = 3 := by have hadd := Finset.card_sdiff_add_card_eq_card (Finset.subset_univ B5) rw [Finset.card_univ, Fintype.card_fun, Fintype.card_bool, Fintype.card_fin, hB5_card] at hadd omega obtain ⟨t₁, t₂, t₃, h12, h13, h23, hcomp_eq⟩ := Finset.card_eq_three.1 hcomp_card have hB5_eq : B5 = Finset.univ \ {t₁, t₂, t₃} := by rw [← hcomp_eq, Finset.sdiff_sdiff_eq_self (Finset.subset_univ B5)] obtain ⟨σ, flips, horb⟩ := cube5_orbit_classification t₁ t₂ t₃ h12 h13 h23 rw [← hB5_eq] at horb -- Step 4: Apply the corresponding affine `B₃` symmetry to `C₂`! let φ_perm : (Fin 3 → ZMod p) ≃+ (Fin 3 → ZMod p) := { toFun := fun u i => u (σ i) invFun := fun u i => u (σ.symm i) left_inv := fun u => by funext i; simp right_inv := fun u => by funext i; simp map_add' := fun u v => by funext i; rfl } let φ_neg : (Fin 3 → ZMod p) ≃+ (Fin 3 → ZMod p) := { toFun := fun u i => if flips i then -u i else u i invFun := fun u i => if flips i then -u i else u i left_inv := fun u => by funext i; by_cases h : flips i = true <;> simp [h] right_inv := fun u => by funext i; by_cases h : flips i = true <;> simp [h] map_add' := fun u v => by funext i; by_cases h : flips i = true · simp [h]; ring · simp [h] } let sh : Fin 3 → ZMod p := fun i => if flips i then 1 else 0 let C₃ := ((C₂.image φ_perm).image φ_neg).image (· + sh) have hC₃ : IsAperiodic C₃ := isAperiodic_image_add (isAperiodic_image_addEquiv (isAperiodic_image_addEquiv hC₂ φ_perm) φ_neg) sh have hact_comm : ∀ v : Fin 3 → Bool, φ_neg (φ_perm (toZ v)) + sh = toZ (actBool σ flips v) := by intro v; funext i simp only [φ_neg, φ_perm, toZ, sh, actBool, AddEquiv.coe_mk, Equiv.coe_fn_mk, Pi.add_apply] by_cases h1 : flips i = true <;> by_cases h2 : v (σ i) = true <;> simp [h1, h2] -- Every `w ∈ B5.image (actBool σ flips)` satisfies `toZ w ∈ Fiber C₃ (φ_neg (φ_perm 0) + sh)`. let xbase : Fin 3 → ZMod p := φ_neg (φ_perm 0) + sh have hF3_img : Fiber C₃ xbase = (((Fiber C₂ 0).image φ_perm).image φ_neg).image (· + sh) := by rw [fiber_image_add, fiber_image_addEquiv, fiber_image_addEquiv] have hmem_F3 : ∀ w ∈ B5.image (actBool σ flips), toZ w ∈ Fiber C₃ xbase := by intro w hw obtain ⟨v, hv, rfl⟩ := Finset.mem_image.1 hw rw [← hact_comm v, hF3_img] exact Finset.mem_image_of_mem _ (Finset.mem_image_of_mem _ (Finset.mem_image_of_mem _ (hF5_sub (hB5_toZ v hv)))) -- In all 3 canonical orbits, `![false, false, false]` belongs to the orbit, so `0 ∈ Fiber C₃ xbase`, -- hence `0 ∉ C₃` and `Fiber C₃ 0 = Fiber C₃ xbase`! have htoZ_0 : toZ ![false, false, false] = 0 := by funext i; fin_cases i <;> rfl have htoZ_001 : toZ ![false, false, true] = ![0, 0, 1] := by funext i; fin_cases i <;> rfl have htoZ_010 : toZ ![false, true, false] = ![0, 1, 0] := by funext i; fin_cases i <;> rfl have htoZ_011 : toZ ![false, true, true] = ![0, 1, 1] := by funext i; fin_cases i <;> rfl have htoZ_100 : toZ ![true, false, false] = ![1, 0, 0] := by funext i; fin_cases i <;> rfl have htoZ_101 : toZ ![true, false, true] = ![1, 0, 1] := by funext i; fin_cases i <;> rfl have htoZ_111 : toZ ![true, true, true] = ![1, 1, 1] := by funext i; fin_cases i <;> rfl rcases horb with hA | hB | hC_orb · have h0_in : (0 : Fin 3 → ZMod p) ∈ Fiber C₃ xbase := by rw [← htoZ_0]; exact hmem_F3 _ (by rw [hA]; decide) have h0C₃ : (0 : Fin 3 → ZMod p) ∉ C₃ := by classical exact (Finset.mem_sdiff.1 (Finset.mem_filter.1 h0_in).1).2 have hFeq : Fiber C₃ 0 = Fiber C₃ xbase := fiber_eq_of_mem h0_in rw [← hFeq] at hmem_F3 exact absurd_orbit_A hp3 hC₃ h0C₃ (htoZ_001 ▸ hmem_F3 _ (by rw [hA]; decide)) (htoZ_010 ▸ hmem_F3 _ (by rw [hA]; decide)) (htoZ_011 ▸ hmem_F3 _ (by rw [hA]; decide)) (htoZ_100 ▸ hmem_F3 _ (by rw [hA]; decide)) · have h0_in : (0 : Fin 3 → ZMod p) ∈ Fiber C₃ xbase := by rw [← htoZ_0]; exact hmem_F3 _ (by rw [hB]; decide) have h0C₃ : (0 : Fin 3 → ZMod p) ∉ C₃ := by classical exact (Finset.mem_sdiff.1 (Finset.mem_filter.1 h0_in).1).2 have hFeq : Fiber C₃ 0 = Fiber C₃ xbase := fiber_eq_of_mem h0_in rw [← hFeq] at hmem_F3 exact absurd_orbit_B hp3 hC₃ h0C₃ (htoZ_010 ▸ hmem_F3 _ (by rw [hB]; decide)) (htoZ_011 ▸ hmem_F3 _ (by rw [hB]; decide)) (htoZ_100 ▸ hmem_F3 _ (by rw [hB]; decide)) (htoZ_101 ▸ hmem_F3 _ (by rw [hB]; decide)) · have h0_in : (0 : Fin 3 → ZMod p) ∈ Fiber C₃ xbase := by rw [← htoZ_0]; exact hmem_F3 _ (by rw [hC_orb]; decide) have h0C₃ : (0 : Fin 3 → ZMod p) ∉ C₃ := by classical exact (Finset.mem_sdiff.1 (Finset.mem_filter.1 h0_in).1).2 have hFeq : Fiber C₃ 0 = Fiber C₃ xbase := fiber_eq_of_mem h0_in rw [← hFeq] at hmem_F3 exact absurd_orbit_C hp3 hC₃ h0C₃ (htoZ_001 ▸ hmem_F3 _ (by rw [hC_orb]; decide)) (htoZ_010 ▸ hmem_F3 _ (by rw [hC_orb]; decide)) (htoZ_100 ▸ hmem_F3 _ (by rw [hC_orb]; decide)) (htoZ_111 ▸ hmem_F3 _ (by rw [hC_orb]; decide)) end MainTheorem section SpectrumWitnesses variable {p : ℕ} [Fact p.Prime] private lemma mem_fiber_iff_profile (C : Finset (Fin 3 → ZMod p)) {x₀ : Fin 3 → ZMod p} (hx₀ : x₀ ∉ C) (x : Fin 3 → ZMod p) : x ∈ Fiber C x₀ ↔ x ∉ C ∧ ∀ t : Fin 3 → ZMod p, indC C (x + t) + indC C (x - t) = indC C (x₀ + t) + indC C (x₀ - t) := by classical simp only [Fiber, Finset.mem_filter, Finset.mem_sdiff, Finset.mem_univ, true_and] constructor · rintro ⟨hx, h⟩; exact ⟨hx, (autocorr_insert_eq_iff C hx hx₀).1 h⟩ · rintro ⟨hx, h⟩; exact ⟨hx, (autocorr_insert_eq_iff C hx hx₀).2 h⟩ private lemma natCast_ne_zero_of_lt {n : ℕ} (hn0 : 0 < n) (hnp : n < p) : (n : ZMod p) ≠ 0 := by intro h have hdvd : p ∣ n := (ZMod.natCast_eq_zero_iff n p).1 h exact absurd (Nat.le_of_dvd hn0 hdvd) (not_le_of_gt hnp) /-! ### Witness for `k = 1` (all odd primes `p ≥ 3`) -/ /-- The 4-element simplex core `{0, e₀, e₁, e₂}` in `(ZMod p)^3`. -/ def coreOne (p : ℕ) [NeZero p] : Finset (Fin 3 → ZMod p) := {0, ![1, 0, 0], ![0, 1, 0], ![0, 0, 1]} /-- For every odd prime `p ≥ 3`, `coreOne p` is aperiodic, avoids `![1, 1, 1]`, and has singleton fiber `{![1, 1, 1]}` of cardinality `1`. -/ theorem exists_fiber_card_one (hp3 : 3 ≤ p) : ∃ (C : Finset (Fin 3 → ZMod p)) (x₀ : Fin 3 → ZMod p), IsAperiodic C ∧ x₀ ∉ C ∧ (Fiber C x₀).card = 1 := by have hp : p.Prime := Fact.out have h1 : (1 : ZMod p) ≠ 0 := one_ne_zero have h2 : (2 : ZMod p) ≠ 0 := by simpa using natCast_ne_zero_of_lt (p := p) (n := 2) (by omega) (by omega) have h2_ne_1 : (2 : ZMod p) ≠ 1 := fun h => h1 (by linear_combination h) have hn1_0 : (-1 : ZMod p) ≠ 0 := fun h => h1 (by linear_combination -h) have hn1_1 : (-1 : ZMod p) ≠ 1 := fun h => h2 (by linear_combination -h) have hn2_0 : (-2 : ZMod p) ≠ 0 := fun h => h2 (by linear_combination -h) have h4 : (4 : ZMod p) ≠ 0 := by intro h have hdvd : p ∣ 4 := (ZMod.natCast_eq_zero_iff 4 p).1 (by simpa using h) have hdvd2 : p ∣ 2 := by have : p ∣ 2 * 2 := by simpa using hdvd exact (hp.dvd_mul.1 this).elim id id have hle : p ≤ 2 := Nat.le_of_dvd (by omega) hdvd2 omega let x₀ : Fin 3 → ZMod p := ![1, 1, 1] have hmem_iff : ∀ u : Fin 3 → ZMod p, u ∈ coreOne p ↔ (u 0 = 0 ∧ u 1 = 0 ∧ u 2 = 0) ∨ (u 0 = 1 ∧ u 1 = 0 ∧ u 2 = 0) ∨ (u 0 = 0 ∧ u 1 = 1 ∧ u 2 = 0) ∨ (u 0 = 0 ∧ u 1 = 0 ∧ u 2 = 1) := by intro u simp only [coreOne, Finset.mem_insert, Finset.mem_singleton] constructor · rintro (rfl | rfl | rfl | rfl) · left; exact ⟨rfl, rfl, rfl⟩ · right; left; exact ⟨rfl, rfl, rfl⟩ · right; right; left; exact ⟨rfl, rfl, rfl⟩ · right; right; right; exact ⟨rfl, rfl, rfl⟩ · rintro (⟨h0, h1', h2'⟩ | ⟨h0, h1', h2'⟩ | ⟨h0, h1', h2'⟩ | ⟨h0, h1', h2'⟩) · left; funext i; fin_cases i <;> simp [h0, h1', h2'] · right; left; funext i; fin_cases i <;> simp [h0, h1', h2'] · right; right; left; funext i; fin_cases i <;> simp [h0, h1', h2'] · right; right; right; funext i; fin_cases i <;> simp [h0, h1', h2'] have hnot_two_nz : ∀ u : Fin 3 → ZMod p, (u 0 ≠ 0 ∧ u 1 ≠ 0) ∨ (u 0 ≠ 0 ∧ u 2 ≠ 0) ∨ (u 1 ≠ 0 ∧ u 2 ≠ 0) → u ∉ coreOne p := by intro u hnz hu rw [hmem_iff] at hu rcases hu with ⟨a, b, c⟩ | ⟨a, b, c⟩ | ⟨a, b, c⟩ | ⟨a, b, c⟩ <;> rcases hnz with ⟨h0', h1'⟩ | ⟨h0', h2'⟩ | ⟨h1', h2'⟩ <;> contradiction have hnot_ne01 : ∀ u : Fin 3 → ZMod p, (u 0 ≠ 0 ∧ u 0 ≠ 1) ∨ (u 1 ≠ 0 ∧ u 1 ≠ 1) ∨ (u 2 ≠ 0 ∧ u 2 ≠ 1) → u ∉ coreOne p := by intro u hne hu rw [hmem_iff] at hu rcases hu with ⟨a, b, c⟩ | ⟨a, b, c⟩ | ⟨a, b, c⟩ | ⟨a, b, c⟩ <;> rcases hne with ⟨h0', h1'⟩ | ⟨h0', h1'⟩ | ⟨h0', h1'⟩ <;> contradiction have hcard_core : (coreOne p).card = 4 := by unfold coreOne have ha : (0 : Fin 3 → ZMod p) ≠ ![1, 0, 0] := fun h => h1 (congr_fun h 0).symm have hb : (0 : Fin 3 → ZMod p) ≠ ![0, 1, 0] := fun h => h1 (congr_fun h 1).symm have hc : (0 : Fin 3 → ZMod p) ≠ ![0, 0, 1] := fun h => h1 (congr_fun h 2).symm have hd : (![1, 0, 0] : Fin 3 → ZMod p) ≠ ![0, 1, 0] := fun h => h1 (congr_fun h 0) have he : (![1, 0, 0] : Fin 3 → ZMod p) ≠ ![0, 0, 1] := fun h => h1 (congr_fun h 0) have hf : (![0, 1, 0] : Fin 3 → ZMod p) ≠ ![0, 0, 1] := fun h => h1 (congr_fun h 1) rw [Finset.card_insert_of_notMem, Finset.card_insert_of_notMem, Finset.card_insert_of_notMem, Finset.card_singleton] <;> simp [ha, hb, hc, hd, he, hf] have haper : IsAperiodic (coreOne p) := by intro g hg have hsum_eq : ∑ u ∈ coreOne p, (u + g) = ∑ u ∈ coreOne p, u := by have himg : ∑ u ∈ (coreOne p).image (· + g), u = ∑ u ∈ coreOne p, (u + g) := Finset.sum_image (fun _ _ _ _ h => add_right_cancel h) rw [← himg, hg] rw [Finset.sum_add_distrib, Finset.sum_const, hcard_core] at hsum_eq have h4g : (4 : ℕ) • g = 0 := add_left_cancel (hsum_eq.trans (add_zero _).symm) funext i have hi : (4 : ZMod p) * g i = 0 := by have := congr_fun h4g i simpa [nsmul_eq_mul] using this exact (mul_eq_zero.1 hi).resolve_left h4 have hx₀ : x₀ ∉ coreOne p := hnot_two_nz x₀ (Or.inl ⟨h1, h1⟩) have hfiber_eq : Fiber (coreOne p) x₀ = {x₀} := by ext x rw [Finset.mem_singleton] constructor · intro hx obtain ⟨_, hprof⟩ := (mem_fiber_iff_profile (coreOne p) hx₀ x).1 hx let t0 : Fin 3 → ZMod p := ![1, 1, 1] let t1 : Fin 3 → ZMod p := ![0, 1, 1] let t2 : Fin 3 → ZMod p := ![1, 0, 1] let t3 : Fin 3 → ZMod p := ![1, 1, 0] have h1p1 : (1 : ZMod p) + 1 ≠ 0 := fun h => h2 (by linear_combination h) have hp0 : indC (coreOne p) (x₀ + t0) + indC (coreOne p) (x₀ - t0) = 1 := by have h1' : x₀ + t0 ∉ coreOne p := hnot_two_nz _ (Or.inl ⟨by simp [x₀, t0, h1p1], by simp [x₀, t0, h1p1]⟩) have h2' : x₀ - t0 ∈ coreOne p := by rw [hmem_iff]; left; simp [x₀, t0] unfold indC; rw [if_neg h1', if_pos h2'] have hp1 : indC (coreOne p) (x₀ + t1) + indC (coreOne p) (x₀ - t1) = 1 := by have h1' : x₀ + t1 ∉ coreOne p := hnot_two_nz _ (Or.inl ⟨by simp [x₀, t1, h1], by simp [x₀, t1, h1p1]⟩) have h2' : x₀ - t1 ∈ coreOne p := by rw [hmem_iff]; right; left; simp [x₀, t1] unfold indC; rw [if_neg h1', if_pos h2'] have hp2 : indC (coreOne p) (x₀ + t2) + indC (coreOne p) (x₀ - t2) = 1 := by have h1' : x₀ + t2 ∉ coreOne p := hnot_two_nz _ (Or.inl ⟨by simp [x₀, t2, h1p1], by simp [x₀, t2, h1]⟩) have h2' : x₀ - t2 ∈ coreOne p := by rw [hmem_iff]; right; right; left; simp [x₀, t2] unfold indC; rw [if_neg h1', if_pos h2'] have hp3' : indC (coreOne p) (x₀ + t3) + indC (coreOne p) (x₀ - t3) = 1 := by have h1' : x₀ + t3 ∉ coreOne p := hnot_two_nz _ (Or.inl ⟨by simp [x₀, t3, h1p1], by simp [x₀, t3, h1p1]⟩) have h2' : x₀ - t3 ∈ coreOne p := by rw [hmem_iff]; right; right; right; simp [x₀, t3] unfold indC; rw [if_neg h1', if_pos h2'] have h0x := (hprof t0).trans hp0 have h1x := (hprof t1).trans hp1 have h2x := (hprof t2).trans hp2 have h3x := (hprof t3).trans hp3' have hor : x + t0 ∈ coreOne p ∨ x - t0 ∈ coreOne p := by by_contra hboth; push Not at hboth unfold indC at h0x; rw [if_neg hboth.1, if_neg hboth.2] at h0x; omega have hkill : ∀ (t : Fin 3 → ZMod p), indC (coreOne p) (x + t) + indC (coreOne p) (x - t) = 1 → x + t ∉ coreOne p → x - t ∉ coreOne p → False := by intro t ht hn1 hn2; unfold indC at ht; rw [if_neg hn1, if_neg hn2] at ht; omega rcases hor with hplus | hminus · rw [hmem_iff] at hplus rcases hplus with ⟨a, b, c⟩ | ⟨a, b, c⟩ | ⟨a, b, c⟩ | ⟨a, b, c⟩ · -- `x = ![-1, -1, -1]` killed by `t1` have hx0 : x 0 = -1 := by simp [t0] at a; linear_combination a have hx1 : x 1 = -1 := by simp [t0] at b; linear_combination b have hx2 : x 2 = -1 := by simp [t0] at c; linear_combination c exfalso; refine hkill t1 h1x ?_ ?_ · exact hnot_ne01 _ (Or.inl ⟨by simp [t1, hx0, hn1_0], by simp [t1, hx0, hn1_1]⟩) · exact hnot_two_nz _ (Or.inl ⟨by simp [t1, hx0, hn1_0], by simp [t1, hx1]; exact fun h => hn2_0 (by linear_combination h)⟩) · -- `x = ![0, -1, -1]` killed by `t2` have hx0 : x 0 = 0 := by simp [t0] at a; linear_combination a have hx1 : x 1 = -1 := by simp [t0] at b; linear_combination b have hx2 : x 2 = -1 := by simp [t0] at c; linear_combination c exfalso; refine hkill t2 h2x ?_ ?_ · exact hnot_two_nz _ (Or.inl ⟨by simp [t2, hx0, h1], by simp [t2, hx1, hn1_0]⟩) · exact hnot_two_nz _ (Or.inl ⟨by simp [t2, hx0, hn1_0], by simp [t2, hx1, hn1_0]⟩) · -- `x = ![-1, 0, -1]` killed by `t1` have hx0 : x 0 = -1 := by simp [t0] at a; linear_combination a have hx1 : x 1 = 0 := by simp [t0] at b; linear_combination b have hx2 : x 2 = -1 := by simp [t0] at c; linear_combination c exfalso; refine hkill t1 h1x ?_ ?_ · exact hnot_two_nz _ (Or.inl ⟨by simp [t1, hx0, hn1_0], by simp [t1, hx1, h1]⟩) · exact hnot_two_nz _ (Or.inl ⟨by simp [t1, hx0, hn1_0], by simp [t1, hx1, hn1_0]⟩) · -- `x = ![-1, -1, 0]` killed by `t1` have hx0 : x 0 = -1 := by simp [t0] at a; linear_combination a have hx1 : x 1 = -1 := by simp [t0] at b; linear_combination b have hx2 : x 2 = 0 := by simp [t0] at c; linear_combination c exfalso; refine hkill t1 h1x ?_ ?_ · exact hnot_two_nz _ (Or.inr (Or.inl ⟨by simp [t1, hx0, hn1_0], by simp [t1, hx2, h1]⟩)) · exact hnot_two_nz _ (Or.inr (Or.inl ⟨by simp [t1, hx0, hn1_0], by simp [t1, hx2, hn1_0]⟩)) · rw [hmem_iff] at hminus rcases hminus with ⟨a, b, c⟩ | ⟨a, b, c⟩ | ⟨a, b, c⟩ | ⟨a, b, c⟩ · -- `x = ![1, 1, 1] = x₀`! have hx0 : x 0 = 1 := by simp [t0] at a; linear_combination a have hx1 : x 1 = 1 := by simp [t0] at b; linear_combination b have hx2 : x 2 = 1 := by simp [t0] at c; linear_combination c funext i; fin_cases i <;> simp [x₀, hx0, hx1, hx2] · -- `x = ![2, 1, 1]` killed by `t1` have hx0 : x 0 = 2 := by simp [t0] at a; linear_combination a have hx1 : x 1 = 1 := by simp [t0] at b; linear_combination b have hx2 : x 2 = 1 := by simp [t0] at c; linear_combination c exfalso; refine hkill t1 h1x ?_ ?_ · exact hnot_two_nz _ (Or.inl ⟨by simp [t1, hx0, h2], by simp [t1, hx1]; exact fun h => h2 (by linear_combination h)⟩) · exact hnot_ne01 _ (Or.inl ⟨by simp [t1, hx0, h2], by simp [t1, hx0, h2_ne_1]⟩) · -- `x = ![1, 2, 1]` killed by `t2` have hx0 : x 0 = 1 := by simp [t0] at a; linear_combination a have hx1 : x 1 = 2 := by simp [t0] at b; linear_combination b have hx2 : x 2 = 1 := by simp [t0] at c; linear_combination c exfalso; refine hkill t2 h2x ?_ ?_ · exact hnot_two_nz _ (Or.inl ⟨by simp [t2, hx0]; exact fun h => h2 (by linear_combination h), by simp [t2, hx1, h2]⟩) · exact hnot_ne01 _ (Or.inr (Or.inl ⟨by simp [t2, hx1, h2], by simp [t2, hx1, h2_ne_1]⟩)) · -- `x = ![1, 1, 2]` killed by `t3` have hx0 : x 0 = 1 := by simp [t0] at a; linear_combination a have hx1 : x 1 = 1 := by simp [t0] at b; linear_combination b have hx2 : x 2 = 2 := by simp [t0] at c; linear_combination c exfalso; refine hkill t3 h3x ?_ ?_ · exact hnot_two_nz _ (Or.inl ⟨by simp [t3, hx0]; exact fun h => h2 (by linear_combination h), by simp [t3, hx1]; exact fun h => h2 (by linear_combination h)⟩) · exact hnot_ne01 _ (Or.inr (Or.inr ⟨by simp [t3, hx2, h2], by simp [t3, hx2, h2_ne_1]⟩)) · rintro rfl; exact mem_fiber_self (coreOne p) hx₀ exact ⟨coreOne p, x₀, haper, hx₀, by rw [hfiber_eq, Finset.card_singleton]⟩ /-! ### Witness for `k = 2` (all odd primes `p ≥ 3`) -/ /-- For every odd prime `p ≥ 3`, `{0}` is aperiodic, avoids `![1, 0, 0]`, and has exact fiber `{![1, 0, 0], ![-1, 0, 0]}` of cardinality `2`. -/ theorem exists_fiber_card_two (hp3 : 3 ≤ p) : ∃ (C : Finset (Fin 3 → ZMod p)) (x₀ : Fin 3 → ZMod p), IsAperiodic C ∧ x₀ ∉ C ∧ (Fiber C x₀).card = 2 := by have h1 : (1 : ZMod p) ≠ 0 := one_ne_zero have h2 : (2 : ZMod p) ≠ 0 := by simpa using natCast_ne_zero_of_lt (p := p) (n := 2) (by omega) (by omega) let C : Finset (Fin 3 → ZMod p) := {0} let x₀ : Fin 3 → ZMod p := ![1, 0, 0] have haper : IsAperiodic C := by intro g hg have hmem : (0 : Fin 3 → ZMod p) + g ∈ C := by rw [← hg]; exact Finset.mem_image_of_mem _ (Finset.mem_singleton_self 0) simpa [C] using hmem have hx₀ : x₀ ∉ C := by simp only [C, Finset.mem_singleton] intro h; exact h1 (congr_fun h 0) have hneg_not : -x₀ ∉ C := by simp only [C, Finset.mem_singleton] intro h; exact h1 (neg_eq_zero.1 (congr_fun h 0)) have hne : x₀ ≠ -x₀ := by intro h have h0 := congr_fun h 0 simp only [x₀, Pi.neg_apply, Matrix.cons_val_zero] at h0 exact h2 (by linear_combination h0) have hfiber_eq : Fiber C x₀ = {x₀, -x₀} := by ext x simp only [Finset.mem_insert, Finset.mem_singleton] constructor · intro hx obtain ⟨_, hprof⟩ := (mem_fiber_iff_profile C hx₀ x).1 hx have h10 := hprof x₀ have hplus_out : x₀ + x₀ ∉ C := by simp only [C, Finset.mem_singleton] intro h have h0 := congr_fun h 0 simp only [x₀, Pi.add_apply, Pi.zero_apply, Matrix.cons_val_zero] at h0 exact h2 (by linear_combination h0) have hminus_in : x₀ - x₀ ∈ C := by simp [C] unfold indC at h10 rw [if_neg hplus_out, if_pos hminus_in] at h10 by_cases h1' : x + x₀ ∈ C · right; simp only [C, Finset.mem_singleton] at h1'; exact eq_neg_of_add_eq_zero_left h1' · by_cases h2' : x - x₀ ∈ C · left; simp only [C, Finset.mem_singleton] at h2'; exact sub_eq_zero.1 h2' · rw [if_neg h1', if_neg h2'] at h10; omega · rintro (rfl | rfl) · exact mem_fiber_self C hx₀ · rw [mem_fiber_iff_profile C hx₀] refine ⟨hneg_not, fun t => ?_⟩ unfold indC have e1 : (-x₀ + t ∈ C) ↔ (x₀ - t ∈ C) := by simp only [C, Finset.mem_singleton] constructor <;> intro h · have : -(x₀ - t) = 0 := by rw [neg_sub, sub_eq_add_neg, add_comm]; simpa [add_comm] using h exact neg_eq_zero.1 this · have : -x₀ + t = -(x₀ - t) := by abel rw [this, h, neg_zero] have e2 : (-x₀ - t ∈ C) ↔ (x₀ + t ∈ C) := by simp only [C, Finset.mem_singleton] constructor <;> intro h · have : -(x₀ + t) = 0 := by rw [neg_add, ← sub_eq_add_neg]; exact h exact neg_eq_zero.1 this · have : -x₀ - t = -(x₀ + t) := by abel rw [this, h, neg_zero] simp only [e1, e2]; omega exact ⟨C, x₀, haper, hx₀, by rw [hfiber_eq, Finset.card_pair hne]⟩ /-! ### Witness for `k = 3` (all odd primes `p ≥ 3`) -/ /-- Explicit 5-slice core in `(ZMod p)^3` yielding a fiber of size 3 for every prime `p ≥ 5`. -/ def coreThreeGeFive (p : ℕ) [NeZero p] : Finset (Fin 3 → ZMod p) := Finset.univ.filter fun u => (u 2 = 1 ∧ u 0 = 0) ∨ (u 2 = -1 ∧ u 0 = 1) ∨ (u 2 = 2 ∧ u 1 = 0) ∨ (u 2 = -2 ∧ u 1 = 1) ∨ (u 2 = 0 ∧ u 0 + u 1 = (2 : ZMod p)⁻¹) private lemma fiber_card_three_of_ge_five (hp5 : 5 ≤ p) : IsAperiodic (coreThreeGeFive p) ∧ (0 : Fin 3 → ZMod p) ∉ coreThreeGeFive p ∧ (Fiber (coreThreeGeFive p) 0).card = 3 := by have h1 : (1 : ZMod p) ≠ 0 := one_ne_zero have h2 : (2 : ZMod p) ≠ 0 := by simpa using natCast_ne_zero_of_lt (p := p) (n := 2) (by omega) (by omega) have h3 : (3 : ZMod p) ≠ 0 := by simpa using natCast_ne_zero_of_lt (p := p) (n := 3) (by omega) (by omega) have h4 : (4 : ZMod p) ≠ 0 := by simpa using natCast_ne_zero_of_lt (p := p) (n := 4) (by omega) (by omega) have h1_neg1 : (1 : ZMod p) ≠ -1 := fun h => h2 (by linear_combination h) have h2_1 : (2 : ZMod p) ≠ 1 := fun h => h1 (by linear_combination h) have h2_neg1 : (2 : ZMod p) ≠ -1 := fun h => h3 (by linear_combination h) have hneg2_0 : (-2 : ZMod p) ≠ 0 := fun h => h2 (by linear_combination -h) have hneg2_1 : (-2 : ZMod p) ≠ 1 := fun h => h3 (by linear_combination -h) have hneg2_neg1 : (-2 : ZMod p) ≠ -1 := fun h => h1 (by linear_combination -h) have hneg2_2 : (-2 : ZMod p) ≠ 2 := fun h => h4 (by linear_combination -h) have hneg1_0 : (-1 : ZMod p) ≠ 0 := fun h => h1 (by linear_combination -h) let c : ZMod p := (2 : ZMod p)⁻¹ have h2c : 2 * c = 1 := mul_inv_cancel₀ h2 have hc0 : c ≠ 0 := inv_ne_zero h2 have hc1 : c ≠ 1 := fun h => h1 (by linear_combination h2c - 2 * h) have hc_neg : c ≠ -c := fun h => h1 (by linear_combination -h2c + (by linear_combination h : 2 * c = 0)) have h2pc_ne : 2 + c ≠ c := fun h => h2 (by linear_combination h) have h2mc_ne : 2 - c ≠ c := fun h => h1 (by linear_combination h + h2c) have hmem_iff : ∀ u : Fin 3 → ZMod p, u ∈ coreThreeGeFive p ↔ (u 2 = 1 ∧ u 0 = 0) ∨ (u 2 = -1 ∧ u 0 = 1) ∨ (u 2 = 2 ∧ u 1 = 0) ∨ (u 2 = -2 ∧ u 1 = 1) ∨ (u 2 = 0 ∧ u 0 + u 1 = c) := fun u => by simp [coreThreeGeFive, c] have h0_not : (0 : Fin 3 → ZMod p) ∉ coreThreeGeFive p := by rw [hmem_iff] simp only [Pi.zero_apply, zero_add] rintro (⟨h, _⟩ | ⟨h, _⟩ | ⟨h, _⟩ | ⟨h, _⟩ | ⟨_, h⟩) · exact h1 h.symm · exact hneg1_0 h.symm · exact h2 h.symm · exact hneg2_0 h.symm · exact hc0 h.symm have haper : IsAperiodic (coreThreeGeFive p) := by intro g hg have hshift : ∀ u : Fin 3 → ZMod p, u ∈ coreThreeGeFive p → u + g ∈ coreThreeGeFive p := by intro u hu; rw [← hg]; exact Finset.mem_image_of_mem _ hu let u₁ : Fin 3 → ZMod p := ![0, c, 0] let u₂ : Fin 3 → ZMod p := ![1, c - 1, 0] have hu₁ : u₁ ∈ coreThreeGeFive p := by rw [hmem_iff]; right; right; right; right; simp [u₁] have hu₂ : u₂ ∈ coreThreeGeFive p := by rw [hmem_iff]; right; right; right; right; simp [u₂] have hg2 : g 2 = 0 := by have hm1 := (hmem_iff (u₁ + g)).1 (hshift u₁ hu₁) have hm2 := (hmem_iff (u₂ + g)).1 (hshift u₂ hu₂) have h10 : (u₁ + g) 0 = g 0 := by simp [u₁] have h11 : (u₁ + g) 1 = c + g 1 := by simp [u₁] have h12 : (u₁ + g) 2 = g 2 := by simp [u₁] have h20 : (u₂ + g) 0 = 1 + g 0 := by simp [u₂] have h21 : (u₂ + g) 1 = c - 1 + g 1 := by simp [u₂] have h22 : (u₂ + g) 2 = g 2 := by simp [u₂] rw [h10, h11, h12] at hm1 rw [h20, h21, h22] at hm2 rcases hm1 with ⟨hz, ha1⟩ | ⟨hz, ha1⟩ | ⟨hz, hb1⟩ | ⟨hz, hb1⟩ | ⟨hz, _⟩ · rcases hm2 with ⟨_, ha2⟩ | ⟨hz2, _⟩ | ⟨hz2, _⟩ | ⟨hz2, _⟩ | ⟨hz2, _⟩ · exact absurd (by linear_combination ha2 - ha1 : (1 : ZMod p) = 0) h1 · exact absurd (hz.symm.trans hz2) h1_neg1 · exact absurd (hz2.symm.trans hz) h2_1 · exact absurd (hz2.symm.trans hz) hneg2_1 · exact absurd (hz.symm.trans hz2) h1 · rcases hm2 with ⟨hz2, _⟩ | ⟨_, ha2⟩ | ⟨hz2, _⟩ | ⟨hz2, _⟩ | ⟨hz2, _⟩ · exact absurd (hz2.symm.trans hz) h1_neg1 · exact absurd (by linear_combination ha2 - ha1 : (1 : ZMod p) = 0) h1 · exact absurd (hz2.symm.trans hz) h2_neg1 · exact absurd (hz2.symm.trans hz) hneg2_neg1 · exact absurd (hz.symm.trans hz2) hneg1_0 · rcases hm2 with ⟨hz2, _⟩ | ⟨hz2, _⟩ | ⟨_, hb2⟩ | ⟨hz2, _⟩ | ⟨hz2, _⟩ · exact absurd (hz.symm.trans hz2) h2_1 · exact absurd (hz.symm.trans hz2) h2_neg1 · exact absurd (by linear_combination hb1 - hb2 : (1 : ZMod p) = 0) h1 · exact absurd (hz2.symm.trans hz) hneg2_2 · exact absurd (hz.symm.trans hz2) h2 · rcases hm2 with ⟨hz2, _⟩ | ⟨hz2, _⟩ | ⟨hz2, _⟩ | ⟨_, hb2⟩ | ⟨hz2, _⟩ · exact absurd (hz.symm.trans hz2) hneg2_1 · exact absurd (hz.symm.trans hz2) hneg2_neg1 · exact absurd (hz.symm.trans hz2) hneg2_2 · exact absurd (by linear_combination hb1 - hb2 : (1 : ZMod p) = 0) h1 · exact absurd (hz.symm.trans hz2) hneg2_0 · exact hz have hg0 : g 0 = 0 := by let v : Fin 3 → ZMod p := ![0, 0, 1] have hv : v ∈ coreThreeGeFive p := by rw [hmem_iff]; left; simp [v] have hmv := (hmem_iff (v + g)).1 (hshift v hv) simp only [Pi.add_apply, v, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.cons_val_two, Matrix.head_cons, Matrix.tail_cons, hg2, add_zero, zero_add] at hmv rcases hmv with ⟨_, h⟩ | ⟨h, _⟩ | ⟨h, _⟩ | ⟨h, _⟩ | ⟨h, _⟩ · exact h · exact absurd h h1_neg1 · exact absurd h.symm h2_1 · exact absurd h.symm hneg2_1 · exact absurd h h1 have hg1 : g 1 = 0 := by let w : Fin 3 → ZMod p := ![0, 0, 2] have hw : w ∈ coreThreeGeFive p := by rw [hmem_iff]; right; right; left; simp [w] have hmw := (hmem_iff (w + g)).1 (hshift w hw) simp only [Pi.add_apply, w, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.cons_val_two, Matrix.head_cons, Matrix.tail_cons, hg2, add_zero, zero_add] at hmw rcases hmw with ⟨h, _⟩ | ⟨h, _⟩ | ⟨_, h⟩ | ⟨h, _⟩ | ⟨h, _⟩ · exact absurd h h2_1 · exact absurd h h2_neg1 · exact h · exact absurd h.symm hneg2_2 · exact absurd h h2 funext i; fin_cases i <;> assumption let s0 : Fin 3 → ZMod p := 0 let s1 : Fin 3 → ZMod p := ![1, 0, 0] let s2 : Fin 3 → ZMod p := ![0, 1, 0] have hs_mem : ∀ x : Fin 3 → ZMod p, x 2 = 0 → (x 0 = 0 ∨ x 0 = 1) → (x 1 = 0 ∨ x 1 = 1) → (x 0 + x 1 = 0 ∨ x 0 + x 1 = 1) → x ∈ Fiber (coreThreeGeFive p) 0 := by intro x hx2 hx0 hx1 hx01 rw [mem_fiber_iff_profile (coreThreeGeFive p) h0_not] refine ⟨?_, ?_⟩ · rw [hmem_iff] rintro (⟨h, _⟩ | ⟨h, _⟩ | ⟨h, _⟩ | ⟨h, _⟩ | ⟨_, h⟩) · exact h1 (h.symm.trans hx2) · exact hneg1_0 (h.symm.trans hx2) · exact h2 (h.symm.trans hx2) · exact hneg2_0 (h.symm.trans hx2) · rcases hx01 with h01 | h01 · exact hc0 (h.symm.trans h01) · exact hc1 (h.symm.trans h01) · intro t have ht_add : (x + t) 2 = t 2 := by simp [hx2] have ht_sub : (x - t) 2 = -t 2 := by simp [hx2] have h0_add : (0 + t : Fin 3 → ZMod p) 2 = t 2 := by simp have h0_sub : (0 - t : Fin 3 → ZMod p) 2 = -t 2 := by simp by_cases hz1 : t 2 = 1 · have hnegz : -t 2 = -1 := by rw [hz1] have hx_p : x + t ∈ coreThreeGeFive p ↔ x 0 + t 0 = 0 := by rw [hmem_iff, ht_add, hz1]; simp [h1_neg1, h2_1.symm, hneg2_1.symm, h1] have hx_m : x - t ∈ coreThreeGeFive p ↔ x 0 - t 0 = 1 := by rw [hmem_iff, ht_sub, hnegz]; simp [h1_neg1.symm, h2_neg1.symm, hneg2_neg1.symm, hneg1_0] have h0_p : 0 + t ∈ coreThreeGeFive p ↔ t 0 = 0 := by rw [hmem_iff, h0_add, hz1]; simp [h1_neg1, h2_1.symm, hneg2_1.symm, h1] have h0_m : 0 - t ∈ coreThreeGeFive p ↔ -t 0 = 1 := by rw [hmem_iff, h0_sub, hnegz]; simp [h1_neg1.symm, h2_neg1.symm, hneg2_neg1.symm, hneg1_0] unfold indC; simp only [hx_p, hx_m, h0_p, h0_m] rcases hx0 with h0 | h0 · simp [h0] · rw [h0] have e1 : (1 + t 0 = 0) ↔ (-t 0 = 1) := by constructor <;> intro h <;> linear_combination -h have e2 : (1 - t 0 = 1) ↔ (t 0 = 0) := by constructor <;> intro h <;> linear_combination -h simp only [e1, e2]; omega · by_cases hzn1 : t 2 = -1 · have hnegz : -t 2 = 1 := by rw [hzn1, neg_neg] have hx_p : x + t ∈ coreThreeGeFive p ↔ x 0 + t 0 = 1 := by rw [hmem_iff, ht_add, hzn1]; simp [h1_neg1.symm, h2_neg1.symm, hneg2_neg1.symm, hneg1_0] have hx_m : x - t ∈ coreThreeGeFive p ↔ x 0 - t 0 = 0 := by rw [hmem_iff, ht_sub, hnegz]; simp [h1_neg1, h2_1.symm, hneg2_1.symm, h1] have h0_p : 0 + t ∈ coreThreeGeFive p ↔ t 0 = 1 := by rw [hmem_iff, h0_add, hzn1]; simp [h1_neg1.symm, h2_neg1.symm, hneg2_neg1.symm, hneg1_0] have h0_m : 0 - t ∈ coreThreeGeFive p ↔ -t 0 = 0 := by rw [hmem_iff, h0_sub, hnegz]; simp [h1_neg1, h2_1.symm, hneg2_1.symm, h1] unfold indC; simp only [hx_p, hx_m, h0_p, h0_m] rcases hx0 with h0 | h0 · simp [h0] · rw [h0] have e1 : (1 + t 0 = 1) ↔ (-t 0 = 0) := by constructor <;> intro h <;> linear_combination -h have e2 : (1 - t 0 = 0) ↔ (t 0 = 1) := by constructor <;> intro h <;> linear_combination -h simp only [e1, e2]; omega · by_cases hz2 : t 2 = 2 · have hnegz : -t 2 = -2 := by rw [hz2] have hx_p : x + t ∈ coreThreeGeFive p ↔ x 1 + t 1 = 0 := by rw [hmem_iff, ht_add, hz2]; simp [h2_1, h2_neg1, hneg2_2.symm, h2] have hx_m : x - t ∈ coreThreeGeFive p ↔ x 1 - t 1 = 1 := by rw [hmem_iff, ht_sub, hnegz]; simp [hneg2_1, hneg2_neg1, hneg2_2, hneg2_0] have h0_p : 0 + t ∈ coreThreeGeFive p ↔ t 1 = 0 := by rw [hmem_iff, h0_add, hz2]; simp [h2_1, h2_neg1, hneg2_2.symm, h2] have h0_m : 0 - t ∈ coreThreeGeFive p ↔ -t 1 = 1 := by rw [hmem_iff, h0_sub, hnegz]; simp [hneg2_1, hneg2_neg1, hneg2_2, hneg2_0] unfold indC; simp only [hx_p, hx_m, h0_p, h0_m] rcases hx1 with h0 | h0 · simp [h0] · rw [h0] have e1 : (1 + t 1 = 0) ↔ (-t 1 = 1) := by constructor <;> intro h <;> linear_combination -h have e2 : (1 - t 1 = 1) ↔ (t 1 = 0) := by constructor <;> intro h <;> linear_combination -h simp only [e1, e2]; omega · by_cases hzn2 : t 2 = -2 · have hnegz : -t 2 = 2 := by rw [hzn2, neg_neg] have hx_p : x + t ∈ coreThreeGeFive p ↔ x 1 + t 1 = 1 := by rw [hmem_iff, ht_add, hzn2]; simp [hneg2_1, hneg2_neg1, hneg2_2, hneg2_0] have hx_m : x - t ∈ coreThreeGeFive p ↔ x 1 - t 1 = 0 := by rw [hmem_iff, ht_sub, hnegz]; simp [h2_1, h2_neg1, hneg2_2.symm, h2] have h0_p : 0 + t ∈ coreThreeGeFive p ↔ t 1 = 1 := by rw [hmem_iff, h0_add, hzn2]; simp [hneg2_1, hneg2_neg1, hneg2_2, hneg2_0] have h0_m : 0 - t ∈ coreThreeGeFive p ↔ -t 1 = 0 := by rw [hmem_iff, h0_sub, hnegz]; simp [h2_1, h2_neg1, hneg2_2.symm, h2] unfold indC; simp only [hx_p, hx_m, h0_p, h0_m] rcases hx1 with h0 | h0 · simp [h0] · rw [h0] have e1 : (1 + t 1 = 1) ↔ (-t 1 = 0) := by constructor <;> intro h <;> linear_combination -h have e2 : (1 - t 1 = 0) ↔ (t 1 = 1) := by constructor <;> intro h <;> linear_combination -h simp only [e1, e2]; omega · by_cases hz0 : t 2 = 0 · have hnegz : -t 2 = 0 := by rw [hz0, neg_zero] have hx_p : x + t ∈ coreThreeGeFive p ↔ x 0 + x 1 + (t 0 + t 1) = c := by rw [hmem_iff, ht_add, hz0] simp [h1.symm, hneg1_0.symm, h2.symm, hneg2_0.symm] constructor <;> intro h <;> linear_combination h have hx_m : x - t ∈ coreThreeGeFive p ↔ x 0 + x 1 - (t 0 + t 1) = c := by rw [hmem_iff, ht_sub, hnegz] simp [h1.symm, hneg1_0.symm, h2.symm, hneg2_0.symm] constructor <;> intro h <;> linear_combination h have h0_p : 0 + t ∈ coreThreeGeFive p ↔ t 0 + t 1 = c := by rw [hmem_iff, h0_add, hz0]; simp [h1.symm, hneg1_0.symm, h2.symm, hneg2_0.symm] have h0_m : 0 - t ∈ coreThreeGeFive p ↔ -(t 0 + t 1) = c := by rw [hmem_iff, h0_sub, hnegz] simp [h1.symm, hneg1_0.symm, h2.symm, hneg2_0.symm] constructor <;> intro h <;> linear_combination h unfold indC; simp only [hx_p, hx_m, h0_p, h0_m] rcases hx01 with h01 | h01 · simp [h01] · rw [h01] have e1 : (1 + (t 0 + t 1) = c) ↔ (-(t 0 + t 1) = c) := by constructor <;> intro h <;> linear_combination -h - h2c have e2 : (1 - (t 0 + t 1) = c) ↔ (t 0 + t 1 = c) := by constructor <;> intro h <;> linear_combination -h - h2c simp only [e1, e2]; omega · have hnz1 : -t 2 ≠ 1 := fun h => hzn1 (by linear_combination -h) have hnzn1 : -t 2 ≠ -1 := fun h => hz1 (by linear_combination -h) have hnz2 : -t 2 ≠ 2 := fun h => hzn2 (by linear_combination -h) have hnzn2 : -t 2 ≠ -2 := fun h => hz2 (by linear_combination -h) have hnz0 : -t 2 ≠ 0 := fun h => hz0 (by linear_combination -h) have hn1 : x + t ∉ coreThreeGeFive p := by rw [hmem_iff, ht_add]; simp [hz1, hzn1, hz2, hzn2, hz0] have hn2 : x - t ∉ coreThreeGeFive p := by rw [hmem_iff, ht_sub]; simp [hnz1, hnzn1, hnz2, hnzn2, hnz0] have hn3 : 0 + t ∉ coreThreeGeFive p := by rw [hmem_iff, h0_add]; simp [hz1, hzn1, hz2, hzn2, hz0] have hn4 : 0 - t ∉ coreThreeGeFive p := by rw [hmem_iff, h0_sub]; simp [hnz1, hnzn1, hnz2, hnzn2, hnz0] unfold indC; rw [if_neg hn1, if_neg hn2, if_neg hn3, if_neg hn4] have hfiber_eq : Fiber (coreThreeGeFive p) 0 = {s0, s1, s2} := by ext x simp only [Finset.mem_insert, Finset.mem_singleton] constructor · intro hx obtain ⟨_, hprof⟩ := (mem_fiber_iff_profile (coreThreeGeFive p) h0_not x).1 hx have htA0 : indC (coreThreeGeFive p) (0 + ![0, c, 0]) + indC (coreThreeGeFive p) (0 - ![0, c, 0]) = 1 := by have hp_in : (0 + ![0, c, 0] : Fin 3 → ZMod p) ∈ coreThreeGeFive p := by rw [hmem_iff]; right; right; right; right; simp have hm_out : (0 - ![0, c, 0] : Fin 3 → ZMod p) ∉ coreThreeGeFive p := by rw [hmem_iff]; simp [h1.symm, hneg1_0.symm, h2.symm, hneg2_0.symm]; exact hc_neg.symm unfold indC; rw [if_pos hp_in, if_neg hm_out] have htB0 : indC (coreThreeGeFive p) (0 + ![c, 0, 0]) + indC (coreThreeGeFive p) (0 - ![c, 0, 0]) = 1 := by have hp_in : (0 + ![c, 0, 0] : Fin 3 → ZMod p) ∈ coreThreeGeFive p := by rw [hmem_iff]; right; right; right; right; simp have hm_out : (0 - ![c, 0, 0] : Fin 3 → ZMod p) ∉ coreThreeGeFive p := by rw [hmem_iff]; simp [h1.symm, hneg1_0.symm, h2.symm, hneg2_0.symm]; exact hc_neg.symm unfold indC; rw [if_pos hp_in, if_neg hm_out] have hx2 : x 2 = 0 := by have hA := (hprof ![0, c, 0]).trans htA0 have hB := (hprof ![c, 0, 0]).trans htB0 have hnot_eq : ∀ u v : Fin 3 → ZMod p, indC (coreThreeGeFive p) u + indC (coreThreeGeFive p) v = 1 → ((u ∈ coreThreeGeFive p) ↔ (v ∈ coreThreeGeFive p)) → False := by intro u v huv hiff unfold indC at huv by_cases hu : u ∈ coreThreeGeFive p · rw [if_pos hu, if_pos (hiff.1 hu)] at huv; omega · rw [if_neg hu, if_neg (fun hv => hu (hiff.2 hv))] at huv; omega by_cases h1' : x 2 = 1 · exfalso; refine hnot_eq _ _ hA ?_ rw [hmem_iff, hmem_iff] have ha2 : (x + ![0, c, 0]) 2 = 1 := by simp [h1'] have hm2 : (x - ![0, c, 0]) 2 = 1 := by simp [h1'] have ha0 : (x + ![0, c, 0]) 0 = x 0 := by simp have hm0 : (x - ![0, c, 0]) 0 = x 0 := by simp rw [ha2, hm2, ha0, hm0]; simp [h1_neg1, h2_1.symm, hneg2_1.symm, h1] · by_cases hn1' : x 2 = -1 · exfalso; refine hnot_eq _ _ hA ?_ rw [hmem_iff, hmem_iff] have ha2 : (x + ![0, c, 0]) 2 = -1 := by simp [hn1'] have hm2 : (x - ![0, c, 0]) 2 = -1 := by simp [hn1'] have ha0 : (x + ![0, c, 0]) 0 = x 0 := by simp have hm0 : (x - ![0, c, 0]) 0 = x 0 := by simp rw [ha2, hm2, ha0, hm0]; simp [h1_neg1.symm, h2_neg1.symm, hneg2_neg1.symm, hneg1_0] · by_cases h2' : x 2 = 2 · exfalso; refine hnot_eq _ _ hB ?_ rw [hmem_iff, hmem_iff] have ha2 : (x + ![c, 0, 0]) 2 = 2 := by simp [h2'] have hm2 : (x - ![c, 0, 0]) 2 = 2 := by simp [h2'] have ha1 : (x + ![c, 0, 0]) 1 = x 1 := by simp have hm1 : (x - ![c, 0, 0]) 1 = x 1 := by simp rw [ha2, hm2, ha1, hm1]; simp [h2_1, h2_neg1, hneg2_2.symm, h2] · by_cases hn2' : x 2 = -2 · exfalso; refine hnot_eq _ _ hB ?_ rw [hmem_iff, hmem_iff] have ha2 : (x + ![c, 0, 0]) 2 = -2 := by simp [hn2'] have hm2 : (x - ![c, 0, 0]) 2 = -2 := by simp [hn2'] have ha1 : (x + ![c, 0, 0]) 1 = x 1 := by simp have hm1 : (x - ![c, 0, 0]) 1 = x 1 := by simp rw [ha2, hm2, ha1, hm1]; simp [hneg2_1, hneg2_neg1, hneg2_2, hneg2_0] · by_contra h0' have ha2 : (x + ![0, c, 0]) 2 = x 2 := by simp have hm2 : (x - ![0, c, 0]) 2 = x 2 := by simp have hn_p : x + ![0, c, 0] ∉ coreThreeGeFive p := by rw [hmem_iff, ha2]; simp [h1', hn1', h2', hn2', h0'] have hn_m : x - ![0, c, 0] ∉ coreThreeGeFive p := by rw [hmem_iff, hm2]; simp [h1', hn1', h2', hn2', h0'] unfold indC at hA; rw [if_neg hn_p, if_neg hn_m] at hA; omega have hx0 : x 0 = 0 ∨ x 0 = 1 := by let t1 : Fin 3 → ZMod p := ![0, 0, 1] have h10 := hprof t1 have h0_rhs : indC (coreThreeGeFive p) (0 + t1) + indC (coreThreeGeFive p) (0 - t1) = 1 := by have hp_in : (0 + t1 : Fin 3 → ZMod p) ∈ coreThreeGeFive p := by rw [hmem_iff]; left; simp [t1] have hm_out : (0 - t1 : Fin 3 → ZMod p) ∉ coreThreeGeFive p := by rw [hmem_iff]; simp [t1, h1_neg1.symm, h2_neg1.symm, hneg2_neg1.symm, hneg1_0, h1.symm] unfold indC; rw [if_pos hp_in, if_neg hm_out] rw [h0_rhs] at h10 have hp_iff : x + t1 ∈ coreThreeGeFive p ↔ x 0 = 0 := by rw [hmem_iff] have ha2 : (x + t1) 2 = 1 := by simp [t1, hx2] have ha0 : (x + t1) 0 = x 0 := by simp [t1] rw [ha2, ha0]; simp [h1_neg1, h2_1.symm, hneg2_1.symm, h1] have hm_iff : x - t1 ∈ coreThreeGeFive p ↔ x 0 = 1 := by rw [hmem_iff] have hm2 : (x - t1) 2 = -1 := by simp [t1, hx2] have hm0 : (x - t1) 0 = x 0 := by simp [t1] rw [hm2, hm0]; simp [h1_neg1.symm, h2_neg1.symm, hneg2_neg1.symm, hneg1_0] unfold indC at h10; simp only [hp_iff, hm_iff] at h10 by_cases h0 : x 0 = 0 · left; exact h0 · right; by_contra h1'; rw [if_neg h0, if_neg h1'] at h10; omega have hx1 : x 1 = 0 ∨ x 1 = 1 := by let t2 : Fin 3 → ZMod p := ![0, 0, 2] have h20 := hprof t2 have h0_rhs : indC (coreThreeGeFive p) (0 + t2) + indC (coreThreeGeFive p) (0 - t2) = 1 := by have hp_in : (0 + t2 : Fin 3 → ZMod p) ∈ coreThreeGeFive p := by rw [hmem_iff]; right; right; left; simp [t2] have hm_out : (0 - t2 : Fin 3 → ZMod p) ∉ coreThreeGeFive p := by rw [hmem_iff]; simp [t2, hneg2_1, hneg2_neg1, hneg2_2, hneg2_0, h1.symm] unfold indC; rw [if_pos hp_in, if_neg hm_out] rw [h0_rhs] at h20 have hp_iff : x + t2 ∈ coreThreeGeFive p ↔ x 1 = 0 := by rw [hmem_iff] have ha2 : (x + t2) 2 = 2 := by simp [t2, hx2] have ha1 : (x + t2) 1 = x 1 := by simp [t2] rw [ha2, ha1]; simp [h2_1, h2_neg1, hneg2_2.symm, h2] have hm_iff : x - t2 ∈ coreThreeGeFive p ↔ x 1 = 1 := by rw [hmem_iff] have hm2 : (x - t2) 2 = -2 := by simp [t2, hx2] have hm1 : (x - t2) 1 = x 1 := by simp [t2] rw [hm2, hm1]; simp [hneg2_1, hneg2_neg1, hneg2_2, hneg2_0] unfold indC at h20; simp only [hp_iff, hm_iff] at h20 by_cases h0 : x 1 = 0 · left; exact h0 · right; by_contra h1'; rw [if_neg h0, if_neg h1'] at h20; omega rcases hx0 with h0 | h0 <;> rcases hx1 with h1' | h1' · left; funext i; fin_cases i <;> simp [s0, h0, h1', hx2] · right; right; funext i; fin_cases i <;> simp [s2, h0, h1', hx2] · right; left; funext i; fin_cases i <;> simp [s1, h0, h1', hx2] · exfalso have hB := (hprof ![c, 0, 0]).trans htB0 have hn_p : x + ![c, 0, 0] ∉ coreThreeGeFive p := by rw [hmem_iff] have ha2 : (x + ![c, 0, 0]) 2 = 0 := by simp [hx2] have ha0 : (x + ![c, 0, 0]) 0 = 1 + c := by simp [h0] have ha1 : (x + ![c, 0, 0]) 1 = 1 := by simp [h1'] rw [ha2, ha0, ha1]; simp [h1.symm, hneg1_0.symm, h2.symm, hneg2_0.symm] intro h; exact h2pc_ne (by linear_combination h) have hn_m : x - ![c, 0, 0] ∉ coreThreeGeFive p := by rw [hmem_iff] have hm2 : (x - ![c, 0, 0]) 2 = 0 := by simp [hx2] have hm0 : (x - ![c, 0, 0]) 0 = 1 - c := by simp [h0] have hm1 : (x - ![c, 0, 0]) 1 = 1 := by simp [h1'] rw [hm2, hm0, hm1]; simp [h1.symm, hneg1_0.symm, h2.symm, hneg2_0.symm] intro h; exact h2mc_ne (by linear_combination h) unfold indC at hB; rw [if_neg hn_p, if_neg hn_m] at hB; omega · rintro (rfl | rfl | rfl) · exact hs_mem s0 rfl (Or.inl rfl) (Or.inl rfl) (Or.inl (by simp [s0])) · exact hs_mem s1 rfl (Or.inr rfl) (Or.inl rfl) (Or.inr (by simp [s1])) · exact hs_mem s2 rfl (Or.inl rfl) (Or.inr rfl) (Or.inr (by simp [s2])) refine ⟨haper, h0_not, ?_⟩ rw [hfiber_eq] have h01 : s0 ≠ s1 := fun h => h1 (congr_fun h 0).symm have h02 : s0 ≠ s2 := fun h => h1 (congr_fun h 1).symm have h12 : s1 ≠ s2 := fun h => h1 (congr_fun h 0) rw [Finset.card_insert_of_notMem, Finset.card_insert_of_notMem, Finset.card_singleton] · simp [h12] · simp [h01, h02] /-- Explicit 9-element aperiodic core in `(ZMod 3)^3` with fiber `{0, ![1,0,0], ![0,1,0]}` of size 3. -/ def coreThreeZMod3 : Finset (Fin 3 → ZMod 3) := { ![0, 0, 1], ![0, 1, 1], ![1, 0, 1], ![0, 0, 2], ![0, 1, 2], ![1, 0, 2], ![1, 1, 2], ![1, 2, 2], ![2, 1, 2] } private lemma fiber_card_three_zmod3 : IsAperiodic coreThreeZMod3 ∧ (0 : Fin 3 → ZMod 3) ∉ coreThreeZMod3 ∧ (Fiber coreThreeZMod3 0).card = 3 := by have haper : IsAperiodic coreThreeZMod3 := by intro g hg have hdec : ∀ g : Fin 3 → ZMod 3, coreThreeZMod3.image (· + g) = coreThreeZMod3 → g = 0 := by decide exact hdec g hg have h0_not : (0 : Fin 3 → ZMod 3) ∉ coreThreeZMod3 := by decide refine ⟨haper, h0_not, ?_⟩ have hfiber : Fiber coreThreeZMod3 0 = {0, ![1, 0, 0], ![0, 1, 0]} := by ext x rw [mem_fiber_iff_profile coreThreeZMod3 h0_not] have hdec : (x ∉ coreThreeZMod3 ∧ ∀ t : Fin 3 → ZMod 3, indC coreThreeZMod3 (x + t) + indC coreThreeZMod3 (x - t) = indC coreThreeZMod3 (0 + t) + indC coreThreeZMod3 (0 - t)) ↔ x ∈ ({0, ![1, 0, 0], ![0, 1, 0]} : Finset (Fin 3 → ZMod 3)) := by revert x; decide exact hdec rw [hfiber]; decide /-- For every odd prime `p ≥ 3`, `(ZMod p)^3` admits an aperiodic core with fiber cardinality `3`. -/ theorem exists_fiber_card_three (hp3 : 3 ≤ p) : ∃ (C : Finset (Fin 3 → ZMod p)) (x₀ : Fin 3 → ZMod p), IsAperiodic C ∧ x₀ ∉ C ∧ (Fiber C x₀).card = 3 := by have hp : p.Prime := Fact.out by_cases hp5 : 5 ≤ p · exact ⟨coreThreeGeFive p, 0, fiber_card_three_of_ge_five hp5⟩ · have hp_eq : p = 3 := by have hne4 : p ≠ 4 := fun h => by subst h; exact absurd hp (by decide) omega subst hp_eq exact ⟨coreThreeZMod3, 0, fiber_card_three_zmod3⟩ /-! ### Witness for `k = 4` (all odd primes `p ≥ 3`) -/ /-- Explicit 4-slice core in `(ZMod p)^3` yielding a fiber of size 4 for every prime `p ≥ 5`. -/ def coreFourGeFive (p : ℕ) [NeZero p] : Finset (Fin 3 → ZMod p) := Finset.univ.filter fun u => (u 2 = 1 ∧ u 0 = 0) ∨ (u 2 = -1 ∧ u 0 = 1) ∨ (u 2 = 2 ∧ u 1 = 0) ∨ (u 2 = -2 ∧ u 1 = 1) private lemma fiber_card_four_of_ge_five (hp5 : 5 ≤ p) : IsAperiodic (coreFourGeFive p) ∧ (0 : Fin 3 → ZMod p) ∉ coreFourGeFive p ∧ (Fiber (coreFourGeFive p) 0).card = 4 := by have h1 : (1 : ZMod p) ≠ 0 := one_ne_zero have h2 : (2 : ZMod p) ≠ 0 := by simpa using natCast_ne_zero_of_lt (p := p) (n := 2) (by omega) (by omega) have h3 : (3 : ZMod p) ≠ 0 := by simpa using natCast_ne_zero_of_lt (p := p) (n := 3) (by omega) (by omega) have h4 : (4 : ZMod p) ≠ 0 := by simpa using natCast_ne_zero_of_lt (p := p) (n := 4) (by omega) (by omega) have h1_neg1 : (1 : ZMod p) ≠ -1 := fun h => h2 (by linear_combination h) have h2_1 : (2 : ZMod p) ≠ 1 := fun h => h1 (by linear_combination h) have h2_neg1 : (2 : ZMod p) ≠ -1 := fun h => h3 (by linear_combination h) have hneg2_0 : (-2 : ZMod p) ≠ 0 := fun h => h2 (by linear_combination -h) have hneg2_1 : (-2 : ZMod p) ≠ 1 := fun h => h3 (by linear_combination -h) have hneg2_neg1 : (-2 : ZMod p) ≠ -1 := fun h => h1 (by linear_combination -h) have hneg2_2 : (-2 : ZMod p) ≠ 2 := fun h => h4 (by linear_combination -h) have hneg1_0 : (-1 : ZMod p) ≠ 0 := fun h => h1 (by linear_combination -h) have hmem_iff : ∀ u : Fin 3 → ZMod p, u ∈ coreFourGeFive p ↔ (u 2 = 1 ∧ u 0 = 0) ∨ (u 2 = -1 ∧ u 0 = 1) ∨ (u 2 = 2 ∧ u 1 = 0) ∨ (u 2 = -2 ∧ u 1 = 1) := fun u => by simp [coreFourGeFive] have h0_not : (0 : Fin 3 → ZMod p) ∉ coreFourGeFive p := by rw [hmem_iff]; simp only [Pi.zero_apply] rintro (⟨h, _⟩ | ⟨h, _⟩ | ⟨h, _⟩ | ⟨h, _⟩) · exact h1 h.symm · exact hneg1_0 h.symm · exact h2 h.symm · exact hneg2_0 h.symm -- 1. Aperiodicity: vertical slices `z = ±1` cannot map to horizontal slices `z = ±2`, -- so `1 + g 2 ∈ {1, -1}` and `-1 + g 2 ∈ {1, -1}`, forcing `g 2 = 0` since `2 ≠ -2`! have haper : IsAperiodic (coreFourGeFive p) := by intro g hg have hshift : ∀ u : Fin 3 → ZMod p, u ∈ coreFourGeFive p → u + g ∈ coreFourGeFive p := by intro u hu; rw [← hg]; exact Finset.mem_image_of_mem _ hu have hvert : ∀ z₀ x₀ : ZMod p, (![x₀, 0, z₀] : Fin 3 → ZMod p) ∈ coreFourGeFive p → (![x₀, 1, z₀] : Fin 3 → ZMod p) ∈ coreFourGeFive p → z₀ + g 2 = 1 ∨ z₀ + g 2 = -1 := by intro z₀ x₀ ha hb have hma := (hmem_iff (![x₀, 0, z₀] + g)).1 (hshift _ ha) have hmb := (hmem_iff (![x₀, 1, z₀] + g)).1 (hshift _ hb) simp only [Pi.add_apply, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.cons_val_two, Matrix.head_cons, Matrix.tail_cons, zero_add] at hma hmb rcases hma with ⟨hz, _⟩ | ⟨hz, _⟩ | ⟨hz, hy1⟩ | ⟨hz, hy1⟩ · left; exact hz · right; exact hz · rcases hmb with ⟨hz2, _⟩ | ⟨hz2, _⟩ | ⟨_, hy2⟩ | ⟨hz2, _⟩ · exact absurd (hz.symm.trans hz2) h2_1 · exact absurd (hz.symm.trans hz2) h2_neg1 · exact absurd (by linear_combination hy2 - hy1 : (1 : ZMod p) = 0) h1 · exact absurd (hz2.symm.trans hz) hneg2_2 · rcases hmb with ⟨hz2, _⟩ | ⟨hz2, _⟩ | ⟨hz2, _⟩ | ⟨_, hy2⟩ · exact absurd (hz.symm.trans hz2) hneg2_1 · exact absurd (hz.symm.trans hz2) hneg2_neg1 · exact absurd (hz.symm.trans hz2) hneg2_2 · exact absurd (by linear_combination hy2 - hy1 : (1 : ZMod p) = 0) h1 have h1g : 1 + g 2 = 1 ∨ 1 + g 2 = -1 := hvert 1 0 (by rw [hmem_iff]; left; simp) (by rw [hmem_iff]; left; simp) have hn1g : -1 + g 2 = 1 ∨ -1 + g 2 = -1 := hvert (-1) 1 (by rw [hmem_iff]; right; left; simp) (by rw [hmem_iff]; right; left; simp) have hg2 : g 2 = 0 := by rcases h1g with h | h · linear_combination h · rcases hn1g with h' | h' · exact absurd (by linear_combination h' - h : (-2 : ZMod p) = 2) hneg2_2 · linear_combination h' have hg0 : g 0 = 0 := by let v : Fin 3 → ZMod p := ![0, 0, 1] have hv : v ∈ coreFourGeFive p := by rw [hmem_iff]; left; simp [v] have hmv := (hmem_iff (v + g)).1 (hshift v hv) simp only [Pi.add_apply, v, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.cons_val_two, Matrix.head_cons, Matrix.tail_cons, hg2, add_zero, zero_add] at hmv rcases hmv with ⟨_, h⟩ | ⟨h, _⟩ | ⟨h, _⟩ | ⟨h, _⟩ · exact h · exact absurd h h1_neg1 · exact absurd h.symm h2_1 · exact absurd h.symm hneg2_1 have hg1 : g 1 = 0 := by let w : Fin 3 → ZMod p := ![0, 0, 2] have hw : w ∈ coreFourGeFive p := by rw [hmem_iff]; right; right; left; simp [w] have hmw := (hmem_iff (w + g)).1 (hshift w hw) simp only [Pi.add_apply, w, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.cons_val_two, Matrix.head_cons, Matrix.tail_cons, hg2, add_zero, zero_add] at hmw rcases hmw with ⟨h, _⟩ | ⟨h, _⟩ | ⟨_, h⟩ | ⟨h, _⟩ · exact absurd h h2_1 · exact absurd h h2_neg1 · exact h · exact absurd h.symm hneg2_2 funext i; fin_cases i <;> assumption -- 2. All 4 sites `{0, ![1,0,0], ![0,1,0], ![1,1,0]}` belong to `Fiber (coreFourGeFive p) 0`. have hs_mem : ∀ x : Fin 3 → ZMod p, x 2 = 0 → (x 0 = 0 ∨ x 0 = 1) → (x 1 = 0 ∨ x 1 = 1) → x ∈ Fiber (coreFourGeFive p) 0 := by intro x hx2 hx0 hx1 rw [mem_fiber_iff_profile (coreFourGeFive p) h0_not] refine ⟨?_, ?_⟩ · rw [hmem_iff] rintro (⟨h, _⟩ | ⟨h, _⟩ | ⟨h, _⟩ | ⟨h, _⟩) · exact h1 (h.symm.trans hx2) · exact hneg1_0 (h.symm.trans hx2) · exact h2 (h.symm.trans hx2) · exact hneg2_0 (h.symm.trans hx2) · intro t have ht_add : (x + t) 2 = t 2 := by simp [hx2] have ht_sub : (x - t) 2 = -t 2 := by simp [hx2] have h0_add : (0 + t : Fin 3 → ZMod p) 2 = t 2 := by simp have h0_sub : (0 - t : Fin 3 → ZMod p) 2 = -t 2 := by simp by_cases hz1 : t 2 = 1 · have hnegz : -t 2 = -1 := by rw [hz1] have hx_p : x + t ∈ coreFourGeFive p ↔ x 0 + t 0 = 0 := by rw [hmem_iff, ht_add, hz1]; simp [h1_neg1, h2_1.symm, hneg2_1.symm] have hx_m : x - t ∈ coreFourGeFive p ↔ x 0 - t 0 = 1 := by rw [hmem_iff, ht_sub, hnegz]; simp [h1_neg1.symm, h2_neg1.symm, hneg2_neg1.symm] have h0_p : 0 + t ∈ coreFourGeFive p ↔ t 0 = 0 := by rw [hmem_iff, h0_add, hz1]; simp [h1_neg1, h2_1.symm, hneg2_1.symm] have h0_m : 0 - t ∈ coreFourGeFive p ↔ -t 0 = 1 := by rw [hmem_iff, h0_sub, hnegz]; simp [h1_neg1.symm, h2_neg1.symm, hneg2_neg1.symm] unfold indC; simp only [hx_p, hx_m, h0_p, h0_m] rcases hx0 with h0 | h0 · simp [h0] · rw [h0] have e1 : (1 + t 0 = 0) ↔ (-t 0 = 1) := by constructor <;> intro h <;> linear_combination -h have e2 : (1 - t 0 = 1) ↔ (t 0 = 0) := by constructor <;> intro h <;> linear_combination -h simp only [e1, e2]; omega · by_cases hzn1 : t 2 = -1 · have hnegz : -t 2 = 1 := by rw [hzn1, neg_neg] have hx_p : x + t ∈ coreFourGeFive p ↔ x 0 + t 0 = 1 := by rw [hmem_iff, ht_add, hzn1]; simp [h1_neg1.symm, h2_neg1.symm, hneg2_neg1.symm] have hx_m : x - t ∈ coreFourGeFive p ↔ x 0 - t 0 = 0 := by rw [hmem_iff, ht_sub, hnegz]; simp [h1_neg1, h2_1.symm, hneg2_1.symm] have h0_p : 0 + t ∈ coreFourGeFive p ↔ t 0 = 1 := by rw [hmem_iff, h0_add, hzn1]; simp [h1_neg1.symm, h2_neg1.symm, hneg2_neg1.symm] have h0_m : 0 - t ∈ coreFourGeFive p ↔ -t 0 = 0 := by rw [hmem_iff, h0_sub, hnegz]; simp [h1_neg1, h2_1.symm, hneg2_1.symm] unfold indC; simp only [hx_p, hx_m, h0_p, h0_m] rcases hx0 with h0 | h0 · simp [h0] · rw [h0] have e1 : (1 + t 0 = 1) ↔ (-t 0 = 0) := by constructor <;> intro h <;> linear_combination -h have e2 : (1 - t 0 = 0) ↔ (t 0 = 1) := by constructor <;> intro h <;> linear_combination -h simp only [e1, e2]; omega · by_cases hz2 : t 2 = 2 · have hnegz : -t 2 = -2 := by rw [hz2] have hx_p : x + t ∈ coreFourGeFive p ↔ x 1 + t 1 = 0 := by rw [hmem_iff, ht_add, hz2]; simp [h2_1, h2_neg1, hneg2_2.symm] have hx_m : x - t ∈ coreFourGeFive p ↔ x 1 - t 1 = 1 := by rw [hmem_iff, ht_sub, hnegz]; simp [hneg2_1, hneg2_neg1, hneg2_2] have h0_p : 0 + t ∈ coreFourGeFive p ↔ t 1 = 0 := by rw [hmem_iff, h0_add, hz2]; simp [h2_1, h2_neg1, hneg2_2.symm] have h0_m : 0 - t ∈ coreFourGeFive p ↔ -t 1 = 1 := by rw [hmem_iff, h0_sub, hnegz]; simp [hneg2_1, hneg2_neg1, hneg2_2] unfold indC; simp only [hx_p, hx_m, h0_p, h0_m] rcases hx1 with h0 | h0 · simp [h0] · rw [h0] have e1 : (1 + t 1 = 0) ↔ (-t 1 = 1) := by constructor <;> intro h <;> linear_combination -h have e2 : (1 - t 1 = 1) ↔ (t 1 = 0) := by constructor <;> intro h <;> linear_combination -h simp only [e1, e2]; omega · by_cases hzn2 : t 2 = -2 · have hnegz : -t 2 = 2 := by rw [hzn2, neg_neg] have hx_p : x + t ∈ coreFourGeFive p ↔ x 1 + t 1 = 1 := by rw [hmem_iff, ht_add, hzn2]; simp [hneg2_1, hneg2_neg1, hneg2_2] have hx_m : x - t ∈ coreFourGeFive p ↔ x 1 - t 1 = 0 := by rw [hmem_iff, ht_sub, hnegz]; simp [h2_1, h2_neg1, hneg2_2.symm] have h0_p : 0 + t ∈ coreFourGeFive p ↔ t 1 = 1 := by rw [hmem_iff, h0_add, hzn2]; simp [hneg2_1, hneg2_neg1, hneg2_2] have h0_m : 0 - t ∈ coreFourGeFive p ↔ -t 1 = 0 := by rw [hmem_iff, h0_sub, hnegz]; simp [h2_1, h2_neg1, hneg2_2.symm] unfold indC; simp only [hx_p, hx_m, h0_p, h0_m] rcases hx1 with h0 | h0 · simp [h0] · rw [h0] have e1 : (1 + t 1 = 1) ↔ (-t 1 = 0) := by constructor <;> intro h <;> linear_combination -h have e2 : (1 - t 1 = 0) ↔ (t 1 = 1) := by constructor <;> intro h <;> linear_combination -h simp only [e1, e2]; omega · have hnz1 : -t 2 ≠ 1 := fun h => hzn1 (by linear_combination -h) have hnzn1 : -t 2 ≠ -1 := fun h => hz1 (by linear_combination -h) have hnz2 : -t 2 ≠ 2 := fun h => hzn2 (by linear_combination -h) have hnzn2 : -t 2 ≠ -2 := fun h => hz2 (by linear_combination -h) have hn1 : x + t ∉ coreFourGeFive p := by rw [hmem_iff, ht_add]; simp [hz1, hzn1, hz2, hzn2] have hn2 : x - t ∉ coreFourGeFive p := by rw [hmem_iff, ht_sub]; simp [hnz1, hnzn1, hnz2, hnzn2] have hn3 : 0 + t ∉ coreFourGeFive p := by rw [hmem_iff, h0_add]; simp [hz1, hzn1, hz2, hzn2] have hn4 : 0 - t ∉ coreFourGeFive p := by rw [hmem_iff, h0_sub]; simp [hnz1, hnzn1, hnz2, hnzn2] unfold indC; rw [if_neg hn1, if_neg hn2, if_neg hn3, if_neg hn4] let s0 : Fin 3 → ZMod p := 0 let s1 : Fin 3 → ZMod p := ![1, 0, 0] let s2 : Fin 3 → ZMod p := ![0, 1, 0] let s3 : Fin 3 → ZMod p := ![1, 1, 0] have hsub4 : ({s0, s1, s2, s3} : Finset (Fin 3 → ZMod p)) ⊆ Fiber (coreFourGeFive p) 0 := by intro x hx simp only [Finset.mem_insert, Finset.mem_singleton] at hx rcases hx with rfl | rfl | rfl | rfl · exact hs_mem s0 rfl (Or.inl rfl) (Or.inl rfl) · exact hs_mem s1 rfl (Or.inr rfl) (Or.inl rfl) · exact hs_mem s2 rfl (Or.inl rfl) (Or.inr rfl) · exact hs_mem s3 rfl (Or.inr rfl) (Or.inr rfl) have hcard_4 : ({s0, s1, s2, s3} : Finset (Fin 3 → ZMod p)).card = 4 := by have h01 : s0 ≠ s1 := fun h => h1 (congr_fun h 0).symm have h02 : s0 ≠ s2 := fun h => h1 (congr_fun h 1).symm have h03 : s0 ≠ s3 := fun h => h1 (congr_fun h 0).symm have h12 : s1 ≠ s2 := fun h => h1 (congr_fun h 0) have h13 : s1 ≠ s3 := fun h => h1 (congr_fun h 1).symm have h23 : s2 ≠ s3 := fun h => h1 (congr_fun h 0).symm rw [Finset.card_insert_of_notMem, Finset.card_insert_of_notMem, Finset.card_insert_of_notMem, Finset.card_singleton] <;> simp [h01, h02, h03, h12, h13, h23] have hge4 : 4 ≤ (Fiber (coreFourGeFive p) 0).card := by rw [← hcard_4]; exact Finset.card_le_card hsub4 have hle4 : (Fiber (coreFourGeFive p) 0).card ≤ 4 := rank3_fiber_card_le_four (by omega) (coreFourGeFive p) haper h0_not exact ⟨haper, h0_not, by omega⟩ /-- Explicit 12-element aperiodic core in `(ZMod 3)^3` with fiber `{0, ![0,0,1], ![0,1,0], ![1,0,0]}` of size 4. -/ def coreFourZMod3 : Finset (Fin 3 → ZMod 3) := { ![0, 0, 2], ![0, 1, 2], ![0, 2, 2], ![1, 0, 1], ![1, 2, 1], ![1, 2, 2], ![2, 0, 0], ![2, 1, 0], ![2, 1, 2], ![2, 2, 0], ![2, 2, 1], ![2, 2, 2] } private lemma fiber_card_four_zmod3 : IsAperiodic coreFourZMod3 ∧ (0 : Fin 3 → ZMod 3) ∉ coreFourZMod3 ∧ (Fiber coreFourZMod3 0).card = 4 := by have haper : IsAperiodic coreFourZMod3 := by intro g hg have hdec : ∀ g : Fin 3 → ZMod 3, coreFourZMod3.image (· + g) = coreFourZMod3 → g = 0 := by decide exact hdec g hg have h0_not : (0 : Fin 3 → ZMod 3) ∉ coreFourZMod3 := by decide refine ⟨haper, h0_not, ?_⟩ have hfiber : Fiber coreFourZMod3 0 = {0, ![0, 0, 1], ![0, 1, 0], ![1, 0, 0]} := by ext x rw [mem_fiber_iff_profile coreFourZMod3 h0_not] have hdec : (x ∉ coreFourZMod3 ∧ ∀ t : Fin 3 → ZMod 3, indC coreFourZMod3 (x + t) + indC coreFourZMod3 (x - t) = indC coreFourZMod3 (0 + t) + indC coreFourZMod3 (0 - t)) ↔ x ∈ ({0, ![0, 0, 1], ![0, 1, 0], ![1, 0, 0]} : Finset (Fin 3 → ZMod 3)) := by revert x; decide exact hdec rw [hfiber]; decide /-- For every odd prime `p ≥ 3`, `(ZMod p)^3` admits an aperiodic core with fiber cardinality `4`. -/ theorem exists_fiber_card_four (hp3 : 3 ≤ p) : ∃ (C : Finset (Fin 3 → ZMod p)) (x₀ : Fin 3 → ZMod p), IsAperiodic C ∧ x₀ ∉ C ∧ (Fiber C x₀).card = 4 := by have hp : p.Prime := Fact.out by_cases hp5 : 5 ≤ p · exact ⟨coreFourGeFive p, 0, fiber_card_four_of_ge_five hp5⟩ · have hp_eq : p = 3 := by have hne4 : p ≠ 4 := fun h => by subst h; exact absurd hp (by decide) omega subst hp_eq exact ⟨coreFourZMod3, 0, fiber_card_four_zmod3⟩ end SpectrumWitnesses section ExactSpectrum /-- **Complete Fiber-Size Spectrum Theorem in `(ZMod p)^3`**: For every odd prime `p ≥ 3` and every `k : ℕ`, there exist an aperiodic support `C : Finset (Fin 3 → ZMod p)` and `x₀ ∉ C` with `(Fiber C x₀).card = k` if and only if `k ∈ {1, 2, 3, 4}`. -/ theorem rank3_fiber_size_spectrum {p : ℕ} [Fact p.Prime] (hp3 : 3 ≤ p) (k : ℕ) : (∃ (C : Finset (Fin 3 → ZMod p)) (x₀ : Fin 3 → ZMod p), IsAperiodic C ∧ x₀ ∉ C ∧ (Fiber C x₀).card = k) ↔ k ∈ ({1, 2, 3, 4} : Finset ℕ) := by simp only [Finset.mem_insert, Finset.mem_singleton] constructor · rintro ⟨C, x₀, hC, hx₀, rfl⟩ have hpos : 1 ≤ (Fiber C x₀).card := Finset.one_le_card.2 ⟨x₀, mem_fiber_self C hx₀⟩ have hle4 : (Fiber C x₀).card ≤ 4 := rank3_fiber_card_le_four hp3 C hC hx₀ omega · rintro (rfl | rfl | rfl | rfl) · exact exists_fiber_card_one hp3 · exact exists_fiber_card_two hp3 · exact exists_fiber_card_three hp3 · exact exists_fiber_card_four hp3 end ExactSpectrum #print axioms rank3_fiber_card_le_four #print axioms exists_fiber_card_one #print axioms exists_fiber_card_two #print axioms exists_fiber_card_three #print axioms exists_fiber_card_four #print axioms rank3_fiber_size_spectrum end OpenAlgebraTopology.Rank3Spectrum