πŸ›οΈ Atlasβœ’οΈFormalizations.NumberTheory.NumericalSemigroup.HalfSystems view on GitHub β†—12 theorems
/-Copyright (c) 2026 Carles MarΓ­n. All rights reserved.Released under Apache 2.0 license as described in the file LICENSE.Authors: Carles MarΓ­n, Claude (AI assistant)-/module public import Mathlib.FieldTheory.Finite.Basicpublic import Mathlib.Algebra.Polynomial.BigOperatorspublic import Mathlib.Algebra.Polynomial.Eval.Degree /-!# Vanishing even moments characterise Gauss's half-systems Proposition `prop:semisistema` of *The order generated by a column of the SU(n)β‚– S-matrix (Part II)*:over a finite field `K` of characteristic `β‰  2` with `q` elements, a set `T` of non-zero elements whose evenmoments `βˆ‘_{t ∈ T} t ^ (2k)` vanish for `1 ≀ k` and `2k < q - 1` (that is, `2 ≀ r ≀ q - 3`) is empty, all of`KΛ£`, or a half-system (exactly one of `a`, `-a` for every `a β‰  0`); conversely half-systems have those momentszero. The note states it for `𝔽_p` and attributes it to nobody (it was not found under five vocabularies). The proof follows the note: group `T` by squares, `w(y) = #{t ∈ T | tΒ² = y}`; the moments become`βˆ‘_{y ∈ QR} w(y) y^k`; the quadratic residues have `βˆ‘ y^k = 0` in the same range; and a Vandermonde step(done here with the polynomial `X Β· ∏ (X - r)`) forces `w` to be constant, `0`, `1` or `2`. ## Main results * `HalfSystems.eq_zero_of_moments`: the Vandermonde step.* `HalfSystems.trichotomy`: the proposition.* `HalfSystems.moments_of_halfSystem`: the converse.-/ @[expose] public section open Finset Polynomial namespace HalfSystems section Vandermonde variable {K : Type*} [Field K] [DecidableEq K] /-- If `d` vanishes at `qβ‚€ ∈ Q` and `βˆ‘_{q ∈ Q} d q Β· q^k = 0` for `1 ≀ k < #Q`, with `0 βˆ‰ Q`, then `d = 0` on `Q`. -/theorem eq_zero_of_moments {Q : Finset K} (h0 : (0 : K) βˆ‰ Q) {qβ‚€ : K} (hqβ‚€ : qβ‚€ ∈ Q) (d : K β†’ K)    (hdβ‚€ : d qβ‚€ = 0) (hmom : βˆ€ k, 1 ≀ k β†’ k < Q.card β†’ βˆ‘ q ∈ Q, d q * q ^ k = 0) :    βˆ€ q₁ ∈ Q, d q₁ = 0 := by  intro q₁ hq₁  by_cases h01 : q₁ = qβ‚€  Β· rw [h01]; exact hdβ‚€  set R := (Q.erase qβ‚€).erase q₁ with hR  have hq₁' : q₁ ∈ Q.erase qβ‚€ := mem_erase.2 ⟨h01, hqβ‚βŸ©  have hRcard : R.card + 2 = Q.card := by    have h1 := card_erase_of_mem hq₁'    have h2 := card_erase_of_mem hqβ‚€    have h3 : 1 ≀ (Q.erase qβ‚€).card := card_pos.2 ⟨q₁, hq₁'⟩    rw [hR, h1, h2]    have h4 : 1 ≀ Q.card - 1 := by rw [← h2]; exact h3    omega  set P : K[X] := X * ∏ r ∈ R, (X - C r) with hP  have hmon : (∏ r ∈ R, (X - C r)).Monic := monic_prod_of_monic _ _ fun r _ => monic_X_sub_C r  have hdeg : P.natDegree < Q.card := by    rw [hP, monic_X.natDegree_mul hmon, natDegree_X, natDegree_finsetProd_X_sub_C_eq_card]    omega  have key : βˆ‘ q ∈ Q, d q * P.eval q = 0 := by    calc βˆ‘ q ∈ Q, d q * P.eval q        = βˆ‘ q ∈ Q, d q * βˆ‘ j ∈ range Q.card, P.coeff j * q ^ j := by          refine sum_congr rfl fun q _ => ?_          rw [eval_eq_sum_range' hdeg]      _ = βˆ‘ j ∈ range Q.card, P.coeff j * βˆ‘ q ∈ Q, d q * q ^ j := by          simp_rw [mul_sum]          rw [sum_comm]          refine sum_congr rfl fun j _ => sum_congr rfl fun q _ => by ring      _ = 0 := by          refine sum_eq_zero fun j hj => ?_          rcases Nat.eq_zero_or_pos j with hj0 | hjpos          Β· rw [hj0, hP, coeff_X_mul_zero, zero_mul]          Β· rw [hmom j hjpos (mem_range.1 hj), mul_zero]  have single : βˆ‘ q ∈ Q, d q * P.eval q = d q₁ * P.eval q₁ := by    refine sum_eq_single q₁ (fun q hq hne => ?_) (fun h => absurd hq₁ h)    by_cases hq0 : q = qβ‚€    Β· rw [hq0, hdβ‚€, zero_mul]    Β· have hqR : q ∈ R := mem_erase.2 ⟨hne, mem_erase.2 ⟨hq0, hq⟩⟩      have : (∏ r ∈ R, (X - C r)).eval q = 0 := by        rw [eval_prod]        exact prod_eq_zero hqR (by simp)      rw [hP, eval_mul, this, mul_zero, mul_zero]  have hne : P.eval q₁ β‰  0 := by    rw [hP, eval_mul, eval_X, eval_prod]    refine mul_ne_zero (fun h => h0 (h β–Έ hq₁)) ?_    refine prod_ne_zero_iff.2 fun r hr => ?_    simp only [eval_sub, eval_X, eval_C]    intro h    have : q₁ = r := sub_eq_zero.1 h    exact (mem_erase.1 hr).1 this.symm  rw [key] at single  exact (mul_eq_zero.1 single.symm).resolve_right hne end Vandermonde section FiniteField variable {K : Type*} [Field K] [Fintype K] [DecidableEq K] /-- The non-zero squares. -/def QR (K : Type*) [Field K] [Fintype K] [DecidableEq K] : Finset K := (univ.erase 0).image (Β· ^ 2) /-- `w T y` = number of `t ∈ T` with `tΒ² = y`. -/def w (T : Finset K) (y : K) : β„• := #{t ∈ T | t ^ 2 = y} variable (h2 : (2 : K) β‰  0)include h2 omit [Fintype K] [DecidableEq K] intheorem neg_ne_self {x : K} (hx : x β‰  0) : -x β‰  x := by  intro h  have : (2 : K) * x = 0 := by linear_combination -h  exact hx ((mul_eq_zero.1 this).resolve_left h2) omit [Fintype K] inset_option linter.unusedSectionVars false intheorem filter_sq_eq (S : Finset K) (x : K) : {t ∈ S | t ^ 2 = x ^ 2} = S.filter (fun t => t = x ∨ t = -x) := by  ext t  simp only [mem_filter, sq_eq_sq_iff_eq_or_eq_neg] theorem card_fiber_two {x : K} (hx : x β‰  0) : #{t ∈ univ.erase (0 : K) | t ^ 2 = x ^ 2} = 2 := by  rw [filter_sq_eq h2]  have : (univ.erase (0 : K)).filter (fun t => t = x ∨ t = -x) = {x, -x} := by    ext t    simp only [mem_filter, mem_erase, mem_univ, and_true, mem_insert, mem_singleton]    constructor    Β· exact fun h => h.2    Β· rintro (h | h) <;> refine ⟨?_, by tauto⟩ <;> rw [h]      Β· exact hx      Β· exact neg_ne_zero.2 hx  rw [this, card_pair (neg_ne_self h2 hx).symm] set_option linter.unusedSectionVars false intheorem mapsTo_QR (T : Finset K) (hT : (0 : K) βˆ‰ T) : (T : Set K).MapsTo (Β· ^ 2) (QR K) := by  intro t ht  simp only [QR, coe_image, Set.mem_image, mem_coe, mem_erase, mem_univ, and_true]  exact ⟨t, fun h => hT (h β–Έ ht), rfl⟩ theorem sum_moment (T : Finset K) (hT : (0 : K) βˆ‰ T) (k : β„•) :    βˆ‘ t ∈ T, t ^ (2 * k) = βˆ‘ y ∈ QR K, (w T y : K) * y ^ k := by  rw [← sum_fiberwise_of_maps_to (mapsTo_QR h2 T hT)]  refine sum_congr rfl fun y _ => ?_  rw [w, ← nsmul_eq_mul, ← sum_const]  refine sum_congr rfl fun t ht => ?_  rw [(mem_filter.1 ht).2.symm, pow_mul] theorem two_mul_card_QR : 2 * (QR K).card = Fintype.card K - 1 := by  have h := card_eq_sum_card_fiberwise (mapsTo_QR h2 (univ.erase (0 : K)) (by simp))  rw [card_erase_of_mem (mem_univ _), card_univ] at h  rw [h, mul_comm, ← smul_eq_mul, ← sum_const]  refine sum_congr rfl fun y hy => ?_  obtain ⟨x, hx, rfl⟩ := mem_image.1 hy  exact (card_fiber_two h2 (mem_erase.1 hx).1).symm theorem sum_QR_pow {k : β„•} (hk : 1 ≀ k) (hk2 : 2 * k < Fintype.card K - 1) : βˆ‘ y ∈ QR K, y ^ k = 0 := by  have hall := FiniteField.sum_pow_lt_card_sub_one (K := K) (2 * k) hk2  have h0 : βˆ‘ x : K, x ^ (2 * k) = βˆ‘ x ∈ univ.erase (0 : K), x ^ (2 * k) := by    rw [← add_sum_erase _ _ (mem_univ (0 : K)), zero_pow (by omega), zero_add]  rw [h0, sum_moment h2 _ (by simp)] at hall  have hw : βˆ€ y ∈ QR K, (w (univ.erase (0 : K)) y : K) = 2 := by    intro y hy    obtain ⟨x, hx, rfl⟩ := mem_image.1 hy    rw [w, card_fiber_two h2 (mem_erase.1 hx).1]    norm_num  rw [sum_congr rfl fun y hy => by rw [hw y hy], ← mul_sum] at hall  exact (mul_eq_zero.1 hall).resolve_left h2 omit [Fintype K] [DecidableEq K] intheorem cast_inj_le_two {a b : β„•} (ha : a ≀ 2) (hb : b ≀ 2) (h : (a : K) = (b : K)) : a = b := by  have h1 : (1 : K) β‰  0 := one_ne_zero  interval_cases a <;> interval_cases b  all_goals first    | rfl    | (exfalso; push_cast at h; first        | exact h1 h | exact h1 h.symm | exact h2 h | exact h2 h.symm        | exact h1 (by linear_combination -h) | exact h1 (by linear_combination h)) omit [Fintype K] intheorem w_le_two (T : Finset K) {x : K} (_hx : x β‰  0) : w T (x ^ 2) ≀ 2 := by  rw [w, filter_sq_eq h2]  calc #(T.filter fun t => t = x ∨ t = -x) ≀ #({x, -x} : Finset K) := by        refine card_le_card fun t ht => ?_        rcases (mem_filter.1 ht).2 with h | h <;> simp [h]    _ ≀ 2 := card_le_two /-- Proposition `prop:semisistema`. -/theorem trichotomy (T : Finset K) (hT : (0 : K) βˆ‰ T)    (hmom : βˆ€ k, 1 ≀ k β†’ 2 * k < Fintype.card K - 1 β†’ βˆ‘ t ∈ T, t ^ (2 * k) = 0) :    T = βˆ… ∨ T = univ.erase 0 ∨ βˆ€ a : K, a β‰  0 β†’ (a ∈ T ↔ -a βˆ‰ T) := by  have hcard := two_mul_card_QR h2 (K := K)  have h1Q : (1 : K) ∈ QR K := mem_image.2 ⟨1, by simp, one_pow 2⟩  have hdzero := eq_zero_of_moments (Q := QR K) (by simp [QR]) h1Q    (fun y => (w T y : K) - (w T 1 : K)) (by simp) (by      intro k hk hkQ      have h2k : 2 * k < Fintype.card K - 1 := by omega      simp_rw [sub_mul, sum_sub_distrib, ← mul_sum]      rw [← sum_moment h2 T hT, hmom k hk h2k, sum_QR_pow h2 hk h2k, mul_zero, sub_zero])  -- w is constant on the squares: c = w T 1  have hconst : βˆ€ x : K, x β‰  0 β†’ w T (x ^ 2) = w T 1 := by    intro x hx    have := hdzero (x ^ 2) (mem_image.2 ⟨x, by simp [hx], rfl⟩)    exact cast_inj_le_two h2 (w_le_two h2 T hx) (by simpa using w_le_two h2 T one_ne_zero)      (sub_eq_zero.1 this)  have hfib : βˆ€ x : K, x β‰  0 β†’ w T (x ^ 2) = #(T.filter fun t => t = x ∨ t = -x) := by    intro x _; rw [w, filter_sq_eq h2]  have hpair : βˆ€ x : K, x β‰  0 β†’ (T.filter fun t => t = x ∨ t = -x) =      (if x ∈ T then {x} else βˆ…) βˆͺ (if -x ∈ T then {-x} else βˆ…) := by    intro x _    ext t    by_cases hxT : x ∈ T <;> by_cases hnT : -x ∈ T <;>      simp only [mem_filter, mem_union, hxT, hnT, ite_true, ite_false, mem_singleton, notMem_empty] <;>      constructor <;> intro h <;> aesop  have hcount : βˆ€ x : K, x β‰  0 β†’      w T (x ^ 2) = (if x ∈ T then 1 else 0) + (if -x ∈ T then 1 else 0) := by    intro x hx    rw [hfib x hx, hpair x hx]    by_cases hxT : x ∈ T <;> by_cases hnT : -x ∈ T <;> simp only [hxT, hnT, ite_true, ite_false]    Β· rw [card_union_of_disjoint (disjoint_singleton.2 (neg_ne_self h2 hx).symm)]; simp    Β· simp    Β· simp    Β· simp  have hc : w T 1 ≀ 2 := by simpa using w_le_two h2 T one_ne_zero  interval_cases hw1 : w T 1  Β· left    refine eq_empty_of_forall_notMem fun t ht => ?_    have h := hconst t (fun h => hT (h β–Έ ht))    rw [hcount t (fun h => hT (h β–Έ ht))] at h    simp [ht] at h  Β· right; right    intro a ha    have h := hconst a ha    rw [hcount a ha] at h    by_cases haT : a ∈ T <;> by_cases hnT : -a ∈ T <;> simp_all  Β· right; left    ext t    simp only [mem_erase, mem_univ, and_true]    constructor    Β· exact fun ht h => hT (h β–Έ ht)    Β· intro ht      have h := hconst t ht      rw [hcount t ht] at h      by_contra htT      rw [ite_eq_right htT] at h      split_ifs at h <;> omega /-- The converse: half-systems have the even moments zero. -/theorem moments_of_halfSystem (T : Finset K) (hT : (0 : K) βˆ‰ T)    (hhalf : βˆ€ a : K, a β‰  0 β†’ (a ∈ T ↔ -a βˆ‰ T)) {k : β„•} (hk : 1 ≀ k) (hk2 : 2 * k < Fintype.card K - 1) :    βˆ‘ t ∈ T, t ^ (2 * k) = 0 := by  rw [sum_moment h2 T hT]  have hw : βˆ€ y ∈ QR K, (w T y : K) = 1 := by    intro y hy    obtain ⟨x, hx, rfl⟩ := mem_image.1 hy    have hx0 := (mem_erase.1 hx).1    rw [w, filter_sq_eq h2]    have hsub : T.filter (fun t => t = x ∨ t = -x) = if x ∈ T then {x} else {-x} := by      ext t      by_cases hxT : x ∈ T      Β· have hn : -x βˆ‰ T := (hhalf x hx0).1 hxT        simp only [mem_filter, hxT, ite_true, mem_singleton]        constructor        Β· rintro ⟨ht, h | h⟩          Β· exact h          Β· exact absurd (h β–Έ ht) hn        Β· intro h; exact ⟨h β–Έ hxT, Or.inl h⟩      Β· have hn : -x ∈ T := by          by_contra h; exact hxT ((hhalf x hx0).2 h)        simp only [mem_filter, hxT, ite_false, mem_singleton]        constructor        Β· rintro ⟨ht, h | h⟩          Β· exact absurd (h β–Έ ht) hxT          Β· exact h        Β· intro h; exact ⟨h β–Έ hn, Or.inr h⟩    rw [hsub]    split_ifs <;> simp  rw [sum_congr rfl fun y hy => by rw [hw y hy, one_mul]]  exact sum_QR_pow h2 hk hk2 end FiniteField end HalfSystems