Unit 9, lesson 47

Residuals, Forward Error and Backward Error

Why a small residual need not mean an accurate solution, how forward and backward error answer different questions, how the condition number links them, and what backward stability and numerical rank mean.

  • Video 47
  • Size, Conditioning and Error

The proposed solution x^=(1,1)\hat{x} = (1, 1) of diag⁡(1,10−3) x=(1,0)\operatorname{diag}(1, 10^{-3})\,x = (1, 0) misses the right-hand side by only 10−310^{-3}, yet the true solution is (1,0)(1, 0), so the proposal is wrong by 100100 percent. How can both statements be true? This lesson separates the residual, the forward error and the backward error, which answer different questions, proves the bound that connects them through the condition number, and explains what backward stability promises and what it cannot. It also separates exact rank from numerical rank and shows that a tiny determinant does not by itself signal ill-conditioning. Throughout, F\mathbb{F} is R\mathbb{R} or C\mathbb{C}, a tuple such as (1,0)(1, 0) stands for a column vector, and every error is measured in a declared vector norm with its induced matrix norm, usually the Euclidean one.

Key terms

Residual and forward error

Definition Let A∈Fm×nA \in \mathbb{F}^{m \times n} and b∈Fmb \in \mathbb{F}^m, and let x^∈Fn\hat{x} \in \mathbb{F}^n be a proposed solution of Ax=bAx = b. The residual of x^\hat{x} is

r=b−Ax^∈Fm.r = b - A\hat{x} \in \mathbb{F}^m.

It measures the mismatch in the equation, in the output space, and it can be computed from the data without knowing any exact solution. In exact arithmetic r=0r = 0 exactly when x^\hat{x} solves the system. For b≠0b \ne 0 the relative residual is ∥r∥/∥b∥\lVert r \rVert / \lVert b \rVert. Now let AA be square and invertible and b≠0b \ne 0, so that the exact solution x=A−1bx = A^{-1}b is nonzero. The forward error of x^\hat{x} is x^−x\hat{x} - x, measured absolutely by ∥x^−x∥\lVert \hat{x} - x \rVert or relatively by

∥x^−x∥∥x∥.\frac{\lVert \hat{x} - x \rVert}{\lVert x \rVert}.

The forward error lives in the input space, and it usually cannot be computed, because xx is unknown. A residual and an error are different kinds of quantity, with different units in general, so they should not be compared as bare numbers without a sensitivity relation. A residual computed in floating-point arithmetic also carries its own rounding error, so a tiny computed residual has to be read together with that error.

In plain words The residual asks how badly the proposed answer fails the equation. The forward error asks how far the proposed answer is from the true one. The first can be checked directly, and the second usually cannot.

Example Let A=diag⁡(1,10−3)A = \operatorname{diag}(1, 10^{-3}), b=(1,0)b = (1, 0) and x^=(1,1)\hat{x} = (1, 1). Then Ax^=(1,10−3)A\hat{x} = (1, 10^{-3}), so r=(0,−10−3)r = (0, -10^{-3}) and the relative residual is 10−310^{-3}. The exact solution is x=(1,0)x = (1, 0), so the forward error is (0,1)(0, 1) and the relative forward error is 11. The matrix compresses the second input direction by the factor 10−310^{-3}, so a large error in that direction produces only a small mismatch in the output.

Backward error

Definition The backward error of a proposed solution x^\hat{x} is the size of the smallest change of the data, within a stated class of allowed changes, that makes x^\hat{x} an exact solution. The class and the way changes are measured must be stated, because different models give different numbers.

In the right-hand-side model, AA stays fixed and we require Ax^=b+δbA\hat{x} = b + \delta b. The only such change is δb=−r\delta b = -r, so the backward error is ∥r∥\lVert r \rVert, and relative to b≠0b \ne 0 it equals the relative residual ∥r∥/∥b∥\lVert r \rVert / \lVert b \rVert.

In the matrix model with the Euclidean norm, bb stays fixed, x^≠0\hat{x} \ne 0, and we require (A+δA)x^=b(A + \delta A)\hat{x} = b, that is δA x^=r\delta A\,\hat{x} = r. Every such δA\delta A has ∥δA∥2≥∥r∥2/∥x^∥2\lVert \delta A \rVert_2 \ge \lVert r \rVert_2 / \lVert \hat{x} \rVert_2, because ∥r∥2≤∥δA∥2∥x^∥2\lVert r \rVert_2 \le \lVert \delta A \rVert_2 \lVert \hat{x} \rVert_2. The rank-one matrix

δA=r x^∗x^∗x^\delta A = \frac{r\,\hat{x}^{*}}{\hat{x}^{*}\hat{x}}

satisfies δA x^=r\delta A\,\hat{x} = r and has ∥δA∥2=∥r∥2/∥x^∥2\lVert \delta A \rVert_2 = \lVert r \rVert_2 / \lVert \hat{x} \rVert_2, so it attains the minimum. Relative to ∥A∥2\lVert A \rVert_2 the backward error is ∥r∥2/(∥A∥2∥x^∥2)\lVert r \rVert_2 / (\lVert A \rVert_2 \lVert \hat{x} \rVert_2), which has a different denominator from the first model. If x^=0\hat{x} = 0 and r≠0r \ne 0, no change of AA alone can help, since every matrix sends 00 to 00. Allowing changes of both AA and bb, or bounding each entry separately, defines still other backward errors.

In plain words Backward error turns the question around. Instead of asking how wrong the answer is, it asks how little the problem would have to change for the answer to be exactly right.

Example With the data of the previous example, x^=(1,1)\hat{x} = (1, 1) exactly solves Ax=(1,10−3)Ax = (1, 10^{-3}), a right-hand side that differs from bb by 10−310^{-3}. So the relative backward error in the right-hand-side model is 10−310^{-3}. In the matrix model the minimal change and the changed matrix are

δA=12[00−10−3−10−3],A+δA=[10−5⋅10−45⋅10−4],\begin{gathered} \delta A = \frac{1}{2}\begin{bmatrix} 0 & 0 \\ -10^{-3} & -10^{-3} \end{bmatrix}, \\[0.4em] A + \delta A = \begin{bmatrix} 1 & 0 \\ -5 \cdot 10^{-4} & 5 \cdot 10^{-4} \end{bmatrix}, \end{gathered}

and indeed (A+δA)(1,1)=(1,0)=b(A + \delta A)(1, 1) = (1, 0) = b. Here ∥δA∥2=10−3/2≈7.1⋅10−4\lVert \delta A \rVert_2 = 10^{-3}/\sqrt{2} \approx 7.1 \cdot 10^{-4}, while ∥A∥2=1\lVert A \rVert_2 = 1. In both models x^\hat{x} exactly solves a very nearby problem, although its forward error is 100100 percent.

Residual bound on the forward error

Definition Let A∈Fn×nA \in \mathbb{F}^{n \times n} be invertible, let b≠0b \ne 0 and x=A−1bx = A^{-1}b, and let x^\hat{x} have residual r=b−Ax^r = b - A\hat{x}. In any vector norm on Fn\mathbb{F}^n with its induced matrix norm and condition number κ(A)=∥A∥ ∥A−1∥\kappa(A) = \lVert A \rVert \, \lVert A^{-1} \rVert,

∥x^−x∥∥x∥≤κ(A) ∥r∥∥b∥,∥x^−x∥∥x∥≥1κ(A) ∥r∥∥b∥.\begin{gathered} \frac{\lVert \hat{x} - x \rVert}{\lVert x \rVert} \le \kappa(A) \, \frac{\lVert r \rVert}{\lVert b \rVert}, \\[0.4em] \frac{\lVert \hat{x} - x \rVert}{\lVert x \rVert} \ge \frac{1}{\kappa(A)} \, \frac{\lVert r \rVert}{\lVert b \rVert}. \end{gathered}

Subtracting Ax=bAx = b from Ax^=b−rA\hat{x} = b - r gives A(x^−x)=−rA(\hat{x} - x) = -r, so x^−x=−A−1r\hat{x} - x = -A^{-1}r and ∥x^−x∥≤∥A−1∥ ∥r∥\lVert \hat{x} - x \rVert \le \lVert A^{-1} \rVert \, \lVert r \rVert. Dividing by ∥x∥\lVert x \rVert and using ∥b∥≤∥A∥ ∥x∥\lVert b \rVert \le \lVert A \rVert \, \lVert x \rVert gives the upper bound. For the lower bound, ∥r∥=∥A(x^−x)∥≤∥A∥ ∥x^−x∥\lVert r \rVert = \lVert A(\hat{x} - x) \rVert \le \lVert A \rVert \, \lVert \hat{x} - x \rVert and ∥x∥=∥A−1b∥≤∥A−1∥ ∥b∥\lVert x \rVert = \lVert A^{-1}b \rVert \le \lVert A^{-1} \rVert \, \lVert b \rVert. Multiplying ∥x^−x∥≥∥r∥/∥A∥\lVert \hat{x} - x \rVert \ge \lVert r \rVert / \lVert A \rVert by 1/∥x∥≥1/(∥A−1∥ ∥b∥)1/\lVert x \rVert \ge 1/(\lVert A^{-1} \rVert \, \lVert b \rVert) gives it. The relative residual is the relative right-hand-side backward error, so in this model the relative forward error is at most the condition number times the relative backward error. In the Euclidean norm both bounds are attained for suitable bb and x^\hat{x}, but for a particular x^\hat{x} the error can lie anywhere between them. The proof uses A−1A^{-1}, so it does not apply to a singular system.

In plain words Multiplying the relative residual by κ(A)\kappa(A) gives a ceiling for the relative error, and dividing by κ(A)\kappa(A) gives a floor. The true error lies somewhere between them. So a small residual guarantees a small error only when the ceiling is small too, and the larger the condition number, the smaller the residual has to be.

Example In the first example κ2(A)=1000\kappa_2(A) = 1000 and the relative residual is 10−310^{-3}, so the upper bound is 11, and the actual relative error 11 attains it. For the same AA and bb, the proposal x^=(1−10−4,0)\hat{x} = (1 - 10^{-4}, 0) has r=(10−4,0)r = (10^{-4}, 0), so its relative residual is 10−410^{-4}, and its relative forward error is also 10−410^{-4}. The two bounds give the range from 10−710^{-7} to 10−110^{-1}. The upper bound is valid but far from the truth, because this error lies along the direction that AA does not compress.

Ill-conditioned system

Definition Let A∈Fn×nA \in \mathbb{F}^{n \times n} be invertible, with a declared norm. The system Ax=bAx = b, with AA fixed and bb subject to error, is ill-conditioned when κ(A)\kappa(A) is large, so that, for some right-hand sides, small relative changes in bb can cause relative changes in xx up to κ(A)\kappa(A) times larger. There is no universal threshold. If the data carry relative errors up to η\eta, solutions consistent with the data can differ from xx by relative amounts up to κ(A) η\kappa(A)\,\eta, and for some right-hand sides and perturbations that worst case is reached. When κ(A) η\kappa(A)\,\eta is near 11 or larger, the bound no longer guarantees even one correct digit. Ill-conditioning belongs to the problem, its norm and its error model. No algorithm removes it, although a poor algorithm can add errors of its own.

The size of the determinant is not a test of conditioning. Writing A=UΣV∗A = U\Sigma V^{*} with unitary UU and VV, whose determinants have absolute value 11, gives

∣det⁡A∣=σ1σ2⋯σn,κ2(A)=σ1σn.\begin{gathered} \lvert \det A \rvert = \sigma_1 \sigma_2 \cdots \sigma_n, \\[0.4em] \kappa_2(A) = \frac{\sigma_1}{\sigma_n}. \end{gathered}

In absolute value the determinant is the product of the singular values, while the condition number is a ratio of two of them. Scaling AA by c≠0c \ne 0 multiplies the determinant by cnc^n and leaves the condition number unchanged.

In plain words An ill-conditioned system is one whose data cannot pin down the answer to the accuracy one might expect. What matters is how unevenly the matrix stretches different directions, not how small its entries or its determinant are.

Example For ε=10−6\varepsilon = 10^{-6} the matrix εI2\varepsilon I_2 has determinant 10−1210^{-12}, but κ2(εI2)=1\kappa_2(\varepsilon I_2) = 1. Every relative change in bb gives the same relative change in x=106 bx = 10^{6}\,b, although absolute changes are multiplied by 10610^{6}. In the other direction, diag⁡(103,10−3)\operatorname{diag}(10^{3}, 10^{-3}) has determinant 11 and κ2=106\kappa_2 = 10^{6}, so a relative error of 10−810^{-8} in bb can produce a relative error of 10−210^{-2} in xx.

Backward stability

Definition The floating-point rounding model describes arithmetic with a unit roundoff uu. A real number yy in the normal range is stored as fl⁡(y)=y(1+δ)\operatorname{fl}(y) = y(1 + \delta) with ∣δ∣≤u\lvert \delta \rvert \le u, and each basic operation ∘\circ, one of ++, −-, ×\times and ÷\div, applied to stored numbers ss and tt returns

fl⁡(s∘t)=(s∘t)(1+δ),∣δ∣≤u.\operatorname{fl}(s \circ t) = (s \circ t)(1 + \delta), \qquad \lvert \delta \rvert \le u.

Overflow and underflow are excluded from this simple model. Rounding to nearest with dd significant decimal digits gives u=12⋅101−du = \tfrac{1}{2} \cdot 10^{1 - d}, and IEEE double precision has u=2−53≈1.1⋅10−16u = 2^{-53} \approx 1.1 \cdot 10^{-16}.

An algorithm for square systems Ax=bAx = b is backward stable, normwise and under this model, if for every input it returns a vector x^\hat{x} that exactly solves a nearby system

(A+δA) x^=b+δb(A + \delta A)\,\hat{x} = b + \delta b

with ∥δA∥≤cnu∥A∥\lVert \delta A \rVert \le c_n u \lVert A \rVert and ∥δb∥≤cnu∥b∥\lVert \delta b \rVert \le c_n u \lVert b \rVert, where cnc_n is a modest constant that depends only on the dimension. If AA is invertible, b≠0b \ne 0 and x=A−1bx = A^{-1}b is the exact solution, combining this with conditioning gives

∥x^−x∥∥x∥≤2 κ(A) cnu1−κ(A) cnuwhenever κ(A) cnu<1,\begin{gathered} \frac{\lVert \hat{x} - x \rVert}{\lVert x \rVert} \le \frac{2\,\kappa(A)\,c_n u}{1 - \kappa(A)\,c_n u} \\[0.4em] \text{whenever } \kappa(A)\,c_n u < 1, \end{gathered}

which follows from A(x^−x)=δb−δA x^A(\hat{x} - x) = \delta b - \delta A\,\hat{x}, the inequality ∥x^∥≤∥x∥+∥x^−x∥\lVert \hat{x} \rVert \le \lVert x \rVert + \lVert \hat{x} - x \rVert and ∥b∥≤∥A∥ ∥x∥\lVert b \rVert \le \lVert A \rVert \, \lVert x \rVert. So backward stability guarantees a small forward error only when κ(A) cnu\kappa(A)\,c_n u is small. It controls the error that the algorithm adds, while the condition number decides what that error does to the answer. Proving that a whole algorithm is backward stable requires bounding every rounded operation it performs. A small residual in one example proves nothing of the kind.

In plain words Every arithmetic step may be off by a tiny relative amount. A backward stable method promises that its answer is the exact answer to a problem that differs from yours by a modest multiple of that tiny amount. It cannot promise more accuracy than the problem itself allows.

Example With four significant digits, u=12⋅10−3=5⋅10−4u = \tfrac{1}{2} \cdot 10^{-3} = 5 \cdot 10^{-4}. Solving 3x=23x = 2 by one division gives x^=fl⁡(2/3)=0.6667\hat{x} = \operatorname{fl}(2/3) = 0.6667, with relative error 5⋅10−5≤u5 \cdot 10^{-5} \le u. Since 3⋅0.6667=2.00013 \cdot 0.6667 = 2.0001, the computed value is the exact solution of 3x=2.00013x = 2.0001, whose right-hand side differs from 22 by the relative amount 5⋅10−55 \cdot 10^{-5}. In general, for a≠0a \ne 0, the computed fl⁡(b/a)=(b/a)(1+δ)\operatorname{fl}(b/a) = (b/a)(1 + \delta) exactly solves ax=b(1+δ)ax = b(1 + \delta), so one rounded division is backward stable with c1=1c_1 = 1. Because κ(3)=1\kappa(3) = 1, it is also accurate in the forward sense.

Numerical rank

Definition Let A∈Fm×nA \in \mathbb{F}^{m \times n} have singular values σ1≥⋯≥σp≥0\sigma_1 \ge \cdots \ge \sigma_p \ge 0, where p=min⁡(m,n)p = \min(m, n). Its exact rank is the number of nonzero singular values, counted with no tolerance. For a tolerance τ>0\tau > 0, its numerical rank is the number of singular values greater than τ\tau. By the Eckart-Young theorem in the spectral norm, this is the smallest rank of a matrix within spectral distance τ\tau of AA,

min⁡{ rank⁡B:∥A−B∥2≤τ }.\min \{\, \operatorname{rank} B : \lVert A - B \rVert_2 \le \tau \,\}.

If exactly kk singular values exceed τ\tau, the truncated SVD AkA_k has rank kk and ∥A−Ak∥2=σk+1≤τ\lVert A - A_k \rVert_2 = \sigma_{k+1} \le \tau, with σp+1\sigma_{p+1} read as 00, while every BB of rank less than kk has ∥A−B∥2≥σk>τ\lVert A - B \rVert_2 \ge \sigma_k > \tau. The tolerance has to come from the problem, for example from the size of the measurement errors in AA or from the rounding errors of the arithmetic, not from a wish for tidy output. It is an absolute size in the units of AA, so rescaling AA without rescaling τ\tau can change the count. Replacing AA by a matrix of lower rank also changes the problem. It can make a solution less sensitive to noise, but the reduced model no longer represents every direction of AA.

In plain words Exact rank asks whether a direction is crushed to exactly zero. Numerical rank asks whether it is crushed below the level at which the data can be trusted.

Example The matrix with columns (1,1)(1, 1) and (10−3,−10−3)(10^{-3}, -10^{-3}) has orthogonal columns, so its singular values are their lengths 2\sqrt{2} and 2⋅10−3≈1.4⋅10−3\sqrt{2} \cdot 10^{-3} \approx 1.4 \cdot 10^{-3}, and its exact rank is 22. If the matrix is known only to within 10−210^{-2} in spectral norm, the tolerance τ=10−2\tau = 10^{-2} gives numerical rank 11. Indeed the rank-one matrix with columns (1,1)(1, 1) and (0,0)(0, 0) lies at spectral distance 2⋅10−3\sqrt{2} \cdot 10^{-3}, well inside that uncertainty. If the matrix is accurate to 10−610^{-6}, the tolerance τ=10−6\tau = 10^{-6} gives numerical rank 22, and both directions are resolved.

Check yourself

  1. Let A=diag⁡(2,1100)A = \operatorname{diag}(2, \tfrac{1}{100}), b=(2,0)b = (2, 0) and x^=(1,12)\hat{x} = (1, \tfrac{1}{2}). Find the residual, the relative residual, the relative forward error and κ2(A)\kappa_2(A), and compare the error with the upper bound from the residual.
Show the answer

The product is Ax^=(2,1200)A\hat{x} = (2, \tfrac{1}{200}), so r=(0,−1200)r = (0, -\tfrac{1}{200}) and the relative residual is 1200/2=1400\tfrac{1}{200} / 2 = \tfrac{1}{400}. The exact solution is x=(1,0)x = (1, 0), so the forward error is (0,12)(0, \tfrac{1}{2}) and the relative forward error is 12\tfrac{1}{2}. The singular values are 22 and 1100\tfrac{1}{100}, so κ2(A)=200\kappa_2(A) = 200, and the upper bound is 200⋅1400=12200 \cdot \tfrac{1}{400} = \tfrac{1}{2}. The bound is attained. The relative right-hand-side backward error is only 1400\tfrac{1}{400}, yet the answer is off by 5050 percent.

  1. Let A=diag⁡(1,10−3)A = \operatorname{diag}(1, 10^{-3}) and b=(0,10−3)b = (0, 10^{-3}), and take x^=(10−3,1)\hat{x} = (10^{-3}, 1). Compute the relative residual and the relative forward error. Does a large residual prove that an answer is poor?
Show the answer

The exact solution is x=(0,1)x = (0, 1). The product is Ax^=(10−3,10−3)A\hat{x} = (10^{-3}, 10^{-3}), so r=(−10−3,0)r = (-10^{-3}, 0). Since ∥b∥2=10−3\lVert b \rVert_2 = 10^{-3}, the relative residual is 11. The forward error is (10−3,0)(10^{-3}, 0), so the relative forward error is 10−310^{-3}, and the lower bound 11000⋅1\tfrac{1}{1000} \cdot 1 is attained.

So a large residual does not prove that an answer is poor. Here a residual of 100100 percent sits next to an error of 0.10.1 percent. The right-hand side is small because the exact solution lies along the direction that AA compresses, while the error points along the direction that AA leaves alone. The answer is accurate in the forward sense, but its relative right-hand-side backward error is large. Which one matters depends on the question being asked.

  1. Let A=10−4I3A = 10^{-4} I_3. Find det⁡A\det A and κ2(A)\kappa_2(A). Is the system Ax=bAx = b ill-conditioned? Find the numerical rank of AA for the tolerances 10−610^{-6} and 10−310^{-3}.
Show the answer

The determinant is (10−4)3=10−12(10^{-4})^3 = 10^{-12}. All three singular values equal 10−410^{-4}, so κ2(A)=1\kappa_2(A) = 1 and the system is perfectly conditioned. A relative change in bb produces the same relative change in x=104 bx = 10^{4}\,b, although absolute changes grow by the factor 10410^{4}. The tiny determinant says nothing about conditioning.

For τ=10−6\tau = 10^{-6} all three singular values exceed the tolerance, so the numerical rank is 33. For τ=10−3\tau = 10^{-3} none does, so the numerical rank is 00. The zero matrix lies within spectral distance 10−410^{-4} of AA, so if AA is known only to within 10−310^{-3} in spectral norm, the data cannot be told apart from zero. That is a statement about absolute size in the units of AA, not about conditioning.

How this lesson connects

It also uses rounding a number to a fixed number of significant digits.