Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Lemma 1: the LDA eigenvalues are real and nonnegative

Proved
SSLSpectralEmbedding.lda_eigenvalues_real_nonneg

by Xeroth · Nov 24, 2026 · Mathlib 0df444a (Lean v4.33.1)

graph-laplacianmatrix-analysisself-supervised-learningspectral-embeddingvicreg

Let X∈RN×DX\in\mathbb{R}^{N\times D}X∈RN×D be data with class labels y∈{1,…,C}Ny\in\{1,\dots,C\}^Ny∈{1,…,C}N. Let Gi,j=1/NcG_{i,j}=1/N_cGi,j​=1/Nc​ when yi=yj=cy_i=y_j=cyi​=yj​=c (NcN_cNc​ the size of class ccc) and Gi,j=0G_{i,j}=0Gi,j​=0 otherwise. Let Σw=X⊤(I−G)X\Sigma_w=X^\top(I-G)XΣw​=X⊤(I−G)X and Σb=X⊤GX\Sigma_b=X^\top GXΣb​=X⊤GX be the within- and between-class scatter matrices, and suppose Σw\Sigma_wΣw​ is invertible. Let Σw−1/2\Sigma_w^{-1/2}Σw−1/2​ be the positive definite square root of Σw−1\Sigma_w^{-1}Σw−1​. Then

  1. Σw−1Σb\Sigma_w^{-1}\Sigma_bΣw−1​Σb​ and Σw−1/2ΣbΣw−1/2\Sigma_w^{-1/2}\Sigma_b\Sigma_w^{-1/2}Σw−1/2​Σb​Σw−1/2​ have the same characteristic polynomial, hence the same eigenvalues with multiplicity;
  2. Σw−1/2ΣbΣw−1/2\Sigma_w^{-1/2}\Sigma_b\Sigma_w^{-1/2}Σw−1/2​Σb​Σw−1/2​ is symmetric;
  3. every (complex) eigenvalue of Σw−1Σb\Sigma_w^{-1}\Sigma_bΣw−1​Σb​ is real and nonnegative.

The lemma ensures that the generalized eigenvalue problem of LDA, and the division by 1+λLDA1+\lambda_{\rm LDA}1+λLDA​ in Appendix A.16, are well posed.

Formalization Note The square root Σw−1/2\Sigma_w^{-1/2}Σw−1/2​ is any positive definite SSS with S2=Σw−1S^2=\Sigma_w^{-1}S2=Σw−1​, which is unique. Nonnegativity rests on Σb\Sigma_bΣb​ being positive semidefinite, which the paper does not state: symmetry alone gives real, not nonnegative, eigenvalues.

Preamble
import Mathlib
import Definitions.Def_SSLSpectralEmbedding_Basic

open Matrix
Formal statement
namespace SSLSpectralEmbedding

theorem lda_eigenvalues_real_nonneg {N D C : ℕ} (X : Matrix (Fin N) (Fin D) ℝ) (y : Fin N → Fin C)
    (hw : (withinScatter X y).det ≠ 0)
    (S : Matrix (Fin D) (Fin D) ℝ) (hS : S.PosDef) (hSS : S * S = (withinScatter X y)⁻¹) :
    ((withinScatter X y)⁻¹ * betweenScatter X y).charpoly = (S * betweenScatter X y * S).charpoly ∧
    (S * betweenScatter X y * S).IsHermitian ∧
    ∀ μ : ℂ, (((withinScatter X y)⁻¹ * betweenScatter X y).charpoly.map (algebraMap ℝ ℂ)).IsRoot μ →
      μ.im = 0 ∧ 0 ≤ μ.re := by sorry

end SSLSpectralEmbedding
Source
Balestriero and LeCun, Contrastive and Non-Contrastive Self-Supervised Learning Recover Global and Local Spectral Embedding Methods, arXiv:2205.11508v3 (NeurIPS 2022), Appendix A.15, Lemma 1, p. 31
Read-back

What the Lean code literally says, in plain math · claude-opus-5-5

Let N,D,CN, D, CN,D,C be natural numbers, with no constraints. Let XXX be an arbitrary real N×DN \times DN×D matrix, whose iii-th row is the data point of sample iii. Let y:{1,…,N}→{1,…,C}y : \{1,\dots,N\} \to \{1,\dots,C\}y:{1,…,N}→{1,…,C} be an arbitrary labelling that assigns each sample iii a class yiy_iyi​. Classes that no sample receives are allowed.

For a class ccc, let Nc=#{k:yk=c}N_c = \#\{k : y_k = c\}Nc​=#{k:yk​=c} be the number of samples carrying label ccc. The N×NN\times NN×N supervised relation matrix GGG is defined entrywise by

Gij={1Nyiif yi=yj,0otherwise.G_{ij} = \begin{cases} \dfrac{1}{N_{y_i}} & \text{if } y_i = y_j,\\[4pt] 0 & \text{otherwise.}\end{cases}Gij​=⎩⎨⎧​Nyi​​1​0​if yi​=yj​,otherwise.​

Since sample iii itself has label yiy_iyi​, we have Nyi≥1N_{y_i} \ge 1Nyi​​≥1, so no division by zero occurs. Note that GGG has nonzero diagonal: Gii=1/NyiG_{ii} = 1/N_{y_i}Gii​=1/Nyi​​. From GGG the theorem builds two real D×DD\times DD×D matrices, where III is the N×NN\times NN×N identity:

  • the within-class scatter Σw=X⊤(I−G) X\Sigma_w = X^\top (I - G)\, XΣw​=X⊤(I−G)X;
  • the between-class scatter Σb=X⊤G X\Sigma_b = X^\top G\, XΣb​=X⊤GX.

Hypotheses.

  1. det⁡Σw≠0\det \Sigma_w \neq 0detΣw​=0, so Σw\Sigma_wΣw​ is invertible and Σw−1\Sigma_w^{-1}Σw−1​ denotes its true inverse.
  2. SSS is a real D×DD\times DD×D matrix that is positive definite: it is symmetric and v⊤Sv>0v^\top S v > 0v⊤Sv>0 for every nonzero v∈RDv \in \mathbb{R}^Dv∈RD.
  3. SSS satisfies S2=Σw−1S^2 = \Sigma_w^{-1}S2=Σw−1​.

Conclusion. All three of the following hold:

  1. The characteristic polynomials agree:
χΣw−1Σb(t)=χS Σb S(t).\chi_{\Sigma_w^{-1}\Sigma_b}(t) = \chi_{S\,\Sigma_b\,S}(t).χΣw−1​Σb​​(t)=χSΣb​S​(t).
  1. The matrix S Σb SS\,\Sigma_b\,SSΣb​S is symmetric.
  2. Regard the real polynomial χΣw−1Σb\chi_{\Sigma_w^{-1}\Sigma_b}χΣw−1​Σb​​ as a polynomial with complex coefficients. Then every complex root μ\muμ of it satisfies
Im⁡μ=0andRe⁡μ≥0.\operatorname{Im}\mu = 0 \quad\text{and}\quad \operatorname{Re}\mu \ge 0.Imμ=0andReμ≥0.

That is, every eigenvalue of Σw−1Σb\Sigma_w^{-1}\Sigma_bΣw−1​Σb​ is a nonnegative real number.

The statement says nothing about multiplicities. It does not assert that S Σb SS\,\Sigma_b\,SSΣb​S is positive semidefinite; it asserts only that it is symmetric.

Edge cases.

  • D=0D = 0D=0: all matrices are empty. Then det⁡Σw=1\det\Sigma_w = 1detΣw​=1, the empty SSS satisfies the hypotheses, both characteristic polynomials equal 111, and the root condition holds vacuously.
  • N=0N = 0N=0: Σw\Sigma_wΣw​ is the D×DD\times DD×D zero matrix, so the determinant hypothesis can hold only when D=0D = 0D=0.
  • C=0C = 0C=0: a labelling exists only when N=0N = 0N=0.
  • Every class has exactly one sample: then G=IG = IG=I and Σw=0\Sigma_w = 0Σw​=0, so the hypothesis det⁡Σw≠0\det\Sigma_w \ne 0detΣw​=0 fails whenever D≥1D \ge 1D≥1.
  • In general: the determinant hypothesis requires X⊤(I−G)XX^\top(I-G)XX⊤(I−G)X to be nonsingular. This constrains NNN, DDD, the class sizes and XXX jointly. For example, it is impossible when DDD exceeds NNN minus the number of distinct labels that actually occur.
Human review
  • Endorsed by Shuze Chen · Nov 24, 2026

    Confirmed by the moderator at approval.

  • Endorsed by Xeroth · Nov 24, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me