🏛️ Atlas✒️Formalizations.NumberTheory.SymplecticCharacterOrders.SupportAndIndex view on GitHub ↗20 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-/module public import Mathlib.Data.ZMod.Basicpublic import Mathlib.Algebra.BigOperators.Intervalspublic import Mathlib.Data.Nat.Factorization.Basicpublic import Mathlib.Order.Interval.Finset.Natpublic import Mathlib.Tactic.Ringpublic import Mathlib.Tactic.Linarithpublic import Mathlib.Tactic.Zifypublic import Mathlib.Tactic.IntervalCases /-!# The support of the conductor and the index: the arithmetic With `S(c) = ∑_{1≤j≤m, j≡c} j − ∑_{1≤j≤m, j≡−c} j` (modulus `n`), this file proves the closedform of `S` and the arithmetic of the statements on the support of the conductor and on the index`[O : A]`. The ring-theoretic inputs (part (b) of the support theorem and the segment lemma`Segmentos.lem_seg`) enter as explicit hypotheses. ## Main results * `SopIndice.S_formula`: the four-case closed form of `S(c)` for `m = k n + r`, `0 ≤ r < n`,  `1 ≤ c ≤ n − 1`.* `SopIndice.sop_c_ii`: if `n ∤ h, h + 1, h + 2` (`h = 2m`), then for every prime `p` some `c`  with `2c ≢ 0 (mod n)` has `p ∤ S(c)`.* `SopIndice.sop_c`: part (c) of the support theorem, from the hypotheses above.* `SopIndice.indice_val`, `SopIndice.indice_hminus`, `SopIndice.indice_dos`,  `SopIndice.indice_small`, `SopIndice.indice_six`, `SopIndice.indice_prod`: the valuations, the  sufficient conditions for `W₁ > d/2`, the residues `q' ∈ {1, 2, 3, 4, 6}` and the product  formula for `[O : A]`. ## References * C. Marín, *Conductors of orders generated by character values of Sp(2m)*, preprint (2026);  programs and outputs: Zenodo, doi:10.5281/zenodo.23090540.* C. Marín, *Where the character values of Sp(2m) at a torsion element fail to generate the ring  of integers*, Zenodo (2026), doi:10.5281/zenodo.22813216 (a longer preprint of the same work).-/ @[expose] public section open Finset namespace SopIndice /-! ## The moment `S(c)` and its closed form -/ /-- `S(c) = ∑_{1≤j≤m, j≡c (n)} j − ∑_{1≤j≤m, j≡−c (n)} j`. -/def S (n m : ℕ) (c : ZMod n) : ℤ :=  ∑ j ∈ Icc 1 m, ((if (j : ZMod n) = c then (j : ℤ) else 0) -    (if (j : ZMod n) = -c then (j : ℤ) else 0)) /-- The four cases of the proof of `thm:sop`(c), for `m = kn + r` and `1 ≤ c ≤ n − 1`(`r < q' − c` is written `r + c < n`). -/def Sform (n k r c : ℕ) : ℤ :=  if c ≤ r ∧ r + c < n then (2 * k + 1) * c  else if n ≤ r + c ∧ r < c then -((2 * k + 1) * ((n : ℤ) - c))  else if n ≤ r + c ∧ c ≤ r then (k + 1) * (2 * c - n)  else k * (2 * c - n) /-- `D n m`: `n` divides `h = 2m`, `h + 1` or `h + 2`. -/def D (n m : ℕ) : Prop := n ∣ 2 * m ∨ n ∣ 2 * m + 1 ∨ n ∣ 2 * m + 2 lemma eq_of_dvd_lt {n x : ℕ} (h : n ∣ x) (h0 : 0 < x) (h2 : x < 2 * n) : x = n := by  obtain ⟨t, rfl⟩ := h  rcases t with _ | _ | t  · simp at h0  · ring  · nlinarith lemma S_succ (n m : ℕ) (c : ZMod n) :    S n (m + 1) c = S n m c + ((if ((m + 1 : ℕ) : ZMod n) = c then ((m + 1 : ℕ) : ℤ) else 0) -      (if ((m + 1 : ℕ) : ZMod n) = -c then ((m + 1 : ℕ) : ℤ) else 0)) := by  unfold S  rw [Finset.sum_Icc_succ_top (by omega)] /-- Membership of `kn + s` in the classes `c` and `−c`, for `0 < s < n`, `0 < c < n`. -/lemma cast_eq_c {n k s c : ℕ} (hs : s < n) (hc : c < n) :    (((k * n + s : ℕ)) : ZMod n) = (c : ZMod n) ↔ s = c := by  have : (((k * n + s : ℕ)) : ZMod n) = (s : ZMod n) := by push_cast; simp  rw [this, ZMod.natCast_eq_natCast_iff', Nat.mod_eq_of_lt hs, Nat.mod_eq_of_lt hc] lemma cast_eq_negc {n k s c : ℕ} (hs0 : 0 < s) (hs : s < n) (hc0 : 0 < c) (hc : c < n) :    (((k * n + s : ℕ)) : ZMod n) = -(c : ZMod n) ↔ s + c = n := by  have : (((k * n + s : ℕ)) : ZMod n) = (s : ZMod n) := by push_cast; simp  rw [this, eq_neg_iff_add_eq_zero, ← Nat.cast_add, ZMod.natCast_eq_zero_iff]  constructor  · intro h; exact eq_of_dvd_lt h (by omega) (by omega)  · intro h; rw [h] lemma S_block (n k c : ℕ) (hc0 : 0 < c) (hcn : c < n) (h0 : S n (k * n) c = Sform n k 0 c) :    ∀ r, r < n → S n (k * n + r) c = Sform n k r c := by  intro r  induction r with  | zero => intro _; simpa using h0  | succ r ih =>    intro hr    rw [← add_assoc, S_succ, ih (by omega), show k * n + r + 1 = k * n + (r + 1) from rfl]    simp only [cast_eq_c (k := k) (s := r + 1) (by omega) hcn,      cast_eq_negc (k := k) (s := r + 1) (by omega) (by omega) hc0 hcn]    unfold Sform    push_cast    split_ifs <;> first | omega | (zify at *; nlinarith) lemma S_zero_eq (n c : ℕ) (hc0 : 0 < c) (hcn : c < n) : S n 0 c = Sform n 0 0 c := by  unfold S Sform  rw [Finset.Icc_eq_empty (by omega), sum_empty]  split_ifs <;> omega /-- **The count in the proof of `thm:sop`(c).** For `m = kn + r`, `0 ≤ r < n`, `1 ≤ c ≤ n−1`:`S(c) = (2k+1)c` if `c ≤ r < n−c`; `−(2k+1)(n−c)` if `n−c ≤ r < c`; `(k+1)(2c−n)` if`n−c ≤ r` and `c ≤ r`; `k(2c−n)` if `r < c` and `r < n−c`. -/theorem S_formula (n k r c : ℕ) (hc0 : 0 < c) (hcn : c < n) (hr : r < n) :    S n (k * n + r) c = Sform n k r c := by  induction k generalizing r with  | zero =>    apply S_block n 0 c hc0 hcn _ r hr    simpa using S_zero_eq n c hc0 hcn  | succ k ih =>    apply S_block n (k + 1) c hc0 hcn _ r hr    have h1 := S_block n k c hc0 hcn (by simpa using ih 0 (by omega)) (n - 1) (by omega)    have h2 : (k + 1) * n = k * n + (n - 1) + 1 := by      have : 1 ≤ n := by omega      rw [add_mul, one_mul]; omega    have hcast : (((k * n + (n - 1) + 1 : ℕ)) : ZMod n) = 0 := by      rw [← h2]; push_cast; simp    have hc : (c : ZMod n) ≠ 0 := by      rw [Ne, ZMod.natCast_eq_zero_iff]      exact fun h => absurd (Nat.le_of_dvd hc0 h) (by omega)    have hc' : (0 : ZMod n) ≠ (c : ZMod n) := fun h => hc h.symm    have hc'' : (0 : ZMod n) ≠ -(c : ZMod n) := fun h => hc (neg_eq_zero.mp h.symm)    rw [h2, S_succ, h1, hcast, ite_eq_right hc', ite_eq_right hc'']    unfold Sform    push_cast    split_ifs <;> omega /-! ## `thm:sop`(c) -/ /-- If `n ∤ h, h+1, h+2`, the residue `r = m mod n` avoids the list of `lem:seg`. -/lemma r_of_not_D {n k r : ℕ} (hr : r < n) (hD : ¬ D n (k * n + r)) :    r ≠ 0 ∧ r + 1 ≠ n ∧ 2 * r + 1 ≠ n ∧ 2 * r + 2 ≠ n ∧ 2 * r ≠ n := by  unfold D at hD  refine ⟨?_, ?_, ?_, ?_, ?_⟩ <;> intro h <;> apply hD  · left; exact ⟨2 * k, by subst h; ring⟩  · right; right; exact ⟨2 * k + 2, by rw [← h]; ring⟩  · right; left; exact ⟨2 * k + 1, by rw [← h]; ring⟩  · right; right; exact ⟨2 * k + 1, by rw [← h]; ring⟩  · left; exact ⟨2 * k + 1, by rw [← h]; ring⟩ lemma two_c_ne {n c : ℕ} (hc0 : 0 < c) (hcn : c < n) (h2 : 2 * c ≠ n) :    2 * (c : ZMod n) ≠ 0 := by  intro h  have : ((2 * c : ℕ) : ZMod n) = 0 := by push_cast; exact h  rw [ZMod.natCast_eq_zero_iff] at this  exact h2 (eq_of_dvd_lt this (by omega) (by omega)) lemma not_dvd_both {p : ℕ} (hp : p.Prime) {a b : ℤ} (hab : ∃ x y : ℤ, x * a + y * b = 1) :    ¬ ((p : ℤ) ∣ a ∧ (p : ℤ) ∣ b) := by  rintro ⟨ha, hb⟩  have h1 : (p : ℤ) ∣ 1 := by    obtain ⟨x, y, h⟩ := hab    rw [← h]; exact dvd_add (dvd_mul_of_dvd_right ha x) (dvd_mul_of_dvd_right hb y)  exact hp.one_lt.ne' (Nat.dvd_one.mp (Int.natCast_dvd_natCast.mp (by simpa using h1))) /-- **Clause (ii) of `thm:sop`(b) holds when (i) does** (proof of `thm:sop`(c)). For `n ≥ 3`with `n ∤ h, h+1, h+2` (`h = 2m`) and every prime `p`, including `p = 2`, some class `c` with`2c ≢ 0 (mod n)` has `p ∤ S(c)`: `S(1) = 2k+1` and `S(c*) ∈ {−k, −2k, k+1, 2(k+1)}`. -/theorem sop_c_ii {n m p : ℕ} (hn : 3 ≤ n) (hp : p.Prime) (hD : ¬ D n m) :    ∃ c : ZMod n, 2 * c ≠ 0 ∧ ¬ (p : ℤ) ∣ S n m c := by  have hm : m = (m / n) * n + m % n := by rw [mul_comm]; exact (Nat.div_add_mod m n).symm  set k := m / n  set r := m % n  have hr : r < n := Nat.mod_lt _ (by omega)  rw [hm] at hD ⊢  obtain ⟨h0, h1, h2, h3, h4⟩ := r_of_not_D hr hD  -- `S(1) = 2k+1`  have hS1 : S n (k * n + r) ((1 : ℕ) : ZMod n) = 2 * k + 1 := by    rw [S_formula n k r 1 (by omega) (by omega) hr]; unfold Sform    rw [ite_eq_left ⟨by omega, by omega⟩]; ring  have h1ne : 2 * ((1 : ℕ) : ZMod n) ≠ 0 := two_c_ne (by omega) (by omega) (by omega)  -- the second class `c*`  obtain ⟨c, hc0, hcn, hc2, hSc⟩ : ∃ c : ℕ, 0 < c ∧ c < n ∧ 2 * c ≠ n ∧      (Sform n k r c = -k ∨ Sform n k r c = -(2 * k) ∨ Sform n k r c = k + 1 ∨        Sform n k r c = 2 * (k + 1)) := by    rcases Nat.even_or_odd n with ⟨t, ht⟩ | ⟨t, ht⟩    · rcases lt_or_gt_of_ne h4 with hlt | hgt      · refine ⟨t - 1, by omega, by omega, by omega, Or.inr (Or.inl ?_)⟩        unfold Sform        rw [ite_eq_right (by omega), ite_eq_right (by omega), ite_eq_right (by omega)]        have : ((t - 1 : ℕ) : ℤ) = (t : ℤ) - 1 := by push_cast [Nat.cast_sub (by omega : 1 ≤ t)]; ring        rw [this, ht]; push_cast; ring      · refine ⟨t + 1, by omega, by omega, by omega, Or.inr (Or.inr (Or.inr ?_))⟩        unfold Sform        rw [ite_eq_right (by omega), ite_eq_right (by omega), ite_eq_left ⟨by omega, by omega⟩, ht]        push_cast; ring    · rcases lt_or_gt_of_ne h4 with hlt | hgt      · refine ⟨t, by omega, by omega, by omega, Or.inl ?_⟩        unfold Sform        rw [ite_eq_right (by omega), ite_eq_right (by omega), ite_eq_right (by omega), ht]        push_cast; ring      · refine ⟨t + 1, by omega, by omega, by omega, Or.inr (Or.inr (Or.inl ?_))⟩        unfold Sform        rw [ite_eq_right (by omega), ite_eq_right (by omega), ite_eq_left ⟨by omega, by omega⟩, ht]        push_cast; ring  have hcS := S_formula n k r c hc0 hcn hr  by_contra hall  push Not at hall  have hd1 := hall _ h1ne  have hdc := hall _ (two_c_ne hc0 hcn hc2)  rw [hS1] at hd1  rw [hcS] at hdc  apply not_dvd_both hp _ ⟨hd1, hdc⟩  rcases hSc with h | h | h | h <;> rw [h]  · exact ⟨1, 2, by ring⟩  · exact ⟨1, 1, by ring⟩  · exact ⟨-1, 2, by ring⟩  · exact ⟨-1, 1, by ring⟩ /-- Clause (ii) of `thm:sop`(b): `E = 1`, or `S(c) ≢ 0 (mod p)` for some `c` with `2c ≢ 0`. -/def ClauseII (n m p E : ℕ) : Prop := E = 1 ∨ ∃ c : ZMod n, 2 * c ≠ 0 ∧ ¬ (p : ℤ) ∣ S n m c /-- **`thm:sop`(c)**, conditional. Hypotheses: `hb` is `thm:sop`(b) (`p ∣ [O:A]` iff (i) or (ii)fails; it needs the ring-theoretic infrastructure of orders, not formalized), and `hseg` is`lem:seg` read as "(i) fails iff `n ∣ h, h+1` or `h+2`" (proved as`Segmentos.lem_seg` and `Segmentos.seg_stable_of_dvd`; it needs a unit `a ≢ ±1`, i.e. `q' ∉ {1,2,3,4,6}`). Thearithmetic step, (ii) holds whenever (i) does, is `sop_c_ii`. -/theorem sop_c {n m p E idx : ℕ} (hn : 3 ≤ n) (hp : p.Prime) (I : Prop)    (hb : p ∣ idx ↔ ¬ I ∨ ¬ ClauseII n m p E) (hseg : ¬ I ↔ D n m) :    p ∣ idx ↔ D n m := by  rw [hb]  constructor  · rintro (h | h)    · exact hseg.mp h    · by_contra hD      exact h (Or.inr (sop_c_ii hn hp hD))  · intro hD; exact Or.inl (hseg.mpr hD) /-! ## `cor:indice` -/ /-- **`cor:indice`, the valuations.** From `thm:loc`(d), `v_p([O:A]) = ∑_{i<e}(d − W_i)` and`v_p([A:f]) = ∑_{i<e} W_i`, with `W₀ = 1`, `W₁ ≤ d`, `e ∈ {1, 2}` (from `prop:mono`(b) /`prop:cert`(b)) and `e = 1 ↔ W₁ = d` (`thm:loc`(c)): `v_p([O:A]) = 2d − 1 − W₁`, which is`(d − 1) + (d − W₁)`, and `v_p([A:f]) = 1` if `W₁ = d`, `1 + W₁` otherwise. -/theorem indice_val (d e : ℕ) (W : ℕ → ℕ) (hW0 : W 0 = 1) (hd : 1 ≤ d) (hle : W 1 ≤ d)    (he : e = 1 ∨ e = 2) (hc : e = 1 ↔ W 1 = d) (v vf : ℕ)    (hv : v = ∑ i ∈ range e, (d - W i)) (hvf : vf = ∑ i ∈ range e, W i) :    v = 2 * d - 1 - W 1 ∧ v = (d - 1) + (d - W 1) ∧ vf = if W 1 = d then 1 else 1 + W 1 := by  rcases he with rfl | rfl  · have h1 := hc.mp rfl    simp only [range_one, sum_singleton, hW0] at hv hvf    refine ⟨by omega, by omega, by rw [ite_eq_left h1]; exact hvf⟩  · have h1 : W 1 ≠ d := fun h => absurd (hc.mpr h) (by omega)    simp only [sum_range_succ, range_zero, sum_empty, hW0] at hv hvf    refine ⟨by omega, by omega, by rw [ite_eq_right h1]; omega⟩ /-- **`cor:indice`, families of `thm:hminus`(a).** `d − W₁ = k ≤ v_p(h⁻) < d/2` gives `W₁ > d/2`. -/theorem indice_hminus (d W1 k vh : ℕ) (hle : W1 ≤ d) (hk : d - W1 = k) (hkv : k ≤ vh)    (hv : 2 * vh < d) : d < 2 * W1 := by omega /-- **`cor:indice`, case (b) of `cor:dos`.** `d − W₁ = d/t` with `t ≥ 3`, `t ∣ d` gives`W₁ ≥ 2d/3`, hence `W₁ > d/2` when `d > 0`. -/theorem indice_dos (d W1 t : ℕ) (hle : W1 ≤ d) (ht : 3 ≤ t) (htd : t ∣ d) (h : d - W1 = d / t) :    2 * d ≤ 3 * W1 ∧ (0 < d → d < 2 * W1) := by  obtain ⟨s, rfl⟩ := htd  rw [Nat.mul_div_cancel_left s (by omega)] at h  have : 3 * s ≤ t * s := Nat.mul_le_mul_right s ht  constructor  · omega  · intro hd    have hs : 0 < s := Nat.pos_of_ne_zero (by rintro rfl; simp at hd)    omega /-- **`cor:indice`, proof.** `h` even and `q' ∈ {1,2,3,4}` force `q' ∣ h, h+1` or `h+2`("`4` divides `h` or `h+2`, and `3` divides one of three consecutive integers"). -/theorem indice_small (h n : ℕ) (he : Even h) (hn : n = 1 ∨ n = 2 ∨ n = 3 ∨ n = 4) :    n ∣ h ∨ n ∣ h + 1 ∨ n ∣ h + 2 := by  obtain ⟨a, rfl⟩ := he  simp only [Nat.dvd_iff_mod_eq_zero]  have h3 : a % 3 < 3 := Nat.mod_lt _ (by norm_num)  rcases hn with rfl | rfl | rfl | rfl  · omega  · omega  · interval_cases hh : a % 3 <;> omega  · omega /-- **`cor:indice`, proof, `q' = 6`.** `6 ∤ h, h+1, h+2` (`h = 2m`) iff `m ≡ 1 (mod 3)`. -/theorem indice_six (m : ℕ) : ¬ D 6 m ↔ m % 3 = 1 := by  unfold D; omega /-- **`cor:indice`, proof, `q' = 6`**: "`S(1) = 2k+1` and `S(2) = −2k` or `−2(k+1)` for`m = 6k+1` or `m = 6k+4`". -/theorem indice_six_S (k : ℕ) :    S 6 (6 * k + 1) ((1 : ℕ) : ZMod 6) = 2 * k + 1 ∧    S 6 (6 * k + 1) ((2 : ℕ) : ZMod 6) = -(2 * k) ∧    S 6 (6 * k + 4) ((1 : ℕ) : ZMod 6) = 2 * k + 1 ∧    S 6 (6 * k + 4) ((2 : ℕ) : ZMod 6) = -(2 * (k + 1)) := by  simp only [show 6 * k = k * 6 from mul_comm _ _]  refine ⟨?_, ?_, ?_, ?_⟩ <;> rw [S_formula _ _ _ _ (by norm_num) (by norm_num) (by norm_num)] <;>    unfold Sform <;> norm_num <;> ring /-- **`cor:indice`, proof, `q' = 6`**: "these are coprime, so (ii) holds". For `m ≡ 1 (mod 3)`and every prime `p`, `ClauseII 6 m p E` holds (through `c = 1` or `c = 2`). -/theorem indice_six_ii {m p : ℕ} (hp : p.Prime) (hm : m % 3 = 1) (E : ℕ) : ClauseII 6 m p E := by  right  exact sop_c_ii (by norm_num) hp ((indice_six m).mpr hm) /-- **`cor:indice`, the product formula.** If `v_p([O:A]) = d_p − 1 + (d_p − W₁(p))` for theprimes `p` of a finite set `P` and `v_p([O:A]) = 0` for every other prime (`thm:sop`(a),(c) andthe case `q' = 6`, as hypotheses), then `[O:A] = ∏_{p∈P} p^{d_p − 1 + (d_p − W₁(p))}`. -/theorem indice_prod {idx : ℕ} (hidx : idx ≠ 0) (P : Finset ℕ) (hP : ∀ p ∈ P, p.Prime)    (d W : ℕ → ℕ)    (hv : ∀ p, p.Prime → idx.factorization p = if p ∈ P then d p - 1 + (d p - W p) else 0) :    idx = ∏ p ∈ P, p ^ (d p - 1 + (d p - W p)) := by  have hne : ∀ p ∈ P, p ^ (d p - 1 + (d p - W p)) ≠ 0 := fun p hp =>    pow_ne_zero _ (hP p hp).ne_zero  apply Nat.eq_of_factorization_eq hidx (Finset.prod_ne_zero_iff.mpr hne)  intro p  rw [Nat.factorization_prod hne, Finset.sum_apply']  rw [Finset.sum_congr rfl (fun q hq => by rw [(hP q hq).factorization_pow])]  simp only [Finsupp.single_apply]  rw [Finset.sum_ite_eq' P p]  by_cases hp : p.Prime  · exact hv p hp  · rw [Nat.factorization_eq_zero_of_not_prime _ hp, ite_eq_right (fun h => hp (hP p h))] /-! ## Controls against a mistyped definition -/ /-- `n = 5`, `m = 7`: `S(2) = (2 + 7) − 3 = 6`, the first case with `k = 1`, `r = 2`. -/example : S 5 7 ((2 : ℕ) : ZMod 5) = 6 := by decideexample : Sform 5 1 2 2 = 6 := by decide/-- `n = 7`, `m = 10`: `S(3) = (3 + 10) − 4 = 9 = (2·1+1)·3`, computed both ways. -/example : S 7 10 ((3 : ℕ) : ZMod 7) = Sform 7 1 3 3 := by decide/-- Running example `A₃(35)` after `thm:sop`: `h = 6`; `q' = 5` divides none of `6, 7, 8`,`q' = 7 = h + 1`. -/example : ¬ D 5 3 ∧ D 7 3 := by unfold D; decide end SopIndice