Skip to content

The Big-Cell Kloosterman Sieve and Remaining-Term Link Bounds ​

This page explains the two analytic engines feeding Moments.lean — src/New/Spanning/MainTerm/EnergyEstimate.lean (04_spanning/energy_estimate, 15 declarations, 3 let-in-type stub truncations documented in full below) and src/New/Spanning/RemainingTerms/Sum.lean (04_spanning/remaining_terms_sum, 26 declarations, 0 stub truncations) — together with their upstream foundations in MainTerm/GlobalSieve.lean, RemainingTerms/SiegelLemma.lean, and RemainingTerms/SchurTest.lean. Return to the Stage 04 Overview, or revisit Target Dimension, Multiplicity Equality & Spanning and Relative-Trace Unfolding & Second Moments.

Level 1 · First-Principles

Level 1 — First-Principles ​

To prove that the whole-group second moment of Ps=P∗ρ(s)P overshoots the baseline Dmain by no more than (1+9b−4), Moments.lean cannot afford a loose constant factor anywhere. Instead, it splits all rational elements γ outside the Bessel subgroup along a sharp geometric dividing line and feeds each side into its own specialized analytic engine:

Side-by-side split diagram of the two Stage 04 analytic engines feeding Moments.lean: Left lane Main Term via generic cell reductions and Poisson summation; Right lane Remaining Terms via InSameLinkClass branching and sublattice counting

Left lane: The Main-Term Engine (EnergyEstimate.lean + GlobalSieve.lean) ​

When a finite-prime reduction s∈G¯ is an open reduction whose leading frame-product determinants do not vanish modulo a chosen place above p0Kloosterman sieve, every rational term γ sitting over (c,s,c′) automatically lands in the generic big cell (IsOpenElement.leadingMinor_ne_zero). In the big cell, every term factors cleanly as a Weyl head wp (carrying ϱ rational unit coordinates p0,…,pϱ−1 and a final coordinate t) times a floor-group element σ.

The Kloosterman sieve bounds the squared norm of these big-cell cut Bessel orbital amplitude sumsBessel orbital integral with sharp leading constant 1+b−4 in two moves:

  1. Siegel's step: At the infinite places, the Gram matrix of weighted cut orbital integrals matches a positive-semidefinite band-limited kernel bandLimit n. At the finite places T (covering the level primesprime number M,N and auxiliary places), Siegel's mass formula turns the sum of squared coset amplitudes into a Hermitian pairing of bandLimit n against a finite-place Kloosterman density lastEntryDensity. By the product formula matching archimedean sizes against finite-place moduli on unitsarithmetic height, all powers of the head coordinates pa cancel cleanly between the infinite and finite factors.
  2. Entry-by-entry one-sided Poisson summation: Peeling off one head coordinate at a time via one-sided Poisson summation (GlobalSieve.lean) replaces the discrete rational sum by a nested hierarchy of positive-semidefinite integrals plus a tiny nonzero-frequency tail. Collecting all factors (sieve_constant_le) bounds the open-cell link second moment by(1+b−4)b−6k|Sg|Dmainν2(linkSecondMoment_isOpenElement_le),gaining an extra factor b−6k for every place in Sg where s fixes a frame vector.

Right lane: Remaining-Term Sublattice Bounds (RemainingTerms/Sum.lean) ​

The left lane bounds only one link at a time and only on open reductions. Everything left over—cross-terms between different links, terms where the discriminant g=|Δ|2−N2|Δ′|2 vanishes, and reductions s that fail to be open because the frame span meets its s-image modulo some prime above M—is routed to RemainingTerms/Sum.lean.

To every term γ, Stage 04 attaches its Hermitian sublattice built from pairs (t,γ−1t) in the middle quotient X⊥/Xlink lattice. For any pair (γ,γ′) sitting over the same block (c,s,c′), their intersection Λγ∩Λγ′ is their common link, with pair discriminant d (measuring its squared fundamental volumeGram determinant). The engine branches on whether γ and γ′ lie in the same non-degenerate link class (InSameLinkClass):

  • Cross-link or g=0 pairs (¬InSameLinkClass): Sharing the same mod-M reduction s forces a congruence saving (2/M)2if in d2 whenever the links differ in codimension i≥1 (pairDiscriminant_sq_le). Combining the weighted Schur test (bounding each orbit's termSize in terms of its level gauge G−k/2) with Bombieri–Vaaler Siegel's lemma (counting all sublattices of corank l≤n3 and bounded discriminant) crushes all cross-link and g=0 pairs below b−kfDid (sum_termSize_mul_not_inSameLinkClass_le ⇒ secondMoment_remainingTerms_le).
  • Same-link g≠0 pairs on meeting reductions (InSameLinkClass with meetNorm s ≥ z): When s fails to be open, the product of norms of places where the frame collides with its s-image gives the frame-meeting norm S.meetNorm s≥z>0. The same lattice-counting engine extracts a factor (b2f/z)k (sum_termSize_mul_inSameLinkClass_le ⇒ linkSecondMoment_le_of_le_meetNorm), crushing non-open reductions far below Dmain.

Where this analogy breaks ​

Drawing the main term and remaining terms as two symmetric lanes hides a fundamental asymmetry in how they win. The Kloosterman sieve (left lane) must preserve the exact leading constant 1 (losing at most b−4), so it uses genuine Fourier duality (one-sided Poisson summation) on positive-semidefinite band-limited kernels where the zero frequency matches Dmain on the nose. By contrast, Remaining Terms (right lane) uses no phase cancellation between pairs at all—it applies the triangle inequality to bound every cross-term by positive absolute values termSize γ * termSize γ', winning solely because the congruence and frame-meeting savings (2/M)2if and z−1 are raised to the huge rank exponent k, overwhelming the lattice-counting zeta sum.

Level 2 · Undergrad Bridge

Level 2 — Undergrad Bridge ​

1. Main Term: Big-Cell Kloosterman Sieve (EnergyEstimate.lean + GlobalSieve.lean) ​

  1. Open reductions force the big cell (leadingMinor_frameGram_map, exists_leadingMinor_reduceAt_eq, IsOpenElement.leadingMinor_ne_zero): Leading minors of frameGram commute with ring maps, so for any γ∈S.termsOver c s c′, the l-th leading minor of S.frameProducts γ is integral and reduces at every chosen place w to the l-th leading minor of frameGram (s i w). If s is open (S.IsOpenElement s—all proper leading minors are nonzero at some chosen place above p0), then leadingMinor(S.frameProducts γ,l)≠0 for all l<n.
  2. Archimedean Gram matrix and product-formula cancellation (prod_bandLimit_eq_gram, gramScalar_mul_headDensity): Fix a star-stable finite set of places T off which M−1,N−1, the lattice basis, and head units T0⊂E× are integral, a floor-group element σ∈floorGroup ϱ with last frame product t (|Φv(t)|2>N2 for all v∣∞), and scaled archimedean head coordinates xv,p,a=frameScaleSq(v,a)⋅Φv(padTuple(p,t)a) with frameScaleSq(v,a)=κv2(ϱ−a)/N.
    • prod_bandLimit_eq_gram identifies the matrix Rp,q=∏v∣∞(S.besselSystem v).bandLimit n (xv,p) (xv,q) as Matrix.gram ℂ of the cut Bessel orbital integrals at γ=wpσ, weighted by the scalar ρ(t,p).
    • gramScalar_mul_headDensity multiplies ρ(t,p) by the finite-place head density G.headDensity ϱ at T: by the global product formula (|pa|T1/2=∏v∣∞|Φv(pa)|−1), every power of pa cancels identically, leaving r⋅∏v(|Φv(t)|2−N2)k−1 where r=S.normalizingConst(k−1)>0 (normalizingConst_sq_pos).
  3. Siegel's step (IsFillingData.mul_sum_norm_sum_cosetAmplitude_sq_le): Grouping distinct tuples (ci,ci′,red(ni),σi) by their last entry ti and applying MainTerm/SiegelTopBound.lean boundsr2∑i‖∑p:Finϱ→T0S.cosetAmplitude .cut ci si ci′ (wp,tiσi)‖2≤(1+b−6)S.scaledSiegelConst⋅Re∑t′,p,qRp,q(t′)G.lastEntryDensity(yp,t′,yq,t′)Y.massRatio.
  4. One-sided Poisson summation (GlobalSieve.lean::sieve) and sharp constant assembly (prod_poissonConst_eq, scaledSiegelConst_mul_decayConst_le, sieve_constant_le): The finite-place Kloosterman densities form a SieveSystem of mass ≤(1+b−6)b−6k|Sg| when Y fixes a frame vector Dw for each w∈Sg above p0. Multiplying by the archimedean bandLimit systems (mass ≤(1+b−10)/degv) and running entry-by-entry one-sided Poisson summation (densitySum_succ_le_mul_densitySum_add → sieve) bounds the right-hand side by(∏i<nS.poissonConst i)((∏v1+b−10degv)1+b−6b6k|Sg|+b2403n9fS.decayConst).By prod_poissonConst_eq, ∏i<nS.poissonConst i=r2⋅vol(O^E)n(|S.BesselCoord|/Λ)2/cGf. Absorbing the frequency-decay error into b−10Dmain (scaledSiegelConst_mul_decayConst_le) and combining (1+b−6)((1+b−9)2(1+b−6)+b−10)≤1+b−4 (one_add_inv_pow_ten_pow_le, one_add_pow_six_mul_add_pow_ten_le_one_add_pow_four) gives sieve_constant_le. Dividing by r2>0 yields sum_norm_sum_cosetAmplitude_sq_le and, summing over all links, New.Filling.linkSecondMoment_isOpenElement_le:linkSecondMoment {γ∣g(γ)≠0} {s∈S.fixer Sg D∣S.IsOpenElement s}≤(1+b−4)b−6k|Sg|Dmainν2.
  1. Near pairs and discriminant compression (Sum.lean, lines 59–147): For any near pair (γ,γ′) over an agreeing block (c,s,c′) (IsNearPairOverAgreeingBlock):
    • 1≤d:=S.pairDiscriminant c c′ γ γ′ (one_le_pairDiscriminant);
    • letting i=S.linkCorank γ γ′ be the codimension of commonLink γ γ' in each link, pairDiscriminant_sq_le givesd2≤(2M)2ifG(γ)G(γ′);
    • corank_le_and_pairDiscriminant_le bounds both the corank l=k−dimE⁡(commonLink γ γ′)≤n3 and the discriminant d≤S.discriminantBound=bn3f (mem_boundedDiscNearPairs).
  2. Weighted Schur test + Bombieri–Vaaler Siegel's lemma (SchurTest.lean, SiegelLemma.lean, Sum.lean:149–305):
    • SchurTest.lean::amplitudeMajorant_sq_le bounds each orbit's amplitude majorant by Cauchy–Schwarz with the inverting schurWeight (νv−(k+i)), feeding termSize_sq_le: termSize(c,c′,γ)2≤τ4D/(npG(γ)k).
    • Whenever (dη)2≤G(γ)G(γ′) and τl+6Dη−k≤B, each pair contributes at most Bd−k/(τl+2np) (termSize_mul_le, ofReal_termSize_mul_le).
    • Summing d−k over all Hermitian sublattices of corank l≤n3 via SiegelLemma.lean::tsum_sublatticeDiscriminant_inv_le (Bombieri–Vaaler Siegel's lemma cuts out each codimension-s subspace by s short vectors) and cube_add_one_le_tailScale (n3+1≤τ) proves the master template sum_termSize_mul_le: total pair-size sum ≤τB.
  3. Branching on InSameLinkClass (Sum.lean, lines 307–837):
    • Not in the same link class (sum_termSize_mul_not_inSameLinkClass_le): If link γ ≠ link γ' (i≥1), take η=(M/2)if and D=Dmain (cellRankSecondMoment_le_mainSecondMoment, pow_mul_mainSecondMoment_div_le); if g=0 for either term, its cell rank drops below the top cell. Either way, sum_termSize_mul_le yields total sum ≤b−kfDid.
    • Reduction to one link (enorm_amplitudeSum_mul_le, enorm_amplitudeSum_sq_le ⇒ secondMoment_remainingTerms_le): Partitioning any bi-unipotent-stable subset T⊆Γ∗ by Piece (each link Λ with g≠0, plus the g=0 piece) isolates the diagonal same-link squares from cross-link and g=0 pairs, proving:linkSecondMoment {γ∣g(γ)≠0} Ω≤wν2⟹secondMoment(S.amplitudeSum .cut Γ∗) Ω≤w+Didbkf.
    • Same link class with meeting norm (sum_termSize_mul_inSameLinkClass_le ⇒ linkSecondMoment_le_of_le_meetNorm): For pairs with InSameLinkClass γ γ' over reductions s∈Ω satisfying z ≤ S.meetNorm s (z≠0), taking η∝z/b2f inside sum_termSize_mul_le bounds both the pair sum by (b2f/z)kDmain and the link second moment bylinkSecondMoment {γ∣g(γ)≠0} Ω≤(b2fz)kDmainν2.
Level 3 · Formal Lean Contract

Level 3 — Formal Lean Contract ​

The extracted skeletons skeleton/04_spanning/energy_estimate.lean (15 declarations, 3 stub truncations) and skeleton/04_spanning/remaining_terms_sum.lean (26 declarations, 0 stub truncations) mirror src/New/Spanning/MainTerm/EnergyEstimate.lean and src/New/Spanning/RemainingTerms/Sum.lean at pinned upstream commit 41c2716658c42ba08eb0648994a2efe83082a95c.

Critical Honesty Disclosure: Three let-in-Type Stub Truncations in energy_estimate.lean ​

rh-extract splits declaration signatures from proof bodies at the first top-level (depth-0) := token. Three intermediate lemmas in src/New/Spanning/MainTerm/EnergyEstimate.lean use let ... := bindings inside their return type, causing the extracted stubs in skeleton/04_spanning/energy_estimate.lean at L127 (gramScalar_mul_headDensity), L145 (prod_bandLimit_eq_gram), and L180 (IsFillingData.mul_sum_norm_sum_cosetAmplitude_sq_le) to truncate immediately at that first let ... := binding (replaced by := by sorry). For complete mathematical accuracy, their exact untruncated statements from upstream src/New/Spanning/MainTerm/EnergyEstimate.lean:371–510 (41c2716658c4) are quoted verbatim below:

lean
-- Upstream: src/New/Spanning/MainTerm/EnergyEstimate.lean:371-386
-- (truncated at `let x ... :=` in skeleton/04_spanning/energy_estimate.lean:127)
lemma gramScalar_mul_headDensity
    [S.IsAdmissible] {T : Finset (FinPlace E)} [T.StarStable] {P : Floors.IntegralPlace (LocProd T)}
    {G : Floors.PlaceData (Fin (𝔰.k - (6 * 𝔰.ϱ + 13))) (S.latticeMiddle (LocProd T))
      (𝔰.ϱ + 1 + 2 * 𝔰.ϱ + 5)} {kPred : ℕ} (hk : 𝔰.k = kPred + 1)
    {T₀ : Finset Eˣ} (hT₀ : ∀ x ∈ T₀, x.val ∈ ratIntegralOff T ∧ x⁻¹.val ∈ ratIntegralOff T)
    {t : Eˣ} (h_large : ∀ v : NumberField.InfinitePlace E, S.N ^ 2 < ‖Φ v t.val‖ ^ 2)
    (p : Fin 𝔰.ϱ → T₀) :
    let x (v : NumberField.InfinitePlace E) (a : ℕ) : ℂˣ :=
      unitOrOne (S.frameScaleSq v a * Φ v (padTuple (fun b : Fin 𝔰.ϱ ↦ (p b).val) t a).val)
    (∏ v : NumberField.InfinitePlace E, √𝔰.openCellConst *
        √(‖(x v 𝔰.ϱ).val‖ ^ 2 - 1) ^ (𝔰.k - 1) / Fintype.card (S.besselSystem v).Index *
        ∏ a ∈ Finset.range 𝔰.ϱ, ‖(x v a).val‖ ^ (𝔰.k + 1 + 2 * (𝔰.ϱ - (a + 1)))) *
      (G.headDensity 𝔰.ϱ (Units.map (ratToPlaces T) ∘ padTuple (fun b : Fin 𝔰.ϱ ↦ (p b).val) t)
        1).toReal =
      S.normalizingConst kPred *
        √((∏ v : NumberField.InfinitePlace E, (‖Φ v t.val‖ ^ 2 - S.N ^ 2)) ^ (𝔰.k - 1))

-- Upstream: src/New/Spanning/MainTerm/EnergyEstimate.lean:425-438
-- (truncated at `let x ... :=` in skeleton/04_spanning/energy_estimate.lean:145)
lemma prod_bandLimit_eq_gram {T₀ : Finset Eˣ} {σ : S.G E} {t : Eˣ}
    (hσ : σ ∈ Shape.Form.floorGroup 𝔰.ϱ) (h_tail : S.frameProducts σ 𝔰.top 𝔰.top = t) :
    let x (v : NumberField.InfinitePlace E) (p : Fin 𝔰.ϱ → T₀) (a : ℕ) : ℂˣ :=
      unitOrOne (S.frameScaleSq v a * Φ v (padTuple (fun b : Fin 𝔰.ϱ ↦ (p b).val) t a).val)
    let R : Matrix (Fin 𝔰.ϱ → T₀) (Fin 𝔰.ϱ → T₀) ℂ := fun p q : Fin 𝔰.ϱ → T₀ ↦
      ∏ v : NumberField.InfinitePlace E, (S.besselSystem v).bandLimit 𝔰.n (x v p) (x v q)
    R = Matrix.gram ℂ fun p : Fin 𝔰.ϱ → T₀ ↦
      (∏ v : NumberField.InfinitePlace E, √𝔰.openCellConst *
          √(‖(x v p 𝔰.ϱ).val‖ ^ 2 - 1) ^ (𝔰.k - 1) / Fintype.card (S.besselSystem v).Index *
          ∏ a ∈ Finset.range 𝔰.ϱ, ‖(x v p a).val‖ ^ (𝔰.k + 1 + 2 * (𝔰.ϱ - (a + 1)))) •
        besselOrbitalIntegral volume
          (fun g : NumberField.InfinitePlace E → 𝔰.G₁ ↦ WithLp.toLp 2 (S.besselFn .cut g))
          (S.ratToInf
            (Floors.FloorGroups.weylElem 𝔰.ϱ (padTuple (fun a : Fin 𝔰.ϱ ↦ (p a).val) t) * σ))

-- Upstream: src/New/Spanning/MainTerm/EnergyEstimate.lean:482-510
-- (truncated at `let r : ℝ :=` in skeleton/04_spanning/energy_estimate.lean:180)
lemma IsFillingData.mul_sum_norm_sum_cosetAmplitude_sq_le [S.IsAdmissible] {T : Finset (FinPlace E)}
    [T.StarStable] [Fact (S.ideleM⁻¹.val ∈ integralOff T)] {P : Floors.IntegralPlace (LocProd T)}
    {G : Floors.PlaceData (Fin (𝔰.k - (6 * 𝔰.ϱ + 13))) (S.latticeMiddle (LocProd T))
      (𝔰.ϱ + 1 + 2 * 𝔰.ϱ + 5)} (hG : S.IsFillingData T G) (Y : G.IntermediateGroup)
    {kPred : ℕ} (hk : 𝔰.k = kPred + 1) {ι : Type} [Fintype ι] [DecidableEq Eˣ]
    {c c' : ι → S.Classes} {σ : ι → S.G E} {n : ι → S.latticeStabilizer} {t : ι → Eˣ}
    (h_inj : (fun i : ι ↦ (c i, c' i, S.reduction (n i), σ i)).Injective)
    (hσ : ∀ i : ι, σ i ∈ Shape.Form.floorGroup 𝔰.ϱ)
    (h_tail : ∀ i : ι, S.frameProducts (σ i) 𝔰.top 𝔰.top = t i)
    (h_large : ∀ (i : ι) (v : NumberField.InfinitePlace E), S.N ^ 2 < ‖Φ v (t i).val‖ ^ 2)
    (hn_mem_Y : ∀ i : ι, S.toPlaces T (n i) ∈ Y.val) {T₀ : Finset Eˣ}
    (hT₀ : ∀ x ∈ T₀, x.val ∈ ratIntegralOff T ∧ x⁻¹.val ∈ ratIntegralOff T)
    (hT_basis : S.latticeBasis ∈ intGL 𝔰.BesselIndex (integralOff T))
    (hT_N : (S.N : E)⁻¹ ∈ ratIntegralOff T)
    (h_off : ∀ i : ι, S.IsIntegralOff T (S.translateByClassReps (c i) (c' i) (σ i))) :
    let r : ℝ := S.normalizingConst kPred
    let x (v : NumberField.InfinitePlace E) (p : Fin 𝔰.ϱ → T₀) (t : Eˣ) (a : ℕ) : ℂˣ :=
      unitOrOne (S.frameScaleSq v a * Φ v (padTuple (fun b : Fin 𝔰.ϱ ↦ (p b).val) t a).val)
    let y (p : Fin 𝔰.ϱ → T₀) (t : Eˣ) : ℕ → (LocProd T)ˣ :=
      Units.map (ratToPlaces T) ∘ padTuple (fun a : Fin 𝔰.ϱ ↦ (p a).val) t
    r ^ 2 * ∑ i : ι, ‖∑ p : Fin 𝔰.ϱ → T₀, S.cosetAmplitude .cut (c i) (S.reduction (n i)) (c' i)
        (Floors.FloorGroups.weylElem 𝔰.ϱ (padTuple (fun a : Fin 𝔰.ϱ ↦ (p a).val) (t i)) *
          σ i)‖ ^ 2 ≤
      (1 + S.b⁻¹ ^ 6) * S.scaledSiegelConst *
        (∑ t' ∈ univ.image t, ∑ p : Fin 𝔰.ϱ → T₀, ∑ q : Fin 𝔰.ϱ → T₀,
          (∏ v : NumberField.InfinitePlace E,
            (S.besselSystem v).bandLimit 𝔰.n (x v p t') (x v q t')) *
          (G.lastEntryDensity (S.piNAt T) Y (y p t') (y q t') / Y.massRatio.toReal)).re

Untruncated Headline Signatures ​

From skeleton/04_spanning/energy_estimate.lean (upstream EnergyEstimate.lean:620–685) and skeleton/04_spanning/remaining_terms_sum.lean (upstream RemainingTerms/Sum.lean:678–837):

lean
theorem New.Filling.linkSecondMoment_isOpenElement_le [S.IsAdmissible] (Sg : Finset (S.chosenPlaces 0))
    (D : ∀ w : S.chosenPlaces 0, S.FrameVector w) :
    linkSecondMoment {γ : S.G E | S.termDisc γ ≠ 0}
      {s : S.ResidueGL | s ∈ S.fixer Sg D ∧ S.IsOpenElement s} ≤
      .ofReal ((1 + (S.b ^ 4)⁻¹) * (S.b ^ (6 * 𝔰.k))⁻¹ ^ #Sg * S.mainSecondMoment *
        S.unipotentCovolume ^ 2)

theorem New.Filling.secondMoment_remainingTerms_le {E : Type} [Field E] [CMType E] {𝔰 : Shape} {S : Filling E 𝔰}
    [HasPrimitiveRoot5040 E] [S.IsAdmissible] {w : ℝ} {Ω : Set S.ResidueGL} (hw : 0 ≤ w)
    (h_linkMoment : linkSecondMoment {γ : S.G E | S.termDisc γ ≠ 0} Ω ≤
      ENNReal.ofReal (w * S.unipotentCovolume ^ 2)) :
    secondMoment (S.amplitudeSum .cut S.remainingTerms) Ω ≤
      w + S.identitySecondMoment / S.b ^ (𝔰.k * numInfPlaces E)

theorem New.Filling.linkSecondMoment_le_of_le_meetNorm {E : Type} [Field E] [CMType E]
    {𝔰 : Shape} {S : Filling E 𝔰} [HasPrimitiveRoot5040 E] [S.IsAdmissible]
    {Ω : Set S.ResidueGL} {z : ℕ} (hz : z ≠ 0)
    (h_meet : ∀ s ∈ Ω, z ≤ S.meetNorm s) :
    linkSecondMoment {γ : S.G E | S.termDisc γ ≠ 0} Ω ≤
      ENNReal.ofReal ((S.b ^ (2 * numInfPlaces E) / z) ^ 𝔰.k * S.mainSecondMoment *
        S.unipotentCovolume ^ 2)
  • Verification status (audit/verification-status.json): Local Lean compilation and kernel replay remain build_status: unverified-locally at pinned commit 41c2716658c42ba08eb0648994a2efe83082a95c (41c2716658c4). Static token scanning has scan_scope: entry, covering only Challenge.lean, src/Main.lean, and src/Statements.lean (0 forbidden tokens in solution files, 5 expected sorry tokens in Challenge.lean). Neither EnergyEstimate.lean nor RemainingTerms/Sum.lean has been locally compiled, kernel-checked, or statically scanned here.

lemma New.Filling.leadingMinor_frameGram_map — Upstream source (src/New/Spanning/MainTerm/EnergyEstimate.lean L58-L66)

lean
/-- The leading minors of the frame products (the products of the frame of the middle form over
the lattice with its image under `X`) commute with ring maps. -/
lemma New.Filling.leadingMinor_frameGram_map {R R' : Type} [CommRing R] [CommRing R'] (φ : R →+* R')
    (X : Matrix 𝔰.BesselIndex 𝔰.BesselIndex R) (l : Fin (𝔰.n + 1)) :
    leadingMinor ((S.latticeMiddle R').frameGram (X.map φ)) l =
      φ (leadingMinor ((S.latticeMiddle R).frameGram X) l) := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/MainTerm/EnergyEstimate.lean:58-66 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=4 body_sha256=c068690bccaae1b662ddbc1641493c08d66fa3cd48218587190076c2098008fa]

lemma New.Filling.exists_leadingMinor_reduceAt_eq — Upstream source (src/New/Spanning/MainTerm/EnergyEstimate.lean L68-L89)

lean
/-- If `γ ∈ S.termsOver c s c'`, that is, `h_c⁻¹ γ h_c'` lies in K and has reduction `s`, then for
each `l` the leading minor of order `l` of `S.frameProducts γ` is integral. At every place `w` in
`S.chosenPlaces i` its reduction `reduceAt w` equals the same minor of
`(S.latticeMiddle (ResField w)).frameGram (s i w)`. -/
lemma New.Filling.exists_leadingMinor_reduceAt_eq {c c' : S.Classes} {s : S.ResidueGL} {γ : S.G E}
    (hγ : γ ∈ S.termsOver c s c') (l : Fin (𝔰.n + 1)) :
    ∃ δ : Ô E, δ.1 = algebraMap E (𝔸f E) (leadingMinor (S.frameProducts γ) l) ∧
      ∀ (i : Fin 2) (w : S.chosenPlaces i), reduceAt w.1 δ =
        leadingMinor ((S.latticeMiddle (ResField w.1)).frameGram (s i w).1) l := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/MainTerm/EnergyEstimate.lean:68-89 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=14 body_sha256=39908f231578608441f77d1aa0cdaf9df99b884b85e9a6e89a00612f3f3be5a4]

lemma New.Filling.IsOpenElement.leadingMinor_ne_zero — Upstream source (src/New/Spanning/MainTerm/EnergyEstimate.lean L91-L100)

lean
/-- If `s` is open, that is, at some chosen place above the first prime none of its proper leading
minors of frame products vanishes, then for every term `γ` over a block `(c, s, c')` no proper
leading minor of the frame products of `γ` vanishes: `γ` lies in the big cell. -/
lemma New.Filling.IsOpenElement.leadingMinor_ne_zero {c c' : S.Classes} {s : S.ResidueGL}
    (hs : S.IsOpenElement s) {γ : S.G E} (hγ : γ ∈ S.termsOver c s c') (l : Fin 𝔰.n) :
    leadingMinor (S.frameProducts γ) l.castSucc ≠ 0 := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/MainTerm/EnergyEstimate.lean:91-100 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=5 body_sha256=d029e606f1cad6337b7022d2c89cdfe664b26a9c3f63291ac683d2e4d03f1265]

lemma New.Filling.one_add_inv_pow_ten_pow_le — Upstream source (src/New/Spanning/MainTerm/EnergyEstimate.lean L102-L116)

lean
/-- With `f` the number of infinite places, the factor `(1 + S.b⁻¹ ^ 10) ^ f` of the sieve is at
most `1 + S.b⁻¹ ^ 9`, because `f ≤ S.b / 1000` by the hypothesis `S.IsAdmissible`. -/
lemma New.Filling.one_add_inv_pow_ten_pow_le :
    (1 + S.b⁻¹ ^ 10) ^ Core.numInfPlaces E ≤ 1 + S.b⁻¹ ^ 9 := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/MainTerm/EnergyEstimate.lean:102-116 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=12 body_sha256=bbbe293182254b431f53dc43816541c4ff6ad59c97112491216565358c101221]

lemma New.Filling.one_add_pow_six_mul_add_pow_ten_le_one_add_pow_four — Upstream source (src/New/Spanning/MainTerm/EnergyEstimate.lean L118-L139)

lean
/-- For `0 ≤ u ≤ 1 / 1000` one has `(1 + u⁶) ((1 + u⁹)² (1 + u⁶) + u¹⁰) ≤ 1 + u⁴`. With `u = b⁻¹`
this collects the error factors in `sieve_constant_le`. -/
lemma New.Filling.one_add_pow_six_mul_add_pow_ten_le_one_add_pow_four {u : ℝ} (hu : 0 ≤ u)
    (hu_le : u ≤ 1 / 1000) :
    (1 + u ^ 6) * ((1 + u ^ 9) * (1 + u ^ 9) * (1 + u ^ 6) + u ^ 10) ≤ 1 + u ^ 4 := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/MainTerm/EnergyEstimate.lean:118-139 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=18 body_sha256=3921aef2a6bac7906a23e361e476d4238fe8da1a01b4afdbe89127ee7e4fbbab]

abbrev New.Filling.normalizingConst — Upstream source (src/New/Spanning/MainTerm/EnergyEstimate.lean L141-L147)

lean
/-- The normalising constant `r` of the main term, used with `k = 𝔰.k - 1`: the product over the
infinite places of √`openCellConst` and powers of the squared scales `frameScaleSq` of the frame
vectors, divided by the number of Bessel coordinates. -/
noncomputable abbrev New.Filling.normalizingConst (S : Filling E 𝔰) [S.IsAdmissible] (k : ℕ) : ℝ := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/MainTerm/EnergyEstimate.lean:141-147 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=3 body_sha256=d44d7efe05ba396c8c42b14b600976966a5d10fa9a0e79b09cd42539aa777686]

lemma New.Filling.prod_poissonConst_eq — Upstream source (src/New/Spanning/MainTerm/EnergyEstimate.lean L149-L173)

lean
/-- Assume `S.IsAdmissible` and `𝔰.k = kPred + 1`. The product of the Poisson summation constants
`S.poissonConst i` over `i < 𝔰.n` is `S.normalizingConst kPred ^ 2` times
`volÔ E ^ 𝔰.n (dim / Λ) ^ 2 / c_G ^ f`, where `dim = Fintype.card S.BesselCoord` is the number of
Bessel coordinates, `Λ = S.frameScaleProd`, `c_G = 𝔰.openCellConst` and `f` is the number of
infinite places. -/
lemma New.Filling.prod_poissonConst_eq [S.IsAdmissible] {kPred : ℕ} (hk : 𝔰.k = kPred + 1) :
    ∏ i ∈ Finset.range 𝔰.n, S.poissonConst i =
      S.normalizingConst kPred ^ 2 *
        (volÔ E ^ 𝔰.n * (Fintype.card S.BesselCoord / S.frameScaleProd) ^ 2 /
          𝔰.openCellConst ^ Core.numInfPlaces E) := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/MainTerm/EnergyEstimate.lean:149-173 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=16 body_sha256=06d216dc2fabc23a906ffea043c8b58869bbb98e206d1fa7f58756694bea7202]

lemma New.Filling.scaledSiegelConst_mul_decayConst_le — Upstream source (src/New/Spanning/MainTerm/EnergyEstimate.lean L177-L262)

lean
/-- The error is measured against the identity second moment. Let `f` be the number of infinite
places, `n = 𝔰.n = ϱ + 1` the number of frame vectors, `k = 𝔰.k` and `dim` the number of Bessel
coordinates. The left side has three factors: the constant `scaledSiegelConst` of Siegel's step; the
quotient `vol(Ô) ^ n (dim / Λ)² / c_G ^ f` of the constants of Poisson summation by the squared
normalising constant, where `Λ = frameScaleProd` is a product of powers of the squared scales of the
frame vectors and `c_G = openCellConst = vol U(k)² / (vol U(k + 2ϱ + 1) vol U(k - 1))`; and
`decayConst`, the product over the infinite places `v` of a volume ratio of the shape times
`(|κ_v| ^ (2ϱ + 1) / (M N)) ^ (k - n⁷)` with `κ_v = S.realM v`. It is at most `b ^ (n⁹ f)` times
`dim * identitySecondMoment * unipotentCovolume²`. Here `identitySecondMoment` is the order of the
reduction of the Bessel subgroup times the number of classes times `dim`. -/
lemma New.Filling.scaledSiegelConst_mul_decayConst_le [S.IsAdmissible] :
    S.scaledSiegelConst * (volÔ E ^ 𝔰.n * (Fintype.card S.BesselCoord / S.frameScaleProd) ^ 2 /
        𝔰.openCellConst ^ Core.numInfPlaces E) * S.decayConst ≤
      S.b ^ (𝔰.n ^ 9 * Core.numInfPlaces E) *
        (Fintype.card S.BesselCoord * S.identitySecondMoment * S.unipotentCovolume ^ 2) := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/MainTerm/EnergyEstimate.lean:177-262 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=72 body_sha256=316dd8e8b7569960cbf9e49f86dcc8b3f3953ba79ef37b078f21935b324f0392]

lemma New.Filling.sieve_constant_le — Upstream source (src/New/Spanning/MainTerm/EnergyEstimate.lean L264-L348)

lean
/-- Let `S` be admissible with size parameter `b`, `kPred = 𝔰.k - 1`, and let the number `numSieved`
of places at which vectors are fixed be at most `f`, the number of infinite places. The theorem
`sieve` bounds a sum of last entry densities over pairs of heads by `(∏ i, poissonConst i) * ((∏ v,
(1 + b⁻¹⁰) / deg v) * m + ε)`. Here `poissonConst i`, the constant of Poisson summation in entry
`i`, is vol(Ô) over the Jacobian of the scaling at the infinite places; `deg v` is the degree of the
Bessel system at `v`; `m` bounds the mass at the finite places; and
`ε = b^(2403 𝔰.n⁹ f) * decayConst` is the error, `decayConst` being the product of the constants in
the decay at the infinite places. For `m = (1 + b⁻⁶) / b^(6 𝔰.k numSieved)`, this bound times the
constant `(1 + b⁻⁶) * scaledSiegelConst` of Siegel's step is at most `r² (1 + b⁻⁴) b^(-6 𝔰.k
numSieved) * mainSecondMoment * unipotentCovolume²`, where `r = S.normalizingConst kPred` and
`mainSecondMoment = sourceDim² / ((∏ v, deg v) * mass)`, with the mass of the genus of the standard
Hermitian lattice of rank `𝔰.r`. -/
lemma New.Filling.sieve_constant_le [S.IsAdmissible] {kPred numSieved : ℕ} (hk : 𝔰.k = kPred + 1)
    (h_numSieved : numSieved ≤ Core.numInfPlaces E) :
    (1 + S.b⁻¹ ^ 6) * S.scaledSiegelConst *
        ((∏ i ∈ Finset.range 𝔰.n, S.poissonConst i) *
          ((∏ v : NumberField.InfinitePlace E, (1 + S.b⁻¹ ^ 10) / (S.besselSystem v).deg) *
              ((1 + S.b⁻¹ ^ 6) / (S.b ^ (6 * 𝔰.k)) ^ numSieved) +
            S.b ^ (2403 * 𝔰.n ^ 9 * Core.numInfPlaces E) * S.decayConst)) ≤
      S.normalizingConst kPred ^ 2 *
        ((1 + (S.b ^ 4)⁻¹) * (S.b ^ (6 * 𝔰.k))⁻¹ ^ numSieved * S.mainSecondMoment *
          S.unipotentCovolume ^ 2) := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/MainTerm/EnergyEstimate.lean:264-348 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=64 body_sha256=e2d73ecdb833e64687b78264c5a9b50c7f188966d7f1eb958d4c9e44cf59b176]

lemma New.Filling.normalizingConst_sq_pos — Upstream source (src/New/Spanning/MainTerm/EnergyEstimate.lean L350-L358)

lean
/-- The square of the normalising constant is positive. -/
lemma New.Filling.normalizingConst_sq_pos [S.IsAdmissible] (kPred : ℕ) :
    0 < S.normalizingConst kPred ^ 2 := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/MainTerm/EnergyEstimate.lean:350-358 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=7 body_sha256=ffb1c38d19c7cc67ed2783b02c2c189d9e26c422de0403848939d93d1775cbd8]

lemma New.Filling.gramScalar_mul_headDensity — Upstream source (src/New/Spanning/MainTerm/EnergyEstimate.lean L360-L410)

lean
/-- Let `P` be a structure of finite place on the product of the completions at `T`, and `G` a
filling datum for it. Let the head have ϱ first entries `p`, units off `T`, and last entry `t` with
‖t‖² > N² at every infinite place; `x v a` is its entry of index `a` under `Φ v` times
`S.frameScaleSq v a = κ_v^(2(ϱ - a)) / N`, the squared scale of the frame vector `a`
(`κ_v = S.realM v`). The first factor on the left is the product over `v` of the scalars of
`normalizedOrbitalIntegral` at `x v`; in it `openCellConst` is a ratio of volumes of compact unitary
groups and `(S.besselSystem v).Index` indexes a basis of the value space of the Bessel functions at
`v`. The second factor `G.headDensity` is a product of powers of the moduli of `p` for `P`. Their
product is `S.normalizingConst kPred`, with `kPred = 𝔰.k - 1`, times the square root of (∏ (‖t‖² -
N²))^(𝔰.k - 1). By the product formula the powers of `p` cancel; the constant collects
√`openCellConst`, the powers of the squared scales and the numbers of indices. -/
lemma New.Filling.gramScalar_mul_headDensity
    [S.IsAdmissible] {T : Finset (FinPlace E)} [T.StarStable] {P : Floors.IntegralPlace (LocProd T)}
    {G : Floors.PlaceData (Fin (𝔰.k - (6 * 𝔰.ϱ + 13))) (S.latticeMiddle (LocProd T))
      (𝔰.ϱ + 1 + 2 * 𝔰.ϱ + 5)} {kPred : ℕ} (hk : 𝔰.k = kPred + 1)
    {T₀ : Finset Eˣ} (hT₀ : ∀ x ∈ T₀, x.val ∈ ratIntegralOff T ∧ x⁻¹.val ∈ ratIntegralOff T)
    {t : Eˣ} (h_large : ∀ v : NumberField.InfinitePlace E, S.N ^ 2 < ‖Φ v t.val‖ ^ 2)
    (p : Fin 𝔰.ϱ → T₀) :
    let x (v : NumberField.InfinitePlace E) (a : ℕ) : ℂˣ := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/MainTerm/EnergyEstimate.lean:360-410 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=32 body_sha256=7c8aecf3b6f3b08992a751e8bdece2d1df0e41951e36546f2eb85a887b3e1f02]

lemma New.Filling.prod_bandLimit_eq_gram — Upstream source (src/New/Spanning/MainTerm/EnergyEstimate.lean L412-L461)

lean
/-- Let `S` be an admissible filling, and `σ` a rational element of the floor group (it fixes the
hyperbolic basis vectors `e_a`, `e*_a` for `a < ϱ`) with last frame product `t`. A head is a tuple
`p` of ϱ entries from a finite set `T₀` of units of `E`, followed by `t`; `x v p a` is its entry of
index `a` under the embedding `Φ v`, times the squared scale `S.frameScaleSq v a` of the frame
vector `a` at `v`. The Weyl element `w_p` of the head sends `e_a` to `p_a e*_a` and `e*_a` to
`e_a / p̄_a` for `a < ϱ`. Let `W = S.besselFn .cut` be the product over the infinite places of the
cut Bessel functions W♭, which have bounded support modulo the Bessel subgroup, and let
`besselOrbitalIntegral volume W γ` be the tensor ∫ W(g) ⊗ W(γ⁻¹ g)^* dg. Let `R p q` be the product
over `v` of `bandLimit 𝔰.n`, the top one of the forms on pairs of heads that the Bessel system at
`v` provides for the sieve. Then `R` is the Gram matrix of the orbital integrals at `γ = w_p σ`,
each weighted by the product over `v` of the scalar of `normalizedOrbitalIntegral`, √c_G · (|x_ϱ|² -
1)^((k - 1)/2) · |I|⁻¹ · ∏_{a<ϱ} |x_a|^(k + 1 + 2(ϱ - a - 1)), where `x = x v p`, `k = 𝔰.k`,
`c_G = 𝔰.openCellConst` and `I` is the index set of the Bessel system at `v`. -/
lemma New.Filling.prod_bandLimit_eq_gram {T₀ : Finset Eˣ} {σ : S.G E} {t : Eˣ}
    (hσ : σ ∈ Shape.Form.floorGroup 𝔰.ϱ) (h_tail : S.frameProducts σ 𝔰.top 𝔰.top = t) :
    let x (v : NumberField.InfinitePlace E) (p : Fin 𝔰.ϱ → T₀) (a : ℕ) : ℂˣ := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/MainTerm/EnergyEstimate.lean:412-461 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=34 body_sha256=56c917bb59232d55f25d6f8a88f5009ca17b18e85da88a243f02940e4457a090]

lemma New.Filling.IsFillingData.mul_sum_norm_sum_cosetAmplitude_sq_le — Upstream source (src/New/Spanning/MainTerm/EnergyEstimate.lean L465-L551)

lean
/-- Siegel's step. Let `S` be an admissible filling of shape `𝔰` over a CM field `E` with Weil data,
and let `kPred = 𝔰.k - 1`. Let `1 / M`, `1 / N`, the lattice basis and its inverse be integral off
the finite set of places `T`. Let `P` be a structure of finite place on the product of the
completions at `T`, `G` a filling datum for it, and `Y` a group between the congruence group of `G`
and the integral points. Take finitely many distinct classes `(c i, S.reduction (n i), c' i, σ i)`,
with `σ i` in the floor group, last entry `t i` with ‖t i‖² > N² at every infinite place, position
integral off `T` and lift `n i` in `Y` at `T`.

On the left, `S.cosetAmplitude .cut c s c' γ` is the sum of the amplitudes of the cut function at
`u γ u'⁻¹` over the rational unipotent `u`, `u'` for which this element lies over `(c, s, c')`. It
is summed over `γ = w_p σ`, for the Weyl elements `w_p` of the heads with first entries `p` in a
finite set `T₀` of units off `T`. The squared norms of these class sums, times `r²` for the
normalising constant `r`, add up to at most `(1 + b⁻⁶) * S.scaledSiegelConst` times the real part of
a sum over the last entries and the pairs of heads. The summand is the product of the top forms
`bandLimit 𝔰.n` of the Bessel systems at the infinite places with the density `G.lastEntryDensity`
at `T`, divided by `Y.massRatio = vol(Y) vol(K) / fl²`, where `K` is the congruence group of `G` and
`fl = G.unipotentMass`. -/
lemma New.Filling.IsFillingData.mul_sum_norm_sum_cosetAmplitude_sq_le [S.IsAdmissible] {T : Finset (FinPlace E)}
    [T.StarStable] [Fact (S.ideleM⁻¹.val ∈ integralOff T)] {P : Floors.IntegralPlace (LocProd T)}
    {G : Floors.PlaceData (Fin (𝔰.k - (6 * 𝔰.ϱ + 13))) (S.latticeMiddle (LocProd T))
      (𝔰.ϱ + 1 + 2 * 𝔰.ϱ + 5)} (hG : S.IsFillingData T G) (Y : G.IntermediateGroup)
    {kPred : ℕ} (hk : 𝔰.k = kPred + 1) {ι : Type} [Fintype ι] [DecidableEq Eˣ]
    {c c' : ι → S.Classes} {σ : ι → S.G E} {n : ι → S.latticeStabilizer} {t : ι → Eˣ}
    (h_inj : (fun i : ι ↦ (c i, c' i, S.reduction (n i), σ i)).Injective)
    (hσ : ∀ i : ι, σ i ∈ Shape.Form.floorGroup 𝔰.ϱ)
    (h_tail : ∀ i : ι, S.frameProducts (σ i) 𝔰.top 𝔰.top = t i)
    (h_large : ∀ (i : ι) (v : NumberField.InfinitePlace E), S.N ^ 2 < ‖Φ v (t i).val‖ ^ 2)
    (hn_mem_Y : ∀ i : ι, S.toPlaces T (n i) ∈ Y.val) {T₀ : Finset Eˣ}
    (hT₀ : ∀ x ∈ T₀, x.val ∈ ratIntegralOff T ∧ x⁻¹.val ∈ ratIntegralOff T)
    (hT_basis : S.latticeBasis ∈ intGL 𝔰.BesselIndex (integralOff T))
    (hT_N : (S.N : E)⁻¹ ∈ ratIntegralOff T)
    (h_off : ∀ i : ι, S.IsIntegralOff T (S.translateByClassReps (c i) (c' i) (σ i))) :
    let r : ℝ := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/MainTerm/EnergyEstimate.lean:465-551 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=55 body_sha256=d94cba7b8f9a092fabb44ac2948bfdcdbd184e254085e7a2fa9ff44ae5ad7199]

lemma New.Filling.sum_norm_sum_cosetAmplitude_sq_le — Upstream source (src/New/Spanning/MainTerm/EnergyEstimate.lean L553-L618)

lean
/-- Let `S` be an admissible filling of shape `𝔰` over a CM field `E` with Weil data, with size
parameter `b = S.b`, and `Sg` a set of chosen places above the first level prime p₀
(`S.chosenPlaces 0`). Take finitely many distinct classes `(c i, S.reduction (n i), c' i, σ i)`
whose last entries `t i` lie in a finite set `T₀` of units off `T`, whose positions are integral off
`T` and whose reductions are in `S.fixer Sg D`. Here `σ i` is in the floor group, its last frame
product is `t i`, and ‖t i‖² > N² at every infinite place; `1 / M`, `1 / N`, the lattice basis and
its inverse are integral off `T`. The double coset sum `S.cosetAmplitude .cut c s c' γ` adds the
amplitudes of the cut Bessel function at `u γ u'⁻¹` over the rational unipotent `u`, `u'` for which
this element lies over `(c, s, c')`. These sums, added over the heads with entries in `T₀`, have
total square norm at most `(1 + b⁻⁴) b^(-6 𝔰.k |Sg|)` times
`mainSecondMoment = sourceDim² / (besselDegree * mass)` times `unipotentCovolume²`. -/
lemma New.Filling.sum_norm_sum_cosetAmplitude_sq_le [S.IsAdmissible] (Sg : Finset (S.chosenPlaces 0))
    (D : ∀ w : S.chosenPlaces 0, S.FrameVector w) {ι : Type} [Fintype ι] {c c' : ι → S.Classes}
    {σ : ι → S.G E} {n : ι → S.latticeStabilizer} {t : ι → Eˣ}
    (h_inj : (fun i : ι ↦ (c i, c' i, S.reduction (n i), σ i)).Injective)
    (hσ : ∀ i : ι, σ i ∈ Shape.Form.floorGroup 𝔰.ϱ)
    (h_tail : ∀ i : ι, S.frameProducts (σ i) 𝔰.top 𝔰.top = t i)
    (h_large : ∀ (i : ι) (v : NumberField.InfinitePlace E), S.N ^ 2 < ‖Φ v (t i).val‖ ^ 2)
    (hn_fix : ∀ i : ι, S.reduction (n i) ∈ S.fixer Sg D)
    {T₀ : Finset Eˣ} (ht : ∀ i : ι, t i ∈ T₀) {T : Finset (FinPlace E)} [T.StarStable]
    (hT₀ : ∀ x ∈ T₀, x.val ∈ ratIntegralOff T ∧ x⁻¹.val ∈ ratIntegralOff T)
    [hT_M : Fact (S.ideleM⁻¹.val ∈ integralOff T)]
    (hT_basis : S.latticeBasis ∈ intGL 𝔰.BesselIndex (integralOff T))
    (hT_N : (S.N : E)⁻¹ ∈ ratIntegralOff T)
    (h_off : ∀ i : ι, S.IsIntegralOff T (S.translateByClassReps (c i) (c' i) (σ i))) :
    ∑ i : ι, ‖∑ p : Fin 𝔰.ϱ → T₀, S.cosetAmplitude .cut (c i) (S.reduction (n i)) (c' i)
        (Floors.FloorGroups.weylElem 𝔰.ϱ (padTuple (fun a : Fin 𝔰.ϱ ↦ (p a).val) (t i)) *
          σ i)‖ ^ 2 ≤
      (1 + (S.b ^ 4)⁻¹) * (S.b ^ (6 * 𝔰.k))⁻¹ ^ #Sg * S.mainSecondMoment *
        S.unipotentCovolume ^ 2 := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/MainTerm/EnergyEstimate.lean:553-618 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=37 body_sha256=3afe984e37324c52f99e852795d1c732e7d5a8d2870da26c4007b86fd80b0b80]

theorem New.Filling.linkSecondMoment_isOpenElement_le — Upstream source (src/New/Spanning/MainTerm/EnergyEstimate.lean L620-L685)

lean
/-- Let `S` be an admissible filling of shape `𝔰` over a CM field `E` with Weil data, `Sg` a set of
chosen places above the first level prime p₀, and `D w` a nonzero vector of the span of the frame
modulo `w` or modulo its conjugate. On the left, `linkSecondMoment` sums the squared norms of the
class sums of the cut function over all links, pairs of classes, and reductions `s` that are open
and fix `D w` for `w ∈ Sg`. With `X` the isotropic span of `e₁, …, e_ϱ`, the link of a term `γ` is
the module of pairs of classes in `X^⊥/X` of `t` and `γ⁻¹ t`, for `t` orthogonal to `X` and `γ X`;
each class sum runs over the terms of one link. Only terms `γ` with
`termDisc γ = |Δ|² - N² |Δ'|² ≠ 0` enter, where `Δ` is the determinant and `Δ'` the leading minor of
size ϱ of the frame products of `γ`. The bound is `(1 + b⁻⁴) b^(-6 𝔰.k |Sg|)` times
`mainSecondMoment = sourceDim² / (besselDegree * mass)` times `unipotentCovolume²`. Here `b` is the
size parameter of `S`, `𝔰.k` is the rank of X₀, `mass` is the mass of the genus of the standard
Hermitian lattice of rank `𝔰.r`, and `unipotentCovolume` is an explicit number which, if `E`
contains a primitive 5040th root of unity, is the integral of the cutoff `S.classCutoff c` over the
real unipotent group, for every class `c` (`lintegral_classCutoff_eq_unipotentCovolume`). -/
theorem New.Filling.linkSecondMoment_isOpenElement_le [S.IsAdmissible] (Sg : Finset (S.chosenPlaces 0))
    (D : ∀ w : S.chosenPlaces 0, S.FrameVector w) :
    linkSecondMoment {γ : S.G E | S.termDisc γ ≠ 0}
      {s : S.ResidueGL | s ∈ S.fixer Sg D ∧ S.IsOpenElement s} ≤
      .ofReal ((1 + (S.b ^ 4)⁻¹) * (S.b ^ (6 * 𝔰.k))⁻¹ ^ #Sg * S.mainSecondMoment *
        S.unipotentCovolume ^ 2) := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/MainTerm/EnergyEstimate.lean:620-685 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=47 body_sha256=3b0372a0a8a8c603695b2e60d28eef62edc72a6774c7c0f3664e4a1f5d92a5ef]

lemma New.Filling.eq_of_mem_termsOver — Upstream source (src/New/Spanning/RemainingTerms/Sum.lean L59-L65)

lean
/-- A term `γ` over the classes `c`, `c'` determines the reduction `s` of its block `(c, s, c')`. -/
lemma New.Filling.eq_of_mem_termsOver {E : Type} [Field E] [CMType E] {𝔰 : Shape} {S : Filling E 𝔰}
    {c c' : S.Classes} {γ : S.G E} {s s' : S.ResidueGL}
    (h : γ ∈ S.termsOver c s c') (h' : γ ∈ S.termsOver c s' c') : s = s' := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/RemainingTerms/Sum.lean:59-65 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=4 body_sha256=fcaa2739108a762477a5db76289fa2871f41ed7524508f6aacf0684d16ee3190]

lemma New.Filling.IsNearPairOverAgreeingBlock.one_le_pairDiscriminant — Upstream source (src/New/Spanning/RemainingTerms/Sum.lean L67-L73)

lean
/-- The common lattice of a near pair (two near representative terms over one block whose `s`
agrees) has discriminant at least `1`. -/
lemma New.Filling.IsNearPairOverAgreeingBlock.one_le_pairDiscriminant {E : Type} [Field E] [CMType E]
    {𝔰 : Shape} {S : Filling E 𝔰} [HasPrimitiveRoot5040 E] {c c' : S.Classes} {q : S.G E × S.G E}
    (hq : S.IsNearPairOverAgreeingBlock c c' q) : 1 ≤ S.pairDiscriminant c c' q.1 q.2 := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/RemainingTerms/Sum.lean:67-73 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=3 body_sha256=092cecf800fdab1bee7b20b68bc1ab637b84861c77645ce43e85c84eddfe35d9]

lemma New.Filling.IsNearPairOverAgreeingBlock.pairDiscriminant_sq_le — Upstream source (src/New/Spanning/RemainingTerms/Sum.lean L75-L87)

lean
/-- For a near pair `(γ, γ')`, the square of the discriminant of the common lattice is at most
`(2 / M) ^ (2 i f)` times the product of the two gauges, where `i` is the codimension in each link
(`New.link`) of the intersection of the links, `M = S.M` is the congruence level and `f` is the
number of infinite places. -/
lemma New.Filling.IsNearPairOverAgreeingBlock.pairDiscriminant_sq_le {E : Type} [Field E] [CMType E]
    {𝔰 : Shape} {S : Filling E 𝔰} [HasPrimitiveRoot5040 E]
    {c c' : S.Classes} {γ γ' : S.G E} (hq : S.IsNearPairOverAgreeingBlock c c' (γ, γ')) :
    S.pairDiscriminant c c' γ γ' ^ 2 ≤
      (2 / S.M) ^ (2 * S.linkCorank γ γ' * numInfPlaces E) *
        (S.levelGauge (S.cellRank γ) c c' γ * S.levelGauge (S.cellRank γ') c c' γ') := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/RemainingTerms/Sum.lean:75-87 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=4 body_sha256=b21816642c1ba38b558075edecd2c53faf14406a9dc53ecf36b821013b586841]

lemma New.Filling.IsNearPairOverAgreeingBlock.corank_le_and_pairDiscriminant_le — Upstream source (src/New/Spanning/RemainingTerms/Sum.lean L89-L136)

lean
/-- Let `S` be data of the filling theorem that satisfy the standing hypotheses `S.IsAdmissible`.
Let `(γ, γ')` be a near pair over the classes `c`, `c'`. Its common lattice has corank at most `n³`
and discriminant at most `S.discriminantBound = b ^ (n³ f)`. -/
lemma New.Filling.IsNearPairOverAgreeingBlock.corank_le_and_pairDiscriminant_le {E : Type} [Field E] [CMType E]
    {𝔰 : Shape} {S : Filling E 𝔰} [HasPrimitiveRoot5040 E] [S.IsAdmissible]
    {c c' : S.Classes} {γ γ' : S.G E} (hq : S.IsNearPairOverAgreeingBlock c c' (γ, γ')) :
    𝔰.k - finrank E (commonLink γ γ') ≤ 𝔰.n ^ 3 ∧
    S.pairDiscriminant c c' γ γ' ≤ S.discriminantBound := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/RemainingTerms/Sum.lean:89-136 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=41 body_sha256=c9edbb76f022762b00fe2ab5fd66ad9ecb7b553ec5d9bb111eccb768c413eae3]

lemma New.Filling.IsNearPairOverAgreeingBlock.mem_boundedDiscNearPairs — Upstream source (src/New/Spanning/RemainingTerms/Sum.lean L138-L147)

lean
/-- A near pair (two near representative terms over one block whose `s` agrees) lies in
`S.boundedDiscNearPairs l c c'`, the set of near pairs of corank `l` and bounded discriminant, for
`l` the corank of its common lattice. -/
lemma New.Filling.IsNearPairOverAgreeingBlock.mem_boundedDiscNearPairs {E : Type} [Field E] [CMType E]
    {𝔰 : Shape} {S : Filling E 𝔰} [HasPrimitiveRoot5040 E] [S.IsAdmissible] {c c' : S.Classes}
    {γ γ' : S.G E} (hq : S.IsNearPairOverAgreeingBlock c c' (γ, γ')) :
    (γ, γ') ∈ S.boundedDiscNearPairs (𝔰.k - finrank E (commonLink γ γ')) c c' := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/RemainingTerms/Sum.lean:138-147 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=3 body_sha256=ec86c03ef14d1116eb8eb5aa6b08338f4a23dc36bf547bc78dc725367d4449a5]

lemma New.Filling.termSize_sq_le — Upstream source (src/New/Spanning/RemainingTerms/Sum.lean L149-L164)

lean
/-- Let `S` be data of the filling theorem that satisfy the standing hypotheses `S.IsAdmissible`.
Let `c`, `c'` be classes and `γ` a rational point of cell rank `j = S.cellRank γ` whose gauge
`G = S.levelGauge j c c' γ` is positive. If the constant `S.cellRankSecondMoment j` is at most `D`,
then the square of the size `S.termSize c c' γ` is at most `τ⁴ D / (n_p G ^ k)`. -/
lemma New.Filling.termSize_sq_le {E : Type} [Field E] [CMType E] {𝔰 : Shape} {S : Filling E 𝔰}
    [S.IsAdmissible] {c c' : S.Classes} {γ : S.G E} {D : ℝ}
    (h_gauge_pos : 0 < S.levelGauge (S.cellRank γ) c c' γ)
    (hD : S.cellRankSecondMoment (S.cellRank γ) ≤ D) :
    S.termSize c c' γ ^ 2 ≤
      S.tailScale ^ 4 * D / (S.pairCountScale * S.levelGauge (S.cellRank γ) c c' γ ^ 𝔰.k) := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/RemainingTerms/Sum.lean:149-164 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=7 body_sha256=e8cf83f60b9b62d89440c44d38c8df1903623bb7635a0b6e8f80f50cdbad9872]

lemma New.Filling.IsNearPairOverAgreeingBlock.termSize_mul_le — Upstream source (src/New/Spanning/RemainingTerms/Sum.lean L168-L200)

lean
/-- Let `S` be data of the filling theorem that satisfy the standing hypotheses `S.IsAdmissible`.
Let `(γ, γ')` be a near pair over the classes `c`, `c'` and `d` the discriminant of its common
lattice `S.pairLattice`. Let `η > 0`. If `(d η)²` is at most the product of the two gauges and the
constants `S.cellRankSecondMoment` of both cell ranks are at most `D`, then the product of the sizes
`S.termSize` is at most `τ⁴ D η ^ (-k) d ^ (-k) / n_p`. -/
lemma New.Filling.IsNearPairOverAgreeingBlock.termSize_mul_le {E : Type} [Field E] [CMType E]
    {𝔰 : Shape} {S : Filling E 𝔰} [HasPrimitiveRoot5040 E] [S.IsAdmissible] {c c' : S.Classes}
    {γ γ' : S.G E} (hq : S.IsNearPairOverAgreeingBlock c c' (γ, γ')) {η D : ℝ} (hη : 0 < η)
    (h_gain : (S.pairDiscriminant c c' γ γ' * η) ^ 2 ≤
      S.levelGauge (S.cellRank γ) c c' γ * S.levelGauge (S.cellRank γ') c c' γ')
    (hD : S.cellRankSecondMoment (S.cellRank γ) ≤ D)
    (hD' : S.cellRankSecondMoment (S.cellRank γ') ≤ D) :
    S.termSize c c' γ * S.termSize c c' γ' ≤
      S.tailScale ^ 4 * D / η ^ 𝔰.k / S.pairCountScale *
        (S.pairDiscriminant c c' γ γ' ^ 𝔰.k)⁻¹ := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/RemainingTerms/Sum.lean:168-200 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=19 body_sha256=da54f26622a4e4cbae32303e11b6b7c55083ae16fb78608cecc4b5ec503169c9]

lemma New.Filling.IsNearPairOverAgreeingBlock.ofReal_termSize_mul_le — Upstream source (src/New/Spanning/RemainingTerms/Sum.lean L202-L229)

lean
/-- Let `S` be data of the filling theorem that satisfy the standing hypotheses `S.IsAdmissible`.
Let `(γ, γ')` be a near pair over the classes `c`, `c'`, whose common lattice `S.pairLattice` has
corank `l = k - finrank E (commonLink γ γ')` and discriminant `d = S.pairDiscriminant c c' γ γ'`.
Let `η > 0`. Suppose that `(d η)²` is at most the product of the two gauges, `D` bounds the
constants `S.cellRankSecondMoment` of both cell ranks, and `τ ^ (l + 6) D η ^ (-k) ≤ B`. Then the
product of the sizes `S.termSize` is at most `B d ^ (-k) / (τ ^ (l + 2) n_p)`. -/
lemma New.Filling.IsNearPairOverAgreeingBlock.ofReal_termSize_mul_le {E : Type} [Field E] [CMType E]
    {𝔰 : Shape} {S : Filling E 𝔰} [HasPrimitiveRoot5040 E] [S.IsAdmissible] {c c' : S.Classes}
    {γ γ' : S.G E} (hq : S.IsNearPairOverAgreeingBlock c c' (γ, γ')) {η D B : ℝ} (hη : 0 < η)
    (h_gain : (S.pairDiscriminant c c' γ γ' * η) ^ 2 ≤
      S.levelGauge (S.cellRank γ) c c' γ * S.levelGauge (S.cellRank γ') c c' γ')
    (hD : S.cellRankSecondMoment (S.cellRank γ) ≤ D)
    (hD' : S.cellRankSecondMoment (S.cellRank γ') ≤ D)
    (h_budget : S.tailScale ^ (𝔰.k - finrank E (commonLink γ γ') + 6) * D / η ^ 𝔰.k ≤ B) :
    ENNReal.ofReal (S.termSize c c' γ * S.termSize c c' γ') ≤
      .ofReal (B / (S.tailScale ^ (𝔰.k - finrank E (commonLink γ γ') + 2) * S.pairCountScale)) *
        .ofReal (S.pairDiscriminant c c' γ γ' ^ 𝔰.k)⁻¹ := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/RemainingTerms/Sum.lean:202-229 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=12 body_sha256=4e58c982af2b516e7a1d8b2f731941f9de3fc85a899e9c39515df1b6e21110ed]

lemma New.Filling.cube_add_one_le_tailScale — Upstream source (src/New/Spanning/RemainingTerms/Sum.lean L231-L239)

lean
/-- The number `n³ + 1` of possible coranks is at most `τ = S.tailScale`. -/
lemma New.Filling.cube_add_one_le_tailScale {E : Type} [Field E] [CMType E] {𝔰 : Shape} (S : Filling E 𝔰)
    [S.IsAdmissible] : ((𝔰.n ^ 3 + 1 : ℕ) : ℝ) ≤ S.tailScale := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/RemainingTerms/Sum.lean:231-239 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=7 body_sha256=d2b3d14f0691cd60a07b42bac8f846a8f4ebab9665c0245e76f2e67d9bfe6fa9]

lemma New.Filling.sum_termSize_mul_le — Upstream source (src/New/Spanning/RemainingTerms/Sum.lean L241-L305)

lean
/-- Let `S` be data of the filling theorem that satisfy the standing hypotheses `S.IsAdmissible`.
For all classes `c`, `c'` let `P c c'` be a set of near pairs over `c`, `c'`. Suppose that for each
pair, with a common lattice of corank `l` and discriminant `d`, there are `η > 0` and `D` such that
`(d η)²` is at most the product of the two gauges, `D` bounds the constants `S.cellRankSecondMoment`
of both cell ranks, and `τ ^ (l + 6) D η ^ (-k) ≤ B`, where `τ = S.tailScale`, `k = 𝔰.k` and
`B ≥ 0`. Then the products of the sizes `S.termSize` of the two terms add up to at most `τ B`. -/
lemma New.Filling.sum_termSize_mul_le {E : Type} [Field E] [CMType E] {𝔰 : Shape} {S : Filling E 𝔰}
    [HasPrimitiveRoot5040 E] [S.IsAdmissible] (P : S.Classes → S.Classes → Set (S.G E × S.G E))
    (h_nearPair : ∀ c c' : S.Classes, ∀ q ∈ P c c', S.IsNearPairOverAgreeingBlock c c' q)
    {B : ℝ} (hB : 0 ≤ B)
    (h_gain : ∀ (c c' : S.Classes) (γ γ' : S.G E), (γ, γ') ∈ P c c' → ∃ η D : ℝ, 0 < η ∧
      (S.pairDiscriminant c c' γ γ' * η) ^ 2 ≤
        S.levelGauge (S.cellRank γ) c c' γ * S.levelGauge (S.cellRank γ') c c' γ' ∧
      S.cellRankSecondMoment (S.cellRank γ) ≤ D ∧
      S.cellRankSecondMoment (S.cellRank γ') ≤ D ∧
      S.tailScale ^ (𝔰.k - finrank E (commonLink γ γ') + 6) * D / η ^ 𝔰.k ≤ B) :
    ∑ c : S.Classes, ∑ c' : S.Classes, ∑' q : P c c', ENNReal.ofReal
        (S.termSize c c' (q : S.G E × S.G E).1 * S.termSize c c' (q : S.G E × S.G E).2) ≤
      .ofReal (S.tailScale * B) := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/RemainingTerms/Sum.lean:241-305 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=47 body_sha256=37953476b29cd9ef38b823b557523012ebe93a74e0559bea8979f18df6b84dfc]

def New.Filling.InSameLinkClass — Upstream source (src/New/Spanning/RemainingTerms/Sum.lean L307-L311)

lean
/-- Two terms lie in the same link class if `𝗀 = S.termDisc` vanishes for neither and their links
(`New.link`) are equal. -/
def New.Filling.InSameLinkClass {E : Type} [Field E] [CMType E] {𝔰 : Shape} (S : Filling E 𝔰)
    (γ γ' : S.G E) : Prop := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/RemainingTerms/Sum.lean:307-311 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=1 body_sha256=e093af84c10014efc350d4892c8fdbca474621789edd1c82b70e5c4ca8ed0e0f]

lemma New.Filling.cellRankSecondMoment_le_mainSecondMoment — Upstream source (src/New/Spanning/RemainingTerms/Sum.lean L313-L328)

lean
/-- Let `S` be data of the filling theorem that satisfy the standing hypotheses `S.IsAdmissible`.
The second moment `S.cellRankSecondMoment j` of every cell rank `j` is at most `S.mainSecondMoment`,
the second moment of the top cell rank `ϱ + 1`. -/
lemma New.Filling.cellRankSecondMoment_le_mainSecondMoment {E : Type} [Field E] [CMType E]
    {𝔰 : Shape} {S : Filling E 𝔰} [S.IsAdmissible] (j : Fin (𝔰.ϱ + 2)) :
    S.cellRankSecondMoment j ≤ S.mainSecondMoment := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/RemainingTerms/Sum.lean:313-328 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=11 body_sha256=c9c1e58f95335fe674ef996af4dccacd3b633bd8b3ffde17cebad3d63dfaeebb]

lemma New.Filling.pow_mul_mainSecondMoment_div_le — Upstream source (src/New/Spanning/RemainingTerms/Sum.lean L330-L375)

lean
/-- Let `E` be a CM field, and let `S` be data of the filling theorem over `E` that satisfy the
standing hypotheses `S.IsAdmissible`. For `i ≥ 1` and `l ≤ i + 1` we have `τ ^ (l + 6) 𝒟_main
(M / 2) ^ (-i f k) ≤ τ ^ (-10) 𝒟_id`. This serves pairs whose links intersect in codimension `i` and
whose common lattice has corank `l`. -/
lemma New.Filling.pow_mul_mainSecondMoment_div_le {E : Type} [Field E] [CMType E] {𝔰 : Shape} {S : Filling E 𝔰}
    [ok : S.IsAdmissible] {i l : ℕ} (hi : i ≠ 0) (hl : l ≤ i + 1) :
    S.tailScale ^ (l + 6) * S.mainSecondMoment / ((S.M / 2) ^ (i * numInfPlaces E)) ^ 𝔰.k ≤
      S.identitySecondMoment / S.tailScale ^ 10 := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/RemainingTerms/Sum.lean:330-375 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=39 body_sha256=2fbe83dd7ef1c11f0f43f1b41140a656a1dd43f2007a1a055ce74eb3f79ed18d]

theorem New.Filling.sum_termSize_mul_not_inSameLinkClass_le — Upstream source (src/New/Spanning/RemainingTerms/Sum.lean L377-L446)

lean
/-- **Remaining terms, pairs that do not lie in the same link class.** Let `E` be a CM field with a
primitive root of unity of order 5040, and let `S` be data of the filling theorem over `E` that
satisfy the standing hypotheses `S.IsAdmissible`. Sum over all classes `c`, `c'` and all near pairs
over them whose links (`New.link`) differ or for one of which `𝗀 = S.termDisc` vanishes. The
products of the sizes of the two terms add up to at most `b ^ (-k f) 𝒟_id`. -/
theorem New.Filling.sum_termSize_mul_not_inSameLinkClass_le {E : Type} [Field E] [CMType E]
    {𝔰 : Shape} {S : Filling E 𝔰} [HasPrimitiveRoot5040 E] [S.IsAdmissible] :
    ∑ c : S.Classes, ∑ c' : S.Classes,
      ∑' q : {q : S.G E × S.G E |
        S.IsNearPairOverAgreeingBlock c c' q ∧ ¬S.InSameLinkClass q.1 q.2},
        ENNReal.ofReal
          (S.termSize c c' (q : S.G E × S.G E).1 * S.termSize c c' (q : S.G E × S.G E).2) ≤
      .ofReal (S.identitySecondMoment / S.b ^ (𝔰.k * numInfPlaces E)) := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/RemainingTerms/Sum.lean:377-446 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=58 body_sha256=a4d4a6336df890b5c790afb8e3ecb5437f191f8bbec2d7d817f1067384a8a181]

theorem New.Filling.sum_termSize_mul_inSameLinkClass_le — Upstream source (src/New/Spanning/RemainingTerms/Sum.lean L448-L491)

lean
/-- **Remaining terms, pairs in the same link class.** Let `E` be a CM field with a primitive root
of unity of order 5040, and let `S` be data of the filling theorem over `E` that satisfy the
standing hypotheses `S.IsAdmissible`. Let `z ≠ 0`. Sum over all classes `c`, `c'` and all near pairs
over them with equal links (`New.link`), with `𝗀 = S.termDisc ≠ 0` for both terms, and whose
reduction `s` has `z ≤ S.meetNorm s`. The products of the sizes `S.termSize` of the two terms add up
to at most `(b ^ (2 f) / z) ^ k 𝒟_main`. -/
theorem New.Filling.sum_termSize_mul_inSameLinkClass_le {E : Type} [Field E] [CMType E]
    {𝔰 : Shape} {S : Filling E 𝔰} [HasPrimitiveRoot5040 E] [S.IsAdmissible] {z : ℕ} (hz : z ≠ 0) :
    ∑ c : S.Classes, ∑ c' : S.Classes,
      ∑' q : {q : S.G E × S.G E | S.IsNearPairOverAgreeingBlock c c' q ∧
        S.InSameLinkClass q.1 q.2 ∧ ∃ s : S.ResidueGL, z ≤ S.meetNorm s ∧ q.1 ∈ S.termsOver c s c'},
        ENNReal.ofReal
          (S.termSize c c' (q : S.G E × S.G E).1 * S.termSize c c' (q : S.G E × S.G E).2) ≤
      .ofReal ((S.b ^ (2 * numInfPlaces E) / z) ^ 𝔰.k * S.mainSecondMoment) := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/RemainingTerms/Sum.lean:448-491 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=31 body_sha256=9323043c0a11612a26bd9c0c66096998696184ac5dc4ad6f30ff5dd524f05928]

abbrev New.Filling.Piece — Upstream source (src/New/Spanning/RemainingTerms/Sum.lean L493-L495)

lean
/-- The pieces into which a block is split: one for each link, and one for `𝗀 = 0`. -/
abbrev New.Filling.Piece (E : Type) [Field E] (𝔰 : Shape) : Type := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/RemainingTerms/Sum.lean:493-495 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=1 body_sha256=01d7507b83f655895d07762a8284cba2b3f3f16be9b84b4beb86486939fab96f]

def New.Filling.piece — Upstream source (src/New/Spanning/RemainingTerms/Sum.lean L498-L502)

lean
/-- The piece of a term `γ`: its link if `𝗀(γ) = S.termDisc γ ≠ 0`; the terms with `𝗀 = 0` form one
further piece. -/
noncomputable def New.Filling.piece {E : Type} [Field E] [CMType E] {𝔰 : Shape} (S : Filling E 𝔰)
    (γ : S.G E) : Piece E 𝔰 := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/RemainingTerms/Sum.lean:498-502 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=1 body_sha256=310438bca471be1623c5e98ece064248b5845b663835a31e7479dc4730a62c90]

lemma New.Filling.piece_eq_some_iff — Upstream source (src/New/Spanning/RemainingTerms/Sum.lean L504-L509)

lean
/-- The piece of `γ` is the submodule `Λ` if and only if `𝗀(γ) = S.termDisc γ` is not zero and the
link of `γ` is `Λ`. -/
lemma New.Filling.piece_eq_some_iff {E : Type} [Field E] [CMType E] {𝔰 : Shape} {S : Filling E 𝔰}
    {γ : S.G E} {Λ : Submodule E (𝔰.MiddleIndex ⊕ 𝔰.MiddleIndex → E)} :
    S.piece γ = some Λ ↔ S.termDisc γ ≠ 0 ∧ link γ = Λ := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/RemainingTerms/Sum.lean:504-509 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=2 body_sha256=ecefb517d7ee0782db3e757ab86e4f039a361a334b16fe6bed9cbbbe54cbace3]

lemma New.Filling.IsStable.inter_piece — Upstream source (src/New/Spanning/RemainingTerms/Sum.lean L511-L522)

lean
/-- The part `T ∩ S.piece ⁻¹' {κ}` of a stable set `T` in one piece `κ` is stable. A stable set is
one invariant on both sides under the rational points of the Bessel unipotent group. This holds
because `S.termDisc` and the link are invariant. -/
lemma New.Filling.IsStable.inter_piece {E : Type} [Field E] [CMType E] {𝔰 : Shape} {S : Filling E 𝔰}
    {T : Set (S.G E)} (hT : S.IsStable T) (κ : Piece E 𝔰) :
    S.IsStable (T ∩ S.piece ⁻¹' {κ}) := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/RemainingTerms/Sum.lean:511-522 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=7 body_sha256=ae74652a40196fef750911a3f5bdf9aba308d826591e9ab25407bcea9daef9a7]

lemma New.Filling.mem_of_mem_nearRepresentativesOver — Upstream source (src/New/Spanning/RemainingTerms/Sum.lean L524-L529)

lean
/-- A near representative of `T` over a block `(c, s, c')` (a chosen near term, that has a cell
rank, where `s` agrees) belongs to `T`. -/
lemma New.Filling.mem_of_mem_nearRepresentativesOver {E : Type} [Field E] [CMType E]
    {𝔰 : Shape} {S : Filling E 𝔰} {c c' : S.Classes} {T : Set (S.G E)} {s : S.ResidueGL}
    {p : S.G E} (hp : p ∈ S.nearRepresentativesOver T c s c') : p ∈ T := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/RemainingTerms/Sum.lean:524-529 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=1 body_sha256=a765597dac51efe3fe857931be46ef45d19bfffd9e9f438daa1085f6b59941b2]

lemma New.Filling.mem_termsOver_of_mem_nearRepresentativesOver — Upstream source (src/New/Spanning/RemainingTerms/Sum.lean L531-L536)

lean
/-- A near representative of `T` over the block `(c, s, c')` is a term over this block. -/
lemma New.Filling.mem_termsOver_of_mem_nearRepresentativesOver {E : Type} [Field E] [CMType E]
    {𝔰 : Shape} {S : Filling E 𝔰} {c c' : S.Classes} {T : Set (S.G E)}
    {s : S.ResidueGL} {p : S.G E} (hp : p ∈ S.nearRepresentativesOver T c s c') :
    p ∈ S.termsOver c s c' := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/RemainingTerms/Sum.lean:531-536 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=1 body_sha256=df7ff8b4b6aefe0671bd083c0d5dd9307fd214e0e025533d83e8e5ee0e8c8b94]

lemma New.Filling.isNearPairOverAgreeingBlock_of_mem_nearRepresentativesOver — Upstream source (src/New/Spanning/RemainingTerms/Sum.lean L538-L548)

lean
/-- Two near representatives over the same block `(c, s, c')` form a near pair over an agreeing
block, that is, two near representatives over one block whose reduction `s` agrees. -/
lemma New.Filling.isNearPairOverAgreeingBlock_of_mem_nearRepresentativesOver {E : Type} [Field E] [CMType E]
    {𝔰 : Shape} {S : Filling E 𝔰} {c c' : S.Classes}
    {T T' : Set (S.G E)} {s : S.ResidueGL} {p p' : S.G E}
    (hp : p ∈ S.nearRepresentativesOver T c s c')
    (hp' : p' ∈ S.nearRepresentativesOver T' c s c') :
    S.IsNearPairOverAgreeingBlock c c' (p, p') := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/RemainingTerms/Sum.lean:538-548 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=4 body_sha256=3d92e1bc660a3433798952633c3d4b1fd92230dbda320ca326673aeb614d7b0d]

lemma New.Filling.enorm_amplitudeSum_mul_le — Upstream source (src/New/Spanning/RemainingTerms/Sum.lean L550-L585)

lean
/-- Let `E` be a CM field with a primitive root of unity of order 5040, and let `S` be data of the
filling theorem over `E` that satisfy the standing hypotheses `S.IsAdmissible`. Let `T`, `T'` be
subsets of `Γ* = S.remainingTerms` that are stable, that is, invariant on both sides under the
rational points of the Bessel unipotent group. The product of the norms of the sums of the
amplitudes of their terms over `(c, s, c')` is at most the sum, over a near representative of `T`
and one of `T'`, of the square of the covolume `S.unipotentCovolume` times the product of the two
sizes.

A rational point `γ` lies over `(c, s, c')` if `h_c⁻¹ γ h_c'` (`h_c = S.classRep c`) is integral
with reduction `s`. Its amplitude is the integral over the archimedean points `y` of
`β_c(y) β_c'(γ⁻¹ y) W(y) ⊗ W(γ⁻¹ y)^*`, where `β_c = S.classCutoff c` and `W` is the cut Bessel
function, the Bessel function times a cutoff in the length `besselLength` at each infinite place. A
near representative of `T` over `(c, s, c')` is a `γ ∈ T` over `(c, s, c')` that is near (some
archimedean point `y` and `γ⁻¹ y` are both reduced and of bounded size, `S.boxedPoints`), is the
chosen element of its double coset under the groups `S.classUnipotent₀` and has a cell rank; there
are none unless `S.Agrees s`. The size `S.termSize c c' γ` is `τ² (D_j / (n_p G ^ k)) ^ (1 / 2)`,
where `j = S.cellRank γ` is the index of the cell of `γ`, `D_j = S.cellRankSecondMoment j`,
`G = S.levelGauge j c c' γ` is its gauge, `n_p = S.pairCountScale` and `τ = S.tailScale`. -/
lemma New.Filling.enorm_amplitudeSum_mul_le {E : Type} [Field E] [CMType E] {𝔰 : Shape} {S : Filling E 𝔰}
    [HasPrimitiveRoot5040 E] [S.IsAdmissible] {c c' : S.Classes} {T T' : Set (S.G E)}
    (hT : S.IsStable T) (hT' : S.IsStable T')
    (h_sub : T ⊆ S.remainingTerms) (h_sub' : T' ⊆ S.remainingTerms) {s : S.ResidueGL} :
    ‖S.amplitudeSum .cut T c s c'‖ₑ * ‖S.amplitudeSum .cut T' c s c'‖ₑ ≤
      ∑' q : S.nearRepresentativesOver T c s c' × S.nearRepresentativesOver T' c s c',
        .ofReal (S.unipotentCovolume ^ 2) *
        .ofReal (S.termSize c c' q.1 * S.termSize c c' q.2) := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/RemainingTerms/Sum.lean:550-585 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=11 body_sha256=6702041563c308fea8b5ea09d31eecc4ee2ec46eedc70cf9bc54f33f3afbacad]

lemma New.Filling.enorm_amplitudeSum_sq_le — Upstream source (src/New/Spanning/RemainingTerms/Sum.lean L587-L676)

lean
/-- Let `E` be a CM field with a primitive root of unity of order 5040, and let `S` be data of the
filling theorem over `E` that satisfy the standing hypotheses `S.IsAdmissible`. Let
`T ⊆ Γ* = S.remainingTerms` be stable (invariant on both sides under the rational points of the
Bessel unipotent group). The squared norm of the sum of the amplitudes of the terms of `T` over
`(c, s, c')` is at most the sum over submodules `Λ` of the same squared norms for the terms of `T`
with `𝗀 = S.termDisc ≠ 0` and link `Λ`, plus `S.unipotentCovolume ^ 2` times the sum of the products
of the sizes over the pairs of near representatives of `T` whose links differ or for one of which
`𝗀` vanishes.

The link `link γ` is the module of pairs (class of `t`, class of `γ⁻¹ t`) in `X^⊥/X`,
`X = ⟨e₁, …, e_ϱ⟩`, `t ⊥ X, γ X`. A rational point `γ` lies over `(c, s, c')` if `h_c⁻¹ γ h_c'`
(`h_c = S.classRep c`) is integral with reduction `s`. Its amplitude is the integral over the
archimedean points `y` of `β_c(y) β_c'(γ⁻¹ y) W(y) ⊗ W(γ⁻¹ y)^*`, where `β_c = S.classCutoff c` and
`W` is the cut Bessel function, the Bessel function times a cutoff in the length `besselLength` at
each infinite place. A near representative of `T` over `(c, s, c')` is a `γ ∈ T` over `(c, s, c')`
that is near (some archimedean point `y` and `γ⁻¹ y` are both reduced and of bounded size,
`S.boxedPoints`), is the chosen element of its double coset under the groups `S.classUnipotent₀` and
has a cell rank; there are none unless `S.Agrees s`. The size `S.termSize c c' γ` is
`τ² (D_j / (n_p G ^ k)) ^ (1 / 2)`, where `j = S.cellRank γ` is the index of the cell of `γ`,
`D_j = S.cellRankSecondMoment j`, `G = S.levelGauge j c c' γ` is its gauge, `n_p = S.pairCountScale`
and `τ = S.tailScale`. -/
lemma New.Filling.enorm_amplitudeSum_sq_le {E : Type} [Field E] [CMType E] {𝔰 : Shape} {S : Filling E 𝔰}
    [HasPrimitiveRoot5040 E] [S.IsAdmissible] {c c' : S.Classes} {T : Set (S.G E)}
    (hT : S.IsStable T) (h_sub : T ⊆ S.remainingTerms) (s : S.ResidueGL) :
    ‖S.amplitudeSum .cut T c s c'‖ₑ ^ 2 ≤
      ∑' Λ : Submodule E (𝔰.MiddleIndex ⊕ 𝔰.MiddleIndex → E),
        ‖S.amplitudeSum .cut (T ∩ {γ : S.G E | S.termDisc γ ≠ 0} ∩ link ⁻¹' {Λ}) c s c'‖ₑ ^ 2 +
      .ofReal (S.unipotentCovolume ^ 2) *
        ∑' q : {q ∈ S.nearRepresentativesOver T c s c' ×ˢ S.nearRepresentativesOver T c s c' |
            ¬S.InSameLinkClass q.1 q.2},
          .ofReal
            (S.termSize c c' (q : S.G E × S.G E).1 * S.termSize c c' (q : S.G E × S.G E).2) := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/RemainingTerms/Sum.lean:587-676 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=59 body_sha256=ae3379c115c13866d5e8c29f5d8ab15b4b93c1ea9d85f6c1fe6a3f1f7c7a09f0]

theorem New.Filling.secondMoment_remainingTerms_le — Upstream source (src/New/Spanning/RemainingTerms/Sum.lean L678-L744)

lean
/-- **Remaining terms, reduction to one link.** Let `E` be a CM field with a primitive root of unity
of order 5040, and let `S` be data of the filling theorem over `E` that satisfy the standing
hypotheses `S.IsAdmissible`. Let `Ω` be a set of reductions, `w ≥ 0` and `ν = S.unipotentCovolume`.
Suppose that the terms with `𝗀 = S.termDisc ≠ 0`, taken link by link, have sum of squared norms of
amplitude sums (`linkSecondMoment`) at most `w ν²` over `Ω`. Then the second moment over `Ω` of
`Γ* = S.remainingTerms`, for the cut Bessel function, is at most `w + b ^ (-k f) 𝒟_id`. -/
theorem New.Filling.secondMoment_remainingTerms_le {E : Type} [Field E] [CMType E] {𝔰 : Shape} {S : Filling E 𝔰}
    [HasPrimitiveRoot5040 E] [S.IsAdmissible] {w : ℝ} {Ω : Set S.ResidueGL} (hw : 0 ≤ w)
    (h_linkMoment : linkSecondMoment {γ : S.G E | S.termDisc γ ≠ 0} Ω ≤
      ENNReal.ofReal (w * S.unipotentCovolume ^ 2)) :
    secondMoment (S.amplitudeSum .cut S.remainingTerms) Ω ≤
      w + S.identitySecondMoment / S.b ^ (𝔰.k * numInfPlaces E) := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/RemainingTerms/Sum.lean:678-744 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=56 body_sha256=3c2af6c1bdc63690d9b604f16733a02541b507b06fdfcdae71de19bef9e095aa]

theorem New.Filling.linkSecondMoment_le_of_le_meetNorm — Upstream source (src/New/Spanning/RemainingTerms/Sum.lean L746-L837)

lean
/-- **Remaining terms, one link at a time.** Let `E` be a CM field with a primitive root of unity of
order 5040, and let `S` be data of the filling theorem over `E` that satisfy the standing hypotheses
`S.IsAdmissible`. Let `Ω` be a set of reductions, that is, of elements of `S.ResidueGL`, the product
of the general linear groups over the residue fields at the chosen places above the level `M = S.M`.
A reduction `s` meets at a place above `M` if, modulo that place, the span of the frame and its
image under `s` share a nonzero vector; `S.meetNorm s` is the norm of the product of the places at
which `s` meets. Let `z ≠ 0` be a natural number with `z ≤ S.meetNorm s` for every `s ∈ Ω`.

Let `T` be the set of rational points `γ` of the unitary group with `S.termDisc γ ≠ 0`. For classes
`c`, `c'`, a reduction `s` and a submodule `Λ`, take the sum of the amplitudes of the `γ ∈ T` that
lie over `(c, s, c')` and have link `Λ`. The squared norms of these sums, added over all `c`, `c'`,
`s ∈ Ω` and `Λ`, give `linkSecondMoment T Ω`, and this is at most `(b ^ (2 f) / z) ^ k 𝒟_main ν²`.
Here `b = S.b` is the size parameter, `k = 𝔰.k` is the dimension of the definite space, `f` is the
number of infinite places of `E`, and `𝒟_main = S.mainSecondMoment` and the covolume
`ν = S.unipotentCovolume` are real constants attached to `S`. -/
theorem New.Filling.linkSecondMoment_le_of_le_meetNorm {E : Type} [Field E] [CMType E]
    {𝔰 : Shape} {S : Filling E 𝔰} [HasPrimitiveRoot5040 E] [S.IsAdmissible]
    {Ω : Set S.ResidueGL} {z : ℕ} (hz : z ≠ 0)
    (h_meet : ∀ s ∈ Ω, z ≤ S.meetNorm s) :
    linkSecondMoment {γ : S.G E | S.termDisc γ ≠ 0} Ω ≤
      ENNReal.ofReal ((S.b ^ (2 * numInfPlaces E) / z) ^ 𝔰.k * S.mainSecondMoment *
        S.unipotentCovolume ^ 2) := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Spanning/RemainingTerms/Sum.lean:746-837 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=71 body_sha256=735a073c6fa733fa16111a4dff76e0205d67f61294b66fb7052772d763a46245]

Page Glossary ​

Kloosterman sieve
A global entry-by-entry one-sided Poisson summation engine pairing archimedean band-limited Bessel Gram matrices with finite Kloosterman densities to bound the big-cell second moment by (1 + b⁻⁴) b⁻⁶ᵏ|S_g| D_main ν².
Bessel orbital integral
An archimedean correlation integral ∫ β_c(y) β_{c'}(γ⁻¹ y) W(y) ⊗ W(γ⁻¹ y)* dy unfolding Petersson inner products P* ρ(s) P into class-indexed amplitude blocks.
prime number
A whole number greater than 1 whose only positive whole-number divisors are 1 and itself; every integer above 1 factors uniquely into a product of them.
arithmetic height
A logarithmic measure combining ordinary archimedean size with prime-by-prime p-adic divisibility, locked together by the product formula so a nonzero algebraic quantity cannot be simultaneously small at every place.
link lattice
The Hermitian sublattice shared by two rational filling terms over one reduction block, whose discriminant and Bombieri–Vaaler Siegel's lemma counts crush cross-link and non-open terms via a weighted Schur test.
Gram determinant
The determinant of the matrix of pairwise inner products of a family of vectors, measuring the squared volume of the parallelotope they span and controlled by Hadamard's and Fischer's inequalities.