/-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