|
| 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 |
0 commit comments