Skip to content

Lean formalization of the Riemann Hypothesis (Alpöge, 2026-11-20) being cleaned up by members of the Lean community.

Python
22.1 KB
Raw Blame
module

import TauCeti.LinearAlgebra.Determinant.Basic
import TauCeti.LinearAlgebra.Submodule.CardFinrank
public import Mathlib.LinearAlgebra.Lagrange
public import Mathlib.RingTheory.Polynomial.UniversalFactorizationRing
import Mathlib.Algebra.AffineMonoid.UniqueSums
import Mathlib.NumberTheory.NumberField.CanonicalEmbedding.Basic
import Mathlib.RingTheory.Coalgebra.IsFrobenius
import Mathlib.RingTheory.Henselian
import Mathlib.RingTheory.HopfAlgebra.Basic
import Mathlib.RingTheory.RegularLocalRing.Defs
import Mathlib.RingTheory.SimpleRing.Principal
public import Lib.Speed

/-!
# The q-binomial theorem, fibre sums, and Schur polynomials in the coefficients

The q-binomial theorem is proved as a sum over the subspaces of a vector space over a field with `q`
elements. There is a lemma on grouping a finite sum by the fibres of a map. Schur polynomials are
defined without division, as integer polynomials in the coefficients of a monic polynomial; `s_l(r)`
denotes the Schur polynomial with exponent tuple `l`, evaluated at a tuple of roots `r`. Three
algebraic facts serve to extract values of Schur polynomials from vanishing linear forms.

## Main definitions and results

* `New.q_binomial_submodule`: the sum of `New.heckePolyCoeff X U` over the subspaces `U` of `W` is
  `New.SiegelWeil.qPochhammer q (dim W) X`.
* `New.Variety.genericSchur`, `New.Variety.rootCoeffEval`: the Schur polynomial in the coefficients,
  and evaluation at the coefficients of the monic polynomial with a given multiset of roots.
* `New.Variety.rootCoeffEval_genericSchur_mul_det`: the value times the Vandermonde determinant is
  `det (r i ^ l j)`.
* `New.Variety.sum_lagrange_smul_rootCoeffEval`: for distinct elements r₁, …, r_a of a field,
  summing s_l(r₁, …, X rᵢ, …) against the Lagrange factors ∏_{k ≠ i} (X rᵢ − r_k)/(rᵢ − r_k)
  gives s_l(r)·∑ⱼ X^(l j).
* `New.Variety.map_prod_rootCoeffEval_eq_zero`: a linear form that kills the families
  j ↦ ∏_{i, σ} ∏_{t ∈ x(j, σ)} (1 − c(i, σ)(α) t) for all α, with the c(i, σ) algebraically
  independent, kills the products over σ of polynomials of bounded degree in the coefficients of
  ∏_{t ∈ x(j, σ)} (X − t).

## Relation to the literature

Known results: the q-binomial theorem, counted over the subspaces of a finite vector space, and the
bialternant formula for Schur polynomials.
-/

@[expose] public section

/-! ## The q-binomial theorem over the subspaces of a finite vector space -/

section QBinomial

open Finset Module Submodule

-- Finite types of vectors and of subspaces are summed over through `Fintype.ofFinite`.
attribute [local instance low] Fintype.ofFinite

/-- The product of `1 - q ^ l * X` over `0 ≤ l < m`. For `q` the norm of a split place, it is the
Hecke polynomial of the trivial representation in rank `m`. -/
@[simp]
noncomputable abbrev New.SiegelWeil.qPochhammer (q m : ℕ) (X : ℂ) : ℂ :=
  ∏ l ∈ range m, (1 - (q : ℂ) ^ l * X)

/-- The number `(-X) ^ d * q ^ (d choose 2)` attached to a subspace `U` of `k^n` of dimension `d`,
where `q` is the number of elements of `k`. -/
noncomputable abbrev New.heckePolyCoeff {n k : Type*} [Field k] (X : ℂ) (U : Submodule k (n → k)) :
    ℂ :=
  (-X) ^ finrank k U * (Nat.card k : ℂ) ^ (finrank k U).choose 2

open scoped Classical in
/-- The q-binomial theorem for subspaces: for a subspace `W` of `k^n`, with `n` finite and `k` a
field with `q` elements, and for `X : ℂ`, the sum of `(-X) ^ dim U * q ^ (dim U choose 2)`
(`heckePolyCoeff X U`) over the subspaces `U ≤ W` is `∏ l < dim W, (1 - q ^ l * X)`
(`SiegelWeil.qPochhammer q (dim W) X`).

A variant of the finite q-binomial theorem as in Macdonald, with a sum over subspaces in place of
Gaussian binomial coefficients. -/
lemma New.q_binomial_submodule (n k : Type*) [Finite n] [Field k] [Finite k]
    (W : Submodule k (n → k)) (X : ℂ) :
    ∑ U : Submodule k (n → k) with U ≤ W, heckePolyCoeff X U =
      SiegelWeil.qPochhammer (Nat.card k) (finrank k W) X := by
  let q := Fintype.card k
  let d := finrank k W
  let weight (j : ℕ) : ℂ := (-X) ^ j * (q : ℂ) ^ j.choose 2
  -- Submodules below W are the subspaces of W itself.
  have subspaces : (∑ U : Submodule k (n → k) with U ≤ W, heckePolyCoeff X U) =
      ∑ U : Submodule k W, weight (finrank k U) := by
    rw [sum_subtype (p := fun U ↦ U ∈ Set.Iic W) _ (fun U ↦ by simp)]
    symm
    apply Fintype.sum_equiv W.mapIic.toEquiv
    intro T
    change weight (finrank k T) = heckePolyCoeff X (T.map W.subtype)
    unfold heckePolyCoeff
    rw [Nat.card_eq_fintype_card,
      ← (T.equivMapOfInjective W.subtype W.subtype_injective).finrank_eq]
  -- Collect the terms of each dimension and apply the finite q-binomial theorem.
  have ranks (U : Submodule k W) (_ : U ∈ univ) : finrank k U ∈ range (d + 1) :=
    mem_range.mpr (Nat.lt_succ_of_le U.finrank_le)
  rw [subspaces, ← sum_fiberwise_of_maps_to' ranks weight]
  have product := TauCeti.prod_one_add_pow_mul_eq_sum_gaussianBinomial (q : ℂ) (-X) d
  simp only [mul_neg, ← sub_eq_add_neg] at product
  unfold SiegelWeil.qPochhammer
  rw [Nat.card_eq_fintype_card, product]
  apply sum_congr rfl
  intro j _
  rw [sum_const, nsmul_eq_mul, ← Fintype.card_subtype, ← Nat.card_eq_fintype_card,
    TauCeti.card_submodule_finrank_eq_gaussianBinomial]
  rw [show ((TauCeti.gaussianBinomial q d j : ℕ) : ℂ) = TauCeti.gaussianBinomial (q : ℂ) d j
    from TauCeti.map_gaussianBinomial (Nat.castRingHom ℂ) q d j]
  dsimp only [weight]
  ring

end QBinomial

/-! ## Sums over an image grouped by fibres -/

/-- Let `S` be a finite set and `ψ` a map. If for `t ∈ S` the value `F (ψ t)` divided by the size of
the fibre of `ψ` in `S` through `t` is `G t / D`, and `G` has sum zero over `S`, then `F` has sum
zero over `ψ '' S`. -/
lemma New.Variety.finsum_image_eq_zero_of_fibers {T C : Type*} {S : Set T} (hS : S.Finite)
    (ψ : T → C) {G : T → ℂ} {F : C → ℂ} {D : ℂ} (h_sum : ∑ᶠ t ∈ S, G t = 0)
    (h_ratio : ∀ t ∈ S, F (ψ t) / Nat.card {s ∈ S | ψ s = ψ t} = G t / D) :
    ∑ᶠ c ∈ ψ '' S, F c = 0 := by
  classical
  -- Group the sum `∑ G t / D` over `S` by the fibres of `ψ`: the fibre over `c` contributes `F c`.
  lift S to Finset T using hS
  rw_mod_cast [finsum_mem_finset_eq_sum] at h_sum ⊢
  have fibre (t : T) (ht : t ∈ S) : F (ψ t) = ∑ s ∈ S with ψ s = ψ t, G s / D := by
    -- By `h_ratio` the summand is constant on the fibre.
    have const : ∀ s ∈ {s ∈ S | ψ s = ψ t}, G s / D = F (ψ t) / {s ∈ S | ψ s = ψ t}.card := by
      simp +contextual [← h_ratio, ← Set.ncard_coe_finset]
    rw [Finset.sum_eq_card_nsmul const, nsmul_eq_mul,
      mul_div_cancel₀ _ (Nat.cast_ne_zero.2 (Finset.card_ne_zero.2 ⟨t, by simp [ht]⟩))]
  rw [S.sum_image' (fun s ↦ G s / D) fibre, ← S.sum_div, h_sum, zero_div]

/-!
## Schur polynomials in the coefficients of a monic polynomial

A Schur polynomial in `a` variables is symmetric, so it is an integer polynomial in the coefficients
of `∏ (X - r i)`. Here it is defined in that form, without division, for any tuple of exponents
`l : Fin a → ℕ` (classically `l j` is a part of a partition plus `j`).
-/

section SchurPolynomial

open Matrix Polynomial Finset Fin Lagrange

namespace New.Variety

variable {a : ℕ} (l : Fin a → ℕ) {R S : Type} [CommRing R] [CommRing S]
  (r : Fin a → R) (s : Multiset R)

/-- For exponents `l : Fin a → ℕ`, the determinant of the matrix of coefficients of the remainders
of the `X ^ l j` modulo `freeMonic ℤ a`, the generic monic polynomial of degree `a`. It is an
integer polynomial in the `a` generic coefficients. -/
noncomputable def genericSchur : MvPolynomial (Fin a) ℤ :=
  (of fun k j : Fin a ↦ (X ^ l j %ₘ freeMonic ℤ a).coeff k.val).det

/-- Evaluation of an integer polynomial in `a` variables at the coefficients of degree less than `a`
of `∏ (X - t)`, with `t` running over the multiset `s`. Applied to `genericSchur l`, with `s` of
size `a`, it gives the value of the Schur polynomial at the roots. -/
noncomputable def rootCoeffEval : MvPolynomial (Fin a) ℤ →ₐ[ℤ] R :=
  MvPolynomial.aeval (R := ℤ) fun i : Fin a ↦ (s.map fun t : R ↦ X - C t).prod.coeff i

/-- `rootCoeffEval s`, evaluation at the coefficients of `∏ t ∈ s, (X - t)`, commutes with a ring
homomorphism `f`, applied to the roots. -/
lemma rootCoeffEval_map (f : R →+* S) (q : MvPolynomial (Fin a) ℤ) :
    rootCoeffEval (a := a) (s.map f) q = f (rootCoeffEval s q) := by
  rw [rootCoeffEval, rootCoeffEval, MvPolynomial.map_aeval, MvPolynomial.aeval_eq_eval₂Hom,
    RingHom.ext_int (f.comp (algebraMap ℤ R)) (algebraMap ℤ S)]
  simp [← coeff_map, Polynomial.map_multiset_prod]

/-- The bialternant formula over a commutative ring `R`: the Schur polynomial `genericSchur l`,
evaluated at the coefficients of `∏ (X - r i)`, times the Vandermonde determinant of `r` is the
generalised Vandermonde determinant `det (r i ^ l j)`. -/
lemma rootCoeffEval_genericSchur_mul_det :
    rootCoeffEval (univ.val.map r) (genericSchur l) * (vandermonde r).det =
      (of fun i j : Fin a ↦ r i ^ l j).det := by
  nontriviality R
  -- Specialise `freeMonic ℤ a` to `nodal univ r = ∏ (X - r k)` via `φ = rootCoeffEval`.
  let φ := (MvPolynomial.mapEquivMonic ℤ R a).symm (.mk (nodal univ r) nodal_monic (by simp))
  have hφ : (freeMonic ℤ a).map φ = nodal univ r :=
    congrArg Subtype.val ((MvPolynomial.mapEquivMonic ℤ R a).apply_symm_apply _)
  have hφ_eq : rootCoeffEval (univ.val.map r) = φ := MvPolynomial.algHom_ext fun k ↦ by
    simp [rootCoeffEval, φ, MvPolynomial.mapEquivMonic, nodal, ← Fin.prod_ofFn, Function.comp_def]
  rw [hφ_eq, genericSchur, mul_comm, AlgHom.map_det, ← det_mul]
  refine congrArg det (Matrix.ext fun i j ↦ ?_)
  -- Each entry `(i, j)` evaluates `X ^ l j %ₘ freeMonic ℤ a` at `r i`, giving `r i ^ l j`.
  trans (X ^ l j %ₘ freeMonic ℤ a).eval₂ φ (r i)
  · conv_rhs => rw [← sum_modByMonic_coeff (monic_freeMonic ℤ a) (degree_freeMonic ℤ a).le]
    simp [Matrix.mul_apply, mul_comm, eval₂_finsetSum]
  · rw [eval₂_modByMonic_eq_self_of_root (by simp [eval₂_eq_eval_map, hφ, eval_nodal_at_node]),
      eval₂_X_pow, of_apply]

end New.Variety

end SchurPolynomial

/-! ## Extracting Schur polynomials from vanishing linear forms -/

section SchurExtraction

open NumberField Matrix Submodule Polynomial Finset Lagrange Multiset Set SetLike Fintype

namespace New.Variety

variable {a : ℕ} {ι S K R : Type _} [Fintype S] [Field K] [CommRing R] [Algebra K R]

/-- Lagrange interpolation of `X ^ j`, for `j < a`, at distinct nodes `r₁, …, r_a`, evaluated at a
polynomial `t`. -/
lemma sum_aeval_lagrange_basis_mul_C_pow (r : Fin a ↪ K) (t : K[X]) (j : Fin a) :
    ∑ k : Fin a, aeval t (Lagrange.basis Finset.univ r k) * C (r k) ^ j.val = t ^ j.val := by
  have h_pow : (X : K[X]) ^ j.val = ∑ k, Lagrange.basis univ r k * C (r k) ^ j.val := by
    simpa [mul_comm] using eq_interpolate (f := X ^ j.val) (s := univ) r.injective.injOn (by simp)
  simpa using congrArg (aeval t) h_pow.symm

/-- For distinct `r₁, …, r_a` in a field `K` and exponents `l : Fin a → ℕ`, the identity `∑ᵢ
∏_{k ≠ i} (X rᵢ - r_k) / (rᵢ - r_k) · s_l(r₁, …, X rᵢ, …, r_a) = s_l(r) · ∑ⱼ X ^ l j` holds in
`K[X]`. Here `s_l(r)` is `genericSchur l` evaluated by `rootCoeffEval` at the coefficients of
`∏ (T - r_k)`. This is the determinant of the coefficients of the remainders of the `X ^ l j` modulo
that product, so the exponents `l j` play the role of the alternant exponents `λ_j + a - j` of a
Schur polynomial, not of a partition `λ`. -/
lemma sum_lagrange_smul_rootCoeffEval (l : Fin a → ℕ) (r : Fin a ↪ K) :
    ∑ i : Fin a, aeval (X * C (r i)) (Lagrange.basis Finset.univ r i) •
        rootCoeffEval (univ.val.map fun k : Fin a ↦ (if k = i then X else 1) * C (r k))
          (genericSchur l) =
      C (rootCoeffEval (univ.val.map r) (genericSchur l)) * ∑ j : Fin a, X ^ l j := by
  -- Multiply by the Vandermonde determinant of `r` and use the bialternant formula.
  refine mul_right_cancel₀ (b := (vandermonde (C ∘ r)).det)
    (det_vandermonde_ne_zero_iff.2 (C_injective.comp r.injective)) ?_
  -- The image of the bialternant formula under `C`.
  have h_schur : C (rootCoeffEval (univ.val.map r) (genericSchur l)) * (vandermonde (C ∘ r)).det =
      (of fun k j : Fin a ↦ C (r k) ^ l j).det := by
    simpa [← rootCoeffEval_map, Function.comp_def] using
      rootCoeffEval_genericSchur_mul_det l (C ∘ r)
  -- By Lagrange interpolation, the row of `X * r i` is the combination of the rows of the `r k`
  -- with coefficients `basis k (X * r i)`; only `k = i` counts in the determinant.
  have replace_row (i : Fin a) :
      aeval (X * C (r i)) (Lagrange.basis univ r i) • (vandermonde (C ∘ r)).det =
        (vandermonde fun k ↦ (if k = i then X else 1) * C (r k)).det := by
    rw [← det_updateRow_sum _ i fun k ↦ aeval (X * C (r i)) (Lagrange.basis univ r k)]
    congr 1
    ext k j : 1
    by_cases hk : k = i <;> simp [hk, sum_aeval_lagrange_basis_mul_C_pow, Finset.sum_apply]
  -- So each term on the left becomes a generalised Vandermonde determinant with one row changed.
  let A := of fun k j : Fin a ↦ C (r k) ^ l j
  have h_left (i : Fin a) : aeval (X * C (r i)) (Lagrange.basis univ r i) •
      rootCoeffEval (univ.val.map fun k : Fin a ↦ (if k = i then X else 1) * C (r k))
        (genericSchur l) * (vandermonde (C ∘ r)).det =
      (A.updateRow i fun j ↦ X ^ l j * A i j).det := by
    rw [smul_mul_assoc, ← mul_smul_comm, replace_row, rootCoeffEval_genericSchur_mul_det]
    congr 1
    ext k j : 1
    by_cases hk : k = i
    · subst k
      simpa [A, Matrix.updateRow_apply, mul_pow] using
        (mul_comm (C (r i) ^ l j) ((X : K[X]) ^ l j))
    · simp [A, Matrix.updateRow_apply, hk]
  rw [sum_mul, mul_right_comm, h_schur, Finset.sum_congr rfl fun i _ ↦ h_left i,
    Matrix.sum_det_updateRow_mul_row, mul_comm]

open MvPolynomial RingOfIntegers Finsupp

/-- For a number field `E` and a type `ι`, the doubled coordinate functions `α ↦ σ (2 * α i)` on
`(𝓞 E)^ι`, indexed by the pairs `(i, σ)` of an index `i: ι` and an embedding `σ` of `E` in `ℂ`, are
algebraically independent over `ℂ`. -/
lemma algebraicIndependent_embedding_two_mul {E : Type*} [Field E] [NumberField E] :
    AlgebraicIndependent ℂ fun (p : ι × (E →+* ℂ)) (α : ι → 𝓞 E) ↦ p.2 (2 * α p.1 : 𝓞 E) := by
  -- Write `αᵢ` in an integral basis of `𝓞 E`. A relation `P` becomes a polynomial in the
  -- coordinates that vanishes at all natural numbers, hence is zero; the change of variables is
  -- invertible over `ℂ` because the embedded integral basis `b` is a basis of `(E →+* ℂ) → ℂ`.
  refine algebraicIndependent_iff.2 fun P hP ↦ ?_
  let I : Type _ := Module.Free.ChooseBasisIndex ℤ (𝓞 E)
  let b : Module.Basis I ℂ ((E →+* ℂ) → ℂ) := canonicalEmbedding.latticeBasis E
  -- `coord (i, σ)` is `σ (2 αᵢ)` as a linear form in the coordinates of `αᵢ`.
  let coord : ι × (E →+* ℂ) → MvPolynomial (ι × I) ℂ :=
    fun (i, σ) ↦ 2 • ∑ k : I, .X (i, k) * .C (b k σ)
  have h_nat (z : ι × I → ℕ) :
      MvPolynomial.aeval (fun p ↦ (z p : ℂ)) (MvPolynomial.aeval coord P) = 0 := by
    let α (i : ι) : 𝓞 E := ∑ k : I, (z (i, k) : 𝓞 E) * basis E k
    have hPα : MvPolynomial.aeval (fun p : ι × (E →+* ℂ) ↦ p.2 (2 * α p.1 : 𝓞 E)) P = 0 := by
      simpa [comp_aeval_apply] using congrArg (Pi.evalAlgHom ℂ _ α) hP
    have hb (k : I) (σ : E →+* ℂ) : b k σ = σ (basis E k) := by simp [b, I]
    simpa [comp_aeval_apply, α, hb, coord, two_mul] using hPα
  have h_zero : MvPolynomial.aeval coord P = 0 := by
    refine funext_set (fun _ ↦ Set.range (Nat.cast : ℕ → ℂ))
      (fun _ ↦ infinite_range_of_injective Nat.cast_injective) fun x hx ↦ ?_
    choose z hz using fun p : ι × I ↦ hx p (Set.mem_univ p)
    rw [← _root_.funext hz, ← aeval_eq_eval, _root_.map_zero]
    exact h_nat z
  -- To evaluate `P` at `v`, take as coordinates those of `v (i, ·) / 2` in the basis `b`.
  refine MvPolynomial.funext fun v ↦ ?_
  let y (p : ι × I) : ℂ := b.repr (fun σ ↦ v (p.1, σ) / 2) p.2
  have h_coord (p : ι × (E →+* ℂ)) : MvPolynomial.aeval y (coord p) = v p := by
    have h_repr : ∑ k : I, y (p.1, k) * b k p.2 = v p / 2 := by
      simpa [y] using congrFun (b.sum_repr fun σ ↦ v (p.1, σ) / 2) p.2
    simp [coord, two_mul, h_repr]
  simpa [comp_aeval_apply, h_coord] using congrArg (MvPolynomial.aeval y) h_zero

/-- If a linear form kills the products of `1 - c (i, σ) α * t` for every `α`, algebraic
independence of the functions `c (i, σ)` forces it to kill each product of signed elementary
symmetric functions. These products are the coefficients of the expanded family. -/
lemma map_prod_esymm_eq_zero [Fintype ι] {A : Type*} {c : ι × S → A → K}
    (hc : AlgebraicIndependent K c) {J : Type*} {x : J → S → Multiset R}
    (hx : ∀ (j : J) (σ : S), (x j σ).card = a) (L : (J → R) →ₗ[K] K)
    (hL : ∀ α : A, L (fun j : J ↦
      ∏ i : ι, ∏ σ : S, ((x j σ).map fun t : R ↦ 1 - algebraMap K R (c (i, σ) α) * t).prod) = 0)
    (y : ι × S → Fin a.succ) :
    L (∏ p : ι × S, fun j : J ↦ (-1) ^ (y p).val * (x j p.2).esymm (y p)) = 0 := by
  classical
  let e (σ : S) (k : Fin a.succ) (j : J) : R := (-1) ^ k.val * (x j σ).esymm k
  -- Vieta's formula at `X = 1` for the multiset `b • x j σ`.
  have vieta (j : J) (σ : S) (b : K) :
      ((x j σ).map fun t ↦ 1 - b • t).prod = ∑ k : Fin a.succ, b ^ k.val • e σ k j := by
    simpa [eval_multiset_prod, sum_range, eval_finsetSum, hx, ← pow_smul_esymm] using
      congrArg (Polynomial.eval 1) ((x j σ).map fun t ↦ b • t).prod_X_sub_X_eq_sum_esymm
  have expand (α : A) :
      L (∑ y : ι × S → Fin a.succ, (∏ p, c p α ^ (y p).val) • ∏ p, e p.2 (y p)) = 0 := by
    rw [← hL α]
    refine congrArg L (_root_.funext fun j ↦ ?_)
    simp_rw [← Algebra.smul_def, vieta, ← prod_prod_type']
    simp [prod_univ_sum, prod_smul]
  -- The expanded relation is a linear combination of distinct monomials in the `c (i, σ)`.
  let expo (y : ι × S → Fin a.succ) : ι × S →₀ ℕ := equivFunOnFinite.symm (Fin.val ∘ y)
  have indep : LinearIndependent K fun y : ι × S → Fin a.succ ↦
      MvPolynomial.aeval c (monomial (expo y) (1 : K)) :=
    ((basisMonomials (ι × S) K).linearIndependent.map_injOn (MvPolynomial.aeval c).toLinearMap
      hc.injOn).comp expo (equivFunOnFinite.symm.injective.comp Fin.val_injective.comp_left)
  refine Fintype.linearIndependent_iff.1 indep (fun y ↦ L (∏ p, e p.2 (y p))) ?_ y
  ext α
  simpa [expo, MvPolynomial.aeval_monomial, mul_comm] using expand α

/-- Evaluating a polynomial of total degree at most `n` at the root coefficients gives an
element of the `n`th power of the span of the signed elementary symmetric functions. The
zeroth elementary symmetric function supplies `1`, so monomials of smaller degree can be padded. -/
lemma rootCoeffEval_mem_pow_span_esymm {J : Type*} {x : J → Multiset R}
    (hx : ∀ j : J, (x j).card = a) {q : MvPolynomial (Fin a) ℤ} {n : ℕ}
    (h_deg : q.totalDegree ≤ n) :
    (fun j ↦ rootCoeffEval (x j) q) ∈
      (span K (.range fun k : Fin a.succ ↦ fun j : J ↦ (-1) ^ k.val * (x j).esymm k)) ^ n := by
  classical
  let e (k : Fin a.succ) (j : J) : R := (-1) ^ k.val * (x j).esymm k
  let M : Submodule K (J → R) := span K (.range e)
  have one_le_M : 1 ≤ M :=
    one_le.2 (subset_span ⟨0, _root_.funext fun j ↦ by simp [e, Multiset.esymm]⟩)
  have eval_eq : (fun j ↦ rootCoeffEval (x j) q) =
      ∑ d ∈ q.support, q.coeff d • ∏ k : Fin a, e k.castSucc.rev ^ d k := by
    ext j
    simp [rootCoeffEval, aeval_eq_eval₂Hom, eval₂_eq', prod_X_sub_C_coeff, hx, e]
  change (fun j ↦ rootCoeffEval (x j) q) ∈ M ^ n
  rw [eval_eq]
  refine sum_mem fun d hd ↦ zsmul_mem ?_ _
  have monomial_mem : ∏ k : Fin a, e k.castSucc.rev ^ d k ∈ M ^ ∑ k, d k := by
    simpa using prod_pow_mem_graded (fun m : ℕ ↦ M ^ m) 1 (fun k : Fin a ↦ e k.castSucc.rev) d
      (by simp [M, mem_span_of_mem])
  exact pow_le_pow_right' one_le_M
    (by simpa [sum_fintype] using (le_totalDegree hd).trans h_deg) monomial_mem

/-- Let the functions `c (i, σ) : A → K` be algebraically independent over `K`, let each polynomial
`q σ` have total degree at most `card ι`, and let each multiset `x j σ` have `a` elements. If a
linear form `L` kills the family `j ↦ ∏_{i, σ} ∏_{t ∈ x j σ} (1 - c (i, σ) α * t)` for every `α`,
then it kills `j ↦ ∏_σ rootCoeffEval (x j σ) (q σ)`, where `rootCoeffEval (x j σ)` evaluates at the
coefficients of `∏_{t ∈ x j σ} (X - t)`. -/
lemma map_prod_rootCoeffEval_eq_zero [Fintype ι] {A : Type*} {q : S → MvPolynomial (Fin a) ℤ}
    (h_deg : ∀ σ : S, (q σ).totalDegree ≤ Fintype.card ι) {c : ι × S → A → K}
    (hc : AlgebraicIndependent K c) {J : Type*} {x : J → S → Multiset R}
    (hx : ∀ (j : J) (σ : S), (x j σ).card = a) (L : (J → R) →ₗ[K] K)
    (hL : ∀ α : A, L (fun j : J ↦
      ∏ i : ι, ∏ σ : S, ((x j σ).map fun t : R ↦ 1 - algebraMap K R (c (i, σ) α) * t).prod) = 0) :
    L (fun j : J ↦ ∏ σ : S, rootCoeffEval (x j σ) (q σ)) = 0 := by
  classical
  let e (σ : S) (k : Fin a.succ) (j : J) : R := (-1) ^ k.val * (x j σ).esymm k
  let M (σ : S) : Submodule K (J → R) := span K (.range (e σ))
  -- Coefficient extraction puts the product of the spans in the kernel of `L`.
  have le_ker : ∏ σ : S, ∏ _ : ι, M σ ≤ L.ker := by
    rw [← prod_prod_type_right' fun (_ : ι) (σ : S) ↦ M σ]
    simpa [M, e, prod_span, span_le, ← image_fintype_prod_pi, ← range_piMap,
      range_subset_iff] using map_prod_esymm_eq_zero hc hx L hL
  -- The degree bound puts each evaluated polynomial in the corresponding power of its span.
  have eval_mem (σ : S) : (fun j ↦ rootCoeffEval (x j σ) (q σ)) ∈ ∏ _ : ι, M σ := by
    simpa only [M, e, Finset.prod_const, Finset.card_univ] using
      rootCoeffEval_mem_pow_span_esymm (K := K) (fun j ↦ hx j σ) (h_deg σ)
  simpa [prod_fn] using le_ker
    (Finset.prod_hom_rel (r := fun f N ↦ f ∈ N) ⟨1, by simp⟩ fun σ _ _ ↦ mul_mem_mul (eval_mem σ))

end New.Variety

end SchurExtraction