Book XXIV contents · ← Chapter 7 · master indexChapter 8 · Book XXI →
Principia Orthogona · Book XXIV · Linear and nonlinear · Chapter 8

Inner products and the spectral theorem

An inner product gives lengths, angles and perpendicularity. With it, the closest point in a subspace is the foot of a perpendicular, fitting a line to data is a projection, and a symmetric matrix, which in chapter 7 could have been anything, turns out to have real eigenvalues and perpendicular eigenvectors.

The object. A real symmetric 2×2 matrix A = [[a,b],[b,d]]. Choose a, b, d and read off the trace T, the determinant D, the two real eigenvalues, an eigenvector for each, their dot product (which is zero), and whether the quadratic form a x² + 2b xy + d y² is positive definite, negative definite, indefinite or singular. The button counts the 343 matrices with entries from −3 to 3.

abd
Held textLax, Linear Algebra and Its Applications 2nd ed., Chapter 7, Euclidean Structure: Schwarz p.79, triangle and Pythagoras p.80, Gram–Schmidt p.81, orthogonal complement and projection pp.82–83, closest point and adjoint p.84, least squares p.86; Chapter 8, Spectral Theory of Self-Adjoint Mappings: self-adjoint p.101, Hessian p.102, quadratic forms p.103, Theorem 4 p.106 (scan; page checks in the script)
Claim typestandard mathematics, no new results; Hermitian matrices, normal maps and the singular value decomposition are not in this chapter
LeanOrtho.lean: eight statements, compiled (standard axioms only)
Checksch08-verify.py: exact arithmetic, exhaustive finite families, page references
layers

1 · The scalar product, lengths and angles

Intuition

The scalar product (u, v) = u1v1 + … + unvn measures how much two vectors point the same way. Its square root of (u, u) is the length. Two facts make the geometry work: the product of lengths is never smaller than the size of the scalar product (Schwarz), so an angle can be defined, and the length of a sum is never more than the sum of lengths (triangle). When the scalar product is zero the vectors are perpendicular, and then the lengths obey Pythagoras.

Statement
Euclidean structure and Theorem 1, Schwarz (Lax p.79)For real vectors, (x, y) is symmetric, linear in each slot, and (x, x) > 0 for x ≠ 0. Then |(x, y)| ≤ |x| |y|, with equality exactly when x and y are proportional.
Triangle inequality and Pythagoras (Lax p.80)|x + y| ≤ |x| + |y|. If (x, y) = 0 then |x + y|² = |x|² + |y|².
Proof

Schwarz. If y = 0 both sides are 0. Otherwise, for every real t, 0 ≤ (x − ty, x − ty) = |x|² − 2t(x, y) + t²|y|². Take t = (x, y)/|y|²: this gives 0 ≤ |x|² − (x, y)²/|y|², which is the inequality squared. Equality means (x − ty, x − ty) = 0, so x = ty by positivity. □

Triangle. |x + y|² = |x|² + 2(x, y) + |y|² ≤ |x|² + 2|x||y| + |y|² = (|x| + |y|)² by Schwarz. Pythagoras is the same expansion with the middle term 0. □

Remarks

Lax pp.77–80. Lean: schwarz, triangle and pythagoras are calls to Mathlib’s abs_real_inner_le_norm, norm_add_le and norm_add_sq_eq_norm_sq_add_norm_sq_real, stated for any real inner product space; compiled. For pythagoras the Mathlib lemma gives the squares as products, and one nlinarith step turns them into powers. The script checks Schwarz for all 15,625 ordered pairs of integer vectors in {−2,…,2}3; that equality holds exactly for proportional pairs; the triangle inequality exactly, through squares; and Pythagoras for every orthogonal pair. Controls: the form x1y1 − x2y2 is not positive, since (1,1) is not zero but has “length squared” 0, and Schwarz fails for it: u = (1,0), v = (2,1) give (u, v)² = 4 but (u, u)(v, v) = 1 × 3 = 3. Positivity is doing real work.

2 · Gram–Schmidt: making a basis perpendicular

Intuition

Given any basis, you can straighten it. Keep the first vector. From the second, subtract its shadow along the first. From the third, subtract its shadows along the first two. What is left of each is perpendicular to all earlier ones, and nothing is lost because each step only subtracts combinations of earlier vectors.

Statement
Theorem 4, Gram–Schmidt (Lax p.81)Let y1, …, yn be a basis. Then there are mutually orthogonal nonzero vectors x1, …, xn with xk = yk + (a combination of y1, …, yk−1). Dividing each by its length gives an orthonormal basis.
Proof and worked example

The step. Set xk = yk − ∑j<k [(yk, xj)/(xj, xj)] xj. For i < k, (xk, xi) = (yk, xi) − (yk, xi) = 0, because the earlier xj are orthogonal to one another. And xk is not zero, since otherwise yk would be a combination of y1, …, yk−1. □

Example. y1 = (1,1,0), y2 = (1,0,1), y3 = (0,1,1). Then x1 = (1,1,0). For x2: (y2, x1) = 1 and (x1, x1) = 2, so x2 = (1,0,1) − ½(1,1,0) = (½, −½, 1). For x3: the shadow on x1 has coefficient 1/2 and on x2 has coefficient (1/2)/(3/2) = 1/3, so x3 = (0,1,1) − ½(1,1,0) − ⅓(½, −½, 1) = (−⅔, ⅔, ⅔). Check: (x1, x2) = ½ − ½ = 0, (x1, x3) = 0, (x2, x3) = −⅓ − ⅓ + ⅔ = 0.

Remarks

Lean: not stated; Mathlib has Gram–Schmidt, and the file does not use it. The script runs the worked example in exact fractions, and 200 random integer bases of Q3 (fixed seed): in every case the output is mutually orthogonal and nonzero, and x3 − y3 lies in the span of y1 and y2, which is the triangular property. The output vectors are left unnormalised so everything stays rational.

3 · Orthogonal complement, projection, the closest point

Intuition

Pick a subspace Y, say a line or a plane through the origin. Every vector splits uniquely into a part inside Y and a part perpendicular to Y. The inside part is the orthogonal projection: it is the point of Y nearest to the vector, because any other point of Y adds a sideways step at a right angle to the perpendicular, and by Pythagoras that only lengthens the trip.

Statement
Theorem 6 (Lax p.82)For a subspace Y of a finite-dimensional X, every x is uniquely x = y + y⊥ with y in Y and y⊥ in the orthogonal complement Y⊥. The map P x = y is the orthogonal projection (Lax p.83).
Projection and closest point (Lax pp.83–84)P is linear, P² = P and P is symmetric. And |x − Px| < |x − z| for every z in Y other than Px: Px is the closest point of Y to x. If Y is the range of the matrix A with independent columns, P = A(ATA)−1AT.
Proof and example

The closest point. For z in Y, x − z = (x − Px) + (Px − z), where the first is in Y⊥ and the second is in Y, so by Pythagoras |x − z|² = |x − Px|² + |Px − z|², which is larger unless z = Px. □

The formula. Write Px = Ac. The condition x − Ac ⊥ every column of A is AT(x − Ac) = 0, that is ATA c = ATx. ATA is invertible when the columns are independent, because ATAc = 0 gives |Ac|² = cTATAc = 0, so Ac = 0 and c = 0. Then c = (ATA)−1ATx. □

Example. Project x = (3,1) onto the line through (1,1). The coefficient is (x, (1,1))/((1,1),(1,1)) = 4/2 = 2, so Px = (2,2) and the remainder is (1,−1), perpendicular to (1,1) because 1 − 1 = 0. Check by Pythagoras: |x|² = 10 = |Px|² + |x − Px|² = 8 + 2.

Remarks

Lean: complement states that Y and Y⊥ are complementary (IsCompl) in a finite-dimensional real inner product space, from Mathlib’s orthogonal-complement lemma; compiled, with a warning that the lemma used is deprecated in favour of Submodule.isCompl_orthogonal (left unchanged, it still works). The script checks, for 200 random integer 4×2 matrices with independent columns (fixed seed): P = A(ATA)−1AT satisfies P² = P exactly, P is symmetric, x − Px is orthogonal to both columns, and no competitor Ac with c on a 17×17 grid of half-integers is closer to x than Px. That last check is an illustration of Theorem 8, not a proof.

4 · The adjoint, and least squares

Intuition

Fitting a line to points that do not lie on one line is the same problem as finding the closest point. The data vector b is not in the range of the matrix A, so ask for the point of the range nearest to b. The answer is its projection, and the equations that say “the leftover is perpendicular to every column of A” are the normal equations ATA c = ATb. This is the arithmetic behind linear regression in statistics.

Statement
The adjoint (Lax pp.84–85)For a matrix A the adjoint is the transpose: (Ax, y) = (x, ATy) for all x, y. It satisfies (A + B)T = AT + BT and (AB)T = BTAT. A is self-adjoint if AT = A.
Theorem 10, least squares (Lax p.86)The vector c minimising |Ac − b| is the solution of ATA c = ATb. If the columns of A are independent the solution is unique.
Proof and example

Adjoint. (Ax, y) = ∑i (∑j aijxj) yi = ∑j xj (∑i aijyi) = (x, ATy). Least squares is Theorem 8 for the range of A, as in section 3. □

Example, four points. Fit y = c0 + c1t to (0,1), (1,2), (2,2), (3,4). The matrix A has rows (1,0), (1,1), (1,2), (1,3) and b = (1,2,2,4). Then ATA = [[4,6],[6,14]] and ATb = (9,18). Since det ATA = 56 − 36 = 20, the inverse is (1/20)[[14,−6],[−6,4]], and c = (1/20)(126 − 108, −54 + 72) = (9/10, 9/10). The line is y = 0.9 + 0.9 t, the fitted values are 0.9, 1.8, 2.7, 3.6, and the residuals are 0.1, 0.2, −0.7, 0.4. They add to 0 and are orthogonal to the t column (0.2 − 1.4 + 1.2 = 0). The sum of squared residuals is 0.01 + 0.04 + 0.49 + 0.16 = 7/10.

Remarks

Lean: not stated. The script checks every number in the example in exact fractions: the normal equations [[4,6],[6,14]] and (9,18), the solution, the residuals, the sum 7/10, that no line with intercept and slope within 1/2 of the fit (441 lines, steps of 1/20) has a smaller sum of squares, and that moving the intercept by 1/10 adds exactly 4 × (1/10)² = 1/25, as Pythagoras predicts. Link to statistics. This is the computation behind the least-squares line of OpenIntro Statistics, chapter 8 (linear regression with a single predictor; about page 303 of the held copy, a reference the script does not check). What this chapter does not do is any of the statistics: no standard errors, no model assumptions.

5 · Self-adjoint maps and quadratic forms

Intuition

A symmetric matrix A defines a quadratic form q(y) = (Ay, y), a bowl-shaped, saddle-shaped or trough-shaped function on the plane. Near a critical point, any smooth function of several variables looks like such a form built from its second derivatives, the Hessian, which is symmetric because mixed partial derivatives agree. So whether a critical point is a minimum, a maximum or a saddle is a question about the signs of a symmetric matrix.

Statement
Quadratic forms and the Hessian (Lax pp.101–103)For real symmetric A, q(y) = (Ay, y) = ∑ aij yi yj. The Hessian of a function f at a point is the symmetric matrix of its second partial derivatives. Lax’s Theorem 1 on p.103 is also about quadratic forms; this chapter uses only the 2×2 sign test below, proved from scratch.
2×2 sign testFor A = [[a,b],[b,d]] with T = a + d and D = ad − b²: the form is positive definite exactly when a > 0 and D > 0, equivalently when T > 0 and D > 0; negative definite when T < 0 and D > 0; indefinite when D < 0; and singular when D = 0.
Proof of the sign test

Complete the square: if a ≠ 0, a y1² + 2b y1y2 + d y2² = a(y1 + (b/a)y2)² + (D/a) y2². If a > 0 and D > 0 both terms are non-negative and they vanish together only at y = 0: positive definite. If D < 0 the two terms have opposite signs, so the form takes both signs. If D > 0 then a and d have the same sign (ad > b² ≥ 0), so a > 0 exactly when T > 0. The cases a = 0 are handled by d, or by D = −b² ≤ 0. □

Remarks

Lean: not stated; the sign test is checked by the script, not by Lean. The script runs over all 343 symmetric integer matrices with entries from −3 to 3: 31 positive definite, 31 negative definite, 256 indefinite, 25 singular; for all 343 the two forms of the positive-definite test agree; and each positive-definite matrix has q(y) > 0 at all 48 nonzero y with entries in −3..3 (an illustration). The Hessian test for critical points (positive definite means local minimum) is Lax’s statement of a result from calculus; it is referenced here, not proved, and the script does not check it.

6 · The spectral theorem for symmetric matrices

Intuition

In chapter 7 a real matrix could have no real eigenvalue (a rotation), or too few eigenvectors (a shear). Symmetry rules out both. The reason in two dimensions is a one-line computation: the two eigenvectors, built from the entries, are automatically perpendicular. In every dimension the same thing holds, so a symmetric matrix is a stretching along a set of perpendicular axes, and those axes are the natural coordinates for the quadratic form.

Statement
Theorem 4, the spectral theorem (Lax p.106)A self-adjoint map on a finite-dimensional real Euclidean space has real eigenvalues and an orthonormal basis of eigenvectors. Equivalently, a real symmetric matrix A equals ∑ λi Pi, where the Pi are the orthogonal projections onto the eigenspaces.
The 2×2 caseFor real a, b, d the discriminant (a − d)² + 4b² is non-negative, so the eigenvalues are real. If λ1 ≠ λ2 are the two roots of λ² − Tλ + D, then (b, λ1 − a) and (b, λ2 − a) are eigenvectors and they are orthogonal.
Proof of the 2×2 case and an example

Real roots. T² − 4D = (a + d)² − 4(ad − b²) = (a − d)² + 4b² ≥ 0. Eigenvector. Row one of (A − λI)(b, λ − a)T is (a − λ)b + b(λ − a) = 0, and row two is b² + (d − λ)(λ − a) = b² − (λ² − Tλ + ad) = −(λ² − Tλ + D) = 0 when λ is a root. Orthogonal. The dot product is b² + (λ1 − a)(λ2 − a) = b² + λ1λ2 − a(λ1 + λ2) + a² = b² + D − aT + a² = b² + (ad − b²) − a(a + d) + a² = 0, using λ1 + λ2 = T and λ1λ2 = D. □

General case, in outline (the standard maximisation argument). Maximise the quadratic form (Ax, x) over unit vectors; the maximum is attained (the sphere is compact) at a vector h, and the Lagrange condition gives Ah = λh with λ real. The perpendicular complement of h is carried into itself by A (because (Ax, h) = (x, Ah) = λ(x, h) = 0 for x ⊥ h), so the argument repeats in one dimension fewer. This outline is not machine-checked here.

Example. A = [[2,1,1],[1,2,1],[1,1,2]]. A(1,1,1) = (4,4,4), and A(1,−1,0) = (1,−1,0), A(0,1,−1) = (0,1,−1), so the eigenvalues are 4, 1, 1, and (1,1,1) is perpendicular to the plane spanned by the other two. Then A = 4P1 + 1P2 with P1 = (1/3)J (J all ones) the projection onto (1,1,1) and P2 = I − P1. For the 2×2 case A = [[2,1],[1,2]]: eigenvalues 3 and 1, eigenvectors (1,1) and (1,−1), dot product 0.

Remarks

Lean: eigen_equation is the algebraic heart of the 2×2 orthogonality, proved by linear_combination from the two root equations; eigenbasis_orthonormal is Mathlib’s spectral theorem for symmetric linear maps, stated with an orthonormal basis and real eigenvalues; both compiled. The script checks, for all 343 matrices: the discriminant is non-negative; the 336 with distinct eigenvalues have orthogonal eigenvectors (b, λ − a) by the exact identity b² + D − aT + a² = 0; the other 7 are the scalar matrices. And the 3×3 decomposition above: P1² = P1, P2² = P2, P1P2 = 0, P1 + P2 = I, and 4P1 + P2 = A, all symmetric.

Controls: what symmetry and the reals each contribute. The symmetric matrix [[0,1],[1,1]] has no eigenvalue over F3, because t² − t − 1 has no root there, so the theorem needs the real numbers. The complex symmetric matrix [[1,i],[i,−1]] is not zero but squares to zero, so its only eigenvalue is 0 and it is not diagonalisable: symmetry alone, without realness (it is symmetric but not Hermitian), is not enough. And the non-symmetric [[1,1],[0,1]] has one eigenvalue and one eigenvector line, so no orthogonal pair of eigenvectors. Each control breaks one hypothesis and the conclusion fails.

7 · What is not here

Remarks

Four things are left out on purpose. Complex inner products, Hermitian and normal matrices, which are Lax’s setting for the full spectral theory, are not here. The singular value decomposition, which extends these ideas to non-square matrices, is not here. The existence of the maximum used in the outline of the general proof rests on compactness of the unit sphere, which is not proved in this chapter. And the second-derivative test for critical points of a function of several variables, which uses the Hessian, is stated as a reference to calculus, not proved. The step from this chapter to principal components in statistics (the eigenvectors of a covariance matrix) is an application of the spectral theorem and of a definition of covariance that this book does not yet give.

8 · Exercises

  1. Verify Schwarz for u = (1,2,3) and v = (4,−1,0), and find the angle between them.
  2. Apply Gram–Schmidt to (1,0,0), (1,1,0), (1,1,1). What do you get, and why?
  3. Find the projection of (1,2,3) onto the plane spanned by (1,0,0) and (0,1,0), and the distance from the point to the plane.
  4. Find the least-squares line through (0,0), (1,1), (2,3). Check that the residuals sum to 0 and are orthogonal to the t column.
  5. Decide whether [[1,2],[2,1]], [[1,2],[2,4]] and [[2,3],[3,1]] are positive definite, negative definite, indefinite or singular, using the sign test, and give an eigenvector pair for each.
  6. Show that for a symmetric matrix, eigenvectors belonging to different eigenvalues are orthogonal, by computing (Ah, k) in two ways.
  7. Show that P2 = P and PT = P for P = A(ATA)−1AT.
  8. Show that for any real matrix A, ATA is symmetric with non-negative eigenvalues, and that it is positive definite exactly when the columns of A are independent.