









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










1999 - 2006^
Dianne P. O'Leary
1
1999 - 2006^
Dianne P. O'Leary
2
1999 - 2006^
Dianne P. O'Leary
3
1999 - 2006^
Dianne P. O'Leary
4
1999 - 2006^
Dianne P. O'Leary
5
1999 - 2006^
Dianne P. O'Leary
6
1999 - 2006^
Dianne P. O'Leary
7
limit^ (as n becomes infinite) of some function G(n).Can’t take this limit on a computer, so decide to use G(150).^ G(1), G(2),
1999 - 2006^
Dianne P. O'Leary
8
π. Approximate it by 3.1415926. 3 1 4 1
1999 - 2006^
Dianne P. O'Leary
13
1999 - 2006^
Dianne P. O'Leary
14
How integers are stored in computers:Each^ word
(storage location) in a machine contains a fixed number of digits.Example: A machine with a 6-digit word might represent
1985 as^0
1999 - 2006^
Dianne P. O'Leary
15
Most calculators use
decimal (base 10)
representation.
Each digit is an integer between 0 and 9.The value of the number is1 x 10 + 9 x 10 + 8 x 10 + 5 x 10
1999 - 2006^
Dianne P. O'Leary
16
Most computers use
binary (base 2)
representation.
Each digit is the integer 0 or 1.If the number above is binary, its value is1 x 2 + 0 x 2 + 1 x 2 + 1 x 2 + 0 x 2
. (or 22 in base 10)
4 3
1999 - 2006^
Dianne P. O'Leary
17
+_______________________^ Note the “
carry ” here!
(binary) = 10
1 + 1 + 1 = 11 (binary)=
1999 - 2006^
Dianne P. O'Leary
18
+_______________________^ Note the “
carry ” here!
In decimal notation,
1999 - 2006^
Dianne P. O'Leary
19
Computers represent negative numbers using“one’s complement”, “two’s complement”,or sign-magnitude representation. Sign magnitude
is easiest, and enough for us: if the first bit is zero, then the number is positive.Otherwise, it is negative.
Denotes^
Denotes^
1999 - 2006^
Dianne P. O'Leary
20
1999 - 2006^
Dianne P. O'Leary
25
very^ limited range of numbers.
1999 - 2006^
Dianne P. O'Leary
26
If we wanted to store 15 x 2
11 , we would need 16 bits: Instead, let’s agree to code numbers as
two^ fixed point
numbers:
z x 2^ ,
with z = 15 saved as 01111and p = 11 saved as 01011. Now we can have fractions, too:
binary .101 = 1 x 2 + 0 x 2
1999 - 2006^
Dianne P. O'Leary
27
Jargon:^ z is called the
mantissa
or^ significand
p is called the
exponent
p ± z x 2
To make the representation unique (since, for example,^1 2 x 2= 4 x 2
0 ), we make the rule that
1 ≤^ z < 2
(normalization
We store^
d digits^ for the mantissa, and limit the range of the exponent to
m^ ≤^ p^ ≤ M, for some integers m and M.
1999 - 2006^
Dianne P. O'Leary
28
(^10) 15 x 2= 1111
(^10) x 2= 1.111 2
(^13) x 2 2 mantissa^
z = +1. exponent^
p = + -10^ 15 x 2 = 1111x 2^2
-7x 2 2 mantissa^
z = +1. exponent^
p = -
1999 - 2006^
Dianne P. O'Leary
29
Up until the mid-1980s, each computer manufacturer had adifferent choice for d, m, and M, and even a different wayto select answers to arithmetic problems.A program written for one machine often would not computethe same answers on other machines.The situation improved somewhat with the introduction in 1987of^ IEEE standard
floating point arithmetic.
1999 - 2006^
Dianne P. O'Leary
30
On most machines today,single precision:
d = 24, m = -126, M = 127 double precision: d = 53, m = -1022, M = 1023.(And the representation is 2’s complement, notsign-magnitude, so that the number -|x| is stored as 2
d^ - |x|,
where d is the number of bits allotted for its representation.)
1999 - 2006^
Dianne P. O'Leary
31
Machine arithmetic is more complicated for floating point.Example: In fixed point, we added 3 + 10.Here it is in floating point:3 =^ 11 (binary) = 1.100 x 2
1 z = 1.100,
p = 1
10 = 1010 (binary) = 1.010 x 2
3 z = 1.010,
p = 11.
p = 11
p = 11
1999 - 2006^
Dianne P. O'Leary
32
0 + 1.0001 x 2
p = 0
p = 0
1
But we can only store 1.0000 x 2
1! The error is called
roundoff
1999 - 2006^
Dianne P. O'Leary
37
not^ equally
spaced. (Try to draw them on a number line.)• A wide range of variably-spaced numbers can berepresented exactly.• For addition, subtraction, and multiplication, eitherwe get exactly the right answer or a rounded versionof it, or we can detect underflow or overflow.
1999 - 2006^
Dianne P. O'Leary
38
1999 - 2006^
Dianne P. O'Leary
39
numbers. Computers do not work with these; for instance, theydo not have a representation for the numbers
π^ or e or
even 0.1 .Dealing with the finite approximations called
floating point
numbers means that we need to understand
error and
its propagation.
1999 - 2006^
Dianne P. O'Leary
40
in c as an approximation to x:|x – c| Relative error
in c as an approximation to nonzero x:|x –^ c|^ |x|
1999 - 2006^
Dianne P. O'Leary
41
2.003^ x^
0 10 (suppose
±^ .001 or .05% error)
0 10 (suppose
±^ .001 or .05% error)
Result of subtraction:
0.003^ x^
but true answer could be as small as 2.002 - 2.001 = 0.001,
or as large as
1999 - 2006^
Dianne P. O'Leary
42
2.003^ x^
0 10 (suppose
±^ .001 or .05% error)
0 10 (suppose
±^ .001 or .05% error)
Result of subtraction:
0.003^ x^
0 10 (±^ .002 or 200% error if trueanswer is 0.001) Catastrophic cancellation
, or “loss of significance”
1999 - 2006^
Dianne P. O'Leary
43
, the bounds on
absolute errors
add.
1999 - 2006^
Dianne P. O'Leary
44
If X = x (^
-^ r)^ and^
Y = y (^
-^ s)
then r is the relative error in x and s is the relative errorin y. You could show thatxy - XYxy^
≤^ |r| + |s| + |rs
1999 - 2006^
Dianne P. O'Leary
49
(sqrt(x+e) + sqrt(x)) =^ x + e - x
e
sqrt(x+e) + sqrt(x)
sqrt(x+e) + sqrt(x)
so^ x= 28 - sqrt(783) = sqrt(784) - sqrt(783).^2
1999 - 2006^
Dianne P. O'Leary
50
Then f(x+a) - f(x) = f
′(x) a + 1/2 f
(^2) ″(x) a+ ...
1999 - 2006^
Dianne P. O'Leary
51
1999 - 2006^
Dianne P. O'Leary
52
determines the cumulative effects of error. Two approaches:• Forward error analysis• Backward error analysis
1999 - 2006^
Dianne P. O'Leary
53
Space of answers
1999 - 2006^
Dianne P. O'Leary
54
Space of answers
Trueproblem(known)
Truesolution (unknown)
1999 - 2006^
Dianne P. O'Leary
55
Space of answers
Trueproblem(known)
Truesolution#(unknown) Computedsolution
1999 - 2006^
Dianne P. O'Leary
56
Space of answers
Trueproblem(known)
(known)region#guaranteedto containtrue soln. Computedsolution
1999 - 2006^
Dianne P. O'Leary
61