Professional Documents
Culture Documents
Numerics II
Review:
Want millionth digit of
2:
b 2 102d c
d = 106
a (1 + n ) n may be + or -
Xn+1 =
=
Xn + a/Xn
2
a(1 + n ) +
p
(a)
a
a(1+n )
2
(1 + n ) +
1
(1+n )
2
2 + 2n + n 2
2(1 + n )
p
n 2
=
(a) 1 +
2(1 + n )
p
=
(a)
Lecture 12
Numerics II
Therefore,
n+1 =
n 2
2(1 + n )
Multiplication Algorithms:
1. Naive Divide & Conquer method: (d2 ) time
2. Karatsuba: (dlog2 3 ) = (d1.584... )
3. Toom-Cook generalizes Karatsuba (break into k 2 parts )
T (d) = 5T (d/3) + (d) = dlog3 5 = d1.465...
4. Schnhage-Strassen - almost linear! (d lg d lg lg d) using FFT. All of these are
in gmpy package
a
b
1
first
b
1
R
High-precision rep of
means b c where R is large value s.t. it is easy to
b
b
divide by R
Ex: R = 2k for binary representations
Lecture 12
Numerics II
Division
R
b
1
b
R
zero at x =
x R
b
1
x2
1
b
i
R
f (i )
i 0
= i
f (i )
1/i 2
bi 2 multiply
1
b
i + i 2
= 2i
R easy div
i R
Example
R
216
65536
=
=
= 13107.2
b
5
5
216
Try initial guess
= 214
4
Want
0 = 214 = 16384
1 = 2 (16384) 5(16384)2 /65536 = 12288
2 = 2 (12288) 5(12288)2 /65536 = 13056
3 = 2 (13056) 5(13056)2 /65536 = 13107
Error Analysis
bi 2
R
R
Assume i = (1 + i )
b
2
R
b R
= 2 (1 + i )
(1 + i )2
b
R b
R
=
(2 + 2i ) (1 + 2i + i 2 )
b
R
R
1 i 2 = (1 + i+1 ) where i+1 = i 2
=
b
b
i+1 = 2i
Lecture 12
Numerics II
+ c
+ c d < 2 c d
c 1 + c 2 + c 4 + + c
4
2
Termination
i + ba/i c
c
2
Do floors hurt? Does program terminate? ( and are the fractional parts below.)
Iteration is
Iteration: i+1 = b
i+1 =
=
i +
a
i
2
i +
2
a
i
where =
+ and 0 < 1
2
i + ai
a+b
Since
ab,
a, so subtracting always leaves us b ac. This
2
2
wont stay stuck above if i < 1 (good initial guess).
We are calling this the first level, since Newtons method is used within division, which would
be the second level of applying it when we are computing square roots.
MIT OpenCourseWare
http://ocw.mit.edu
For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.