forked from leanprover-community/mathlib4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGramMatrix.lean
More file actions
139 lines (107 loc) Β· 4.97 KB
/
GramMatrix.lean
File metadata and controls
139 lines (107 loc) Β· 4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/-
Copyright (c) 2025 Peter Pfaffelhuber. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Peter Pfaffelhuber
-/
module
public import Mathlib.Analysis.InnerProductSpace.Basic
public import Mathlib.Analysis.InnerProductSpace.PiL2
public import Mathlib.LinearAlgebra.Matrix.PosDef
import Mathlib.Analysis.Matrix.Order
/-! # Gram Matrices
This file defines Gram matrices and proves their positive semidefiniteness.
Results require `RCLike π`.
## Main definition
* `Matrix.gram` : the `Matrix n n π` with `βͺv i, v jβ«` at `i j : n`, where `v : n β E` for an
`Inner π E`.
## Main results
* `Matrix.posSemidef_gram`: Gram matrices are positive semidefinite.
* `Matrix.posDef_gram_iff_linearIndependent`: Linear independence of `v` is
equivalent to positive definiteness of `gram π v`.
-/
@[expose] public section
open RCLike Real Matrix
open scoped InnerProductSpace ComplexOrder ComplexConjugate
variable {E n Ξ± π : Type*}
namespace Matrix
/-- The entries of a Gram matrix are inner products of vectors in an inner product space. -/
def gram (π : Type*) [Inner π E] (v : n β E) : Matrix n n π := of fun i j β¦ βͺv i, v jβ«_π
@[simp]
lemma gram_apply [Inner π E] (v : n β E) (i j : n) :
(gram π v) i j = βͺv i, v jβ«_π := rfl
variable [RCLike π]
section SemiInnerProductSpace
variable [SeminormedAddCommGroup E] [InnerProductSpace π E]
@[simp]
lemma gram_zero : gram π (0 : n β E) = 0 := Matrix.ext fun _ _ β¦ inner_zero_left _
@[simp]
lemma gram_single [DecidableEq n] (i : n) (x : E) :
gram π (Pi.single i x) = Matrix.single i i βͺx, xβ«_π := by
ext j k
obtain hij | rfl := ne_or_eq i j
Β· simp [hij]
obtain hik | rfl := ne_or_eq i k
Β· simp [hik]
simp
lemma submatrix_gram (v : n β E) {m : Set n} (f : m β n) :
(gram π v).submatrix f f = gram π (v β f) := rfl
variable (π) in
/-- A Gram matrix is Hermitian. -/
lemma isHermitian_gram (v : n β E) : (gram π v).IsHermitian :=
Matrix.ext fun _ _ β¦ inner_conj_symm _ _
theorem star_dotProduct_gram_mulVec [Fintype n] (v : n β E) (x y : n β π) :
star x β¬α΅₯ (gram π v) *α΅₯ y = βͺβ i, x i β’ v i, β i, y i β’ v iβ«_π := by
trans β i, β j, conj (x i) * y j * βͺv i, v jβ«_π
Β· simp_rw [dotProduct, mul_assoc, β Finset.mul_sum, mulVec, dotProduct, mul_comm, β star_def,
gram_apply, Pi.star_apply]
Β· simp_rw [sum_inner, inner_sum, inner_smul_left, inner_smul_right, mul_assoc]
variable [Finite n]
variable (π) in
/-- A Gram matrix is positive semidefinite. -/
theorem posSemidef_gram (v : n β E) :
PosSemidef (gram π v) := by
have := Fintype.ofFinite n
refine .of_dotProduct_mulVec_nonneg (isHermitian_gram _ _) fun x β¦ ?_
rw [star_dotProduct_gram_mulVec, le_iff_re_im]
simp
/-- In a normed space, positive definiteness of `gram π v` implies linear independence of `v`. -/
theorem linearIndependent_of_posDef_gram {v : n β E} (h_gram : PosDef (gram π v)) :
LinearIndependent π v := by
have := Fintype.ofFinite n
rw [Fintype.linearIndependent_iff]
intro y hy
have := h_gram.dotProduct_mulVec_pos (x := y)
simp_all [star_dotProduct_gram_mulVec]
omit [Finite n] in
theorem linearIndependent_of_det_gram_ne_zero [Fintype n] [DecidableEq n] {v : n β E}
(h : (gram π v).det β 0) : LinearIndependent π v :=
linearIndependent_of_posDef_gram <| (posSemidef_gram π v).posDef_iff_det_ne_zero.mpr h
end SemiInnerProductSpace
section NormedInnerProductSpace
variable [NormedAddCommGroup E] [InnerProductSpace π E] [Finite n]
/-- In a normed space, linear independence of `v` implies positive definiteness of `gram π v`. -/
theorem posDef_gram_of_linearIndependent
{v : n β E} (h_li : LinearIndependent π v) : PosDef (gram π v) := by
have := Fintype.ofFinite n
rw [Fintype.linearIndependent_iff] at h_li
refine .of_dotProduct_mulVec_pos (isHermitian_gram _ _) fun x hx β¦
((posSemidef_gram ..).dotProduct_mulVec_nonneg _).lt_of_ne' ?_
rw [star_dotProduct_gram_mulVec, inner_self_eq_zero.ne]
exact mt (h_li x) (mt funext hx)
/-- In a normed space, linear independence of `v` is equivalent to positive definiteness of
`gram π v`. -/
theorem posDef_gram_iff_linearIndependent {v : n β E} :
PosDef (gram π v) β LinearIndependent π v :=
β¨linearIndependent_of_posDef_gram, posDef_gram_of_linearIndependentβ©
omit [Finite n] in
theorem det_gram_ne_zero_iff_linearIndependent [Fintype n] [DecidableEq n] {v : n β E} :
(gram π v).det β 0 β LinearIndependent π v := by
rw [β posDef_gram_iff_linearIndependent, (posSemidef_gram π v).posDef_iff_det_ne_zero]
omit [Finite n] in
theorem gram_eq_conjTranspose_mul {ΞΉ : Type*} [Fintype ΞΉ] (b : OrthonormalBasis ΞΉ π E) (v : n β E) :
letI m := of fun i j β¦ b.repr (v j) i
gram π v = mα΄΄ * m := by
ext i j
simp [mul_apply, b.repr_apply_apply, b.sum_inner_mul_inner]
end NormedInnerProductSpace
end Matrix