24.1  Floating Point and Backward Error

Chapter 16 ended with a number and a warning. The number was κ(A), which bounds how much a relative error in the data can be magnified on the way to the answer. The warning was that κ says nothing about arithmetic: it “describes a problem”, and an error bound of its shape “only becomes a statement about a computation once one knows how large a perturbation the computation itself introduces”. That chapter closed the door with a sentence we now have to walk through: “Conditioning bounds what any method can promise; whether a given method keeps that promise is stability, and it is Chapter 24’s subject.”

This section builds the two things that were missing. First a model of machine arithmetic — an assumption, stated plainly as one, because floating-point arithmetic is not a theorem of linear algebra. Then the vocabulary that turns the model into verdicts about algorithms: forward error, backward error, and stability.

24.1.1. Two answers to one question

Chapter 16 §08 left a small experiment on the reader’s desk. The system was 10−15x1+x2=1,x1+x2=2, whose coefficient matrix has κ∞<5: by every measure of Chapter 16 this problem is as well behaved as a problem can be, and its exact solution is (1,1) to fourteen places. Eliminating x1 with the first equation as the pivot row, and rounding to twelve significant decimal digits at every step, returns (0,1). Exchanging the two equations first, and rounding in exactly the same way, returns (1,1).

Two algorithms, one problem, one arithmetic, and one of the two answers has no correct digit in it. Nothing in Chapter 16 can tell the two apart, because κ never mentions a method. Section 2 works that example in the model below and says exactly what the exchange achieved. This section builds the language it will be said in.

24.1.2. A model of machine arithmetic

A machine holds finitely many numbers. It cannot hold 1/3, it cannot hold 2, and between any two numbers it does hold there are infinitely many it does not. So the result of an arithmetic operation on two stored numbers is usually not a stored number, and the machine must replace it by a neighbor.

We could try to describe which numbers a particular machine stores and exactly how it rounds. That would be a description of a machine, not mathematics, and it would be obsolete before the ink dried. What is wanted instead is the one property of rounding that every later argument uses, elevated into an assumption.

Every operation is performed exactly and then moved to the nearest stored number, so each operation multiplies its exact answer by something within u of 1.

Definition 24.1.1 (The floating-point model)

A floating-point model consists of a finite set R⊆R of representable numbers with 0,1∈R and −R=R, a map fl:R→R sending each real number to a nearest element of R, and a real number u>0 called the unit roundoff, subject to the following.

  • (FP1) (Rounding.) For every t∈R in range, fl(t)=t(1+δ) for some δ with |δ|≤u.
  • (FP2) (Arithmetic.) For x,y∈R and ⊙∈{+,−,×,÷} with y≠0 when ⊙ is ÷, the computed value of x⊙y is fl(x⊙y); the computed value of x for x∈R, x≥0, is fl(x). Hence fl(x⊙y)=(x⊙y)(1+δ),|δ|≤u, and likewise fl(x)=x(1+δ) with |δ|≤u.
  • (FP3) (No overflow or underflow.) Every quantity occurring in a computation we analyze is assumed to be in range, so that (FP1) applies to it.

Clause by clause. “A nearest element” is a mild requirement, and the only use we make of it is the observation that |t|≤1 forces |fl(t)|≤1, because 1∈R. (FP1) is the whole content of the word roundoff: the error made in storing a real number is relative, of size at most u, and that is essentially the only thing we will ever know about fl. (FP2) says an operation is as accurate as storing its answer would be — the machine does not do anything stupid in between. The displayed identity is what every proof in this chapter actually uses, and it is worth reading aloud: the computed product is the exact product times 1+δ. (FP3) is an honest exclusion. Numbers too large or too small for R break (FP1) completely, and analyzing them is a separate subject; we assume the problem away and say so each time it matters.

This is a definition, not a theorem. Nothing in Chapters 1 to 21 implies it, and nothing in this chapter proves it. It is an idealization of a machine, in the way that a frictionless plane is an idealization of a table. The arithmetic in common use satisfies it for the four operations and the square root, with u a little over 10−16; a decimal machine carrying t significant digits satisfies it with u=12⋅101−t. Every statement in this chapter that mentions rounding is a theorem about the model, and carries exactly as much authority as the model does.

Example (The model we compute in)

Throughout this chapter, a worked number comes from the six-digit decimal model: R is the set of numbers ±d1.d2d3d4d5d6×10e with digits di, d1≠0 and e in some fixed finite range, together with 0; and fl rounds to the nearest such number. (The range of e is what (FP3) lets us stop thinking about.) What is u, and what is fl(99999996)?

Solution. Two consecutive representable numbers of the same exponent e differ by 10e−5, and a number t with that exponent has |t|≥10e. Rounding to the nearest moves t by at most half the gap, so |fl(t)−t|≤12⋅10e−5≤12⋅10−5|t|, which is (FP1) with u=12⋅10−5=5×10−6.

For fl(99999996): the number is 9.9999996×107, and the two neighbors with six digits are 9.99999×107 and 1.00000×108. The second is nearer, so fl(99999996)=108. Note what happened: eight digits went in, six came out, and the two digits that were lost were the only two that distinguished 99999996 from 108.

Warning. A model with an absolute error bound would be a different, and false, model. Suppose we had written fl(x+y)=(x+y)+δ with |δ|≤u. Then fl(106+1) would have to be within u=5×10−6 of 106+1, whereas a six-digit machine returns 106, an absolute error of 1. The error a machine makes is proportional to the size of the number it is storing; a machine is accurate in ratio, never in amount. Confusing the two is the commonest mistake in the subject, and (FP1) exists to prevent it.

Quick check. In the six-digit model, is fl(x+y)=x+y possible when x and y are representable and both non-zero? Is fl(x−y)=x−y possible when x≠y?

Solution. Yes to both, and easily. 1+2=3 is representable, so the first addition is exact. For the second, 108−99999.9=99900000.1, which is not representable, so that particular subtraction is inexact; but 1.00001−1.00000=10−5 is representable exactly, so that subtraction is exact. The model never claims an operation is inexact. It claims only a bound on how inexact it can be. That both extremes occur is what makes the subject interesting: the second subtraction is performed exactly, and it is nevertheless the shape of subtraction that destroys answers, as the last example of this section will show.

24.1.3. Accumulated rounding: the constant γk

A single operation costs a factor 1+δ. An algorithm performs many, and the factors pile up: an answer typically carries a product like (1+δ1)(1+δ2)⋯(1+δk), sometimes with an inverted factor where a division occurred. Carrying such products around is unbearable, so we bound them once and for all. The constant that results is used in every remaining section of this chapter.

Lemma 24.1.1 (Accumulated rounding)

Let k≥1 and let δ1,…,δk satisfy |δi|≤u, and let ρ1,…,ρk∈{+1,−1}. If ku<1, then ∏i=1k(1+δi)ρi=1+θwith|θ|≤γk:=ku1−ku.

Idea. Induction on k, with the two signs treated as two cases. The only thing to watch is that the recursion for γk survives division, where the denominator 1−u costs something; the definition γk=ku/(1−ku) is exactly the bound that absorbs that cost.

Proof. Note first that ku<1 forces ju<1 for j≤k, so every γj with j≤k is defined and positive, and γ1≤γ2≤⋯≤γk.

Base case k=1. If ρ1=+1, then θ=δ1 and |θ|≤u≤u/(1−u)=γ1. If ρ1=−1, then θ=11+δ1−1=−δ11+δ1,|θ|≤u1−u=γ1, where 1+δ1≥1−u>0 because u<1.

Inductive step. Suppose the product of the first k−1 factors is 1+θ′ with |θ′|≤γk−1, and write δ=δk.

If ρk=+1, then 1+θ=(1+θ′)(1+δ), so θ=θ′+δ+θ′δ and |θ|≤γk−1+u+γk−1u=(k−1)u+u(1−(k−1)u)+(k−1)u21−(k−1)u=ku1−(k−1)u, and 1−(k−1)u≥1−ku>0, so this is at most ku/(1−ku)=γk.

If ρk=−1, then 1+θ=(1+θ′)/(1+δ), so θ=(θ′−δ)/(1+δ) and |θ|≤(γk−1+u)/(1−u). It remains to check that this is at most γk. Clearing the positive denominators 1−(k−1)u, 1−u and 1−ku, the inequality (γk−1+u)/(1−u)≤γk is equivalent to u(k−(k−1)u)(1−ku)≤ku(1−ku+(k−1)u2), and expanding both sides gives k−k2u−(k−1)u+k(k−1)u2 on the left against k−k2u+k(k−1)u2 on the right, after dividing by u>0. The left side is the right side minus (k−1)u, which is at least 0, so the left side is at most the right side and the inequality holds. This proves the lemma.

Remark. Read γk as “about ku”. Indeed if ku≤0.01 then γk≤ku/0.99<1.02ku. The denominator is there only so that the induction above closes; it is never the point of a bound. We will also use, without further comment, that γj≤γk for j≤k, and we set γ0=0, which is what the formula gives and what the empty product deserves.

24.1.4. The first backward error analysis

Here is the simplest algorithm in the book: add up n products. What comes out is not x⊤y. But it is exactly x⊤y for a slightly different x — and that turns out to be the useful thing to say.

Theorem 24.1.2 (Backward Error of an Inner Product)

Let x,y∈Rn have representable entries, let nu<1, and let the inner product be computed in the model of Definition 24.1.1 in the natural order, s1=fl(x1y1),sk=fl(sk−1+fl(xkyk))(k=2,…,n). Then there is a vector Δx∈Rn with sn=(x+Δx)⊤yand|Δxi|≤γn|xi|  for every i.

Idea. Unroll the recursion and see which rounding factors touch which term. The term xkyk picks up one factor from its own multiplication and one from each addition it takes part in afterwards, so no term collects more than n factors. Lemma 24.1.1 converts “at most n factors” into “1+θ with |θ|≤γn”, and a factor attached to xkyk can be blamed on xk alone.

Proof. By (FP2) there are numbers δk and εk, all of modulus at most u, with fl(xkyk)=xkyk(1+δk)(1≤k≤n),sk=(sk−1+fl(xkyk))(1+εk)(2≤k≤n). An induction on m gives sm=∑k=1mxkyk(1+δk)∏j=max(k,2)m(1+εj), the empty product being 1: for m=1 this is s1=x1y1(1+δ1), and the step from m−1 to m multiplies every existing term by 1+εm and adds the new term xmym(1+δm)(1+εm), which is what the formula says.

Take m=n and count factors in the k-th term. For k=1 there are 1+(n−1)=n of them; for k≥2 there are 1+(n−k+1)=n−k+2≤n. Every factor has the form 1+δ with |δ|≤u, and nu<1, so Lemma 24.1.1 (with all ρi=+1) gives numbers θk with sn=∑k=1nxkyk(1+θk),|θk|≤γn. Put Δxk=xkθk. Then |Δxk|≤γn|xk| and sn=∑k(xk+Δxk)yk=(x+Δx)⊤y. This proves the theorem.

The conclusion is worth staring at. The computed number is not close to x⊤y — if x⊤y happens to be tiny compared with ∑k|xkyk|, it can be wrong in every digit. What the theorem says is different and stronger in kind: the computed number is an inner product, exactly, of data within a relative γn of the given data. The algorithm has not solved a nearby problem approximately; it has solved a nearby problem exactly.

Remark. The same proof, with the roles of x and y exchanged, gives sn=x⊤(y+Δy) with |Δy|≤γn|y| entrywise. What it does not give is a perturbation of both at once with half the constant, and it does not give a bound on |sn−x⊤y| relative to |x⊤y|. Exercise (C1: When backward stability says nothing) makes the last point precise. For complex x,y the operations +, × are themselves built from several real operations, so the model must be applied to those; the resulting bound has the same shape with a modestly larger constant, and we do not prove it here or use it.

24.1.5. Forward error, backward error, stability

We can now name what Theorem 24.1.2 did, and the alternative it declined to do. Fix a problem: a map f:D→Rm from data to answers, where D is a set of admissible data in some RN. The set D always consists of real data and is never cut down to the representable ones: for the problems of this chapter it is all of RN, or all invertible matrices, and it has to be, because the perturbed datum a+Δa below must lie in it. An algorithm for f is a map f^ — defined at the representable data, and sending each of them to whatever the computation actually returns in the model, rounding and all. Two numbers measure how the second differs from the first.

Definition 24.1.2 (Forward and backward error)

Let f be a problem, f^ an algorithm for it, and a∈D a representable datum with f(a)≠0. The forward error of f^ at a is the relative error in the answer, ‖f^(a)−f(a)‖‖f(a)‖. The backward error of f^ at a is the smallest relative perturbation of the data that accounts for the computed answer exactly, inf{‖Δa‖‖a‖:a+Δa∈D and f(a+Δa)=f^(a)}, with the convention that it is ∞ when no such Δa exists.

The forward error is what a user wants to know and can almost never compute, since it needs f(a). The backward error is what an analyst can bound, because bounding it only requires exhibiting one Δa, which a proof like the one above hands over for free. An algorithm whose backward error is always as small as the arithmetic allows is the best one can hope for.

A backward stable algorithm returns the exact answer to a question you might as well have asked.

Definition 24.1.3 (Backward stability)

Let f:D→Rm be a problem. An algorithm f^ for f, running in a floating-point model with unit roundoff u, is backward stable if there is a constant c, depending only on the dimensions of the data and not on the data itself or on u, such that for every representable a∈D there exists Δa∈RN with a+Δa∈D,f^(a)=f(a+Δa),‖Δa‖≤cu‖a‖.

The small words carry the weight. For every a: one lucky datum proves nothing. c independent of the data: a “constant” allowed to grow with ‖a‖ or with κ would make the definition vacuous. c independent of u: the bound must improve when the arithmetic does. The constant is allowed to depend on n, and in practice always does — γn is about nu, not u — which is why “backward stable” is a statement about a family of algorithms indexed by size, and why nobody worries much about a factor of n.

By Theorem 24.1.2, the natural inner product algorithm is backward stable as an algorithm in x for the problem x↦x⊤y with y fixed, on the domain D=Rn. Take c=1.02n, which depends on the dimension alone. Indeed the entrywise bound |Δx|≤γn|x| implies ‖Δx‖≤γn‖x‖ in each of the norms ‖⋅‖1, ‖⋅‖2, ‖⋅‖∞, and γn≤1.02nu in every model with nu≤0.01, by the remark after Lemma 24.1.1. (Restricting to such models is how a bound stated with γn is turned into one with a constant independent of u, and we do it silently from here on.)

Some algorithms are not backward stable and are not bad either: they perturb the data a little and the answer a little, and neither perturbation alone accounts for the result. The weaker notion that covers them is worth naming, so that we never have to claim more than we have proved.

Definition 24.1.4 (Mixed forward-backward stability)

An algorithm f^ for f:D→Rm is mixed forward-backward stable if there is a constant c, depending only on the dimensions, such that for every representable a∈D there are Δa and Δy with a+Δa∈D and f^(a)=f(a+Δa)+Δy,‖Δa‖≤cu‖a‖,‖Δy‖≤cu‖f(a+Δa)‖.

Backward stability is the special case Δy=0, so it is the stronger statement of the two. A mixed stable algorithm does not satisfy the hypothesis of the next theorem: its Δy contributes a further term to the forward error, and we do not estimate that term anywhere in this chapter. Where a method in this chapter is only mixed stable, we say so, and we claim nothing more about it than the definition gives.

Warning. Backward stable does not mean accurate, and inaccurate does not mean unstable. A backward stable algorithm commits to nothing about the forward error except what the problem allows, and for an ill-conditioned problem that is very little. Conversely, an algorithm can return an accurate answer on one datum by luck while being backward unstable. The two words describe different objects: conditioning belongs to f, stability belongs to f^. Chapter 16 §08 promised exactly this: “Chapter 24 draws the distinction properly, defines backward stability, and proves which of the algorithms in this book have it.” Definition 24.1.3 is the definition; the proofs occupy Sections 2 and 3, and the next theorem is the only bridge between the two sides.

24.1.6. Multiplying the two together

The rule of thumb everyone quotes is forward error ≲ condition number × backward error. For linear systems it is not a rule of thumb at all. It is Theorem 16.8.3 with a different reading of the same symbols.

Theorem 24.1.3 (Forward Error from Backward Error)

Let A∈Mn(C) be invertible, b≠0, and Ax=b. Let x^ be any vector which is the exact solution of a perturbed system, (A+ΔA)x^=b,‖ΔA‖‖A‖≤η, and suppose r:=κ(A)η<1. Then A+ΔA is invertible and ‖x^−x‖‖x‖≤r1−r=κ(A)η1−κ(A)η. In particular, if η=cu is admissible — as it is when the algorithm producing x^ is backward stable with constant c for the problem A↦A−1b with b held fixed, so that only A is perturbed — and if κ(A)cu≤12, then the forward relative error is at most 2κ(A)cu.

Idea. There is nothing to do: backward stability says the computed answer solves a perturbed system exactly, and Chapter 16 already bounded the effect of perturbing A. The content of the theorem is the translation, not the estimate.

Proof. Since ‖ΔA‖/‖A‖≤η, we have κ(A)‖ΔA‖/‖A‖≤r<1, so Theorem 16.8.3 (b), applied with E=ΔA, says that A+ΔA is invertible and that ‖x^−x‖‖x‖≤r′1−r′,r′:=κ(A)‖ΔA‖‖A‖≤r. The function s↦s/(1−s) is increasing on [0,1), since its derivative (1−s)−2 is positive there, so r′/(1−r′)≤r/(1−r). For the last claim put η=cu; then r=κ(A)cu≤12 gives 1−r≥12 and r/(1−r)≤2r. This proves the theorem.

Remark. When the right-hand side is perturbed too. A solver for Ax=b normally perturbs the pair (A,b), returning x^≠0 with (A+ΔA)x^=b+Δb,‖ΔA‖2≤cu‖A‖2,‖Δb‖2≤cu‖b‖2, which is not literally the hypothesis above. One absorption repairs that. Put ΔA′=ΔA−Δbx^∗/‖x^‖22; then (A+ΔA′)x^=b+Δb−Δb=b, and the subtracted matrix is an outer product, of 2-norm ‖Δb‖2/‖x^‖2. So Theorem 24.1.3 applies in the 2-norm with η=cu(1+‖b‖2‖A‖2‖x^‖2)≤cu(1+‖x‖2‖x^‖2), the last step because ‖b‖2=‖Ax‖2≤‖A‖2‖x‖2. That is a small multiple of cu as soon as the computed x^ is not much shorter than x, and it is how every later appeal to the theorem for a linear solver is to be read.

Reading the bound in digits. Suppose the arithmetic has u≈10−16 and the algorithm is backward stable with a modest c. The bound then reads: relative forward error at most about κ(A)⋅10−16. Taking logarithms, the computed answer may be wrong from about the (16−log10⁡κ(A))-th significant digit onward. This is the origin of the sentence “a stable solve loses about log10⁡κ decimal digits”. Two cautions, both real. It is an upper bound, so the loss may be smaller — Chapter 16 §08’s warning that “the condition number bounds the error; it does not produce it” applies verbatim. And it is a statement about κ(A) for the problem as posed: an algorithm that quietly poses a different problem pays that problem’s condition number instead.

That last point is the whole of Chapter 16 §08’s remaining ledger. Its third unpaid item read: “Hence the comparison of the two algorithms — that a stable implementation of the QR route loses about log10⁡κ2(A) decimal digits while forming and solving the normal equations loses about 2log10⁡κ2(A) — is still Chapter 24’s to prove.” The theorem above supplies the first half of the sentence for any backward stable method. Section 3 supplies the second half and the two algorithms, using Chapter 16’s own Theorem 16.8.4 for the square.

Quick check. An algorithm for Ax=b is backward stable, κ(A)=108, and u=10−16. A user reports that the computed x^ has only eight correct digits and concludes that the algorithm is broken. What is wrong with the conclusion?

Solution. Nothing at all is wrong with the algorithm: Theorem 24.1.3 — applied after absorbing any perturbation of b into ΔA, as in the remark following it — predicts a relative forward error of about κ(A)u=10−8, up to the modest constant c, which is exactly eight correct digits. The loss is charged to the problem, not to the method. Chapter 16 §08 put it as sharply as it can be put: with data of limited accuracy, an ill-conditioned answer is not determined to more digits than that, whatever anybody computes with.

24.1.7. Cancellation, and where the damage really happens

Backward stability is a property of a whole algorithm, and algorithms are usually wrecked in one place. That place is almost always a subtraction of two nearly equal numbers. The following example is the standard one, and it repays being done digit by digit.

Example (Two ways to solve a quadratic)

In the six-digit decimal model of Example (The model we compute in), find the two roots of x2−104x+1=0 by the quadratic formula x±=12(104±108−4), and then again with the smaller root computed as x−=1/x+. Compare with the exact roots.

Solution. The exact roots. Their sum is 104 and their product is 1. Now 9999.99982=108−4+4×10−8, which is just above 108−4, so 108−4=9999.99979999… and x+=9999.99989999…,x−=1x+=1.0000000100…×10−4.

The formula, step by step. Each line is one operation of the model.

  • fl(104×104)=108, exactly representable, no error.
  • fl(108−4)=fl(99999996)=1.00000×108, by Example (The model we compute in). Here the two informative digits are lost, and the relative error committed is about 4×10−8, comfortably inside u=5×10−6. The model is behaving perfectly.
  • fl(108)=104, exactly.
  • fl(104+104)=2×104 and fl(2×104÷2)=104: the computed x+ is 104, with relative error 10−8. Excellent.
  • fl(104−104)=0, exactly, and fl(0÷2)=0: the computed x− is 0.

The repair. Compute x+=104 as above, then fl(1÷104)=10−4, whose relative error against 1.00000001×10−4 is 10−8.

What to conclude. The second route loses nothing; the first returns a root with no correct digit, indeed with no digits at all. And notice where the damage was done. The fatal subtraction 104−104 was performed exactly: both operands were representable and so was their difference. The error was already present, manufactured four lines earlier when 99999996 was rounded to 108, and the subtraction merely deleted the digits the two operands had in common, which was all of them. Cancellation does not create error. It exposes error, by deleting the digits that were correct and promoting the ones that were not.

Warning. A small residual is not a small error, and a small error is not a small residual. For a computed solution x^ of Ax=b with x^≠0, put r=b−Ax^ and ΔA=rx^∗‖x^‖22,so that(A+ΔA)x^=Ax^+r=b, and ‖ΔA‖2=‖r‖2/‖x^‖2: Cauchy–Schwarz gives ≤, and ΔAx^=r attains it — the computation is the one in the proof of Theorem 20.4.4, with b in place of μx^. So a small relative residual is a small backward error, and nothing more: by Theorem 24.1.3 the forward error may still be κ(A) times as large. In the other direction, an accurate x^ for a badly scaled A can have a residual far larger than one expects. Chapter 20 §04’s Theorem 20.4.4 is the eigenvalue version of exactly this move, and that section named the technique: “An error analysis of this kind, which measures an answer by a change in the data that makes it exact, is a backward error analysis. Chapter 24 builds on it.”

24.1.8. Exercises

A. Check your understanding

Exercise (A1)
  • (a) State the three clauses of Definition 24.1.1, and say which one is an exclusion rather than an assumption about accuracy.
  • (b) Define the unit roundoff, and give its value for a decimal model carrying t significant digits.
  • (c) Define the forward error and the backward error of an algorithm at a datum, and say which of the two a user can usually measure.
  • (d) Decide whether each statement is correct, with a reason: (i) “a backward stable algorithm returns an answer with small forward error”; (ii) “if the computed x^ has a tiny residual, then x^ is close to x”.
  • (e) Why is Definition 24.1.1 called a model rather than a theorem?

Solution.

  • (a) (FP1) rounding is relative, with error at most u; (FP2) each operation returns the rounding of its exact result, so fl(x⊙y)=(x⊙y)(1+δ) with |δ|≤u; (FP3) no overflow or underflow. (FP3) is the exclusion: it does not say the arithmetic is good, it says we decline to analyze the case where it is not.

  • (b) u is the bound in (FP1): |fl(t)−t|≤u|t| for every in-range t. For a decimal model with t significant digits, u=12⋅101−t (Example (The model we compute in) does the case t=6).

  • (c) See Definition 24.1.2. The forward error is ‖f^(a)−f(a)‖/‖f(a)‖, the backward error the smallest ‖Δa‖/‖a‖ with f(a+Δa)=f^(a). A user can usually measure neither directly, but the backward error is the one an analyst can bound, because a bound needs only one exhibited Δa; computing the forward error needs the exact answer, which is what the computation was for.

  • (d)
    • (i) Incorrect. It returns an answer with small backward error; the forward error is then at most about κ times that, by Theorem 24.1.3 (after absorbing any perturbation of b, as the remark after that theorem does), and for large κ that is no guarantee at all. (ii) Incorrect, for the same reason: a small residual is a small backward error (see the warning above), which bounds the forward error only after multiplication by κ(A).
  • (e) Because it is an assumption about a physical machine, not a consequence of anything proved earlier in the book. Nothing in Chapters 1 to 21 mentions rounding. Everything this chapter proves about arithmetic is a theorem about the model, true of any machine that satisfies it and silent about one that does not.

B. Practice

Exercise (B1: The γ calculus)

Assume (j+k)u<1.

  • (a) Prove that 1+γk=1/(1−ku).
  • (b) Hence prove that γj+γk+γjγk≤γj+k.
  • (c) Explain in one sentence why (b) is the statement one needs when two separately analyzed computations are performed one after the other.

Solution.

  • (a) 1+γk=1+ku/(1−ku)=((1−ku)+ku)/(1−ku)=1/(1−ku).

  • (b) Using (a) twice, 1+γj+γk+γjγk=(1+γj)(1+γk)=1(1−ju)(1−ku). Now (1−ju)(1−ku)=1−(j+k)u+jku2≥1−(j+k)u>0, and inverting reverses the inequality between positive numbers, so the right-hand side is at most 1/(1−(j+k)u)=1+γj+k. Subtracting 1 gives the claim.

  • (c) If one stage multiplies the exact answer by 1+θ1 with |θ1|≤γj and the next by 1+θ2 with |θ2|≤γk, the combined factor is 1+θ1+θ2+θ1θ2, and (b) says the total is still of the form 1+θ with |θ|≤γj+k — the counts simply add.

Exercise (B2: Summation)

Let x1,…,xn be representable, let nu<1, and let sn be computed by s1=x1, sk=fl(sk−1+xk).

  • (a) Prove that sn=∑k=1nxk(1+θk) with |θk|≤γn−1.
  • (b) Deduce |sn−∑kxk|≤γn−1∑k|xk|, and explain why this is not a bound on the relative error of sn.
  • (c) Give three representable numbers in the six-digit model for which the computed sum has relative error larger than u.

Solution.

  • (a) By (FP2), sk=(sk−1+xk)(1+εk) for 2≤k≤n, with |εk|≤u. Unrolling as in the proof of Theorem 24.1.2, sn=∑k=1nxk∏j=max(k,2)n(1+εj). The k=1 and k=2 terms carry n−1 factors and the rest carry fewer, so Lemma 24.1.1 gives |θk|≤γn−1.

  • (b) Subtract ∑kxk and use the triangle inequality: |sn−∑kxk|=|∑kxkθk|≤γn−1∑k|xk|. It is not a relative error bound because the right-hand side involves ∑k|xk|, not |∑kxk|, and the two differ by an arbitrarily large factor when the xk have mixed signs and cancel.

  • (c) Take x1=1, x2=10−7, x3=−1, summed in that order. Then fl(1+10−7)=1, since 1+10−7 lies strictly between the representable neighbors 1 and 1.00001 and is nearer the first; and fl(1−1)=0. The computed sum is 0, the true sum is 10−7, and the relative error is 1. This is (b) at work: ∑|xk|=2 while |∑xk|=10−7.

Exercise (B3: The model by hand)

Work in the six-digit decimal model.

  • (a) Compute fl(1/3) and verify (FP1) for it.
  • (b) Compute the two sides of fl(fl(a+b)+c) and fl(a+fl(b+c)) for a=105, b=1, c=1, and say what this shows about the model.

Solution.

  • (a) 1/3=3.333333―×10−1, so fl(1/3)=0.333333 and |fl(1/3)−1/3|=13×10−6. Dividing by 1/3 gives a relative error of 10−6, which is at most u=5×10−6.

  • (b) Left: fl(105+1)=100001 exactly (six digits), and fl(100001+1)=100002. Right: fl(1+1)=2, and fl(105+2)=100002. Here the two agree. Change a to 106: left gives fl(106+1)=106, then fl(106+1)=106; right gives fl(1+1)=2, then fl(106+2)=106 as well, since 1000002 rounds to 1.00000×106. Try a=106, b=c=3: left is 106 then 106; right is 6 then fl(1000006)=1.00001×106. The two differ. Floating-point addition is commutative but not associative, so the order of a summation is part of the algorithm, not an irrelevance — which is why Theorem 24.1.2 names the order it analyzes.

C. Going deeper

Exercise (C1: When backward stability says nothing)

Let x,y∈Rn and let sn be the computed inner product of Theorem 24.1.2.

  • (a) Prove that |sn−x⊤y|≤γn|x|⊤|y|, where |⋅| is entrywise.
  • (b) Deduce that if all xiyi≥0 then the relative error of sn is at most γn.
  • (c) Give x,y∈R3 with representable entries, in the six-digit model, for which the relative error of sn is at least 1. Explain why this does not contradict Theorem 24.1.2.

Solution.

  • (a) By the theorem’s proof, sn=∑kxkyk(1+θk) with |θk|≤γn, so |sn−x⊤y|=|∑kxkykθk|≤γn∑k|xk||yk|=γn|x|⊤|y|.

  • (b) If every xkyk≥0 then |x|⊤|y|=∑kxkyk=x⊤y, so (a) reads |sn−x⊤y|≤γnx⊤y, which is the relative bound (and x⊤y>0 unless every term vanishes, in which case sn=0 too).

  • (c) Take x=(1,10−7,−1) and y=(1,1,1), all representable. Each product xkyk is computed exactly, so δ1=δ2=δ3=0. Then s1=1; next s2=fl(1+10−7)=1, which is (1+10−7)(1+ε2) with ε2=−10−71+10−7,|ε2|<10−7<u; finally s3=fl(1−1)=0, exactly, so ε3=0 serves. The true value is x⊤y=10−7, so the forward relative error is 1.

There is no contradiction. Following the proof, θ1=θ2=ε2 and θ3=0, all of modulus below u≤γ3, and indeed (1+ε2)+10−7(1+ε2)−1=(1+10−7)(1+ε2)−1=0=s3. So the backward perturbation Δx=(ε2,10−7ε2,0) is of relative size about 10−7 in every coordinate: the algorithm solved a neighboring problem exactly. What made the answer worthless is the problem, not the method: here |x|⊤|y|=2+10−7 while x⊤y=10−7, so part (a)’s bound is twenty million times the quantity being computed. This is the same phenomenon as Example (Two ways to solve a quadratic), seen through the backward error.

Exercise (C2: An unstable way to compute a variance)

Given x1,…,xN with mean x―=1N∑ixi, the quantity S=∑i(xi−x―)2 can be computed in one pass as S=∑ixi2−1N(∑ixi)2, or in two passes by forming x― first.

  • (a) Verify the identity ∑i(xi−x―)2=∑ixi2−1N(∑ixi)2.
  • (b) In the six-digit model, run both routes on x=(10000,10001,10002), showing every operation, and compare with the exact value S=2.
  • (c) Say which route is to be preferred and why, in the vocabulary of this section.

Solution.

  • (a) Expand: ∑i(xi−x―)2=∑ixi2−2x―∑ixi+Nx―2. Since ∑ixi=Nx―, the last two terms are −2Nx―2+Nx―2=−Nx―2=−1N(∑ixi)2.

  • (b) One pass. The squares are 108, 100020001, 100040004; rounding each to six digits gives 1.00000×108, 1.00020×108 and 1.00040×108, and accumulating gives fl(1.00000×108+1.00020×108)=2.00020×108 and then 3.00060×108. The sum ∑ixi=30003 is exact, its square is 900180009, which rounds to 9.00180×108, and dividing by 3 gives 3.00060×108. Subtracting: fl(3.00060×108−3.00060×108)=0.

    Two passes. x―=fl(30003/3)=10001, exactly. The deviations −1,0,1 are computed exactly, their squares are 1,0,1, and the sum is 2, the exact answer.

  • (c) The two-pass route. The one-pass route subtracts two nine-digit numbers that agree in their first six digits, so in a six-digit model it commits catastrophic cancellation and returns 0; worse, 0 is not the value of S for any small relative perturbation of the data. Indeed S(x+Δx)=0 forces the three perturbed entries to be equal, say to v; and for x=(10000,10001,10002) the largest of |xi−v| is at least 1, whatever v is, because x3−x1=2. So every Δx that accounts for the computed answer has ‖Δx‖∞‖x‖∞≥110002>19u, whereas Definition 24.1.3 allows cu. One datum bounds the constant rather than disposing of it — what this shows exactly is that no c≤19 will serve for the one-pass route — but the mechanism is general, and it is the one Example (Two ways to solve a quadratic) identified. The two-pass route performs the subtraction xi−x― first, while the operands are still exactly representable, and nothing is ever lost. Same identity, same arithmetic, different algorithm — which is precisely the distinction between a problem and a method.

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.