import Mathlib /-! # Exact Discriminant Formula and Universal Modular Reducibility for OEIS A217785 For `n : ℕ`, define the polynomial $$s_n(x) = \sum_{k=0}^n (k + 1) x^k \in \mathbb{Z}[x].$$ Zhi-Wei Sun's Conjecture 4 on OEIS A217785 (`FormalConjectures/OEIS/217785.lean`) asserts that for `n ≥ 1`, `s_n(x)` is reducible modulo every prime `p` if and only if `n = 8 k (k + 1)` for some positive integer `k`. In this file we prove: 1. **Exact algebraic and differential identities** over any commutative ring `R`: - `(X - 1)^2 * s_n(X) = (n + 1) X^{n+2} - (n + 2) X^{n+1} + 1` (`polySR_mul_X_sub_one_sq`). - `(X - 1) * s_n'(X) + 2 * s_n(X) = (n + 1)(n + 2) X^n` (`polySR_diff_identity`). 2. **Universal modular factorizations at ramified primes**: - At `p = 2` for every even `n = 2m ≥ 2`: `s_{2m}(X) = (∑_{j=0}^m X^j)^2` in `(ZMod 2)[X]` (`polyS_mod_two_eq_sq`, `polyS_not_irreducible_two`). - At every odd prime `p ∣ n + 1` with `n ≥ 4`: `s_n(X)` is reducible in `(ZMod p)[X]` (`polyS_not_irreducible_of_dvd_succ`). - At every odd prime `p ∣ n + 2` with even `n = 2m ≥ 2`: `s_{2m}(X)` is reducible in `(ZMod p)[X]` (`polyS_not_irreducible_of_dvd_add_two`). 3. **Exact Stickelberger–Frobenius quadratic-residue obstruction**: For every even `n = 2m ≥ 2` and every odd prime `p` with `p ∤ (2m + 1)` and `p ∤ (m + 1)`, if `s_{2m}(X)` is irreducible over `ZMod p`, then `(-1)^m (m + 1)` is NOT a square in `ZMod p` (`polyS_even_irreducible_imp_not_isSquare`), equivalently `legendreSym p ((-1)^m * (m + 1)) = -1` (`polyS_even_irreducible_imp_legendreSym_eq_neg_one`). 4. **Complete proof of the `(⇐)` direction of OEIS A217785 Conjecture 4**: For every `k > 0` and every prime `p`, the polynomial `s_{8 k (k + 1)}(X)` is reducible over `ZMod p` (`conjecture_4_mpr`). 5. **Exact square-discriminant classification**: For `m ≥ 1`, `IsSquare ((-1 : ℤ)^m * (m + 1 : ℤ))` holds if and only if `∃ k > 0, 2m = 8k(k+1)` (`even_disc_isSquare_iff`). 6. **Exact closed-form discriminant root product** over any splitting field `K` in which `2 * (n + 1) * (n + 2) ≠ 0` (`polySR_disc_root_formula`). All proofs are completely elementary, self-contained, and depend only on standard Lean axioms. -/ namespace OeisA217785 open Polynomial Finset /-- The polynomial `s_n(x) = ∑_{k=0}^n (k + 1) x^k` over `ℤ[x]`, matching `FormalConjectures/OEIS/217785.lean` verbatim. -/ noncomputable def polyS (n : ℕ) : Polynomial ℤ := ∑ k ∈ Finset.range (n + 1), Polynomial.C (k + 1 : ℤ) * Polynomial.X ^ k /-- Generic version of `s_n(x) = ∑_{k=0}^n (k + 1) x^k` over any commutative ring `R`. -/ noncomputable def polySR (R : Type*) [CommRing R] (n : ℕ) : Polynomial R := ∑ k ∈ Finset.range (n + 1), Polynomial.C ((k + 1 : ℕ) : R) * Polynomial.X ^ k lemma map_polyS (R : Type*) [CommRing R] (n : ℕ) : Polynomial.map (Int.castRingHom R) (polyS n) = polySR R n := by unfold polyS polySR rw [Polynomial.map_sum] refine Finset.sum_congr rfl fun k _ => ?_ simp [Polynomial.map_mul, Polynomial.map_pow, Polynomial.map_X] lemma map_polySR {R S : Type*} [CommRing R] [CommRing S] (f : R →+* S) (n : ℕ) : Polynomial.map f (polySR R n) = polySR S n := by unfold polySR rw [Polynomial.map_sum] refine Finset.sum_congr rfl fun k _ => ?_ simp [Polynomial.map_mul, Polynomial.map_pow, Polynomial.map_X] /-! ### Section 1: Exact Algebraic and Differential Identities -/ /-- `(X - 1) * ∑_{k=0}^n X^k = X^{n+1} - 1`. -/ lemma geom_sum_mul_X_sub_one {R : Type*} [CommRing R] (n : ℕ) : (X - 1 : R[X]) * (∑ k ∈ range (n + 1), X ^ k) = X ^ (n + 1) - 1 := by induction n with | zero => simp | succ n ih => rw [sum_range_succ, mul_add, ih] ring /-- First-difference identity: `(X - 1) * s_n(X) = (n + 1) * X^{n+1} - ∑_{k=0}^n X^k`. -/ lemma polySR_mul_X_sub_one {R : Type*} [CommRing R] (n : ℕ) : (X - 1 : R[X]) * polySR R n = C ((n + 1 : ℕ) : R) * X ^ (n + 1) - ∑ k ∈ range (n + 1), X ^ k := by induction n with | zero => unfold polySR simp | succ n ih => have hstep : polySR R (n + 1) = polySR R n + C ((n + 2 : ℕ) : R) * X ^ (n + 1) := by unfold polySR rw [sum_range_succ] have hC : C ((n + 2 : ℕ) : R) = C ((n + 1 : ℕ) : R) + 1 := by rw [show n + 2 = (n + 1) + 1 by omega, Nat.cast_add, Nat.cast_one, map_add, map_one] rw [hstep, mul_add, ih, hC] rw [Finset.sum_range_succ _ (n + 1)] ring /-- Exact closed form over any commutative ring `R`: `(X - 1)^2 * s_n(X) = (n + 1) X^{n+2} - (n + 2) X^{n+1} + 1`. -/ theorem polySR_mul_X_sub_one_sq {R : Type*} [CommRing R] (n : ℕ) : (X - 1 : R[X]) ^ 2 * polySR R n = C ((n + 1 : ℕ) : R) * X ^ (n + 2) - C ((n + 2 : ℕ) : R) * X ^ (n + 1) + 1 := by have hC : C ((n + 2 : ℕ) : R) = C ((n + 1 : ℕ) : R) + 1 := by rw [show n + 2 = (n + 1) + 1 by omega, Nat.cast_add, Nat.cast_one, map_add, map_one] calc (X - 1 : R[X]) ^ 2 * polySR R n = (X - 1) * ((X - 1) * polySR R n) := by ring _ = (X - 1) * (C ((n + 1 : ℕ) : R) * X ^ (n + 1) - ∑ k ∈ range (n + 1), X ^ k) := by rw [polySR_mul_X_sub_one] _ = (X - 1) * (C ((n + 1 : ℕ) : R) * X ^ (n + 1)) - (X - 1) * ∑ k ∈ range (n + 1), X ^ k := by ring _ = (X - 1) * (C ((n + 1 : ℕ) : R) * X ^ (n + 1)) - (X ^ (n + 1) - 1) := by rw [geom_sum_mul_X_sub_one] _ = C ((n + 1 : ℕ) : R) * X ^ (n + 2) - C ((n + 2 : ℕ) : R) * X ^ (n + 1) + 1 := by rw [hC]; ring /-- Exact closed form over `ℤ[X]`. -/ theorem polyS_mul_X_sub_one_sq (n : ℕ) : (X - 1 : ℤ[X]) ^ 2 * polyS n = C ((n + 1 : ℕ) : ℤ) * X ^ (n + 2) - C ((n + 2 : ℕ) : ℤ) * X ^ (n + 1) + 1 := by have h := polySR_mul_X_sub_one_sq (R := ℤ) n have hEq : polySR ℤ n = polyS n := by unfold polySR polyS refine Finset.sum_congr rfl fun k _ => ?_ push_cast rfl rwa [hEq] at h /-- Exact first-order differential identity over any commutative ring `R`: `(X - 1) * s_n'(X) + 2 * s_n(X) = (n + 1)(n + 2) X^n`. -/ theorem polySR_diff_identity {R : Type*} [CommRing R] (n : ℕ) : (X - 1 : R[X]) * Polynomial.derivative (polySR R n) + 2 * polySR R n = C (((n + 1) * (n + 2) : ℕ) : R) * X ^ n := by induction n with | zero => unfold polySR simp [Polynomial.C_ofNat] | succ n ih => have hstep : polySR R (n + 1) = polySR R n + C ((n + 2 : ℕ) : R) * X ^ (n + 1) := by unfold polySR rw [sum_range_succ] rw [hstep, map_add, Polynomial.derivative_C_mul_X_pow] simp only [Nat.add_sub_cancel, map_mul] have h1 : (X - 1 : R[X]) * (Polynomial.derivative (polySR R n) + C ((n + 2 : ℕ) : R) * C ((n + 1 : ℕ) : R) * X ^ n) + 2 * (polySR R n + C ((n + 2 : ℕ) : R) * X ^ (n + 1)) = ((X - 1) * Polynomial.derivative (polySR R n) + 2 * polySR R n) + (X - 1) * (C ((n + 2 : ℕ) : R) * C ((n + 1 : ℕ) : R) * X ^ n) + 2 * (C ((n + 2 : ℕ) : R) * X ^ (n + 1)) := by ring rw [h1, ih] have hC1 : C (((n + 1) * (n + 2) : ℕ) : R) = C ((n + 2 : ℕ) : R) * C ((n + 1 : ℕ) : R) := by rw [← map_mul]; push_cast; ring_nf have hC2 : C (((n + 2) * (n + 3) : ℕ) : R) = C ((n + 2 : ℕ) : R) * C ((n + 1 : ℕ) : R) + 2 * C ((n + 2 : ℕ) : R) := by rw [← map_mul, ← C_ofNat, ← map_mul, ← map_add] congr 1 push_cast ring rw [hC1, hC2] ring /-- Coefficient formula for `polySR`. -/ lemma polySR_coeff {R : Type*} [CommRing R] (n k : ℕ) : (polySR R n).coeff k = if k ≤ n then ((k + 1 : ℕ) : R) else 0 := by unfold polySR rw [Polynomial.finsetSum_coeff] simp only [Polynomial.coeff_C_mul_X_pow] rw [Finset.sum_ite_eq] simp only [Finset.mem_range, Nat.lt_succ_iff] /-- Evaluation at `0`: `s_n(0) = 1`. -/ lemma polySR_eval_zero {R : Type*} [CommRing R] (n : ℕ) : (polySR R n).eval 0 = 1 := by rw [← Polynomial.coeff_zero_eq_eval_zero, polySR_coeff] simp /-- Evaluation at `1`: `2 * s_n(1) = (n + 1) * (n + 2)`. -/ lemma two_mul_polySR_eval_one {R : Type*} [CommRing R] (n : ℕ) : 2 * (polySR R n).eval 1 = (((n + 1) * (n + 2) : ℕ) : R) := by have h := congrArg (Polynomial.eval (1 : R)) (polySR_diff_identity (R := R) n) simp only [Polynomial.eval_add, Polynomial.eval_mul, Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_one, sub_self, zero_mul, zero_add, Polynomial.eval_ofNat, Polynomial.eval_C, Polynomial.eval_pow, one_pow, mul_one] at h exact h /-- Degree upper bound: `natDegree (polySR R n) ≤ n`. -/ lemma polySR_natDegree_le {R : Type*} [CommRing R] (n : ℕ) : (polySR R n).natDegree ≤ n := by rw [Polynomial.natDegree_le_iff_coeff_eq_zero] intro k hk rw [polySR_coeff, if_neg (by omega)] /-- Exact degree when `(n + 1 : R) ≠ 0`. -/ lemma polySR_natDegree_eq {R : Type*} [CommRing R] {n : ℕ} (h : ((n + 1 : ℕ) : R) ≠ 0) : (polySR R n).natDegree = n := by apply le_antisymm (polySR_natDegree_le n) apply Polynomial.le_natDegree_of_ne_zero rw [polySR_coeff, if_pos le_rfl] exact h /-- Leading coefficient when `(n + 1 : R) ≠ 0`. -/ lemma polySR_leadingCoeff {R : Type*} [CommRing R] {n : ℕ} (h : ((n + 1 : ℕ) : R) ≠ 0) : (polySR R n).leadingCoeff = ((n + 1 : ℕ) : R) := by rw [Polynomial.leadingCoeff, polySR_natDegree_eq h, polySR_coeff, if_pos le_rfl] /-! ### Section 2: Universal Reducibility at `p = 2` and at Odd Primes Dividing `(n + 1)(n + 2)` -/ /-- Over `ZMod 2`, for every even `n = 2m`, `s_{2m}(X) = (∑_{j=0}^m X^j)^2`. -/ theorem polyS_mod_two_eq_sq (m : ℕ) : polySR (ZMod 2) (2 * m) = (∑ j ∈ range (m + 1), (X : (ZMod 2)[X]) ^ j) ^ 2 := by have hsq : (∑ j ∈ range (m + 1), (X : (ZMod 2)[X]) ^ j) ^ 2 = ∑ j ∈ range (m + 1), (X : (ZMod 2)[X]) ^ (2 * j) := by rw [← frobenius_def, map_sum] refine Finset.sum_congr rfl fun j _ => ?_ rw [frobenius_def, ← pow_mul, mul_comm] rw [hsq] ext k rw [polySR_coeff, Polynomial.finsetSum_coeff] simp only [Polynomial.coeff_X_pow] by_cases hk : k ≤ 2 * m · rw [if_pos hk] rcases Nat.even_or_odd k with ⟨j, rfl⟩ | ⟨j, rfl⟩ · have hj : j ∈ range (m + 1) := by rw [Finset.mem_range]; omega rw [Finset.sum_eq_single j] · simp only [show j + j = 2 * j by omega, ↓reduceIte] push_cast have h20 : (2 : ZMod 2) = 0 := by decide rw [h20, zero_mul, zero_add] · intro i _ hij rw [if_neg (by omega)] · intro hnot; exact absurd hj hnot · have hzero : ((2 * j + 1 + 1 : ℕ) : ZMod 2) = 0 := by rw [show 2 * j + 1 + 1 = 2 * (j + 1) by omega] push_cast have h20 : (2 : ZMod 2) = 0 := by decide rw [h20, zero_mul] rw [hzero] symm refine Finset.sum_eq_zero fun i _ => ?_ rw [if_neg (by omega)] · rw [if_neg hk] symm refine Finset.sum_eq_zero fun i hi => ?_ rw [Finset.mem_range] at hi rw [if_neg (by omega)] /-- For every `m ≥ 1`, `s_{2m}(X)` is reducible over `ZMod 2`. -/ theorem polyS_not_irreducible_two {m : ℕ} (hm : 1 ≤ m) : ¬ Irreducible (polySR (ZMod 2) (2 * m)) := by rw [polyS_mod_two_eq_sq] set g : (ZMod 2)[X] := ∑ j ∈ range (m + 1), X ^ j have hdeg : g.natDegree = m := by apply le_antisymm · rw [Polynomial.natDegree_le_iff_coeff_eq_zero] intro k hk rw [Polynomial.finsetSum_coeff] refine Finset.sum_eq_zero fun j hj => ?_ rw [Finset.mem_range] at hj rw [Polynomial.coeff_X_pow, if_neg (by omega)] · apply Polynomial.le_natDegree_of_ne_zero rw [Polynomial.finsetSum_coeff, Finset.sum_eq_single m] · simp · intro j _ hjm; rw [Polynomial.coeff_X_pow, if_neg hjm.symm] · intro hnot; exact absurd (Finset.mem_range.mpr (by omega)) hnot have hnu : ¬ IsUnit g := by intro hu have h0 := Polynomial.natDegree_eq_zero_of_isUnit hu omega rw [sq] intro hirr rcases hirr.isUnit_or_isUnit rfl with h | h <;> exact hnu h /-- Helper: if `(X - 1)^2 * f = -(X^q - 1)^p` in `(ZMod p)[X]` with `p` an odd prime and either `q ≥ 2` or `p ≥ 5`, then `f` is reducible. -/ lemma not_irreducible_of_X_sub_one_sq_mul_eq_neg_pow {p q : ℕ} [Fact p.Prime] (hp2 : p ≠ 2) (hq1 : 1 ≤ q) (hq_or_p : 2 ≤ q ∨ 5 ≤ p) {f : (ZMod p)[X]} (hf : (X - 1 : (ZMod p)[X]) ^ 2 * f = -(X ^ q - 1) ^ p) : ¬ Irreducible f := by have hp_ge3 : 3 ≤ p := by have hp2' := (Fact.out : p.Prime).two_le omega set h : (ZMod p)[X] := ∑ j ∈ range q, X ^ j have hfact : (X : (ZMod p)[X]) ^ q - 1 = (X - 1) * h := by have := geom_sum_mul_X_sub_one (R := ZMod p) (q - 1) rw [Nat.sub_add_cancel hq1] at this exact this.symm have hpowX : (X - 1 : (ZMod p)[X]) ^ p = (X - 1) ^ 2 * (X - 1) ^ (p - 2) := by rw [← pow_add, show 2 + (p - 2) = p by omega] have hpow : (X - 1 : (ZMod p)[X]) ^ 2 * f = (X - 1) ^ 2 * (-(X - 1) ^ (p - 2) * h ^ p) := by rw [hf, hfact, mul_pow, hpowX] ring have hX1_ne : (X - 1 : (ZMod p)[X]) ^ 2 ≠ 0 := by apply pow_ne_zero intro h0 have := congrArg (Polynomial.eval 0) h0 simp at this have hf_eq : f = -(X - 1) ^ (p - 2) * h ^ p := mul_left_cancel₀ hX1_ne hpow have hX1_deg : (X - 1 : (ZMod p)[X]).natDegree = 1 := Polynomial.natDegree_X_sub_C 1 have hX1_nu : ¬ IsUnit (X - 1 : (ZMod p)[X]) := by intro hu have := Polynomial.natDegree_eq_zero_of_isUnit hu omega rw [hf_eq] rcases hq_or_p with hq2 | hp5 · -- Case `q ≥ 2`: both `-(X - 1)^(p - 2)` and `h^p` are non-units. have hdeg_h : h.natDegree = q - 1 := by apply le_antisymm · rw [Polynomial.natDegree_le_iff_coeff_eq_zero] intro k hk rw [Polynomial.finsetSum_coeff] refine Finset.sum_eq_zero fun j hj => ?_ rw [Finset.mem_range] at hj rw [Polynomial.coeff_X_pow, if_neg (by omega)] · apply Polynomial.le_natDegree_of_ne_zero rw [Polynomial.finsetSum_coeff, Finset.sum_eq_single (q - 1)] · simp · intro j _ hne; rw [Polynomial.coeff_X_pow, if_neg hne.symm] · intro hnot; exact absurd (Finset.mem_range.mpr (by omega)) hnot have hh_nu : ¬ IsUnit h := by intro hu have := Polynomial.natDegree_eq_zero_of_isUnit hu omega have hnu1 : ¬ IsUnit (-(X - 1 : (ZMod p)[X]) ^ (p - 2)) := by intro hu have hu' : IsUnit ((X - 1 : (ZMod p)[X]) ^ (p - 2)) := by simpa using hu.neg exact hX1_nu ((isUnit_pow_iff (by omega)).mp hu') have hnu2 : ¬ IsUnit (h ^ p) := by intro hu exact hh_nu ((isUnit_pow_iff (by omega)).mp hu) intro hirr rcases hirr.isUnit_or_isUnit rfl with h1 | h2 · exact hnu1 h1 · exact hnu2 h2 · -- Case `p ≥ 5`: factor as `(X - 1) * (-(X - 1)^(p - 3) * h^p)`, both divisible by `X - 1`. have hsplit : -(X - 1 : (ZMod p)[X]) ^ (p - 2) * h ^ p = (X - 1) * (-(X - 1) ^ (p - 3) * h ^ p) := by have hp3 : (X - 1 : (ZMod p)[X]) ^ (p - 2) = (X - 1) * (X - 1) ^ (p - 3) := by rw [← pow_succ', show p - 3 + 1 = p - 2 by omega] rw [hp3] ring have hnu2 : ¬ IsUnit (-(X - 1 : (ZMod p)[X]) ^ (p - 3) * h ^ p) := by intro hu have hdvd : (X - 1 : (ZMod p)[X]) ∣ -(X - 1) ^ (p - 3) * h ^ p := by have hp4 : (X - 1 : (ZMod p)[X]) ^ (p - 3) = (X - 1) * (X - 1) ^ (p - 4) := by rw [← pow_succ', show p - 4 + 1 = p - 3 by omega] refine ⟨-(X - 1) ^ (p - 4) * h ^ p, ?_⟩ rw [hp4] ring exact hX1_nu (isUnit_of_dvd_unit hdvd hu) intro hirr rcases hirr.isUnit_or_isUnit hsplit with h1 | h2 · exact hX1_nu h1 · exact hnu2 h2 /-- Over `ZMod p`, if `p` is an odd prime dividing `n + 1` and `n ≥ 4`, then `s_n(X)` is reducible. -/ theorem polyS_not_irreducible_of_dvd_succ {p n : ℕ} [Fact p.Prime] (hp2 : p ≠ 2) (hn : 4 ≤ n) (hdvd : p ∣ n + 1) : ¬ Irreducible (polySR (ZMod p) n) := by obtain ⟨q, hq⟩ := hdvd have hq1 : 1 ≤ q := by by_contra h0 have hq0 : q = 0 := by omega rw [hq0, mul_zero] at hq omega have hq_or_p : 2 ≤ q ∨ 5 ≤ p := by by_cases hq2 : 2 ≤ q · exact Or.inl hq2 · have hqeq : q = 1 := by omega rw [hqeq, mul_one] at hq exact Or.inr (by omega) apply not_irreducible_of_X_sub_one_sq_mul_eq_neg_pow (q := q) hp2 hq1 hq_or_p have hid := polySR_mul_X_sub_one_sq (R := ZMod p) n have h1 : ((n + 1 : ℕ) : ZMod p) = 0 := (ZMod.natCast_eq_zero_iff (n + 1) p).mpr ⟨q, hq⟩ have h2 : ((n + 2 : ℕ) : ZMod p) = 1 := by rw [show n + 2 = (n + 1) + 1 by omega, Nat.cast_add, h1, zero_add, Nat.cast_one] rw [h1, h2, map_zero, zero_mul, zero_sub, map_one, one_mul] at hid rw [hid] have hpow : ((X : (ZMod p)[X]) ^ q - 1) ^ p = X ^ (n + 1) - 1 := by rw [sub_pow_char, one_pow, ← pow_mul, mul_comm, ← hq] rw [hpow] ring /-- Over `ZMod p`, if `p` is an odd prime dividing `2m + 2` with `m ≥ 1`, then `s_{2m}(X)` is reducible. -/ theorem polyS_not_irreducible_of_dvd_add_two {p m : ℕ} [Fact p.Prime] (hp2 : p ≠ 2) (hm : 1 ≤ m) (hdvd : p ∣ 2 * m + 2) : ¬ Irreducible (polySR (ZMod p) (2 * m)) := by obtain ⟨q, hq⟩ := hdvd have hq_even : 2 ∣ q := by have h2dvd : 2 ∣ p * q := ⟨m + 1, by omega⟩ have hcop : Nat.Coprime 2 p := (Nat.Prime.coprime_iff_not_dvd Nat.prime_two).mpr fun h2p => hp2 ((Nat.dvd_prime (Fact.out : p.Prime)).mp h2p |>.resolve_left (by decide)).symm exact hcop.dvd_of_dvd_mul_left h2dvd have hq1 : 1 ≤ q := by by_contra h0 have hq0 : q = 0 := by omega rw [hq0, mul_zero] at hq omega have hq2 : 2 ≤ q := by obtain ⟨t, ht⟩ := hq_even omega apply not_irreducible_of_X_sub_one_sq_mul_eq_neg_pow (q := q) hp2 hq1 (Or.inl hq2) have hid := polySR_mul_X_sub_one_sq (R := ZMod p) (2 * m) have h2 : ((2 * m + 2 : ℕ) : ZMod p) = 0 := (ZMod.natCast_eq_zero_iff (2 * m + 2) p).mpr ⟨q, hq⟩ have h1 : ((2 * m + 1 : ℕ) : ZMod p) = -1 := by have hadd : ((2 * m + 1 : ℕ) : ZMod p) + 1 = 0 := by have : ((2 * m + 1 : ℕ) : ZMod p) + 1 = ((2 * m + 2 : ℕ) : ZMod p) := by push_cast; ring rw [this, h2] exact eq_neg_of_add_eq_zero_left hadd rw [h1, h2, map_neg, map_one, map_zero, zero_mul, sub_zero] at hid rw [hid] have hpow : ((X : (ZMod p)[X]) ^ q - 1) ^ p = X ^ (2 * m + 2) - 1 := by rw [sub_pow_char, one_pow, ← pow_mul, mul_comm, ← hq] rw [hpow] ring /-! ### Section 3: Exact Discriminant Root Product and Stickelberger–Frobenius Obstruction -/ /-- The index set of ordered pairs `(i, j)` in `Fin n × Fin n` with `i < j`. -/ def ltPairs (n : ℕ) : Finset (Fin n × Fin n) := Finset.univ.filter fun x => x.1 < x.2 /-- Cardinality of `ltPairs n` is `n * (n - 1) / 2`. -/ lemma card_ltPairs (n : ℕ) : (ltPairs n).card = n * (n - 1) / 2 := by have hne : (Finset.univ.filter fun x : Fin n × Fin n => x.1 ≠ x.2).card = n * (n - 1) := by have h1 : (Finset.univ.filter fun x : Fin n × Fin n => x.1 ≠ x.2) = Finset.univ.offDiag := by ext ⟨a, b⟩ simp [Finset.mem_offDiag] rw [h1, Finset.offDiag_card, Finset.card_univ, Fintype.card_fin] cases n with | zero => simp | succ k => simp only [Nat.add_sub_cancel] have hmul : (k + 1) * (k + 1) = (k + 1) * k + (k + 1) := by ring omega have hdisj : Disjoint (ltPairs n) (Finset.univ.filter fun x : Fin n × Fin n => x.2 < x.1) := by unfold ltPairs rw [Finset.disjoint_filter] intro x _ h1 h2 exact lt_asymm h1 h2 have hunion : (Finset.univ.filter fun x : Fin n × Fin n => x.1 ≠ x.2) = ltPairs n ∪ (Finset.univ.filter fun x : Fin n × Fin n => x.2 < x.1) := by ext ⟨a, b⟩ simp only [ltPairs, Finset.mem_union, Finset.mem_filter, Finset.mem_univ, true_and] exact ne_iff_lt_or_gt have hswap : (Finset.univ.filter fun x : Fin n × Fin n => x.2 < x.1).card = (ltPairs n).card := by refine Finset.card_bij (fun x _ => x.swap) ?_ ?_ ?_ · intro x hx simp only [ltPairs, Finset.mem_filter, Finset.mem_univ, true_and, Prod.swap] at hx ⊢ exact hx · intro x _ y _ hxy exact Prod.swap_injective hxy · intro y hy refine ⟨y.swap, ?_, Prod.swap_swap y⟩ simp only [ltPairs, Finset.mem_filter, Finset.mem_univ, true_and, Prod.swap] at hy ⊢ exact hy have h2 : 2 * (ltPairs n).card = n * (n - 1) := by rw [← hne, hunion, Finset.card_union_of_disjoint hdisj, hswap, two_mul] omega /-- For even `n = 2m`, `(-1 : R) ^ (ltPairs (2 * m)).card = (-1 : R) ^ m`. -/ lemma neg_one_pow_card_ltPairs_even {R : Type*} [Ring R] (m : ℕ) : (-1 : R) ^ (ltPairs (2 * m)).card = (-1 : R) ^ m := by rw [card_ltPairs] have hdiv : 2 * m * (2 * m - 1) / 2 = m * (2 * m - 1) := by rw [mul_assoc, Nat.mul_div_cancel_left _ (by decide)] rw [hdiv] rcases m with _ | m' · simp · have hodd : Odd (2 * (m' + 1) - 1) := ⟨m', by omega⟩ rw [mul_comm, pow_mul, hodd.neg_one_pow] /-- Product rule for the derivative of a finite product of polynomials. -/ lemma derivative_finset_prod {K ι : Type*} [CommRing K] [DecidableEq ι] (s : Finset ι) (g : ι → K[X]) : Polynomial.derivative (∏ j ∈ s, g j) = ∑ j ∈ s, Polynomial.derivative (g j) * ∏ k ∈ s.erase j, g k := by induction s using Finset.induction_on with | empty => simp | insert a s ha ih => rw [Finset.prod_insert ha, Polynomial.derivative_mul, ih, Finset.sum_insert ha, Finset.erase_insert ha, Finset.mul_sum] congr 1 refine Finset.sum_congr rfl fun j hj => ?_ have hja : j ≠ a := fun h => ha (h ▸ hj) have herase : (insert a s).erase j = insert a (s.erase j) := Finset.erase_insert_of_ne hja.symm have ha' : a ∉ s.erase j := fun h => ha (Finset.mem_of_mem_erase h) rw [herase, Finset.prod_insert ha'] ring /-- Derivative of `C c * ∏ j, (X - C (r j))` evaluated at `r i`. -/ lemma derivative_eval_of_splits {K : Type*} [CommRing K] {n : ℕ} (c : K) (r : Fin n → K) (F : K[X]) (hF : F = C c * ∏ j : Fin n, (X - C (r j))) (i : Fin n) : F.derivative.eval (r i) = c * ∏ j ∈ Finset.univ.erase i, (r i - r j) := by rw [hF, Polynomial.derivative_C_mul, derivative_finset_prod, Polynomial.eval_mul, Polynomial.eval_C, Polynomial.eval_finsetSum] congr 1 rw [Finset.sum_eq_single i] · simp only [Polynomial.derivative_sub, Polynomial.derivative_X, Polynomial.derivative_C, sub_zero, one_mul, Polynomial.eval_prod, Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C] · intro k _ hki simp only [Polynomial.derivative_sub, Polynomial.derivative_X, Polynomial.derivative_C, sub_zero, one_mul, Polynomial.eval_prod, Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C] apply Finset.prod_eq_zero (Finset.mem_erase.mpr ⟨hki.symm, Finset.mem_univ i⟩) exact sub_self (r i) · intro hnot; exact absurd (Finset.mem_univ i) hnot /-- Product of `F'(r i)` in terms of the Vandermonde product `Δ = ∏_{i < j} (r j - r i)`. -/ lemma prod_derivative_eval_eq_vandermonde_sq {K : Type*} [CommRing K] {n : ℕ} (c : K) (r : Fin n → K) (F : K[X]) (hF : F = C c * ∏ j : Fin n, (X - C (r j))) : ∏ i : Fin n, F.derivative.eval (r i) = c ^ n * (-1 : K) ^ (ltPairs n).card * (∏ x ∈ ltPairs n, (r x.2 - r x.1)) ^ 2 := by have h1 : ∏ i : Fin n, F.derivative.eval (r i) = c ^ n * ∏ i : Fin n, ∏ j ∈ Finset.univ.erase i, (r i - r j) := by calc ∏ i : Fin n, F.derivative.eval (r i) = ∏ i : Fin n, (c * ∏ j ∈ Finset.univ.erase i, (r i - r j)) := by refine Finset.prod_congr rfl fun i _ => derivative_eval_of_splits c r F hF i _ = (∏ _i : Fin n, c) * ∏ i : Fin n, ∏ j ∈ Finset.univ.erase i, (r i - r j) := Finset.prod_mul_distrib _ = c ^ n * ∏ i : Fin n, ∏ j ∈ Finset.univ.erase i, (r i - r j) := by simp rw [h1] have hdouble : (∏ i : Fin n, ∏ j ∈ Finset.univ.erase i, (r i - r j)) = ∏ x ∈ (Finset.univ.filter fun x : Fin n × Fin n => x.1 ≠ x.2), (r x.1 - r x.2) := by let emb : ((_ : Fin n) × Fin n) ↪ Fin n × Fin n := ⟨fun s => (s.1, s.2), fun a b h => by cases a; cases b; simp only [Prod.mk.injEq] at h; cases h.1; cases h.2; rfl⟩ have hset : (Finset.univ.filter fun x : Fin n × Fin n => x.1 ≠ x.2) = (Finset.univ.sigma fun i : Fin n => Finset.univ.erase i).map emb := by ext ⟨a, b⟩ simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_map, Finset.mem_sigma, Finset.mem_erase, and_true, emb] constructor · intro h exact ⟨⟨a, b⟩, h.symm, rfl⟩ · rintro ⟨⟨a', b'⟩, hne, hmk⟩ have ha : a' = a := congrArg Prod.fst hmk have hb : b' = b := congrArg Prod.snd hmk subst ha hb exact hne.symm rw [hset, Finset.prod_map, Finset.prod_sigma] rfl rw [hdouble] have hdisj : Disjoint (ltPairs n) (Finset.univ.filter fun x : Fin n × Fin n => x.2 < x.1) := by unfold ltPairs rw [Finset.disjoint_filter] intro x _ h1 h2 exact lt_asymm h1 h2 have hunion : (Finset.univ.filter fun x : Fin n × Fin n => x.1 ≠ x.2) = ltPairs n ∪ (Finset.univ.filter fun x : Fin n × Fin n => x.2 < x.1) := by ext ⟨a, b⟩ simp only [ltPairs, Finset.mem_union, Finset.mem_filter, Finset.mem_univ, true_and] exact ne_iff_lt_or_gt rw [hunion, Finset.prod_union hdisj] set Δ : K := ∏ x ∈ ltPairs n, (r x.2 - r x.1) have hpart1 : ∏ x ∈ ltPairs n, (r x.1 - r x.2) = (-1 : K) ^ (ltPairs n).card * Δ := by calc ∏ x ∈ ltPairs n, (r x.1 - r x.2) = ∏ x ∈ ltPairs n, ((-1 : K) * (r x.2 - r x.1)) := by refine Finset.prod_congr rfl fun x _ => by ring _ = (∏ _x ∈ ltPairs n, (-1 : K)) * Δ := Finset.prod_mul_distrib _ = (-1 : K) ^ (ltPairs n).card * Δ := by rw [Finset.prod_const] have hpart2 : ∏ x ∈ (Finset.univ.filter fun x : Fin n × Fin n => x.2 < x.1), (r x.1 - r x.2) = Δ := by refine Finset.prod_bij (fun x _ => x.swap) ?_ ?_ ?_ ?_ · intro x hx simp only [ltPairs, Finset.mem_filter, Finset.mem_univ, true_and, Prod.swap] at hx ⊢ exact hx · intro x _ y _ hxy exact Prod.swap_injective hxy · intro y hy refine ⟨y.swap, ?_, Prod.swap_swap y⟩ simp only [ltPairs, Finset.mem_filter, Finset.mem_univ, true_and, Prod.swap] at hy ⊢ exact hy · intro x _ rfl rw [hpart1, hpart2] ring /-- **Exact Closed-Form Discriminant Root Formula** over any field `K` in which `polySR K n` splits as `(n + 1) ∏_{j=0}^{n-1} (X - r_j)` with `2 * (n + 1) * (n + 2) ≠ 0`: $$(n + 1)^n \cdot (-1)^{\binom{n}{2}} \cdot \Delta^2 = 2 (n + 2)^{n - 1},$$ equivalently $$\operatorname{disc}(s_n) = (-1)^{\binom{n}{2}} (n + 1)^{n - 2} \prod_{i} s_n'(r_i) = (-1)^{\binom{n}{2}} \cdot 2 \cdot (n + 1)^{n - 2} (n + 2)^{n - 1}.$$ -/ theorem polySR_disc_root_formula {K : Type*} [Field K] {n : ℕ} (hn : 1 ≤ n) (hc1 : ((n + 1 : ℕ) : K) ≠ 0) (hc2 : ((n + 2 : ℕ) : K) ≠ 0) (r : Fin n → K) (hsplit : polySR K n = C ((n + 1 : ℕ) : K) * ∏ j : Fin n, (X - C (r j))) : ((n + 1 : ℕ) : K) ^ n * (-1 : K) ^ (ltPairs n).card * (∏ x ∈ ltPairs n, (r x.2 - r x.1)) ^ 2 = 2 * ((n + 2 : ℕ) : K) ^ (n - 1) := by set F : K[X] := polySR K n set c : K := ((n + 1 : ℕ) : K) have hroot : ∀ i : Fin n, F.eval (r i) = 0 := by intro i rw [hsplit, Polynomial.eval_mul, Polynomial.eval_prod] rw [Finset.prod_eq_zero (Finset.mem_univ i)] · simp · simp -- Step 1: Evaluate the differential identity at each root `r i`. have hdiff_r : ∀ i : Fin n, (r i - 1) * F.derivative.eval (r i) = (((n + 1) * (n + 2) : ℕ) : K) * (r i) ^ n := by intro i have h := congrArg (Polynomial.eval (r i)) (polySR_diff_identity (R := K) n) simp only [Polynomial.eval_add, Polynomial.eval_mul, Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_one, Polynomial.eval_ofNat, Polynomial.eval_C, Polynomial.eval_pow] at h change (r i - 1) * F.derivative.eval (r i) + 2 * F.eval (r i) = _ at h rw [hroot i, mul_zero, add_zero] at h exact h -- Step 2: Take the product over all `i : Fin n`. have hprod_diff : (∏ i : Fin n, (r i - 1)) * (∏ i : Fin n, F.derivative.eval (r i)) = (((n + 1) * (n + 2) : ℕ) : K) ^ n * (∏ i : Fin n, r i) ^ n := by calc (∏ i : Fin n, (r i - 1)) * (∏ i : Fin n, F.derivative.eval (r i)) = ∏ i : Fin n, ((r i - 1) * F.derivative.eval (r i)) := by rw [Finset.prod_mul_distrib] _ = ∏ i : Fin n, ((((n + 1) * (n + 2) : ℕ) : K) * (r i) ^ n) := by refine Finset.prod_congr rfl fun i _ => hdiff_r i _ = (∏ _i : Fin n, (((n + 1) * (n + 2) : ℕ) : K)) * ∏ i : Fin n, (r i) ^ n := Finset.prod_mul_distrib _ = (((n + 1) * (n + 2) : ℕ) : K) ^ n * (∏ i : Fin n, r i) ^ n := by rw [Finset.prod_const, Finset.card_univ, Fintype.card_fin, Finset.prod_pow] -- Step 3: Evaluate `hsplit` at `0` to get `c * (-1)^n * ∏ r_i = 1`. have hprod_r : c * (-1 : K) ^ n * (∏ i : Fin n, r i) = 1 := by have h0 := congrArg (Polynomial.eval (0 : K)) hsplit rw [polySR_eval_zero, Polynomial.eval_mul, Polynomial.eval_C, Polynomial.eval_prod] at h0 have hneg : (∏ j : Fin n, (X - C (r j)).eval 0) = (-1 : K) ^ n * ∏ j : Fin n, r j := by calc ∏ j : Fin n, (X - C (r j)).eval 0 = ∏ j : Fin n, ((-1 : K) * r j) := by refine Finset.prod_congr rfl fun j _ => by simp _ = (∏ _j : Fin n, (-1 : K)) * ∏ j : Fin n, r j := Finset.prod_mul_distrib _ = (-1 : K) ^ n * ∏ j : Fin n, r j := by simp rw [hneg] at h0 linear_combination -h0 -- Step 4: Evaluate `hsplit` at `1` to get `2 * (-1)^n * ∏ (r_i - 1) = n + 2`. have hprod_r_sub_one : 2 * (-1 : K) ^ n * (∏ i : Fin n, (r i - 1)) = ((n + 2 : ℕ) : K) := by have h1 := congrArg (Polynomial.eval (1 : K)) hsplit have h2eval := two_mul_polySR_eval_one (R := K) n rw [Polynomial.eval_mul, Polynomial.eval_C, Polynomial.eval_prod] at h1 have hneg1 : (∏ j : Fin n, (X - C (r j)).eval 1) = (-1 : K) ^ n * ∏ j : Fin n, (r j - 1) := by calc ∏ j : Fin n, (X - C (r j)).eval 1 = ∏ j : Fin n, ((-1 : K) * (r j - 1)) := by refine Finset.prod_congr rfl fun j _ => by simp _ = (∏ _j : Fin n, (-1 : K)) * ∏ j : Fin n, (r j - 1) := Finset.prod_mul_distrib _ = (-1 : K) ^ n * ∏ j : Fin n, (r j - 1) := by simp rw [hneg1] at h1 have hmul : c * (2 * (-1 : K) ^ n * ∏ j : Fin n, (r j - 1)) = c * ((n + 2 : ℕ) : K) := by calc c * (2 * (-1 : K) ^ n * ∏ j : Fin n, (r j - 1)) = 2 * (c * ((-1 : K) ^ n * ∏ j : Fin n, (r j - 1))) := by ring _ = 2 * (polySR K n).eval 1 := by rw [← h1] _ = (((n + 1) * (n + 2) : ℕ) : K) := h2eval _ = c * ((n + 2 : ℕ) : K) := by dsimp [c]; push_cast; ring exact mul_left_cancel₀ hc1 hmul -- Step 5: Combine and cancel `n + 2 ≠ 0`. have hsign : ((-1 : K) ^ n) ^ n = (-1 : K) ^ n := by rw [← pow_mul] rcases Nat.even_or_odd n with ⟨t, rfl⟩ | ⟨t, rfl⟩ · have h1 : Even (t + t) := ⟨t, rfl⟩ have h2 : Even ((t + t) * (t + t)) := Even.mul_left h1 _ rw [h1.neg_one_pow, h2.neg_one_pow] · have h1 : Odd (2 * t + 1) := ⟨t, rfl⟩ have h2 : Odd ((2 * t + 1) * (2 * t + 1)) := Odd.mul h1 h1 rw [h1.neg_one_pow, h2.neg_one_pow] have hcr : (c * ∏ i : Fin n, r i) ^ n = (-1 : K) ^ n := by have h1 : (c * ∏ i : Fin n, r i) * (-1 : K) ^ n = 1 := by linear_combination hprod_r have h2 : (c * ∏ i : Fin n, r i) = (-1 : K) ^ n := by have hsq : (-1 : K) ^ n * (-1 : K) ^ n = 1 := by rw [← pow_add, ← two_mul, Even.neg_one_pow ⟨n, by omega⟩] calc c * ∏ i : Fin n, r i = (c * ∏ i : Fin n, r i) * ((-1 : K) ^ n * (-1 : K) ^ n) := by rw [hsq, mul_one] _ = ((c * ∏ i : Fin n, r i) * (-1 : K) ^ n) * (-1 : K) ^ n := by ring _ = (-1 : K) ^ n := by rw [h1, one_mul] rw [h2, hsign] have hfinal : ((n + 2 : ℕ) : K) * (∏ i : Fin n, F.derivative.eval (r i)) = ((n + 2 : ℕ) : K) * (2 * ((n + 2 : ℕ) : K) ^ (n - 1)) := by have hrhs : (((n + 1) * (n + 2) : ℕ) : K) ^ n * (∏ i : Fin n, r i) ^ n = ((n + 2 : ℕ) : K) ^ n * (-1 : K) ^ n := by have hcast : (((n + 1) * (n + 2) : ℕ) : K) = ((n + 2 : ℕ) : K) * c := by dsimp [c]; push_cast; ring rw [hcast, mul_pow, mul_assoc, ← mul_pow, hcr] have hpow : ((n + 2 : ℕ) : K) ^ n = ((n + 2 : ℕ) : K) * ((n + 2 : ℕ) : K) ^ (n - 1) := by rw [← pow_succ', Nat.sub_add_cancel hn] calc ((n + 2 : ℕ) : K) * (∏ i : Fin n, F.derivative.eval (r i)) = (2 * (-1 : K) ^ n * ∏ i : Fin n, (r i - 1)) * (∏ i : Fin n, F.derivative.eval (r i)) := by rw [hprod_r_sub_one] _ = 2 * (-1 : K) ^ n * ((∏ i : Fin n, (r i - 1)) * (∏ i : Fin n, F.derivative.eval (r i))) := by ring _ = 2 * (-1 : K) ^ n * (((n + 2 : ℕ) : K) ^ n * (-1 : K) ^ n) := by rw [hprod_diff, hrhs] _ = 2 * ((n + 2 : ℕ) : K) ^ n * ((-1 : K) ^ n * (-1 : K) ^ n) := by ring _ = 2 * ((n + 2 : ℕ) : K) ^ n := by rw [← pow_add, ← two_mul, Even.neg_one_pow ⟨n, by omega⟩, mul_one] _ = ((n + 2 : ℕ) : K) * (2 * ((n + 2 : ℕ) : K) ^ (n - 1)) := by rw [hpow]; ring have hprod_eq : ∏ i : Fin n, F.derivative.eval (r i) = 2 * ((n + 2 : ℕ) : K) ^ (n - 1) := mul_left_cancel₀ hc2 hfinal rw [← hprod_eq] exact (prod_derivative_eval_eq_vandermonde_sq c r F hsplit).symm /-- Frobenius action on polynomial evaluation over a `ZMod p`-algebra of characteristic `p`. -/ lemma aeval_pow_char {p : ℕ} [Fact p.Prime] {K : Type*} [Field K] [Algebra (ZMod p) K] [CharP K p] (x : K) (g : (ZMod p)[X]) : (Polynomial.aeval x g) ^ p = Polynomial.aeval (x ^ p) g := by induction g using Polynomial.induction_on' with | add g₁ g₂ ih₁ ih₂ => rw [map_add, add_pow_char, ih₁, ih₂, map_add] | monomial k a => rw [Polynomial.aeval_monomial, Polynomial.aeval_monomial, mul_pow, ← map_pow, ZMod.pow_card a, ← pow_mul, mul_comm k p, pow_mul] /-- Iterated Frobenius action on polynomial evaluation over a `ZMod p`-algebra of characteristic `p`. -/ lemma aeval_pow_char_pow {p : ℕ} [Fact p.Prime] {K : Type*} [Field K] [Algebra (ZMod p) K] [CharP K p] (x : K) (g : (ZMod p)[X]) (k : ℕ) : (Polynomial.aeval x g) ^ (p ^ k) = Polynomial.aeval (x ^ (p ^ k)) g := by induction k with | zero => simp | succ k ih => rw [pow_succ, pow_mul, ih, aeval_pow_char, ← pow_mul] /-- Frobenius shift on the Vandermonde product of an `n`-cycle `r_i = α^{p^i}`: for even `n = 2m ≥ 2`, `Δ^p = -Δ`. -/ lemma vandermonde_pow_char_eq_neg {p m : ℕ} [Fact p.Prime] {K : Type*} [Field K] [CharP K p] (hm : 1 ≤ m) (α : K) (hcyc : α ^ (p ^ (2 * m)) = α) : (∏ x ∈ ltPairs (2 * m), (α ^ (p ^ x.2.val) - α ^ (p ^ x.1.val))) ^ p = -(∏ x ∈ ltPairs (2 * m), (α ^ (p ^ x.2.val) - α ^ (p ^ x.1.val))) := by set n : ℕ := 2 * m have hn : 0 < n := by omega let r : Fin n → K := fun i => α ^ (p ^ i.val) let σ : Fin n → Fin n := fun i => ⟨(i.val + 1) % n, Nat.mod_lt _ hn⟩ have hr_pow : ∀ i : Fin n, (r i) ^ p = r (σ i) := by intro i change (α ^ (p ^ i.val)) ^ p = α ^ (p ^ ((i.val + 1) % n)) rw [← pow_mul, ← pow_succ] by_cases hi : i.val + 1 < n · rw [Nat.mod_eq_of_lt hi] · have hieq : i.val + 1 = n := by omega rw [hieq, Nat.mod_self, pow_zero, pow_one, hcyc] have hstep1 : (∏ x ∈ ltPairs n, (r x.2 - r x.1)) ^ p = ∏ x ∈ ltPairs n, (r (σ x.2) - r (σ x.1)) := by rw [← Finset.prod_pow] refine Finset.prod_congr rfl fun x _ => ?_ rw [sub_pow_char, hr_pow, hr_pow] change (∏ x ∈ ltPairs n, (r x.2 - r x.1)) ^ p = -(∏ x ∈ ltPairs n, (r x.2 - r x.1)) rw [hstep1] -- Partition `ltPairs n` into `S₁ = {j + 1 < n}` and `S₂ = {j + 1 = n}`. set S₁ : Finset (Fin n × Fin n) := (ltPairs n).filter fun x => x.2.val + 1 < n set S₂ : Finset (Fin n × Fin n) := (ltPairs n).filter fun x => x.2.val + 1 = n have hS_disj : Disjoint S₁ S₂ := by rw [Finset.disjoint_filter] intro x _ h1 h2; omega have hS_union : ltPairs n = S₁ ∪ S₂ := by ext x simp only [S₁, S₂, Finset.mem_union, Finset.mem_filter] constructor · intro hx have hlt : x.2.val < n := x.2.isLt by_cases h : x.2.val + 1 < n · exact Or.inl ⟨hx, h⟩ · exact Or.inr ⟨hx, by omega⟩ · rintro (⟨hx, _⟩ | ⟨hx, _⟩) <;> exact hx -- Partition `ltPairs n` into `T₁ = {0 < i}` and `T₂ = {i = 0}`. set T₁ : Finset (Fin n × Fin n) := (ltPairs n).filter fun x => 0 < x.1.val set T₂ : Finset (Fin n × Fin n) := (ltPairs n).filter fun x => x.1.val = 0 have hT_disj : Disjoint T₁ T₂ := by rw [Finset.disjoint_filter] intro x _ h1 h2; omega have hT_union : ltPairs n = T₁ ∪ T₂ := by ext x simp only [T₁, T₂, Finset.mem_union, Finset.mem_filter] constructor · intro hx by_cases h : 0 < x.1.val · exact Or.inl ⟨hx, h⟩ · exact Or.inr ⟨hx, by omega⟩ · rintro (⟨hx, _⟩ | ⟨hx, _⟩) <;> exact hx -- Bijection `S₁ ↔ T₁` via `(i, j) ↦ (σ i, σ j)`. have hprod1 : (∏ x ∈ S₁, (r (σ x.2) - r (σ x.1))) = ∏ y ∈ T₁, (r y.2 - r y.1) := by refine Finset.prod_bij (fun x _ => (σ x.1, σ x.2)) ?_ ?_ ?_ ?_ · intro x hx simp only [S₁, T₁, ltPairs, Finset.mem_filter, Finset.mem_univ, true_and] at hx ⊢ have hx1 : x.1.val + 1 < n := by have : x.1.val < x.2.val := hx.1 omega simp only [σ, Fin.lt_def, Nat.mod_eq_of_lt hx1, Nat.mod_eq_of_lt hx.2] exact ⟨by omega, by omega⟩ · intro x hx y hy hxy simp only [S₁, ltPairs, Finset.mem_filter, Finset.mem_univ, true_and] at hx hy have hx1 : x.1.val + 1 < n := by have : x.1.val < x.2.val := hx.1; omega have hy1 : y.1.val + 1 < n := by have : y.1.val < y.2.val := hy.1; omega simp only [Prod.mk.injEq, σ, Fin.ext_iff, Nat.mod_eq_of_lt hx1, Nat.mod_eq_of_lt hx.2, Nat.mod_eq_of_lt hy1, Nat.mod_eq_of_lt hy.2] at hxy exact Prod.ext (Fin.ext (by omega)) (Fin.ext (by omega)) · intro y hy simp only [T₁, ltPairs, Finset.mem_filter, Finset.mem_univ, true_and] at hy have hy1 : y.1.val < y.2.val := hy.1 have hy2 : y.2.val < n := y.2.isLt refine ⟨(⟨y.1.val - 1, by omega⟩, ⟨y.2.val - 1, by omega⟩), ?_, ?_⟩ · simp only [S₁, ltPairs, Finset.mem_filter, Finset.mem_univ, true_and, Fin.lt_def] exact ⟨by omega, by omega⟩ · apply Prod.ext <;> apply Fin.ext <;> dsimp [σ] · rw [show y.1.val - 1 + 1 = y.1.val by omega, Nat.mod_eq_of_lt y.1.isLt] · rw [show y.2.val - 1 + 1 = y.2.val by omega, Nat.mod_eq_of_lt y.2.isLt] · intro x _ rfl -- Bijection `S₂ ↔ T₂` via `(i, n - 1) ↦ (0, σ i)` with sign `-1` on each factor. have hprod2 : (∏ x ∈ S₂, (r (σ x.2) - r (σ x.1))) = (-1 : K) ^ S₂.card * ∏ y ∈ T₂, (r y.2 - r y.1) := by have hneg : (∏ x ∈ S₂, (r (σ x.2) - r (σ x.1))) = (-1 : K) ^ S₂.card * ∏ x ∈ S₂, (r (σ x.1) - r (σ x.2)) := by calc ∏ x ∈ S₂, (r (σ x.2) - r (σ x.1)) = ∏ x ∈ S₂, ((-1 : K) * (r (σ x.1) - r (σ x.2))) := by refine Finset.prod_congr rfl fun x _ => by ring _ = (∏ _x ∈ S₂, (-1 : K)) * ∏ x ∈ S₂, (r (σ x.1) - r (σ x.2)) := Finset.prod_mul_distrib _ = (-1 : K) ^ S₂.card * ∏ x ∈ S₂, (r (σ x.1) - r (σ x.2)) := by rw [Finset.prod_const] rw [hneg] congr 1 refine Finset.prod_bij (fun x _ => (σ x.2, σ x.1)) ?_ ?_ ?_ ?_ · intro x hx simp only [S₂, T₂, ltPairs, Finset.mem_filter, Finset.mem_univ, true_and] at hx ⊢ have hx1 : x.1.val + 1 < n := by have : x.1.val < x.2.val := hx.1; omega simp only [σ, Fin.lt_def, hx.2, Nat.mod_self, Nat.mod_eq_of_lt hx1] exact ⟨by omega, trivial⟩ · intro x hx y hy hxy simp only [S₂, ltPairs, Finset.mem_filter, Finset.mem_univ, true_and] at hx hy have hx1 : x.1.val + 1 < n := by have : x.1.val < x.2.val := hx.1; omega have hy1 : y.1.val + 1 < n := by have : y.1.val < y.2.val := hy.1; omega simp only [Prod.mk.injEq, σ, Fin.ext_iff, Nat.mod_eq_of_lt hx1, Nat.mod_eq_of_lt hy1] at hxy exact Prod.ext (Fin.ext (by omega)) (Fin.ext (by omega)) · intro y hy simp only [T₂, ltPairs, Finset.mem_filter, Finset.mem_univ, true_and] at hy have hy1 : y.1.val < y.2.val := hy.1 have hy2 : y.2.val < n := y.2.isLt refine ⟨(⟨y.2.val - 1, by omega⟩, ⟨n - 1, by omega⟩), ?_, ?_⟩ · simp only [S₂, ltPairs, Finset.mem_filter, Finset.mem_univ, true_and, Fin.lt_def] exact ⟨by omega, by omega⟩ · apply Prod.ext <;> apply Fin.ext <;> dsimp [σ] · rw [show n - 1 + 1 = n by omega, Nat.mod_self, hy.2] · rw [show y.2.val - 1 + 1 = y.2.val by omega, Nat.mod_eq_of_lt y.2.isLt] · intro x _ rfl -- Compute `S₂.card = n - 1 = 2 * m - 1`, which is odd! have hcard_S₂ : S₂.card = 2 * m - 1 := by have hbij : S₂.card = (Finset.range (2 * m - 1)).card := by refine Finset.card_bij (fun x _ => x.1.val) ?_ ?_ ?_ · intro x hx simp only [S₂, ltPairs, Finset.mem_filter, Finset.mem_univ, true_and] at hx rw [Finset.mem_range] have : x.1.val < x.2.val := hx.1 omega · intro x hx y hy hxy simp only [S₂, ltPairs, Finset.mem_filter, Finset.mem_univ, true_and] at hx hy exact Prod.ext (Fin.ext hxy) (Fin.ext (by omega)) · intro k hk rw [Finset.mem_range] at hk refine ⟨(⟨k, by omega⟩, ⟨2 * m - 1, by omega⟩), ?_, rfl⟩ simp only [S₂, ltPairs, Finset.mem_filter, Finset.mem_univ, true_and, Fin.lt_def] exact ⟨by omega, by omega⟩ rw [hbij, Finset.card_range] have hodd : Odd S₂.card := by rw [hcard_S₂] exact ⟨m - 1, by omega⟩ calc ∏ x ∈ ltPairs n, (r (σ x.2) - r (σ x.1)) = (∏ x ∈ S₁, (r (σ x.2) - r (σ x.1))) * (∏ x ∈ S₂, (r (σ x.2) - r (σ x.1))) := by conv_lhs => rw [hS_union] rw [Finset.prod_union hS_disj] _ = (∏ y ∈ T₁, (r y.2 - r y.1)) * ((-1 : K) ^ S₂.card * ∏ y ∈ T₂, (r y.2 - r y.1)) := by rw [hprod1, hprod2] _ = (-1 : K) ^ S₂.card * ((∏ y ∈ T₁, (r y.2 - r y.1)) * ∏ y ∈ T₂, (r y.2 - r y.1)) := by ring _ = -(∏ y ∈ ltPairs n, (r y.2 - r y.1)) := by rw [hodd.neg_one_pow, ← Finset.prod_union hT_disj, ← hT_union] ring /-- **Sharp Stickelberger–Frobenius Criterion for `polyS` of Even Degree**: Let `m ≥ 1` and let `p` be an odd prime with `p ∤ (2m + 1)` and `p ∤ (m + 1)`. If `s_{2m}(X)` is irreducible over `ZMod p`, then `(-1)^m * (m + 1)` is NOT a square in `ZMod p`. -/ theorem polyS_even_irreducible_imp_not_isSquare {p m : ℕ} [Fact p.Prime] (hp2 : p ≠ 2) (hm : 1 ≤ m) (hd1 : ¬ p ∣ 2 * m + 1) (hd2 : ¬ p ∣ m + 1) (hirr : Irreducible (polySR (ZMod p) (2 * m))) : ¬ IsSquare (((-1 : ZMod p) ^ m) * ((m + 1 : ℕ) : ZMod p)) := by have hp : p.Prime := Fact.out have hp_gt1 : 1 < p := hp.one_lt set n : ℕ := 2 * m set f : (ZMod p)[X] := polySR (ZMod p) n have h2_ne : (2 : ZMod p) ≠ 0 := by intro h0 have hd : p ∣ 2 := (ZMod.natCast_eq_zero_iff 2 p).mp h0 exact hp2 ((Nat.dvd_prime Nat.prime_two).mp hd |>.resolve_left hp.ne_one) have hc1_ne : ((n + 1 : ℕ) : ZMod p) ≠ 0 := by intro h0 exact hd1 ((ZMod.natCast_eq_zero_iff (2 * m + 1) p).mp h0) have hm1_ne : ((m + 1 : ℕ) : ZMod p) ≠ 0 := by intro h0 exact hd2 ((ZMod.natCast_eq_zero_iff (m + 1) p).mp h0) have hc2_ne : ((n + 2 : ℕ) : ZMod p) ≠ 0 := by have h2m2 : ((n + 2 : ℕ) : ZMod p) = 2 * ((m + 1 : ℕ) : ZMod p) := by change ((2 * m + 2 : ℕ) : ZMod p) = _ push_cast; ring rw [h2m2] exact mul_ne_zero h2_ne hm1_ne have hf_deg : f.natDegree = n := polySR_natDegree_eq hc1_ne -- Work in the finite extension field `K = AdjoinRoot f`. let _ : Fact (Irreducible f) := ⟨hirr⟩ let K := AdjoinRoot f let _ : Field K := AdjoinRoot.instField let pb : PowerBasis (ZMod p) K := AdjoinRoot.powerBasis hirr.ne_zero have hpb_dim : pb.dim = n := by change f.natDegree = n exact hf_deg let _ : Fintype K := Fintype.ofEquiv (Fin pb.dim → ZMod p) pb.basis.equivFun.toEquiv.symm have hcard_K : Fintype.card K = p ^ n := by rw [Fintype.card_congr pb.basis.equivFun.toEquiv, Fintype.card_fun, Fintype.card_fin, ZMod.card, hpb_dim] let _ : CharP K p := charP_of_injective_algebraMap (algebraMap (ZMod p) K).injective p set α : K := AdjoinRoot.root f have hα_root : Polynomial.aeval α f = 0 := by rw [AdjoinRoot.aeval_eq, AdjoinRoot.mk_self] let r : Fin n → K := fun j => α ^ (p ^ j.val) -- Step 1: Every `r j` is a root of `F = polySR K n`. set F : K[X] := polySR K n have hF_map : F = f.map (algebraMap (ZMod p) K) := (map_polySR (algebraMap (ZMod p) K) n).symm have hr_root : ∀ j : Fin n, F.IsRoot (r j) := by intro j rw [Polynomial.IsRoot, hF_map, Polynomial.eval_map, ← Polynomial.aeval_def, ← aeval_pow_char_pow, hα_root, zero_pow (pow_ne_zero j.val hp.ne_zero)] -- Step 2: The `n` conjugates `r 0, ..., r (n - 1)` are pairwise distinct. have hr_inj : Function.Injective r := by intro i j hij by_contra hne wlog hlt : i < j generalizing i j · exact this hij.symm (Ne.symm hne) (lt_of_le_of_ne (not_lt.mp hlt) (Ne.symm hne)) set d : ℕ := j.val - i.val have hd_pos : 0 < d := by omega have hd_lt : d < n := by omega have hj_eq : j.val = d + i.val := by omega have hpow_eq : (α ^ (p ^ d)) ^ (p ^ i.val) = α ^ (p ^ i.val) := by rw [← pow_mul, ← pow_add, ← hj_eq] exact hij.symm have hiter_inj : ∀ k : ℕ, Function.Injective (fun x : K => x ^ (p ^ k)) := by intro k induction k with | zero => intro x y hxy; simpa using hxy | succ k ih => intro x y hxy apply ih apply frobenius_inj K p simpa [frobenius_def, pow_succ, pow_mul] using hxy have hα_fix : α ^ (p ^ d) = α := hiter_inj i.val hpow_eq have hall_fix : ∀ x : K, x ^ (p ^ d) = x := by intro x obtain ⟨g, rfl⟩ := AdjoinRoot.mk_surjective x change (AdjoinRoot.mk f g) ^ (p ^ d) = AdjoinRoot.mk f g have hmk : AdjoinRoot.mk f g = Polynomial.aeval α g := by rw [← AdjoinRoot.aeval_eq] rw [hmk, aeval_pow_char_pow, hα_fix] set Q : K[X] := X ^ (p ^ d) - X have hpd_gt1 : 1 < p ^ d := one_lt_pow₀ hp_gt1 (by omega) have hQ_ne : Q ≠ 0 := by intro h0 have hc := congrArg (fun P : K[X] => P.coeff (p ^ d)) h0 simp only [Q, Polynomial.coeff_sub, Polynomial.coeff_X_pow, Polynomial.coeff_X, Polynomial.coeff_zero, ite_true, if_neg (by omega : 1 ≠ p ^ d), sub_zero] at hc exact one_ne_zero hc have hQ_deg : Q.natDegree ≤ p ^ d := le_trans (Polynomial.natDegree_sub_le _ _) (max_le (Polynomial.natDegree_X_pow_le (p ^ d)) (le_trans Polynomial.natDegree_X_le (by omega))) have hsub : (Finset.univ : Finset K) ⊆ Q.roots.toFinset := by intro x _ rw [Multiset.mem_toFinset, Polynomial.mem_roots hQ_ne, Polynomial.IsRoot, Polynomial.eval_sub, Polynomial.eval_pow, Polynomial.eval_X, hall_fix x, sub_self] have hle : Fintype.card K ≤ p ^ d := by calc Fintype.card K = (Finset.univ : Finset K).card := rfl _ ≤ Q.roots.toFinset.card := Finset.card_le_card hsub _ ≤ Q.roots.card := Multiset.toFinset_card_le Q.roots _ ≤ Q.natDegree := Polynomial.card_roots' Q _ ≤ p ^ d := hQ_deg rw [hcard_K] at hle exact not_lt_of_ge hle (Nat.pow_lt_pow_right hp_gt1 hd_lt) -- Step 3: `F` splits completely as `C ((n + 1 : ℕ) : K) * ∏ j, (X - C (r j))`. set P : K[X] := ∏ j : Fin n, (X - C (r j)) have hP_monic : P.Monic := Polynomial.monic_prod_of_monic _ _ fun j _ => Polynomial.monic_X_sub_C (r j) have hP_deg : P.natDegree = n := by rw [Polynomial.natDegree_prod_of_monic _ _ (fun j _ => Polynomial.monic_X_sub_C (r j))] simp have hP_dvd : P ∣ F := by refine Finset.prod_dvd_of_coprime ?_ fun j _ => Polynomial.dvd_iff_isRoot.mpr (hr_root j) intro i _ j _ hij have hne : r j - r i ≠ 0 := sub_ne_zero.mpr (fun h => hij (hr_inj h.symm)) refine ⟨C (r j - r i)⁻¹, -C (r j - r i)⁻¹, ?_⟩ have hmul : C (r j - r i)⁻¹ * (X - C (r i)) + -C (r j - r i)⁻¹ * (X - C (r j)) = C ((r j - r i)⁻¹ * (r j - r i)) := by rw [map_mul, map_sub] ring rw [hmul, inv_mul_cancel₀ hne, map_one] obtain ⟨U, hFU⟩ := hP_dvd have hc1K_ne : ((n + 1 : ℕ) : K) ≠ 0 := by intro h0 have h0' : algebraMap (ZMod p) K ((n + 1 : ℕ) : ZMod p) = 0 := by rw [map_natCast]; exact h0 exact hc1_ne ((map_eq_zero_iff (algebraMap (ZMod p) K) (algebraMap (ZMod p) K).injective).mp h0') have hF_deg : F.natDegree = n := polySR_natDegree_eq hc1K_ne have hF_lc : F.leadingCoeff = ((n + 1 : ℕ) : K) := polySR_leadingCoeff hc1K_ne have hF_ne : F ≠ 0 := by intro h0; rw [h0, Polynomial.leadingCoeff_zero] at hF_lc; exact hc1K_ne hF_lc.symm have hU_ne : U ≠ 0 := by intro h0; rw [h0, mul_zero] at hFU; exact hF_ne hFU have hU_deg : U.natDegree = 0 := by have hdeg_mul := Polynomial.natDegree_mul hP_monic.ne_zero hU_ne rw [← hFU, hF_deg, hP_deg] at hdeg_mul omega have hU_eq : U = C ((n + 1 : ℕ) : K) := by have h1 : U = C (U.coeff 0) := Polynomial.eq_C_of_natDegree_eq_zero hU_deg have hlc : U.leadingCoeff = U.coeff 0 := by rw [Polynomial.leadingCoeff, hU_deg] have h2 : F.leadingCoeff = P.leadingCoeff * U.leadingCoeff := by rw [hFU, Polynomial.leadingCoeff_mul] rw [hF_lc, hP_monic.leadingCoeff, one_mul, hlc] at h2 rw [h1, ← h2] have hsplit : F = C ((n + 1 : ℕ) : K) * ∏ j : Fin n, (X - C (r j)) := by rw [hFU, hU_eq, mul_comm] -- Step 4: Apply the exact discriminant root formula and the Frobenius sign flip. set Δ : K := ∏ x ∈ ltPairs n, (r x.2 - r x.1) have hΔ_ne : Δ ≠ 0 := by rw [Finset.prod_ne_zero_iff] intro x hx simp only [ltPairs, Finset.mem_filter, Finset.mem_univ, true_and] at hx exact sub_ne_zero.mpr (fun h => ne_of_gt hx (hr_inj h)) have hcyc : α ^ (p ^ n) = α := by rw [← hcard_K] exact FiniteField.pow_card α have hΔ_frob : Δ ^ p = -Δ := vandermonde_pow_char_eq_neg hm α hcyc have h2K_ne : (2 : K) ≠ 0 := by intro h0 have h0' : algebraMap (ZMod p) K (2 : ZMod p) = 0 := by rw [map_ofNat]; exact h0 exact h2_ne ((map_eq_zero_iff (algebraMap (ZMod p) K) (algebraMap (ZMod p) K).injective).mp h0') have hc2K_ne : ((n + 2 : ℕ) : K) ≠ 0 := by intro h0 have h0' : algebraMap (ZMod p) K ((n + 2 : ℕ) : ZMod p) = 0 := by rw [map_natCast]; exact h0 exact hc2_ne ((map_eq_zero_iff (algebraMap (ZMod p) K) (algebraMap (ZMod p) K).injective).mp h0') have hdisc := polySR_disc_root_formula (K := K) (n := n) (by omega) hc1K_ne hc2K_ne r hsplit rw [neg_one_pow_card_ltPairs_even m] at hdisc -- Step 5: Assume `(-1)^m * (m + 1) = u^2` in `ZMod p` and derive `Δ ∈ ZMod p`, contradiction! rintro ⟨u, hu⟩ have hsq_u : u ^ 2 = ((-1 : ZMod p) ^ m) * ((m + 1 : ℕ) : ZMod p) := by rw [sq, ← hu] set t : ZMod p := u * (2 : ZMod p) ^ m * ((m + 1 : ℕ) : ZMod p) ^ (m - 1) * (((n + 1 : ℕ) : ZMod p) ^ m)⁻¹ have ht_sq : ((n + 1 : ℕ) : K) ^ n * (algebraMap (ZMod p) K t) ^ 2 = (-1 : K) ^ m * (2 * ((n + 2 : ℕ) : K) ^ (n - 1)) := by have hcast_t : algebraMap (ZMod p) K t = algebraMap (ZMod p) K u * (2 : K) ^ m * ((m + 1 : ℕ) : K) ^ (m - 1) * (((n + 1 : ℕ) : K) ^ m)⁻¹ := by simp only [t, map_mul, map_pow, map_inv₀, map_ofNat, map_natCast] have hcast_u2 : (algebraMap (ZMod p) K u) ^ 2 = (-1 : K) ^ m * ((m + 1 : ℕ) : K) := by rw [← map_pow, hsq_u] simp only [map_mul, map_pow, map_neg, map_one, map_natCast] have hc_pow : ((n + 1 : ℕ) : K) ^ n * ((((n + 1 : ℕ) : K) ^ m)⁻¹) ^ 2 = 1 := by have hne : ((n + 1 : ℕ) : K) ^ m ≠ 0 := pow_ne_zero m hc1K_ne have hpow_c : ((n + 1 : ℕ) : K) ^ n = (((n + 1 : ℕ) : K) ^ m) ^ 2 := by rw [← pow_mul] congr 1 omega rw [hpow_c, ← mul_pow, mul_inv_cancel₀ hne, one_pow] have h2n : (2 : K) * ((n + 2 : ℕ) : K) ^ (n - 1) = (2 : K) ^ (2 * m) * ((m + 1 : ℕ) : K) ^ (2 * m - 1) := by have h2m2 : ((n + 2 : ℕ) : K) = 2 * ((m + 1 : ℕ) : K) := by change ((2 * m + 2 : ℕ) : K) = _ push_cast; ring rw [h2m2, mul_pow, ← mul_assoc] have h2pow : (2 : K) * (2 : K) ^ (2 * m - 1) = (2 : K) ^ (2 * m) := by rw [← pow_succ', show 2 * m - 1 + 1 = 2 * m by omega] rw [h2pow] have hmpow : ((m + 1 : ℕ) : K) * (((m + 1 : ℕ) : K) ^ (m - 1)) ^ 2 = ((m + 1 : ℕ) : K) ^ (2 * m - 1) := by rw [← pow_mul, ← pow_succ'] congr 1 omega calc ((n + 1 : ℕ) : K) ^ n * (algebraMap (ZMod p) K t) ^ 2 = (((n + 1 : ℕ) : K) ^ n * ((((n + 1 : ℕ) : K) ^ m)⁻¹) ^ 2) * (algebraMap (ZMod p) K u) ^ 2 * ((2 : K) ^ m) ^ 2 * (((m + 1 : ℕ) : K) ^ (m - 1)) ^ 2 := by rw [hcast_t]; ring _ = (-1 : K) ^ m * (2 : K) ^ (2 * m) * (((m + 1 : ℕ) : K) * (((m + 1 : ℕ) : K) ^ (m - 1)) ^ 2) := by rw [hc_pow, one_mul, hcast_u2, ← pow_mul, mul_comm m 2]; ring _ = (-1 : K) ^ m * (2 * ((n + 2 : ℕ) : K) ^ (n - 1)) := by rw [hmpow, h2n]; ring have hΔ_sq : Δ ^ 2 = (algebraMap (ZMod p) K t) ^ 2 := by have hmul : ((n + 1 : ℕ) : K) ^ n * Δ ^ 2 = ((n + 1 : ℕ) : K) ^ n * (algebraMap (ZMod p) K t) ^ 2 := by have hsign2 : (-1 : K) ^ m * (-1 : K) ^ m = 1 := by rw [← pow_add, ← two_mul, Even.neg_one_pow ⟨m, by omega⟩] rw [ht_sq, ← hdisc] calc ((n + 1 : ℕ) : K) ^ n * Δ ^ 2 = ((-1 : K) ^ m * (-1 : K) ^ m) * (((n + 1 : ℕ) : K) ^ n * Δ ^ 2) := by rw [hsign2, one_mul] _ = (-1 : K) ^ m * (((n + 1 : ℕ) : K) ^ n * (-1 : K) ^ m * Δ ^ 2) := by ring exact mul_left_cancel₀ (pow_ne_zero n hc1K_ne) hmul have hΔ_in_base : Δ ^ p = Δ := by rcases sq_eq_sq_iff_eq_or_eq_neg.mp hΔ_sq with hpos | hneg · rw [hpos, ← map_pow, ZMod.pow_card] · rw [hneg, ← map_neg, ← map_pow, ZMod.pow_card] have h2Δ : (2 : K) * Δ = 0 := by have : Δ = -Δ := hΔ_in_base.symm.trans hΔ_frob linear_combination this rcases mul_eq_zero.mp h2Δ with h20 | hΔ0 · exact h2K_ne h20 · exact hΔ_ne hΔ0 /-- Legendre-symbol formulation of the sharp Stickelberger–Frobenius obstruction: for every `m ≥ 1` and odd prime `p` not dividing `(2m + 1)(m + 1)`, if `s_{2m}(X)` is irreducible modulo `p`, then `legendreSym p ((-1)^m * (m + 1)) = -1`. -/ theorem polyS_even_irreducible_imp_legendreSym_eq_neg_one {p m : ℕ} [Fact p.Prime] (hp2 : p ≠ 2) (hm : 1 ≤ m) (hd1 : ¬ p ∣ 2 * m + 1) (hd2 : ¬ p ∣ m + 1) (hirr : Irreducible (Polynomial.map (Int.castRingHom (ZMod p)) (polyS (2 * m)))) : legendreSym p ((-1 : ℤ) ^ m * (m + 1 : ℤ)) = -1 := by rw [map_polyS] at hirr have hnsq := polyS_even_irreducible_imp_not_isSquare hp2 hm hd1 hd2 hirr have hcast : (((-1 : ℤ) ^ m * (m + 1 : ℤ) : ℤ) : ZMod p) = ((-1 : ZMod p) ^ m) * ((m + 1 : ℕ) : ZMod p) := by push_cast; rfl rw [legendreSym.eq_neg_one_iff] rwa [hcast] /-! ### Section 4: Complete Proof of the `(⇐)` Direction of OEIS A217785 Conjecture 4 -/ /-- **Main Theorem (OEIS A217785 Conjecture 4, `(⇐)` direction)**: For every positive integer `k`, the polynomial $$s_{8k(k+1)}(x) = \sum_{j=0}^{8k(k+1)} (j + 1) x^j$$ is reducible modulo EVERY prime `p`. -/ theorem conjecture_4_mpr (n : ℕ) (hn : ∃ k : ℕ, 0 < k ∧ n = 8 * k * (k + 1)) : ∀ p : ℕ, p.Prime → ¬ Irreducible (Polynomial.map (Int.castRingHom (ZMod p)) (polyS n)) := by obtain ⟨k, hk, rfl⟩ := hn intro p hp rw [map_polyS] let _ : Fact p.Prime := ⟨hp⟩ set m : ℕ := 4 * k * (k + 1) have hn_eq : 8 * k * (k + 1) = 2 * m := by dsimp [m]; ring have hm_ge2 : 2 ≤ m := by dsimp [m]; nlinarith have hm_ge1 : 1 ≤ m := le_trans (by decide) hm_ge2 rw [hn_eq] by_cases hp2 : p = 2 · subst hp2 exact polyS_not_irreducible_two hm_ge1 · by_cases hd1 : p ∣ 2 * m + 1 · exact polyS_not_irreducible_of_dvd_succ hp2 (by linarith) hd1 · by_cases hd2 : p ∣ m + 1 · have hd2' : p ∣ 2 * m + 2 := by obtain ⟨t, ht⟩ := hd2 exact ⟨2 * t, by linarith⟩ exact polyS_not_irreducible_of_dvd_add_two hp2 hm_ge1 hd2' · intro hirr have hnsq := polyS_even_irreducible_imp_not_isSquare hp2 hm_ge1 hd1 hd2 hirr apply hnsq have hm_even : Even m := ⟨2 * k * (k + 1), by dsimp [m]; ring⟩ have hm1_sq : m + 1 = (2 * k + 1) ^ 2 := by dsimp [m]; ring refine ⟨((2 * k + 1 : ℕ) : ZMod p), ?_⟩ rw [hm_even.neg_one_pow, one_mul, hm1_sq, Nat.cast_pow, sq] /-! ### Section 5: Exact Square-Discriminant Classification -/ /-- **Exact Square-Discriminant Classification**: For `m ≥ 1`, the square-free kernel factor `(-1)^m * (m + 1)` of `disc(s_{2m})` is a perfect square in `ℤ` if and only if `2m = 8k(k + 1)` for some `k > 0`. -/ theorem even_disc_isSquare_iff (m : ℕ) (hm : 1 ≤ m) : IsSquare ((-1 : ℤ) ^ m * ((m + 1 : ℕ) : ℤ)) ↔ ∃ k : ℕ, 0 < k ∧ 2 * m = 8 * k * (k + 1) := by constructor · rintro ⟨r, hr⟩ have hm_even : Even m := by rcases Nat.even_or_odd m with he | ho · exact he · rw [ho.neg_one_pow] at hr have hneg : -((m + 1 : ℕ) : ℤ) < 0 := by omega have hnn : 0 ≤ r * r := mul_self_nonneg r omega rw [hm_even.neg_one_pow, one_mul] at hr have hnat : m + 1 = r.natAbs * r.natAbs := by have h1 : ((m + 1 : ℕ) : ℤ) = (r.natAbs : ℤ) * (r.natAbs : ℤ) := by rw [hr, ← sq, ← sq, Int.natAbs_sq] exact_mod_cast h1 have hr_odd : Odd r.natAbs := by obtain ⟨t, ht⟩ := hm_even rcases Nat.even_or_odd r.natAbs with ⟨u, hu⟩ | ho · exfalso have h1 : m + 1 = 2 * (2 * u * u) := by rw [hnat, hu]; ring omega · exact ho obtain ⟨k, hk⟩ := hr_odd have hk_pos : 0 < k := by by_contra h0 have hk0 : k = 0 := by omega rw [hk0] at hk rw [hk] at hnat omega refine ⟨k, hk_pos, ?_⟩ rw [hk] at hnat nlinarith · rintro ⟨k, hk, h2m⟩ have hm_eq : m = 4 * k * (k + 1) := by linarith have hm_even : Even m := ⟨2 * k * (k + 1), by linarith⟩ refine ⟨(2 * k + 1 : ℤ), ?_⟩ rw [hm_even.neg_one_pow, one_mul, hm_eq] push_cast ring /-! ### Axiom Audit -/ #print axioms polySR_mul_X_sub_one_sq #print axioms polySR_diff_identity #print axioms polyS_mod_two_eq_sq #print axioms polyS_not_irreducible_two #print axioms polyS_not_irreducible_of_dvd_succ #print axioms polyS_not_irreducible_of_dvd_add_two #print axioms polySR_disc_root_formula #print axioms polyS_even_irreducible_imp_not_isSquare #print axioms polyS_even_irreducible_imp_legendreSym_eq_neg_one #print axioms conjecture_4_mpr #print axioms even_disc_isSquare_iff end OeisA217785