import Mathlib.Data.ZMod.Basic import Mathlib.Data.Finset.Card import Mathlib.Data.Fintype.Pi import Mathlib.Tactic.Abel /-! # Theorem 3.1: Unique Recovery over Elementary Abelian 2-Groups `(ZMod 2)^r` For `G = Fin r → ZMod 2`, any aperiodic `C : Finset G`, and any `x₀ ∉ C`, we prove `Fiber C x₀ = {x₀}`. -/ namespace AbelianHomometry.ElemAbelian2 open scoped BigOperators section Definitions 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 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 end Definitions /-- In `Fin r → ZMod 2`, subtraction coincides with addition. -/ private lemma sub_eq_add_zmod2 {r : ℕ} (x t : Fin r → ZMod 2) : x - t = x + t := by funext i change x i - t i = x i + t i have hneg : ∀ a : ZMod 2, -a = a := by decide rw [sub_eq_add_neg, hneg] /-- **Theorem 3.1**: Over any elementary abelian 2-group `(ZMod 2)^r`, every aperiodic support `C` and site `x₀ ∉ C` has unique single-point recovery: `Fiber C x₀ = {x₀}`. -/ theorem fiber_eq_singleton_elemAbelian2 {r : ℕ} (C : Finset (Fin r → ZMod 2)) (hC : IsAperiodic C) {x₀ : Fin r → ZMod 2} (hx₀ : x₀ ∉ C) : Fiber C x₀ = {x₀} := by classical ext x simp only [Fiber, Finset.mem_filter, Finset.mem_sdiff, Finset.mem_univ, true_and, Finset.mem_singleton] constructor · rintro ⟨hx, hauto⟩ have hprof := (autocorr_insert_eq_iff C hx hx₀).1 hauto have hmem : ∀ t : Fin r → ZMod 2, x + t ∈ C ↔ x₀ + t ∈ C := by intro t have ht := hprof t rw [sub_eq_add_zmod2 x t, sub_eq_add_zmod2 x₀ t] at ht have hind : indC C (x + t) = indC C (x₀ + t) := by omega unfold indC at hind by_cases h1 : x + t ∈ C <;> by_cases h2 : x₀ + t ∈ C <;> simp_all have himg : C.image (· + (x₀ - x)) = C := by ext u simp only [Finset.mem_image] constructor · rintro ⟨v, hv, rfl⟩ have h := (hmem (v - x)).1 (by simpa [add_sub_cancel] using hv) have heq : x₀ + (v - x) = v + (x₀ - x) := by abel rwa [← heq] · intro hu refine ⟨u - (x₀ - x), ?_, by abel⟩ have h := (hmem (u - x₀)).2 (by simpa [add_sub_cancel] using hu) have heq : x + (u - x₀) = u - (x₀ - x) := by abel rwa [← heq] have hzero : x₀ - x = 0 := hC (x₀ - x) himg exact (sub_eq_zero.1 hzero).symm · rintro rfl exact ⟨hx₀, rfl⟩ #print axioms fiber_eq_singleton_elemAbelian2 end AbelianHomometry.ElemAbelian2