PositiveSemidefinite.lean
Lean 4 source, lean/DataMiningAsObservation/PositiveSemidefinite.lean at commit bccca4f. Appendix C, Machine-checked statements, says what each file proves. All Lean files.
/-
PositiveSemidefinite.lean. Chapter 0 section 0.3 and section 0.5, the positive semidefinite
matrix.
A matrix is positive semidefinite when every quadratic form in it is nonnegative. The sum
of two such matrices is one, a nonnegative multiple is one, an outer product of a vector
with itself is one, the read operator is one whenever the weights are nonnegative, and the
diagonal entries of one are nonnegative.
-/
import Mathlib
import DataMiningAsObservation.ReadOperator
namespace DMO.PositiveSemidefinite
open Matrix DMO.ReadOperator
variable {Ω : Type*} [Fintype Ω] {n : ℕ}
/-- Positive semidefinite. -/
def IsPSD (A : Matrix (Fin n) (Fin n) ℝ) : Prop := ∀ x, 0 ≤ x ⬝ᵥ (A *ᵥ x)
/-- **A sum of positive semidefinite matrices is positive semidefinite.** -/
theorem psd_add {A B : Matrix (Fin n) (Fin n) ℝ} (hA : IsPSD A) (hB : IsPSD B) :
IsPSD (A + B) := fun x => by
rw [add_mulVec, dotProduct_add]
exact add_nonneg (hA x) (hB x)
/-- **A nonnegative multiple of a positive semidefinite matrix is positive semidefinite.** -/
theorem psd_smul {A : Matrix (Fin n) (Fin n) ℝ} (hA : IsPSD A) (c : ℝ) (hc : 0 ≤ c) :
IsPSD (c • A) := fun x => by
have h : (c • A) *ᵥ x = c • (A *ᵥ x) := by
ext i
simp [Matrix.mulVec, dotProduct, Finset.mul_sum, mul_assoc]
rw [h, dotProduct_smul, smul_eq_mul]
exact mul_nonneg hc (hA x)
/-- **An outer product of a vector with itself is positive semidefinite.** -/
theorem psd_outer (g : Fin n → ℝ) : IsPSD (vecMulVec g g) := fun x => by
rw [rank_one_reads_one_direction, dotProduct_smul, smul_eq_mul, dotProduct_comm x g]
exact mul_self_nonneg _
/-- **The read operator is positive semidefinite.** -/
theorem psd_readOp (w : Ω → ℝ) (hw : ∀ ω, 0 ≤ w ω) (g : Ω → Fin n → ℝ) : IsPSD (readOp w g) :=
fun x => quad_readOp_nonneg w hw g x
/-- **The diagonal of a positive semidefinite matrix is nonnegative.** -/
theorem psd_diag_nonneg {A : Matrix (Fin n) (Fin n) ℝ} (hA : IsPSD A) (i : Fin n) : 0 ≤ A i i := by
have := hA (Pi.single i 1)
simpa [Matrix.mulVec, dotProduct, Pi.single_apply] using this
end DMO.PositiveSemidefinite