{VERSION 1 0 "X11/Motif" "1.0"}{GLOBALS 3 1}{FONT 0 "-adobe-helve
tica-bold-r-normal--*-140-*" "helvetica" "Helvetica-Bold" 8 14 0
"Helvetica-Bold" 12}{FONT 1 "-adobe-times-medium-r-normal--*-140-
*" "times" "Times-Roman" 4 14 64 "Times-Roman" 12}{FONT 2 "-adobe
-courier-medium-r-normal--*-140-*" "courier" "Courier" 4 14 192 "
Courier" 12}{SCP_R 1 0 128{COM_R 2 0{TEXT 1 43 "Significant Digit
s and Interval Arithmetic\015"}}{COM_R 3 0{TEXT 1 272 "This works
heet is designed to accompany Chapter 3 of \"Introduction to Scie
ntific Programming: Computational Problem Solving Using Maple and
C\" by Joseph L. Zachary. In it, we will use Maple to explore t
he methods of significant digits and interval arithmetic. (30Sep
96)\015"}}{SEP_R 4 0}{COM_R 5 0{TEXT 1 287 "\015Getting Started. \+
To use this worksheet you will need to use some extensions to Ma
ple that we have created. Read in our interval arithmetic packag
e by evaluating the Maple command below. (You will need to have \+
first installed our custom Maple library and configured Maple to \+
use it.)\012"}}{INP_R 6 0 "> "{TEXT 0 15 "with(interval);"}}
{COM_R 7 0{TEXT 1 0 ""}}{SEP_R 8 0}{SEP_R 9 0}{COM_R 10 0{TEXT 1
299 "\015Counting the Digits of a Mantissa. Let's begin by makin
g sure that you know how to count the number of digits in the man
tissa of a floating-point number. We have created a function \"d
igitCount\" that takes a floating-point number as its parameter a
nd returns the number of digits in its mantissa.\015"}}{SEP_R 11
0}{COM_R 12 0{TEXT 1 137 "\015In the absence of trailing and lead
ing zeros, it is straightforward to count digits. Here we see th
at 1523. has a four-digit mantissa.\012"}}{INP_R 13 0 "> "{TEXT 0
18 "digitCount(1523.);"}}{COM_R 14 0{TEXT 1 108 "\015Here is ano
ther way to write 1523. The value of the exponent does not chang
e the significant digit count.\012"}}{INP_R 15 0 "> "{TEXT 0 20 "
digitCount(15.23e2);"}}{COM_R 16 0{TEXT 1 26 "\015And here is a t
hird way.\012"}}{INP_R 17 0 "> "{TEXT 0 20 "digitCount(.1523e4);"
}}{COM_R 18 0{TEXT 1 105 " \012We have just seen three different \+
ways to write 1523, and each example had four digits in its manti
ssa."}}{COM_R 19 0{TEXT 1 121 "\015Trailing zeros are not ignored
when counting digits. For example, notice the differences among
the following examples.\012"}}{INP_R 20 0 "> "{TEXT 0 18 "digitC
ount(5000.);"}}{INP_R 21 0 "> "{TEXT 0 17 "digitCount(50e2);"}}
{INP_R 22 0 "> "{TEXT 0 17 "digitCount(.5e4);"}}{COM_R 23 0{TEXT
1 120 "\012Even though all three of these are ways of writing 500
0, all three have different numbers of digits in their mantissas.
"}}{COM_R 24 0{TEXT 1 114 "\015Leading zeros, unlike trailing zer
os, are unimportant and can be disregarded when counting digits i
n a mantissa.\012"}}{INP_R 25 0 "> "{TEXT 0 16 "digitCount(.51);"
}}{INP_R 26 0 "> "{TEXT 0 20 "digitCount(.0051e2);"}}{INP_R 27 0
"> "{TEXT 0 22 "digitCount(.000051e4);"}}{COM_R 28 0{TEXT 1 88 "\
012All three are ways of writing .51, and all three are written w
ith two-digit mantissas. "}}{COM_R 29 0{TEXT 1 83 "\015The last e
xample shows that leading zeros are ignored but trailing zeros ar
e not.\012"}}{INP_R 30 0 "> "{TEXT 0 22 "digitCount(.005100e2);"}
}{COM_R 31 0{TEXT 1 0 ""}}{SEP_R 32 0}{COM_R 33 0{TEXT 1 147 "\01
5Exercises. Following are some calls to digitCount. See if you \+
can predict each result before looking at it. Try some of you ow
n examples, too.\012"}}{INP_R 34 0 "> "{TEXT 0 18 "digitCount(100
.0);"}}{INP_R 35 0 "> "{TEXT 0 21 "digitCount(00002.10);"}}{INP_R
36 0 "> "{TEXT 0 20 "digitCount(.0001e4);"}}{INP_R 37 0 "> "
{TEXT 0 21 "digitCount(1.0001e4);"}}{COM_R 38 0{TEXT 1 0 ""}}
{SEP_R 39 0}{SEP_R 40 0}{COM_R 41 0{TEXT 1 287 "\015Rounding Floa
ting-Point Numbers. Next let's make sure that you understand abo
ut rounding. When we talk about \"rounding a number to four digi
ts,\" what we mean is \"find the closest number with a four-digit
mantissa.\" The function roundFloat will round to a specified n
umber of digits.\015"}}{SEP_R 42 0}{COM_R 43 0{TEXT 1 31 "\015If \+
we round 16. to two digits\012"}}{INP_R 44 0 "> "{TEXT 0 19 "roun
dFloat(16., 2);"}}{COM_R 45 0{TEXT 1 89 "\012we get back 16, sinc
e it already consists of two digits. If we round if to one digit
,\015 "}}{INP_R 46 0 "> "{TEXT 0 19 "roundFloat(16., 1);"}}{COM_R
47 0{TEXT 1 49 "\012we get back 20. If we round it to three dig
its\012"}}{INP_R 48 0 "> "{TEXT 0 19 "roundFloat(16., 3);"}}
{COM_R 49 0{TEXT 1 87 "\012we still get back 16, but this time it
is written with three digits in the mantissa. "}}{COM_R 50 0
{TEXT 1 35 "\015If we round .000244 to two digits\012"}}{INP_R 51
0 "> "{TEXT 0 23 "roundFloat(.000244, 2);"}}{COM_R 52 0{TEXT 1
172 "\012we get .00024 as the result. Notice how the .000244 was
rounded down, because that was where the closest two-digit manti
ssa was. If we round .000246, on the other hand,\012"}}{INP_R 53
0 "> "{TEXT 0 23 "roundFloat(.000246, 2);"}}{COM_R 54 0{TEXT 1
60 "\012it is rounded up. If a number falls exactly in the middl
e\012"}}{INP_R 55 0 "> "{TEXT 0 23 "roundFloat(.000245, 2);"}}
{COM_R 56 0{TEXT 1 69 "\012Maple rounds up, although it could jus
t as well have rounded down. \015"}}{SEP_R 57 0}{COM_R 58 0{TEXT
1 144 "\015Exercises. Here are a few more examples. Try to pred
ict the answer before\012having Maple evaluate it. Try out some \+
of your own examples, too.\012"}}{INP_R 59 0 "> "{TEXT 0 20 "roun
dFloat(123., 2);"}}{COM_R 60 0{TEXT 1 0 ""}}{INP_R 61 0 "> "{TEXT
0 20 "roundFloat(1e10, 4);"}}{COM_R 62 0{TEXT 1 0 ""}}{INP_R 63
0 "> "{TEXT 0 20 "roundFloat(1.51, 1);"}}{COM_R 64 0{TEXT 1 0 ""}
}{INP_R 65 0 "> "{TEXT 0 24 "roundFloat(.0002345, 1);"}}{COM_R 66
0{TEXT 1 0 ""}}{INP_R 67 0 "> "{TEXT 0 25 "roundFloat(15555550.,
2);"}}{COM_R 68 0{TEXT 1 0 ""}}{INP_R 69 0 "> "{TEXT 0 25 "round
Float(15444449., 2);"}}{COM_R 70 0{TEXT 1 0 ""}}{SEP_R 71 0}
{SEP_R 72 0}{COM_R 73 0{TEXT 1 715 "\015Significant Digits. No m
atter how sophisticated the measuring device, any physical measur
ement is an approximation. When we write a measurement in scient
ific notation, the number of digits in the mantissa conveys cruci
al information. For example, when we say that a measurement is \
"1500.\" (four significant digits), we are asserting that the tru
e value, when rounded off to four digits, will be equal to 1500. \+
When we say that a measurement is \"1.5e3\" (two significant dig
its), we are asserting that the true value, when rounded off to t
wo digits, will be equal to 1500. There's a big difference in th
ese two cases---assuming that both measurements are correct, the \+
first is much more precise than the second."}}{COM_R 74 0{TEXT 1
219 "\015To help understand what's going on, we'll use the functi
on \"findRange\". If we give it a measurement written to some nu
mber of significant digits, it will give us back the range in whi
ch the true measurement must lie.\015"}}{SEP_R 75 0}{COM_R 76 0
{TEXT 1 83 "\015For eample, the only numbers which, when rounded \+
to four digits, will equal 1500\015 "}}{INP_R 77 0 "> "{TEXT 0 17
"findRange(1500.);"}}{COM_R 78 0{TEXT 1 121 "\012lie in the rang
e from 1499.5 to 1500.5. By comparison, the numbers which, when \+
rounded to two digits, will equal 1500 \015"}}{INP_R 79 0 "> "
{TEXT 0 17 "findRange(1.5e3);"}}{COM_R 80 0{TEXT 1 188 "\012lie i
n the much broader range from 1450 to 1550. The first measuremen
t, which was presumably made by a much more precise instrument th
an the second one, conveys more precise information."}}{COM_R 81
0{TEXT 1 51 "\015Here are a few more examples. The measurement 1
,\012"}}{INP_R 82 0 "> "{TEXT 0 14 "findRange(1.);"}}{COM_R 83 0
{TEXT 1 160 "\012written with only one digit, represents a true m
easurements that lies anywhere from .5 to 1.5. But if we measure
more precisely and claim 1.00 as our result,\012"}}{INP_R 84 0 "
> "{TEXT 0 16 "findRange(1.00);"}}{COM_R 85 0{TEXT 1 45 "\012we'v
e pinned things down much more closely.\015"}}{SEP_R 86 0}{COM_R
87 0{TEXT 1 168 "\015Exercises. Here are some for you to try out
. As before, try to figure out what the answer should be before \+
asking Maple to evaluate them. And try some of your own.\012"}}
{INP_R 88 0 "> "{TEXT 0 18 "findRange(1.23e5);"}}{INP_R 89 0 "> "
{TEXT 0 17 "findRange(.0001);"}}{INP_R 90 0 "> "{TEXT 0 18 "findR
ange(7.0001);"}}{INP_R 91 0 "> "{TEXT 0 18 "findRange(19.2e5);"}}
{COM_R 92 0{TEXT 1 0 ""}}{SEP_R 93 0}{SEP_R 94 0}{COM_R 95 0{TEXT
1 327 "\015Interval Arithmetic. We have now discussed how to co
unt the number of digits in a mantissa, what it means to round a \+
number to some number of digits, and the importance of writing ph
ysical measurements so as to indicate the number of significant d
igits. We can now consider what it means to do arithmetic with m
easurements.\015"}}{SEP_R 96 0}{COM_R 97 0{TEXT 1 90 "\015Suppose
that we multiply 3.6 and 4.5, both of which are known to two sig
nificant digits.\012"}}{INP_R 98 0 "> "{TEXT 0 10 "3.6 * 4.5;"}}
{COM_R 99 0{TEXT 1 455 "\012Maple gives the answer with a four-di
git mantissa, but that doesn't mean that all of the digits in the
product are meaningful. The usual rule of thumb is that a produ
ct such as this should be rounded to the same number of digits as
there are in the least precise measurement involved in the calcu
lation. This is called the method of significant digits. Since \+
both of our measurements here have two significant digits, we sho
uld round the 16.20 to 16.\015"}}{COM_R 100 0{TEXT 1 178 "If we t
ake the resulting 16 at face value, we might be tempted to conclu
de that the true product must lie between 15.5 and 16.5. But we \+
can put exact bounds on the true product."}}{COM_R 101 0{TEXT 1
141 "\015The smallest value the product can possibly take is if t
he 3.6 is actually 3.55 and the 4.5 is actually 4.45. In this ca
se, the product is\012"}}{INP_R 102 0 "> "{TEXT 0 12 "3.55 * 4.45
;"}}{COM_R 103 0{TEXT 1 145 "\012The largest value that the produ
ct can possibly take is if the 3.6 is actually 3.65 and the 4.5 i
s actually 4.55. In this case, the product is\012"}}{INP_R 104 0
"> "{TEXT 0 12 "3.65 * 4.55;"}}{COM_R 105 0{TEXT 1 131 "\012Assu
ming that the measurements 3.6 and 4.5 are both accurate to two d
igits, the true answer must lie between 15.7975 and 16.6075. "}}
{COM_R 106 0{TEXT 1 291 "\015This approach is called the method o
f interval arithmetic. The bounds on the true answer that we obt
ained with interval arithmetic are slightly different than the on
es obtained via the method of significant digits. This is becaus
e the method of significant digits is only a rule of thumb."}}
{COM_R 107 0{TEXT 1 111 "\015The method of significant digits get
s less useful as more numbers become involved in a calculation. \+
Consider\012"}}{INP_R 108 0 "> "{TEXT 0 20 "(3.61 * 4.5) / 17.7;"
}}{COM_R 109 0{TEXT 1 251 " \012Here we get a ten-digit answer. \+
The method of significant digits would have us round this to two \+
digits, obtaining .92 as our answer, meaning that the true answer
should lie between .915 and .925. By interval arithmetic we obt
ain the low bound as\012"}}{INP_R 110 0 "> "{TEXT 0 23 "(3.605 * \+
4.45) / 17.75;"}}{COM_R 111 0{TEXT 1 23 "\012and the high bound a
s\012"}}{INP_R 112 0 "> "{TEXT 0 23 "(3.615 * 4.55) / 17.65;"}}
{COM_R 113 0{TEXT 1 120 "\012The true answer thus lies between .9
03 and .932. The method of significant digits would have had us \+
believe otherwise."}}{COM_R 114 0{TEXT 1 324 "\015It can get rath
er tricky to compute bounds via interval arithmetic. To compute \+
the low bound in the last example, we had to use the smallest pos
sible values for the measurements in the numerator and the larges
t possible values for the measurements in the denominator, and th
en reverse the process to obtain the high bound."}}{COM_R 115 0
{TEXT 1 373 "\015The final function provided by the library that \+
you loaded at the beginning of this worksheet, \"intervalEval\", \+
will do interval arithmetic for us. We give it as its argument t
he expression that we wish to evaluate with the measurements encl
osed in backquotes. (The backquote key is in the upper left or right
corner of most keyboards.) With the example above, we simply do
\012"}}{INP_R 116 0 "> "{TEXT 0 38 "intervalEval(`3.61` * `4.5` /
`17.7`);"}}{COM_R 117 0{TEXT 1 59 "\012and we get back the inter
val in which the result must lie."}}{COM_R 118 0{TEXT 1 216 "\015
If a computation involves a number that is NOT a measurement, we\
012simply leave off the backquotes and write it as usual. For ex
ample, the calculation of the circumference of the earth from Cha
pter 3 of the text is \015"}}{INP_R 119 0 "> "{TEXT 0 40 "interva
lEval(360 / 7.2 * 50e2 * 0.1575);"}}{COM_R 120 0{TEXT 1 95 "\012W
e get an exact answer because we didn't put the measurements in b
ackquotes. When we do that\012"}}{INP_R 121 0 "> "{TEXT 0 50 "in
tervalEval((360 / `7.2`) * (`50e2` * `0.1575`));"}}{COM_R 122 0
{TEXT 1 35 "\012we get bounds on the true answer.\015"}}{SEP_R
123 0}{COM_R 124 0{TEXT 1 652 "\015Exercises. Doing interval ari
thmetic can take a big of ingenuity. Given the ranges in which s
everal the measurements involved in a calculation must lie, you m
ust figure out what is the smallest possible answer and what is t
he largest possible answer. If you don't have access to Maple an
d our library functions, it can take a bit of thought. As a fina
l exercise, we will give some expressions. Use interval arithmet
ic to calculate the interval in which the true value must lie, an
d compare it to the result predicted by the method of significant
digits. Then check your answer with \"intervalEval\". As alway
s, try out some examples of your own.\012"}}{INP_R 125 0 "> "
{TEXT 0 20 "2.5e2 * 2.4e1 + 11.;"}}{INP_R 126 0 "> "{TEXT 0 18 "s
qrt(45.1) * .001;"}}{INP_R 127 0 "> "{TEXT 0 19 "4.5^3.001 + 100.
00;"}}{COM_R 128 0{TEXT 1 0 ""}}{SEP_R 129 0}}{END}