Skip to content

Siegel–Weil Exchange and the Commuting Theta Square ​

This page unpacks the analytic engine at the foundation of Stage 05: src/New/Determinant/Exchange/TheoremForPartners.lean (05_determinant/theorem_for_partners, 27 declarations, 3 let-type stub truncations documented verbatim below) and src/New/Determinant/Exchange/OneSquare.lean (05_determinant/one_square, 32 declarations, 5 let-type stub truncations including all three headline square theorems, documented verbatim below). Return to the Stage 05 Overview, or continue to Chain Determinant Factorization and Two-Grid Auxiliary Forms and Regular Twist Families and the Assembly of Theorem C.

Level 1 · First-Principles

Level 1 — First-Principles ​

Before Stage 05 can factor an m-step chain of theta lifts or sweep periods across two square grids, it needs one fundamental move: trading a theta lift through a large space for a theta lift through a smaller complementary space, with exact control over how the proportionality scalar changes when we twist by a tame character ν. That move is built in two stacked steps—first for a single space W (TheoremForPartners.lean), and then for a doubled space W=U1⊕U2 (OneSquare.lean).

Side-by-side two-panel diagram contrasting complementary-rank theta exchange on the left with the doubled four-corner square on the right

Left panel: Complementary-rank theta exchange (TheoremForPartners.lean) ​

Take a Hermitian space W of even rank |n|=|a|+|b| with q negative signs, paired against two partner spaces of complementary ranksSiegel–Weil exchange: a larger partner V of rank |a|=|b|+2e and a smaller partner V′ of rank |b|, whose negative signs add up to q. Using unitary dual-pair theta kernelstheta correspondence, integrating over U(V) sends finite-prime data Φ (supported on the last |a| rows of k−1 for k∈GLn(OE/m)) to a function on U(W), while integrating over U(V′) sends finite-prime data Ψ (supported on the first |b| columns of k) to a function on U(W).

When Φ and Ψ are matched functions—satisfying Φ(x)=χ(detk)Ψ(y) for the residue character χ of a tame character ν of weight μ—the flagship exchange identity (New.Exchange.exchange_identity) proves that these two integrals are proportional pointwise on U(W):

∫[U(V)]θW,V(x⊗Φ)(g,h)dh=c∫[U(V′)]θV′,W(v⊗Ψ)(h,g)dh,

with three crucial guarantees:

  1. Real vector fixed before twisting: Given a real Schwartz vector v for (V′,W), the matching Schwartz vector x for (W,V) and a base real constant C>0 are chosen once and for all before picking any modulus m or tame character ν of weight μ.
  2. Exact L-value modulus: The proportionality constant c∈C (in the complex planecomplex plane) depends on (m,ν,χ), is guaranteed nonzero, and obeys∥c∥2=C⋅L∗(e)≠0,L∗(e)=(∏w∈Sqwe2)∏z=1e|LS(z,ν)|2,where S is the set of places dividing m and LS(z,ν) is the partial Hecke L-value omitting S∪S¯Hecke L-value ratio.
  3. Reusable beyond Stage 05: Besides feeding OneSquare.lean inside Stage 05, 05_determinant/theorem_for_partners exports exchange_identity directly to Stage 06 (06_one_lift/three_exchanges, mediated in upstream Lean by ExplicitMatching.lean).

How does TheoremForPartners.lean pin down ∥c∥2=C⋅L∗(e) with C independent of ν? First, exchange_of_matches descends from the top of a hyperbolic Witt tower and expresses C1∥c∥2 as L∗(e) times an equal-rank theta ratio |I(z)(1)|2/L∗(rk(H⊕W)/2) on H⊕W (extending L∗ to negative integers via lValueProdInt, L∗(−e)=L∗(e)−1). Applying that identity twice on a positive-definite space J of rank 2k—once with +k and once with −k—and equating the two sides by Fubini's theorem cancels L∗(k) identically, proving that the equal-rank ratio is a nonzero constant independent of ν (exists_equalRankThetaRatio_eq_const).

Right panel: The four-corner theta square (OneSquare.lean) ​

Now apply the doubling trick of seesaw dual reductive pairsseesaw duality: set W=U1⊕U2, and pair W against A (rank |n|+2t) at the top and A′ (rank |n|) at the bottom. A form f1 on U1 can travel to U2 along two routes:

  • Top route (Θi(x)): lift from U1 to A, then take the transposed lift from A to U2 using the two column blocks of a matrix x modulo mi.
  • Bottom route (Θi′(y)): take the transposed lift from U1 to A′, then lift from A′ to U2 using the two row blocks of a matrix y modulo mi.

Because the theta kernel on (U1⊕U2,A) splits as a product of the edge kernels on (U1,A) and (U2,A), integrating exchange_identity against forms f1 on U1 and f2 on U2 yields the theta square lawtheta square law (one_square_identity_of_isEdgeFamily): both routes transform by χi(detg) under invertible block matrices, and for all matched functions (Ψ,Ψ′) modulo mi,

∑yΨ′(y)Θi′(y)=κci∑xΨ(x)Θi(x),∥ci∥2=C⋅L∗(t)≠0.

Here κ∈C is independent of the index i, the character νi, the modulus mi, and the forms.

Critical mathematical honesty note on κ: one_square_identity_of_isEdgeFamily does NOT prove κ≠0! As upstream GUIDE.md §2 states explicitly, κ is independent of the character, modulus, and forms, is never computed, and is not shown nonzero in OneSquare.lean. That is completely harmless here: non-vanishing of the composite chain scalar is established later in ChainNorms.lean and NormOfChain.lean (chainDeterminant_pos) from the injectivity of the first theta lifts in the convergent range of the Rallis inner product formulaRallis inner product formula.

Where this analogy breaks ​

Drawing OneSquare.lean as a commuting diamond of arrows from U1 to U2 makes it look like Θi′=(κ/ci)Θi as individual maps with a known nonzero ratio. Both impressions break in the real proof. First, individual point-matrix lifts never commute on their own—commutation holds only after summing over matched functions (Ψ,Ψ′) over the finite residue ring OE/mi, where left- and right-GL equivariance by χi∘det ties the blocks together (SquareLaw). Second, passing from polynomial Fock vectors to the abstract Schwartz vector w delivered by exchange_identity via moment-Lipschitz density (exists_eq_mul_of_forall_polyVector) gives a single twist-independent limit κ without certifying κ≠0.

Level 2 · Undergrad Bridge

Level 2 — Undergrad Bridge ​

1. Complementary-rank exchange (TheoremForPartners.lean, 27 decls) ​

  1. Adjoint coordinates and flipping U (adjointCoords, adjointCoords_finEquiv_apply, adjointDatum, IsSchwartzVector.adjointDatum, neg_mem_flipSpace_Gamma_iff, AreMatched.right_eq_pow_mul_apply_smul): Passing from (U,W) to (W,U−) (where U−=flipSpaceU negates the signs u↦−u) acts on finite adelic matrices by conjugate transpose times the integral unit normNegOne of norm −1. exists_localDatum_adjointDatum_eq_smul and exists_mul_thetaSmall_adjointDatum_eq_mul_integral convert thetaSmall on (W,U−) into the integral of pairTheta on (U,W) up to a complex scalar d of modulus 1.
  2. From standard data to matched functions (thetaLarge_eq_smul_of_areMatched, exists_rowColExchangeIdentity_of_even_rank, exchange_of_matches): On standard determinant data (stdRowDatum σ χ z, stdColDatum χ z), removing hyperbolic planes from W0=H⊕W (RemovingPlanes.lean) proves exists_rowColExchangeIdentity_of_even_rank. Expanding any locally constant matched pair (Φ,Ψ) in translates of standard data (thetaLarge_eq_smul_of_areMatched) and flipping U− back to U yields exchange_of_matches:C∥c∥2=lValueProdInt c (|r|−|n|/2)⋅equalRankThetaRatio(H⊕W,c,z),where lValueProdInt extends lValueProd to Z via L∗(−e)=L∗(e)−1.
  3. Why the equal-rank theta ratio is a nonzero constant (integral_thetaOnRealData_eq_zero, thetaLargeVanishes_of_equalRankThetaRatio_eq_zero, exists_equalRankThetaRatio_ne_zero, eq_mul_of_integral_pairTheta, exists_thetaLarge_eq_mul_quotMeasure, exists_quotMeasure_mul_eq_mul_integral_pairTheta, exists_equalRankThetaRatio_sq_eq, exists_equalRankThetaRatio_const_ne_zero, exists_equalRankThetaRatio_add_plane, equalRankThetaRatio_eq_of_signs_eq, exists_equalRankThetaRatio_eq_const):
    • For positive-definite J of rank 2k: applying exchange_of_matches to (J,J,0) gives B|c1|2=L∗(k)R(c) and thetaLarge(J,J)=c1⋅vol([U(0)]) (exists_thetaLarge_eq_mul_quotMeasure); applying it to (J,0,J) gives C|c2|2=L∗(−k)R(c) and vol([U(0)])ξ=c2∫pairTheta (exists_quotMeasure_mul_eq_mul_integral_pairTheta).
    • By Fubini's theorem on the compact quotient [U(J)]×[U(J)] (eq_mul_of_integral_pairTheta), vol⋅ξ=c2⋅c1⋅vol, so |c1c2|2=|ξ|2 is independent of c. Multiplying the two norm equations cancels L∗(k)L∗(−k)=1, forcing R(c)2=const (exists_equalRankThetaRatio_sq_eq).
    • Non-vanishing for k≤μ (exists_equalRankThetaRatio_ne_zero, proved by contrapositive via thetaLargeVanishes_of_equalRankThetaRatio_eq_zero and VanishingDescends.lean) plus hyperbolic-plane induction (exists_equalRankThetaRatio_add_plane) proves exists_equalRankThetaRatio_eq_const: for rkW=2k+2q and k≤μ, some Schwartz vector z on H⊕W has equalRankThetaRatio equal to a single constant C0≠0 across all tame characters of weight μ.
  4. Mod-m matching and arbitrary splitting characters (spaceChar_mul_spaceChar_eq_iff, exists_areMatched_modDatum_eq, exchange_theorem, exchange_identity): Lifting matched functions over OE/m to local completions (exists_areMatched_modDatum_eq) and plugging in the constant-C0 vector z yields exchange_theorem (with characters γ,1 vs. γ,γ), and spaceChar_mul_spaceChar_eq_iff generalizes to arbitrary splitting characters α,α′ with α.spaceChar|a|⋅α′.spaceChar|b|=ν.baseChange−1 in New.Exchange.exchange_identity.

2. The commuting theta square (OneSquare.lean, 32 decls) ​

  1. Equivariance and support of matched functions (pairWeil_modDatum_single_mul_left, pairWeil_modDatum_single_mul_right, hasLeftInv_transpose_of_areMatched, hasLeftInv_of_areMatched, IsTameFor.exists_inv_rankTwist_inv): Matched (Ψ,Ψ′) over OE/m force Ψ to live on onto matrices (HasLeftInv xᵀ) and Ψ′ to live on left-invertible matrices (HasLeftInv y), ensuring convergence of the theta integrals on both sides.
  2. Integrability, Fock-moment Lipschitz control, and polynomial density (exists_integrable_kernel_bound, exists_eq_mul_of_forall_polyVector, upIntegrand, downIntegrand, exists_upIntegrand_bound, integrable_upIntegrand, exists_norm_integral_upIntegrand_sub_le, integrable_downIntegrand): Rapidly decreasing cusp forms f1∈U1.rapidFunctions, f2∈U2.rapidFunctions absorb the polynomial height growth of the theta kernel on U1⊕U2, making upIntegrand integrable and Lipschitz in fockMoment N w.
  3. Kernel splitting and passing to arbitrary Schwartz vectors (modKernel_single_sum_left, modKernel_single_sum_right, integral_upIntegrand, integral_downIntegrand, integral_sum_upIntegrand_eq_mul, exists_integral_upIntegrand_eq_mul_integral_lift): On Fock polynomials P1⋅P2, the kernel on U1⊕U2 splits into the product of the two edge kernels (integral_upIntegrand, integral_downIntegrand). Applying exists_eq_mul_of_forall_polyVector extends that proportionality to the Schwartz vector w returned by exchange_identity, yielding the twist-independent scalar κ∈C (possibly 0).
  4. Equivariance + matched sum ⇒ SquareLaw (pairTransposedLift_comp_pairLift_mul, pairLift_comp_pairTransposedLift_mul, IsSquare, exists_sum_pairLift_comp_pairTransposedLift_eq_smul, equivariant_and_exists_sum_eq_of_areMatched, one_square_identity_of_isEdgeFamily): Integrating integral_sum_upIntegrand_eq_mul over [U1]×[U2] against (f1,z¯) yields κ∑Ψ(x)⟨z,Θi(x)f1⟩=ci∑Ψ′(y)⟨z,Θi′(y)f1⟩. Dividing by ci≠0 (ne_zero_of_norm_sq_eq) proves exists_sum_pairLift_comp_pairTransposedLift_eq_smul, joins it with GL-equivariance in equivariant_and_exists_sum_eq_of_areMatched, and packages the two-family case into SquareLaw (χ i) σ (κ / c) in New.Exchange.one_square_identity_of_isEdgeFamily.
Level 3 · Formal Lean Contract

Level 3 — Formal Lean Contract ​

The extracted skeletons skeleton/05_determinant/theorem_for_partners.lean (27 declarations, 3 stub truncations) and skeleton/05_determinant/one_square.lean (32 declarations, 5 stub truncations) mirror src/New/Determinant/Exchange/TheoremForPartners.lean and src/New/Determinant/Exchange/OneSquare.lean at pinned upstream commit 41c2716658c42ba08eb0648994a2efe83082a95c.

Critical Honesty Disclosure: All 8 let-Type Stub Truncations (theorem_for_partners.lean [3] & one_square.lean [5]) ​

Because rh-extract splits declaration signatures from proof bodies at the first depth-0 := token, every declaration that introduces a let ... := binding inside its return type truncates immediately at that let binding in the extracted skeleton (replaced by := by sorry). In Stage 05 Exchange, this affects 3 lemmas in theorem_for_partners.lean (exchange_of_matches L138, exists_quotMeasure_mul_eq_mul_integral_pairTheta L248, exchange_theorem L368 — whereas exchange_identity at L389 extracts completely untruncated) and 5 declarations in one_square.lean (exists_integrable_kernel_bound L73, exists_norm_integral_upIntegrand_sub_le L198, and all three headline square theorems: exists_sum_pairLift_comp_pairTransposedLift_eq_smul L449, equivariant_and_exists_sum_eq_of_areMatched L505, and one_square_identity_of_isEdgeFamily L544).

For complete mathematical accuracy, all 8 exact untruncated statements from pinned upstream commit 41c2716658c4 are quoted verbatim below:

A. Three truncated lemmas in TheoremForPartners.lean ​

lean
-- 1. Upstream: src/New/Determinant/Exchange/TheoremForPartners.lean:325-342
-- (truncated at `let γ : AutChar E :=` in skeleton/05_determinant/theorem_for_partners.lean:138)
lemma exchange_of_matches (W : Space E n s) (U : Space E b u) (μ : InfinitePlace E → ℤ)
    (V : Space E r t) (σ : b ⊕ r ≃ n)
    {z : PairFock E (hyperbolicSigns Unit ⊕ᵥ s) (hyperbolicSigns Unit ⊕ᵥ s)} {y : PairFock E u s}
    (hz : IsSchwartzVector z) (hy : IsSchwartzVector y)
    (h_signs : negCount s = negCount t + negCount u) (h_even : 2 ∣ card n) :
    ∃ (C : ℝ) (v : PairFock E s t), IsSchwartzVector v ∧ ∀ 𝔠 : SplitTameChar E μ,
      let γ : AutChar E := rankTwist 𝔠.character⁻¹ n
      ∃ c : ℂ,
        -- (a) the modulus of the constant
        C * ‖c‖ ^ 2 =
          lValueProdInt 𝔠 (card r - card n / 2) * equalRankThetaRatio (hyperbolicSum Unit W) 𝔠 z ∧
        -- (b) the identity of theta integrals, for all matched functions
        ∀ (Φ : Matrix r n (LocProd 𝔠.ramifiedPlaces) → ℂ)
          (Ψ : Matrix n b (LocProd 𝔠.ramifiedPlaces) → ℂ),
          IsLocallyConstant Ψ → AreMatched SemilocalField.O σ 𝔠.semilocalChar Φ Ψ → ∀ g : G E s,
          thetaIntegral W V γ 1 (localDatum W V v Φ 𝔠.readsAt) g =
            c * ∫ h : G E u, pairTheta U W γ γ (localDatum U W y Ψ 𝔠.readsAt) (h, g)
              ∂U.quotMeasure

-- 2. Upstream: src/New/Determinant/Exchange/TheoremForPartners.lean:646-657
-- (truncated at `let γ : AutChar E :=` in skeleton/05_determinant/theorem_for_partners.lean:248)
lemma exists_quotMeasure_mul_eq_mul_integral_pairTheta (μ : InfinitePlace E → ℤ) {k : ℕ}
    (hm : card m = 2 * k) (J : Space E m 1)
    {v : PairFock E (Sum.elim (hyperbolicSigns Unit) (1 : m → ℤˣ))
      (Sum.elim (hyperbolicSigns Unit) (1 : m → ℤˣ))}
    {y : PairFock E (1 : m → ℤˣ) 1} (hv : IsSchwartzVector v) (hy : IsSchwartzVector y) :
    ∃ (C : ℝ) (ξ : ℂ), ∀ 𝔠 : SplitTameChar E μ,
      let γ : AutChar E := rankTwist 𝔠.character⁻¹ m
      ∃ c : ℂ,
        C * ‖c‖ ^ 2 = lValueProdInt 𝔠 (-k) * equalRankThetaRatio (hyperbolicSum Unit J) 𝔠 v ∧
        ∀ g : G E (1 : m → ℤˣ), (stdSpace E Empty).quotMeasure.real Set.univ * ξ =
          c * ∫ h : G E (1 : m → ℤˣ), pairTheta J J γ γ
            (localDatum J J y (stdColDatum 𝔠.semilocalChar 1) 𝔠.readsAt) (h, g) ∂J.quotMeasure

-- 3. Upstream: src/New/Determinant/Exchange/TheoremForPartners.lean:985-1003
-- (truncated at `let γ : AutChar E :=` in skeleton/05_determinant/theorem_for_partners.lean:368)
lemma exchange_theorem (σ : b ⊕ a ≃ n) (h_signs : negCount s = negCount t + negCount t') {e : ℕ}
    (h_rank : card a = card b + 2 * e) (h_few_neg : 2 * negCount s + 2 ≤ card n)
    {μ : NumberField.InfinitePlace E → ℤ}
    (hμ : ∀ τ : NumberField.InfinitePlace E, card n ≤ 2 * μ τ + 2 * negCount s)
    {v : Fock.fockSpace (realSigns E (homSigns t' s))} (hv : IsSchwartzVector v) :
    ∃ (C : ℝ) (x : Fock.fockSpace (realSigns E (homSigns s t))),
      IsSchwartzVector x ∧
      ∀ (𝔪 : Modulus E) (ν : AutChar E) (χ : MulChar 𝔪.ResidueRing ℂ), IsTameFor 𝔪 ν μ χ →
        let γ : AutChar E := rankTwist ν⁻¹ n
        ∃ c ≠ (0 : ℂ),
          -- (a) the size of the constant
          ‖c‖ ^ 2 = C * lValueProd 𝔪.places ν e ∧
          -- (b) the exchange of the two theta integrals on matched functions modulo `𝔪`
          ∀ (Φ : Matrix a n 𝔪.ResidueRing → ℂ) (Ψ : Matrix n b 𝔪.ResidueRing → ℂ),
            AreMatched ⊤ σ χ Φ Ψ →
            ∀ g : G E s,
            thetaIntegral W V γ 1 (modDatum W V 𝔪 Φ x) g =
              c *
                ∫ h : G E t', pairTheta V' W γ γ (modDatum V' W 𝔪 Ψ v) (h, g) ∂V'.quotMeasure

B. Five truncated declarations in OneSquare.lean (including all three headline square theorems) ​

lean
-- 4. Upstream: src/New/Determinant/Exchange/OneSquare.lean:156-167
-- (truncated at `let F : ... :=` in skeleton/05_determinant/one_square.lean:73)
lemma exists_integrable_kernel_bound {A : Space E n' s'} {U₁ : Space E n₁ s₁}
    {U₂ : Space E n₂ s₂} {φ₁ : G E s₁ → ℂ} {φ₂ : G E s₂ → ℂ} (hφ₁ : φ₁ ∈ U₁.rapidFunctions)
    (hφ₂ : φ₂ ∈ U₂.rapidFunctions) (ν₀ : AutChar E)
    {K : fockSpace s → G E (s₁ ⊕ᵥ s₂) → G E s' → ℂ}
    (hK_le : ∃ (B N : ℕ) (C : ℝ), ∀ (v : fockSpace s) (g : G E (s₁ ⊕ᵥ s₂)) (z : G E s'),
      fockMoment N v ≠ ⊤ → ‖K v g z‖ ≤ C * (fockMoment N v).toReal * (U₁.sum U₂).height g ^ B)
    (hK_cont : ∀ v : fockSpace s, Continuous ↿(K v)) :
    ∃ (N : ℕ) (C : ℝ), ∀ v : fockSpace s, fockMoment N v ≠ ⊤ →
      let F : (G E s₁ × G E s₂) × G E s' → ℂ := fun ((g₁, g₂), z) ↦
        φ₁ g₁ * φ₂ g₂ * (ν₀.val g₂.det * K v (G.sum (g₁, g₂)) z)
      Integrable F ((U₁.quotMeasure.prod U₂.quotMeasure).prod A.quotMeasure) ∧
      ∀ q : (G E s₁ × G E s₂) × G E s', ‖F q‖ ≤ C * (fockMoment N v).toReal

-- 5. Upstream: src/New/Determinant/Exchange/OneSquare.lean:350-359
-- (truncated at `let μA : ... :=` in skeleton/05_determinant/one_square.lean:198)
lemma exists_norm_integral_upIntegrand_sub_le (h𝔪 : Nonempty 𝔪.places)
    (hf₁ : f₁ ∈ U₁.rapidFunctions) (hf₂ : f₂ ∈ U₂.rapidFunctions)
    {x : Matrix n' (n₁ ⊕ n₂) 𝔪.ResidueRing} (hx : HasLeftInv xᵀ) :
    let μA : Measure ((G E s₁ × G E s₂) × G E s') :=
      (U₁.quotMeasure.prod U₂.quotMeasure).prod A.quotMeasure
    ∃ (N : ℕ) (D : ℝ), ∀ v v' : PairFock E (s₁ ⊕ᵥ s₂) s',
      fockMoment N v ≠ ⊤ → fockMoment N v' ≠ ⊤ → fockMoment N (v' - v) ≠ ⊤ →
      ‖∫ q : (G E s₁ × G E s₂) × G E s', upIntegrand A U₁ U₂ ν₀ γ b f₁ f₂ x v q ∂μA -
          ∫ q : (G E s₁ × G E s₂) × G E s', upIntegrand A U₁ U₂ ν₀ γ b f₁ f₂ x v' q ∂μA‖ ≤
        D * (fockMoment N (v' - v)).toReal

-- 6. Upstream: src/New/Determinant/Exchange/OneSquare.lean:747-771
-- (truncated at `let Θ ... :=` in skeleton/05_determinant/one_square.lean:449)
theorem exists_sum_pairLift_comp_pairTransposedLift_eq_smul
    (A' : Space E n s) (A : Space E n' s') (U₁ : Space E n₁ s₁) (U₂ : Space E n₂ s₂)
    {I : Type*} {e : GInf E s' → ℂ} {e' : GInf E s → ℂ} {e₁ : GInf E s₁ → ℂ} {e₂ : GInf E s₂ → ℂ}
    {a₁ a₂ b₁ b₂ a₁' a₂' b₁' b₂' : I → AutChar E}
    {P₁ : MvPolynomial (InfinitePlace E × n' × n₁) ℂ}
    {P₂ : MvPolynomial (InfinitePlace E × n' × n₂) ℂ}
    {P₁' : MvPolynomial (InfinitePlace E × n₁ × n) ℂ}
    {P₂' : MvPolynomial (InfinitePlace E × n₂ × n) ℂ} (σ : n ⊕ n' ≃ n₁ ⊕ n₂) {t : ℕ}
    {μ : InfinitePlace E → ℤ} {𝔪 : I → Modulus E} {ν : I → AutChar E}
    {χ : ∀ i : I, MulChar (𝔪 i).ResidueRing ℂ}
    (h_square : IsSquare e e' e₁ e₂ a₁ a₂ b₁ b₂ a₁' a₂' b₁' b₂' P₁ P₂ P₁' P₂' t μ 𝔪 ν χ) :
    let Θ (i : I) (x : Matrix n' (n₁ ⊕ n₂) (𝔪 i).ResidueRing) : U₁.Form e₁ →ₗ[ℂ] U₂.Form e₂ :=
      pairTransposedLift U₂ A (a₂ i) (b₂ i) P₂ (Pi.single x.toCols₂ 1) e e₂ ∘ₗ
        pairLift U₁ A (a₁ i) (b₁ i) P₁ (Pi.single x.toCols₁ 1) e₁ e
    let Θ' (i : I) (y : Matrix (n₁ ⊕ n₂) n (𝔪 i).ResidueRing) : U₁.Form e₁ →ₗ[ℂ] U₂.Form e₂ :=
      pairLift A' U₂ (b₂' i) (a₂' i) P₂' (Pi.single y.toRows₂ 1) e' e₂ ∘ₗ
        pairTransposedLift A' U₁ (b₁' i) (a₁' i) P₁' (Pi.single y.toRows₁ 1) e₁ e'
    ∃ C : ℝ, 0 < C ∧ ∃ κ : ℂ, ∀ i : I, ∃ c : ℂ,
      ‖c‖ ^ 2 = C * lValueProd (𝔪 i).places (ν i) t ∧
      C * lValueProd (𝔪 i).places (ν i) t ≠ 0 ∧
      ∀ (Ψ : Matrix n' (n₁ ⊕ n₂) (𝔪 i).ResidueRing → ℂ)
        (Ψ' : Matrix (n₁ ⊕ n₂) n (𝔪 i).ResidueRing → ℂ),
        AreMatched ⊤ σ (χ i) Ψ Ψ' →
          ∑ y : Matrix (n₁ ⊕ n₂) n (𝔪 i).ResidueRing, Ψ' y • Θ' i y =
            (κ / c) • ∑ x : Matrix n' (n₁ ⊕ n₂) (𝔪 i).ResidueRing, Ψ x • Θ i x

-- 7. Upstream: src/New/Determinant/Exchange/OneSquare.lean:896-929
-- (truncated at `let Θ ... :=` in skeleton/05_determinant/one_square.lean:505)
theorem equivariant_and_exists_sum_eq_of_areMatched {E n n' n₁ n₂ : Type} [Field E] [CMType E]
    [WeilData E] [Fintype n] [DecidableEq n] [Fintype n'] [DecidableEq n']
    [Fintype n₁] [DecidableEq n₁] [Fintype n₂] [DecidableEq n₂]
    {s : n → ℤˣ} {s' : n' → ℤˣ} {s₁ : n₁ → ℤˣ} {s₂ : n₂ → ℤˣ}
    (A' : Space E n s) (A : Space E n' s') (U₁ : Space E n₁ s₁) (U₂ : Space E n₂ s₂) {I : Type*}
    {e : GInf E s' → ℂ} {e' : GInf E s → ℂ} {e₁ : GInf E s₁ → ℂ} {e₂ : GInf E s₂ → ℂ}
    {a₁ a₂ b₁ b₂ a₁' a₂' b₁' b₂' : I → AutChar E}
    {P₁ : MvPolynomial (InfinitePlace E × n' × n₁) ℂ}
    {P₂ : MvPolynomial (InfinitePlace E × n' × n₂) ℂ}
    {P₁' : MvPolynomial (InfinitePlace E × n₁ × n) ℂ}
    {P₂' : MvPolynomial (InfinitePlace E × n₂ × n) ℂ} (σ : n ⊕ n' ≃ n₁ ⊕ n₂) {t : ℕ}
    {μ : InfinitePlace E → ℤ} {𝔪 : I → Modulus E} {ν : I → AutChar E}
    {χ : ∀ i : I, MulChar (𝔪 i).ResidueRing ℂ}
    (h_square : IsSquare e e' e₁ e₂ a₁ a₂ b₁ b₂ a₁' a₂' b₁' b₂' P₁ P₂ P₁' P₂' t μ 𝔪 ν χ) :
    let Θ (i : I) (x : Matrix n' (n₁ ⊕ n₂) (𝔪 i).ResidueRing) : U₁.Form e₁ →ₗ[ℂ] U₂.Form e₂ :=
      pairTransposedLift U₂ A (a₂ i) (b₂ i) P₂ (Pi.single x.toCols₂ 1) e e₂ ∘ₗ
        pairLift U₁ A (a₁ i) (b₁ i) P₁ (Pi.single x.toCols₁ 1) e₁ e
    let Θ' (i : I) (y : Matrix (n₁ ⊕ n₂) n (𝔪 i).ResidueRing) : U₁.Form e₁ →ₗ[ℂ] U₂.Form e₂ :=
      pairLift A' U₂ (b₂' i) (a₂' i) P₂' (Pi.single y.toRows₂ 1) e' e₂ ∘ₗ
        pairTransposedLift A' U₁ (b₁' i) (a₁' i) P₁' (Pi.single y.toRows₁ 1) e₁ e'
    -- (a)
    (∀ (i : I) (g : GL n' (𝔪 i).ResidueRing) (x : Matrix n' (n₁ ⊕ n₂) (𝔪 i).ResidueRing),
      Θ i (g.val * x) = χ i g.val.det • Θ i x) ∧
    (∀ (i : I) (g : GL n (𝔪 i).ResidueRing) (y : Matrix (n₁ ⊕ n₂) n (𝔪 i).ResidueRing),
      Θ' i (y * g.val) = χ i g.val.det • Θ' i y) ∧
    -- (b)
    ∃ C : ℝ, 0 < C ∧ ∃ κ : ℂ, ∀ i : I, ∃ c : ℂ,
      ‖c‖ ^ 2 = C * lValueProd (𝔪 i).places (ν i) t ∧
      C * lValueProd (𝔪 i).places (ν i) t ≠ 0 ∧
      ∀ (Ψ : Matrix n' (n₁ ⊕ n₂) (𝔪 i).ResidueRing → ℂ)
        (Ψ' : Matrix (n₁ ⊕ n₂) n (𝔪 i).ResidueRing → ℂ),
        AreMatched ⊤ σ (χ i) Ψ Ψ' →
          ∑ y : Matrix (n₁ ⊕ n₂) n (𝔪 i).ResidueRing, Ψ' y • Θ' i y =
            (κ / c) • ∑ x : Matrix n' (n₁ ⊕ n₂) (𝔪 i).ResidueRing, Ψ x • Θ i x

-- 8. Upstream: src/New/Determinant/Exchange/OneSquare.lean:972-1003
-- (truncated at `let Θ ... :=` in skeleton/05_determinant/one_square.lean:544)
lemma one_square_identity_of_isEdgeFamily (A' : Space E n s) (A : Space E n' s')
    (U₁ : Space E n₁ s₁) (U₂ : Space E n₂ s₂) {I : Type*}
    {k₁ : Bool → GInf E s₁ → ℂ} {k₂ : Bool → GInf E s₂ → ℂ} {d : Bool}
    {k : Bool → GInf E s' → ℂ} {Φ₁ : MvPolynomial (InfinitePlace E × n' × n₁) ℂ}
    {Φ₂ : MvPolynomial (InfinitePlace E × n' × n₂) ℂ} {k' : Bool → GInf E s → ℂ}
    {Φ₁' : MvPolynomial (InfinitePlace E × n₁ × n) ℂ}
    {Φ₂' : MvPolynomial (InfinitePlace E × n₂ × n) ℂ}
    {a b : I → ∀ (m : Type) [Fintype m], AutChar E} {ν : I → AutChar E} {𝔪 : I → Modulus E}
    {χ : ∀ i : I, MulChar (𝔪 i).ResidueRing ℂ}
    (h₂ : IsEdgeFamily b k₂ k d Φ₂) (h₁ : IsEdgeFamily a k₁ k (!d) Φ₁)
    (h₂' : IsEdgeFamily a k' k₂ (!d) Φ₂') (h₁' : IsEdgeFamily b k' k₁ d Φ₁') (σ : n ⊕ n' ≃ n₁ ⊕ n₂)
    (h_signs : negCount (s₁ ⊕ᵥ s₂) = negCount s' + negCount s) (t : ℕ)
    (h_rank : card n' = card n + 2 * t) (h_few_neg : 2 * negCount (s₁ ⊕ᵥ s₂) + 2 ≤ card (n₁ ⊕ n₂))
    {μ : InfinitePlace E → ℤ}
    (hμ : ∀ τ : InfinitePlace E, card (n₁ ⊕ n₂) ≤ 2 * μ τ + 2 * negCount (s₁ ⊕ᵥ s₂))
    (h_tame : ∀ i : I, IsTameFor (𝔪 i) (ν i) μ (χ i))
    (h_chars : ∀ (i : I) {p q : Type} [Fintype p] [Fintype q],
      card p + card q = card n₁ + card n₂ → a i p * b i q = rankTwist (ν i)⁻¹ (n₁ ⊕ n₂)) :
    let Θ (i : I) (x : Matrix n' (n₁ ⊕ n₂) (𝔪 i).ResidueRing) :
        U₁.Form (k₁ !d) →ₗ[ℂ] U₂.Form (k₂ !d) :=
      modTransposedLift U₂ A (b i) Φ₂ (Pi.single x.toCols₂ 1) (k !d) (k₂ !d) ∘ₗ
        modLift U₁ A (a i) Φ₁ (Pi.single x.toCols₁ 1) (k₁ !d) (k !d)
    let Θ' (i : I) (y : Matrix (n₁ ⊕ n₂) n (𝔪 i).ResidueRing) :
        U₁.Form (k₁ !d) →ₗ[ℂ] U₂.Form (k₂ !d) :=
      modLift A' U₂ (a i) Φ₂' (Pi.single y.toRows₂ 1) (k' !d) (k₂ !d) ∘ₗ
        modTransposedLift A' U₁ (b i) Φ₁' (Pi.single y.toRows₁ 1) (k₁ !d) (k' !d)
    ∃ (C : ℝ) (κ : ℂ), ∀ i : I, ∃ c : ℂ,
      c ≠ 0 ∧
      ‖c‖ ^ 2 = C * lValueProd (𝔪 i).places (ν i) t ∧
      ∀ (f : U₁.Form (k₁ !d)) (l : U₂.Form (k₂ !d) →ₗ[ℂ] ℂ),
        SquareLaw (χ i) σ (κ / c) (fun x : Matrix n' (n₁ ⊕ n₂) (𝔪 i).ResidueRing ↦ l (Θ i x f))
          (fun y : Matrix (n₁ ⊕ n₂) n (𝔪 i).ResidueRing ↦ l (Θ' i y f))

Untruncated Flagship Signature (exchange_identity) ​

From skeleton/05_determinant/theorem_for_partners.lean:389-407 (upstream TheoremForPartners.lean:1051-1113):

lean
theorem New.Exchange.exchange_identity (σ : b ⊕ a ≃ n) (h_signs : negCount s = negCount t + negCount t')
    {e : ℕ} (h_rank : card a = card b + 2 * e) (h_few_neg : 2 * negCount s + 2 ≤ card n)
    {μ : NumberField.InfinitePlace E → ℤ}
    (hμ : ∀ τ : NumberField.InfinitePlace E, card n ≤ 2 * μ τ + 2 * negCount s)
    {v : PairFock E t' s} (hv : IsSchwartzVector v) :
    ∃ C : ℝ, 0 < C ∧ ∃ x : PairFock E s t, IsSchwartzVector x ∧
      ∀ (𝔪 : Modulus E) (ν : AutChar E) (χ : MulChar 𝔪.ResidueRing ℂ), IsTameFor 𝔪 ν μ χ →
      ∃ c : ℂ,
        ‖c‖ ^ 2 = C * lValueProd 𝔪.places ν e ∧
        C * lValueProd 𝔪.places ν e ≠ 0 ∧
        ∀ α α' : AutChar E,
          α.spaceChar (card a) * α'.spaceChar (card b) = ν.baseChange⁻¹ →
          ∀ (Φ : Matrix a n 𝔪.ResidueRing → ℂ) (Ψ : Matrix n b 𝔪.ResidueRing → ℂ),
            AreMatched ⊤ σ χ Φ Ψ →
            ∀ g : G E s,
              thetaIntegral W V (rankTwist ν⁻¹ n) α (modDatum W V 𝔪 Φ x) g =
                c * ∫ h : G E t',
                  pairTheta V' W α' (rankTwist ν⁻¹ n) (modDatum V' W 𝔪 Ψ v) (h, g)
                  ∂V'.quotMeasure
  • 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 TheoremForPartners.lean nor OneSquare.lean has been locally compiled, kernel-checked, or statically scanned here.

abbrev New.Exchange.adjointCoords — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L88-L92)

lean
/-- Passing to adjoint maps: the change of coordinates that carries data for the pair `(U, W)` to
data for `(W, U⁻)`. Here `W` has signs `s`, `U` has signs `u` and the opposite space `U⁻` has
signs `-u`. -/
abbrev New.Exchange.adjointCoords : CoordChange E (.id ℂ) (homSigns u s) (homSigns s (-u)) := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:88-92 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=1 body_sha256=cb4e727552edc279ad48655928e40d25534d6cf369aeb4e187b6c092b42bf7ea]

lemma New.Exchange.adjointCoords_finEquiv_apply — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L94-L98)

lean
/-- On finite adelic matrices `adjointCoords` is the conjugate transpose, scaled by the integral
unit `normNegOne` of norm `-1`. -/
lemma New.Exchange.adjointCoords_finEquiv_apply (x : b × n → 𝔸f E) (i : n × b) :
    (adjointCoords E s u).finEquiv x i = (normNegOne (E := E) : Ô E) * star (x i.swap) := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:94-98 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=1 body_sha256=8fd55f0f44bbc477f43ecdbab9916420f312d687b202a5a69fcfd2d701c19bde]

def New.Exchange.adjointDatum — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L100-L102)

lean
/-- The real vector `y^ad` for `(W, U⁻)` that belongs to a real vector `y` for `(U, W)`: the image
of `y` under the real part of `adjointCoords`. -/
def New.Exchange.adjointDatum (y : PairFock E u s) : PairFock E s (-u) := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:100-102 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=1 body_sha256=d75d0f5c3f67f749c34daedf63e21ce20f908dd3b906e1b216e54442e4f2ec51]

lemma New.Exchange.IsSchwartzVector.adjointDatum — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L104-L127)

lean
/-- Let `U`, `W` have signs `u`, `s` and let `y` be a vector of the real Fock space of `(U, W)` all
of whose moments are finite. Then so are all moments of `adjointDatum y`, the vector for `(W, U⁻)`
obtained by passing to adjoint maps; the opposite space `U⁻` has signs `-u`. -/
lemma New.Exchange.IsSchwartzVector.adjointDatum {y : PairFock E u s} (hy : IsSchwartzVector y) :
    IsSchwartzVector (adjointDatum y) := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:104-127 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=20 body_sha256=24c71794b198360be31f21d5e2e6a70d25051c343d3734bfee3fffff2c35b8fc]

lemma New.Exchange.neg_mem_flipSpace_Gamma_iff — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L129-L134)

lean
/-- `New.G.neg` carries the rational points of `U` onto those of the opposite space
`U⁻ = flipSpace U`. -/
lemma New.Exchange.neg_mem_flipSpace_Gamma_iff (U : Space E b u) (g : G E u) :
    G.neg g ∈ (flipSpace U).Γ ↔ g ∈ U.Γ := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:129-134 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=3 body_sha256=912227e6d7f5e51d5093e315ed78db1ad65f98935743c2421bf42f4274b2ade1]

lemma New.AreMatched.right_eq_pow_mul_apply_smul — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L136-L144)

lean
/-- Multiplying the argument by a unit `ε` of `O` divides the second of two matched functions by
`χ ε ^ card b`, the value of `χ` at the determinant of the scalar matrix `ε` of size `b`. -/
lemma New.AreMatched.right_eq_pow_mul_apply_smul {R : Type} [CommRing R] {O : Subring R}
    {σ : b ⊕ r ≃ n} {χ : MulChar R ℂ} {Φ : Matrix r n R → ℂ} {Ψ : Matrix n b R → ℂ}
    (h : AreMatched O σ χ Φ Ψ) (ε : Oˣ) (X : Matrix n b R) :
    Ψ X = χ ε ^ card b * Ψ ((ε.val : R) • X) := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:136-144 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=4 body_sha256=9456cb95510c7732e0fe010d75ae129b1decb204a519323b9031ed1b88a9d956]

lemma New.Exchange.exists_localDatum_adjointDatum_eq_smul — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L146-L194)

lean
/-- Let `σ` split `n` into `b` and `r`, let `𝔠` be a tame character: a character `ν = 𝔠.character`
of `[U(1)]` of weight `μ`, tamely ramified exactly at a finite set `S = 𝔠.ramifiedPlaces` of split
places, and let `y` lie in the real Fock space of `(U, W)`. There is a number `a` of modulus one
with the following property. Let `Ψ` be a Schwartz–Bruhat function on left invertible matrices that
is matched with some `Φ`: `Φ` is supported on the last rows of `k⁻¹` and `Ψ` on the first columns of
`k` (split by `σ`), for `k` in `GL_n` of the local integers at `S`, and there
`Φ = 𝔠.semilocalChar (det k) * Ψ`. Let `U⁻ = flipSpace U` be the opposite space, `adjointCoords` the
passage to adjoint maps from `(U, W)` to `(W, U⁻)`, and `y^ad = adjointDatum y` the image of `y`.
Then the datum with real part `y^ad`, the function `x ↦ Ψ xᵀ` at the conjugates of `S`
(`𝔠.readsAt.star`) and the vacuum elsewhere is `a` times the image of the datum with real part `y`,
the function `Ψ` at `S` (`𝔠.readsAt`) and the vacuum elsewhere. -/
lemma New.Exchange.exists_localDatum_adjointDatum_eq_smul (W : Space E n s) (U : Space E b u) (σ : b ⊕ r ≃ n)
    {μ : InfinitePlace E → ℤ} (𝔠 : SplitTameChar E μ) (y : PairFock E u s) :
    ∃ a : ℂ, ‖a‖ = 1 ∧ ∀ (Φ : Matrix r n (LocProd 𝔠.ramifiedPlaces) → ℂ)
      (Ψ : Matrix n b (LocProd 𝔠.ramifiedPlaces) → ℂ),
      Ψ ∈ schwartzBruhat {y | HasLeftInv y} → AreMatched SemilocalField.O σ 𝔠.semilocalChar Φ Ψ →
        localDatum W (flipSpace U) (adjointDatum y)
            (fun x : Matrix b n (LocProd 𝔠.ramifiedPlaces) ↦ Ψ xᵀ) 𝔠.readsAt.star =
          a • (adjointCoords E s u).map (localDatum U W y Ψ 𝔠.readsAt) := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:146-194 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=31 body_sha256=ccd3d0b809100c52e0cb7a60dfc34e7e76e3097d45ecebbdfa1281d9d6dcfb6b]

lemma New.Exchange.exists_mul_thetaSmall_adjointDatum_eq_mul_integral — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L196-L236)

lean
/-- Let `W` have even rank, split by `σ` into `b` and `r`, let `𝔠` be a tame character: a character
`ν = 𝔠.character` of `[U(1)]` of weight `μ`, tamely ramified exactly at a finite set
`S = 𝔠.ramifiedPlaces` of split places, and put `γ = rankTwist ν⁻¹ n = ν⁻¹ υ ^ (rk W / 2)`. There is
a number `d` of modulus one with the following property. Let `Ψ` be a Schwartz–Bruhat function on
left invertible matrices that is matched with some `Φ`: `Φ` is supported on the last rows of `k⁻¹`
and `Ψ` on the first columns of `k` (split by `σ`), for `k` in `GL_n` of the local integers at `S`,
and there `Φ = 𝔠.semilocalChar (det k) * Ψ`. Let `U⁻ = flipSpace U` be the opposite space and
`y^ad = adjointDatum y` the image of `y` under passage to adjoint maps. Then for `g` in the adelic
group `U(W) = G E s`, `γ (det g)` times `thetaSmall`, the theta integral of `(W, U⁻)` over `[U(U⁻)]`
with characters `ν υ ^ (rk W / 2)`, `υ ^ rk U`, real part `y^ad` and `x ↦ Ψ xᵀ` at the conjugates of
`S`, is `d` times the integral over the quotient `[U(U)]` of the theta kernel `pairTheta` of
`(U, W)` with characters `γ`, `γ`, real part `y` and `Ψ` at `S`. -/
lemma New.Exchange.exists_mul_thetaSmall_adjointDatum_eq_mul_integral (W : Space E n s) (U : Space E b u)
    (σ : b ⊕ r ≃ n)
    (h_even : 2 ∣ card n) {μ : InfinitePlace E → ℤ} (𝔠 : SplitTameChar E μ) (y : PairFock E u s) :
    ∃ d : ℂ, ‖d‖ = 1 ∧ ∀ (Φ : Matrix r n (LocProd 𝔠.ramifiedPlaces) → ℂ)
      (Ψ : Matrix n b (LocProd 𝔠.ramifiedPlaces) → ℂ),
      Ψ ∈ schwartzBruhat {y | HasLeftInv y} → AreMatched SemilocalField.O σ 𝔠.semilocalChar Φ Ψ →
        ∀ g : G E s,
        (rankTwist 𝔠.character⁻¹ n).val g.det * thetaSmall W (flipSpace U) 𝔠 (adjointDatum y) Ψ g =
          d * ∫ h : G E u, pairTheta U W (rankTwist 𝔠.character⁻¹ n) (rankTwist 𝔠.character⁻¹ n)
            (localDatum U W y Ψ 𝔠.readsAt) (h, g) ∂U.quotMeasure := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:196-236 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=20 body_sha256=0efac0fac6156e4cea72dfe756896bdd8c97cde000d6ebdc69f240ca92884d02]

lemma New.Exchange.thetaLarge_eq_smul_of_areMatched — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L238-L276)

lean
/-- Let `W` have even rank `rk U + rk V` (`σ`, `h_even`), let `𝔠` be a tame character: a character
`ν = 𝔠.character` of `[U(1)]` of weight `μ`, tamely ramified exactly at a finite set
`S = 𝔠.ramifiedPlaces` of split places, put `χ = 𝔠.semilocalChar`, and let `v`, `y` be real Schwartz
vectors. The standard functions `stdRowDatum σ χ z`, `stdColDatum χ z` send `x` to `χ⁻¹` of the
determinant of `z` stacked on `x`, resp. of `z * x`. Suppose that `thetaLarge` is `c` times
`thetaSmall` on them for all `z` with integral entries. Then the same holds for all matched `Φ`, `Ψ`
with `Ψ` locally constant, and `Ψ` has compact support in the left invertible matrices. -/
lemma New.Exchange.thetaLarge_eq_smul_of_areMatched (W : Space E n s) (V : Space E r t) (U : Space E b u)
    (σ : b ⊕ r ≃ n) (h_even : 2 ∣ card n) {μ : InfinitePlace E → ℤ} {𝔠 : SplitTameChar E μ}
    {v : PairFock E s t} {y : PairFock E s u} (hv : IsSchwartzVector v) (hy : IsSchwartzVector y)
    {c : ℂ}
    (h_std : ∀ z : Matrix b n (LocProd 𝔠.ramifiedPlaces), IsIntMatrix SemilocalField.O z →
      thetaLarge W V 𝔠 v (stdRowDatum σ 𝔠.semilocalChar z) = c • thetaSmall W U 𝔠 y
        (stdColDatum 𝔠.semilocalChar z))
    {Φ : Matrix r n (LocProd 𝔠.ramifiedPlaces) → ℂ} {Ψ : Matrix n b (LocProd 𝔠.ramifiedPlaces) → ℂ}
    (hΨ : IsLocallyConstant Ψ) (hΦΨ : AreMatched SemilocalField.O σ 𝔠.semilocalChar Φ Ψ) :
    Ψ ∈ schwartzBruhat {y | HasLeftInv y} ∧ thetaLarge W V 𝔠 v Φ = c • thetaSmall W U 𝔠 y Ψ := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:238-276 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=23 body_sha256=c8f41e8c7d1dfbde05e35aaa83e0b808bba40e23d3f7b5ac6688a30bc18b5ec9]

lemma New.Exchange.exists_rowColExchangeIdentity_of_even_rank — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L278-L311)

lean
/-- Let `W₀ = H ⊕ W` with `H` a hyperbolic plane, and let `W` have even rank `rk U + rk V` (`σ`,
`h_even`) and as many negative signs (`negCount`) as `V ⊕ U⁻`, with `U⁻` the opposite space
(`h_signs`). For real Schwartz vectors `z` for `(W₀, W₀)` and `y` for `(W, U)` there is a vector `v`
for `(W, V)` with `RowColExchangeIdentity W V U μ σ v y`: `v` and `y` are Schwartz, and there is a
real `C` such that each tame character `𝔠` of weight `μ` has a number `c` with (a) and (b). (a)
`C |c| ^ 2` is `L_*(rk V - rk W / 2)` times the equal rank ratio `|I(z)(1)| ^ 2 / L_*(rk W₀ / 2)`,
where `I(z)` is the theta integral of `(W₀, W₀)` at `z` and `χ⁻¹(det)`, `χ = 𝔠.semilocalChar`. (b)
On the standard functions `stdRowDatum σ χ`, `stdColDatum χ` of each integral matrix (`χ⁻¹` of the
determinant that it completes), `thetaLarge` over `[U(V)]` at `v` is `c` times `thetaSmall` over
`[U(U)]` at `y`. -/
lemma New.Exchange.exists_rowColExchangeIdentity_of_even_rank (W : Space E n s) (U : Space E b u)
    (μ : InfinitePlace E → ℤ) (V : Space E r t) (σ : b ⊕ r ≃ n)
    {z : PairFock E (hyperbolicSigns Unit ⊕ᵥ s) (hyperbolicSigns Unit ⊕ᵥ s)} {y : PairFock E s u}
    (hz : IsSchwartzVector z) (hy : IsSchwartzVector y)
    (h_signs : negCount u + negCount s = card b + negCount t) (h_even : 2 ∣ card n) :
    ∃ v : PairFock E s t, RowColExchangeIdentity W V U μ σ v y
      fun 𝔠 : SplitTameChar E μ ↦ equalRankThetaRatio (hyperbolicSum Unit W) 𝔠 z := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:278-311 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=18 body_sha256=436b4a36e877cbde56204a659c9de34efb171d414dd16a8833763d101188363c]

lemma New.Exchange.exchange_of_matches — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L313-L367)

lean
/-- Let `W₀ = H ⊕ W` with `H` a hyperbolic plane, and let `W` have even rank `rk U + rk V` (`σ`,
`h_even`) and as many negative signs as `U` and `V` together (`h_signs`). Let `z` for `(W₀, W₀)` and
`y` for `(U, W)` be real Schwartz vectors. There are `C` and a Schwartz vector `v` for `(W, V)` such
that each tame character `𝔠` of weight `μ` has a number `c` with (a) and (b). Put `ν = 𝔠.character`,
`S = 𝔠.ramifiedPlaces`, `χ = 𝔠.semilocalChar` and `γ = ν⁻¹ υ ^ (rk W / 2)`, where `υ` is the
splitting character of the Weil data on norm-one ideles (`upsilonU1`). (a) `C |c| ^ 2` is
`L_*(rk V - rk W / 2)` times the equal rank ratio `|I(z)(1)| ^ 2 / L_*(rk W₀ / 2)`, where `I(z)` is
the theta integral of `(W₀, W₀)` at `z` and `χ⁻¹(det)`, `L_*(e) = ∏_{w ∈ S} q_w ^ (e ^ 2)
∏_{1 ≤ i ≤ e} |L^S(i, ν)| ^ 2` and `L_*(-e) = L_*(e)⁻¹` (`lValueProdInt`). (b) For all matched
functions `Φ`, `Ψ` with `Ψ` locally constant, the integral over `[U(V)]` of the theta kernel of
`(W, V)` with characters `γ`, `1` at `(v, Φ)` is `c` times the integral over `[U(U)]` of the theta
kernel of `(U, W)` with characters `γ`, `γ` at `(y, Ψ)`, as functions on `U(W) = G E s`. -/
lemma New.Exchange.exchange_of_matches (W : Space E n s) (U : Space E b u) (μ : InfinitePlace E → ℤ)
    (V : Space E r t) (σ : b ⊕ r ≃ n)
    {z : PairFock E (hyperbolicSigns Unit ⊕ᵥ s) (hyperbolicSigns Unit ⊕ᵥ s)} {y : PairFock E u s}
    (hz : IsSchwartzVector z) (hy : IsSchwartzVector y)
    (h_signs : negCount s = negCount t + negCount u) (h_even : 2 ∣ card n) :
    ∃ (C : ℝ) (v : PairFock E s t), IsSchwartzVector v ∧ ∀ 𝔠 : SplitTameChar E μ,
      let γ : AutChar E := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:313-367 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=37 body_sha256=ea352bd4912b69586316225cf6f4538c539a4bd695662e3533e1c478369ea952]

lemma New.Exchange.integral_thetaOnRealData_eq_zero — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L411-L479)

lean
/-- Let `𝔠` be a tame character, `χ = 𝔠.semilocalChar` and `γ = rankTwist 𝔠.character⁻¹
n = 𝔠.character⁻¹ υ ^ ⌊rk W / 2⌋`. Suppose that `thetaLarge`, the theta integral of `(W, W)` over
the second `[U(W)]` with characters `γ`, `γ`, vanishes at the finite datum `χ⁻¹(det)`
(`stdColDatum χ 1`) for all real Schwartz vectors, and let `w` be such a vector for `(W, V.sum W)`.
Form `thetaOnRealData`, the theta series as a functional of the real vector, with characters `γ` and
`γ β` for any character `β`, and finite datum `f ⊗ χ⁻¹(det)` (`boxProd` of `f` for `(W, V)` and
`namedVector`, the vacuum with this function put in at the ramified places, which `𝔠.readsAt`
reads), after the Heisenberg translation by the adelic matrix with rows `x` for `V` and `0` for `W`.
Then for `g` in `U(W)` and `y` in `U(V)` its value at `w` and `(g, (y, l))` has integral zero over
`l` in `[U(W)]`. -/
lemma New.Exchange.integral_thetaOnRealData_eq_zero (W : Space E n s) {μ : InfinitePlace E → ℤ}
    {𝔠 : SplitTameChar E μ}
    (h_zero : ∀ v : PairFock E s s, IsSchwartzVector v → ∀ g : G E s,
      thetaLarge W W 𝔠 v (stdColDatum 𝔠.semilocalChar 1) g = 0)
    {r : Type} [Fintype r] [DecidableEq r] {t : r → ℤˣ} (V : Space E r t)
    {w : PairFock E s (Sum.elim t s)} (hw : IsSchwartzVector w) (β : AutChar E) (f : 𝒮 (W.hom V))
    (x : Matrix r n (𝔸 E)) (g : G E s) (y : G E t) :
    ∫ l : G E s, thetaOnRealData W (V.sum W) (rankTwist 𝔠.character⁻¹ n)
      (rankTwist 𝔠.character⁻¹ n * β)
      (boxProd (homSigns_sum_target signs_comp_refl) f
        (namedVector W W (stdColDatum 𝔠.semilocalChar 1) 𝔠.readsAt))
      (Matrix.fromRows x 0) (g, G.sum (y, l)) w ∂W.quotMeasure = 0 := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:411-479 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=48 body_sha256=b156b8f447bd16bc1c4c5241e0bf6276ef5dd4f6e04cc3992cc511cfcffc157c]

lemma New.Exchange.isSchwartzVector_realPairWeil — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L482-L491)

lean
/-- The real Weil representation `realPairWeil` of a pair of unitary groups with signs `s`, `t` and
weights `γ`, `γ'` preserves the Fock vectors all of whose moments are finite. -/
lemma New.Exchange.isSchwartzVector_realPairWeil {r : Type} [Fintype r] [DecidableEq r] {t : r → ℤˣ}
    (γ γ' : InfinitePlace E → ℤ) (p : GInf E s × GInf E t) {v : PairFock E s t}
    (hv : IsSchwartzVector v) : IsSchwartzVector (realPairWeil γ γ' p v) := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:482-491 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=6 body_sha256=6504c8b12112fe58a9122364039abd59b4ebe080165bff96dbf9fb1b28dd0b6a]

lemma New.Exchange.thetaLargeVanishes_of_equalRankThetaRatio_eq_zero — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L495-L539)

lean
/-- Let `J = stdSpace E m` be positive definite of even rank `2 k`,
`Y = H ⊕ J = hyperbolicSum Unit J` with `H` a hyperbolic plane, and `𝔠` a tame character: a
character `ν = 𝔠.character` of `[U(1)]` of weight `μ`, tamely ramified exactly at a finite set
`S = 𝔠.ramifiedPlaces` of split places. Suppose that the equal rank ratio of `Y`, the normalised
square of the theta integral of `(Y, Y)` at `1`, is zero at every Schwartz vector. Then the theta
integral of the pair `(H ^ (2 k) ⊕ Y, J⁻ ⊕ Y)` vanishes at every Schwartz vector and every standard
datum: `𝔠.semilocalChar⁻¹` of the determinant of an integral `m`-row matrix completed by a variable
one, the rows being ordered by `sumAssoc`. -/
lemma New.Exchange.thetaLargeVanishes_of_equalRankThetaRatio_eq_zero {μ : InfinitePlace E → ℤ}
    (hm : 2 ∣ card m) {𝔠 : SplitTameChar E μ}
    (h_zero : ∀ v : PairFock E (Sum.elim (hyperbolicSigns Unit) 1)
      (Sum.elim (hyperbolicSigns Unit) 1),
      IsSchwartzVector v → equalRankThetaRatio (hyperbolicSum Unit (stdSpace E m)) 𝔠 v = 0) :
    ThetaLargeVanishes 𝔠 (hyperbolicSum m (hyperbolicSum Unit (stdSpace E m)))
      ((stdSpace E m).neg.sum (hyperbolicSum Unit (stdSpace E m)))
      (sumAssoc m m ((Unit ⊕ Unit) ⊕ m)).symm := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:495-539 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=30 body_sha256=7e99d7bc24277a9ef8c70e627eb715b65e1f36677ffeadea98670b38d6269467]

lemma New.Exchange.exists_equalRankThetaRatio_ne_zero — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L541-L567)

lean
/-- Non-vanishing: let `J = stdSpace E m` be the positive definite space of rank `2 k` and let
`k ≤ μ w` at every infinite place `w`. Let `𝔠` be a tame character: a character of `[U(1)]` of
weight `μ`, tamely ramified exactly at a finite set of split places. There is a Schwartz vector `v`
at which the equal rank ratio of `Y = H ⊕ J = hyperbolicSum Unit J`, the normalised square of the
theta integral of `(Y, Y)` at `1`, is not zero. -/
lemma New.Exchange.exists_equalRankThetaRatio_ne_zero (μ : InfinitePlace E → ℤ) {k : ℕ}
    (hm : card m = 2 * k) (hμ : ∀ w : InfinitePlace E, k ≤ μ w) (𝔠 : SplitTameChar E μ) :
    ∃ v : PairFock E (Sum.elim (hyperbolicSigns Unit) 1) (Sum.elim (hyperbolicSigns Unit) 1),
      IsSchwartzVector v ∧ equalRankThetaRatio (hyperbolicSum Unit (stdSpace E m)) 𝔠 v ≠ 0 := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:541-567 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=19 body_sha256=4a55d4584fc83dfbc7908400466cc06a0b29d31dc058d83b768c05811cb31bd7]

lemma New.Exchange.eq_mul_of_integral_pairTheta — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L569-L592)

lean
/-- Let `J` be positive definite. Let the integral of the theta kernel of `(J, J)` over the target
group be the constant `a`, and let `c` times its integral over the source group be the constant `b`.
Then `b = c a`, by Fubini's theorem. -/
lemma New.Exchange.eq_mul_of_integral_pairTheta (J : Space E n 1) (γ : AutChar E) (f : 𝒮 (J.hom J)) {a b c : ℂ}
    (h_target : ∀ g : G E (1 : n → ℤˣ),
      ∫ h : G E (1 : n → ℤˣ), pairTheta J J γ γ f (g, h) ∂J.quotMeasure = a)
    (h_source : ∀ g : G E (1 : n → ℤˣ),
      b = c * ∫ h : G E (1 : n → ℤˣ), pairTheta J J γ γ f (h, g) ∂J.quotMeasure) :
    b = c * a := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:569-592 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=16 body_sha256=ee43984ac40113045a599903bacfe27be7b468572e49783f9a1fe7c98fb3665c]

lemma New.Exchange.exists_thetaLarge_eq_mul_quotMeasure — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L594-L634)

lean
/-- The exchange identity for `(J, J, 0)`. Let `J` be positive definite of rank `2 k` and `v` a
Schwartz vector for `(H ⊕ J, H ⊕ J)`, with `H` a hyperbolic plane. There are `B` and a Schwartz `y`
for `(J, J)` such that, for each tame character `𝔠` of weight `μ`, the theta integral of `y` and the
finite datum `stdColDatum χ 1`, the function `χ⁻¹(det)` for `χ = 𝔠.semilocalChar`, is a constant `c`
times the volume of `[U(0)]`, where `B |c| ^ 2` is `L_*(k)` times the equal rank ratio
`|I(v)(1)| ^ 2 / L_*(k + 1)`. Here `I(v)` is the theta integral at `v` and `χ⁻¹(det)`, and
`L_*(e) = ∏_{w ∈ S} q_w ^ (e ^ 2) ∏_{1 ≤ i ≤ e} |L^S(i, ν)| ^ 2` for `ν = 𝔠.character` and
`S = 𝔠.ramifiedPlaces`. -/
lemma New.Exchange.exists_thetaLarge_eq_mul_quotMeasure (μ : InfinitePlace E → ℤ) {k : ℕ} (hm : card m = 2 * k)
    (J : Space E m 1)
    {v : PairFock E (Sum.elim (hyperbolicSigns Unit) (1 : m → ℤˣ))
      (Sum.elim (hyperbolicSigns Unit) (1 : m → ℤˣ))}
    (hv : IsSchwartzVector v) :
    ∃ (B : ℝ) (y : PairFock E (1 : m → ℤˣ) 1), IsSchwartzVector y ∧
      ∀ 𝔠 : SplitTameChar E μ, ∃ c : ℂ,
        B * ‖c‖ ^ 2 = lValueProdInt 𝔠 k * equalRankThetaRatio (hyperbolicSum Unit J) 𝔠 v ∧
        ∀ g : G E (1 : m → ℤˣ), thetaLarge J J 𝔠 y (stdColDatum 𝔠.semilocalChar 1) g =
          c * (stdSpace E Empty).quotMeasure.real Set.univ := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:594-634 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=24 body_sha256=6e41ffdbf14b789a250a7b4d1e91fcdddf8e7957901923a1c2087a6a22f4974e]

lemma New.Exchange.exists_quotMeasure_mul_eq_mul_integral_pairTheta — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L636-L682)

lean
/-- The exchange identity for `(J, 0, J)`. Let `J` be positive definite of rank `2 k`, and let `v`
for `(H ⊕ J, H ⊕ J)`, with `H` a hyperbolic plane, and `y` for `(J, J)` be Schwartz vectors. There
are `C` and a number `ξ` such that each tame character `𝔠` of weight `μ` has a number `c` as
follows. The volume of `[U(0)]` times `ξ` is `c` times the integral over the first `[U(J)]` of the
theta kernel of `(J, J)` with both characters `γ = ν⁻¹ υ ^ k` and datum `y` at the infinite places,
`χ⁻¹(det)` (`stdColDatum χ 1`) at `S` and the vacuum elsewhere (`localDatum`), and `C |c| ^ 2` is
`L_*(-k) = L_*(k)⁻¹` times the equal rank ratio `|I(v)(1)| ^ 2 / L_*(k + 1)`. Here
`ν = 𝔠.character`, `S = 𝔠.ramifiedPlaces`, `χ = 𝔠.semilocalChar`, `υ` is the splitting character of
the Weil data on norm-one ideles, `I(v)` is the theta integral at `v` and `χ⁻¹(det)`, and
`L_*(e) = ∏_{w ∈ S} q_w ^ (e ^ 2) ∏_{1 ≤ i ≤ e} |L^S(i, ν)| ^ 2`. -/
lemma New.Exchange.exists_quotMeasure_mul_eq_mul_integral_pairTheta (μ : InfinitePlace E → ℤ) {k : ℕ}
    (hm : card m = 2 * k) (J : Space E m 1)
    {v : PairFock E (Sum.elim (hyperbolicSigns Unit) (1 : m → ℤˣ))
      (Sum.elim (hyperbolicSigns Unit) (1 : m → ℤˣ))}
    {y : PairFock E (1 : m → ℤˣ) 1} (hv : IsSchwartzVector v) (hy : IsSchwartzVector y) :
    ∃ (C : ℝ) (ξ : ℂ), ∀ 𝔠 : SplitTameChar E μ,
      let γ : AutChar E := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:636-682 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=31 body_sha256=733dffeff1fbee877287033decc26dc4208afad1341b34cfe1ecce1caabe31d8]

lemma New.Exchange.exists_equalRankThetaRatio_sq_eq — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L684-L724)

lean
/-- The exchange identity used twice. Let `J` be positive definite of rank `2 k` and `v` a Schwartz
vector for `(H ⊕ J, H ⊕ J)`, with `H` a hyperbolic plane. As `𝔠` runs through the tame characters of
weight `μ`, the square of the equal rank ratio `|I(v)(1)| ^ 2 / L_*(k + 1)` is one number `D`. Here
`I(v)` is the theta integral `thetaLarge` with real part `v` and the function `χ⁻¹(det)` at the
ramified places, `χ = 𝔠.semilocalChar`, and `L_*(e) = ∏_{w ∈ S} q_w ^ (e ^ 2) ∏_{1 ≤ i ≤ e} |L^S(i,
ν)| ^ 2` for `ν = 𝔠.character` and `S = 𝔠.ramifiedPlaces`. -/
lemma New.Exchange.exists_equalRankThetaRatio_sq_eq (μ : InfinitePlace E → ℤ) {k : ℕ} (hm : card m = 2 * k)
    (J : Space E m 1)
    {v : PairFock E (Sum.elim (hyperbolicSigns Unit) (1 : m → ℤˣ))
      (Sum.elim (hyperbolicSigns Unit) (1 : m → ℤˣ))}
    (hv : IsSchwartzVector v) :
    ∃ D : ℝ, ∀ 𝔠 : SplitTameChar E μ, equalRankThetaRatio (hyperbolicSum Unit J) 𝔠 v ^ 2 = D := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:684-724 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=30 body_sha256=35ca87318a94e12d9129569fc042d88872ccefae628d72ef9231a6da95fce07b]

lemma New.Exchange.exists_equalRankThetaRatio_const_ne_zero — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L726-L745)

lean
/-- The value on the first floor. Let `J` be the standard positive definite space of rank `2 k` and
`k ≤ μ` at every infinite place. Some Schwartz vector `v` for `(H ⊕ J, H ⊕ J)` has an equal rank
ratio that is one number `C ≠ 0` for all tame characters of weight `μ`. -/
lemma New.Exchange.exists_equalRankThetaRatio_const_ne_zero (μ : InfinitePlace E → ℤ) {k : ℕ}
    (hm : card m = 2 * k) (hμ : ∀ w : InfinitePlace E, k ≤ μ w) :
    ∃ v : PairFock E (Sum.elim (hyperbolicSigns Unit) (1 : m → ℤˣ))
      (Sum.elim (hyperbolicSigns Unit) 1),
      IsSchwartzVector v ∧ ∃ C ≠ (0 : ℝ),
        ∀ 𝔠 : SplitTameChar E μ, equalRankThetaRatio (hyperbolicSum Unit (stdSpace E m)) 𝔠 v =
          C := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:726-745 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=11 body_sha256=33c697ab29f054b5e5b6b0a7e5f3385780329108785f4a46816a16747bb9db57]

lemma New.Exchange.exists_equalRankThetaRatio_add_plane — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L747-L794)

lean
/-- Adding a plane. Let `W` have even rank and let `A` be an adapted splitting `W' = W ⊕ H` with `H`
a hyperbolic plane (its frames are orthonormal at the infinite and integral at the finite places).
Each Schwartz vector `v` for `(W, W)` has a Schwartz vector `v'` for `(W', W')` whose equal rank
ratio is `C` times the ratio `|I(v)(1)| ^ 2 / L_*(rk W / 2)` of `v`. The constant `C > 0` is the
same for all tame characters `𝔠` of weight `μ`. Here `I(v)` is the theta integral `thetaLarge` with
real part `v` and the function `χ⁻¹(det)` at the ramified places, `χ = 𝔠.semilocalChar`, and
`L_*(e) = ∏_{w ∈ S} q_w ^ (e ^ 2) ∏_{1 ≤ i ≤ e} |L^S(i, ν)| ^ 2` for `ν = 𝔠.character` and
`S = 𝔠.ramifiedPlaces`. -/
lemma New.Exchange.exists_equalRankThetaRatio_add_plane {W : Space E n s} (μ : InfinitePlace E → ℤ)
    {n' : Type} [Fintype n'] [DecidableEq n'] {s' : n' → ℤˣ}
    {W' : Space E n' s'} (A : W'.Splitting W Unit) [IsBaseAdapted A] (h_even : 2 ∣ card n)
    {v : PairFock E s s} (hv : IsSchwartzVector v) :
    ∃ v' : PairFock E s' s', IsSchwartzVector v' ∧ ∃ C > (0 : ℝ), ∀ 𝔠 : SplitTameChar E μ,
      equalRankThetaRatio W' 𝔠 v' = C * equalRankThetaRatio W 𝔠 v := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:747-794 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=35 body_sha256=01927fc58ecc373c91b5ae6145c19dadb00fdc098bd9951c5380091a93a01356]

lemma New.Exchange.equalRankThetaRatio_eq_of_signs_eq — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L796-L813)

lean
/-- Let `Y` have even rank and let `A` be an adapted splitting `Y = W ⊕ H` with `H` a hyperbolic
plane (its frames are orthonormal at the infinite and integral at the finite places). Let `Y₁` be
any space with the signs of `Y`, `𝔠` a tame character and `v` a Schwartz vector (all Fock moments
finite). Then the equal rank ratio `|I(1)| ^ 2 / L_*(rank / 2)` is the same for `Y₁` and `Y`, where
`I` is the theta integral of `v` and `𝔠.semilocalChar⁻¹(det)` for the pair `(Y₁, Y₁)`, resp.
`(Y, Y)`, and `L_* = lValueProdInt 𝔠` is a product of partial L-values of `𝔠`. -/
lemma New.Exchange.equalRankThetaRatio_eq_of_signs_eq {W : Space E n s} {μ : InfinitePlace E → ℤ}
    {n' : Type} [Fintype n'] [DecidableEq n'] {s' : n' → ℤˣ}
    {Y : Space E n' s'} (A : Y.Splitting W Unit) [IsBaseAdapted A] (Y₁ : Space E n' s')
    (h_even : 2 ∣ card n') (𝔠 : SplitTameChar E μ) {v : PairFock E s' s'}
    (hv : IsSchwartzVector v) :
    equalRankThetaRatio Y₁ 𝔠 v = equalRankThetaRatio Y 𝔠 v := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:796-813 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=7 body_sha256=dd23985f7206f9c947a4615e16fcd9ebe1db0aa2cca9e30610df6b177ef5bfa4]

lemma New.Exchange.exists_equalRankThetaRatio_eq_const — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L815-L852)

lean
/-- The value of the equal rank ratio. Let `rk W = 2 k + 2 q`, where `q` is the number of negative
signs of `W`, and `k ≤ μ` at every infinite place. There are a Schwartz vector (all Fock moments
finite) `v` for `(H ⊕ W, H ⊕ W)`, with `H` a hyperbolic plane, and `C ≠ 0` such that
`|I(v)(1)| ^ 2 / L_*(rk W / 2 + 1) = C` for every tame character `𝔠` of weight `μ`. Here `I(v)` is
the theta integral `thetaLarge` with real part `v` and the function `χ⁻¹(det)` at the ramified
places, `χ = 𝔠.semilocalChar`, and `L_*(e) = ∏_{w ∈ S} q_w ^ (e ^ 2) ∏_{1 ≤ i ≤ e} |L^S(i, ν)| ^ 2`
for `ν = 𝔠.character` and `S = 𝔠.ramifiedPlaces`. -/
lemma New.Exchange.exists_equalRankThetaRatio_eq_const (W : Space E n s) (μ : InfinitePlace E → ℤ) (k : ℕ)
    (h_rank : card n = 2 * k + 2 * negCount s) (hμ : ∀ w : InfinitePlace E, k ≤ μ w) :
    ∃ v : PairFock E (Sum.elim (hyperbolicSigns Unit) s) (Sum.elim (hyperbolicSigns Unit) s),
      IsSchwartzVector v ∧ ∃ C ≠ (0 : ℝ),
        ∀ 𝔠 : SplitTameChar E μ, equalRankThetaRatio (hyperbolicSum Unit W) 𝔠 v = C := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:815-852 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=27 body_sha256=69cd52834c2ae3f79bd626b7f18403abda2f1183c97fe0407e4ca5718b6b06ee]

lemma New.Exchange.spaceChar_mul_spaceChar_eq_iff — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L869-L880)

lean
/-- The space character `α.spaceChar p` is the Hecke character `x ↦ α (x / x̄) υ x ^ (-p)`. In even
rank `card N = p + q` those of `α` in rank `p` and of `α'` in rank `q` multiply to the inverse of
the base change `x ↦ ν (x / x̄)` exactly if `α * α' = rankTwist ν⁻¹ N = ν⁻¹ υ ^ (card N / 2)`. -/
lemma New.Exchange.spaceChar_mul_spaceChar_eq_iff {E : Type} [Field E] [CMType E] [WeilData E]
    {N : Type} [Fintype N] {α α' ν : AutChar E} {p q : ℕ}
    (h_card : card N = p + q) (h_even : 2 ∣ card N) :
    α.spaceChar p * α'.spaceChar q = ν.baseChange⁻¹ ↔ α * α' = rankTwist ν⁻¹ N := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:869-880 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=6 body_sha256=8d8abeb1bd7e19ca9b67ce945a8b143231744ecefb4623878538e45d283cceef]

lemma New.Exchange.exists_areMatched_modDatum_eq — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L886-L972)

lean
/-- Let `W`, `V`, `V'` be spaces with coordinates indexed by `n`, `a`, `b`, split by
`σ : b ⊕ a ≃ n`, and let the tame character `𝔠` be ramified exactly at the primes of the modulus
`𝔪`. Let `Φ`, `Ψ` be matched functions over `O_E / 𝔪` for the product `χ` of the residue characters
of `𝔠`: `Φ` is supported on the last rows of `k⁻¹` and `Ψ` on the first columns of `k` (split by
`σ`), for `k` in `GL_n(O_E / 𝔪)` (the subring `⊤`), and there `Φ = χ (det k) * Ψ`. Then there are
functions `Φ'`, `Ψ'` on matrices over the completions at these primes, matched over the local
integers `SemilocalField.O` for `𝔠.semilocalChar`, with `Ψ'` locally constant, that give the same
adelic data as `Φ` for `(W, V)` and `Ψ` for `(V', W)`, whatever the real vector. -/
lemma New.Exchange.exists_areMatched_modDatum_eq (σ : b ⊕ a ≃ n) {μ : NumberField.InfinitePlace E → ℤ}
    (𝔪 : Modulus E) (𝔠 : SplitTameChar E μ)
    (h_ramified : (𝔠.ramifiedPlaces : Set (FinPlace E)) = 𝔪.places)
    {Φ : Matrix a n 𝔪.ResidueRing → ℂ} {Ψ : Matrix n b 𝔪.ResidueRing → ℂ}
    (h_matched : AreMatched ⊤ σ (𝔪.charOfTamePart 𝔠.tamePart) Φ Ψ) :
    ∃ (Φ' : Matrix a n (LocProd 𝔠.ramifiedPlaces) → ℂ)
      (Ψ' : Matrix n b (LocProd 𝔠.ramifiedPlaces) → ℂ),
      IsLocallyConstant Ψ' ∧
      AreMatched SemilocalField.O σ 𝔠.semilocalChar Φ' Ψ' ∧
      (∀ x : PairFock E s t, modDatum W V 𝔪 Φ x = localDatum W V x Φ' 𝔠.readsAt) ∧
      ∀ v : PairFock E t' s, modDatum V' W 𝔪 Ψ v = localDatum V' W v Ψ' 𝔠.readsAt := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:886-972 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=69 body_sha256=773ddda7178de9f782c03c672c4d4633acb101fc4217b47ed803b249d263010a]

lemma New.Exchange.exchange_theorem — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L974-L1049)

lean
/-- Let `W`, `V`, `V'` have ranks `|n| = |b| + |a|` (split by `σ`), `|a| = |b| + 2e` and `|b|`. Let
`W` have as many negative signs `q` as `V` and `V'` together, with `2q + 2 ≤ |n|`. Let the weights
satisfy `|n| ≤ 2 μ + 2q`, and let `v` be a real Schwartz vector for `(V', W)`. There are `C` and a
Schwartz `x` for `(W, V)` such that every character `ν` of `[U(1)]` of weight `μ` that is tame for
`(𝔪, χ)` (ramified exactly at the primes of `𝔪`, with residue character `χ`) has some `c ≠ 0` with
(a) and (b). (a) `‖c‖²` is `C` times `lValueProd 𝔪.places ν e`, a power of the norm of the primes of
`𝔪` times the product of the squares of the partial L-values `|L^S(z, ν)|` for `z = 1, …, e`, with
`S` the primes of `𝔪`; so `C > 0` as soon as such a `ν` exists. (b) For all matched functions `Φ`,
`Ψ` modulo `𝔪`, the theta integral of `(x, Φ)` over `[U(V)]` is `c` times that of `(v, Ψ)` over
`[U(V')]`, as functions on `U(W)`. The left side has the characters `γ` and `1`, the right side `γ`
and `γ`, with `γ = rankTwist ν⁻¹ n = ν⁻¹ υ ^ (|n| / 2)`. -/
lemma New.Exchange.exchange_theorem (σ : b ⊕ a ≃ n) (h_signs : negCount s = negCount t + negCount t') {e : ℕ}
    (h_rank : card a = card b + 2 * e) (h_few_neg : 2 * negCount s + 2 ≤ card n)
    {μ : NumberField.InfinitePlace E → ℤ}
    (hμ : ∀ τ : NumberField.InfinitePlace E, card n ≤ 2 * μ τ + 2 * negCount s)
    {v : Fock.fockSpace (realSigns E (homSigns t' s))} (hv : IsSchwartzVector v) :
    ∃ (C : ℝ) (x : Fock.fockSpace (realSigns E (homSigns s t))),
      IsSchwartzVector x ∧
      ∀ (𝔪 : Modulus E) (ν : AutChar E) (χ : MulChar 𝔪.ResidueRing ℂ), IsTameFor 𝔪 ν μ χ →
        let γ : AutChar E := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:974-1049 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=57 body_sha256=433d6f1601635a43d46e259dff644a43694803df23cac5877107549cc0e3d689]

theorem New.Exchange.exchange_identity — Upstream source (src/New/Determinant/Exchange/TheoremForPartners.lean L1051-L1113)

lean
/-- Let `W`, `V`, `V'` have ranks `|n| = |b| + |a|` (split by `σ`), `|a| = |b| + 2e`, `|b|`. Let `W`
have as many negative signs `q` as `V` and `V'` together, with `2q + 2 ≤ |n| ≤ 2 μ + 2q`, and let
`v` be a real Schwartz vector for `(V', W)`. There are `C > 0` and a Schwartz vector `x` for
`(W, V)`, chosen before `𝔪` and `ν`, such that every character `ν` of `[U(1)]` of weight `μ` that is
tame for `(𝔪, χ)` has a number `c` as follows. Its size is `‖c‖² = C * lValueProd 𝔪.places ν e ≠ 0`.
For all `α`, `α'` such that the characters `α.spaceChar |a|` of `V` and `α'.spaceChar |b|` of `V'`
have product inverse to the base change `x ↦ ν (x / x̄)`, and all matched functions `Φ`, `Ψ` modulo
`𝔪`, the theta integral of `(x, Φ)` over `[U(V)]` is `c` times that of `(v, Ψ)` over `[U(V')]`, as
functions on `U(W)`. The character of `W` is `rankTwist ν⁻¹ n = ν⁻¹ υ ^ (|n| / 2)`, and `modDatum`
puts a function modulo `𝔪` at the primes of `𝔪` and the vacuum at the other finite places. -/
theorem New.Exchange.exchange_identity (σ : b ⊕ a ≃ n) (h_signs : negCount s = negCount t + negCount t')
    {e : ℕ} (h_rank : card a = card b + 2 * e) (h_few_neg : 2 * negCount s + 2 ≤ card n)
    {μ : NumberField.InfinitePlace E → ℤ}
    (hμ : ∀ τ : NumberField.InfinitePlace E, card n ≤ 2 * μ τ + 2 * negCount s)
    {v : PairFock E t' s} (hv : IsSchwartzVector v) :
    ∃ C : ℝ, 0 < C ∧ ∃ x : PairFock E s t, IsSchwartzVector x ∧
      ∀ (𝔪 : Modulus E) (ν : AutChar E) (χ : MulChar 𝔪.ResidueRing ℂ), IsTameFor 𝔪 ν μ χ →
      ∃ c : ℂ,
        ‖c‖ ^ 2 = C * lValueProd 𝔪.places ν e ∧
        C * lValueProd 𝔪.places ν e ≠ 0 ∧
        ∀ α α' : AutChar E,
          α.spaceChar (card a) * α'.spaceChar (card b) = ν.baseChange⁻¹ →
          ∀ (Φ : Matrix a n 𝔪.ResidueRing → ℂ) (Ψ : Matrix n b 𝔪.ResidueRing → ℂ),
            AreMatched ⊤ σ χ Φ Ψ →
            ∀ g : G E s,
              thetaIntegral W V (rankTwist ν⁻¹ n) α (modDatum W V 𝔪 Φ x) g =
                c * ∫ h : G E t',
                  pairTheta V' W α' (rankTwist ν⁻¹ n) (modDatum V' W 𝔪 Ψ v) (h, g)
                  ∂V'.quotMeasure := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/TheoremForPartners.lean:1051-1113 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=35 body_sha256=2396e45bc2ed2f6b012f1855e86abf910c7cf9ccfe578ce3c15b69d6d63da09e]

lemma New.Exchange.pairWeil_modDatum_single_mul_left — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L64-L75)

lean
/-- Let `k = liftMod g` be the chosen integral finite adelic point of `U(T)` with residue `g` modulo
`𝔪`. In the Weil representation `pairWeil S T α β` of `U(S) × U(T)`, twisted by the characters `α`,
`β`, let `k⁻¹` act in the finite part of `U(T)`, all other components being `1`. It sends the point
datum at `g x` to `(α (det k))⁻¹` times the point datum at `x`. -/
lemma New.Exchange.pairWeil_modDatum_single_mul_left (S : Space E n s) (T : Space E n' s') {𝔪 : Modulus E}
    (α β : AutChar E) (g : GL n' 𝔪.ResidueRing) (x : Matrix n' n 𝔪.ResidueRing)
    (v : PairFock E s s') :
    pairWeil S T α β ((1, 1), 1, (liftMod g).val⁻¹) (modDatum S T 𝔪 (Pi.single (g.val * x) 1) v) =
      (α⁻¹.val (detFin s' (liftMod g).val) : ℂ) • modDatum S T 𝔪 (Pi.single x 1) v := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:64-75 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=4 body_sha256=da7aec42a2df1f1e41b1526e7b1990a29ce2feae79cac5357031206d50a21cf6]

lemma New.Exchange.pairWeil_modDatum_single_mul_right — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L77-L88)

lean
/-- Let `k = liftMod g` be the chosen integral finite adelic point of `U(S)` with residue `g` modulo
`𝔪`. In the Weil representation `pairWeil S T α β` of `U(S) × U(T)`, twisted by the characters `α`,
`β`, let `k` act in the finite part of `U(S)`, all other components being `1`. It sends the point
datum at `y g` to `(β (det k))⁻¹` times the point datum at `y`. -/
lemma New.Exchange.pairWeil_modDatum_single_mul_right (S : Space E n s) (T : Space E n' s') {𝔪 : Modulus E}
    (α β : AutChar E) (g : GL n 𝔪.ResidueRing) (y : Matrix n' n 𝔪.ResidueRing)
    (v : PairFock E s s') :
    pairWeil S T α β ((1, (liftMod g).val), 1, 1) (modDatum S T 𝔪 (Pi.single (y * g.val) 1) v) =
      (β⁻¹.val (detFin s (liftMod g).val) : ℂ) • modDatum S T 𝔪 (Pi.single y 1) v := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:77-88 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=4 body_sha256=9fc4e88d438f075af99301fbbee178bd70b6195f5eccf3bbad4ba45f6b4d3eae]

lemma New.Exchange.hasLeftInv_transpose_of_areMatched — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L91-L99)

lean
/-- Let `Ψ`, `Ψ'` be matched for the character `χ` over the whole residue ring (`⊤`), the indices
being split by `σ`; in particular `Ψ` vanishes off the blocks of rows `n'` of invertible matrices.
Then `Ψ` vanishes off the onto matrices, those whose transpose has a left inverse. -/
lemma New.Exchange.hasLeftInv_transpose_of_areMatched {𝔪 : Modulus E} {σ : n ⊕ n' ≃ n₁ ⊕ n₂}
    {χ : MulChar 𝔪.ResidueRing ℂ} {Ψ : Matrix n' (n₁ ⊕ n₂) 𝔪.ResidueRing → ℂ}
    {Ψ' : Matrix (n₁ ⊕ n₂) n 𝔪.ResidueRing → ℂ} (h_part : AreMatched ⊤ σ χ Ψ Ψ')
    {x : Matrix n' (n₁ ⊕ n₂) 𝔪.ResidueRing} (hx : Ψ x ≠ 0) : HasLeftInv xᵀ := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:91-99 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=3 body_sha256=79b244190fbace931d67aa8f4316ce639650b981b0fd361e49ed46cc45130d87]

lemma New.Exchange.hasLeftInv_of_areMatched — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L102-L110)

lean
/-- Let `Ψ`, `Ψ'` be matched for the character `χ` over the whole residue ring (`⊤`), the indices
being split by `σ`; in particular `Ψ'` vanishes off the blocks of columns `n` of invertible
matrices. Then `Ψ'` vanishes off the left invertible matrices. -/
lemma New.Exchange.hasLeftInv_of_areMatched {𝔪 : Modulus E} {σ : n ⊕ n' ≃ n₁ ⊕ n₂}
    {χ : MulChar 𝔪.ResidueRing ℂ} {Ψ : Matrix n' (n₁ ⊕ n₂) 𝔪.ResidueRing → ℂ}
    {Ψ' : Matrix (n₁ ⊕ n₂) n 𝔪.ResidueRing → ℂ} (h_part : AreMatched ⊤ σ χ Ψ Ψ')
    {y : Matrix (n₁ ⊕ n₂) n 𝔪.ResidueRing} (hy : Ψ' y ≠ 0) : HasLeftInv y := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:102-110 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=3 body_sha256=52b39cabff935aca109c6a8ed9e84d8dc0f6c9f3d31c0fffdbbde717980f69e5]

lemma New.Exchange.IsTameFor.exists_inv_rankTwist_inv — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L112-L122)

lean
/-- Let the character `ν` of `[U(1)]` be tame of weight `μ` for `(𝔪, χ)`: `𝔪 ≠ 1`, `ν` has weight
`μ` at the infinite places, its tame part is nontrivial exactly at the places dividing `𝔪`, and `χ`
is the character of the residue ring that the tame part defines. Then the inverse of
`rankTwist ν⁻¹ N = ν⁻¹ * upsilonU1 ^ (card N / 2)` is tame for `(𝔪, χ)`, of some weight `μ'`. -/
lemma New.Exchange.IsTameFor.exists_inv_rankTwist_inv {𝔪 : Modulus E} {ν : AutChar E} {μ : InfinitePlace E → ℤ}
    {χ : MulChar 𝔪.ResidueRing ℂ} (h_tame : IsTameFor 𝔪 ν μ χ) (N : Type) [Fintype N] :
    ∃ μ' : InfinitePlace E → ℤ, IsTameFor 𝔪 (rankTwist ν⁻¹ N)⁻¹ μ' χ := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:112-122 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=5 body_sha256=0f7b0e98d49aa59f29257ac7fdbc3598270763c3412707e7b4745695bffef536]

lemma New.Exchange.integral_integral_sum_eq — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L125-L147)

lean
/-- Suppose each `F i` with nonzero coefficient `c i` is integrable for the product of the quotient
measures of `U₁`, `U₂` and `A`, with integral `r i`. Then the iterated integral of `∑ i, c i • F i`
equals `∑ i, c i • r i`. The inner integral is over `A` and the outer one over `U₁ × U₂`. -/
lemma New.Exchange.integral_integral_sum_eq {A : Space E n' s'} {U₁ : Space E n₁ s₁} {U₂ : Space E n₂ s₂}
    {ι : Type*} [Fintype ι] {c r : ι → ℂ} {F : ι → (G E s₁ × G E s₂) × G E s' → ℂ}
    (hF_int : ∀ i : ι, c i ≠ 0 →
      Integrable (F i) ((U₁.quotMeasure.prod U₂.quotMeasure).prod A.quotMeasure))
    (hF_val : ∀ i : ι, c i ≠ 0 → ∫ q : (G E s₁ × G E s₂) × G E s', F i q
      ∂(U₁.quotMeasure.prod U₂.quotMeasure).prod A.quotMeasure = r i) :
    ∫ g : G E s₁ × G E s₂, ∫ h : G E s', ∑ i : ι, c i • F i (g, h) ∂A.quotMeasure
        ∂U₁.quotMeasure.prod U₂.quotMeasure = ∑ i : ι, c i • r i := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:125-147 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=13 body_sha256=d620c276b5ea903a3efa8379186894d751d2b644f05ebd4d5ef876ba290d0800]

lemma New.Exchange.exists_integrable_kernel_bound — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L150-L190)

lean
/-- Let `s` be any sign vector and `fockSpace s` its Fock space. For `v` in it with finite moment
`fockMoment N v = ∫ (1 + ‖z‖) ^ N * |v z| dz`, let `K v` be a continuous kernel on `U₁ ⊕ U₂` and
`A`, bounded by a multiple of that moment times a power of the height on `U₁ ⊕ U₂`, uniformly in the
variable of `A`. Let `φ₁`, `φ₂` be rapidly decreasing functions on the adelic unitary groups of
`U₁`, `U₂`, and `ν₀` a character of `[U(1)]`. Then `φ₁ g₁ * φ₂ g₂ * ν₀ (det g₂) * K v (g₁ ⊕ g₂) z`,
as a function on `(U₁ × U₂) × A`, is integrable and bounded by a constant times a moment of `v`. -/
lemma New.Exchange.exists_integrable_kernel_bound {A : Space E n' s'} {U₁ : Space E n₁ s₁}
    {U₂ : Space E n₂ s₂} {φ₁ : G E s₁ → ℂ} {φ₂ : G E s₂ → ℂ} (hφ₁ : φ₁ ∈ U₁.rapidFunctions)
    (hφ₂ : φ₂ ∈ U₂.rapidFunctions) (ν₀ : AutChar E)
    {K : fockSpace s → G E (s₁ ⊕ᵥ s₂) → G E s' → ℂ}
    (hK_le : ∃ (B N : ℕ) (C : ℝ), ∀ (v : fockSpace s) (g : G E (s₁ ⊕ᵥ s₂)) (z : G E s'),
      fockMoment N v ≠ ⊤ → ‖K v g z‖ ≤ C * (fockMoment N v).toReal * (U₁.sum U₂).height g ^ B)
    (hK_cont : ∀ v : fockSpace s, Continuous ↿(K v)) :
    ∃ (N : ℕ) (C : ℝ), ∀ v : fockSpace s, fockMoment N v ≠ ⊤ →
      let F : (G E s₁ × G E s₂) × G E s' → ℂ := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:150-190 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=27 body_sha256=47207c1dcd0418459a9e35a1cecec56445f328f38c82b39144f19e1e7018a999]

lemma New.Exchange.exists_eq_mul_of_forall_polyVector — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L192-L218)

lean
/-- Let `s` be a sign vector on a finite index type `n`, so that a polynomial `P` in variables
indexed by `n` has a Fock vector `polyVector s P`. Let numbers `Λ j v` depend on a Fock vector `v`,
each being Lipschitz for one moment `fockMoment N v = ∫ (1 + ‖z‖) ^ N * |v z| dz`. If, for every
polynomial `P`, the numbers `Λ j (polyVector s P)` are one multiple of given numbers `ρ j`, the same
holds for every vector `x` whose moments are all finite. -/
lemma New.Exchange.exists_eq_mul_of_forall_polyVector {J : Type*} {Λ : J → fockSpace s → ℂ} {ρ : J → ℂ}
    (h_lipschitz : ∀ j : J, ∃ (N : ℕ) (D : ℝ), ∀ v w : fockSpace s,
      fockMoment N v ≠ ⊤ → fockMoment N w ≠ ⊤ → fockMoment N (w - v) ≠ ⊤ →
      ‖Λ j v - Λ j w‖ ≤ D * (fockMoment N (w - v)).toReal)
    (h_poly : ∀ P : MvPolynomial n ℂ, ∃ r : ℂ, ∀ j : J, Λ j (polyVector s P) = r * ρ j)
    {x : fockSpace s} (hx : IsSchwartzVector x) : ∃ κ : ℂ, ∀ j : J, Λ j x = κ * ρ j := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:192-218 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=17 body_sha256=9d328b2be63907888962499a03dbe1fd7a6781bef01819b1143875b68d7ae997]

lemma New.Exchange.single_one_eq_mul_of_coordinates — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L227-L234)

lean
/-- A point mass factors into the point masses of two coordinates that determine the point. -/
lemma New.Exchange.single_one_eq_mul_of_coordinates {α β γ : Type*} [DecidableEq α] [DecidableEq β]
    [DecidableEq γ] (x : α) (f : α → β) (g : α → γ)
    (h : ∀ y, (f y = f x ∧ g y = g x) ↔ y = x) :
    (Pi.single x 1 : α → ℂ) = fun y ↦
      (Pi.single (f x) 1 : β → ℂ) (f y) * (Pi.single (g x) 1 : γ → ℂ) (g y) := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:227-234 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=3 body_sha256=14e89ec365ea80279c1d9cb44fe99891400989caa951296dc4abd89f17054c57]

lemma New.Exchange.modKernel_single_sum_left — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L236-L254)

lean
/-- Let `U₁`, `U₂`, `A` be hermitian spaces, `ν₀` and `aᵢ`, `bᵢ` characters of `[U(1)]` with
`b₂ * ν₀ = b₁`. Take the indicator function of `x` and the product of `P₁` and `P₂`, read by
`renameRowsCols` in the variables of the two column blocks. Then the kernel of `(U₁ ⊕ U₂, A)` at
`g₁ ⊕ g₂`, for the characters `a₁ a₂` and `b₁`, is the product of the kernels of `(U₁, A)` and
`(U₂, A)`, for the column blocks of `x`, divided by `ν₀ (det g₂)`. -/
lemma New.Exchange.modKernel_single_sum_left {a₁ a₂ b₁ b₂ : AutChar E} (hb : b₂ * ν₀ = b₁)
    (x : Matrix n' (n₁ ⊕ n₂) 𝔪.ResidueRing) (P₁ : MvPolynomial (InfinitePlace E × n' × n₁) ℂ)
    (P₂ : MvPolynomial (InfinitePlace E × n' × n₂) ℂ) (g₁ : G E s₁) (g₂ : G E s₂) (h : G E s') :
    ν₀.val g₂.det * modKernel (U₁.sum U₂) A (a₁ * a₂) b₁ 𝔪 (Pi.single x 1)
        (renameRowsCols id Sum.inl P₁ * renameRowsCols id Sum.inr P₂) (G.sum (g₁, g₂)) h =
      modKernel U₁ A a₁ b₁ 𝔪 (Pi.single x.toCols₁ 1) P₁ g₁ h *
        modKernel U₂ A a₂ b₂ 𝔪 (Pi.single x.toCols₂ 1) P₂ g₂ h := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:236-254 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=8 body_sha256=e1e5721e5c4687ecc7fe497c4e0e7825d1d971cec6b64737cee1a5ae1aac64aa]

lemma New.Exchange.modKernel_single_sum_right — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L256-L273)

lean
/-- Let `A'`, `U₁`, `U₂` be hermitian spaces, `ν₀` and `aᵢ`, `bᵢ` characters of `[U(1)]` with
`b₁ * ν₀ = b₂`. Take the indicator function of `y` and the product of `P₁` and `P₂`, read by
`renameRowsCols` in the variables of the two row blocks. Then the kernel of `(A', U₁ ⊕ U₂)` at
`g₁ ⊕ g₂`, for the characters `b₁` and `a₁ a₂`, is the product of the kernels of `(A', U₁)` and
`(A', U₂)`, for the row blocks of `y`, divided by `ν₀ (det g₂)`. -/
lemma New.Exchange.modKernel_single_sum_right {a₁ a₂ b₁ b₂ : AutChar E} (hb : b₁ * ν₀ = b₂)
    (y : Matrix (n₁ ⊕ n₂) n 𝔪.ResidueRing) (P₁ : MvPolynomial (InfinitePlace E × n₁ × n) ℂ)
    (P₂ : MvPolynomial (InfinitePlace E × n₂ × n) ℂ) (h : G E s) (g₁ : G E s₁) (g₂ : G E s₂) :
    ν₀.val g₂.det * modKernel A' (U₁.sum U₂) b₁ (a₁ * a₂) 𝔪 (Pi.single y 1)
        (renameRowsCols Sum.inl id P₁ * renameRowsCols Sum.inr id P₂) h (G.sum (g₁, g₂)) =
      modKernel A' U₁ b₁ a₁ 𝔪 (Pi.single y.toRows₁ 1) P₁ h g₁ *
        modKernel A' U₂ b₂ a₂ 𝔪 (Pi.single y.toRows₂ 1) P₂ h g₂ := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:256-273 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=7 body_sha256=1c960b5d6ce283fe0ba9fa1478303130c3e16cb7aa6a8d260ac77a778868b773]

def New.Exchange.upIntegrand — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L275-L281)

lean
/-- The theta kernel of `(U₁ ⊕ U₂, A)` for the point datum at `x` with real part `w`, at
`(g₁ ⊕ g₂, h)`, times `f₁ g₁ * f₂ g₂ * ν₀ (det g₂)`. The characters `γ`, `b` of `[U(1)]` twist the
Weil representation in the kernel by `γ (det h) * (b (det (g₁ ⊕ g₂)))⁻¹`. -/
def New.Exchange.upIntegrand (f₁ : G E s₁ → ℂ) (f₂ : G E s₂ → ℂ) (x : Matrix n' (n₁ ⊕ n₂) 𝔪.ResidueRing)
    (w : PairFock E (s₁ ⊕ᵥ s₂) s') (q : (G E s₁ × G E s₂) × G E s') : ℂ := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:275-281 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=2 body_sha256=047171cd6d593ff54b387fd8fbdbaa82369052eba32fa072e727851fcbd0f957]

def New.Exchange.downIntegrand — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L283-L289)

lean
/-- The theta kernel of `(A', U₁ ⊕ U₂)` for the point datum at `y` with real part `w`, at
`(h, g₁ ⊕ g₂)`, times `f₁ g₁ * f₂ g₂ * ν₀ (det g₂)`. The characters `γ`, `b` of `[U(1)]` twist the
Weil representation in the kernel by `(γ (det h))⁻¹ * b (det (g₁ ⊕ g₂))`. -/
def New.Exchange.downIntegrand (f₁ : G E s₁ → ℂ) (f₂ : G E s₂ → ℂ) (y : Matrix (n₁ ⊕ n₂) n 𝔪.ResidueRing)
    (w : PairFock E s (s₁ ⊕ᵥ s₂)) (q : (G E s₁ × G E s₂) × G E s) : ℂ := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:283-289 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=2 body_sha256=9315899304aa1454f483c97078389e2238513030e7f9befeadc52bd1e95dc118]

lemma New.Exchange.upIntegrand_add — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L291-L297)

lean
/-- The function `upIntegrand` is additive in its real datum, the Fock vector in
`PairFock E (s₁ ⊕ᵥ s₂) s'`: its value at `v + w` is the sum of its values at `v` and at `w`. -/
lemma New.Exchange.upIntegrand_add (f₁ : G E s₁ → ℂ) (f₂ : G E s₂ → ℂ) (x : Matrix n' (n₁ ⊕ n₂) 𝔪.ResidueRing)
    (v w : PairFock E (s₁ ⊕ᵥ s₂) s') : upIntegrand A U₁ U₂ ν₀ γ b f₁ f₂ x (v + w) =
      upIntegrand A U₁ U₂ ν₀ γ b f₁ f₂ x v + upIntegrand A U₁ U₂ ν₀ γ b f₁ f₂ x w := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:291-297 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=3 body_sha256=2e01d9ab5f260064969ec3a6b90790dc7feb6ab44a224bdbc6696aa1210e4001]

lemma New.Exchange.upIntegrand_sub — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L299-L304)

lean
/-- The function `upIntegrand` respects differences in its real datum, the Fock vector in
`PairFock E (s₁ ⊕ᵥ s₂) s'`: its value at `v - w` is its value at `v` minus its value at `w`. -/
lemma New.Exchange.upIntegrand_sub (f₁ : G E s₁ → ℂ) (f₂ : G E s₂ → ℂ) (x : Matrix n' (n₁ ⊕ n₂) 𝔪.ResidueRing)
    (v w : PairFock E (s₁ ⊕ᵥ s₂) s') : upIntegrand A U₁ U₂ ν₀ γ b f₁ f₂ x (v - w) =
      upIntegrand A U₁ U₂ ν₀ γ b f₁ f₂ x v - upIntegrand A U₁ U₂ ν₀ γ b f₁ f₂ x w := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:299-304 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=2 body_sha256=883470d3a4c3c2f646f6431d25a263c162bea5169a1598a75ddb85db343fb214]

lemma New.Exchange.exists_upIntegrand_bound — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L306-L328)

lean
/-- Let `x` be onto modulo an ideal `𝔪` with at least one prime divisor (`𝔪 ≠ 1`), let `f₁`, `f₂`
be automorphic functions of rapid decay for the hermitian spaces `U₁`, `U₂`, and let `ν₀`, `γ`, `b`
be any characters of `[U(1)]`. At `((g₁, g₂), h)`, `upIntegrand` is `f₁ g₁ * f₂ g₂ * ν₀ (det g₂)`
times the theta kernel of `(U₁ ⊕ U₂, A)`, twisted by `γ (det h) * (b (det (g₁ ⊕ g₂)))⁻¹`, for the
point datum at `x` with real part `w`: the theta datum whose part at `𝔪` is the indicator function
of `x` and whose part at infinity is `w`, a vector of the Fock space of the pair (`PairFock`).
There are `N` and `D` such that, whenever `fockMoment N w = ∫ (1 + ‖z‖) ^ N * |w z| dz` is finite,
this function is integrable for the product of the quotient measures of `U₁`, `U₂`, `A` and
bounded by `D * fockMoment N w`. -/
lemma New.Exchange.exists_upIntegrand_bound (h𝔪 : Nonempty 𝔪.places) (hf₁ : f₁ ∈ U₁.rapidFunctions)
    (hf₂ : f₂ ∈ U₂.rapidFunctions) {x : Matrix n' (n₁ ⊕ n₂) 𝔪.ResidueRing} (hx : HasLeftInv xᵀ) :
    ∃ (N : ℕ) (D : ℝ), ∀ w : PairFock E (s₁ ⊕ᵥ s₂) s', fockMoment N w ≠ ⊤ →
      Integrable (upIntegrand A U₁ U₂ ν₀ γ b f₁ f₂ x w)
        ((U₁.quotMeasure.prod U₂.quotMeasure).prod A.quotMeasure) ∧
      ∀ q : (G E s₁ × G E s₂) × G E s',
        ‖upIntegrand A U₁ U₂ ν₀ γ b f₁ f₂ x w q‖ ≤ D * (fockMoment N w).toReal := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:306-328 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=8 body_sha256=57e09e490abd6862fea29a3cb7681b3bac7bc2da2b18c4f6ac142ae63b2912ea]

lemma New.Exchange.integrable_upIntegrand — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L330-L341)

lean
/-- Let `𝔪` have at least one prime divisor (`𝔪.places` nonempty), and let `x` be a matrix modulo
`𝔪` whose transpose `xᵀ` has a left inverse. Let `f₁`, `f₂` be automorphic functions of rapid decay
for `U₁`, `U₂`. Let all moments `fockMoment N w` of the Fock vector `w` be finite. Then
`upIntegrand` at `x` and `w`, for any characters `ν₀`, `γ`, `b` of `[U(1)]`, is integrable for the
product of the quotient measures of `U₁`, `U₂`, `A`. -/
lemma New.Exchange.integrable_upIntegrand (h𝔪 : Nonempty 𝔪.places) (hf₁ : f₁ ∈ U₁.rapidFunctions)
    (hf₂ : f₂ ∈ U₂.rapidFunctions) {x : Matrix n' (n₁ ⊕ n₂) 𝔪.ResidueRing} (hx : HasLeftInv xᵀ)
    {w : PairFock E (s₁ ⊕ᵥ s₂) s'} (hw : IsSchwartzVector w) :
    Integrable (upIntegrand A U₁ U₂ ν₀ γ b f₁ f₂ x w)
      ((U₁.quotMeasure.prod U₂.quotMeasure).prod A.quotMeasure) := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:330-341 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=3 body_sha256=0da505056b4413d845351a7b154b8a40ac0298f81909837a1fdfa0442a5dae5d]

lemma New.Exchange.exists_norm_integral_upIntegrand_sub_le — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L343-L365)

lean
/-- Let `x` be onto modulo `𝔪 ≠ 1`, let `f₁`, `f₂` be automorphic functions of rapid decay for `U₁`,
`U₂`, and let `ν₀`, `γ`, `b` be any characters of `[U(1)]`. Here `upIntegrand` is the product of
`f₁ g₁`, `f₂ g₂`, `ν₀ (det g₂)` and the theta kernel of `(U₁ ⊕ U₂, A)`, twisted by `γ`, `b`, for the
indicator of `x` modulo `𝔪` and a vector `v` of the Fock space, the real part of the datum. Let
`J v` be its integral for `μA`, the product of the quotient measures of `U₁`, `U₂`, `A`. There are
`N` and `D` with `‖J v - J v'‖ ≤ D * fockMoment N (v' - v)` whenever `v`, `v'` and `v' - v` have a
finite moment of order `N`. -/
lemma New.Exchange.exists_norm_integral_upIntegrand_sub_le (h𝔪 : Nonempty 𝔪.places)
    (hf₁ : f₁ ∈ U₁.rapidFunctions) (hf₂ : f₂ ∈ U₂.rapidFunctions)
    {x : Matrix n' (n₁ ⊕ n₂) 𝔪.ResidueRing} (hx : HasLeftInv xᵀ) :
    let μA : Measure ((G E s₁ × G E s₂) × G E s') := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:343-365 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=12 body_sha256=edcbc6e0b7cc92c4250ad1dfcf79420586b40dcd4febb56f638b411bf566949f]

lemma New.Exchange.integrable_downIntegrand — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L367-L386)

lean
/-- Let `y` be left invertible modulo `𝔪 ≠ 1`, let `f₁`, `f₂` be automorphic functions of rapid
decay for `U₁`, `U₂`, and let `ν₀`, `γ`, `b` be any characters of `[U(1)]`. At `((g₁, g₂), h)`,
`downIntegrand` is `f₁ g₁ * f₂ g₂ * ν₀ (det g₂)` times the theta kernel of `(A', U₁ ⊕ U₂)`, twisted
by `(γ (det h))⁻¹ * b (det (g₁ ⊕ g₂))`, for the point datum at `y` with real part the Fock vector
`w`. If all moments `fockMoment N w = ∫ (1 + ‖z‖) ^ N * |w z| dz` are finite, it is integrable for
the product of the quotient measures of `U₁`, `U₂`, `A'`. -/
lemma New.Exchange.integrable_downIntegrand (h𝔪 : Nonempty 𝔪.places) (hf₁ : f₁ ∈ U₁.rapidFunctions)
    (hf₂ : f₂ ∈ U₂.rapidFunctions) {y : Matrix (n₁ ⊕ n₂) n 𝔪.ResidueRing} (hy : HasLeftInv y)
    {w : PairFock E s (s₁ ⊕ᵥ s₂)} (hw : IsSchwartzVector w) :
    Integrable (downIntegrand A' U₁ U₂ ν₀ γ b f₁ f₂ y w)
      ((U₁.quotMeasure.prod U₂.quotMeasure).prod A'.quotMeasure) := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:367-386 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=10 body_sha256=aa26537dfe260e3155642e374a0eddf56f45528a8cee7c71ec635fb463766ced]

lemma New.Exchange.integral_upIntegrand — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L388-L417)

lean
/-- Let `b₂ * ν₀ = b₁`, let `x` be a matrix modulo `𝔪` and let `P₁`, `P₂` be polynomials on the
pairs `(U₁, A)`, `(U₂, A)`. `upIntegrand` is `f₁ g₁ * f₂ g₂ * ν₀ (det g₂)` times the theta kernel of
`(U₁ ⊕ U₂, A)`. Here it is taken for the point datum at `x`, the Fock vector of `P₁ P₂` and the
characters `a₁ a₂`, `b₁`. If it is integrable, its integral is the integral over `A` of the product
of the theta lifts of `f₁`, `f₂`. -/
lemma New.Exchange.integral_upIntegrand {a₁ a₂ b₁ b₂ : AutChar E} (hb : b₂ * ν₀ = b₁)
    {x : Matrix n' (n₁ ⊕ n₂) 𝔪.ResidueRing} {P₁ : MvPolynomial (InfinitePlace E × n' × n₁) ℂ}
    {P₂ : MvPolynomial (InfinitePlace E × n' × n₂) ℂ}
    (h_int : Integrable (upIntegrand A U₁ U₂ ν₀ (a₁ * a₂) b₁ f₁ f₂ x
        (polyVector (realSigns E (homSigns (s₁ ⊕ᵥ s₂) s'))
          (renameRowsCols id Sum.inl P₁ * renameRowsCols id Sum.inr P₂)))
      ((U₁.quotMeasure.prod U₂.quotMeasure).prod A.quotMeasure)) :
    ∫ q : (G E s₁ × G E s₂) × G E s', upIntegrand A U₁ U₂ ν₀ (a₁ * a₂) b₁ f₁ f₂ x
        (polyVector (realSigns E (homSigns (s₁ ⊕ᵥ s₂) s'))
          (renameRowsCols id Sum.inl P₁ * renameRowsCols id Sum.inr P₂)) q
        ∂(U₁.quotMeasure.prod U₂.quotMeasure).prod A.quotMeasure =
      ∫ h : G E s', lift (pairThetaKer U₁ A a₁ b₁)
          (modDatum U₁ A 𝔪 (Pi.single x.toCols₁ 1) (polyVector (realSigns E (homSigns s₁ s')) P₁))
          f₁ h *
        lift (pairThetaKer U₂ A a₂ b₂)
          (modDatum U₂ A 𝔪 (Pi.single x.toCols₂ 1) (polyVector (realSigns E (homSigns s₂ s')) P₂))
          f₂ h ∂A.quotMeasure := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:388-417 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=9 body_sha256=b8bf97d8854c2550546cd8b3e078a543571364218f187d45abda65563a41cae0]

lemma New.Exchange.integral_downIntegrand — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L419-L448)

lean
/-- Let `b₂ = b₁ ν₀`, let `y` be a matrix modulo `𝔪` and let `P₁`, `P₂` be polynomials on the pairs
`(A', U₁)`, `(A', U₂)` of spaces. Suppose `downIntegrand` is integrable for `y` and the Fock vector
`polyVector` of `P₁ P₂`, with the characters `a₁ a₂` and `b₁`. Then its integral is the integral
over `A'` of a product of two transposed lifts (`swap`). These are the lifts of `f₁` and `f₂` for
the theta kernels `pairThetaKer A' Uᵢ bᵢ aᵢ`. -/
lemma New.Exchange.integral_downIntegrand {a₁ a₂ b₁ b₂ : AutChar E} (hb : b₁ * ν₀ = b₂)
    {y : Matrix (n₁ ⊕ n₂) n 𝔪.ResidueRing} {P₁ : MvPolynomial (InfinitePlace E × n₁ × n) ℂ}
    {P₂ : MvPolynomial (InfinitePlace E × n₂ × n) ℂ}
    (h_int : Integrable (downIntegrand A' U₁ U₂ ν₀ (a₁ * a₂) b₁ f₁ f₂ y
        (polyVector (realSigns E (homSigns s (s₁ ⊕ᵥ s₂)))
          (renameRowsCols Sum.inl id P₁ * renameRowsCols Sum.inr id P₂)))
      ((U₁.quotMeasure.prod U₂.quotMeasure).prod A'.quotMeasure)) :
    ∫ q : (G E s₁ × G E s₂) × G E s, downIntegrand A' U₁ U₂ ν₀ (a₁ * a₂) b₁ f₁ f₂ y
        (polyVector (realSigns E (homSigns s (s₁ ⊕ᵥ s₂)))
          (renameRowsCols Sum.inl id P₁ * renameRowsCols Sum.inr id P₂)) q
        ∂(U₁.quotMeasure.prod U₂.quotMeasure).prod A'.quotMeasure =
      ∫ h : G E s, lift (pairThetaKer A' U₁ b₁ a₁).swap
          (modDatum A' U₁ 𝔪 (Pi.single y.toRows₁ 1) (polyVector (realSigns E (homSigns s s₁)) P₁))
          f₁ h *
        lift (pairThetaKer A' U₂ b₂ a₂).swap
          (modDatum A' U₂ 𝔪 (Pi.single y.toRows₂ 1) (polyVector (realSigns E (homSigns s s₂)) P₂))
          f₂ h ∂A'.quotMeasure := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:419-448 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=9 body_sha256=b2b95230db9a0a3f225812dfd73e95e7e93c95c83cd802136b54fae4dee88b9e]

lemma New.Exchange.integral_sum_upIntegrand_eq_mul — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L450-L469)

lean
/-- Suppose that at `g = (g₁, g₂)` the theta integral `thetaIntegral` of `(U₁ ⊕ U₂, A)` with the
datum `modDatum` of `Ψ` and `w` is `c` times the integral over `A'` of the theta kernel `pairTheta`
of `(A', U₁ ⊕ U₂)` with the datum of `Ψ'` and `v`. Then the integral over `A` in `k` of
`∑ x, Ψ x • upIntegrand … x w (g, k)` is `c` times the integral over `A'` in `k` of
`∑ y, Ψ' y • downIntegrand … y v (g, k)`. -/
lemma New.Exchange.integral_sum_upIntegrand_eq_mul {a b₀ b₀' : AutChar E} {w : PairFock E (s₁ ⊕ᵥ s₂) s'}
    {v : PairFock E s (s₁ ⊕ᵥ s₂)} {Ψ : Matrix n' (n₁ ⊕ n₂) 𝔪.ResidueRing → ℂ}
    {Ψ' : Matrix (n₁ ⊕ n₂) n 𝔪.ResidueRing → ℂ} {c : ℂ} {g : G E s₁ × G E s₂}
    (h_theta : thetaIntegral (U₁.sum U₂) A a b₀ (modDatum (U₁.sum U₂) A 𝔪 Ψ w) (G.sum g) =
      c * ∫ k : G E s, pairTheta A' (U₁.sum U₂) b₀' a
        (modDatum A' (U₁.sum U₂) 𝔪 Ψ' v) (k, G.sum g) ∂A'.quotMeasure) :
    ∫ k : G E s', ∑ x : Matrix n' (n₁ ⊕ n₂) 𝔪.ResidueRing,
        Ψ x • upIntegrand A U₁ U₂ ν₀ a b₀ f₁ f₂ x w (g, k) ∂A.quotMeasure =
      c * ∫ k : G E s, ∑ y : Matrix (n₁ ⊕ n₂) n 𝔪.ResidueRing,
        Ψ' y • downIntegrand A' U₁ U₂ ν₀ a b₀' f₁ f₂ y v (g, k) ∂A'.quotMeasure := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:450-469 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=6 body_sha256=2e28ec832f43f0bd10b88d6c9a3c5c2f162bf0d907754d6aaaf96ba6c5dd0b0c]

lemma New.Exchange.exists_integral_upIntegrand_eq_mul_integral_lift — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L483-L545)

lean
/-- Let `(U₁, A)` and `(U₂, A)` be edges `e₁ → e` and `ē₂ → ē`: with the real data of the
polynomials `P₁`, `P₂`, the theta integrals lift forms of type `e₁`, `ē₂` to forms of type `e`, `ē`
on `A`. Let `w` be a real datum with finite moments, and let `b₂ i * ν₀ i = b₁ i` and `𝔪 i ≠ 1` for
all `i`. There is one number `κ` such that for every member `i` of the family, every `x` onto modulo
`𝔪 i` and all forms `f₁`, `f₂`, the integral of `upIntegrand` is `κ` times the pairing of `f₂` with
the lift of `f₁` to `A` followed by the transposed lift to `U₂`. -/
lemma New.Exchange.exists_integral_upIntegrand_eq_mul_integral_lift {ν₀ : I → AutChar E} {𝔪 : I → Modulus E}
    (h₁ : IsPairEdge a₁ b₁ e₁ e P₁) (h₂ : IsPairEdge a₂ b₂ (star e₂) (star e) P₂)
    (hb : ∀ i : I, b₂ i * ν₀ i = b₁ i) (h𝔪 : ∀ i : I, Nonempty (𝔪 i).places)
    {w : PairFock E (s₁ ⊕ᵥ s₂) s'} (hw : IsSchwartzVector w) :
    ∃ κ : ℂ, ∀ (i : I) (x : Matrix n' (n₁ ⊕ n₂) (𝔪 i).ResidueRing), HasLeftInv xᵀ →
      ∀ (f₁ : U₁.Form e₁) (f₂ : U₂.Form (star e₂)),
      ∫ q : (G E s₁ × G E s₂) × G E s', upIntegrand A U₁ U₂ (ν₀ i) (a₁ i * a₂ i) (b₁ i) f₁ f₂ x w q
          ∂(U₁.quotMeasure.prod U₂.quotMeasure).prod A.quotMeasure =
        κ * ∫ g : G E s₂, f₂ g * pairTransposedLift U₂ A (a₂ i) (b₂ i) P₂ (Pi.single x.toCols₂ 1)
          e e₂ (pairLift U₁ A (a₁ i) (b₁ i) P₁ (Pi.single x.toCols₁ 1) e₁ e f₁) g
          ∂U₂.quotMeasure := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:483-545 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=47 body_sha256=47cd3186ac0cfee593466d5d581a168e8e04410ef23dfa151b53347b44af4944]

lemma New.Exchange.pairTransposedLift_comp_pairLift_mul — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L547-L583)

lean
/-- Let `U₁`, `U₂`, `A` be hermitian spaces, `I` a set and, for `i` in `I`, let `(a₁ i, b₁ i)`,
`(a₂ i, b₂ i)` be the characters of `[U(1)]` on the pairs `(U₁, A)`, `(U₂, A)`. Let these pairs be
edges `e₁ → e` and `ē₂ → ē` (`IsPairEdge`): with the real data of the polynomials `P₁`, `P₂`, theta
integrals lift forms of the first type to forms of the second, a bar being complex conjugation. Take
the lift from `U₁` to `A` followed by the transposed lift to `U₂`, the data modulo `𝔪` being the
indicator functions of the two column blocks of a matrix `x` with rows `n'`, the index set of `A`.
Replacing `x` by `g x` multiplies this map by `χ (det g)`, if `(a₁ i * a₂ i)⁻¹` is tame for
`(𝔪, χ)`: it has some weight `μ` at the infinite places, and its tame part is nontrivial exactly at
the places dividing `𝔪 ≠ 1` and defines `χ` on the residue ring. -/
lemma New.Exchange.pairTransposedLift_comp_pairLift_mul (h₁ : IsPairEdge a₁ b₁ e₁ e P₁)
    (h₂ : IsPairEdge a₂ b₂ (star e₂) (star e) P₂) (i : I) {𝔪 : Modulus E} {μ : InfinitePlace E → ℤ}
    {χ : MulChar 𝔪.ResidueRing ℂ} (h_tame : IsTameFor 𝔪 (a₁ i * a₂ i)⁻¹ μ χ)
    (g : GL n' 𝔪.ResidueRing) (x : Matrix n' (n₁ ⊕ n₂) 𝔪.ResidueRing) :
    pairTransposedLift U₂ A (a₂ i) (b₂ i) P₂ (Pi.single (g.val * x).toCols₂ 1) e e₂ ∘ₗ
        pairLift U₁ A (a₁ i) (b₁ i) P₁ (Pi.single (g.val * x).toCols₁ 1) e₁ e =
      χ g.val.det • (pairTransposedLift U₂ A (a₂ i) (b₂ i) P₂ (Pi.single x.toCols₂ 1) e e₂ ∘ₗ
        pairLift U₁ A (a₁ i) (b₁ i) P₁ (Pi.single x.toCols₁ 1) e₁ e) := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:547-583 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=21 body_sha256=d1edfd33da4b6c27c63380c0592f559a164df8c37913f25e8fdff11e54f2de90]

lemma New.Exchange.pairLift_comp_pairTransposedLift_mul — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L585-L622)

lean
/-- Let `A'`, `U₁`, `U₂` be hermitian spaces, `I` a set and, for `i` in `I`, let `(b₁' i, a₁' i)`,
`(b₂' i, a₂' i)` be the characters of `[U(1)]` on the pairs `(A', U₁)`, `(A', U₂)`. Let these pairs
be edges `ē' → ē₁` and `e' → e₂` (`IsPairEdge`): with the real data of the polynomials `P₁'`, `P₂'`,
theta integrals lift forms of the first type to forms of the second, a bar being complex
conjugation. Take the transposed lift from `U₁` to `A'` followed by the lift to `U₂`, the data
modulo `𝔪` being the indicator functions of the two row blocks of a matrix `y` with columns `n`,
the index set of `A'`. Replacing `y` by `y g` multiplies this map by `χ (det g)`, if
`(a₁' i * a₂' i)⁻¹` is tame for `(𝔪, χ)`: it has some weight `μ` at the infinite places, and its
tame part is nontrivial exactly at the places dividing `𝔪 ≠ 1` and defines `χ` on the residue
ring. -/
lemma New.Exchange.pairLift_comp_pairTransposedLift_mul (h₁ : IsPairEdge b₁' a₁' (star e') (star e₁) P₁')
    (h₂ : IsPairEdge b₂' a₂' e' e₂ P₂') (i : I) {𝔪 : Modulus E} {μ : InfinitePlace E → ℤ}
    {χ : MulChar 𝔪.ResidueRing ℂ} (h_tame : IsTameFor 𝔪 (a₁' i * a₂' i)⁻¹ μ χ)
    (g : GL n 𝔪.ResidueRing) (y : Matrix (n₁ ⊕ n₂) n 𝔪.ResidueRing) :
    pairLift A' U₂ (b₂' i) (a₂' i) P₂' (Pi.single (y * g.val).toRows₂ 1) e' e₂ ∘ₗ
        pairTransposedLift A' U₁ (b₁' i) (a₁' i) P₁' (Pi.single (y * g.val).toRows₁ 1) e₁ e' =
      χ g.val.det • (pairLift A' U₂ (b₂' i) (a₂' i) P₂' (Pi.single y.toRows₂ 1) e' e₂ ∘ₗ
        pairTransposedLift A' U₁ (b₁' i) (a₁' i) P₁' (Pi.single y.toRows₁ 1) e₁ e') := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:585-622 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=21 body_sha256=cd782c99b7115c621cccb34da18941b0807232c20c6dc0256ac59ffcd1b9a4eb]

lemma New.Exchange.integral_transposedLift_mul_transposedLift — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L624-L643)

lean
/-- Let `A'`, `U₁`, `U₂` be hermitian spaces with signs `s`, `s₁`, `s₂`, let the characters
`(b₁' i, a₁' i)`, `(b₂' i, a₂' i)` of `[U(1)]` be attached to the pairs `(A', U₁)`, `(A', U₂)`, and
let these be edges `ē' → ē₁` and `e' → e₂` (`IsPairEdge`): with the real data of `P₁'`, `P₂'`, theta
integrals lift forms of the first type to forms of the second. For forms `f₁`, `f₂` on `U₁`, `U₂` of
types `e₁`, `ē₂`, the integral over the adelic unitary group of `A'`, for its quotient measure
`quotMeasure`, of the product of the transposed lifts of `f₁` and `f₂` is the pairing on `U₂` of
`f₂` with the transposed lift of `f₁` to `A'` followed by the lift to `U₂`. -/
lemma New.Exchange.integral_transposedLift_mul_transposedLift (h₁ : IsPairEdge b₁' a₁' (star e') (star e₁) P₁')
    (h₂ : IsPairEdge b₂' a₂' e' e₂ P₂') (i : I) {𝔪 : Modulus E} (Ψ₁ : Matrix n₁ n 𝔪.ResidueRing → ℂ)
    (Ψ₂ : Matrix n₂ n 𝔪.ResidueRing → ℂ) (f₁ : U₁.Form e₁) (f₂ : U₂.Form (star e₂)) :
    ∫ h : G E s, lift (pairThetaKer A' U₁ (b₁' i) (a₁' i)).swap
          (modDatum A' U₁ 𝔪 Ψ₁ (polyVector (realSigns E (homSigns s s₁)) P₁')) f₁ h *
        lift (pairThetaKer A' U₂ (b₂' i) (a₂' i)).swap
          (modDatum A' U₂ 𝔪 Ψ₂ (polyVector (realSigns E (homSigns s s₂)) P₂')) f₂ h
        ∂A'.quotMeasure =
      ∫ g : G E s₂, f₂ g * pairLift A' U₂ (b₂' i) (a₂' i) P₂' Ψ₂ e' e₂
        (pairTransposedLift A' U₁ (b₁' i) (a₁' i) P₁' Ψ₁ e₁ e' f₁) g ∂U₂.quotMeasure := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:624-643 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=4 body_sha256=4cc59a11ecd85e95330719ae0b3cf2be169d6616891ef7e4da850f0e1abec65d]

lemma New.Exchange.integral_integral_sum_downIntegrand — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L645-L677)

lean
/-- Let `A'`, `U₁`, `U₂` be hermitian spaces with pairs `(A', U₁)`, `(A', U₂)` that are edges
`star e' → star e₁`, `e' → e₂` for the characters `(b₁' i, a₁' i)`, `(b₂' i, a₂' i)` of `[U(1)]`.
Let `b₁' i * ν₀ = b₂' i`, let `𝔪 ≠ 1`, let `Ψ'` vanish off the left invertible matrices, and let the
forms `f₁`, `f₂` of types `e₁`, `star e₂` be rapidly decreasing (`rapidFunctions`). Here
`downIntegrand` at `y` is the theta kernel of `(A', U₁ ⊕ U₂)` for the point datum at `y` with real
part the Fock vector of `P₁' P₂'`, the variables renamed to the two row blocks by `renameRowsCols`,
times `f₁`, `f₂` and `ν₀ ∘ det`. The integral over `U₁ × U₂` and `A'` (quotient measures) of its sum
over `y`, weighted by `Ψ'`, is the sum, weighted by `Ψ'`, of the pairings of `f₂` with the
transposed lift of `f₁` to `A'` followed by the lift to `U₂`. -/
lemma New.Exchange.integral_integral_sum_downIntegrand (h₁ : IsPairEdge b₁' a₁' (star e') (star e₁) P₁')
    (h₂ : IsPairEdge b₂' a₂' e' e₂ P₂') (i : I) {ν₀ : AutChar E} (hb : b₁' i * ν₀ = b₂' i)
    {𝔪 : Modulus E} (h𝔪 : Nonempty 𝔪.places) {Ψ' : Matrix (n₁ ⊕ n₂) n 𝔪.ResidueRing → ℂ}
    (hΨ' : ∀ y : Matrix (n₁ ⊕ n₂) n 𝔪.ResidueRing, Ψ' y ≠ 0 → HasLeftInv y) {f₁ : U₁.Form e₁}
    {f₂ : U₂.Form (star e₂)} (hf₁ : f₁.val ∈ U₁.rapidFunctions) (hf₂ : f₂.val ∈ U₂.rapidFunctions) :
    ∫ g : G E s₁ × G E s₂, ∫ h : G E s, ∑ y : Matrix (n₁ ⊕ n₂) n 𝔪.ResidueRing,
        Ψ' y • downIntegrand A' U₁ U₂ ν₀ (a₁' i * a₂' i) (b₁' i) f₁ f₂ y
          (polyVector (realSigns E (homSigns s (s₁ ⊕ᵥ s₂)))
            (renameRowsCols Sum.inl id P₁' * renameRowsCols Sum.inr id P₂')) (g, h)
        ∂A'.quotMeasure ∂U₁.quotMeasure.prod U₂.quotMeasure =
      ∑ y : Matrix (n₁ ⊕ n₂) n 𝔪.ResidueRing, Ψ' y • ∫ g : G E s₂, f₂ g *
        pairLift A' U₂ (b₂' i) (a₂' i) P₂' (Pi.single y.toRows₂ 1) e' e₂
          (pairTransposedLift A' U₁ (b₁' i) (a₁' i) P₁' (Pi.single y.toRows₁ 1) e₁ e' f₁) g
        ∂U₂.quotMeasure := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:645-677 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=11 body_sha256=249d85662f81e027753a9436b76835c6c0f04e5f70e80af6a767ef7c0f1f3e0c]

lemma New.Exchange.ne_zero_of_norm_sq_eq — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L679-L681)

lean
lemma New.Exchange.ne_zero_of_norm_sq_eq {c : ℂ} {r : ℝ} (h : ‖c‖ ^ 2 = r) (hr : r ≠ 0) : c ≠ 0 := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:679-681 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=3 body_sha256=acb1bb16d8129a2d5fad0225f6e9410e61beb467175c8fd02c6defd0276fd56e]

structure New.Exchange.IsSquare — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L684-L722)

lean
/-- A family of squares with the same real data. The corners are spaces `U₁`, `U₂`, `A`, `A'` with
signs `s₁`, `s₂`, `s'`, `s`, and `W = U₁ ⊕ U₂`. The pairs `(U₁, A)`, `(U₂, A)`, `(A', U₁)`,
`(A', U₂)` carry the characters `(a₁, b₁)`, `(a₂, b₂)`, `(b₁', a₁')`, `(b₂', a₂')`, which depend on
the member `i` of the family, and the polynomials `P₁`, `P₂`, `P₁'`, `P₂'`. For a character `α` of
`[U(1)]`, `α.baseChange` is the Hecke character `x ↦ α (x / x̄)`, and the splitting character of a
space of rank `m` that carries `α` is `α.spaceChar m = α.baseChange * υ⁻¹ ^ m`. -/
structure New.Exchange.IsSquare (t : ℕ) (μ : InfinitePlace E → ℤ) (𝔪 : I → Modulus E) (ν : I → AutChar E)
    (χ : ∀ i : I, MulChar (𝔪 i).ResidueRing ℂ) : Prop where
  /-- `W` has as many negative signs as `A` and `A'` together. -/
  negCount_eq : negCount (s₁ ⊕ᵥ s₂) = negCount s' + negCount s
  /-- The ranks of `A` and `A'` differ by `2 t`. -/
  card_eq : card n' = card n + 2 * t
  /-- Half the rank of `W` exceeds the number of its negative signs. -/
  negCount_lt_half : 2 * negCount (s₁ ⊕ᵥ s₂) + 2 ≤ card (n₁ ⊕ n₂)
  /-- The weights are at least this excess. -/
  card_le_weight (τ : InfinitePlace E) : card (n₁ ⊕ n₂) ≤ 2 * μ τ + 2 * negCount (s₁ ⊕ᵥ s₂)
  /-- The character `ν i` of `[U(1)]` is tame of weight `μ` for `(𝔪 i, χ i)`. -/
  tame (i : I) : IsTameFor (𝔪 i) (ν i) μ (χ i)
  /-- The pair `(U₁, A)` is an edge `e₁ → e`. -/
  edge₁ : IsPairEdge a₁ b₁ e₁ e P₁
  /-- The pair `(U₂, A)` is an edge `ē₂ → ē`. -/
  edge₂ : IsPairEdge a₂ b₂ (star e₂) (star e) P₂
  /-- The pair `(A', U₁)` is an edge `ē' → ē₁`. -/
  edge₁' : IsPairEdge b₁' a₁' (star e') (star e₁) P₁'
  /-- The pair `(A', U₂)` is an edge `e' → e₂`. -/
  edge₂' : IsPairEdge b₂' a₂' e' e₂ P₂'
  /-- On the side of `A`, the splitting characters of `U₁`, `U₂` multiply to `ν̃⁻¹`, the inverse
  base change of `ν`. -/
  spaceChar_mul_up (i : I) : (a₁ i).spaceChar (card n₁) * (a₂ i).spaceChar (card n₂) =
    (ν i).baseChange⁻¹
  /-- So do those on the side of `A'`. -/
  spaceChar_mul_down (i : I) :
    (a₁' i).spaceChar (card n₁) * (a₂' i).spaceChar (card n₂) = (ν i).baseChange⁻¹
  /-- At `U₁`, the splitting characters of `A`, `A'` multiply to `ν̃⁻¹`. -/
  spaceChar_mul_first (i : I) : (b₁ i).spaceChar (card n') * (b₁' i).spaceChar (card n) =
    (ν i).baseChange⁻¹
  /-- So do those at `U₂`. -/
  spaceChar_mul_second (i : I) :
    (b₂ i).spaceChar (card n') * (b₂' i).spaceChar (card n) = (ν i).baseChange⁻¹

theorem New.Exchange.exists_sum_pairLift_comp_pairTransposedLift_eq_smul — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L726-L852)

lean
/-- On matched functions, a transposed lift followed by a lift is a multiple, possibly zero, of a
lift followed by a transposed lift.

The family satisfies `IsSquare`: the four pairs are edges; `ν i` is tame for `𝔪 i ≠ 1`: weight `μ`
at infinity, tame part nontrivial exactly at the places dividing `𝔪 i`, defining `χ i` on the
residue ring; `card n' = card n + 2 t`; the number `N` of negative signs of `W = U₁ ⊕ U₂` is that of
`A` and `A'` together, with `2 N + 2 ≤ card (n₁ ⊕ n₂) ≤ 2 μ τ + 2 N`; the splitting characters
`x ↦ α (x / x̄) * υ x ^ (-m)` of spaces of rank `m` with character `α`, `υ` being the splitting
character of the Weil data, multiply in pairs to the inverse base change of `ν i`. Let `σ` order the
index set of `W` as that of `A'` followed by that of `A`. Let `Θ i x` be the lift from `U₁` to `A`
followed by the transposed lift to `U₂`, and `Θ' i y` the transposed lift to `A'` followed by the
lift to `U₂`, the data modulo `𝔪 i` being the indicator functions of the blocks of `x`, `y`.

There are `C > 0` and `κ`, possibly zero, and for each `i` a number `c` with
`‖c‖ ^ 2 = C * lValueProd (𝔪 i).places (ν i) t ≠ 0`, such that
`∑ Ψ' y • Θ' i y = (κ / c) • ∑ Ψ x • Θ i x` for all matched functions `Ψ`, `Ψ'` of matrices modulo
`𝔪 i`. Here `lValueProd S ν t = ∏_{w ∈ S} q_w ^ (t ^ 2) ∏_{1 ≤ z ≤ t} |L^S(z, ν)| ^ 2`, with `q_w`
the residue cardinality and `L^S(z, ν)` the Euler product of the base change of `ν` outside
`S ∪ S̄`. Matched over the whole residue ring (`⊤`) means: as `k` runs over the invertible matrices
indexed by `n₁ ⊕ n₂`, `Ψ` vanishes off the blocks `x` of rows `n'` of `k⁻¹`, `Ψ'` vanishes off the
blocks `y` of columns `n` of `k`, and `Ψ x = χ i (det k) * Ψ' y` for the two blocks of one `k`. -/
theorem New.Exchange.exists_sum_pairLift_comp_pairTransposedLift_eq_smul
    (A' : Space E n s) (A : Space E n' s') (U₁ : Space E n₁ s₁) (U₂ : Space E n₂ s₂)
    {I : Type*} {e : GInf E s' → ℂ} {e' : GInf E s → ℂ} {e₁ : GInf E s₁ → ℂ} {e₂ : GInf E s₂ → ℂ}
    {a₁ a₂ b₁ b₂ a₁' a₂' b₁' b₂' : I → AutChar E}
    {P₁ : MvPolynomial (InfinitePlace E × n' × n₁) ℂ}
    {P₂ : MvPolynomial (InfinitePlace E × n' × n₂) ℂ}
    {P₁' : MvPolynomial (InfinitePlace E × n₁ × n) ℂ}
    {P₂' : MvPolynomial (InfinitePlace E × n₂ × n) ℂ} (σ : n ⊕ n' ≃ n₁ ⊕ n₂) {t : ℕ}
    {μ : InfinitePlace E → ℤ} {𝔪 : I → Modulus E} {ν : I → AutChar E}
    {χ : ∀ i : I, MulChar (𝔪 i).ResidueRing ℂ}
    (h_square : IsSquare e e' e₁ e₂ a₁ a₂ b₁ b₂ a₁' a₂' b₁' b₂' P₁ P₂ P₁' P₂' t μ 𝔪 ν χ) :
    let Θ (i : I) (x : Matrix n' (n₁ ⊕ n₂) (𝔪 i).ResidueRing) : U₁.Form e₁ →ₗ[ℂ] U₂.Form e₂ := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:726-852 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=94 body_sha256=8611c695f690118be36d72bfb536b306f5d7321093d8bfa6849240d22273741b]

theorem New.Exchange.equivariant_and_exists_sum_eq_of_areMatched — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L854-L948)

lean
/-- One square: two ways to lift forms from `U₁` to `U₂`, through `A` or through `A'`, transform by
the same character and agree on matched functions up to a constant.

Let `E` be a CM field with Weil data, which fix a splitting Hecke character `υ` of `E`. Let `A'`,
`A`, `U₁`, `U₂` be hermitian spaces over `E` with index sets `n`, `n'`, `n₁`, `n₂` and signs `s`,
`s'`, `s₁`, `s₂` at the infinite places (`A'` goes with the unprimed letters). Let `σ` order the
index set of `W = U₁ ⊕ U₂` as `n` followed by `n'`. The types `e'`, `e`, `e₁`, `e₂` are functions on
the real unitary groups (`GInf`) of the four spaces; a type prescribes the behavior of a form at the
infinite places, and `U₁.Form e₁` is the space of forms of type `e₁` on `U₁`. For `i` in a set `I`,
the pairs `(U₁, A)`, `(U₂, A)`, `(A', U₁)`, `(A', U₂)` carry the characters `(a₁ i, b₁ i)`,
`(a₂ i, b₂ i)`, `(b₁' i, a₁' i)`, `(b₂' i, a₂' i)` of `[U(1)]`, the norm-one ideles of `E` modulo
those from `E`, and the polynomials `P₁`, `P₂`, `P₁'`, `P₂'`, whose Fock vectors are the real theta
data.

The hypothesis `IsSquare` says:
* the rank of `A` is that of `A'` plus `2 t`;
* the number `N` of negative signs of `W` is that of `A` and `A'` together, and
  `2 N + 2 ≤ card (n₁ ⊕ n₂) ≤ 2 μ τ + 2 N` at every infinite place `τ`;
* `ν i` is tame for `𝔪 i ≠ 1`: it has weight `μ` at the infinite places, and its tame part is
  nontrivial exactly at the places dividing `𝔪 i` and defines the character `χ i` of the residue
  ring `R = 𝓞 E / 𝔪 i`;
* the four pairs are edges `e₁ → e`, `ē₂ → ē`, `ē' → ē₁`, `e' → e₂`, a bar being complex conjugation
  (`New.Exchange.IsPairEdge`): the characters have weights independent of `i`, and the theta
  integral lifts forms of the first type to forms of the second;
* with `α[m]` the Hecke character `x ↦ α (x / x̄) * υ x ^ (-m)`, each of the four products
  `a₁[card n₁] a₂[card n₂]`, `a₁'[card n₁] a₂'[card n₂]`, `b₁[card n'] b₁'[card n]`,
  `b₂[card n'] b₂'[card n]` at `i` is the inverse of the base change `x ↦ ν i (x / x̄)`.

For a matrix `x` over `R`, `Θ i x` is the theta lift (`pairLift`) from `U₁` to `A` followed by the
transposed lift (`pairTransposedLift`) to `U₂`; the data modulo `𝔪 i` are the indicator functions of
the two column blocks of `x`. For a matrix `y` over `R`, `Θ' i y` is the transposed lift from `U₁`
to `A'` followed by the lift to `U₂`, for the indicator functions of the two row blocks of `y`.
Then:

(a) `Θ i (g x) = χ i (det g) • Θ i x` and `Θ' i (y g) = χ i (det g) • Θ' i y` for invertible `g`.

(b) There are `C > 0` and a number `κ`, possibly zero, both independent of `i`, and for each `i` a
number `c` with `‖c‖ ^ 2 = C * lValueProd S (ν i) t ≠ 0`, such that
`∑ Ψ' y • Θ' i y = (κ / c) • ∑ Ψ x • Θ i x` for all matched `Ψ`, `Ψ'`. Here `S` is the set of places
dividing `𝔪 i`, and `lValueProd S ν t = ∏_{w ∈ S} q_w ^ (t ^ 2) ∏_{1 ≤ z ≤ t} |L^S(z, ν)| ^ 2`, with
`q_w` the residue cardinality and `L^S(z, ν)` the Euler product of the base change of `ν` outside
`S ∪ S̄`. -/
theorem New.Exchange.equivariant_and_exists_sum_eq_of_areMatched {E n n' n₁ n₂ : Type} [Field E] [CMType E]
    [WeilData E] [Fintype n] [DecidableEq n] [Fintype n'] [DecidableEq n']
    [Fintype n₁] [DecidableEq n₁] [Fintype n₂] [DecidableEq n₂]
    {s : n → ℤˣ} {s' : n' → ℤˣ} {s₁ : n₁ → ℤˣ} {s₂ : n₂ → ℤˣ}
    (A' : Space E n s) (A : Space E n' s') (U₁ : Space E n₁ s₁) (U₂ : Space E n₂ s₂) {I : Type*}
    {e : GInf E s' → ℂ} {e' : GInf E s → ℂ} {e₁ : GInf E s₁ → ℂ} {e₂ : GInf E s₂ → ℂ}
    {a₁ a₂ b₁ b₂ a₁' a₂' b₁' b₂' : I → AutChar E}
    {P₁ : MvPolynomial (InfinitePlace E × n' × n₁) ℂ}
    {P₂ : MvPolynomial (InfinitePlace E × n' × n₂) ℂ}
    {P₁' : MvPolynomial (InfinitePlace E × n₁ × n) ℂ}
    {P₂' : MvPolynomial (InfinitePlace E × n₂ × n) ℂ} (σ : n ⊕ n' ≃ n₁ ⊕ n₂) {t : ℕ}
    {μ : InfinitePlace E → ℤ} {𝔪 : I → Modulus E} {ν : I → AutChar E}
    {χ : ∀ i : I, MulChar (𝔪 i).ResidueRing ℂ}
    (h_square : IsSquare e e' e₁ e₂ a₁ a₂ b₁ b₂ a₁' a₂' b₁' b₂' P₁ P₂ P₁' P₂' t μ 𝔪 ν χ) :
    let Θ (i : I) (x : Matrix n' (n₁ ⊕ n₂) (𝔪 i).ResidueRing) : U₁.Form e₁ →ₗ[ℂ] U₂.Form e₂ := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:854-948 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=38 body_sha256=db5c35252c59f9abf4869635e3c9128fcd87c240a0edbd0606f96fcc6791e41f]

lemma New.Exchange.one_square_identity_of_isEdgeFamily — Upstream source (src/New/Determinant/Exchange/OneSquare.lean L950-L1045)

lean
/-- The case of `New.Exchange.equivariant_and_exists_sum_eq_of_areMatched` in which the characters
of `[U(1)]` come from two families `a`, `b` indexed by finite types: `a` on the pairs `(U₁, A)` and
`(A', U₂)`, `b` on `(U₂, A)` and `(A', U₁)`, with `a i p * b i q = rankTwist (ν i)⁻¹ (n₁ ⊕ n₂)`
whenever `card p + card q = card n₁ + card n₂`; here `rankTwist α N = α * upsilonU1 ^ (card N / 2)`,
with `upsilonU1` the restriction to `[U(1)]` of the fixed splitting character. A type of forms is a
function on the real unitary group (`GInf`); `k₁`, `k₂`, `k`, `k'` are pairs of conjugate types on
`U₁`, `U₂`, `A`, `A'`, the edges `h₂`, `h₁'` of the family `b` are taken at `d`, the edges `h₁`,
`h₂'` of the family `a` at `!d`, and the forms in the conclusion have types `k₁ !d`, `k₂ !d`. The
four edges are edge families: the characters of each family have fixed weights, a common tame part,
and the theta integral with the Fock vector of the given polynomial lifts forms of the type at that
edge's index (`d` or `!d`) to forms of the type at the same index. The number `N` of negative signs
of `W = U₁ ⊕ U₂` is that of `A` and `A'` together, the rank of `A` is that of `A'` plus `2 t`,
`2 N + 2 ≤ card (n₁ ⊕ n₂) ≤ 2 μ τ + 2 N` at every infinite place `τ`, and `ν i` is tame of weight
`μ` for the modulus `𝔪 i`: it has weight `μ` at infinity, and its tame part is ramified exactly at
the primes of `𝔪 i` and defines the character `χ i` of the residue ring.

Send a form `f` from `U₁` to `U₂` through `A` (`Θ i x`: lift, then transposed lift) or through `A'`
(`Θ' i y`: transposed lift, then lift), the data modulo `𝔪 i` being the indicator functions of the
blocks of `x` or `y`. There are `C` and `κ`, and for each `i` some `c ≠ 0` with
`‖c‖ ^ 2 = C * lValueProd (𝔪 i).places (ν i) t`, such that for every functional `l` the functions
`L x = l (Θ i x f)` and `L' y = l (Θ' i y f)` satisfy `New.Exchange.SquareLaw` with constant
`κ / c`: both transform by `χ i ∘ det`, and `∑ Ψ' L' = (κ / c) ∑ Ψ L` for all matched `Ψ`, `Ψ'`. -/
lemma New.Exchange.one_square_identity_of_isEdgeFamily (A' : Space E n s) (A : Space E n' s')
    (U₁ : Space E n₁ s₁) (U₂ : Space E n₂ s₂) {I : Type*}
    {k₁ : Bool → GInf E s₁ → ℂ} {k₂ : Bool → GInf E s₂ → ℂ} {d : Bool}
    {k : Bool → GInf E s' → ℂ} {Φ₁ : MvPolynomial (InfinitePlace E × n' × n₁) ℂ}
    {Φ₂ : MvPolynomial (InfinitePlace E × n' × n₂) ℂ} {k' : Bool → GInf E s → ℂ}
    {Φ₁' : MvPolynomial (InfinitePlace E × n₁ × n) ℂ}
    {Φ₂' : MvPolynomial (InfinitePlace E × n₂ × n) ℂ}
    {a b : I → ∀ (m : Type) [Fintype m], AutChar E} {ν : I → AutChar E} {𝔪 : I → Modulus E}
    {χ : ∀ i : I, MulChar (𝔪 i).ResidueRing ℂ}
    (h₂ : IsEdgeFamily b k₂ k d Φ₂) (h₁ : IsEdgeFamily a k₁ k (!d) Φ₁)
    (h₂' : IsEdgeFamily a k' k₂ (!d) Φ₂') (h₁' : IsEdgeFamily b k' k₁ d Φ₁') (σ : n ⊕ n' ≃ n₁ ⊕ n₂)
    (h_signs : negCount (s₁ ⊕ᵥ s₂) = negCount s' + negCount s) (t : ℕ)
    (h_rank : card n' = card n + 2 * t) (h_few_neg : 2 * negCount (s₁ ⊕ᵥ s₂) + 2 ≤ card (n₁ ⊕ n₂))
    {μ : InfinitePlace E → ℤ}
    (hμ : ∀ τ : InfinitePlace E, card (n₁ ⊕ n₂) ≤ 2 * μ τ + 2 * negCount (s₁ ⊕ᵥ s₂))
    (h_tame : ∀ i : I, IsTameFor (𝔪 i) (ν i) μ (χ i))
    (h_chars : ∀ (i : I) {p q : Type} [Fintype p] [Fintype q],
      card p + card q = card n₁ + card n₂ → a i p * b i q = rankTwist (ν i)⁻¹ (n₁ ⊕ n₂)) :
    let Θ (i : I) (x : Matrix n' (n₁ ⊕ n₂) (𝔪 i).ResidueRing) :
        U₁.Form (k₁ !d) →ₗ[ℂ] U₂.Form (k₂ !d) := by
  sorry -- [EXTRACTED_STUB upstream=src/New/Determinant/Exchange/OneSquare.lean:950-1045 commit=41c2716658c42ba08eb0648994a2efe83082a95c body_lines=54 body_sha256=9bdf84c798e83e55361574e231953b90d1df95a84d0a2a30514e1c6e64080177]

Page Glossary ​

Siegel–Weil exchange
Comparing theta integrals to U(W) from two complementary-rank spaces V and V' on matched ramified matrix functions modulo m—agreeing up to a nonzero scalar c with |c|^2 = C * L_*(e).
theta correspondence
An integral transform built from a two-variable theta kernel that carries automorphic forms from one unitary group to another, iterated along a ladder of Hermitian spaces and packaged via admissible chain data.
complex plane
The two-dimensional coordinate plane of numbers s = σ + it, where the horizontal coordinate σ = Re(s) sets decay rate and the vertical coordinate t = Im(s) sets oscillation frequency.
Hecke L-value ratio
The ratio |L^S(z, (nu * theta^s)^-1)| / |L^S(z, nu^-1)| of twisted to untwisted partial Hecke L-values at a critical pair (nu, z), tracking how Siegel–Weil exchange constants scale under twisting across chain quotients and grid turns.
seesaw duality
A dual-pair adjunction identity that trades an iterated lower-chain theta lift of a Poincaré series for a nonzero twist-independent scalar times the restriction of an upper-chain composite theta lift.
theta square law
Commutation of theta lifts around a four-corner square (U_1, U_2, A, A'): summing down-then-up over matched matrix data equals (kappa / c) times summing up-then-down, with |c|^2 = C * L_*(t) != 0 and kappa independent of twist.
Rallis inner product formula
Relating the squared norm (and Gram determinant) of a theta lift or m-step chain of lifts to spherical Hecke operators and single-lift determinants—factoring Z(theta)/Z(1) across m lifts up to quotient L-value ratios.