24.3  Least Squares in Practice

Chapter 11 solved the least-squares problem twice. Section 4 of that chapter produced the normal equations A∗Ax=A∗b (Theorem 11.4.2), and Section 8 rewrote them, once a QR factorization was available, as the triangular system Rx=Q∗b. It then recommended the second route and postponed the reason: “forming A∗A squares the sensitivity of the problem to rounding, while (†) never forms that product at all. Chapter 24 makes ‘sensitivity’ precise and proves the comparison; here we record only the practice.”

Chapter 16 supplied half of the reason. Its Theorem 16.8.4 proved κ2(A∗A)=κ2(A)2 and then listed what was still missing: the conditioning of the fitting problem itself, which involves the residual; the arithmetic, which needed a model; and the comparison of the two algorithms in digits. Sections 1 and 2 of this chapter built the model and the vocabulary. This section pays the three debts, in that order, and ends with the reason the reflections of Chapter 11 are the right way to produce Q and R.

Throughout, F=R or F=C, A∈Mm×n(F) with m≥n and rankA=n, and b∈Fm is non-zero. By Corollary 11.4.4 there is then exactly one least-squares solution x, and A∗A is invertible. All norms are ‖⋅‖2 unless a subscript says otherwise.

24.3.1. How sensitive is the problem?

Before any algorithm is judged, the problem has to be measured. Write

r=b−Ax,Ax=Pcol(A)b,

the residual and the projection of Theorem 11.4.2 (b). Since r⊥col(A) and Ax∈col(A), Pythagoras (Theorem 11.1.3) gives ‖b‖2=‖Ax‖2+‖r‖2. So there is a unique θ∈[0,π/2] with

cos⁡θ=‖Ax‖‖b‖,sin⁡θ=‖r‖‖b‖,
(24.3.1)

the angle between b and the column space of A. It is 0 exactly when the system is consistent and π/2 exactly when A∗b=0, in which case x=0 and no relative error can be spoken of. We assume θ<π/2 throughout, so x≠0.

One number is now missing from Chapter 16’s account, and Eq. 24.3.1 supplies it. Here is the sensitivity of x to a perturbation of the data.

Theorem 24.3.1 (Conditioning of the Least-Squares Problem)

Let A∈Mm×n(F) have rank n≤m, let b≠0, let x be the least-squares solution of Az=b, and let θ<π/2 be as in Eq. 24.3.1. Let E∈Mm×n(F) and f∈Fm, and for real t near 0 let x(t) be the least-squares solution of (A+tE)z=b+tf. Then x(t) is defined and differentiable near t=0, with x(0)=x, and

‖x′(0)‖‖x‖ ≤ κ2(A)(εA+εbcos⁡θ) + κ2(A)2εAtan⁡θ,

where εA=‖E‖/‖A‖ and εb=‖f‖/‖b‖.

Idea. The least-squares solution is x(t)=N(t)−1A(t)∗b(t) with N(t)=A(t)∗A(t), which is a differentiable function of t because N(0) is invertible. Rather than differentiate that formula, differentiate the equation N(t)x(t)=A(t)∗b(t) it comes from: the product rule gives three terms, two of them combine into E∗(b−Ax)=E∗r, and the residual appears by itself. Then read every norm off a singular value decomposition: ‖(A∗A)−1‖=σn−2 is where the square comes from, and the only inequality used to finish is σ1‖x‖≥‖Ax‖=‖b‖cos⁡θ.

Proof. Write A(t)=A+tE, b(t)=b+tf and N(t)=A(t)∗A(t). Every entry of N(t) is a polynomial in t, so N is differentiable in the sense of Definition 16.6.1, and N(0)=A∗A is invertible by Corollary 11.4.4 (c). By Theorem 16.6.5, N(t) is invertible on an open interval around 0 and t↦N(t)−1 is differentiable there. On that interval rankA(t)=n, again by Corollary 11.4.4, so Theorem 11.4.2 has the unique solution x(t)=N(t)−1A(t)∗b(t), differentiable by Lemma 16.6.4. (Conjugation is applied entrywise and commutes with differentiation in the real variable t, so (A(t)∗)′=E∗.)

Differentiate the identity N(t)x(t)=A(t)∗b(t) at t=0 with Lemma 16.6.4. Since N′(0)=E∗A+A∗E, (E∗A+A∗E)x+A∗Ax′(0)=E∗b+A∗f. Move the first bracket across and collect the two terms carrying E∗: A∗Ax′(0)=E∗(b−Ax)−A∗(Ex)+A∗f=E∗r−A∗(Ex)+A∗f. Hence (∗)x′(0)=(A∗A)−1E∗r−(A∗A)−1A∗(Ex)+(A∗A)−1A∗f.

Now the two norms. Write A=UΣV∗ as in Theorem 13.8.1, with σ1≥⋯≥σn>0. As in the proof of Theorem 16.8.4, A∗A=Vdiag(σ12,…,σn2)V∗, so (A∗A)−1=Vdiag(σ1−2,…,σn−2)V∗,(A∗A)−1A∗=VΣ+U∗, where Σ+ is the n×m matrix with σ1−1,…,σn−1 on its diagonal — the second identity because diag(σi−2)Σ∗=Σ+. Unitary factors do not change singular values, rectangular ones included: for unitary U1,V1 of the right sizes, (U1MV1)∗(U1MV1)=V1∗(M∗M)V1 is unitarily similar to M∗M, so the two have the same eigenvalues and Definition 13.8.1 reads the same singular values off them. Hence by Theorem 16.3.3 (c), ‖(A∗A)−1‖=σn−2,‖(A∗A)−1A∗‖=σn−1. Applying these to (∗) with Theorem 16.3.2 (a), ‖x′(0)‖ ≤ ‖E‖‖r‖σn2+‖E‖‖x‖σn+‖f‖σn.

Divide by ‖x‖ and use ‖A‖=σ1 (Theorem 16.3.3 (c)) and κ2(A)=σ1/σn (Definition 16.8.1). The middle term becomes ‖E‖/σn=κ2(A)εA exactly. For the other two, note that σ1‖x‖≥‖Ax‖=‖b‖cos⁡θ, so ‖r‖σ1‖x‖≤‖b‖sin⁡θ‖b‖cos⁡θ=tan⁡θ,‖b‖σ1‖x‖≤1cos⁡θ. Therefore ‖E‖‖r‖σn2‖x‖=σ12σn2⋅‖E‖σ1⋅‖r‖σ1‖x‖≤κ2(A)2εAtan⁡θ,‖f‖σn‖x‖=σ1σn⋅‖f‖‖b‖⋅‖b‖σ1‖x‖≤κ2(A)εbcos⁡θ. Adding the three estimates gives the stated bound. This proves the theorem.

What is linearized, and what is not. The theorem itself is exact: it bounds a derivative, and no term has been discarded. What is an approximation is the use one makes of it. Reading it as

‖Δx‖‖x‖ ≲ [κ2(A)(1+1cos⁡θ)+κ2(A)2tan⁡θ]ε
(24.3.2)

for data perturbed by ‖ΔA‖≤ε‖A‖ and ‖Δb‖≤ε‖b‖ drops a remainder of size O(ε2), exactly as Theorem 16.8.3 (b) drops the factor 1/(1−r). For the ε≈10−16 of the floating-point model that remainder is invisible, and every statement below that carries a ≲ is a statement of this kind.

Two readings of the bound matter.

  • When the residual is zero, θ=0 and the bound is 2κ2(A)ε: the least-squares problem is exactly as sensitive as a square linear system with the same condition number. A square invertible A is always this case, and Theorem 16.8.3 is recovered.
  • When the residual is large, the term κ2(A)2tan⁡θ dominates the bound, and what it measures belongs to the problem: no algorithm can return an answer more accurate than data of that quality determine. This is the sentence Chapter 16 §08 promised, where the least-squares problem was said to have “a sensitivity that depends on κ2(A), on the residual ‖Ax+−b‖ and on the angle between b and col(A)”. Exercise (C1: The squared term is attained) exhibits data on which the κ2(A)2εAtan⁡θ term is attained exactly, so it is not an artifact of the estimates.

Quick check. Take m=n with A invertible. What does Eq. 24.3.1 give for θ, and what does Eq. 24.3.2 reduce to? Compare with Theorem 16.8.3.

Solution. For an invertible square A the system Az=b is consistent, so its least-squares solution has residual r=0 and Eq. 24.3.1 gives sin⁡θ=0, that is θ=0. Then cos⁡θ=1 and tan⁡θ=0, and Eq. 24.3.2 reads ‖Δx‖/‖x‖≲2κ(A)ε. That is Theorem 16.8.3 (a) and (b) added together, with the factor 1/(1−r) replaced by the O(ε2) that the linearization discards. The square case carries no κ2 at all.

24.3.2. Two routes, and the digits they lose

The problem is measured; now the two algorithms. Both are run in the arithmetic of Definition 24.1.1, with u the unit roundoff and γk=ku/(1−ku) the constant of Lemma 24.1.1.

The normal-equation route forms C=fl(A∗A) and d=fl(A∗b) entry by entry as inner products, then solves Cz=d. The matrix it hands to the solver need not be positive definite. The exact A∗A is: x∗A∗Ax=‖Ax‖2>0 for x≠0, the columns of A being independent. The computed C is Hermitian, only one triangle of it being formed, but its eigenvalues are those of A∗A displaced by the rounding, and the smallest of them, σn(A)2, can be displaced past 0 — Example (A matrix where one route survives and the other does not) below exhibits a C that comes out singular, on which the Cholesky factorization of Theorem 13.2.3 fails outright. When C is positive definite — which it is while the rounding stays below σn(A)2 — Cholesky, and the analysis Section 2 gives it, apply.

The cost is mn2 flops to form the product — there are 12n(n+1) entries to compute, each an inner product of length m costing 2m flops — plus 13n3 for the factorization (Proposition 24.2.3 (c)) and 2n2 for the two triangular solves. The QR route never forms that product: it computes a factorization A=QR by reflections (Theorem 11.8.4), applies Q∗ to b, and solves the triangular system Rx=Q∗b by back substitution, which Theorem 24.2.5 showed to be backward stable. Its cost is 2mn2−23n3 flops by a sum of the same kind as Proposition 24.2.3, which we do not write out: about twice the first when m≫n.

The rule of thumb of Theorem 24.1.3 says: forward relative error ≤ condition number × backward relative error. The two routes solve different problems, and that is the whole story. The first solves a square linear system whose matrix is A∗A, of condition number κ2(A)2 by Theorem 16.8.4. The second solves the least-squares problem itself, of sensitivity given by Theorem 24.3.1. Here is the comparison. Part (a) is Theorem 24.1.3 applied to the system A∗Ax=A∗b, except that here the right-hand side is perturbed as well, so we give the short direct argument instead of appealing to it.

Theorem 24.3.2 (The Normal Equations Lose Twice the Digits)

Let A∈Mm×n(F) have rank n≤m, let b≠0, let x be the least-squares solution and let θ<π/2 be as in Eq. 24.3.1. Work in the model of Definition 24.1.1, and suppose mu≤12.

  • (a) (Normal equations.) Suppose C=fl(A∗A) and d=fl(A∗b) are formed by inner products, and that Cz=d is then solved by a method that is backward stable in the sense of Definition 24.1.3, so that the computed x^ satisfies (C+ΔC)x^=d+Δd with ‖ΔC‖≤csu‖C‖ and ‖Δd‖≤csu‖d‖. Then there is a constant c, depending only on m, n and cs and of size O(mn), such that if cuκ2(A)2<1 then ‖x^−x‖‖x‖ ≤ cuκ2(A)2(1+1cos⁡θ)1−cuκ2(A)2. The bound carries κ2(A)2 even when the residual is zero.
  • (b) (A backward stable least-squares solver.) Suppose instead that x^ is the exact least-squares solution of (A+ΔA)z=b+Δb for some ΔA,Δb with ‖ΔA‖≤c′u‖A‖ and ‖Δb‖≤c′u‖b‖. Then, to first order in u as in Eq. 24.3.2, ‖x^−x‖‖x‖ ≲ c′u[κ2(A)(1+1cos⁡θ)+κ2(A)2tan⁡θ].

Idea. For (a), the two sources of error — forming the product, and solving the system — are both perturbations of the exact normal equations, and both are bounded by a constant times u‖A‖2 or u‖A‖‖b‖. Subtract the exact equations from the perturbed ones and multiply by (A∗A)−1, whose norm is σn−2: the two factors of σ1/σn appear there and nowhere else. The one nuisance is that the estimate produces ‖x^‖ rather than ‖x‖; subadditivity of the norm (Corollary 11.1.6) trades one for the other at the cost of the denominator, exactly as in Theorem 16.8.3 (b). For (b) there is nothing to do: the hypothesis says the computed answer is the exact answer to perturbed data, which is what Theorem 24.3.1 measures.

Proof. (a). We argue over R, the field in which Theorem 24.1.2 is stated; over C each complex multiplication and addition is a bounded number of real ones, and the same argument gives the same bound with a larger constant c. Write a1,…,an for the columns of A, so that (A∗A)ij=ai∗aj and (A∗b)i=ai∗b, each an inner product of length m. By Theorem 24.1.2, fl(ai∗aj)=(ai+Δa)∗aj with |Δa|≤γm|ai| entrywise, so |cij−ai∗aj|≤γm|ai|⊤|aj|≤γm‖ai‖‖aj‖, the last step by Cauchy–Schwarz (Theorem 11.1.5). Summing squares and using ‖M‖≤‖M‖F — true because ‖M‖F2=tr(M∗M) is the sum of the eigenvalues of M∗M, hence of the σi(M)2, while ‖M‖=σ1(M) by Theorem 16.3.3 (c) — ‖C−A∗A‖≤‖C−A∗A‖F≤γm(∑i‖ai‖2)=γm‖A‖F2≤nγm‖A‖2. The same argument on d gives ‖d−A∗b‖≤γm‖b‖‖A‖F≤nγm‖A‖‖b‖.

Now add the solver’s backward error. Put Δ=(C+ΔC)−A∗A and h=(d+Δd)−A∗b. Since ‖C‖≤(1+nγm)‖A‖2 and ‖d‖≤(1+nγm)‖A‖‖b‖, ‖Δ‖≤cu‖A‖2,‖h‖≤cu‖A‖‖b‖, with c=2nm+cs(1+2nm) serving, say, since the hypothesis mu≤12 gives γm≤2mu, and n≤n.

The exact solution satisfies A∗Ax=A∗b and the computed one satisfies (A∗A+Δ)x^=A∗b+h. Subtracting, A∗A(x^−x)=h−Δx^,‖x^−x‖≤σn−2(cu‖A‖‖b‖+cu‖A‖2‖x^‖), using ‖(A∗A)−1‖=σn−2 from the proof of Theorem 24.3.1. Divide by ‖x‖, write ρ=‖x^−x‖/‖x‖, and use σ1‖x‖≥‖b‖cos⁡θ together with ‖x^‖≤‖x‖(1+ρ): ρ ≤ cuκ2(A)2(1cos⁡θ+1+ρ). Since cuκ2(A)2<1 we may collect the ρ terms and divide, which gives the stated bound. Nothing in the argument used r, so it holds for θ=0 as it stands.

(b). By hypothesis x^=x(1) for the family of Theorem 24.3.1 with E=ΔA and f=Δb, and εA,εb≤c′u. The stated bound is Eq. 24.3.2 for that family. This proves the theorem.

In digits. A relative error of η means about log10⁡(1/η) correct decimal digits, and an arithmetic with unit roundoff u≈10−16 offers about 16 of them. Part (a) says the normal-equation route returns an answer with relative error about uκ2(A)2: it loses about 2log10⁡κ2(A) digits, whatever the residual. Part (b) says a backward stable least-squares solver returns an answer with relative error about uκ2(A) when the residual is small, and so loses about log10⁡κ2(A) digits.

The comparison Chapter 16 §08 left open has two halves, and only one of them is settled here. The half that is proved is the implication: a backward stable least-squares solver loses about log10⁡κ2(A) digits, while forming A∗A loses about twice that — and part (a), which carries no stability hypothesis at all, is unconditional.

The half that is not proved is that the reflection route of Chapter 11 §08 supplies such a solver. That is the accumulated statement of the remark after Theorem 24.3.3 below, which this book records with credit and does not prove; what Theorem 24.3.3 itself proves is the backward stability of one reflection. A further qualification is the content of the next warning.

Warning. The two-versus-one comparison is a small-residual statement, and the reason is not symmetric. For a large residual the bound in (b) also carries a κ2(A)2, through the term κ2(A)2tan⁡θ. The difference is where that square comes from. In (b) it is the sensitivity of the problem, certified by Theorem 24.3.1, and no method whatever can avoid it. In (a) it is manufactured by the algorithm: it is there when θ=0, where the problem’s own sensitivity is only κ2(A). So the honest form of the comparison is: a backward stable method loses what the problem costs; forming A∗A loses κ2(A) times more than that whenever tan⁡θ≲1/κ2(A), and never less.

Example (A matrix where one route survives and the other does not)

Let ε>0 and A=(11ε00ε),b=(12ε−ε). Find κ2(A), the exact least-squares solution and the residual. Then run both routes in the model with u=2−53, for ε=10−6 and for ε=10−9, and compare.

Solution. Exact data. A⊤A=(1+ε2111+ε2), which sends (1,1) to (2+ε2)(1,1) and (1,−1) to ε2(1,−1). So its eigenvalues are 2+ε2 and ε2, the singular values of A are 2+ε2 and ε, and κ2(A)=2+ε2ε. Also A(2,−1)=(2−1, 2ε, −ε)=b, so the system is consistent: the least-squares solution is x=(2,−1) exactly, the residual is r=0, and θ=0. By Theorem 24.3.1 the problem’s sensitivity is exactly 2κ2(A) — there is no κ22 in the problem at all.

ε=10−6. Here κ2(A)=1.4142136⋅106, so uκ2(A)=1.6⋅10−10 and uκ2(A)2=2.2⋅10−4. Forming the product rounds 1+ε2=1+10−12 to 1.0000000000010000889; the last four digits are the rounding, and they are a relative perturbation of about 10−4 in the difference ε2 that carries the small eigenvalue. Cholesky and the two triangular solves then return x^=(1.99983348134991, −0.99983348134991), a relative error of ‖x^−x‖/‖x‖=1.05⋅10−4 — about four correct digits out of sixteen, and within a factor of 2 of the bound uκ2(A)2=2.2⋅10−4. (Entry by entry the relative errors are 8.3⋅10−5 and 1.7⋅10−4; it is the 2-norm figure that the theorem bounds.) The reflection route returns (2,−1), every digit correct.

ε=10−9. Now κ2(A)=1.4142136⋅109 and uκ2(A)2=222, so part (a) promises nothing at all — and nothing is what it delivers. Since ε2=10−18 is below u, the computed product is C=fl(A⊤A)=(1111), a singular matrix: its Cholesky factorization (Theorem 13.2.3) fails at the second pivot, and the route cannot even be run. The reflection route again returns (2,−1).

The bound is an upper bound. For ε=10−9 the reflection route is entitled to lose log10⁡κ2(A)≈9 digits and in fact loses none: the answer is exactly representable and the arithmetic happens to reach it. Part (b) is a worst case over perturbations, as Theorem 16.8.3 was. Part (a) is an upper bound too, and it is not attained exactly either; what this example shows is that it is not a pessimistic one — the normal-equation route does lose its 2log10⁡κ2(A) digits here, to within a factor of 2 in the error.

Warning. Forming A∗A is not forbidden, it is limited. If κ2(A)=103 then uκ2(A)2≈10−10, and the normal equations return ten correct digits for half the arithmetic. The rule is quantitative, not moral: the route is safe exactly while uκ2(A)2 is small enough for the purpose, and it collapses — as Example (A matrix where one route survives and the other does not) shows — once κ2(A) approaches u−1/2≈108. What is never acceptable is forming the product without knowing which side of that threshold one is on.

24.3.3. Why the reflection route is the stable one

Part (b) above assumed a backward stable least-squares solver. That hypothesis has to be earned, and earning it is what Chapter 11 §08’s reflections are for. The claim to be supported is: applying a Householder reflection by the formula

Hwv=v−2⟨v,w⟩‖w‖2w
(24.3.3)

of Chapter 11 §08 — applying it, never forming the matrix — commits a backward error of size u, with no dependence on the conditioning of anything. Here is that statement, proved.

Theorem 24.3.3 (Backward Stability of One Reflection)

Work in the model of Definition 24.1.1 over R, and suppose (10m+16)u≤14. Let w∈Rm be non-zero and let H=Hw be the reflection of Definition 11.8.1, and suppose w and the input are stored exactly.

  • (a) For v∈Rm, let y^ be the vector computed from v and w by Eq. 24.3.3. Then y^=H(v+Δv),‖Δv‖2≤(10m+16)u‖v‖2.
  • (b) For A∈Mm×n(R), let B^ be the matrix whose columns are computed from those of A in this way. Then B^=H(A+ΔA),‖ΔA‖F≤(10m+16)u‖A‖F.

Idea. Three quantities are computed before anything is subtracted: ‖w‖2, the inner product ⟨v,w⟩, and their quotient β. Each is an inner product or a division, so Theorem 24.1.2 and Lemma 24.1.1 bound them at once, and the crude estimate |β|≤2‖v‖/‖w‖ — which is Cauchy–Schwarz and nothing more — keeps every error proportional to ‖v‖, not to ‖v‖/‖w‖. Then the forward error ‖y^−Hv‖ is converted into a backward error for free, because H is an isometry and its own inverse: Δv=H(y^−Hv) has exactly the same length. Part (b) is part (a) column by column, since the Frobenius norm adds the columns in squares.

Proof. (a). Write ν=‖w‖2, β=2⟨v,w⟩/ν2, so that Hv=v−βw, and abbreviate γk=ku/(1−ku). The hypothesis (10m+16)u≤14 gives in particular (m+2)u≤14, so γk≤43ku≤13 for every k≤m+2.

Step 1: the two inner products. The computed s=fl(w∗w) is a sum of m non-negative terms wi2, each carrying at most m rounding factors, so by Lemma 24.1.1 s=∑iwi2(1+θi) with |θi|≤γm; as every wi2≥0 this gives s=ν2(1+θ) with |θ|≤γm. By Theorem 24.1.2 the computed p=fl(v∗w) satisfies p=⟨v,w⟩+η with |η|≤γm|v|⊤|w|≤γm‖v‖ν, by Cauchy–Schwarz (Theorem 11.1.5).

Step 2: the coefficient. The computed β^ is (2p/s) times two rounding factors, so β^=(2p/s)(1+θ2) with |θ2|≤γ2, by Lemma 24.1.1. Writing 2p/s=(β+ζ)/(1+θ) with ζ=2η/ν2 and |ζ|≤2γm‖v‖/ν, |1+θ21+θ−1|≤γm+γ21−γm≤32(γm+γ2)≤2(m+2)u, using 1−γm≥23 and γk≤43ku; in particular the factor itself has modulus at most 2. Since |β|≤2‖v‖/ν by Cauchy–Schwarz, |β^−β|≤|β|⋅2(m+2)u+2|ζ|≤‖v‖ν(4(m+2)u+6mu)≤Ku‖v‖ν, with K=10m+8. In particular |β^|≤3‖v‖/ν, since Ku≤(10m+16)u≤14.

Step 3: the subtraction. Entry i is computed as y^i=(vi−β^wi(1+δi))(1+δi′) with |δi|,|δi′|≤u. Subtracting (Hv)i=vi−βwi and regrouping, y^i−(Hv)i=(vi−β^wi)δi′+(β−β^)wi−β^wiδi(1+δi′). Take 2-norms over i, one term at a time. The first is at most u(‖v‖+|β^|ν)≤4u‖v‖; the second is |β−β^|ν≤Ku‖v‖; the third is at most |β^|νu(1+u)≤4u‖v‖. Hence ‖y^−Hv‖2≤(K+8)u‖v‖2=(10m+16)u‖v‖2.

Step 4: forward to backward. Put Δv=H(y^−Hv). Then H(v+Δv)=Hv+H2(y^−Hv)=y^ by Proposition 11.8.2 (b), and ‖Δv‖2=‖y^−Hv‖2 because H is unitary (Proposition 11.8.2 (c)). This is (a).

(b). Apply (a) to each column aj, obtaining Δaj with ‖Δaj‖2≤(10m+16)u‖aj‖2, and let ΔA have these columns. Then B^=H(A+ΔA) column by column, and squaring and summing over j gives ‖ΔA‖F≤(10m+16)u‖A‖F. This proves the theorem.

The constants are crude on purpose; what matters is their shape. The bound is a multiple of u and of m, and of nothing else. No condition number appears, and none can: a reflection is an isometry, so it neither stretches nor shrinks, and there is no small quantity anywhere for a rounding error to be measured against.

Remark. What the accumulation says, and that we do not prove it. Running min(n,m−1) reflections as in Theorem 11.8.4, one obtains computed R^ and stored reflection vectors. The classical theorem — due to Wilkinson, and proved by inducting the argument above over the reflections while tracking how the perturbations compose — states that there is an exactly unitary Q~∈Mm(R), not in general the product of the computed reflections, with Q~R^=A+ΔA,‖ΔA‖F≤c(m,n)u‖A‖F, and that the resulting least-squares solution is the exact solution of a problem with data perturbed by O(u) — the hypothesis of Theorem 24.3.2 (b). This accumulated statement is not proved here, and nothing in this book depends on it: every theorem above either proves its own case or carries backward stability as a stated hypothesis. The induction is not deep, but it is long, and the honest thing is to say so.

24.3.4. What goes wrong with Gram–Schmidt

Chapter 11 §02 warned that “the classical process is numerically fragile” and promised that this chapter would say why the reflection route is the stable one. Half of the answer is Theorem 24.3.3. The other half is what the Gram–Schmidt recursion of Theorem 11.2.2 does instead.

The recursion subtracts from ak its components along the vectors already produced. When the columns are nearly dependent, what is left is a small difference of large quantities, and the leading digits cancel, exactly as in the subtraction of nearly equal numbers examined in Section 1. The computed qk is then a unit vector in a noticeably wrong direction, and, worse, the error is not random: it is inherited by every later step. The measured consequence is a loss of orthogonality: the computed Q^ satisfies Q^⊤Q^≠I by an amount that grows with κ2(A). The classical analyses, which we state with credit and do not prove here, say how fast:

  • for the classical process, ‖Q^⊤Q^−I‖ is of order uκ2(A)2 (Kielbasinski; Giraud, Langou and Rozloznik);
  • for the modified process, in which each new vector is projected against the qi one at a time as it is formed rather than all at once from the original ak, it is of order uκ2(A) (Bjorck);
  • for the reflection route it is of order u, independently of κ2(A), which is the content of Theorem 24.3.3.
Example (Three columns and three answers)

Let ε=10−6 and A=(111ε000ε0). Show that κ2(A)=3/ε+O(ε), then run the classical and the modified recursion in the model with u=2−53 and compare the inner products of the computed vectors.

Solution. The condition number. A⊤A=(1+ε21111+ε21111). Its characteristic polynomial factors as det(tI−A⊤A)=(t−ε2)(t2−(3+ε2)t+ε2), as one checks by expanding both sides. The quadratic has roots t± with t+t−=ε2 and t++t−=3+ε2, so t+=3+O(ε2) and t−=ε2/3+O(ε4). Hence σ1=3+O(ε2) and σ3=ε/3+O(ε3), and κ2(A)=3ε/3+O(ε)=3ε+O(ε)=3.000000⋅106. So uκ2(A)=3.3⋅10−10 and uκ2(A)2=1.0⋅10−3.

The computed vectors. Both recursions produce the same q1 and q2, with ⟨q1,q2⟩=6.3⋅10−11: that is the unavoidable uκ2(A), and it is already five to six digits worse than u, being larger by a factor of 5.7⋅105. The two differ at the third step, which is where the cancellation bites: classical:⟨q2,q3⟩=−8.89⋅10−5,modified:⟨q2,q3⟩=0. The classical figure is within a factor of 12 of uκ2(A)2=1.0⋅10−3; the modified figure is at the level of uκ2(A) or below. Two vectors at inner product 9⋅10−5 are at about 89.995 degrees to each other, and a basis that is orthonormal only to five digits is worth five digits in everything computed from it.

24.3.5. The sign in the reflection, quantified

Chapter 11 §08 chose w=x+α‖x‖e1 rather than w′=x−α‖x‖e1, where α is the phase of x1, and said: “Chapter 24 quantifies the loss; the summary here is that both signs are correct mathematics and only one is correct arithmetic.” Here is the quantity.

Take x∈Rm non-zero with x1>0, so α=1, and write x~=(x2,…,xm). Expanding as in Theorem 11.8.3,

‖w‖2=2‖x‖(‖x‖+x1),‖w′‖2=2‖x‖(‖x‖−x1),

and (‖x‖+x1)(‖x‖−x1)=‖x~‖2. Both vectors are built by the same two operations: compute ‖x‖, then add it to or subtract it from x1. The computed norm carries an error of absolute size about u‖x‖, and every other entry is copied from x exactly. So in both cases the computed vector is w+Δw with ‖Δw‖≈u‖x‖ — the same absolute error. What differs is what that error is measured against, because Hw depends on w only through the line it spans. Writing p=w/‖w‖ and q=(w+Δw)/‖w+Δw‖, Definition 11.8.1 gives Hw−Hw+Δw=−2(pp∗−qq∗), and ‖pp∗−qq∗‖≤‖p(p−q)∗‖+‖(p−q)q∗‖=2‖p−q‖≤8‖Δw‖‖w‖. For the last step, abbreviate s=Δw and split p−q=w(1‖w‖−1‖w+s‖)−s‖w+s‖. The second piece has norm ‖s‖/‖w+s‖, and the first has norm |‖w+s‖−‖w‖|/‖w+s‖, which is at most the same quantity by the reverse triangle inequality (Lemma 16.1.1); and ‖w+s‖≥‖w‖/2 as soon as ‖s‖≤‖w‖/2, which is certainly the case here, ‖s‖ being of size u‖x‖. So the computed reflection differs from the intended one by a small multiple of

u‖x‖‖w‖,where‖x‖‖w‖=‖x‖2(‖x‖+x1) ≤ 12.

The safe sign therefore never amplifies: its reflection is accurate to a small multiple of u, no matter what x is. The other sign amplifies by the factor

‖w‖‖w′‖=‖x‖+x1‖x‖−x1=‖x‖+x1‖x~‖,

which is unbounded: it blows up precisely as x approaches a positive multiple of e1, where ‖x~‖→0 and w′→0.

Example (The same vector, the two signs)

Let ε=10−8 and x=(1,ε,ε)∈R3. Predict the amplification factor for each sign, then apply each computed reflection to x in the model with u=2−53 and measure how flat the answer is.

Solution. Prediction. ‖x~‖=2ε=1.41⋅10−8 and ‖x‖=1+2ε2, so ‖x‖/‖w‖=0.5 for the safe sign, while ‖x‖‖w′‖=‖x‖2(‖x‖−1)=7.07⋅107,u‖x‖‖w′‖=7.9⋅10−9.

The arithmetic. The computed ‖x‖ is exactly 1: the true value exceeds 1 by ε2=10−16, which is below the unit roundoff, so the addition returns 1. Hence w^=(2,ε,ε),w^′=(0,ε,ε). The first is right to full relative accuracy in every entry. The second has lost its first entry altogether: it should be −10−16 and it is 0. Applying Eq. 24.3.3, Hw^x=(−1,0,0),Hw^′x=(1, −10−8, −10−8). The safe sign flattens x exactly: the two entries that were supposed to be annihilated are true zeros. The other sign leaves behind entries of size 10−8 beside a vector of norm 1 — a failure of 1.4⋅10−8 where 10−16 was available, and within a factor of 2 of the estimate u‖x‖/‖w′‖=7.9⋅10−9. Eight digits, thrown away by a sign.

For ε=10−6 and ε=10−4 the same computation leaves residues of 1.3⋅10−10 and 1.5⋅10−13, against estimates 7.9⋅10−11 and 7.9⋅10−13. The estimates fall by exactly 100 each time, as 1/‖x~‖ does; the residues fall by 112 and then by 825, because a residue depends on the actual rounding error committed in ‖x‖, which varies with the binary expansion of ‖x‖ and not only with its size. Over four orders of magnitude the estimate stays within a factor of 6 of the measurement, which is all an order-of-magnitude estimate promises.

Non-example by minimal change. Change one character of Example (The same vector, the two signs): take x=(−1,ε,ε) with ε=10−8. The arithmetic is unaltered — the computed ‖x‖ is again exactly 1 — and the rule of Theorem 11.8.3 still works: the phase of x1 is now α=−1, so w=x+α‖x‖e1=(−2,ε,ε), again with ‖x‖/‖w‖=0.5 and again flattening x to (1,0,0) exactly. What fails is the rule with the phase dropped, w=x+‖x‖e1: it returns (0,ε,ε), and that reflection leaves x with the same residue 1.4⋅10−8 as before. So the clause carrying the weight is not the plus sign but the phase α: what the rule requires is that α‖x‖ be added to x1 so that the first entry grows in modulus, never so that it cancels. Reading the plus sign literally is correct mathematics for every x and correct arithmetic only for x1>0.

Warning. The bad sign is not merely inaccurate; on one input it does not exist. If x=ce1 with c>0, then w′=0 and Definition 11.8.1 does not apply at all. That is not an accident of the arithmetic but the limit of the cancellation: the quantity whose leading digits are being destroyed is ‖x‖−x1, and on that input it is zero. An algorithm that is undefined at a point is inaccurate near it, and the sign rule of Theorem 11.8.3 is exactly the rule that keeps the point out of reach.

24.3.6. Exercises

A. Check your understanding

Exercise (A1)
  • (a) Define θ for a least-squares problem Az≈b with rankA=n, and say what θ=0 means about the system.
  • (b) State Theorem 24.3.1, and say which of its two terms survives when the residual is zero.
  • (c) Explain in one sentence why κ2(A)2 appears in the normal-equation route even for a consistent system, and why it need not appear in the reflection route.
  • (d) True or false: “a matrix with κ2(A)=103 should never be handled by the normal equations”. Justify your answer.
  • (e) What quantity does Theorem 24.3.3 bound, and which quantity does it not depend on?

Solution.

  • (a) By Eq. 24.3.1, θ∈[0,π/2] is determined by sin⁡θ=‖r‖/‖b‖ with r=b−Ax the residual, equivalently cos⁡θ=‖Ax‖/‖b‖; it is the angle between b and col(A). Then θ=0 says r=0, that is, the system Az=b is consistent.

  • (b) See Theorem 24.3.1: the relative sensitivity is at most κ2(A)(εA+εb/cos⁡θ)+κ2(A)2εAtan⁡θ. With r=0 we get tan⁡θ=0, and only the κ2(A) term survives, with cos⁡θ=1.

  • (c) The normal-equation route solves a different linear system, the one with matrix A∗A, whose condition number is κ2(A)2 by Theorem 16.8.4, and the rounding committed in forming that matrix is magnified by its condition number, not by A’s; the reflection route never forms the product, and κ2(R)=κ2(A).

  • (d) False. By Theorem 24.3.2 (a) the loss is about 2log10⁡κ2(A)=6 digits out of sixteen, which is usually ample; the route costs about half the arithmetic. The warning after Example (A matrix where one route survives and the other does not) states the rule quantitatively: what matters is whether uκ2(A)2 is small enough for the purpose.

  • (e) It bounds the backward error of applying one reflection by the formula Eq. 24.3.3: the computed output is the exact output for an input perturbed by at most (10m+16)u relatively. It does not depend on any condition number, only on m and u.

B. Practice

Exercise (B1: Reading the bound)

Let A∈M50×3(R) have κ2(A)=105, and suppose the data are accurate to ε=10−10 relatively. Using Eq. 24.3.2 with u≈10−16 where needed:

  • (a) Bound the relative error of the exact least-squares solution caused by the data error, when the residual is zero.
  • (b) Do the same when tan⁡θ=1.
  • (c) In case (b), how many digits does the normal-equation route lose on top of the data error, and how many does a backward stable method lose?

Solution.

  • (a) With θ=0, Eq. 24.3.2 gives 2κ2(A)ε=2⋅105⋅10−10=2⋅10−5: about five correct digits, and no algorithm can restore them.

  • (b) With tan⁡θ=1 we have cos⁡θ=1/2, so the bracket is κ2(1+2)+κ22=2.4⋅105+1010≈1010, and the bound is 1010⋅10−10=1. The data alone determine nothing: the κ22tan⁡θ term has swallowed the problem.

  • (c) The arithmetic contributes uκ2(A)2=10−16⋅1010=10−6 for the normal equations and u(κ2+κ22tan⁡θ)≈10−6 for a backward stable method as well, by Theorem 24.3.2. In this case the two lose the same six digits — because the κ22 is the problem’s, not the algorithm’s. Both are far below the 100 already lost to the data, so the choice of method is irrelevant here; it is for tan⁡θ small that it decides everything.

Exercise (B2: Where the product goes singular)

Let A=(11ε00ε) as in Example (A matrix where one route survives and the other does not), in the model with u=2−53.

  • (a) For which ε does fl(1+ε2)=1 hold, and what is fl(A⊤A) then?
  • (b) Express the threshold in (a) in terms of κ2(A) and u.
  • (c) Explain why the reflection route is untroubled at that threshold.

Solution.

  • (a) By Definition 24.1.1, fl(1+δ)=1 exactly when δ is at most the largest quantity that rounds away beside 1, which is u=2−53≈1.11⋅10−16. So fl(1+ε2)=1 for ε2≤u, that is ε≲1.05⋅10−8. Then every entry of fl(A⊤A) is 1 and the computed matrix is (1111), which is singular: the information distinguishing the two columns has been rounded away.

  • (b) From Example (A matrix where one route survives and the other does not), κ2(A)=2+ε2/ε≈2/ε, so ε2≤u says κ2(A)2≥2/u, that is uκ2(A)2≥2. The normal equations collapse exactly when the bound of Theorem 24.3.2 (a) exceeds 1, which is the same as saying that the route promises no correct digit.

  • (c) The reflection route never computes 1+ε2. It works with A itself, whose entries record ε and not ε2, and by Theorem 24.3.3 each reflection perturbs the data relatively by O(u). A relative perturbation of 10−16 in ε=10−9 leaves ε intact; a relative perturbation of 10−16 in 1 destroys ε2=10−18. Squaring is what moves the small quantity below the rounding level.

Exercise (B3: One reflection, by hand)

Let x=(3,0,4)∈R3.

  • (a) Compute w and w′ as in Theorem 11.8.3, and the two amplification factors ‖x‖/‖w‖ and ‖x‖/‖w′‖.
  • (b) Verify the identity ‖w‖2‖w′‖2=4‖x‖2‖x~‖2 on this example.
  • (c) Is the sign choice important for this x? Justify your answer.

Solution.

  • (a) ‖x‖=5 and x1=3>0, so α=1, w=(8,0,4) and w′=(−2,0,4). Then ‖w‖2=80 and ‖w′‖2=20, so ‖x‖‖w‖=580=54≈0.559,‖x‖‖w′‖=520=52≈1.118. Both are of order 1. (The general formulas agree: ‖w‖2=2⋅5⋅(5+3)=80 and ‖w′‖2=2⋅5⋅(5−3)=20.)

  • (b) x~=(0,4) has ‖x~‖2=16, and 4‖x‖2‖x~‖2=4⋅25⋅16=1600=80⋅20. The identity is ‖w‖2‖w′‖2=4‖x‖2(‖x‖+x1)(‖x‖−x1)=4‖x‖2‖x~‖2.

  • (c) No. The amplification factor of the bad sign is (‖x‖+x1)/‖x~‖=8/4=2, so the two choices differ by a factor of 2 in accuracy, which is nothing. The sign matters only when x is close to a multiple of e1, that is when ‖x~‖≪‖x‖; here ‖x~‖=4 is comparable with ‖x‖=5.

C. Going deeper

Exercise (C1: The squared term is attained)

Let ε,δ>0 and take A=(100ε00),b=(10δ),E=(000001),f=0.

  • (a) Compute κ2(A), the least-squares solution x, the residual r and tan⁡θ.
  • (b) Using (∗) in the proof of Theorem 24.3.1, compute x′(0) exactly.
  • (c) Hence show that the squared term of Theorem 24.3.1 is attained, in the sense that ‖x′(0)‖/‖x‖ equals κ2(A)2εAtan⁡θ exactly, and explain what this says about any algorithm for this problem.

Solution.

  • (a) A⊤A=diag(1,ε2), so the singular values are 1 and ε and κ2(A)=1/ε by the rectangular clause of Definition 16.8.1. The normal equations diag(1,ε2)x=A⊤b=(1,0) give x=(1,0). Then Ax=(1,0,0), so r=b−Ax=(0,0,δ) and, by Eq. 24.3.1, tan⁡θ=‖r‖‖Ax‖=δ. Also ‖E‖=1=‖A‖, so εA=1, and εb=0.

  • (b) The three terms of (∗). First, E⊤r=e2(e3⊤r)=δe2, and (A⊤A)−1=diag(1,ε−2), so the first term is (δ/ε2)e2. Second, Ex=e3(e2⊤x)=0 because x2=0, so the second term vanishes. Third, f=0. Hence x′(0)=(0,δε2).

  • (c) ‖x‖=1 and ‖x′(0)‖=δ/ε2, while κ2(A)2εAtan⁡θ=1ε2⋅1⋅δ=δε2. The two agree exactly: the squared term is attained. The bound as a whole is not, and the reason is that the other two terms are non-negative — here the first of them contributes a further κ2(A)εA=1/ε, so the bound exceeds ‖x′(0)‖/‖x‖ by exactly that much. It is the squared term that matters, and what it says is that the sensitivity is a property of the data (A,b) alone: a perturbation of A of relative size εA really does move the exact answer by κ2(A)2tan⁡θεA relatively, so no algorithm, however stable, can return an answer better than that from data known only to within εA. Compare Theorem 24.3.2 (b): a backward stable method achieves this and no more.

Exercise (C2: Why the residual has to appear)

Let A∈Mm×n(F) have rank n, and let x+=A+b be the least-squares solution, where A+ is the pseudoinverse of Definition 13.11.1.

  • (a) Prove that A+=(A∗A)−1A∗ when rankA=n, and deduce ‖A+‖=1/σn(A).
  • (b) Deduce from (∗) in the proof of Theorem 24.3.1 that if E=0 — only b is perturbed — then no κ2(A)2 term can appear, whatever the residual.
  • (c) Explain, in one or two sentences, why perturbing A is different: which term of (∗) carries the residual, and why it cannot be present when E=0.

Solution.

  • (a) Write A=UΣV∗ (Theorem 13.8.1). Since rankA=n, σ1,…,σn>0, so Σ+ of Definition 13.11.1 has σi−1 on its diagonal and A+=VΣ+U∗. On the other hand A∗A=V(Σ∗Σ)V∗=Vdiag(σi2)V∗, so (A∗A)−1A∗=Vdiag(σi−2)V∗VΣ∗U∗=V(diag(σi−2)Σ∗)U∗=VΣ+U∗=A+, because diag(σi−2)Σ∗ is the n×m matrix with entries σi−2σi=σi−1 on the diagonal and zeros elsewhere. Unitary factors leave singular values alone — (VΣ+U∗)∗(VΣ+U∗)=U(Σ+∗Σ+)U∗ is unitarily similar to Σ+∗Σ+, so the two have the same eigenvalues and Definition 13.8.1 reads the same singular values off them — so ‖A+‖=‖Σ+‖=maxiσi−1=1/σn by Theorem 16.3.3 (c).

  • (b) With E=0, (∗) reduces to x′(0)=A+f, so by (a) ‖x′(0)‖‖x‖≤‖f‖σn‖x‖=κ2(A)εb‖b‖σ1‖x‖≤κ2(A)εbcos⁡θ, a single factor of κ2(A) however large ‖r‖ is. (The residual enters only through 1/cos⁡θ, which is bounded as long as θ is bounded away from π/2.)

  • (c) The residual sits in the term (A∗A)−1E∗r, and that is the only term with (A∗A)−1 not paired with an A∗ — which is exactly why it carries σn−2 rather than σn−1. It is proportional to E, so it vanishes when E=0. Perturbing b tilts the target inside a fixed column space; perturbing A tilts the column space itself, and the residual is the lever arm by which that tilt moves the answer.

Exercise (C3: A reflection applied to a matrix)

Let H=Hw be a Householder reflection in Rm and let A∈Mm×n(R).

  • (a) Using Theorem 24.3.3 (b) and ‖M‖≤‖M‖F≤n‖M‖ for M∈Mm×n, show that the computed B^ satisfies ‖B^−HA‖≤(10m+16)nu‖A‖.
  • (b) Deduce that σi(B^) differs from σi(A) by at most (10m+16)nu‖A‖ for every i. Hint: Chapter 20 §10 or Chapter 17 §09 bounds the perturbation of singular values by the norm of the perturbation.
  • (c) Explain why the corresponding statement is false for the classical Gram–Schmidt process, citing Example (Three columns and three answers).

Solution.

  • (a) By Theorem 24.3.3 (b), B^−HA=HΔA with ‖ΔA‖F≤(10m+16)u‖A‖F. Since H is unitary (Proposition 11.8.2 (c)) it leaves the 2-norm unchanged, so ‖B^−HA‖=‖ΔA‖≤‖ΔA‖F≤(10m+16)u‖A‖F≤(10m+16)nu‖A‖.

  • (b) HA has the same singular values as A: (HA)∗(HA)=A∗H∗HA=A∗A, so Definition 13.8.1 reads the same list off the same matrix. Weyl’s inequality for singular values (Theorem 17.9.4 with j=1, or Corollary 17.9.5 directly) gives |σi(B^)−σi(HA)|≤‖B^−HA‖ for every i, and the right-hand side is bounded in (a).

  • (c) The Gram–Schmidt recursion of Theorem 11.2.2 does not apply a unitary matrix to A; it builds a matrix Q^ out of A and hopes it is unitary. Example (Three columns and three answers) measures the damage: for κ2(A)=3⋅106 the computed vectors have inner products of size 9⋅10−5, so Q^ is unitary only to five digits, and ‖Q^⊤Q^−I‖ exceeds u by eleven orders of magnitude on that one example. (That it does so at the rate uκ2(A)2 in general is the classical estimate quoted above, which this book does not prove.) Any conclusion drawn from “unitary factors leave singular values alone” then inherits that error instead of none. The reflection route wins because the unitary matrix is never in question: it is exactly unitary by construction, and only its input is perturbed.

Found a typo or a mistake? Report it, or read this page’s source

The text of this book is licensed under CC BY-NC-SA 4.0.