Exact Lean source
Nonadditivity.GaussianQuadratic
Download original .lean · View on GitHub · Jump to source
Direct imports
Mathlib.Probability.Distributions.Gaussian.MultivariatedependencyMathlib.Probability.Moments.MGFAnalyticdependencyMathlib.Analysis.SpecialFunctions.Gaussian.GaussianIntegraldependencyMathlib.Analysis.InnerProductSpace.SpectrumdependencyMathlib.Analysis.InnerProductSpace.Tracedependency
Imported by project modules
3 direct reverse imports
Relationships above come from literal import commands. The declarations below link to types and references extracted from Lean’s environment. Source text is complete and unchanged.
Declarations in this module
20 project constants, including generated, internal and private declarations.
20 declarations
Nonadditivity.GaussianQuadratic.abs_eigenvalue_le_normNonadditivity.GaussianQuadratic.basis_repr_sumNonadditivity.GaussianQuadratic.exists_simultaneous_quadratic_boundsNonadditivity.GaussianQuadratic.integrable_exp_centered_quadraticNonadditivity.GaussianQuadratic.integrable_exp_sqNonadditivity.GaussianQuadratic.integrable_exp_trace_centeredNonadditivity.GaussianQuadratic.integral_exp_centered_quadratic_eqNonadditivity.GaussianQuadratic.integral_exp_centered_quadratic_leNonadditivity.GaussianQuadratic.integral_exp_centered_sq_leNonadditivity.GaussianQuadratic.integral_exp_sqNonadditivity.GaussianQuadratic.integral_exp_trace_centered_leNonadditivity.GaussianQuadratic.measure_abs_quadratic_ge_leNonadditivity.GaussianQuadratic.measure_abs_quadratic_ge_le._simp_1_1internal/detail/privateNonadditivity.GaussianQuadratic.measure_abs_quadratic_ge_le._simp_1_2internal/detail/privateNonadditivity.GaussianQuadratic.measure_abs_quadratic_ge_le._simp_1_3internal/detail/privateNonadditivity.GaussianQuadratic.measure_quadratic_ge_leNonadditivity.GaussianQuadratic.measure_quadratic_le_leNonadditivity.GaussianQuadratic.neg_log_one_sub_leNonadditivity.GaussianQuadratic.quadratic_eq_eigen_sumNonadditivity.GaussianQuadratic.trace_sq_eq_sum_eigenvalues_sq
Full module
1/-2Copyright (c) 2026 the Nonadditivity project contributors.3All rights reserved. See COPYRIGHT.md for licensing and attribution.4-/56/-7Copyright (c) 2026 Yuanhe Zhang. All rights reserved.8The adapted portions are released under the Apache License 2.0.910The eigenbasis coordinate calculations in this file adapt proof patterns from11SLT/HansonWright.lean by Yuanhe Zhang, Jason D. Lee, and Fanghui Liu,12released under Apache 2.0 (2026), commit d0f506f0a695018265dccb33bcb05e2f5ca1c876.13The Gaussian density calculation and the quadratic concentration proof below14are established directly against this project's pinned mathlib.15-/16import Mathlib.Probability.Distributions.Gaussian.Multivariate17import Mathlib.Probability.Moments.MGFAnalytic18import Mathlib.Analysis.SpecialFunctions.Gaussian.GaussianIntegral19import Mathlib.Analysis.InnerProductSpace.Spectrum20import Mathlib.Analysis.InnerProductSpace.Trace2122/-! # Exact Gaussian quadratic integrals and concentration2324This file derives the Gaussian quadratic MGF directly from the Gaussian density,25then diagonalizes a symmetric quadratic form. No concentration inequality is26assumed as a hypothesis.27-/2829noncomputable section3031open MeasureTheory ProbabilityTheory Real32open scoped BigOperators NNReal3334namespace Nonadditivity.GaussianQuadratic3536/-- Exact one-dimensional Gaussian square-exponential integral. -/37theorem integral_exp_sq (a : ℝ) (ha : a < 1 / 2) :38(∫ x : ℝ, exp (a * x ^ 2) ∂gaussianReal 0 1) =39(sqrt (1 - 2 * a))⁻¹ := by40rw [integral_gaussianReal_eq_integral_smul (by norm_num : (1 : ℝ≥0) ≠ 0)]41simp only [smul_eq_mul, gaussianPDFReal, NNReal.coe_one, mul_one, sub_zero]42have hpoint (x : ℝ) :43(sqrt (2 * π))⁻¹ * exp (-x ^ 2 / 2) * exp (a * x ^ 2) =44(sqrt (2 * π))⁻¹ * exp (-(1 / 2 - a) * x ^ 2) := by45rw [mul_assoc, ← exp_add]46congr 247ring48simp_rw [hpoint]49rw [integral_const_mul, integral_gaussian]50have hb : 0 < 1 - 2 * a := by linarith51have heq : π / (1 / 2 - a) = (2 * π) / (1 - 2 * a) := by field_simp52rw [heq, sqrt_div (by positivity), ← mul_div_assoc,53inv_mul_cancel₀ (ne_of_gt (sqrt_pos.2 (by positivity : 0 < 2 * π))), one_div]5455/-- The quadratic Gaussian integral is integrable precisely in the subcritical range. -/56theorem integrable_exp_sq (a : ℝ) (ha : a < 1 / 2) :57Integrable (fun x : ℝ => exp (a * x ^ 2)) (gaussianReal 0 1) := by58apply Integrable.of_integral_ne_zero59rw [integral_exp_sq a ha]60exact inv_ne_zero (ne_of_gt (sqrt_pos.2 (by linarith)))6162/-- A convenient elementary logarithm remainder estimate. -/63theorem neg_log_one_sub_le {u : ℝ} (hu : u ≤ 1 / 2) :64-log (1 - u) ≤ u + 2 * u ^ 2 := by65have hp : 0 < 1 - u := by linarith66have h := log_le_sub_one_of_pos (inv_pos.2 hp)67rw [log_inv] at h68have hrem : (1 - u)⁻¹ - 1 ≤ u + 2 * u ^ 2 := by69apply (mul_le_mul_iff_left₀ hp).mp70field_simp71nlinarith [sq_nonneg u, mul_nonneg (sq_nonneg u) (by linarith : 0 ≤ 1 - 2 * u)]72exact h.trans hrem7374/-- Centered scalar square-exponential bound, uniform over both signs. -/75theorem integral_exp_centered_sq_le {a : ℝ} (ha : |a| ≤ 1 / 4) :76(∫ x : ℝ, exp (a * (x ^ 2 - 1)) ∂gaussianReal 0 1) ≤ exp (4 * a ^ 2) := by77have ha' : a < 1 / 2 := by have := le_abs_self a; linarith78have hp : 0 < 1 - 2 * a := by linarith79have hpoint (x : ℝ) : exp (a * (x ^ 2 - 1)) = exp (-a) * exp (a * x ^ 2) := by80rw [← exp_add]81congr 182ring83simp_rw [hpoint]84rw [integral_const_mul, integral_exp_sq a ha']85have hsqrt : (sqrt (1 - 2 * a))⁻¹ = exp (- log (1 - 2 * a) / 2) := by86rw [neg_div, exp_neg, ← log_sqrt hp.le, exp_log (sqrt_pos.2 hp)]87rw [hsqrt, ← exp_add]88apply exp_le_exp.mpr89have hlog := neg_log_one_sub_le (u := 2 * a) (by have := le_abs_self a; linarith)90nlinarith91929394section FiniteDimensional9596variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]97[FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E]9899omit [MeasurableSpace E] [BorelSpace E] in100/-- A real symmetric quadratic form in its orthonormal eigenbasis. -/101theorem quadratic_eq_eigen_sum (T : E →ₗ[ℝ] E) (hT : T.IsSymmetric) (x : E) :102inner ℝ (T x) x = ∑ i : Fin (Module.finrank ℝ E),103hT.eigenvalues rfl i * ((hT.eigenvectorBasis rfl).repr x i) ^ 2 := by104let b := hT.eigenvectorBasis (by rfl : Module.finrank ℝ E = Module.finrank ℝ E)105calc106inner ℝ (T x) x = inner ℝ (b.repr (T x)) (b.repr x) := by107rw [b.repr.inner_map_map]108_ = _ := by109rw [PiLp.inner_apply]110apply Finset.sum_congr rfl111intro i _112have hcoord : b.repr (T x) i = hT.eigenvalues rfl i * b.repr x i := by113simpa [b] using hT.eigenvectorBasis_apply_self_apply114(by rfl : Module.finrank ℝ E = Module.finrank ℝ E) x i115rw [hcoord]116change (b.repr x i) * (hT.eigenvalues rfl i * b.repr x i) = _117change _ = hT.eigenvalues rfl i * (b.repr x i) ^ 2118ring119120omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in121/-- Coordinates of eigenvector synthesis are the coefficients used. -/122theorem basis_repr_sum (b : OrthonormalBasis (Fin (Module.finrank ℝ E)) ℝ E)123(z : Fin (Module.finrank ℝ E) → ℝ) (i : Fin (Module.finrank ℝ E)) :124b.repr (∑ j, z j • b j) i = z i := by125simp only [OrthonormalBasis.repr_apply_apply, inner_sum, inner_smul_right]126rw [Finset.sum_eq_single i]127· simp128· intro j _ hji129rw [b.inner_eq_zero hji.symm]130simp131· intro hi132exact (hi (Finset.mem_univ i)).elim133134/-- Exact centered quadratic Gaussian MGF as a finite product. -/135theorem integral_exp_centered_quadratic_eq136(T : E →L[ℝ] E) (hT : T.toLinearMap.IsSymmetric) (s : ℝ) :137(∫ x : E, exp (s * (inner ℝ (T x) x - ∑ i, hT.eigenvalues rfl i))138∂stdGaussian E) =139∏ i : Fin (Module.finrank ℝ E),140∫ z : ℝ, exp ((s * hT.eigenvalues rfl i) * (z ^ 2 - 1))141∂gaussianReal 0 1 := by142let b := hT.eigenvectorBasis (by rfl : Module.finrank ℝ E = Module.finrank ℝ E)143rw [stdGaussian_eq_map_pi_orthonormalBasis b,144integral_map ((continuous_finset_sum _ fun i _ =>145(continuous_apply i).smul continuous_const).aemeasurable) (by fun_prop)]146have hpoint (z : Fin (Module.finrank ℝ E) → ℝ) :147exp (s * (inner ℝ (T (∑ i, z i • b i)) (∑ i, z i • b i) -148∑ i, hT.eigenvalues rfl i)) =149∏ i, exp ((s * hT.eigenvalues rfl i) * (z i ^ 2 - 1)) := by150rw [← Real.exp_sum]151congr 1152change s * (inner ℝ (T.toLinearMap (∑ i, z i • b i)) (∑ i, z i • b i) - _) = _153rw [quadratic_eq_eigen_sum T.toLinearMap hT]154simp only [show hT.eigenvectorBasis rfl = b from rfl, basis_repr_sum]155rw [← Finset.sum_sub_distrib, Finset.mul_sum]156apply Finset.sum_congr rfl157intro i _158ring159simp_rw [hpoint]160exact integral_fintype_prod_eq_prod (fun i z => exp ((s * hT.eigenvalues rfl i) * (z ^ 2 - 1)))161162/-- The Gaussian quadratic MGF bound from spectral diagonalization and scalar integration. -/163theorem integral_exp_centered_quadratic_le164(T : E →L[ℝ] E) (hT : T.toLinearMap.IsSymmetric) (s : ℝ)165(hs : ∀ i : Fin (Module.finrank ℝ E), |s * hT.eigenvalues rfl i| ≤ 1 / 4) :166(∫ x : E, exp (s * (inner ℝ (T x) x - ∑ i, hT.eigenvalues rfl i))167∂stdGaussian E) ≤168exp (4 * s ^ 2 * ∑ i, (hT.eigenvalues rfl i) ^ 2) := by169rw [integral_exp_centered_quadratic_eq T hT s]170calc171_ ≤ ∏ i : Fin (Module.finrank ℝ E), exp (4 * (s * hT.eigenvalues rfl i) ^ 2) := by172apply Finset.prod_le_prod173· intro i _174exact integral_nonneg (fun _ => exp_nonneg _)175· intro i _176exact integral_exp_centered_sq_le (hs i)177_ = _ := by178rw [← Real.exp_sum]179congr 1180rw [Finset.mul_sum]181apply Finset.sum_congr rfl182intro i _183ring184185/-- Integrability accompanies the Gaussian MGF bound, rather than being assumed. -/186theorem integrable_exp_centered_quadratic187(T : E →L[ℝ] E) (hT : T.toLinearMap.IsSymmetric) (s : ℝ)188(hs : ∀ i : Fin (Module.finrank ℝ E), |s * hT.eigenvalues rfl i| ≤ 1 / 4) :189Integrable (fun x : E => exp (s * (inner ℝ (T x) x - ∑ i, hT.eigenvalues rfl i)))190(stdGaussian E) := by191apply Integrable.of_integral_ne_zero192rw [integral_exp_centered_quadratic_eq T hT s]193apply ne_of_gt194apply Finset.prod_pos195intro i _196have hint : Integrable (fun z : ℝ =>197exp ((s * hT.eigenvalues rfl i) * (z ^ 2 - 1))) (gaussianReal 0 1) := by198have hsmall : s * hT.eigenvalues rfl i < 1 / 2 :=199lt_of_le_of_lt ((le_abs_self _).trans (hs i)) (by norm_num)200have hpt (z : ℝ) : exp ((s * hT.eigenvalues rfl i) * (z ^ 2 - 1)) =201exp (-(s * hT.eigenvalues rfl i)) * exp ((s * hT.eigenvalues rfl i) * z ^ 2) := by202rw [← exp_add]203congr 1204ring205simp_rw [hpt]206exact (integrable_exp_sq _ hsmall).const_mul _207exact mgf_pos hint208209omit [MeasurableSpace E] [BorelSpace E] in210/-- The squared spectral coefficients are the trace of the square. -/211theorem trace_sq_eq_sum_eigenvalues_sq (T : E →L[ℝ] E)212(hT : T.toLinearMap.IsSymmetric) :213(T.toLinearMap * T.toLinearMap).trace ℝ E =214∑ i : Fin (Module.finrank ℝ E), (hT.eigenvalues rfl i) ^ 2 := by215let b := hT.eigenvectorBasis (by rfl : Module.finrank ℝ E = Module.finrank ℝ E)216rw [LinearMap.trace_eq_sum_inner _ b]217apply Finset.sum_congr rfl218intro i _219change inner ℝ (b i) (T.toLinearMap (T.toLinearMap (b i))) = _220have heig : T.toLinearMap (b i) = (hT.eigenvalues rfl i) • b i :=221hT.apply_eigenvectorBasis rfl i222rw [heig, map_smul, heig, inner_smul_right, inner_smul_right]223simp [b.norm_eq_one, pow_two]224225omit [MeasurableSpace E] [BorelSpace E] in226/-- Every spectral coefficient is bounded by the actual operator norm. -/227theorem abs_eigenvalue_le_norm (T : E →L[ℝ] E)228(hT : T.toLinearMap.IsSymmetric) (i : Fin (Module.finrank ℝ E)) :229|hT.eigenvalues rfl i| ≤ ‖T‖ := by230let b := hT.eigenvectorBasis (by rfl : Module.finrank ℝ E = Module.finrank ℝ E)231have h := T.le_opNorm (b i)232have heig : T (b i) = (hT.eigenvalues rfl i) • b i :=233hT.apply_eigenvectorBasis rfl i234simpa only [heig, norm_smul, Real.norm_eq_abs, b.norm_eq_one, mul_one] using h235236/-- A basis-free, centered Gaussian quadratic MGF estimate. -/237theorem integral_exp_trace_centered_le (T : E →L[ℝ] E)238(hT : T.toLinearMap.IsSymmetric) (s : ℝ) (hs : |s| * ‖T‖ ≤ 1 / 4) :239(∫ x : E, exp (s * (inner ℝ (T x) x - T.toLinearMap.trace ℝ E))240∂stdGaussian E) ≤ exp (4 * s ^ 2 * (T.toLinearMap * T.toLinearMap).trace ℝ E) := by241rw [hT.trace_eq_sum_eigenvalues rfl, trace_sq_eq_sum_eigenvalues_sq T hT]242apply integral_exp_centered_quadratic_le T hT s243intro i244rw [abs_mul]245exact (mul_le_mul_of_nonneg_left (abs_eigenvalue_le_norm T hT i) (abs_nonneg s)).trans hs246247/-- Integrability of the centered MGF under the same explicit norm condition. -/248theorem integrable_exp_trace_centered (T : E →L[ℝ] E)249(hT : T.toLinearMap.IsSymmetric) (s : ℝ) (hs : |s| * ‖T‖ ≤ 1 / 4) :250Integrable (fun x : E => exp (s * (inner ℝ (T x) x - T.toLinearMap.trace ℝ E)))251(stdGaussian E) := by252rw [hT.trace_eq_sum_eigenvalues rfl]253apply integrable_exp_centered_quadratic T hT s254intro i255rw [abs_mul]256exact (mul_le_mul_of_nonneg_left (abs_eigenvalue_le_norm T hT i) (abs_nonneg s)).trans hs257258/-- Explicit Gaussian upper-tail bound. The exponent parameter is free for optimization. -/259theorem measure_quadratic_ge_le (T : E →L[ℝ] E)260(hT : T.toLinearMap.IsSymmetric) (s t : ℝ)261(hs : 0 ≤ s) (hsmall : s * ‖T‖ ≤ 1 / 4) :262(stdGaussian E).real {x | t ≤ inner ℝ (T x) x - T.toLinearMap.trace ℝ E} ≤263exp (-s * t + 4 * s ^ 2 * (T.toLinearMap * T.toLinearMap).trace ℝ E) := by264have hsmall' : |s| * ‖T‖ ≤ 1 / 4 := by simpa [abs_of_nonneg hs] using hsmall265calc266_ ≤ exp (-s * t) * (∫ x : E,267exp (s * (inner ℝ (T x) x - T.toLinearMap.trace ℝ E)) ∂stdGaussian E) :=268measure_ge_le_exp_mul_mgf t hs (integrable_exp_trace_centered T hT s hsmall')269_ ≤ exp (-s * t) * exp (4 * s ^ 2 * (T.toLinearMap * T.toLinearMap).trace ℝ E) :=270mul_le_mul_of_nonneg_left (integral_exp_trace_centered_le T hT s hsmall') (exp_nonneg _)271_ = _ := (exp_add _ _).symm272273/-- Explicit Gaussian lower-tail bound. -/274theorem measure_quadratic_le_le (T : E →L[ℝ] E)275(hT : T.toLinearMap.IsSymmetric) (s t : ℝ)276(hs : 0 ≤ s) (hsmall : s * ‖T‖ ≤ 1 / 4) :277(stdGaussian E).real {x | inner ℝ (T x) x - T.toLinearMap.trace ℝ E ≤ -t} ≤278exp (-s * t + 4 * s ^ 2 * (T.toLinearMap * T.toLinearMap).trace ℝ E) := by279have hsmall' : |-s| * ‖T‖ ≤ 1 / 4 := by simpa [abs_neg, abs_of_nonneg hs] using hsmall280calc281_ ≤ exp (-(-s) * (-t)) * (∫ x : E,282exp ((-s) * (inner ℝ (T x) x - T.toLinearMap.trace ℝ E)) ∂stdGaussian E) :=283measure_le_le_exp_mul_mgf (-t) (neg_nonpos.mpr hs)284(integrable_exp_trace_centered T hT (-s) hsmall')285_ ≤ exp (-(-s) * (-t)) * exp (4 * (-s) ^ 2 * (T.toLinearMap * T.toLinearMap).trace ℝ E) :=286mul_le_mul_of_nonneg_left (integral_exp_trace_centered_le T hT (-s) hsmall') (exp_nonneg _)287_ = _ := by rw [← exp_add]; congr 1; ring288289/-- Two-sided concentration for a concrete Gaussian quadratic form. -/290theorem measure_abs_quadratic_ge_le (T : E →L[ℝ] E)291(hT : T.toLinearMap.IsSymmetric) (s t : ℝ)292(hs : 0 ≤ s) (hsmall : s * ‖T‖ ≤ 1 / 4) :293(stdGaussian E).real {x | t ≤ |inner ℝ (T x) x - T.toLinearMap.trace ℝ E|} ≤2942 * exp (-s * t + 4 * s ^ 2 * (T.toLinearMap * T.toLinearMap).trace ℝ E) := by295have heq : {x : E | t ≤ |inner ℝ (T x) x - T.toLinearMap.trace ℝ E|} =296{x | t ≤ inner ℝ (T x) x - T.toLinearMap.trace ℝ E} ∪297{x | inner ℝ (T x) x - T.toLinearMap.trace ℝ E ≤ -t} := by298ext x299simp only [Set.mem_setOf_eq, Set.mem_union, le_abs, le_neg]300rw [heq]301have hu := measure_quadratic_ge_le T hT s t hs hsmall302have hl := measure_quadratic_le_le T hT s t hs hsmall303exact (measureReal_union_le _ _).trans (by linarith)304305/-- A finite collection of quadratic tests is simultaneously passed by an306actual Gaussian sample whenever their explicit Gaussian tail bounds sum to less than one. -/307theorem exists_simultaneous_quadratic_bounds {J : Type*} [Fintype J]308(T : J → E →L[ℝ] E) (hT : ∀ j, (T j).toLinearMap.IsSymmetric)309(s t : J → ℝ) (hs : ∀ j, 0 ≤ s j)310(hsmall : ∀ j, s j * ‖T j‖ ≤ 1 / 4)311(hbudget : (∑ j, 2 * exp (-s j * t j +3124 * s j ^ 2 * ((T j).toLinearMap * (T j).toLinearMap).trace ℝ E)) < 1) :313∃ x : E, ∀ j, |inner ℝ (T j x) x - (T j).toLinearMap.trace ℝ E| < t j := by314classical315by_contra hnone316push_neg at hnone317have hcover : (⋃ j, {x : E | t j ≤318|inner ℝ (T j x) x - (T j).toLinearMap.trace ℝ E|}) = Set.univ := by319apply Set.eq_univ_of_forall320intro x321obtain ⟨j, hj⟩ := hnone x322exact Set.mem_iUnion.mpr ⟨j, hj⟩323have hsum := measureReal_iUnion_fintype_le (μ := stdGaussian E)324(fun j => {x : E | t j ≤ |inner ℝ (T j x) x - (T j).toLinearMap.trace ℝ E|})325rw [hcover, probReal_univ] at hsum326have hbound : (∑ j, (stdGaussian E).real327{x : E | t j ≤ |inner ℝ (T j x) x - (T j).toLinearMap.trace ℝ E|}) ≤328∑ j, 2 * exp (-s j * t j +3294 * s j ^ 2 * ((T j).toLinearMap * (T j).toLinearMap).trace ℝ E) := by330apply Finset.sum_le_sum331intro j _332exact measure_abs_quadratic_ge_le (T j) (hT j) (s j) (t j) (hs j) (hsmall j)333exact (not_lt_of_ge (hsum.trans hbound)) hbudget334335end FiniteDimensional336337end Nonadditivity.GaussianQuadratic