import Mathlib.Topology.Algebra.InfiniteSum.Basic import F04Riemann.TestFunctions /-! # The Weil Quadratic Form `Q(φ)` and Polarized Sesquilinear Form `B(a, b)` (F04 §2) This module defines the exact Weil quadratic form `Q_form` (eq. (2)) and polarized sesquilinear form `B_form` (eq. (3)) from Section 2 of F04, proves finite support and summability of the prime-power sums, proves sesquilinearity, Hermitian symmetry `B_form a b = conj (B_form b a)`, diagonal recovery `B_form φ φ = Q_form φ`, and the exact finite-sum expansion `Q_form (∑ i, c i • φ i)`. -/ namespace F04Riemann open Real Complex MeasureTheory Set Finset /-! ### 1. Finite Support and Summability of the Prime-Power Sum -/ /-- The `n`-th complex arithmetic term in `B(a, b)` (zero for `n < 2` since `Λ(0) = Λ(1) = 0`). -/ noncomputable def arithTermB (a b : TestFn) (n : ℕ) : ℂ := ((arithWeight n : ℝ) : ℂ) * (corr a b (Real.log (n : ℝ)) + corr a b (-Real.log (n : ℝ))) /-- The `n`-th real arithmetic term in `Q(φ)` (zero for `n < 2`). -/ noncomputable def arithTermQ (φ : TestFn) (n : ℕ) : ℝ := arithWeight n * (autoCorr φ (Real.log (n : ℝ))).re lemma arithTermB_finite_support (a b : TestFn) : (Function.support (arithTermB a b)).Finite := by obtain ⟨a₁, b₁, _, ha⟩ := exists_Icc_support_of_hasCompactSupport a.compactSupport obtain ⟨a₂, b₂, _, hb⟩ := exists_Icc_support_of_hasCompactSupport b.compactSupport set M := max (b₁ - a₂) (b₂ - a₁) refine (Set.finite_Iic (Nat.floor (Real.exp (max M 0)) + 1)).subset ?_ intro n hn rw [Function.mem_support] at hn rw [Set.mem_Iic] by_contra hgt push Not at hgt have h2 : 2 ≤ n := by by_contra hlt push Not at hlt exact hn (by simp [arithTermB, arithWeight_eq_zero_of_lt_two hlt]) have hnpos : (0 : ℝ) < (n : ℝ) := by exact_mod_cast (show 0 < n by omega) have hexp_lt : Real.exp (max M 0) < (n : ℝ) := by have hfl := Nat.lt_floor_add_one (Real.exp (max M 0)) have hle : ((Nat.floor (Real.exp (max M 0)) + 1 : ℕ) : ℝ) ≤ (n : ℝ) := by exact_mod_cast hgt.le push_cast at hle linarith have hlog_gt : max M 0 < Real.log (n : ℝ) := by rw [← Real.exp_lt_exp, Real.exp_log hnpos]; exact hexp_lt have h1 : b₁ - a₂ ≤ Real.log (n : ℝ) := le_trans (le_trans (le_max_left _ _) (le_max_left _ _)) hlog_gt.le have h2' : -Real.log (n : ℝ) ≤ a₁ - b₂ := by have : b₂ - a₁ ≤ Real.log (n : ℝ) := le_trans (le_trans (le_max_right _ _) (le_max_left _ _)) hlog_gt.le linarith have hc1 : corr a b (Real.log (n : ℝ)) = 0 := corr_eq_zero_of_ge ha hb h1 have hc2 : corr a b (-Real.log (n : ℝ)) = 0 := corr_eq_zero_of_le ha hb h2' exact hn (by simp [arithTermB, hc1, hc2]) lemma summable_arithTermB (a b : TestFn) : Summable (arithTermB a b) := summable_of_ne_finset_zero (s := (arithTermB_finite_support a b).toFinset) (fun n hn => by by_contra hne exact hn ((arithTermB_finite_support a b).mem_toFinset.mpr hne)) lemma arithTermQ_finite_support (φ : TestFn) : (Function.support (arithTermQ φ)).Finite := by refine (arithTermB_finite_support φ φ).subset ?_ intro n hn rw [Function.mem_support] at hn ⊢ intro hB apply hn have hre : (arithTermB φ φ n).re = 2 * arithTermQ φ n := by unfold arithTermB arithTermQ autoCorr have hneg : corr φ φ (-Real.log (n : ℝ)) = starRingEnd ℂ (corr φ φ (Real.log (n : ℝ))) := autoCorr_neg φ (Real.log (n : ℝ)) rw [hneg] simp only [Complex.mul_re, Complex.ofReal_re, Complex.ofReal_im, zero_mul, sub_zero, Complex.add_re, Complex.conj_re] ring rw [hB, Complex.zero_re] at hre linarith lemma summable_arithTermQ (φ : TestFn) : Summable (arithTermQ φ) := summable_of_ne_finset_zero (s := (arithTermQ_finite_support φ).toFinset) (fun n hn => by by_contra hne exact hn ((arithTermQ_finite_support φ).mem_toFinset.mpr hne)) /-! ### 2. Definitions of `Q_form` (eq. (2)) and `B_form` (eq. (3)) -/ /-- The Weil quadratic form `Q(φ)` from Section 2, eq. (2) of F04: `Q(φ) = ∫_0^∞ w(t) (‖φ‖_2^2 - Re C_φ(t)) dt - A ‖φ‖_2^2 - 2 ∑_{n ≥ 2} (Λ(n)/√n) Re C_φ(log n)`. -/ noncomputable def Q_form (φ : TestFn) : ℝ := (∫ t in Ioi (0 : ℝ), weilWeight t * (normSq φ - (autoCorr φ t).re)) - weilConstA * normSq φ - 2 * ∑' n : ℕ, arithTermQ φ n /-- The polarized sesquilinear form `B(a, b)` from Section 2, eq. (3) of F04: `B(a, b) = ∫_0^∞ w(t) (C_{a,b}(0) - (C_{a,b}(t) + C_{a,b}(-t))/2) dt - A C_{a,b}(0) - ∑_{n ≥ 2} (Λ(n)/√n) (C_{a,b}(log n) + C_{a,b}(-log n))`. -/ noncomputable def B_form (a b : TestFn) : ℂ := (∫ t in Ioi (0 : ℝ), (weilWeight t : ℂ) * (corr a b 0 - (corr a b t + corr a b (-t)) / 2)) - (weilConstA : ℂ) * corr a b 0 - ∑' n : ℕ, arithTermB a b n /-! ### 3. Sesquilinearity, Hermitian Symmetry, and Diagonal Identity -/ theorem B_form_add_left (a₁ a₂ b : TestFn) : B_form (a₁ + a₂) b = B_form a₁ b + B_form a₂ b := by unfold B_form have hint_eq : (fun t => (weilWeight t : ℂ) * (corr (a₁ + a₂) b 0 - (corr (a₁ + a₂) b t + corr (a₁ + a₂) b (-t)) / 2)) = fun t => (weilWeight t : ℂ) * (corr a₁ b 0 - (corr a₁ b t + corr a₁ b (-t)) / 2) + (weilWeight t : ℂ) * (corr a₂ b 0 - (corr a₂ b t + corr a₂ b (-t)) / 2) := by ext t; simp only [corr_add_left]; ring rw [hint_eq, MeasureTheory.integral_add (integrableOn_weil_integrand a₁ b) (integrableOn_weil_integrand a₂ b)] have hsum_eq : arithTermB (a₁ + a₂) b = fun n => arithTermB a₁ b n + arithTermB a₂ b n := by ext n; unfold arithTermB; simp only [corr_add_left]; ring rw [hsum_eq, (summable_arithTermB a₁ b).tsum_add (summable_arithTermB a₂ b), corr_add_left] ring theorem B_form_add_right (a b₁ b₂ : TestFn) : B_form a (b₁ + b₂) = B_form a b₁ + B_form a b₂ := by unfold B_form have hint_eq : (fun t => (weilWeight t : ℂ) * (corr a (b₁ + b₂) 0 - (corr a (b₁ + b₂) t + corr a (b₁ + b₂) (-t)) / 2)) = fun t => (weilWeight t : ℂ) * (corr a b₁ 0 - (corr a b₁ t + corr a b₁ (-t)) / 2) + (weilWeight t : ℂ) * (corr a b₂ 0 - (corr a b₂ t + corr a b₂ (-t)) / 2) := by ext t; simp only [corr_add_right]; ring rw [hint_eq, MeasureTheory.integral_add (integrableOn_weil_integrand a b₁) (integrableOn_weil_integrand a b₂)] have hsum_eq : arithTermB a (b₁ + b₂) = fun n => arithTermB a b₁ n + arithTermB a b₂ n := by ext n; unfold arithTermB; simp only [corr_add_right]; ring rw [hsum_eq, (summable_arithTermB a b₁).tsum_add (summable_arithTermB a b₂), corr_add_right] ring theorem B_form_smul_left (c : ℂ) (a b : TestFn) : B_form (c • a) b = c * B_form a b := by unfold B_form have hint_eq : (fun t => (weilWeight t : ℂ) * (corr (c • a) b 0 - (corr (c • a) b t + corr (c • a) b (-t)) / 2)) = fun t => c * ((weilWeight t : ℂ) * (corr a b 0 - (corr a b t + corr a b (-t)) / 2)) := by ext t; simp only [corr_smul_left]; ring rw [hint_eq, MeasureTheory.integral_const_mul] have hsum_eq : arithTermB (c • a) b = fun n => c * arithTermB a b n := by ext n; unfold arithTermB; simp only [corr_smul_left]; ring rw [hsum_eq, tsum_mul_left, corr_smul_left] ring theorem B_form_smul_right (c : ℂ) (a b : TestFn) : B_form a (c • b) = starRingEnd ℂ c * B_form a b := by unfold B_form have hint_eq : (fun t => (weilWeight t : ℂ) * (corr a (c • b) 0 - (corr a (c • b) t + corr a (c • b) (-t)) / 2)) = fun t => starRingEnd ℂ c * ((weilWeight t : ℂ) * (corr a b 0 - (corr a b t + corr a b (-t)) / 2)) := by ext t; simp only [corr_smul_right]; ring rw [hint_eq, MeasureTheory.integral_const_mul] have hsum_eq : arithTermB a (c • b) = fun n => starRingEnd ℂ c * arithTermB a b n := by ext n; unfold arithTermB; simp only [corr_smul_right]; ring rw [hsum_eq, tsum_mul_left, corr_smul_right] ring theorem B_form_zero_left (b : TestFn) : B_form 0 b = 0 := by have h := B_form_smul_left 0 0 b simpa using h theorem B_form_zero_right (a : TestFn) : B_form a 0 = 0 := by have h := B_form_smul_right 0 a 0 simpa using h /-- Hermitian symmetry `B(a, b) = conj (B(b, a))` from Section 2 of F04. -/ theorem B_form_hermitian (a b : TestFn) : B_form a b = starRingEnd ℂ (B_form b a) := by unfold B_form simp only [map_sub, map_mul, Complex.conj_ofReal] have hint : starRingEnd ℂ (∫ t in Ioi (0 : ℝ), (weilWeight t : ℂ) * (corr b a 0 - (corr b a t + corr b a (-t)) / 2)) = ∫ t in Ioi (0 : ℝ), (weilWeight t : ℂ) * (corr a b 0 - (corr a b t + corr a b (-t)) / 2) := by change Complex.conjCLE (∫ t in Ioi (0 : ℝ), _) = _ rw [← Complex.conjCLE.integral_comp_comm] congr 1; ext t change starRingEnd ℂ ((weilWeight t : ℂ) * (corr b a 0 - (corr b a t + corr b a (-t)) / 2)) = _ simp only [map_mul, map_sub, map_div₀, map_add, Complex.conj_ofReal, map_ofNat] have h0 : starRingEnd ℂ (corr b a 0) = corr a b 0 := by have := corr_symm a b 0; simpa using this.symm have ht : starRingEnd ℂ (corr b a t) = corr a b (-t) := by have := corr_symm a b (-t); simpa using this.symm have hnt : starRingEnd ℂ (corr b a (-t)) = corr a b t := (corr_symm a b t).symm rw [h0, ht, hnt, add_comm] have h0 : starRingEnd ℂ (corr b a 0) = corr a b 0 := by have := corr_symm a b 0; simpa using this.symm have htsum : starRingEnd ℂ (∑' n : ℕ, arithTermB b a n) = ∑' n : ℕ, arithTermB a b n := by have hfin := arithTermB_finite_support b a have hfin' := arithTermB_finite_support a b let S := hfin.toFinset ∪ hfin'.toFinset have h1 : ∑' n : ℕ, arithTermB b a n = ∑ n ∈ S, arithTermB b a n := tsum_eq_sum (fun n hn => by by_contra hne exact hn (Finset.mem_union_left _ (hfin.mem_toFinset.mpr hne))) have h2 : ∑' n : ℕ, arithTermB a b n = ∑ n ∈ S, arithTermB a b n := tsum_eq_sum (fun n hn => by by_contra hne exact hn (Finset.mem_union_right _ (hfin'.mem_toFinset.mpr hne))) rw [h1, h2, map_sum] refine Finset.sum_congr rfl (fun n _ => ?_) unfold arithTermB simp only [map_mul, map_add, Complex.conj_ofReal] have hpos : starRingEnd ℂ (corr b a (Real.log (n : ℝ))) = corr a b (-Real.log (n : ℝ)) := by have := corr_symm a b (-Real.log (n : ℝ)); simpa using this.symm have hneg : starRingEnd ℂ (corr b a (-Real.log (n : ℝ))) = corr a b (Real.log (n : ℝ)) := (corr_symm a b (Real.log (n : ℝ))).symm rw [hpos, hneg, add_comm] rw [hint, h0, htsum] /-- Diagonal recovery `B(φ, φ) = Q(φ)` from Section 2 of F04. -/ theorem B_form_diag (φ : TestFn) : B_form φ φ = (Q_form φ : ℂ) := by unfold B_form Q_form simp only [Complex.ofReal_sub, Complex.ofReal_mul, Complex.ofReal_ofNat] have hint : ∫ t in Ioi (0 : ℝ), (weilWeight t : ℂ) * (corr φ φ 0 - (corr φ φ t + corr φ φ (-t)) / 2) = ((∫ t in Ioi (0 : ℝ), weilWeight t * (normSq φ - (autoCorr φ t).re) : ℝ) : ℂ) := by have hfun : (fun t => (weilWeight t : ℂ) * (corr φ φ 0 - (corr φ φ t + corr φ φ (-t)) / 2)) = fun t => ((weilWeight t * (normSq φ - (autoCorr φ t).re) : ℝ) : ℂ) := by ext t change (weilWeight t : ℂ) * (autoCorr φ 0 - (autoCorr φ t + autoCorr φ (-t)) / 2) = ((weilWeight t * (normSq φ - (autoCorr φ t).re) : ℝ) : ℂ) rw [autoCorr_zero, autoCorr_neg, Complex.add_conj] push_cast ring rw [hfun] exact integral_ofReal have h0 : corr φ φ 0 = (normSq φ : ℂ) := autoCorr_zero φ have hsum : ∑' n : ℕ, arithTermB φ φ n = (2 : ℂ) * ((∑' n : ℕ, arithTermQ φ n : ℝ) : ℂ) := by have hfin := arithTermB_finite_support φ φ have hfinQ := arithTermQ_finite_support φ let S := hfin.toFinset ∪ hfinQ.toFinset rw [tsum_eq_sum (s := S) (fun n hn => by by_contra hne; exact hn (Finset.mem_union_left _ (hfin.mem_toFinset.mpr hne))), tsum_eq_sum (s := S) (fun n hn => by by_contra hne; exact hn (Finset.mem_union_right _ (hfinQ.mem_toFinset.mpr hne)))] push_cast rw [Finset.mul_sum] refine Finset.sum_congr rfl (fun n _ => ?_) unfold arithTermB arithTermQ rw [Complex.ofReal_mul] change ((arithWeight n : ℝ) : ℂ) * (autoCorr φ (Real.log (n : ℝ)) + autoCorr φ (-Real.log (n : ℝ))) = 2 * (((arithWeight n : ℝ) : ℂ) * ((autoCorr φ (Real.log (n : ℝ))).re : ℂ)) rw [autoCorr_neg, Complex.add_conj] push_cast ring rw [hint, h0, hsum] lemma Q_form_eq_re_B_form (φ : TestFn) : Q_form φ = (B_form φ φ).re := by rw [B_form_diag, Complex.ofReal_re] lemma Q_form_smul (c : ℂ) (φ : TestFn) : Q_form (c • φ) = ‖c‖ ^ 2 * Q_form φ := by rw [Q_form_eq_re_B_form, B_form_smul_left, B_form_smul_right, B_form_diag] have hcc : c * starRingEnd ℂ c = ((‖c‖ ^ 2 : ℝ) : ℂ) := by rw [Complex.mul_conj, Complex.normSq_eq_norm_sq, Complex.ofReal_pow] rw [← mul_assoc, hcc, ← Complex.ofReal_mul, Complex.ofReal_re] lemma B_form_sum_left {ι : Type*} (s : Finset ι) (f : ι → TestFn) (b : TestFn) : B_form (∑ i ∈ s, f i) b = ∑ i ∈ s, B_form (f i) b := by classical induction s using Finset.induction_on with | empty => simp [B_form_zero_left] | insert a s ha ih => rw [Finset.sum_insert ha, B_form_add_left, ih, Finset.sum_insert ha] lemma B_form_sum_right {ι : Type*} (a : TestFn) (s : Finset ι) (g : ι → TestFn) : B_form a (∑ i ∈ s, g i) = ∑ i ∈ s, B_form a (g i) := by classical induction s using Finset.induction_on with | empty => simp [B_form_zero_right] | insert x s hx ih => rw [Finset.sum_insert hx, B_form_add_right, ih, Finset.sum_insert hx] /-- Exact finite-sum expansion of `Q(∑ i, c_i φ_i)` into diagonal terms and `2 Re K_{ij}` cross-terms (`K_{ij} = B(φ_j, φ_i)` for `i < j`) (F04 §§4–5). -/ theorem Q_form_sum_expansion {r : ℕ} (φ : Fin r → TestFn) (c : Fin r → ℂ) : Q_form (∑ i : Fin r, c i • φ i) = (∑ i : Fin r, ‖c i‖ ^ 2 * Q_form (φ i)) + 2 * ∑ i : Fin r, ∑ j ∈ Finset.univ.filter (fun j => i < j), (c j * starRingEnd ℂ (c i) * B_form (φ j) (φ i)).re := by rw [Q_form_eq_re_B_form, B_form_sum_left] simp_rw [B_form_sum_right, B_form_smul_left, B_form_smul_right] rw [Complex.re_sum] simp_rw [Complex.re_sum] -- Split double sum `(a, b)` into `a = b`, `a < b`, and `b < a`. have hsplit : ∀ a : Fin r, ∑ b : Fin r, (c a * (starRingEnd ℂ (c b) * B_form (φ a) (φ b))).re = ‖c a‖ ^ 2 * Q_form (φ a) + (∑ b ∈ Finset.univ.filter (fun b => a < b), (c a * (starRingEnd ℂ (c b) * B_form (φ a) (φ b))).re) + (∑ b ∈ Finset.univ.filter (fun b => b < a), (c a * (starRingEnd ℂ (c b) * B_form (φ a) (φ b))).re) := by intro a have hunion : (Finset.univ : Finset (Fin r)) = ({a} ∪ Finset.univ.filter (fun b => a < b)) ∪ Finset.univ.filter (fun b => b < a) := by ext b simp only [Finset.mem_univ, Finset.mem_union, Finset.mem_singleton, Finset.mem_filter, true_and, true_iff] rcases lt_trichotomy a b with hlt | rfl | hgt · exact Or.inl (Or.inr hlt) · exact Or.inl (Or.inl rfl) · exact Or.inr hgt have hd1 : Disjoint ({a} : Finset (Fin r)) (Finset.univ.filter (fun b => a < b)) := by rw [Finset.disjoint_singleton_left]; simp have hd2 : Disjoint ({a} ∪ Finset.univ.filter (fun b => a < b)) (Finset.univ.filter (fun b => b < a)) := by rw [Finset.disjoint_left] intro b hb1 hb2 simp only [Finset.mem_union, Finset.mem_singleton, Finset.mem_filter, Finset.mem_univ, true_and] at hb1 hb2 rcases hb1 with rfl | hgt · exact lt_irrefl _ hb2 · exact lt_asymm hgt hb2 conv_lhs => rw [hunion] rw [Finset.sum_union hd2, Finset.sum_union hd1, Finset.sum_singleton] have hdiag : (c a * (starRingEnd ℂ (c a) * B_form (φ a) (φ a))).re = ‖c a‖ ^ 2 * Q_form (φ a) := by rw [← mul_assoc, Complex.mul_conj, Complex.normSq_eq_norm_sq, B_form_diag, ← Complex.ofReal_mul, Complex.ofReal_re] rw [hdiag] simp_rw [hsplit, Finset.sum_add_distrib] -- Show the two off-diagonal sums are equal via Hermitian symmetry and index swap! have hoff1 : ∑ a : Fin r, ∑ b ∈ Finset.univ.filter (fun b => a < b), (c a * (starRingEnd ℂ (c b) * B_form (φ a) (φ b))).re = ∑ i : Fin r, ∑ j ∈ Finset.univ.filter (fun j => i < j), (c j * starRingEnd ℂ (c i) * B_form (φ j) (φ i)).re := by refine Finset.sum_congr rfl (fun i _ => Finset.sum_congr rfl (fun j _ => ?_)) have hconj : starRingEnd ℂ (c i * (starRingEnd ℂ (c j) * B_form (φ i) (φ j))) = c j * starRingEnd ℂ (c i) * B_form (φ j) (φ i) := by simp only [map_mul, RingHomCompTriple.comp_apply, RingHom.id_apply, ← B_form_hermitian] ring rw [← hconj, Complex.conj_re] have hoff2 : ∑ a : Fin r, ∑ b ∈ Finset.univ.filter (fun b => b < a), (c a * (starRingEnd ℂ (c b) * B_form (φ a) (φ b))).re = ∑ i : Fin r, ∑ j ∈ Finset.univ.filter (fun j => i < j), (c j * starRingEnd ℂ (c i) * B_form (φ j) (φ i)).re := by simp_rw [Finset.sum_filter] rw [Finset.sum_comm] refine Finset.sum_congr rfl (fun i _ => Finset.sum_congr rfl (fun j _ => ?_)) split_ifs <;> simp [mul_assoc] rw [hoff1, hoff2] ring end F04Riemann