Exact Lean source
YoungHyperplaneCovariance
formalization/Cloning/YoungHyperplaneCovariance.lean
Source hash: 73fd1906d18b886e4f6ca591a6dd1c32bc840dc51617fdef3eb74c40811831b5
Full source copied without mathematical changes from the snapshot whose input hash matches the passing audit. Select a line number for a stable source pointer.
The declarations belong to the compiled inventory covered by the project’s shared axiom audit. That audit records an aggregate union, without attributing axioms to individual declarations.
Declarations in this module
definition
Cloning.YoungHyperplane.headCovariancetheorem Cloning.YoungHyperplane.headCovariance_detdefinition Cloning.YoungHyperplane.rootCovarianceMatrixtheorem Cloning.YoungHyperplane.rootCovarianceMatrix_detdefinition Cloning.YoungHyperplane.rootCovariancetheorem Cloning.YoungHyperplane.rootCovariance_dettheorem Cloning.YoungHyperplane.rootGram_mulVectheorem Cloning.YoungHyperplane.headCovariance_mulVectheorem Cloning.YoungHyperplane.rootCovariance_applydefinition Cloning.YoungHyperplane.inverseCovarianceVectortheorem Cloning.YoungHyperplane.inverseCovarianceVector_applytheorem Cloning.YoungHyperplane.rootCovariance_inverseVectortheorem Cloning.YoungHyperplane.inverseCovariance_quadratictheorem Cloning.YoungHyperplane.rootCovariance_det_ne_zerodefinition Cloning.YoungHyperplane.rootCovarianceEquivtheorem Cloning.YoungHyperplane.rootCovarianceEquiv_applytheorem Cloning.YoungHyperplane.rootCovarianceEquiv_symm_applytheorem Cloning.YoungHyperplane.rootCovarianceEquiv_inverse_quadratictheorem Cloning.YoungHyperplane.inverseCovariance_quadratic_postheorem Cloning.YoungHyperplane.rootCovariance_quadratic_postheorem Cloning.YoungHyperplane.rootCovariance_innertheorem Cloning.YoungHyperplane.rootCovariance_isSymmetric1import Cloning.YoungHyperplaneSampling
2import Mathlib.Analysis.InnerProductSpace.Symmetric
3
4/-!
5# The simplex covariance on the actual root hyperplane
6
7These are the exact covariance determinant and inverse quadratic identities
8used in the Young local limit. They are finite-dimensional algebraic identities,
9not local-limit or Stirling asymptotics.
10-/
11
12set_option maxHeartbeats 800000
13set_option backward.isDefEq.respectTransparency false
14noncomputable section
15open scoped BigOperators Topology Classical Matrix
16open MeasureTheory
17
18namespace Cloning.YoungHyperplane
19
20/-- The covariance of the first `d` coordinates of a multinomial fluctuation. -/
21def headCovariance (d : ℕ) (p : Fin (d + 1) → ℝ) : Matrix (Fin d) (Fin d) ℝ :=
22 fun i j ↦ (if i = j then p i.castSucc else 0) - p i.castSucc * p j.castSucc
23
24/-- The principal minor has the exact product normalization. -/
25theorem headCovariance_det (d : ℕ) (p : Fin (d + 1) → ℝ) (hp : ∑ i, p i = 1) :
26 Matrix.det (headCovariance d p) = ∏ i, p i := by
27 have heq : headCovariance d p =
28 Matrix.diagonal (fun i : Fin d ↦ p i.castSucc) *
29 (1 + Matrix.replicateCol Unit (fun _ : Fin d ↦ (1 : ℝ)) *
30 Matrix.replicateRow Unit (fun i : Fin d ↦ -p i.castSucc)) := by
31 ext i j
32 rw [Matrix.diagonal_mul]
33 simp only [headCovariance, Matrix.add_apply, Matrix.mul_apply, Matrix.one_apply]
34 simp only [Matrix.replicateCol_apply, Matrix.replicateRow_apply, one_mul,
35 Fintype.sum_unique]
36 by_cases hij : i = j
37 · simp [hij]; ring
38 · simp [hij]
39 rw [heq, Matrix.det_mul, Matrix.det_diagonal, Matrix.det_one_add_replicateCol_mul_replicateRow]
40 rw [Fin.sum_univ_castSucc] at hp
41 simp only [dotProduct, mul_one, Finset.sum_neg_distrib]
42 rw [Fin.prod_univ_castSucc]
43 congr 1
44 linarith
45
46/-- The induced covariance endomorphism in the nonorthonormal root basis has
47matrix `C G`, where `G=I+11ᵀ` is the root-basis Gram matrix. -/
48def rootCovarianceMatrix (d : ℕ) (p : Fin (d + 1) → ℝ) : Matrix (Fin d) (Fin d) ℝ :=
49 headCovariance d p * (show Matrix (Fin d) (Fin d) ℝ from
50 fun i j ↦ inner ℝ (rootBasis d i) (rootBasis d j))
51
52theorem rootCovarianceMatrix_det (d : ℕ) (p : Fin (d + 1) → ℝ) (hp : ∑ i, p i = 1) :
53 Matrix.det (rootCovarianceMatrix d p) = ((d : ℝ) + 1) * ∏ i, p i := by
54 rw [rootCovarianceMatrix, Matrix.det_mul, headCovariance_det d p hp, rootBasis_gram_det]
55 ring
56
57/-- The covariance is a genuine endomorphism of the Euclidean root hyperplane. -/
58def rootCovariance (d : ℕ) (p : Fin (d + 1) → ℝ) : rootSpace d →ₗ[ℝ] rootSpace d :=
59 (coordinates d).toLinearMap ∘ₗ (rootCovarianceMatrix d p).toLin' ∘ₗ
60 (coordinates d).symm.toLinearMap
61
62theorem rootCovariance_det (d : ℕ) (p : Fin (d + 1) → ℝ) (hp : ∑ i, p i = 1) :
63 LinearMap.det (rootCovariance d p) = ((d : ℝ) + 1) * ∏ i, p i := by
64 rw [rootCovariance, LinearMap.det_conj, LinearMap.det_toLin']
65 exact rootCovarianceMatrix_det d p hp
66
67/-- The root Gram action adds the sum of the coordinates to each component. -/
68theorem rootGram_mulVec (d : ℕ) (x : Fin d → ℝ) (i : Fin d) :
69 ((fun i j ↦ inner ℝ (rootBasis d i) (rootBasis d j)) *ᵥ x) i = x i + ∑ j, x j := by
70 simp only [Matrix.mulVec, dotProduct, rootBasis_inner, add_mul, Finset.sum_add_distrib]
71 simp
72
73/-- Ordinary coordinate action of the principal covariance minor. -/
74theorem headCovariance_mulVec (d : ℕ) (p : Fin (d + 1) → ℝ) (x : Fin d → ℝ) (i : Fin d) :
75 (headCovariance d p *ᵥ x) i =
76 p i.castSucc * x i - p i.castSucc * ∑ j, p j.castSucc * x j := by
77 simp only [Matrix.mulVec, dotProduct, headCovariance, sub_mul, Finset.sum_sub_distrib]
78 rw [show (∑ j : Fin d, (if i = j then p i.castSucc else 0) * x j) = p i.castSucc * x i by simp]
79 rw [Finset.mul_sum]
80 congr 1
81 apply Finset.sum_congr rfl
82 intro j _
83 ring
84
85/-- The constructed endomorphism is exactly the ambient covariance
86`diag(p) - p pᵀ`, restricted to the true Euclidean sum-zero hyperplane. -/
87theorem rootCovariance_apply (d : ℕ) (p : Fin (d + 1) → ℝ) (hp : ∑ i, p i = 1)
88 (x : rootSpace d) (i : Fin (d + 1)) :
89 (rootCovariance d p x).1 i = p i * x.1 i - p i * ∑ j, p j * x.1 j := by
90 have hhead (k : Fin d) : (rootCovariance d p x).1 k.castSucc =
91 p k.castSucc * x.1 k.castSucc - p k.castSucc * ∑ j, p j * x.1 j := by
92 change (coordinates d (((rootCovarianceMatrix d p).toLin') ((coordinates d).symm x))).1 k.castSucc = _
93 rw [coordinates_head, Matrix.toLin'_apply, rootCovarianceMatrix, ← Matrix.mulVec_mulVec]
94 rw [headCovariance_mulVec]
95 simp only [rootGram_mulVec, coordinates_symm_apply]
96 have hx : (∑ j : Fin d, x.1 j.castSucc) + x.1 (Fin.last d) = 0 := by
97 have hx0 : (∑ j, x.1 j) = 0 := x.2
98 simpa only [Fin.sum_univ_castSucc] using hx0
99 have hp' : (∑ j : Fin d, p j.castSucc) + p (Fin.last d) = 1 := by
100 simpa only [Fin.sum_univ_castSucc] using hp
101 rw [Fin.sum_univ_castSucc]
102 simp only [mul_add, Finset.sum_add_distrib, ← Finset.sum_mul]
103 have hpx := congrArg (fun t : ℝ ↦ t * (∑ j : Fin d, x.1 j.castSucc)) hp'
104 have hsum : (∑ j : Fin d, p j.castSucc) * (∑ j : Fin d, x.1 j.castSucc) =
105 (∑ j : Fin d, x.1 j.castSucc) + p (Fin.last d) * x.1 (Fin.last d) := by
106 have hlast := congrArg (fun t : ℝ ↦ p (Fin.last d) * t) hx
107 nlinarith only [hpx, hlast]
108 rw [hsum]
109 ring
110 refine Fin.lastCases ?_ (fun k ↦ hhead k) i
111 have hout : (∑ j : Fin d, (rootCovariance d p x).1 j.castSucc) +
112 (rootCovariance d p x).1 (Fin.last d) = 0 := by
113 have h0 : (∑ j, (rootCovariance d p x).1 j) = 0 := (rootCovariance d p x).2
114 simpa only [Fin.sum_univ_castSucc] using h0
115 have htar : (∑ j, (p j * x.1 j - p j * ∑ k, p k * x.1 k)) = 0 := by
116 rw [Finset.sum_sub_distrib, ← Finset.sum_mul, hp, one_mul, sub_self]
117 rw [Fin.sum_univ_castSucc] at htar
118 simp only [hhead] at hout
119 linarith only [hout, htar]
120
121/-- Explicit inverse vector, subtracting the mean to restore zero total. -/
122def inverseCovarianceVector (d : ℕ) (p : Fin (d + 1) → ℝ) (x : rootSpace d) : rootSpace d :=
123 ⟨WithLp.toLp 2 (fun i ↦ x.1 i / p i - (∑ j, x.1 j / p j) / ((d : ℝ) + 1)), by
124 change (∑ i, (x.1 i / p i - (∑ j, x.1 j / p j) / ((d : ℝ) + 1))) = 0
125 rw [Finset.sum_sub_distrib]
126 simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul,
127 Nat.cast_add, Nat.cast_one]
128 field_simp
129 ring⟩
130
131@[simp] theorem inverseCovarianceVector_apply (d : ℕ) (p : Fin (d + 1) → ℝ)
132 (x : rootSpace d) (i : Fin (d + 1)) :
133 (inverseCovarianceVector d p x).1 i =
134 x.1 i / p i - (∑ j, x.1 j / p j) / ((d : ℝ) + 1) := rfl
135
136/-- The candidate inverse solves the covariance equation for every root-space
137vector; it is not merely a formula for a quadratic form. -/
138theorem rootCovariance_inverseVector (d : ℕ) (p : Fin (d + 1) → ℝ)
139 (hp : ∑ i, p i = 1) (hp0 : ∀ i, p i ≠ 0) (x : rootSpace d) :
140 rootCovariance d p (inverseCovarianceVector d p x) = x := by
141 have hsum : (∑ j, p j * (inverseCovarianceVector d p x).1 j) =
142 -(∑ j, x.1 j / p j) / ((d : ℝ) + 1) := by
143 simp only [inverseCovarianceVector_apply, mul_sub, mul_div_cancel₀ _ (hp0 _),
144 Finset.sum_sub_distrib, ← Finset.sum_mul, hp, one_mul]
145 have hx : (∑ j, x.1 j) = 0 := x.2
146 rw [hx]
147 ring
148 apply Subtype.ext
149 ext i
150 rw [rootCovariance_apply d p hp, hsum, inverseCovarianceVector_apply]
151 rw [mul_sub, mul_div_cancel₀ _ (hp0 i)]
152 ring
153
154/-- The inverse quadratic form is the manuscript's exact weighted sum. -/
155theorem inverseCovariance_quadratic (d : ℕ) (p : Fin (d + 1) → ℝ) (x : rootSpace d) :
156 inner ℝ x (inverseCovarianceVector d p x) = ∑ i, (x.1 i)^2 / p i := by
157 change inner ℝ x.1 (inverseCovarianceVector d p x).1 = _
158 erw [EuclideanSpace.inner_eq_star_dotProduct]
159 simp only [dotProduct, Pi.star_apply, star_trivial, inverseCovarianceVector_apply,
160 sub_mul, Finset.sum_sub_distrib, ← Finset.mul_sum]
161 have hx : (∑ j, x.1 j) = 0 := x.2
162 rw [hx, mul_zero, sub_zero]
163 apply Finset.sum_congr rfl
164 intro i _
165 ring
166
167/-- The covariance determinant is nonzero whenever all spectral coordinates
168are nonzero. -/
169theorem rootCovariance_det_ne_zero (d : ℕ) (p : Fin (d + 1) → ℝ)
170 (hp : ∑ i, p i = 1) (hp0 : ∀ i, p i ≠ 0) :
171 LinearMap.det (rootCovariance d p) ≠ 0 := by
172 rw [rootCovariance_det d p hp]
173 exact mul_ne_zero (by positivity) (Finset.prod_ne_zero_iff.mpr (fun i _ ↦ hp0 i))
174
175/-- The inverse used in the Gaussian density is an actual linear equivalence. -/
176def rootCovarianceEquiv (d : ℕ) (p : Fin (d + 1) → ℝ)
177 (hp : ∑ i, p i = 1) (hp0 : ∀ i, p i ≠ 0) : rootSpace d ≃ₗ[ℝ] rootSpace d :=
178 LinearMap.equivOfIsUnitDet (isUnit_iff_ne_zero.mpr (rootCovariance_det_ne_zero d p hp hp0))
179
180@[simp] theorem rootCovarianceEquiv_apply (d : ℕ) (p : Fin (d + 1) → ℝ)
181 (hp : ∑ i, p i = 1) (hp0 : ∀ i, p i ≠ 0) (x : rootSpace d) :
182 rootCovarianceEquiv d p hp hp0 x = rootCovariance d p x := by
183 simp [rootCovarianceEquiv]
184
185/-- The explicit vector formula is exactly the inverse of the constructed
186covariance equivalence. -/
187theorem rootCovarianceEquiv_symm_apply (d : ℕ) (p : Fin (d + 1) → ℝ)
188 (hp : ∑ i, p i = 1) (hp0 : ∀ i, p i ≠ 0) (x : rootSpace d) :
189 (rootCovarianceEquiv d p hp hp0).symm x = inverseCovarianceVector d p x := by
190 apply (rootCovarianceEquiv d p hp hp0).injective
191 rw [LinearEquiv.apply_symm_apply, rootCovarianceEquiv_apply, rootCovariance_inverseVector d p hp hp0]
192
193/-- Exact Gaussian inverse quadratic form for the actual root-space operator. -/
194theorem rootCovarianceEquiv_inverse_quadratic (d : ℕ) (p : Fin (d + 1) → ℝ)
195 (hp : ∑ i, p i = 1) (hp0 : ∀ i, p i ≠ 0) (x : rootSpace d) :
196 inner ℝ x ((rootCovarianceEquiv d p hp hp0).symm x) = ∑ i, (x.1 i)^2 / p i := by
197 rw [rootCovarianceEquiv_symm_apply, inverseCovariance_quadratic]
198
199/-- Strict positivity of the inverse quadratic form follows from a strictly
200positive spectrum. -/
201theorem inverseCovariance_quadratic_pos (d : ℕ) (p : Fin (d + 1) → ℝ)
202 (hp : ∀ i, 0 < p i) (x : rootSpace d) (hx : x ≠ 0) :
203 0 < inner ℝ x (inverseCovarianceVector d p x) := by
204 rw [inverseCovariance_quadratic]
205 have hi : ∃ i, x.1 i ≠ 0 := by
206 by_contra h
207 push_neg at h
208 apply hx
209 apply Subtype.ext
210 ext i
211 simpa using h i
212 obtain ⟨i, hi⟩ := hi
213 exact Finset.sum_pos' (fun j _ ↦ div_nonneg (sq_nonneg _) (hp j).le)
214 ⟨i, Finset.mem_univ i, div_pos (sq_pos_of_ne_zero hi) (hp i)⟩
215
216/-- The root covariance is positive definite on the actual Euclidean
217hyperplane whenever `p` is a positive normalized spectrum. -/
218theorem rootCovariance_quadratic_pos (d : ℕ) (p : Fin (d + 1) → ℝ)
219 (hp : ∑ i, p i = 1) (hp0 : ∀ i, 0 < p i) (x : rootSpace d) (hx : x ≠ 0) :
220 0 < inner ℝ x (rootCovariance d p x) := by
221 let e := rootCovarianceEquiv d p hp (fun i ↦ (hp0 i).ne')
222 have hy : e x ≠ 0 := by
223 intro h
224 apply hx
225 exact e.injective (by simpa using h)
226 have h := inverseCovariance_quadratic_pos d p hp0 (e x) hy
227 rw [← rootCovarianceEquiv_symm_apply d p hp (fun i ↦ (hp0 i).ne')] at h
228 change 0 < inner ℝ (e x) (e.symm (e x)) at h
229 rw [LinearEquiv.symm_apply_apply, real_inner_comm] at h
230 simpa only [e, rootCovarianceEquiv_apply] using h
231
232/-- Bilinear form of the actual covariance restriction. -/
233theorem rootCovariance_inner (d : ℕ) (p : Fin (d + 1) → ℝ) (hp : ∑ i, p i = 1)
234 (x y : rootSpace d) :
235 inner ℝ x (rootCovariance d p y) =
236 (∑ i, p i * x.1 i * y.1 i) - (∑ i, p i * x.1 i) * (∑ i, p i * y.1 i) := by
237 change inner ℝ x.1 (rootCovariance d p y).1 = _
238 erw [EuclideanSpace.inner_eq_star_dotProduct]
239 simp only [dotProduct, Pi.star_apply, star_trivial, rootCovariance_apply d p hp]
240 calc
241 (∑ i, (p i * y.1 i - p i * ∑ j, p j * y.1 j) * x.1 i) =
242 ∑ i, (p i * x.1 i * y.1 i - (p i * x.1 i) * ∑ j, p j * y.1 j) := by
243 apply Finset.sum_congr rfl
244 intro i _
245 ring
246 _ = _ := by rw [Finset.sum_sub_distrib, ← Finset.sum_mul]
247
248/-- Symmetry, together with the preceding strict positivity theorem, verifies
249that the constructed operator is a nondegenerate Euclidean covariance. -/
250theorem rootCovariance_isSymmetric (d : ℕ) (p : Fin (d + 1) → ℝ) (hp : ∑ i, p i = 1) :
251 (rootCovariance d p).IsSymmetric := by
252 intro x y
253 rw [real_inner_comm y (rootCovariance d p x),
254 rootCovariance_inner d p hp y x, rootCovariance_inner d p hp x y]
255 rw [mul_comm (∑ i, p i * y.1 i) (∑ i, p i * x.1 i)]
256 congr 1
257 apply Finset.sum_congr rfl
258 intro i _
259 ring
260
261end Cloning.YoungHyperplane