If ATr=0, the right side is ∥r∥22+∥Ay∥22≥∥r∥22, with equality only when Ay=0, that is y=0 because the columns of A are independent. So x is the unique minimizer. If ATr=0, take y=tATr with t>0 small: the right side is ∥r∥22−2t∥ATr∥22+t2∥AATr∥22<∥r∥22, so x is not a minimizer. □
Claim 2.C=ATA is symmetric positive definite, so line L3 succeeds and returns an upper triangular R with positive diagonal and RTR=C.
Proof.CT=ATA=C, and vTCv=∥Av∥22>0 for v=0. The column Cholesky algorithm computes, for j=1,…,n, rjj=(cjj−∑k<jrkj2)1/2 and rji=(cji−∑k<jrkjrki)/rjj for i>j. By induction on j, the first j−1 rows of R satisfy the first j−1 rows of RTR=C, and the pivot cjj−∑k<jrkj2 equals the Schur complement sj of the leading (j−1)×(j−1) block in the leading j×j block of C. That block is positive definite, so det of it is the product of the positive leading pivots times sj, and sj>0. So no pivot is ≤0 and the square roots are real and positive. □
Theorem. NORMAL-EQUATIONS returns the least squares solution.
Proof. Lines L4 and L5 solve RTy=d and Rx=y, which are possible because the diagonal of R is positive. Then Cx=RTRx=RTy=d, so ATAx=ATb, and by Claim 1 x is the unique minimizer. ■
Floating point
Assume the standard model with unit roundoff u and mu<1. Write ∥⋅∥ for the 2-norm.
Step 1: forming C and d. Each c^ij is an inner product of length m, so ∣c^ij−cij∣≤γm∑k∣aki∣∣akj∣ (Higham, Section 3.1). Hence C^=C+E1 with ∣E1∣≤γm∣A∣T∣A∣, and in the same way d^=d+f with ∣f∣≤γm∣A∣T∣b∣. For a nonnegative matrix the 2-norm is monotone in the entries, and ∥∣A∣∥≤∥A∥F≤n∥A∥, so
∥E1∥≤nγm∥A∥2,∥f∥≤nγm∥A∥∥b∥.
Step 2: the Cholesky solve. If the Cholesky factorization of C^ runs to completion, the computed x^ satisfies (C^+E2)x^=d^ with ∣E2∣≤γ3n+1∣R^T∣∣R^∣ (Higham, Chapter 10). Since ∥∣R^T∣∣R^∣∥≤n∥R^∥2 and ∥R^∥2=∥R^TR^∥≤∥C^∥(1+O(nu)), this gives ∥E2∥≤cnu∥C∥+O(u2) with cn=O(n2).
Step 3: perturbation. So (C+E)x^=d+f with E=E1+E2, ∥E∥≤ϵ1∥A∥2, ϵ1=(nm+cn)u+O(u2), using ∥C∥=∥A∥2. Subtracting Cx=d gives C(x^−x)=f−Ex^, and ∥C−1∥=1/σn2, so
The bound is in terms of ∥x^∥; if the right side is below 1/2, then ∥x^∥≤2∥x∥ and the same bound holds relative to ∥x∥ with an extra factor 2. This is the bound stated on the page, with cm,n=O(mn+n2). ■
Termination of Cholesky. If C^ is positive definite, the column algorithm completes in floating point whenever cn′uκ2(C^)<1 for a modest cn′ (Higham, Chapter 10). When κ2(A)2u is of order one this can fail, and the implementation then raises NotFullRank instead of returning a value.
What the tests check. The tests compare x^ with the exact rational least squares solution and assert ∥x^−x∥∞/∥x∥∞≤4(m+n)nuκ1(ATA)(1+∥b∥1/(∥A∥1∥x∥∞)), which has the form of Step 3 with the 1-norm quantities, computed exactly, in place of the 2-norm ones; κ2(A)2=κ2(ATA)≤κ1(ATA) for the symmetric matrix ATA.