Skip to content

Commit 26fbcd9

Browse files
pfaffelheric-wiesermattrobballpfaffelhRemyDegenne
committed
feat: introduce Gram matrices (leanprover-community#25883)
A Gram matrix has entry `⟪v i, v j⟫` at `i j : n`, where `v : n → α` is an `InnerProductSpace 𝕜 α`. Give this notion and show that Gram matrices are positive semi-definite. This will be used later in order to show that the covariance matrix for Brownian Motion is positive semi-definite. [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/from-referrer/) Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: pfaffelh <p.p@stochastik.uni-freiburg.de> Co-authored-by: Matthew Robert Ballard <matt@mrb.email> Co-authored-by: pfaffelh <pfaffelh@gmail.com> Co-authored-by: Rémy Degenne <remydegenne@gmail.com>
1 parent 2fb8b41 commit 26fbcd9

3 files changed

Lines changed: 142 additions & 2 deletions

File tree

Mathlib.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,6 +1706,7 @@ import Mathlib.Analysis.InnerProductSpace.Convex
17061706
import Mathlib.Analysis.InnerProductSpace.Defs
17071707
import Mathlib.Analysis.InnerProductSpace.Dual
17081708
import Mathlib.Analysis.InnerProductSpace.EuclideanDist
1709+
import Mathlib.Analysis.InnerProductSpace.GramMatrix
17091710
import Mathlib.Analysis.InnerProductSpace.GramSchmidtOrtho
17101711
import Mathlib.Analysis.InnerProductSpace.Harmonic.Basic
17111712
import Mathlib.Analysis.InnerProductSpace.Harmonic.Constructions
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/-
2+
Copyright (c) 2025 Peter Pfaffelhuber. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Peter Pfaffelhuber
5+
-/
6+
7+
import Mathlib.LinearAlgebra.Matrix.PosDef
8+
9+
/-! # Gram Matrices
10+
11+
This file defines Gram matrices and proves their positive semidefiniteness.
12+
Results require `RCLike 𝕜`.
13+
14+
## Main definition
15+
16+
* `Matrix.gram` : the `Matrix n n 𝕜` with `⟪v i, v j⟫` at `i j : n`, where `v : n → E` for an
17+
`Inner 𝕜 E`.
18+
19+
## Main results
20+
21+
* `Matrix.posSemidef_gram`: Gram matrices are positive semidefinite.
22+
* `Matrix.posDef_gram_iff_linearIndependent`: Linear independence of `v` is
23+
equivalent to positive definiteness of `gram 𝕜 v`.
24+
-/
25+
26+
open RCLike Real Matrix
27+
28+
open scoped InnerProductSpace ComplexOrder ComplexConjugate
29+
30+
variable {E n α 𝕜 : Type*}
31+
namespace Matrix
32+
33+
/-- The entries of a Gram matrix are inner products of vectors in an inner product space. -/
34+
def gram (𝕜 : Type*) [Inner 𝕜 E] (v : n → E) : Matrix n n 𝕜 := of fun i j ↦ ⟪v i, v j⟫_𝕜
35+
36+
@[simp]
37+
lemma gram_apply [Inner 𝕜 E] (v : n → E) (i j : n) :
38+
(gram 𝕜 v) i j = ⟪v i, v j⟫_𝕜 := rfl
39+
40+
variable [RCLike 𝕜]
41+
42+
section SemiInnerProductSpace
43+
variable [SeminormedAddCommGroup E] [InnerProductSpace 𝕜 E]
44+
45+
@[simp]
46+
lemma gram_zero : gram 𝕜 (0 : n → E) = 0 := Matrix.ext fun _ _ ↦ inner_zero_left _
47+
48+
@[simp]
49+
lemma gram_single [DecidableEq n] (i : n) (x : E) :
50+
gram 𝕜 (Pi.single i x) = Matrix.single i i ⟪x, x⟫_𝕜 := by
51+
ext j k
52+
obtain hij | rfl := ne_or_eq i j
53+
· simp [hij]
54+
obtain hik | rfl := ne_or_eq i k
55+
· simp [hik]
56+
simp
57+
58+
lemma submatrix_gram (v : n → E) {m : Set n} (f : m → n) :
59+
(gram 𝕜 v).submatrix f f = gram 𝕜 (v ∘ f) := rfl
60+
61+
variable (𝕜) in
62+
/-- A Gram matrix is Hermitian. -/
63+
lemma isHermitian_gram (v : n → E) : (gram 𝕜 v).IsHermitian :=
64+
Matrix.ext fun _ _ ↦ inner_conj_symm _ _
65+
66+
variable [Fintype n]
67+
68+
theorem star_dotProduct_gram_mulVec (v : n → E) (x y : n → 𝕜) :
69+
star x ⬝ᵥ (gram 𝕜 v) *ᵥ y = ⟪∑ i, x i • v i, ∑ i, y i • v i⟫_𝕜 := by
70+
trans ∑ i, ∑ j, conj (x i) * y j * ⟪v i, v j⟫_𝕜
71+
· simp_rw [dotProduct, mul_assoc, ← Finset.mul_sum, mulVec, dotProduct, mul_comm, ← star_def,
72+
gram_apply, Pi.star_apply]
73+
· simp_rw [sum_inner, inner_sum, inner_smul_left, inner_smul_right, mul_assoc]
74+
75+
variable (𝕜) in
76+
/-- A Gram matrix is positive semidefinite. -/
77+
theorem posSemidef_gram (v : n → E) :
78+
PosSemidef (gram 𝕜 v) := by
79+
refine ⟨isHermitian_gram _ _, fun x ↦ ?_⟩
80+
rw [star_dotProduct_gram_mulVec, le_iff_re_im]
81+
simp [inner_self_nonneg]
82+
83+
/-- In a normed space, positive definiteness of `gram 𝕜 v` implies linear independence of `v`. -/
84+
theorem linearIndependent_of_posDef_gram {v : n → E} (h_gram : PosDef (gram 𝕜 v)) :
85+
LinearIndependent 𝕜 v := by
86+
rw [Fintype.linearIndependent_iff]
87+
intro y hy
88+
obtain ⟨h1, h2⟩ := h_gram
89+
specialize h2 y
90+
simp_all [star_dotProduct_gram_mulVec]
91+
92+
end SemiInnerProductSpace
93+
94+
section NormedInnerProductSpace
95+
variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [Fintype n]
96+
97+
/-- In a normed space, linear independence of `v` implies positive definiteness of `gram 𝕜 v`. -/
98+
theorem posDef_gram_of_linearIndependent
99+
{v : n → E} (h_li : LinearIndependent 𝕜 v) : PosDef (gram 𝕜 v) := by
100+
rw [Fintype.linearIndependent_iff] at h_li
101+
obtain ⟨h0, h1⟩ := posSemidef_gram 𝕜 v
102+
refine ⟨h0, fun x hx ↦ (h1 x).lt_of_ne' ?_⟩
103+
rw [star_dotProduct_gram_mulVec, inner_self_eq_zero.ne]
104+
exact mt (h_li x) (mt funext hx)
105+
106+
/-- In a normed space, linear independence of `v` is equivalent to positive definiteness of
107+
`gram 𝕜 v`. -/
108+
theorem posDef_gram_iff_linearIndependent {v : n → E} :
109+
PosDef (gram 𝕜 v) ↔ LinearIndependent 𝕜 v :=
110+
⟨linearIndependent_of_posDef_gram, posDef_gram_of_linearIndependent⟩
111+
112+
end NormedInnerProductSpace
113+
114+
end Matrix

Mathlib/MeasureTheory/Function/L2Space.lean

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ noncomputable section
2727

2828
open TopologicalSpace MeasureTheory MeasureTheory.Lp Filter
2929

30-
open scoped NNReal ENNReal MeasureTheory
30+
open scoped NNReal ENNReal MeasureTheory InnerProductSpace
3131

3232
namespace MeasureTheory
3333

@@ -195,7 +195,7 @@ end InnerProductSpace
195195

196196
section IndicatorConstLp
197197

198-
variable (𝕜) {s : Set α}
198+
variable (𝕜) {s t : Set α}
199199

200200
/-- The inner product in `L2` of the indicator of a set `indicatorConstLp 2 hs hμs c` and `f` is
201201
equal to the integral of the inner product over `s`: `∫ x in s, ⟪c, f x⟫ ∂μ`. -/
@@ -241,6 +241,31 @@ theorem inner_indicatorConstLp_one (hs : MeasurableSet s) (hμs : μ s ≠ ∞)
241241
⟪indicatorConstLp 2 hs hμs (1 : 𝕜), f⟫ = ∫ x in s, f x ∂μ := by
242242
rw [L2.inner_indicatorConstLp_eq_inner_setIntegral 𝕜 hs hμs (1 : 𝕜) f]; simp
243243

244+
/-- The inner product in `L2` of two `indicatorConstLp`s, i.e. functions which are constant `a : E`
245+
and `b : E` on measurable `s t : Set α` with finite measure, respectively, is `⟪a, b⟫` times the
246+
measure of `s ∩ t`. -/
247+
lemma inner_indicatorConstLp_indicatorConstLp [CompleteSpace E]
248+
(hs : MeasurableSet s) (ht : MeasurableSet t) (hμs : μ s ≠ ∞ := by finiteness)
249+
(hμt : μ t ≠ ∞ := by finiteness) (a b : E) :
250+
⟪indicatorConstLp 2 hs hμs a, indicatorConstLp 2 ht hμt b⟫ = μ.real (s ∩ t) • ⟪a, b⟫ := by
251+
let : InnerProductSpace ℝ E := InnerProductSpace.rclikeToReal 𝕜 E
252+
rw [inner_indicatorConstLp_eq_inner_setIntegral, setIntegral_indicatorConstLp hs,
253+
inner_smul_right_eq_smul, Set.inter_comm]
254+
255+
/-- The inner product in `L2` of indicators of two sets with finite measure
256+
is the measure of the intersection. -/
257+
lemma inner_indicatorConstLp_one_indicatorConstLp_one
258+
(hs : MeasurableSet s) (ht : MeasurableSet t)
259+
(hμs : μ s ≠ ∞ := by finiteness) (hμt : μ t ≠ ∞ := by finiteness) :
260+
⟪indicatorConstLp 2 hs hμs (1 : 𝕜), indicatorConstLp 2 ht hμt (1 : 𝕜)⟫ = μ.real (s ∩ t) := by
261+
simp [inner_indicatorConstLp_indicatorConstLp, RCLike.ofReal_alg]
262+
263+
lemma real_inner_indicatorConstLp_one_indicatorConstLp_one
264+
(hs : MeasurableSet s) (ht : MeasurableSet t)
265+
(hμs : μ s ≠ ∞ := by finiteness) (hμt : μ t ≠ ∞ := by finiteness) :
266+
⟪indicatorConstLp 2 hs hμs (1 : ℝ), indicatorConstLp 2 ht hμt (1 : ℝ)⟫_ℝ = μ.real (s ∩ t) := by
267+
simp [inner_indicatorConstLp_indicatorConstLp]
268+
244269
end IndicatorConstLp
245270

246271
end L2

0 commit comments

Comments
 (0)