Singular Value Decomposition

lean4-prooflinear-algebravisualization
A=UΣV,U,V orthogonal,  Σ diagonal with σi0A = U \Sigma V^\top,\quad U, V \text{ orthogonal},\; \Sigma \text{ diagonal with } \sigma_i \ge 0

Statement

Let AA be an m×nm \times n real matrix. Then there exist orthogonal matrices URm×mU \in \mathbb{R}^{m \times m}, VRn×nV \in \mathbb{R}^{n \times n} and a rectangular diagonal matrix ΣRm×n\Sigma \in \mathbb{R}^{m \times n} with non-negative diagonal entries σ1σ20\sigma_1 \ge \sigma_2 \ge \cdots \ge 0 (the singular values of AA) such that

A=UΣV.A = U \Sigma V^\top.

The singular values are the square roots of the eigenvalues of the symmetric positive semidefinite matrix AAA^\top A.

Visualization

Let A=(3113)A = \begin{pmatrix} 3 & 1 \\ 1 & 3 \end{pmatrix}.

Step 1 — form AA=A2A^\top A = A^2 (symmetric):

AA=(3113)2=(106610).A^\top A = \begin{pmatrix} 3 & 1 \\ 1 & 3 \end{pmatrix}^2 = \begin{pmatrix} 10 & 6 \\ 6 & 10 \end{pmatrix}.

Step 2 — eigenvalues of AAA^\top A: Characteristic polynomial (10λ)236=0λ=16(10-\lambda)^2 - 36 = 0 \Rightarrow \lambda = 16 or λ=4\lambda = 4.

λ\lambdaσ=λ\sigma = \sqrt{\lambda}eigenvector vv (normalized)
16σ1=4\sigma_1 = 412(1,1)\tfrac{1}{\sqrt{2}}(1,1)^\top
4σ2=2\sigma_2 = 212(1,1)\tfrac{1}{\sqrt{2}}(1,-1)^\top

Step 3 — result:

V=12(1111),Σ=(4002),U=12(1111)=V.V = \frac{1}{\sqrt{2}}\begin{pmatrix}1 & 1\\1 & -1\end{pmatrix},\quad \Sigma = \begin{pmatrix}4 & 0\\ 0 & 2\end{pmatrix},\quad U = \frac{1}{\sqrt{2}}\begin{pmatrix}1 & 1\\ 1 & -1\end{pmatrix} = V.

(Here AA is symmetric positive definite, so U=VU = V.)

Proof Sketch

  1. Spectral theorem on AAA^\top A. The matrix AAA^\top A is symmetric and positive semidefinite, so the Spectral TheoremSpectral TheoremA=QΛQT  (real symmetric case)A = Q \Lambda Q^T \;\text{(real symmetric case)}Every real symmetric matrix is orthogonally diagonalizableRead more → applies: AA=VΛVA^\top A = V \Lambda V^\top with VV orthogonal and Λ=diag(σ12,,σr2,0,)\Lambda = \mathrm{diag}(\sigma_1^2, \ldots, \sigma_r^2, 0, \ldots).
  2. Define UU from AVA V. Set ui=Avi/σiu_i = A v_i / \sigma_i for σi>0\sigma_i > 0. These vectors are orthonormal: uiuj=viAAvj/(σiσj)=σi2δij/(σiσj)=δiju_i^\top u_j = v_i^\top A^\top A v_j / (\sigma_i \sigma_j) = \sigma_i^2 \delta_{ij}/(\sigma_i \sigma_j) = \delta_{ij}.
  3. Complete to orthonormal basis. Extend {ui}\{u_i\} to a full orthonormal basis of Rm\mathbb{R}^m. The extra columns of UU correspond to the null space of AA.
  4. Verify factorization. Compute UΣVU \Sigma V^\top column by column: (UΣV)vi=σiui=Avi(U \Sigma V^\top)v_i = \sigma_i u_i = A v_i, so UΣV=AU \Sigma V^\top = A on all of Rn\mathbb{R}^n.

Connections

SVD rests on the Spectral TheoremSpectral TheoremA=QΛQT  (real symmetric case)A = Q \Lambda Q^T \;\text{(real symmetric case)}Every real symmetric matrix is orthogonally diagonalizableRead more → applied to AAA^\top A and generalizes it to non-square matrices. The orthonormal bases produced are the output of Gram–Schmidt OrthogonalizationGram–Schmidt Orthogonalizationek=fkj<kfk,ejej,ejeje_k = f_k - \sum_{j < k} \frac{\langle f_k, e_j\rangle}{\langle e_j, e_j\rangle} e_jAny linearly independent sequence can be transformed into an orthogonal sequence spanning the same subspace.Read more →. The diagonal Σ\Sigma relates directly to the Rank–Nullity TheoremRank–Nullity Theoremrank(f)+nullity(f)=dimV\operatorname{rank}(f) + \operatorname{nullity}(f) = \dim VThe dimensions of image and kernel of a linear map sum to the domain dimensionRead more →: rank(A)=\mathrm{rank}(A) = number of nonzero singular values.

Lean4 Proof

-- Mathlib has IsHermitian.eigenvalues for real symmetric matrices (spectral theorem).
-- We prove the key ingredient: A^T A is positive semidefinite, so its eigenvalues are nonneg.
-- Mathlib: Analysis.Matrix.PosDef -- eigenvalues_nonneg
open Matrix in
theorem AtA_posSemidef (m n : Type*) [Fintype m] [Fintype n] [DecidableEq m]
    (A : Matrix m n ) : (A.transpose * A).PosSemidef := by
  constructor
  · exact isHermitian_transpose_mul_self A
  · intro x
    have : 0 A.mulVec x‖ ^ 2 := sq_nonneg _
    rwa [ inner_self_eq_norm_sq,  Matrix.inner_mul_transpose_apply,
         Matrix.mul_assoc] at this
    rfl

-- Consequence: singular values (sqrt of eigenvalues of A^T A) are nonneg.
open Matrix in
theorem singular_values_nonneg (n : Type*) [Fintype n] [DecidableEq n]
    (A : Matrix n n ) :
    let hH := isHermitian_transpose_mul_self A
     i, 0  hH.eigenvalues i :=
  fun i => eigenvalues_nonneg (AtA_posSemidef n n A) i