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.LinearAlgebra.Dimension.Finrank import Mathlib.LinearAlgebra.Dual.Lemmas import Mathlib.LinearAlgebra.LinearIndependent.Lemmas import Mathlib.Tactic.Linarith import Mathlib.Tactic.FieldSimp /-! # General `3 * 2 ^ (r - 2)` Upper Bound for Elementary Abelian Homometry Fibers For every odd prime `p ≥ 3`, every rank `r ≥ 2`, every aperiodic support `C : Finset (Fin r → ZMod p)`, and every `x₀ ∉ C`, we prove: `(Fiber C x₀).card ≤ 3 * 2 ^ (r - 2)`. This improves the no-full-cube bound `< 2 ^ r` (`≤ 2 ^ r - 1`) by a uniform multiplicative factor of `3 / 4` across all ranks `r ≥ 2`. ## Proof 1. Active characters span `(ZMod p)^r`; pick an active basis, change coordinates, shift `x₀ ↦ 0`, and embed `Fiber C₁ 0` into `Fintype.piFinset S` where each `|S i| ≤ 2`. 2. If `|Fiber C₁ 0| > 3 * 2 ^ (r - 2)`, then every `|S i| = 2` (since any `|S i| ≤ 1` yields `|Fiber| ≤ 2 ^ (r - 1) ≤ 3 * 2 ^ (r - 2)`). Rescaling places `Fiber C₂ 0 ⊆ {0, 1}^r`. 3. Every active character `ξ` of `C₂` must have Hamming weight `≤ 1`: if `ξ i ≠ 0` and `ξ j ≠ 0` with `i ≠ j`, partition `{0, 1}^r` into `2 ^ (r - 2)` two-dimensional faces by fixing all coordinates outside `{i, j}`. Because `p ≥ 3` is odd, `ξ · u` takes at least 3 distinct values on every 2-face, while an active character takes at most 2 values on `Fiber C₂ 0`. Thus `Fiber C₂ 0` meets each 2-face in at most 3 of its 4 vertices, giving `|Fiber C₂ 0| ≤ 3 * 2 ^ (r - 2)`, contradiction. 4. Hence `1_{C₂}(u) = c₀ + ∑_i g_i(u i)` is a sum of 1D functions taking values in `{0, 1}`, so at most one `g_i` is nonconstant; since `r ≥ 2`, some `g_k` is constant, contradicting aperiodicity. -/ namespace OpenAlgebraTopology.TwoFaceBound 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₀] 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)) end Core section MainBound variable {p r : ℕ} [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 have hzero : a - b = 0 := AddChar.zmodAddEquiv.injective (hall.trans (map_zero _).symm) exact sub_eq_zero.1 hzero private def dotHomR (p r : ℕ) (ξ : Fin r → ZMod p) : (Fin r → ZMod p) →+ ZMod p where toFun u := ∑ i : Fin r, ξ 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 charR (p r : ℕ) [NeZero p] (ξ : Fin r → ZMod p) : AddChar (Fin r → ZMod p) ℂ := (e1 p).compAddMonoidHom (dotHomR p r ξ) private lemma charR_apply (p r : ℕ) [NeZero p] (ξ u : Fin r → ZMod p) : charR p r ξ u = e1 p (∑ i : Fin r, ξ i * u i) := rfl private lemma charR_injective (p r : ℕ) [NeZero p] : Function.Injective (charR p r) := by intro ξ η h funext i have hi := DFunLike.congr_fun h (Pi.single i (1 : ZMod p)) simp only [charR_apply, Pi.single_apply, mul_ite, mul_one, mul_zero, Finset.sum_ite_eq', Finset.mem_univ, ↓reduceIte] at hi exact e1_injective p hi private lemma charR_bijective (p r : ℕ) [NeZero p] : Function.Bijective (charR p r) := by rw [Fintype.bijective_iff_injective_and_card, AddChar.card_eq] exact ⟨charR_injective p r, rfl⟩ private noncomputable def FR (C : Finset (Fin r → ZMod p)) (ξ : Fin r → ZMod p) : ℂ := fourierCoeff C (charR p r ξ) private lemma fourier_inversion_zmodR (C : Finset (Fin r → ZMod p)) (u : Fin r → ZMod p) : ∑ ξ : Fin r → ZMod p, FR C ξ * charR p r ξ u = ((p ^ r : ℕ) : ℂ) * (indC C u : ℂ) := by have h := fourier_inversion_indC C u have hbij := Fintype.sum_bijective (charR p r) (charR_bijective p r) (fun ξ => FR C ξ * charR p r ξ u) (fun χ => fourierCoeff C χ * χ u) (fun _ => rfl) rw [hbij, h] simp [Fintype.card_pi, ZMod.card] private lemma isAperiodic_of_orthog_zeroR {C : Finset (Fin r → ZMod p)} (hC : IsAperiodic C) {g : Fin r → ZMod p} (hg : ∀ ξ : Fin r → ZMod p, FR C ξ ≠ 0 → ∑ i : Fin r, ξ i * g i = 0) : g = 0 := by have hind : ∀ u : Fin r → ZMod p, indC C (u + g) = indC C u := by intro u have h1 := fourier_inversion_zmodR C (u + g) have h2 := fourier_inversion_zmodR C u have hsum : ∑ ξ : Fin r → ZMod p, FR C ξ * charR p r ξ (u + g) = ∑ ξ : Fin r → ZMod p, FR C ξ * charR p r ξ u := by refine Finset.sum_congr rfl fun ξ _ => ?_ by_cases hF : FR C ξ = 0 · simp [hF] · have hdot := hg ξ hF have hch : charR p r ξ (u + g) = charR p r ξ u := by rw [AddChar.map_add_eq_mul, charR_apply p r ξ g, hdot, AddChar.map_zero_eq_one, mul_one] rw [hch] rw [h1, h2] at hsum have hpr : ((p ^ r : ℕ) : ℂ) ≠ 0 := Nat.cast_ne_zero.2 (pow_ne_zero r (Fact.out : p.Prime).ne_zero) exact Nat.cast_injective (mul_left_cancel₀ hpr 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_top {C : Finset (Fin r → ZMod p)} (hC : IsAperiodic C) : Submodule.span (ZMod p) {ξ : Fin r → ZMod p | FR C ξ ≠ 0} = ⊤ := by set W : Submodule (ZMod p) (Fin r → ZMod p) := Submodule.span (ZMod p) {ξ : Fin r → ZMod p | FR C ξ ≠ 0} by_contra hne have hfin_lt : Module.finrank (ZMod p) W < Module.finrank (ZMod p) (Fin r → ZMod p) := Submodule.finrank_lt hne let Φ : (Fin r → ZMod p) →ₗ[ZMod p] Module.Dual (ZMod p) W := { toFun := fun g => { toFun := fun w => ∑ i : Fin r, 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 r → 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_zeroR hC intro ξ hF have h0 : Φ g ⟨ξ, Submodule.subset_span hF⟩ = 0 := by rw [LinearMap.mem_ker.1 hg_ker]; rfl exact h0 /-- **Two-Face Partition Lemma**: For an odd prime `p ≥ 3`, if `ξ : Fin r → ZMod p` has two distinct nonzero coordinates `i ≠ j` and takes at most 2 values on a subset `F ⊆ {0, 1}^r`, then `F.card ≤ 3 * 2 ^ (r - 2)`. -/ private lemma card_le_three_mul_two_pow_of_weight_ge_two {p r : ℕ} [Fact p.Prime] (hp3 : 3 ≤ p) (hr : 2 ≤ r) {F : Finset (Fin r → ZMod p)} (hF_cube : ∀ u ∈ F, ∀ k : Fin r, u k = 0 ∨ u k = 1) {ξ : Fin r → ZMod p} {i j : Fin r} (hij : i ≠ j) (hi : ξ i ≠ 0) (hj : ξ j ≠ 0) (hle2 : ∀ u₁ ∈ F, ∀ u₂ ∈ F, ∀ u₃ ∈ F, (∑ k, ξ k * u₁ k) = (∑ k, ξ k * u₂ k) ∨ (∑ k, ξ k * u₁ k) = (∑ k, ξ k * u₃ k) ∨ (∑ k, ξ k * u₂ k) = (∑ k, ξ k * u₃ k)) : F.card ≤ 3 * 2 ^ (r - 2) := 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 -- Map each `u ∈ F` to its restriction `proj u : {k : Fin r // k ≠ i ∧ k ≠ j} → Bool`. let ι := {k : Fin r // k ≠ i ∧ k ≠ j} let proj : (Fin r → ZMod p) → (ι → Bool) := fun u k => decide (u k.1 = 1) -- Each fiber of `proj` inside `F` has cardinality at most 3! have hfiber_le3 : ∀ y : ι → Bool, (F.filter fun u => proj u = y).card ≤ 3 := by intro y -- On a fixed fiber `y`, all coordinates outside `{i, j}` are determined by `y`! have hsame_other : ∀ u ∈ F.filter (fun u => proj u = y), ∀ v ∈ F.filter (fun u => proj u = y), ∀ k : Fin r, k ≠ i → k ≠ j → u k = v k := by intro u hu v hv k hki hkj have huF := (Finset.mem_filter.1 hu).1 have hvF := (Finset.mem_filter.1 hv).1 have huy : proj u ⟨k, hki, hkj⟩ = y ⟨k, hki, hkj⟩ := congr_fun (Finset.mem_filter.1 hu).2 _ have hvy : proj v ⟨k, hki, hkj⟩ = y ⟨k, hki, hkj⟩ := congr_fun (Finset.mem_filter.1 hv).2 _ have hdec : decide (u k = 1) = decide (v k = 1) := huy.trans hvy.symm rcases hF_cube u huF k with hu0 | hu1 <;> rcases hF_cube v hvF k with hv0 | hv1 · rw [hu0, hv0] · simp [hu0, hv1] at hdec · simp [hu1, hv0] at hdec · rw [hu1, hv1] -- Suppose for contradiction the fiber has size ≥ 4; then all 4 vertices of the 2-face belong to `F`! by_contra hgt3 have hge4 : 4 ≤ (F.filter fun u => proj u = y).card := by omega -- Any two elements in the fiber that agree on `(i, j)` are equal! have hinj_ij : ∀ u ∈ F.filter (fun u => proj u = y), ∀ v ∈ F.filter (fun u => proj u = y), u i = v i → u j = v j → u = v := by intro u hu v hv h1 h2 funext k by_cases hki : k = i · subst hki; exact h1 · by_cases hkj : k = j · subst hkj; exact h2 · exact hsame_other u hu v hv k hki hkj -- Map the fiber injectively into `{0, 1} × {0, 1}` (size 4), so it hits all 4 pairs! let pair : (Fin r → ZMod p) → ZMod p × ZMod p := fun u => (u i, u j) let G4 : Finset (ZMod p × ZMod p) := {(0, 0), (1, 0), (0, 1), (1, 1)} have hsub4 : (F.filter fun u => proj u = y).image pair ⊆ G4 := by intro w hw obtain ⟨u, hu, rfl⟩ := Finset.mem_image.1 hw have huF := (Finset.mem_filter.1 hu).1 rcases hF_cube u huF i with h1 | h1 <;> rcases hF_cube u huF j with h2 | h2 <;> simp [G4, pair, h1, h2] have hcard_img : ((F.filter fun u => proj u = y).image pair).card = (F.filter fun u => proj u = y).card := Finset.card_image_of_injOn fun u hu v hv h => hinj_ij u hu v hv (congr_arg Prod.fst h) (congr_arg Prod.snd h) have hcard_G4 : G4.card ≤ 4 := by refine (Finset.card_insert_le _ _).trans ?_ refine Nat.add_le_add_right ((Finset.card_insert_le _ _).trans ?_) 1 refine Nat.add_le_add_right ((Finset.card_insert_le _ _).trans ?_) 1 simp have himg_eq : (F.filter fun u => proj u = y).image pair = G4 := Finset.eq_of_subset_of_card_le hsub4 (by omega) have h00_mem : (0, 0) ∈ (F.filter fun u => proj u = y).image pair := by rw [himg_eq]; simp [G4] have h10_mem : (1, 0) ∈ (F.filter fun u => proj u = y).image pair := by rw [himg_eq]; simp [G4] have h01_mem : (0, 1) ∈ (F.filter fun u => proj u = y).image pair := by rw [himg_eq]; simp [G4] have h11_mem : (1, 1) ∈ (F.filter fun u => proj u = y).image pair := by rw [himg_eq]; simp [G4] obtain ⟨u00, hu00, hp00⟩ := Finset.mem_image.1 h00_mem obtain ⟨u10, hu10, hp10⟩ := Finset.mem_image.1 h10_mem obtain ⟨u01, hu01, hp01⟩ := Finset.mem_image.1 h01_mem obtain ⟨u11, hu11, hp11⟩ := Finset.mem_image.1 h11_mem -- Compute dot-product differences against `u00` cleanly by erasing `i` and `j`. have hdot_sub : ∀ u ∈ F.filter (fun u => proj u = y), (∑ k, ξ k * u k) - (∑ k, ξ k * u00 k) = ξ i * (u i - u00 i) + ξ j * (u j - u00 j) := by intro u hu rw [← Finset.sum_sub_distrib] rw [← Finset.add_sum_erase Finset.univ _ (Finset.mem_univ i)] have hj_in : j ∈ Finset.univ.erase i := Finset.mem_erase.2 ⟨hij.symm, Finset.mem_univ _⟩ rw [← Finset.add_sum_erase (Finset.univ.erase i) _ hj_in] have hrest : ∑ k ∈ (Finset.univ.erase i).erase j, (ξ k * u k - ξ k * u00 k) = 0 := by refine Finset.sum_eq_zero fun k hk => ?_ have hkj : k ≠ j := (Finset.mem_erase.1 hk).1 have hki : k ≠ i := (Finset.mem_erase.1 (Finset.mem_erase.1 hk).2).1 rw [hsame_other u hu u00 hu00 k hki hkj, sub_self] rw [hrest, add_zero] ring let D0 : ZMod p := ∑ k, ξ k * u00 k have hd10 : (∑ k, ξ k * u10 k) = D0 + ξ i := by have h := hdot_sub u10 hu10 have hi10 : u10 i = 1 := congr_arg Prod.fst hp10 have hj10 : u10 j = 0 := congr_arg Prod.snd hp10 have hi00 : u00 i = 0 := congr_arg Prod.fst hp00 have hj00 : u00 j = 0 := congr_arg Prod.snd hp00 rw [hi10, hj10, hi00, hj00] at h linear_combination h have hd01 : (∑ k, ξ k * u01 k) = D0 + ξ j := by have h := hdot_sub u01 hu01 have hi01 : u01 i = 0 := congr_arg Prod.fst hp01 have hj01 : u01 j = 1 := congr_arg Prod.snd hp01 have hi00 : u00 i = 0 := congr_arg Prod.fst hp00 have hj00 : u00 j = 0 := congr_arg Prod.snd hp00 rw [hi01, hj01, hi00, hj00] at h linear_combination h have hd11 : (∑ k, ξ k * u11 k) = D0 + ξ i + ξ j := by have h := hdot_sub u11 hu11 have hi11 : u11 i = 1 := congr_arg Prod.fst hp11 have hj11 : u11 j = 1 := congr_arg Prod.snd hp11 have hi00 : u00 i = 0 := congr_arg Prod.fst hp00 have hj00 : u00 j = 0 := congr_arg Prod.snd hp00 rw [hi11, hj11, hi00, hj00] at h linear_combination h -- Apply `hle2` to `{u00, u10, u01}` and `{u00, u10, u11}`! have htri1 := hle2 u00 (Finset.mem_filter.1 hu00).1 u10 (Finset.mem_filter.1 hu10).1 u01 (Finset.mem_filter.1 hu01).1 rw [hd10, hd01] at htri1 have hξeq : ξ i = ξ j := by rcases htri1 with h | h | h · exact absurd (by linear_combination -h : ξ i = 0) hi · exact absurd (by linear_combination -h : ξ j = 0) hj · linear_combination h have htri2 := hle2 u00 (Finset.mem_filter.1 hu00).1 u10 (Finset.mem_filter.1 hu10).1 u11 (Finset.mem_filter.1 hu11).1 rw [hd10, hd11] at htri2 rcases htri2 with h | h | h · exact hi (by linear_combination -h) · have h2ξ : 2 * ξ i = 0 := by linear_combination -h + hξeq exact (mul_eq_zero.1 h2ξ).elim h2ne0 hi · exact hj (by linear_combination -h) -- Sum the fiber cardinalities over all `y : ι → Bool`! have hsum_card : F.card = ∑ y : ι → Bool, (F.filter fun u => proj u = y).card := by rw [Finset.card_eq_sum_card_fiberwise (f := proj) (t := Finset.univ) (fun _ _ => Finset.mem_univ _)] have hcard_ι : Fintype.card ι = r - 2 := by have hsub_eq : Fintype.card ι = (Finset.univ.filter fun k : Fin r => k ≠ i ∧ k ≠ j).card := by rw [Fintype.card_subtype] rw [hsub_eq] have hfilt : Finset.univ.filter (fun k : Fin r => k ≠ i ∧ k ≠ j) = (Finset.univ.erase i).erase j := by ext k; simp [and_comm] rw [hfilt, Finset.card_erase_of_mem (Finset.mem_erase.2 ⟨hij.symm, Finset.mem_univ _⟩), Finset.card_erase_of_mem (Finset.mem_univ _), Finset.card_univ, Fintype.card_fin] omega calc F.card = ∑ y : ι → Bool, (F.filter fun u => proj u = y).card := hsum_card _ ≤ ∑ _y : ι → Bool, 3 := Finset.sum_le_sum fun y _ => hfiber_le3 y _ = Fintype.card (ι → Bool) * 3 := by simp _ = 3 * 2 ^ (r - 2) := by rw [Fintype.card_fun, Fintype.card_bool, hcard_ι, mul_comm] /-- **General `3 * 2 ^ (r - 2)` Upper Bound**: For every odd prime `p ≥ 3`, every rank `r ≥ 2`, every aperiodic support `C : Finset (Fin r → ZMod p)`, and every `x₀ ∉ C`, the single-point insertion fiber satisfies `(Fiber C x₀).card ≤ 3 * 2 ^ (r - 2)`. -/ theorem fiber_card_le_three_mul_two_pow {p r : ℕ} [Fact p.Prime] (hp3 : 3 ≤ p) (hr : 2 ≤ r) (C : Finset (Fin r → ZMod p)) (hC : IsAperiodic C) {x₀ : Fin r → ZMod p} (hx₀ : x₀ ∉ C) : (Fiber C x₀).card ≤ 3 * 2 ^ (r - 2) := by -- Step 1: Extract an active basis `b : Fin r → (Fin r → ZMod p)`. have hspan := active_span_top hC obtain ⟨t, ht_sub, ht_span, ht_li⟩ := exists_linearIndependent (ZMod p) {ξ : Fin r → ZMod p | FR C ξ ≠ 0} rw [hspan] at ht_span let : Fintype t := Fintype.ofFinite t let B : Module.Basis t (ZMod p) (Fin r → 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 = r := by have h1 := Module.finrank_eq_card_basis B rw [Module.finrank_fin_fun] at h1 exact h1.symm let e : Fin r ≃ t := (Fintype.equivFinOfCardEq hcard_t).symm let b : Fin r → (Fin r → ZMod p) := fun i => (e i).1 have hb_active : ∀ i : Fin r, FR 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] -- Step 2: Change coordinates via `Llin u i = ∑ j, b i j * u j`, shift `x₀ ↦ 0`. let Llin : (Fin r → ZMod p) →ₗ[ZMod p] (Fin r → ZMod p) := { toFun := fun u i => ∑ j : Fin r, 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 r → ZMod p) →ₗ[ZMod p] ZMod p := { toFun := fun ξ => ∑ j : Fin r, ξ 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 r → ZMod p) ≃+ (Fin r → 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 r → 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 r, FR C₁ (Pi.single i 1) ≠ 0 := by intro i have hcalc : FR C₁ (Pi.single i 1) = FR C (b i) * e1 p ((L x₀) i) := by unfold FR 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 _ => ?_ simp only [charR_apply, Pi.single_apply, ite_mul, one_mul, zero_mul, Finset.sum_ite_eq', Finset.mem_univ, ↓reduceIte, ← AddChar.map_add_eq_mul] congr 1 have hLu : (L u) i = ∑ j : Fin r, b i j * u j := rfl have hneg : (-(L u + a)) i = -(L u) i + (L x₀) i := by simp [a]; ring rw [hneg, hLu] simp only [Pi.neg_apply, mul_neg, Finset.sum_neg_distrib] rw [hcalc] exact mul_ne_zero (hb_active i) (addChar_apply_ne_zero (e1 p) _) -- Step 3: Coordinate projections `S i` satisfy `(S i).card ≤ 2`. let S : Fin r → Finset (ZMod p) := fun i => (Fiber C₁ 0).image (fun u => u i) have hS_le2 : ∀ i : Fin r, (S i).card ≤ 2 := by intro i by_contra hgt 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 hr1 := mem_fiber_fourier h0C₁ hu₁ (charR p r (Pi.single i 1)) have hr2 := mem_fiber_fourier h0C₁ hu₂ (charR p r (Pi.single i 1)) have hr3 := mem_fiber_fourier h0C₁ hu₃ (charR p r (Pi.single i 1)) have htri := unit_circle_re_eq_at_most_two (hactive_coord i) ((charR p r (Pi.single i 1)).norm_apply u₁) ((charR p r (Pi.single i 1)).norm_apply u₂) ((charR p r (Pi.single i 1)).norm_apply u₃) (hr1.trans hr2.symm) (hr1.trans hr3.symm) have hch : ∀ u : Fin r → ZMod p, charR p r (Pi.single i 1) u = e1 p (u i) := fun u => by simp [charR_apply, Pi.single_apply] simp only [hch] at htri rcases htri with h | h | h · exact h12 (hu₁v.symm.trans ((e1_injective p h).trans hu₂v)) · exact h13 (hu₁v.symm.trans ((e1_injective p h).trans hu₃v)) · exact h23 (hu₂v.symm.trans ((e1_injective p 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 -- Step 4: Assume `(Fiber C₁ 0).card > 3 * 2 ^ (r - 2)` for contradiction. rw [← hcard₁] by_contra hgt have hgt' : 3 * 2 ^ (r - 2) < (Fiber C₁ 0).card := by omega have hS_eq2 : ∀ i : Fin r, (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 r, (S j).card ≤ 2 ^ (r - 1) := 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)) _ = 2 ^ (r - 1) := by simp have hpow_le : 2 ^ (r - 1) ≤ 3 * 2 ^ (r - 2) := by have hr1 : r - 1 = (r - 2) + 1 := by omega rw [hr1, pow_succ] omega have hcard_prod : (Fiber C₁ 0).card ≤ ∏ j : Fin r, (S j).card := by rw [← Fintype.card_piFinset]; exact Finset.card_le_card hsub_pi omega -- Rescale `S i = {0, sc i}` to `{0, 1}`. have h0_in_S : ∀ i : Fin r, (0 : ZMod p) ∈ S i := fun i => Finset.mem_image.2 ⟨0, mem_fiber_self C₁ h0C₁, rfl⟩ have hex_sc : ∀ i : Fin r, ∃ 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 r → ZMod p) ≃+ (Fin r → 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 h0C₂ : (0 : Fin r → ZMod p) ∉ C₂ := by intro h obtain ⟨u, hu, hueq⟩ := Finset.mem_image.1 h have hu0 : u = 0 := D.injective (hueq.trans (map_zero D).symm) exact h0C₁ (hu0 ▸ hu) 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 : (Fiber C₂ 0).card = (Fiber C₁ 0).card := by rw [hF2_eq, Finset.card_image_of_injective _ D.injective] have hF2_cube : ∀ u ∈ Fiber C₂ 0, ∀ k : Fin r, 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 5: Every active character `ξ` of `C₂` has at most 1 nonzero coordinate (by Two-Face Lemma). have hsupport_le1 : ∀ ξ : Fin r → ZMod p, FR C₂ ξ ≠ 0 → ∀ i j : Fin r, ξ i ≠ 0 → ξ j ≠ 0 → i = j := by intro ξ hF i j hi hj by_contra hij have hle2 : ∀ u₁ ∈ Fiber C₂ 0, ∀ u₂ ∈ Fiber C₂ 0, ∀ u₃ ∈ Fiber C₂ 0, (∑ k, ξ k * u₁ k) = (∑ k, ξ k * u₂ k) ∨ (∑ k, ξ k * u₁ k) = (∑ k, ξ k * u₃ k) ∨ (∑ k, ξ k * u₂ k) = (∑ k, ξ k * u₃ k) := by intro u₁ h₁ u₂ h₂ u₃ h₃ have hr1 := mem_fiber_fourier h0C₂ h₁ (charR p r ξ) have hr2 := mem_fiber_fourier h0C₂ h₂ (charR p r ξ) have hr3 := mem_fiber_fourier h0C₂ h₃ (charR p r ξ) have htri := unit_circle_re_eq_at_most_two hF ((charR p r ξ).norm_apply u₁) ((charR p r ξ).norm_apply u₂) ((charR p r ξ).norm_apply u₃) (hr1.trans hr2.symm) (hr1.trans hr3.symm) 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 have hle_face := card_le_three_mul_two_pow_of_weight_ge_two hp3 hr hF2_cube hij hi hj hle2 omega -- Step 6: Additive 1D decomposition forces periodicity (contradicting `IsAperiodic C₂`). let N : ℝ := (p ^ r : ℕ) have hNpos : (0 : ℝ) < N := Nat.cast_pos.2 (pow_pos (Fact.out : p.Prime).pos r) let c₀ : ℝ := N⁻¹ * (FR C₂ 0).re let g : Fin r → ZMod p → ℝ := fun i x => N⁻¹ * (∑ c ∈ Finset.univ.erase (0 : ZMod p), FR C₂ (Pi.single i c) * e1 p (c * x)).re have hdecomp : ∀ u : Fin r → ZMod p, (indC C₂ u : ℝ) = c₀ + ∑ i : Fin r, g i (u i) := by intro u let T : Fin r → Finset (Fin r → ZMod p) := fun i => (Finset.univ.erase (0 : ZMod p)).image (Pi.single i) have hdisjT : Set.PairwiseDisjoint (↑(Finset.univ : Finset (Fin r)) : Set (Fin r)) T := by intro i _ j _ hij show Disjoint (T i) (T j) rw [Finset.disjoint_left] intro ξ h1 h2 obtain ⟨c₁, hc₁, rfl⟩ := Finset.mem_image.1 h1 obtain ⟨c₂, _, h2'⟩ := Finset.mem_image.1 h2 have := congr_fun h2' i simp [hij] at this exact (Finset.mem_erase.1 hc₁).1 this.symm have h0_notin_biUnion : (0 : Fin r → ZMod p) ∉ Finset.univ.biUnion T := by simp only [Finset.mem_biUnion, Finset.mem_univ, true_and, T, Finset.mem_image, Finset.mem_erase, not_exists, not_and] intro i c hc0 heq have := congr_fun heq i simp at this exact hc0.1 this have hcover : ∀ ξ : Fin r → ZMod p, FR C₂ ξ ≠ 0 → ξ ∈ insert (0 : Fin r → ZMod p) (Finset.univ.biUnion T) := by intro ξ hF by_cases hξ0 : ξ = 0 · rw [hξ0]; exact Finset.mem_insert_self _ _ · refine Finset.mem_insert_of_mem ?_ have hex : ∃ i : Fin r, ξ i ≠ 0 := by by_contra hall; push Not at hall; exact hξ0 (funext hall) obtain ⟨i, hi⟩ := hex rw [Finset.mem_biUnion] refine ⟨i, Finset.mem_univ i, Finset.mem_image.2 ⟨ξ i, Finset.mem_erase.2 ⟨hi, Finset.mem_univ _⟩, ?_⟩⟩ funext j by_cases hji : j = i · subst hji; simp · simp only [Pi.single_apply, if_neg hji] by_contra hj exact hji (hsupport_le1 ξ hF j i (Ne.symm hj) hi) have hinv := fourier_inversion_zmodR C₂ u have hsub : ∑ ξ : Fin r → ZMod p, FR C₂ ξ * charR p r ξ u = ∑ ξ ∈ insert (0 : Fin r → ZMod p) (Finset.univ.biUnion T), FR C₂ ξ * charR p r ξ u := by symm refine Finset.sum_subset (Finset.subset_univ _) fun ξ _ hnot => ?_ have hF0 : FR C₂ ξ = 0 := by by_contra hne; exact hnot (hcover ξ hne) simp [hF0] rw [hsub, Finset.sum_insert h0_notin_biUnion, Finset.sum_biUnion hdisjT] at hinv have hsumT : ∀ i : Fin r, ∑ ξ ∈ T i, FR C₂ ξ * charR p r ξ u = ∑ c ∈ Finset.univ.erase (0 : ZMod p), FR C₂ (Pi.single i c) * e1 p (c * u i) := by intro i rw [Finset.sum_image (fun a _ b _ h => by simpa using congr_fun h i)] refine Finset.sum_congr rfl fun c _ => ?_ simp [charR_apply, Pi.single_apply] simp_rw [hsumT] at hinv have h0char : charR p r 0 u = 1 := by simp [charR_apply] rw [h0char, mul_one] at hinv have hre := congr_arg Complex.re hinv rw [Complex.add_re, Complex.re_sum, Complex.mul_re, Complex.natCast_re, Complex.natCast_im, zero_mul, sub_zero, Complex.natCast_re] at hre have hNmul : N * (indC C₂ u : ℝ) = (FR C₂ 0).re + ∑ i : Fin r, (∑ c ∈ Finset.univ.erase (0 : ZMod p), FR C₂ (Pi.single i c) * e1 p (c * u i)).re := hre.symm dsimp only [c₀, g] rw [← Finset.mul_sum, ← mul_add, ← hNmul] have hN0 : N ≠ 0 := ne_of_gt hNpos field_simp [hN0] have hat_most_one : ∀ i j : Fin r, i ≠ j → (∀ a b : ZMod p, g i a = g i b) ∨ (∀ a b : ZMod p, g j a = g j b) := by intro i j hij by_contra hnc push Not at hnc obtain ⟨⟨a₁, a₂, ha⟩, ⟨b₁, b₂, hb⟩⟩ := hnc have hlt1 : ∃ x₁ x₂, g i x₁ < g i 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 j y₁ < g j 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 let u₁ : Fin r → ZMod p := Function.update (Function.update 0 i x₁) j y₁ let u₂ : Fin r → ZMod p := Function.update (Function.update 0 i x₂) j y₁ let u₃ : Fin r → ZMod p := Function.update (Function.update 0 i x₂) j y₂ have hdiff12 : (indC C₂ u₂ : ℝ) - (indC C₂ u₁ : ℝ) = g i x₂ - g i x₁ := by rw [hdecomp u₂, hdecomp u₁] have hterm : ∀ k : Fin r, g k (u₂ k) - g k (u₁ k) = if k = i then g i x₂ - g i x₁ else 0 := by intro k by_cases hki : k = i · subst hki; simp [u₁, u₂, hij] · by_cases hkj : k = j · subst hkj; simp [u₁, u₂, hki] · simp [u₁, u₂, hki, hkj] have hsum_val : (∑ k : Fin r, g k (u₂ k)) - (∑ k : Fin r, g k (u₁ k)) = g i x₂ - g i x₁ := by rw [← Finset.sum_sub_distrib, Finset.sum_congr rfl (fun k _ => hterm k)]; simp linarith have hdiff23 : (indC C₂ u₃ : ℝ) - (indC C₂ u₂ : ℝ) = g j y₂ - g j y₁ := by rw [hdecomp u₃, hdecomp u₂] have hterm : ∀ k : Fin r, g k (u₃ k) - g k (u₂ k) = if k = j then g j y₂ - g j y₁ else 0 := by intro k by_cases hkj : k = j · subst hkj; simp [u₂, u₃] · simp [u₂, u₃, hkj] have hsum_val : (∑ k : Fin r, g k (u₃ k)) - (∑ k : Fin r, g k (u₂ k)) = g j y₂ - g j y₁ := by rw [← Finset.sum_sub_distrib, Finset.sum_congr rfl (fun k _ => hterm k)]; simp linarith have hbin : ∀ u : Fin r → ZMod p, (indC C₂ u : ℝ) = 0 ∨ (indC C₂ u : ℝ) = 1 := fun u => by unfold indC; split_ifs <;> simp rcases hbin u₁ with h1 | h1 <;> rcases hbin u₂ with h2 | h2 <;> rcases hbin u₃ with h3 | h3 <;> linarith have hex_const : ∃ k : Fin r, ∀ a b : ZMod p, g k a = g k b := by let i0 : Fin r := ⟨0, by omega⟩ let i1 : Fin r := ⟨1, by omega⟩ have hne : i0 ≠ i1 := fun h => Nat.zero_ne_one (congr_arg Fin.val h) rcases hat_most_one i0 i1 hne with h0 | h1 · exact ⟨i0, h0⟩ · exact ⟨i1, h1⟩ obtain ⟨k, hk_const⟩ := hex_const let ek : Fin r → ZMod p := Pi.single k 1 have hek_ne : ek ≠ 0 := by intro h; have := congr_fun h k; simp [ek] at this have hind_per : ∀ u : Fin r → ZMod p, indC C₂ (u + ek) = indC C₂ u := by intro u have h1 := hdecomp (u + ek) have h2 := hdecomp u have hsum : ∑ i : Fin r, g i ((u + ek) i) = ∑ i : Fin r, g i (u i) := by refine Finset.sum_congr rfl fun i _ => ?_ by_cases hik : i = k · subst hik; exact hk_const _ _ · simp [ek, hik] rw [hsum] at h1 exact Nat.cast_injective (h1.trans h2.symm) have himg : C₂.image (· + (-ek)) = C₂ := by ext u simp only [Finset.mem_image] constructor · rintro ⟨v, hv, rfl⟩ have h := hind_per (v + -ek) have hsub : v + -ek + ek = v := by abel rw [hsub] at h unfold indC at h by_cases h1 : v ∈ C₂ <;> by_cases h2 : v + -ek ∈ C₂ <;> simp_all · intro hu refine ⟨u + ek, ?_, by abel⟩ have h := hind_per u unfold indC at h by_cases h1 : u + ek ∈ C₂ <;> by_cases h2 : u ∈ C₂ <;> simp_all have hneg0 := hC₂ (-ek) himg exact hek_ne (by simpa using congr_arg Neg.neg hneg0) end MainBound #print axioms fiber_card_le_three_mul_two_pow end OpenAlgebraTopology.TwoFaceBound