The spectral theorem
谱定理
Use symmetry to obtain a complete orthonormal eigenbasis, reconstruct a matrix, and bound its quadratic form.
spectral-theoremA coupled calculation can become independent scaling
For , the two output coordinates mix both inputs. Switch to the unit directions and , however, and the same map multiplies one coordinate by three and the other by one. The mixing came from the coordinate frame, not from an inability to separate these two modes.
The real symmetric spectral theorem guarantees such an orthonormal eigenbasis for every real symmetric matrix. This is stronger than saying that some eigenvectors exist. It gives a complete basis, real eigenvalues, and an inverse basis change equal to a transpose. MML, Theorem 4.15 and Section 4.4
What symmetry guarantees
For , there is an orthogonal and a real diagonal such that
The map projects onto one unit direction. The sum says: resolve a vector into these perpendicular components, scale each by its eigenvalue, then add them back. Conversely, a real matrix written as with real diagonal must be symmetric, as transposing the product shows. Deep Learning, Section 2.7
Why are distinct modes perpendicular? If and , symmetry gives
For , this forces . That argument alone does not yet prove a complete eigenbasis exists. A proof sketch fills the gap: the continuous function attains a maximum on the finite-dimensional unit sphere. At a maximizing unit vector, its derivative along every perpendicular direction is zero, forcing to be parallel to . Symmetry then makes the perpendicular subspace invariant: for , . Repeat within that smaller space, down to dimension one.
This proof uses the ordinary finite-dimensional Euclidean setting. Within a repeated-eigenvalue subspace, arbitrary eigenvectors need not already be perpendicular; choose an orthonormal basis inside it. Even distinct eigenvalues do not fix eigenvector signs. Sorting eigenvalues and normalizing vectors still leaves that freedom.
A complete 2×2 decomposition
For , the two eigenvalues are
Choose the first column of as with ; its perpendicular companion is the second column. This angle cancels the off-diagonal entry of . The code scales inputs before forming these expressions and handles the zero matrix separately. It solves only real symmetric 2×2 matrices, not a general eigensolver.
import math
def symmetric_eigen2(a, b, d):
# The input represents [[a,b],[b,d]], so symmetry is explicit.
if not all(math.isfinite(x) for x in (a,b,d)):
raise ValueError("finite real entries required")
scale = max(abs(a),abs(b),abs(d))
if scale == 0:
return [0.,0.], [[1.,0.],[0.,1.]]
p,q,r = a/scale,b/scale,d/scale
theta = .5*math.atan2(2*q,p-r)
c,s = math.cos(theta),math.sin(theta)
middle = (p+r)/2
radius = math.hypot((p-r)/2,q)
values = [scale*(middle+radius),scale*(middle-radius)]
if not all(math.isfinite(x) for x in values):
raise ArithmeticError("eigenvalue overflow")
return values, [[c,-s],[s,c]] # eigenvectors are columns
def reconstruct(values, q):
return [[sum(q[i][k]*values[k]*q[j][k] for k in range(2))
for j in range(2)] for i in range(2)]
for a,b,d in [(2.,1.,2.),(2.,0.,2.),(2.,0.,-1.),(0.,0.,0.),(-3.,0.,-2.)]:
values,q = symmetric_eigen2(a,b,d)
restored = reconstruct(values,q)
target = [[a,b],[b,d]]
assert max(abs(restored[i][j]-target[i][j]) for i in range(2) for j in range(2)) < 1e-12
assert max(abs(sum(q[k][i]*q[k][j] for k in range(2))-float(i==j))
for i in range(2) for j in range(2)) < 1e-12
assert symmetric_eigen2(2.,1.,2.)[0] == [3.,1.]
try:
symmetric_eigen2(1.,float('nan'),2.)
except ValueError:
pass
else:
raise AssertionError("nonfinite input accepted")
With the dimension fixed at two, the operation count and working storage are constant. The tests verify reconstruction and orthonormal columns for positive, negative, repeated, and zero eigenvalues. Scaling avoids some intermediate overflow, but subtracting nearly equal numbers can still lose accuracy in a tiny eigenvalue. Larger problems should use a solver intended for symmetric or Hermitian matrices, such as eigh, and check both reconstruction and orthogonality. NumPy eigh
Which properties are invariant?
For nonzero , let . Then
This Rayleigh quotient is a weighted average of eigenvalues. Its bounds explain why a real symmetric matrix is positive definite precisely when every eigenvalue is positive. A zero eigenvalue leaves a flat direction, and a negative eigenvalue provides a direction with negative quadratic value.
Without symmetry, a matrix may have a nonorthogonal eigenbasis, no full eigenbasis, or complex eigenvalues. The quarter-turn matrix is orthogonal but not symmetric, so a real diagonalization of this form is impossible. Do not use “orthogonal matrix” and “orthogonally diagonalizable matrix” interchangeably. In complex spaces the corresponding Hermitian statement uses conjugate transpose and a unitary basis.
Read the decomposition in both directions
- What are the smallest and largest unit-vector values of for the opening example? Answer: one and three, attained on the corresponding eigenvectors.
- Can be replaced by ? Answer: yes; .
- For , is the eigenbasis unique? Answer: no; any orthonormal basis gives the same matrix.
- Does symmetric imply positive definite? Answer: no. is symmetric but has a negative direction.
A common route into several algorithms
Covariance matrices and graph Laplacians often bring symmetry into learning problems. The theorem also constructs SVD through the symmetric matrix , and turns quadratic forms into sums of independent squared coordinates. These mathematical connections do not prescribe the numerically best implementation: constructing a Gram matrix can make small singular values harder to resolve.
Make a prediction, then check
Is the orthonormal eigenbasis of 2I₂ unique?
Learning objectives
- Explain orthogonality and a complete eigenbasis using symmetry.
- Reconstruct a two-dimensional decomposition and bound a quadratic form with its Rayleigh quotient.
Prerequisites & connections
Explore related knowledge →References
- Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft)
Marc Peter Deisenroth; A. Aldo Faisal; Cheng Soon Ong · 2020 - Deep Learning — Chapter 2: Linear Algebra
Ian Goodfellow; Yoshua Bengio; Aaron Courville · 2016 - NumPy — numpy.linalg.eigh
NumPy developers
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-05 · Codex technical check: cited-source comparison, derivation and numerical checks, bilingual argument comparison, and executed Python assertions; no independent human peer review.
- Independently checked eigenpair residuals, trace, determinant and reconstruction on 120 real symmetric 2×2 matrices.
- Checked the sphere-maximum and invariant-complement proof sketch, repeated-value subspaces and eigenvector signs; no uniqueness of the basis is claimed.
- Compared claims, assumptions, examples, exercises and citations across languages; structural validation additionally compares display equations, code and source lists.
Source locations checked:
- Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft) · Theorem 4.15, printed p.111 / PDF p.117; §4.4 symmetric diagonalization
- Deep Learning — Chapter 2: Linear Algebra · §2.7, orthogonal decomposition and Rayleigh bounds
- NumPy — numpy.linalg.eigh · Input symmetry/Hermitian contract and eigenvector-column output
Related topics