Lies My Calculatorand Computer Told Me2■

LIES MY CALCULATOR AND COMPUTER TOLD ME

Lies My Calculator and Computer Told Me▲ See Section 1.4 for a discussion ofgraphing calculators and computers withgraphing software.

●

●

●

●

●

●

●

●

A wide variety of pocket-size calculating devices are currently marketed. Some canrun programs prepared by the user; some have pre-programmed packages for frequently used calculus procedures, including the display of graphs. All have certain
limitations in common: a limited range of magnitude (usually less than 10100 for calculators) and a bound on accuracy (typically eight to thirteen digits).
A calculator usually comes with an owner’s manual. Read it! The manual will tell
you about further limitations (for example, for angles when entering trigonometricfunctions) and perhaps how to overcome them.
Program packages for microcomputers (even the most fundamental ones, which
realize arithmetical operations and elementary functions) often suffer from hidden
flaws. You will be made aware of some of them in the following examples, and you
are encouraged to experiment using the ideas presented here.
Preliminary Experiments with your Calculator or Computer

To have a first look at the limitations and quality of your calculator, make it compute2  3. Of course, the answer is not a terminating decimal so it can’t be represented
exactly on your calculator. If the last displayed digit is 6 rather than 7, then your calculator approximates 23 by truncating instead of rounding, so be prepared for slightly
greater loss of accuracy in longer calculations.
Now multiply the result by 3; that is, calculate 2  3  3. If the answer is 2, thensubtract 2 from the result, thereby calculating 2  3  3  2. Instead of obtaining
0 as the answer, you might obtain a small negative number, which depends on the construction of the circuits. (The calculator keeps, in this case, a few “spare” digits thatare remembered but not shown.) This is all right because, as previously mentioned, thefinite number of digits makes it impossible to represent 2  3 exactly.
2A similar situation occurs when you calculate (s6 )  6. If you do not obtain 0,
the order of magnitude of the result will tell you how many digits the calculator uses
internally.
Next, try to compute 15 using the y x key. Many calculators will indicate an error
because they are built to attempt e 5 ln1. One way to overcome this is to use the factthat 1k  cos k whenever k is an integer.
Calculators are usually constructed to operate in the decimal number system. In
contrast, some microcomputer packages of arithmetical programs operate in a numbersystem with base other than 10 (typically 2 or 16). Here the list of unwelcome tricks
your device can play on you is even larger, since not all terminating decimal numbers
are represented exactly. A recent implementation of the BASIC language shows (indouble precision) examples of incorrect conversion from one number system intoanother, for example,?

8  0.1  0.79999 99999 99999 9whereas?
19  0.1 1.90000 00000 00001

Yet another implementation, apparently free of the preceding anomalies, will not
calculate standard functions in double precision. For example, the number  4  tan11, whose representation with sixteen decimal digits should be
3.14159 26535 89793, appears as 3.14159 29794 31152; this is off by more than

LIES MY CALCULATOR AND COMPUTER TOLD ME◆

33  107. What is worse, the cosine function is programmed so badly that its“cos” 0  1  223. (Can you invent a situation when this could ruin your calculations?) These or similar defects exist in other programming languages too.
The Perils of Subtraction

You might have observed that subtraction of two numbers that are close to each otheris a tricky operation. The difficulty is similar to this thought exercise: Imagine that you
walk blindfolded 100 steps forward and then turn around and walk 99 steps. Are you
sure that you end up exactly one step from where you started?
The name of this phenomenon is “loss of significant digits.” To illustrate, let’s
calculate
8721s3  10,681s2
The approximations from my calculator are
8721s3  15105.21509

and10,681s2  15105.21506

and so we get 8721s3  10,681s2  0.00003. Even with three spare digits exposed,
the difference comes out as 0.00003306. As you can see, the two ten-digit numbers
agree in nine digits that, after subtraction, become zeros before the first nonzero digit.
To make things worse, the formerly small errors in the square roots become more visible. In this particular example we can use rationalization to write
8721s3  10,681s2 

18721s3  10,681s2(work out the details!) and now the loss of significant digits doesn’t occur:1
 0.00003310115
8721s3  10,681s2

to seven digits(It would take too much space to explain why all seven digits are reliable; the subject
numerical analysis deals with these and similar situations.) See Exercise 7 for anotherinstance of restoring lost digits.
Now you can see why in Exercises 2.2 your guess at the limit of tan x  xx 3 wasbound to go wrong: tan x becomes so close to x that the values will eventually agree
in all digits that the calculator is capable of carrying. Similarly, if you start with justabout any continuous function f and try to guess the value off x  limhl0f x  h  f xhlong enough using a calculator, you will end up with a zero, despite all the rules inChapter 3!
Where Calculus is More Powerful than Calculators and Computers

One of the secrets of success of calculus in overcoming the difficulties connected withsubtraction is symbolic manipulation. For instance, a  b  a is always b, although
the calculated value may be different. Try it with a  10 7 and b  s2  105.
Another powerful tool is the use of inequalities; a good example is the Squeeze Theo-4■

LIES MY CALCULATOR AND COMPUTER TOLD ME

rem as demonstrated in Section 2.3. Yet another method for avoiding computationaldifficulties is provided by the Mean Value Theorem and its consequences, such as
l’Hospital’s Rule (which helps solve the aforementioned exercise and others) andTaylor’s Inequality.
The limitations of calculators and computers are further illustrated by infiniteseries. A common misconception is that a series can be summed by adding terms until
there is “practically nothing to add” and “the error is less than the first neglectedterm.” The latter statement is true for certain alternating series (see the AlternatingSeries Estimation Theorem) but not in general; a modified version is true for anotherclass of series (Exercise 10). As an example to refute these misconceptions, let’s consider the series
1n1.001n1which is a convergent p-series ( p  1.001 1). Suppose we were to try to sum thisseries, correct to eight decimal places, by adding terms until they are less than 5 in theninth decimal place. In other words, we would stop when
1n1.001

0.00000 0005

that is, when n  N  196,217,284. (This would require a high-speed computer andincreased precision.) After going to all this trouble, we would end up with the approximating partial sumN

11.001nn1SN  

19.5

But, from the proof of the Integral Test, we have1

nn11.001

dx

y x
11.001

 1000Thus, the machine result represents less than 2% of the correct answer!
Suppose that we then wanted to add a huge number of terms of this series, say, 10100
terms, in order to approximate the infinite sum more closely. (This number 10100,
called a googol, is outside the range of pocket calculators and is much larger than thenumber of elementary particles in our solar system.) If we were to add 10100 terms of
the above series (only in theory; a million years is less than 10 26 microseconds), wewould still obtain a sum of less than 207 compared with the true sum of more than
1000. (This estimate of 207 is obtained by using a more precise form of the Integral
Test, known as the Euler-Maclaurin Formula, and only then using a calculator. The
formula provides a way to accelerate the convergence of this and other series.)
If the two preceding approaches didn’t give the right information about the accuracy of the partial sums, what does? A suitable inequality satisfied by the remainderof the series, as you can see from Exercise 6.
Computers and calculators are not replacements for mathematical thought. They
are just replacements for some kinds of mathematical labor, either numerical or symbolic. There are, and always will be, mathematical problems that can’t be solved by acalculator or computer, regardless of its size and speed. A calculator or computer does
stretch the human capacity for handling numbers and symbols, but there is still considerable scope and necessity for “thinking before doing.”

LIES MY CALCULATOR AND COMPUTER TOLD MEExercises

●

●

●

●

●

●

●

●

●

lim

xl0

1
1
 2
sin2x
x



2. Guess the value oflim

●

●

●

●

●

●

●

●

●

●

●

●

●

●

ln1  hhy

N1f x dx

bers beyond the calculator range. Show that the maximum
value of the function

NnN17. Archimedes found an approximation to 2 by considering(a) Carry out the calculations and compare with the value ofp from more accurate sources, say p  192 sin96.
How many digits did you lose?
(b) Perform rationalization to avoid subtraction of approximate numbers and count the exact digits again.
8. This exercise is related to Exercise 2. Suppose that yourcomputing device has an excellent program for theexponential function expx  e x but a poor program forln x. Use the identity

x2
1.0001 xln a  b  ln 1 124

is greater than 10 . [Hint: Use logarithms.] What is thelimit of f x as x l ?
4. What is a numerically reliable expression to replaces1  cos x, especially when x is a small number? You willneed to use trigonometric identities. (Recall that some computer packages would signal an unnecessary error condition,or even switch to complex arithmetic, when x  0.)

D  ln ln10  1  ln ln10 
9on your calculator. These numbers are so close together thatyou will likely obtain 0 or just a few digits of accuracy.
However, we can use the Mean Value Theorem to achievemuch greater accuracy.
(a) Let f x  ln ln x, a  10 9, and b  10 9  1. Then theMean Value Theorem givesf b  f a  f cb  a  f cb. Since f  is decreasing, we havef b. Use this to estimate the valuea  ebeb

and Taylor’s Inequality to improve the accuracy of ln x.
9. The cubic equationx 3  px  q  0
where we assume for simplicity that p 0, has a classicalsolution formula for the real root, called Cardano’s formula:x

5. Try to evaluate9 f n y f x dx

p  96 s2  s2  s2  s2  s3

3. Even innocent-looking calculus problems can lead to num-f x n1.001, studied in the text, exactly how
many terms do we need (in theory) to make the error lessthan 5 in the ninth decimal place? You can use the inequalities from the proof of the Integral Test:

the perimeter p of a regular 96-gon inscribed in a circle ofradius 1. His formula, in modern notation, isand determine when to stop guessing before the loss of significant digits destroys your result. This time the detrimental
subtraction takes place inside the machine; explain how(assuming that the Taylor series with center a  1 is used toapproximate ln x). Then find the precise answer using anappropriate calculus method.

where a cf a f c
of D.

●n1

6. For the series

and determine when to stop guessing before the loss of significant digits destroys your result. (The answer will dependon your calculator.) Then find the precise answer using anappropriate calculus method.

hl0●(b) Use the Mean Value Theorem a second time to discover
why the quantities f a and f b in part (a) are soclose to each other.

A Click here for answers.
1. Guess the value of●5◆

13





27q  s729q 2  108p32

27q  s729q 2  108p3
2

13



13

For a user of a pocket-size calculator, as well as for an inexperienced programmer, the solution presents several stumbling blocks. First, the second radicand is negative and thefractional power key or routine may not handle it. Next,
even if we fix the negative radical problem, when q is small
in magnitude and p is of moderate size, the small number x
is the difference of two numbers close to sp3.
(a) Show that all these troubles are avoided by the formulax9qa 23  3p  9p2a23

6■

LIES MY CALCULATOR AND COMPUTER TOLD ME

wherea 27 q  s729q 2  108p 3
2

and recall from our study of Taylor and Maclaurin series
that111
1!
2!
nHint: Use the factorization formulaAB

A3  B 3A  AB  B 2

converges to e  1 as n l . The expression in square
brackets converges to c  e  1, a nonzero number,which gets multiplied by a fast-growing factor n!. We conclude that even if all further calculations (after entering a 0)
were performed without errors, the initial inaccuracy would
cause the computed sequence a n  to diverge.

2(b) Evaluateu

4(2  s5 ) 23  1  (2  s5 )23

If the result is simple, relate it to part (a), that is, restore
the cubic equation whose root is u written in this form.

12. (a) A consolation after the catastrophic outcome of Exer-cise 11: If we rewrite the reduction formula to read

10. (a) Consider the power series
xnnn1 100  1f x  a n1 

we can use the inequality used in the squeeze argument
to obtain improvements of the approximations of a n.
Try a 20 again using this reverse approach.
(b) We used the reversed reduction formula to calculatequantities for which we have elementary formulas. To
see that the idea is even more powerful, develop it forthe integrals

It is easy to show that its radius of convergence isr  100. The series will converge rather slowly atx  99: find out how many terms will make the error
less than 5  107.
(b) We can speed up the convergence of the series inpart (a). Show thatx
f100  xf x 1  ann

 x
100

1yx

n

0

and find the number of the terms of this transformed
series that leads to an error less than 5  107.
[Hint: Compare with the series n1 x n100 n , whosesum you know.]e1x dx

where is a constant, 01, and n  0, 1, . . . .
For such the integrals are no longer elementary (notsolvable in “finite terms”), but the numbers can becalculated quickly. Find the integrals for the particular
choice  13 and n  0, 1, . . . , 5 to five digits ofaccuracy.

11. The positive numbers
1a n  y e1xx n dx
0

13. An advanced calculator has a key for a peculiar function:can, in theory, be calculated from a reduction formulaobtained by integration by parts: a 0  e  1,a n  na n1  1. Prove, using 1 e1x e and the Squeeze
Theorem, that lim n l  a n  0. Then try to calculate a20 fromthe reduction formula using your calculator. What wentwrong?
The initial term a 0  e  1 can’t be represented exactly
in a calculator. Let’s call c the approximation of e  1 that
we can enter. Verify from the reduction formula (by observing the pattern after a few steps) thatan  c Answers
11. 3

3. 0

111!
2!

●

●●

●1n!

●

5. (a) 4.82549424  1011
●Ex 

●●if x  0

After so many warnings about the subtraction of closenumbers, you may appreciate that the definitionsinh x  12 e x  ex gives inaccurate results for small x,
where sinh x is close to x. Show that the use of theaccurately evaluated function Ex helps restore theaccuracy of sinh x for small x.

n!

●if x  0

1ex  1x●●●9. (b) 1, x 3  3x  4  0

●

●

●

●

●

●

●

●

●

●●●

●

●