EffectiveRank.lean
Lean 4 source, lean/DataMiningAsObservation/EffectiveRank.lean at commit bccca4f. Appendix C, Machine-checked statements, says what each file proves. All Lean files.
/-
EffectiveRank.lean. Equation 0.7, the effective rank.
The effective rank of a spectrum, the participation ratio, is the square of the sum of the
eigenvalues over the sum of their squares. For a nonnegative spectrum with at least one
positive eigenvalue it lies between one and the number of eigenvalues, it equals the number
of eigenvalues when they are all equal, and it equals one when a single eigenvalue carries
the whole spectrum. No cutoff is chosen.
-/
import Mathlib
namespace DMO.EffectiveRank
open Finset
variable {n : ℕ}
/-- **Equation 0.7.** The effective rank of the spectrum `lam`. -/
noncomputable def effRank (lam : Fin n → ℝ) : ℝ := (∑ i, lam i) ^ 2 / ∑ i, lam i ^ 2
/-- Cauchy–Schwarz. The square of the sum is at most `n` times the sum of squares. -/
theorem sq_sum_le (lam : Fin n → ℝ) : (∑ i, lam i) ^ 2 ≤ n * ∑ i, lam i ^ 2 := by
have h := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ (fun _ : Fin n => (1 : ℝ)) lam
simpa using h
/-- **The effective rank is at most the number of eigenvalues.** -/
theorem effRank_le (lam : Fin n → ℝ) (h : 0 < ∑ i, lam i ^ 2) : effRank lam ≤ n := by
unfold effRank
rw [div_le_iff₀ h]
exact sq_sum_le lam
/-- The sum of squares is at most the square of the sum for a nonnegative spectrum, since
every cross term is nonnegative. -/
theorem sum_sq_le_sq_sum (lam : Fin n → ℝ) (hn : ∀ i, 0 ≤ lam i) :
∑ i, lam i ^ 2 ≤ (∑ i, lam i) ^ 2 := by
rw [sq, Finset.sum_mul_sum]
have hdiag : ∑ i, lam i ^ 2 = ∑ i, ∑ j, if j = i then lam i * lam j else 0 := by
simp [sq]
rw [hdiag]
apply Finset.sum_le_sum; intro i _
apply Finset.sum_le_sum; intro j _
split_ifs with h
· exact le_rfl
· exact mul_nonneg (hn i) (hn j)
/-- **The effective rank is at least one** for a nonnegative spectrum with positive energy. -/
theorem one_le_effRank (lam : Fin n → ℝ) (hn : ∀ i, 0 ≤ lam i) (h : 0 < ∑ i, lam i ^ 2) :
1 ≤ effRank lam := by
unfold effRank
rw [le_div_iff₀ h, one_mul]
exact sum_sq_le_sq_sum lam hn
/-- **A flat spectrum has full effective rank.** -/
theorem effRank_const (c : ℝ) (hc : 0 < c) (hn : 0 < n) :
effRank (fun _ : Fin n => c) = n := by
unfold effRank
simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]
have hn' : (0 : ℝ) < n := by exact_mod_cast hn
field_simp
/-- **A single eigenvalue has effective rank one.** -/
theorem effRank_single (i₀ : Fin n) (c : ℝ) (hc : 0 < c) :
effRank (Pi.single i₀ c) = 1 := by
unfold effRank
simp [Pi.single_apply, hc.ne']
end DMO.EffectiveRank