Solving A Quadratic Equation On A Computer 1966 Forsythe

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

As every high school student kaows, the solutions of a quadratic

equation ax2 +bx+ c = 0 are always given by a single simple


formula in terms of a, b, and c. From the standpoint of algebra,
this completely settles the matter. From the standpoint of finding
useful numerical approximations to these solutions, however,
even the mightiest computers sometimes encounter pitfalls, and
numerical analysts concerned with practical aspects of computing
must use great ingenuity to prevent insignificantly small errors
from snowballing and producing ridiculous answers. In view of
the widespread use of computers, some practical aspects of com­
putation should be part of everyone's basic education in mathe­
matics, the author suggests.

le.. The. fftt..fAemd f,eaL 3(:,(enees.


11
];I/IA.ado
/7 f�!lechefn o/ ES's�s : 11/T/ks�
1.16J.

Solving a Quadratic Equation


on a Computer
George E. Forsythe

The automatic digital computer is one of man's most powerful intellectual


tools. It forms an extension of the human mind that can be compared only
with the augmentation of human muscle by the most powerful engines in
the world.
Computers have a wide variety of applications, ranging from the control
of artificial satellites. to the automatic justification and hyphenation of
English prose, and even to the storage and searching of medical libraries.
However, computers were originally invented to carry out arithmetic
computations rapidly and accqrately, and this remains one of the major
uses of computers today.
As early as World War I, L. F. Richardson indicated how the weather
might be forecast with the aid of a vast computation then far beyond
human capability, provided that enough upper-air weather observations
were available as input data. By the 1940's the upper-air observa­
tions were beginning to appear in quantity. Hence, when Jqhn Von
Neumann and others asked the government for funds to support computer
development, they promised that computers would make it possible to
carry out the arithmetic part of a modern version of Richardson's pro-
SOLVING A QUADRATIC EQUATION ON A COMPUTER 139

gram. It was expected that the weather would soon be forecast routinely
by computer, and so it was. It was even hinted that computers might
make it possible to predict the future �our�e of hurricanes after a variety
of human interventions and thus lead to the eventual control of the weather.
This, disappointingly, has not come to pass.
Many intellectual steps are involved in a project like weather forecasting
by computer. In the first place, a reasonable model of the weather must
be reduced to systems of equations, both algebraic and differential. The
actual solution of such systems of equations is completely beyond the
powers of any computer because, among other things, this involves know­
ing the wind at each of an infinite number of points of space.
Consequently, the second stage of numerical weather prediction is to
replace the infinite number of points of space by a finite number of points
arranged in a number of square-mesh layers spaced one above another,
made of squares perhaps one hundred miles on a side. Instead of trying
to describe and predict the wind at each point of space, one describes and
predicts it at the corners of the meshes. The equations that describe the
exact flow of air and moisture are replaced by much simpler equations,
relating these quantities at neighboring ·points of the mesh. A great deal
of mathematical analysis and experimental computation is needed before
we can discover simple equations for the mesh which reasonably well
simulate the actual equations for continuous space.
At the end of the second stage just described, we have a set of equatio.ns
to solve. Each equation deals with unknown quantities that are real num­
bers. Recall that real numbers may be thought of as infinite decimal
expansions like

-3.3333333333 3333333333 3333333333 .


(3's continued without end) or

3.1415926535 8979323846 2643383279 .


(digits continued without end, but without a predictable pattern). Since
a computer is necessarily a finite collection of parts, it cannot hold
all the decimal digits of even a single general real number. Hence, the
third stage of the use of computers for weather prediction involves the use
of a finite number system to simulate the real number system of mathe­
matics.
Now that automatic digital computers have become so widespread in
this nation, practically all of our scientific computation is done on them.
The main point of this article is to bring out the difference between ..
theoretical computation (that of arithmetic and algebra) and practical
computation (that actually carried out on a computer).
We shall now describe the computer number system and some diffi­
culties involved in using it . .To illustrate the difficulties, we shall consider
140 GEORGE E. FORSYTHE

a mathematical problem that is almost infinitely simpler than the equa­


tions of meteorology - the quadratic equation.

Floating-Point Numbers
We shall first describe a simplified computer number system, the
system of so-called floating-point numbers, and then show some of its
behavior with a simple mathematical computation.
The usual number system of a computer reduces the infinite number of
decimal places of real numbers to a fixed finite number. We first consider
decimal numbers with a sign ( + or -) and one nonzero digit to the left
of the decimal point, and exactly seven zero or nonzero numbers to the
right of the decimal point. Examples of such numbers are -7.3456780,
+1.0000000, +3.3333333, and -9.9808989. We say that such numbers
have 8 s£gnificant d£g£ts. (The choice of 8 significant base-10 digits is
purely for illustration; other systems also are used.) One can represent
approxim�tely 200,000,000 different numbers in this way, but they all
lie between -10 and -1 or between +1 and +10. To enable computers
to hold much bigger and smaller numbers, we add a sign and two more
decimal digits to serve as an exporien� of 10. In one commonly used system,
the exponent is allowed to range from -50 to +49. Thus, the number
-87 i- is represented by

-8.7666667 X 10+01.
In this system, which is much like so-called sc£entific notation, the repre­
sentable numbers all have 8 significant decimal digits. They range from

-9.9999999 X 10 49 to -1.0000000 X 10- 50

and from

+1.0000000 X 10- 50 to 9.9999999 X 10 49 .

The number zero (O) is represented by +0.0000000 X 10- 50• Approx­


imately 20,000,000,000 distinct real numbers are thus representable in the
computeF, and these take the place of the infinite system of mathematical
real numbers.
This computer number system is called the fioat£ng-point number system.
The "point" is the decimal point. The exponent permits the decimal
point effectively to "float" as much as 50 places away (to the left or the
right) from its home position, corresponding to exponent 0.
Special computer facilities make it possible also to use so-called
double precis£on numbers - numbers which have not 8 but 16 significant
digits, with the exponent kept between -49 and +so. The machine works
more slowly when these double precision numbers are used, but this
penalty varies greatly among different computers.
SOLVING A QUADRATIC EQUATION ON A COMPUTER 141

In this paper we shall write floating-point numbers in various ways,


but there will be understood to be exactly 8 significant digits '. For example,
we may write the number eleven a_s 11 _ or 11.0 or +1.1000000 X 10+01
or 1.1 X 10 1 •

Computer Arithmetic
Besides holding floating-point numbers, every scientific computer must
be able to perform on them the elementary arithmetic operations of addi­
tion and subtraction, multiplication and division. Let us consider addition
first. Sometimes the exact sum of two floating-point numbers is itself a
floating-point number; for example,

(+ 2.1415922 X 10+00) + (+ 9.7182818 X 10+00)


= + 1.1859874 X 10 + 01 •
In this case, the computed sum is the same as the exact sum, and the com­
putation is said to be without rounding error. More frequently, the exact
sum is not a floating-point number; For example, the exact sum of
+6.6666667 X 10+01 and +6.6666667 X 10+01 is 133.333334, a number
with 9 significant digits. Hence, the exact sum cannot be held in the
computer but must be rounded to the nearest floating-point number, in
this case to + 1.3333333 X 1o+o 2• This is a typical example wpere
computer addition is only approximately the same as mathematical
addition.
An even worse defect of computer addition appears when the numbers
are numerically very large, so that the sum exceeds the capacity of the
floating-point system. For example, the true sum of+ 9.9900000 X 10+4 9
and +9.9990000 X 10 + 49 is 1.9989 X 10 50, a number greater than the
largest possible floating-point number in our system. The computer should
signal in some manner that an "overflow" has occurred and give the
problem-solving program some option about what action to take. But
it is impossible to store an answer that represents the exact sum to even
one significant digit.
Computer multiplication suffers from the same two defects of computer
addition - the necessity for rounding answers and the possibility of
exponent overflow. While ordinary rounding errors are no more serious
tJ::ian with addition, overflow can be far worse, for the following reason.
The exact sum of two floating-point numbers cannot exceed 2 X 10 50,
but the exact product of two floating-point numbers can be as large as
9.9999998 X 1099, and the product of two numbers each as small as 10 25
can lead to overflow. Moreover, there is a possibility of "underflow"' 1:ri·
multiplication. For example, the true product of 1.01 X 1o- 3 o and
1.01 X 10- 35 is 1.0201 X 10-65, a number smaller by a factor of 10- 15
than the smallest nonzero floating-point number. The most we can expect
142 GEORGE E. FORSYTHE

from the computer is that it will replace the product by zero and give the
program a signal that underflow has occurred.
The problems encountered in computer subtraction are analogous to
those in addition, and in this sense division is analogous to multiplication.
We assume that our computer operations of addition, subtraction,
multiplication, and division, in the absence of overflow or underflow,
will yield as an answer the floating-point number closest to the exact real
answer. (In case of a tie, we permit either choice.) In fact many actual
computer systems achieve this accuracy or come close to it.

Are Floating-Point Numbers Satisfactory?


Anyone who uses a digital computer for scientific computation is faced
with a number system which is only approximately that of mathematics
and arithmetic operations which are only approximately those of true
addition, subtraction, multiplication, and division. The approximations
appear to be very good, generally correct to within one unit in the eighth
decimal digit. Only the most sophisticated of all scientific and engineering
computations deal with numbers accurate to ·a·nything close to eight
decimal places. We might therefore presume that rounding errors would
provide no trouble in most practical computations. Moreover, the range
of magnitudes from 1 o- 5 o to 1 QH9 safely brackets the range of all important
physical and engineering constants, so that we might presume that we
would have no trouble with overflow or underflow.
Is the floating-point arithmetic system so good that we can use it with­
out fear to simulate the real number system of mathematics? Computer
designers certainly hoped so and chose the numbers of significant digits
and the exponent range with this expectation. However, the answer by
now is clear: We may not proceed without fear. There are real difficulties.
On the other hand, it is often possible to proceed with intelligence and
caution a,nd to get around the difficulties. But it has required an astonish­
ing amount of mathematical and computer analysis to get around the
difficulties, particularly in large problems. And, so far, we know well only
l how to handle relatively simple mathematical problems.
We shall illustrate some of the difficulties and their solution in the
1;,1

context of an elementary but important problem, the well-known quad­


fl
1:1

ratic equation of elementary algebra.


l
The Quadratic Equation
The reader will recall considerable time spent in the ninth grade, or
thereabouts, finding the two roots of equations like

6x 2 + Sx - 4 = 0. (1)

One first acquires some experience in factoring the quadratic. School


SOLVING A QUADRATIC EQUATION ON A COMPUTER 143

examples do factor with a frequency bewildering to anyone who has done


mathematics outside of school. For example, take

6x2 + Sx - 4 = (2x - 1)(3x + 4). (2)

If the left-hand side of Equation 2 is to be 0, then either 2x - 1 or 3x+ 4


must be 0. The two possibilities tell us that the roots of Equation 1 are
i and -f.
Factoring in whole numbers is not always possible and turns out to be
unnecessary, for one soon learns a formula that gives the two roots of any
quadratic equation without any factoring. The main result is the following,
the so-called quadratic formula.
If a, b, and c are any real numbers and if a � 0, the quadratic equation

ax2 +bx+ c = 0

is satisfied by exactly two values of x, namely,

-b + -Yb 2 - 4ac
X1 (3)
2a
and

-b - Vb 2 - 4ac
X2 = ·(4)
2e

As an example of the use of the qua�ratic formula, the roots of Equation


1 are

- -5 + v's - 4(6)(-4) -s+VW


2
X1
12 12

- -5 + 11 6 1
= -, X2
-s-VW
12 12 12

The roots agree, of course, with those found by factoring.


One great advantage of the quadratic formula is that it suggests· a
straightforward series of steps proceeding from the real numbers a, b, c to
the solutions x1 , x2.
Any such systematic process for computing some desired answer is
called an "algorithm." In an algorithm no guesses are allowed - one
proceeds directly from the data to the answer. The importance of algo­
rithms is that computers have been expressly designed to be able to carry
out algorithms and nothing but algorithms. That is to say, the logical
steps performed by a computer are exactly those of an algorithm.
Next we give a detailed algorithm for evaluation of the quadratic
formula (Equation 3). (It could be simplified.)
144 GEORGE E. FORSYTHE

Algorithm for computing one root x 1 of the quadratic equation ax 2 +


bx+ C = 0.
(i) Compute z = -b.
(ii) Compute y = b 2•
(iii) Compute w = 4a.
(iv) Compute v = we.
(v) Compute u = y - v.
(vi) Compute t =v;.
(vii) Computes = z + t.
(viii) Computer = 2a.
(ix) Compute xi = s/r.
Notes: 1. For simplicity, we assume here that u = b 2 - 4ac is not negativ6,
to avoid having to deal with imaginary numbers like V -1.
2. An algorithm for computing x2 requires the replacement of steps (vii)
. and (ix) by
(vii)' Computes' = z - t.
(ix)' Compute x2 = s'/r.

In mathematics the above algorithm is impliGitly understood to use


real numbers and to carry out with them exact arithmetic operations
including addition, subtraction, multiplication, division, and even extrac­
tion of the square root of u = b 2 - 4ac. As we showed earlier, a computer
(:annot carry out these exact arithmetic operations and, indeed, cannot
even hold all real numbers a, b, c. Thus, although a real digital computer
can carry out the exact logical steps of the algorithm, it must replace all
numbers by floating-point numbers and all arithmetic operations by
approximate operations.
The question, then, is this: Do the limitations of actual computer
floating-point systems make any appreciable difference in solving quad­
ratic equations?
The answer is : Sometimes yes and sometimes no. We shall give examples
to illustrate both cases.

Examples of the Quadratic Formula on a Computer


Example 1 6x 2 . + 5x - 4 = 0
For this example of Equation 1, the algorithm offers no difficulty to
a computer with the precision we have given except, possibly, for the
square root required in step (vi). Let us make the reasonable assumption
that we have a method (indeed, another algorithm) for computing square
roots with an error not exceeding 0.8 of a unit in the least significant
decimal place. In this case, we will find t = Vu = Vb 2 - 4ac t.o be
11.000000. Then we find that

x, = ( - s.+ 11.000 0.50000000,


SOLVING A QUADRATIC EQUATION ON A COMPUTER 145

a perfect result. The computation of x2 leads to no loss of accuracy until


the final division:

X2 = - 16.000000 /12.000000 = - 1.3333333,

as rounded on the computer. Since this is the correctly rounded value of


the true x2, we conclude that the computer algorithm has done as good a
job as it could possibly do.

Example 2
Before examining the computer solution, we note that the true solutions,
rounded to eleven significant decimals, are

X1 = 99999. 999990

and

X2 = 0.000010000000001.

Moreover, it can be shown that x 1 and x 2 are w_ell determined by the data
in that small changes of the coefficients (1, -10 5, 1) would cause only
slight changes in x1 and x2•
Now let us apply the algorithm and see what are the computed values
of x1 and x2. We have

a = 1.0000000 X 10 +00,
b - -1.0000000 X 1o + os,
C = 1.0000000 X 10+00.

First, to get x1:

z = -b � 1.0000000 X 10+05,
y = b 2 = LOOOOOOO X 10+ 10,
w = 4a = 4.0000000 X 10+00,
V = WC = 4.0000000 X 10+00,
u = y - V = 1.0000000 X 10+ 10,
t = Vu = 1.0000000 X 10+0 s,
s = z + t = 2.0000000 X 10+05,
r = 2a = 2.0000000 X 10 +00,
x1 = s/r = 1.0000000 X 10 + •
05

The step that calls for comment is the computation of u = y - v,· ··


where the value of v is completely lost in rounding the value of u to eight
decimals. The final answer x1 is correct to eight decimals.
We now compute x2:
146 GEORGE E. FORSYTHE

z = - b = 1.0000000 X 1 o+ 05,
y - b 2 = 1.0000000 X 10+ 10,
w 4a = 4.000_0000 X 10+00,
V = WC = 4.0000000 X 10+ 00,
u = y - v = 1.0000000 X 10+10,
t = Vu = 1.0000000 X 1o +05,
s' = z - t =· 0,
r - 2a = 2.0000000 X 10 + 0 �
x2 = s'/r = 0.

This time the computation of s' results in complete cancellation; sos'


and, hence, x2 are both 0. Thus, our algorithm has yielded a value of x2
that differs by approximately 10- 5 from the correct answer, and this might
be considered a rather small deviation. On the other hand, our computed
value of x2 has a relative error of 100 percent - not a single significant
digit is correct. Can this be considered a reasonable computer solution of
the quadratic?
A study of ways in which quadratics are applie_d_ leads to the conclusion
that the measure of accuracy should be that of relative error. As long as a
· root of a quadratic is well determined by the data and is in the range of
floating-point numbers, a good algorithm should give it correctly to several
or most of its leading digits, however large or small the root may be.
Thus, we must conclude that the computer application of our quadratic
algorithm for x2 gave us practically no useful information about the root
X2. It follows that the algorithm is not adequate for solving a quadratic
equation on a computer, because an adequate algorithm ought to work
in every case.

Example 3 6 X 10 30x 2 + 5 X 10 30x - 4 X 10 30 = 0.


This is simply Example 1, with all its coefficients a, b, c multiplied by
the factor 10 30• Thus, the roots are unchanged.
However, the algorithm breaks down at the second step, becausey = b 2
is truly 2.5 X 10 61, a number outside the range of floating-point numbers.
Therefore, the algorithm is again inadequate, though for a very trivial
reason. A simple scaling of the coefficients (e.g., division of the �quation
by 6 X 10 30) would prevent the overflow.

Example 4 10- 30x 2 - 1030x + 10 30 = 0.


Here the true roots are extremely close to 10 60 and 1. One of the roots
is outside the range of floating-point· numbers, and we could hardly
expect to get it from a computer algorithm. The problem is: Can a
reasonable computer algorithm get the root ri'ear 1?
Note that a simple scaling to make the first coefficient equal to 1 will
cause the second and third coefficients to overflow. Hence, a scaling that
SOLVING A QUADRATIC EQUATION ON A COMPUTER 147

helps cope with Example 3 will break down with Example 4. Certainly
our algorithm will not work.
Does the reader feel that equations-with such a large root will not occur
in practical computations? Let him be assured that they do. The final,
physically important result of a.computation is almost certain to lie safely
inside the range of floating-point numbers. InteMnediate results, however,
often have magnitudes smaller than 10- 50 or larger than 10 4 9•
Recently several computing experts agreed that one of the most serious
difficulties with many current computer systems is that they automatically
replace an underflowed answer by zero, without any warning message.
In such a system, 1o- 3 o X 1o- 3 o X 10 3 1 X 10 30 would be computed as 0
(because underflow would occur with the first multiplication step),
whereas 10- 30 X 10 3 1 X 10- 3 0 X 10 30 would be correctly computed as 10.

Example 5 x2 - 4.0000000x + 3.9999999 = 0.

The correctly rounded roots are, to 10 significant digits,

X1 = 2.000316228 and .. X2 = 1.999683772.

If we apply the algorithm, we find that

z = -b = 4.0000000,
y = b 2 = 16.000000,
w = 4a = 4.0000000,
V = WC = 16.000000,
U = y - V = 0,

t=Vu=O,
s - z + t = z - t = 4.0000000,
r - 2a = 2.0000000,
x1 - x2 = s/r = 2.0000000.

The computed roots are both in error by approximately 0.0003162.


That is, out of 7 computed Jigits to the right of the decimal point, only 3
are correct. Also, the computer mistakenly finds a double root instead of
two different roots.
The accuracy seems quite low. However, the roots of Example 5 actually
change very rapidly when the coefficients are changed. In fact, the two
computed roots, x1 = .x2 = 2.0000000, are the exact roots of the nearby
equation 0. 999999992x 2 - 3.999999968x + 3.999999968 = 0. Thus,
though x 1 and x2 are wrong roots of Example 5 by some 3162 units in their
last decimal place, they are true roots of an equation with a, b, c differing. . -
from those of Example 5 by no more than 0.8 of a unit in their last decimal
place.
Example 5 illustrates two different ways of measuring relative errors
148 GEORGE E. FORSYTHE

in any computation. In the so-called "forward" approach to relative


error, the computed roots x1 and x2 differ by a certain number of units
(here 3162) in the last place from_ the .true roots of the given equation. In
the so-called "backward" approach to relative error, the computed roots
x 1 and x2 are the exact roots of an equation with coefficients which differ
by no more than so many units (here 0.8) in the last place from th:ose of
the given equation. The forward rrieasure of error is perhaps more natura_l
and certainly traditional. The backward approach to error is more recent,
but in many contexts turns out to be considerably easier to analyze and
just as useful in practice. Backwards error analysis is one of the major
research ideas to be developed in computational mathematics since the
middle fifties. Cornelius Lanczos devised the backward approach in
another context in the 1940's. Wallace Givens exploited it in 1954 for
computing roots of certain equations. But James Wilkinson has done the
most in the years since 1958 to exploit it as a basis for analyzing errors in
floating-point computation on digital computers.
The reason that backwards error analysis is so useful is this: Some basic
properties on which algebra is based (the associa-tive and distributive
laws) fail to hold for floating-point arithmetic. Hence, a forward error
analysis, which is based directly on the floating-point operations, is
extremely difficult to carry out. On the other hand, backwards error
analysis interprets the result of each computer product, for example, as
the true product of two real numbers that differ very slightly (rom the
factors of the computer product. Thus, in backwards error analysis
one deals with true mathematical multiplication and addition, which are
associative and distributive. This permits analysis to be much more easily
carried out and often leads to closer bounds for the error.
This is not the place to develop these ideas further, but we hope to have
given the reader an inkling of why backwards analysis, when applicable,
is often so much more satisfactory.

Criteria for a Good Quadratic Equation Solver


The previous examples illustrate the behavior and misbehavior of the
usual quadratic algorithm. E�amples 2, 3, and 4 make it clear that for
computer application, the algorithm is not satisfactory for all cases and,
hence, is unacceptable. What do we really expect from a quadratic equa­
tion-solving algorithm for use on a computer?
Should we be content with the computer solution of Example 5, with
its error of 3162 units in x1 and x2, since the computed roots do satisfy an
equation that is so close to the given one?
If we didn't know how to do better, we might be quite content with the
results of Example 5 but certainly not with Example 2. Quadratic equa­
tions arise in many contexts of mathematics and computing. They are so
basic that we should like to be able to compute their roots with almost no
SOLVING A QUADRATIC EQUATION ON A COMPUTER 149

error for almost any equation whose coefficients are floating-point num­
bers. Such performance can be achieved, and it is essential to have such
algorithms in the computer library.- Then, when a quadratic equation
occurs in the midst of a complex and imperfectly understood computation,
we can be sure that the quadratic equation solver can be relied upon to do
its part automatically and well, so that we can concentrate attention on the
rest of the computation.
We want a quadratic equation solver that will accept any floating-point
numbers a, b, c, and compute close decimal approximations to any of the
roots x1, x2 that lie safely within the range of floating-point numbers. Any
computed root should have an error in the last decimal place not exceed­
ing, say, 10 units. If either x1 or x2 underflows, there should be a message
about what happened.
Such an algorithm has been devised by William Kahan of the Univer­
sity of Toronto. The most difficult matter to take care of is the possibility
of overflow or underflow. It will not be possible to describe the complete
algorithm, but we can give some of the more accessible ideas.
First, we discuss the steps taken to overcome the great inaccuracy in
root x2, as computed in Example 2. Iri step (vii)' of Example 2, we sub­
tracted two equal numbers, z and t, to get s' = 0. The true value of t
was not quite equal to z, because in step (v) the true u was not quite equ'al
to y. But t and z, like u and y, could not be distinguished with only 8
decimal digits at our disposal.
An easy cure for the difficulty is to use another method of computing
x2 which does not involve the subtraction of nearly equal numbers.
If a, b, c are any real numbers, and if a � 0 and c � 0, then the quad­
ratic equation

ax 2+bx+c = 0

is satisfied by exactly two values of x, namely,

2c
X1
-b (5)
v'b2 - 4ac
and
2c
X2
-b + v'b2 - 4ac (6)

Formulas 5 and 6 can be proved, for example, by first applying Formu­


las 3 and 4 to the following equivalent form of the given quadra!tc..
equation:

C (�) 2
+ b (�) + a - 0.
150 GEORGE E. FORSYTHE

Note that if b is negative, there is cancellation in Formula 4 for x2 but


not in Formula 6, and there is cancellation in Formula 5 for x 1 but not in
Formula 3. The reverse statements hold if b is positive. So, for any quad­
ratic equation in which neither a nor c is zero, one selects Formulas 3
and 6 when bis positive or zero and Formulas 4 and 5 when bis negative.
For Example 2, Formula 6 leads to the computer result that

a perfectly rounded root.


The inaccuracy of Example 5 cannot be so simply cured, because it is
inherent in working with only 8 decimals, as is revealed by the rapid
change of the roots with changes of a, b, c. The best known cure is to
identify the delicate part of the computation and use greater precision for
it. So Kahan's algorithm uses double precision (here 16 significant decimals)
in the computation of u = b2 - 4ac, followed by rounding to single
precision. The rest of the computation does not need extra precision and is
done in the normal way. There is a small penalty in the extra time re­
quired for that double precision computation, but it is a negligible part
of the total time, spent mostly on scaling and otherwise detecting and
correcting overflow or underflow possibilities.
Recomputation of x 1 in Example 5 looks like the following:

z = -b = 4.0000000,
y = b 2 = 16.0000000 0000000,
w = 4a = 4.0000000 0000000,
V = WC = 15.9999996 0000000,

U = y - V = 0.0000004 00000000 0000000


= 0.0000004 0000000, returning to single precision,
t - Vu = 0.0006324 5553,
s = z + t = 4.0006325,
r = 2a = 2.0000000,
x 1 = s/r = 2.0003163, rounding up.

Note that x1 is in error by only 0.72 of a unit in the last decimal place.
We shall not discuss scaling and dealing with possible overflow· and
underflow. The details are many and technical, and they depend inti­
mately on particular features of the computer on which they are carried
out. They are extremely important to actual computing but less generally
interesting than the ideas just presented. One of the obvious features
involves testing whether any or all of a, b, or c are zero.

Conclusion
We have described some of the pitfalls of applying the· quadratic
formula blindly with an automatic digital computer. We have given
SOLVING A QUADRATIC EQUATION ON A COMPUTER 151

sound cures for two of the pitf�lls and indicated what other work has been
done to create a first-class algorithm for solving a quadratic equation.
The quadratic equation is one of .the simplest mathematical entities
and is solved almost everywhere in applied mathematics. Its actual use
on a computer might be expected to be one of the best understood of
computer algorithms. Indeed it is not, and some more complex compu­
tations were studied first. The fact that the obvious algorithm is so subject
to rounding error is not very widely known by computer users or writers
of elementary textbooks on computing methods or, certainly, most writers
of mathematics textbooks. Of course, it is familiar to specialists in numer­
ical analysis. Thus, even in this elementary prol:5lem, we are working at
the frontiers of common computing knowledge.
The majority of practical computations are understood far less well
than the quadratic equation. A very great deal of difficult research and
development remains to be done before computers will be used as wisely
and well as they can be. Almost certainly various parts of the computations
for weather forecasting contain pitfalls like those of the quadratic equation,
and ignorance of these pitfalls is introducing computational errors that
are interfering with progress in weather forecasting. The same can be said
about most other nontrivial fields of scientific computation.
The moral of the story is that users of computers for mathematical
problems require some knowledge of numerical mathematics. It is not
sufficient to learn some programming language and then simply translate
formulas from a textbook of pure mathematics into the language of a
computer. The formulas and algorithms to be found in most mathematics
texts were devised for the exact · arithmetic of the real number system.
In order to understand the behavior of the formulas when they are used
with the approximate arithmetic of computers, the would-be scientific
computer must consult people and writings specifically concerned with
machine computation.
A further moral is that teachers of arithmetic and algebra should
consider the presentation of their subject in the light of its practical
application. The quadratic formula is very important for understanding
quadratic equations and should be taught. But why hide the fact that it
will not stand up to practical application on computers? In days· gone
by, when few quadratic equations were actually solved, it hardly mat­
tered. But today, when quadratic equations are solved wholesale inside
computers, textbook writers should also present material that is not only
theoretically correct and easily taught but also easily transferable to
practical use. This is a real challenge. In the last analysis, the challenge
will be met by persons who have rich backgrounds in both mathem<1tical
theory and practical application. This is perhaps the most convincing
reason for maintaining the mathematical sciences as a unity.
152 GEORGE E. FORSYTHE

BIBLIOGRAPHY
L. F. Richardson, Weather Prediction by Numerical Process (1922); Reprinted by
Dover Publications, New York, 1965._
I. A. Stegun and M. Abramowitz, "Pitfalls in Computation," SIAM Journal, 4,
1956, 207-219.
R. W. Hamming, Numerical Methods for Scientists and Engineers, McGraw-Hill, New
York, 1962.
E. L. Stiefel, An Introduction to Numerical Mathematics, Academic Press, New York,.
1963.

BIOGRAPHICAL NOTE
George E. Forsythe heads the Computer Science Department at Stanford Uni­
versity. When he founded it in 1961, it was one of the first such departments in a
United States university. From then until 1965, he also directed Stanford's
Computation Center. Forsythe served as president of the Association for Com­
puting Machinery. His interest in computing began early, when, as a seventh­
grader, he tried using a hand-cranked desk calculator to find the decimal expan­
sion of 10,000/7699. He wanted to see how the digits repeated. In World War II,
he encountered more important computation problems as an Army Air Force
meteorology officer. He first formally entered the then-nascent field of computer
sciences while associated with the Institute for Numerical Analysis of the National
Bureau of Standards, Los Angeles.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy