Chapter 16 ended with a number and a warning. The
number was , 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.
Two
answers to one question
Chapter 16 §08 left a small experiment on the
reader’s desk. The system was whose coefficient matrix has :
by every measure of Chapter 16 this problem is as well
behaved as a problem can be, and its exact solution is
to fourteen
places. Eliminating with the first
equation as the pivot row, and rounding to twelve
significant decimal digits at every step, returns . Exchanging the
two equations first, and rounding in exactly the same
way, returns .
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.
A model of
machine arithmetic
A machine holds finitely many numbers. It cannot hold
, it cannot hold
, 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 of .
Definition
24.1.1 (The floating-point model)
A floating-point model consists of a
finite set of representable numbers
with
and , a
map sending each real number to a
nearest element of , and a real number
called the
unit roundoff, subject to the
following.
- (FP1)
(Rounding.) For every in range,
for some
with .
- (FP2)
(Arithmetic.) For and with when is , the computed value
of is
; the
computed value of for , , is . Hence
and likewise with .
- (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 forces ,
because .
(FP1) is the whole content of the word
roundoff: the error made in storing a real
number is relative, of size at most
, and that is
essentially the only thing we will ever know about . (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
.
(FP3) is an honest exclusion. Numbers too large or too
small for 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 a
little over ; a decimal
machine carrying
significant digits satisfies it with . 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: is the set of numbers
with digits , and in some fixed finite
range, together with ; and rounds to the nearest
such number. (The range of is what (FP3) lets us
stop thinking about.) What is , and what is ?
Solution. Two consecutive
representable numbers of the same exponent differ by , and a number
with that
exponent has . Rounding to the nearest moves by at most half the
gap, so which is (FP1) with .
For : the number
is , and the two neighbors with six digits
are and . The second is nearer, so .
Note what happened: eight digits went in, six came out,
and the two digits that were lost were the only two that
distinguished from .
Warning. A model with an
absolute error bound would be a different, and false,
model. Suppose we had written with .
Then would have to be within of
, whereas
a six-digit machine returns , an absolute error
of . 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 possible when and are representable and
both nonzero? Is possible when ?
Solution. Yes to both, and easily.
is
representable, so the first addition is exact. For the
second, , which is not
representable, so that particular subtraction is
inexact; but 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.
Accumulated rounding: the constant
A single operation costs a factor . An algorithm
performs many, and the factors pile up: an answer
typically carries a product like , 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 and
let satisfy , and let . If , then
Idea. Induction on , with the two signs
treated as two cases. The only thing to watch is that
the recursion for survives
division, where the denominator costs something;
the definition is exactly the bound that absorbs
that cost.
Proof. Note first that forces for , so every with is defined and
positive, and .
Base case . If , then and . If , then where because .
Inductive step. Suppose the product of the
first factors
is
with , and write .
If ,
then , so and and , so this is at most .
If ,
then , so and . It remains to check
that this is at most . Clearing the
positive denominators , , and , the inequality is equivalent to and expanding both sides gives on the left against on
the right, after dividing by . The left side
is the right side minus , which is at least
, so the left side
is at most the right side and the inequality holds. This
proves the lemma.
The first
backward error analysis
Here is the simplest algorithm in the book: add up
products. What
comes out is not . But
it is exactly for a
slightly different — and that turns
out to be the useful thing to say.
Theorem
24.1.2 (Backward Error of an Inner
Product)
Let have representable entries, let
, and let
the inner product be computed in the model of Definition 24.1.1 in the
natural order, Then there is a vector
with
Idea. Unroll the recursion and see
which rounding factors touch which term. The term picks up one
factor from its own multiplication and one from each
addition it takes part in afterwards, so no term
collects more than factors. Lemma 24.1.1 converts “at
most factors”
into “
with ”, and a factor attached to can be blamed on
alone.
Proof. By (FP2) there are numbers
and , all of
modulus at most ,
with An induction on gives the empty product being : for this is ,
and the step from to multiplies every
existing term by and adds the new term ,
which is what the formula says.
Take and
count factors in the -th term. For there are of them;
for there
are . Every factor has the form with ,
and , so
Lemma 24.1.1 (with all
) gives
numbers
with Put . Then and . This
proves the theorem.
The conclusion is worth staring at. The computed
number is not close to — if
happens to be tiny compared with , 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 of the given
data. The algorithm has not solved a nearby problem
approximately; it has solved a nearby problem
exactly.
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
from data to answers, where is a set of admissible
data in some . The set always consists of
real data and is never cut down to the
representable ones: for the problems of this chapter it
is all of ,
or all invertible matrices, and it has to be, because
the perturbed datum below must lie in it. An
algorithm for is a map — 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 be a
problem,
an algorithm for it, and a
representable datum with .
The forward error of at is the relative
error in the answer, The backward error of at is the smallest
relative perturbation of the data that accounts for the
computed answer exactly, with the convention that it is when no such
exists.
The forward error is what a user wants to know and
can almost never compute, since it needs . The backward
error is what an analyst can bound, because bounding it
only requires exhibiting one , 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 be a problem. An algorithm for , running in a
floating-point model with unit roundoff , is backward
stable if there is a constant , depending only on the
dimensions of the data and not on the
data itself or on , such that for every
representable there exists with
The small words carry the weight. For every
:
one lucky datum proves nothing. independent of the
data: a “constant” allowed to grow with or with
would make
the definition vacuous. independent of : the bound
must improve when the arithmetic does. The constant is
allowed to depend on , and in practice always
does — is
about , not — 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 .
By Theorem 24.1.2, the
natural inner product algorithm is backward stable as an
algorithm in for the problem
with fixed, on the
domain .
Take ,
which depends on the dimension alone. Indeed the
entrywise bound implies in each of the norms
,
,
,
and in every model with , by the
remark after Lemma 24.1.1. (Restricting
to such models is how a bound stated with is turned into
one with a constant independent of , 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 for is mixed forward-backward
stable if there is a constant , depending only on the
dimensions, such that for every representable there are
and
with
and
Backward stability is the special case , so it is the stronger statement of
the two. A mixed stable algorithm does
not satisfy the hypothesis of the next
theorem: its
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 , stability belongs to
. 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.
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 be invertible, ,
and . Let be any
vector which is the exact solution of a perturbed
system, and suppose . Then is
invertible and In particular, if is admissible —
as it is when the algorithm producing is
backward stable with constant for the problem
with held
fixed, so that only is perturbed — and if
, then the forward relative error is at
most .
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 . The content of the
theorem is the translation, not the
estimate.
Proof. Since , we have , so Theorem 16.8.3 (b), applied
with ,
says that is invertible and that The function is increasing on , since its
derivative is positive
there, so . For the last claim put ; then gives and . This
proves the theorem.
Reading the bound in digits. Suppose
the arithmetic has and the algorithm is backward stable
with a modest .
The bound then reads: relative forward error at most
about . Taking logarithms, the computed
answer may be wrong from about the -th significant digit
onward. This is the origin of the sentence “a stable
solve loses about 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
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
decimal digits while forming and solving the normal
equations loses about —
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 is
backward stable, , and . A user reports that the computed
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 into , as in the
remark following it — predicts a relative forward error
of about , up to the modest constant , 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.
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 by the quadratic formula , and then again with the
smaller root computed as . Compare with the exact roots.
Solution. The exact roots.
Their sum is
and their product is . Now , which is just above , so and
The formula, step by step. Each line is one
operation of the model.
- , exactly representable, no error.
- , by Example (The model we compute in).
Here the two informative digits are
lost, and the relative error committed is about
,
comfortably inside . The model is behaving
perfectly.
- , exactly.
- and : the computed is , with relative
error .
Excellent.
- , exactly, and : the
computed is
.
The repair. Compute as above, then
, whose relative error against
is .
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 was performed exactly:
both operands were representable and so was their
difference. The error was already present, manufactured
four lines earlier when was rounded to
, 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 of
with , put and and :
Cauchy–Schwarz gives , and attains it — the computation is the
one in the proof of Theorem 20.4.4, with
in place
of . So
a small relative residual is a small backward
error, and nothing more: by Theorem 24.1.3 the forward
error may still be times as
large. In the other direction, an accurate for a
badly scaled 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.”
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
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 has a
tiny residual, then is
close to ”.
- (e) Why is Definition 24.1.1 called a
model rather than a theorem?
Solution.
(a) (FP1)
rounding is relative, with error at most ; (FP2) each operation
returns the rounding of its exact result, so with ;
(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) is the bound in (FP1):
for every in-range . For a decimal model
with significant
digits, (Example (The model we compute in)
does the case ).
(c) See Definition 24.1.2. The
forward error is , the backward
error the smallest
with . 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 ; 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 , 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 .
(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 .
- (a) Prove that .
- (b) Hence prove that
.
- (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) .
(b) Using (a)
twice, Now , and
inverting reverses the inequality between positive
numbers, so the right-hand side is at most . Subtracting gives the
claim.
(c) If one stage
multiplies the exact answer by with and the next by with , the combined factor is , and (b) says the total is
still of the form with — the counts simply add.
Exercise
(B2: Summation)
Let be representable, let , and let be computed by , .
- (a) Prove that with .
- (b) Deduce , and explain
why this is not a bound on the relative
error of .
- (c) Give three
representable numbers in the six-digit model for which
the computed sum has relative error larger than .
Solution.
(a) By (FP2),
for , with . Unrolling as in the proof of Theorem 24.1.2, The
and terms
carry factors
and the rest carry fewer, so Lemma 24.1.1 gives .
(b) Subtract
and use
the triangle inequality: . It is not a
relative error bound because the right-hand side
involves , not ,
and the two differ by an arbitrarily large factor when
the have mixed
signs and cancel.
(c) Take , , , summed in that
order. Then , since lies strictly between the representable
neighbors and
and is
nearer the first; and . The computed sum is , the true sum is , and the relative
error is . This is
(b) at work: while .
Exercise
(B3: The model by hand)
Work in the six-digit decimal model.
- (a) Compute and verify (FP1)
for it.
- (b) Compute the two
sides of and for , , ,
and say what this shows about the model.
Solution.
(a) , so and
. Dividing by gives a relative
error of ,
which is at most .
(b) Left:
exactly (six digits), and .
Right: , and . Here the two agree. Change to : left gives ,
then ; right gives , then as
well, since
rounds to . Try , : left is then ; right is then . 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 and let be the computed inner
product of Theorem 24.1.2.
- (a) Prove that ,
where is
entrywise.
- (b) Deduce that if
all
then the relative error of is at most .
- (c) Give with representable entries, in the
six-digit model, for which the relative error of is at least . Explain why this does
not contradict Theorem 24.1.2.
Solution.
(a) By the
theorem’s proof, with , so
(b) If every
then
, so (a)
reads , which is the
relative bound (and unless every term vanishes, in which case
too).
(c) Take and , all representable. Each product
is computed
exactly, so . Then ; next , which is with finally , exactly, so serves.
The true value is , so the forward relative error is .
There is no contradiction. Following the proof, and , all of
modulus below , and indeed So the backward perturbation is of relative size
about in
every coordinate: the algorithm solved a neighboring
problem exactly. What made the answer worthless is the
problem, not the method: here while , 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 with mean , the quantity can be computed
in one pass as , or in
two passes by forming first.
- (a) Verify the
identity .
- (b) In the six-digit
model, run both routes on , showing every
operation, and compare with the exact value .
- (c) Say which route
is to be preferred and why, in the vocabulary of this
section.
Solution.
(a) Expand: . Since , the last two terms are
.
(b) One
pass. The squares are , , ; rounding each
to six digits gives ,
, and , and accumulating gives and
then . The sum is
exact, its square is , which rounds
to , and dividing by gives .
Subtracting: .
Two passes. , exactly. The deviations are computed
exactly, their squares are , and the sum is
, 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 ; worse,
is not the value
of for
any small relative perturbation of the data.
Indeed forces the three perturbed
entries to be equal, say to ; and for the largest of is
at least ,
whatever is,
because . So every that
accounts for the computed answer has whereas Definition 24.1.3 allows
. One datum
bounds the constant rather than disposing of it — what
this shows exactly is that no 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
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.