Addition and SubtractionDefinition. Let A(d) denote the number of steps required to add two numbers...
Transcript of Addition and SubtractionDefinition. Let A(d) denote the number of steps required to add two numbers...
Addition and Subtraction
How fast do we add (or subtract) two numbers n and m?
How fast can we add (or subtract) two numbers n and m?
Definition. Let A(d) denote the number of steps required toadd two numbers with d bits.
Theorem. A(d) ⇣ d.
Addition and Subtraction
How fast do we add (or subtract) two numbers n and m?
How fast can we add (or subtract) two numbers n and m?
Definition. Let A(d) denote the number of steps required toadd two numbers with d bits.
Theorem. A(d) ⇣ d.
Addition and Subtraction
How fast do we add (or subtract) two numbers n and m?
How fast can we add (or subtract) two numbers n and m?
Definition. Let A(d) denote the number of steps required toadd two numbers with d bits.
Theorem. A(d) ⇣ d.
Addition and Subtraction
How fast do we add (or subtract) two numbers n and m?
How fast can we add (or subtract) two numbers n and m?
Definition. Let A(d) denote the number of steps required toadd two numbers with d bits.
Theorem. A(d) ⇣ d.
Addition and Subtraction
How fast do we add (or subtract) two numbers n and m?
How fast can we add (or subtract) two numbers n and m?
Definition. Let A(d) denote the number of steps required toadd two numbers with d bits.
Theorem. A(d) ⇣ d.
Theorem. S(d) ⇣ d.
Definition. Let A(d) denote the maximal number of stepsrequired to add two numbers with d bits.
Multiplication
How fast do we multiply two numbers n and m?
How fast can we multiply two numbers n and m?
Definition. Let M(d) denote the number of steps required tomultiply two numbers with d bits.
Theorem. M(d) ⌧ d2.
Can we do better? Yes
How can we see “easily” that something better is possible?
• Suppose M(d) � d1.5.
• Let d be large, and let " > 0.
• Let n and m have d bits, and write n = an ⇥ 2r + bn
and m = am ⇥ 2r + bm, where r = bd/2c and the aj andbj are integers with bj < 2r.
• From nm = anbn22r + (anbm + ambn)2r + bnbm, deduceM(d) 4M(r + 1) + O(r) (4 + ")M(r + 1).
• Hence, M(d) (4 + ")sM
�(d + 2s+1 � 2)/2s
�.
• Take s = blog2 dc � C (with C big). Then 2s � d/2C+1.
• Conclude, M(d) ⌧ (4 + ")log2 d = dlog(4+")/ log 2.
Theorem. M(d) ⌧ d (log d) log log d.
Multiplication
How fast do we multiply two numbers n and m?
How fast can we multiply two numbers n and m?
Definition. Let M(d) denote the number of steps required tomultiply two numbers with d bits.
Theorem. M(d) ⌧ d2.
Can we do better? Yes
How can we see “easily” that something better is possible?
• Suppose M(d) � d1.5.
• Let d be large, and let " > 0.
• Let n and m have d bits, and write n = an ⇥ 2r + bn
and m = am ⇥ 2r + bm, where r = bd/2c and the aj andbj are integers with bj < 2r.
• From nm = anbn22r + (anbm + ambn)2r + bnbm, deduceM(d) 4M(r + 1) + O(r) (4 + ")M(r + 1).
• Hence, M(d) (4 + ")sM
�(d + 2s+1 � 2)/2s
�.
• Take s = blog2 dc � C (with C big). Then 2s � d/2C+1.
• Conclude, M(d) ⌧ (4 + ")log2 d = dlog(4+")/ log 2.
Theorem. M(d) ⌧ d (log d) log log d.
Multiplication
How fast do we multiply two numbers n and m?
How fast can we multiply two numbers n and m?
Definition. Let M(d) denote the number of steps required tomultiply two numbers with d bits.
Theorem. M(d) ⌧ d2.
Can we do better? Yes
How can we see “easily” that something better is possible?
• Suppose M(d) � d1.5.
• Let d be large, and let " > 0.
• Let n and m have d bits, and write n = an ⇥ 2r + bn
and m = am ⇥ 2r + bm, where r = bd/2c and the aj andbj are integers with bj < 2r.
• From nm = anbn22r + (anbm + ambn)2r + bnbm, deduceM(d) 4M(r + 1) + O(r) (4 + ")M(r + 1).
• Hence, M(d) (4 + ")sM
�(d + 2s+1 � 2)/2s
�.
• Take s = blog2 dc � C (with C big). Then 2s � d/2C+1.
• Conclude, M(d) ⌧ (4 + ")log2 d = dlog(4+")/ log 2.
Theorem. M(d) ⌧ d (log d) log log d.
Multiplication
How fast do we multiply two numbers n and m?
How fast can we multiply two numbers n and m?
Definition. Let M(d) denote the number of steps required tomultiply two numbers with d bits.
Theorem. M(d) ⌧ d2.
Can we do better? Yes
How can we see “easily” that something better is possible?
• Suppose M(d) � d1.5.
• Let d be large, and let " > 0.
• Let n and m have d bits, and write n = an ⇥ 2r + bn
and m = am ⇥ 2r + bm, where r = bd/2c and the aj andbj are integers with bj < 2r.
• From nm = anbn22r + (anbm + ambn)2r + bnbm, deduceM(d) 4M(r + 1) + O(r) (4 + ")M(r + 1).
• Hence, M(d) (4 + ")sM
�(d + 2s+1 � 2)/2s
�.
• Take s = blog2 dc � C (with C big). Then 2s � d/2C+1.
• Conclude, M(d) ⌧ (4 + ")log2 d = dlog(4+")/ log 2.
Theorem. M(d) ⌧ d (log d) log log d.
Multiplication
How fast do we multiply two numbers n and m?
How fast can we multiply two numbers n and m?
Definition. Let M(d) denote the number of steps required tomultiply two numbers with d bits.
Theorem. M(d) ⌧ d2.
Can we do better? Yes
How can we see “easily” that something better is possible?
• Suppose M(d) � d1.5.
• Let d be large, and let " > 0.
• Let n and m have d bits, and write n = an ⇥ 2r + bn
and m = am ⇥ 2r + bm, where r = bd/2c and the aj andbj are integers with bj < 2r.
• From nm = anbn22r + (anbm + ambn)2r + bnbm, deduceM(d) 4M(r + 1) + O(r) (4 + ")M(r + 1).
• Hence, M(d) (4 + ")sM
�(d + 2s+1 � 2)/2s
�.
• Take s = blog2 dc � C (with C big). Then 2s � d/2C+1.
• Conclude, M(d) ⌧ (4 + ")log2 d = dlog(4+")/ log 2.
Theorem. M(d) ⌧ d (log d) log log d.
Multiplication
How fast do we multiply two numbers n and m?
How fast can we multiply two numbers n and m?
Definition. Let M(d) denote the number of steps required tomultiply two numbers with d bits.
Theorem. M(d) ⌧ d2.
Can we do better? Yes
How can we see “easily” that something better is possible?
• Suppose M(d) � d1.5.
• Let d be large, and let " > 0.
• Let n and m have d bits, and write n = an ⇥ 2r + bn
and m = am ⇥ 2r + bm, where r = bd/2c and the aj andbj are integers with bj < 2r.
• From nm = anbn22r + (anbm + ambn)2r + bnbm, deduceM(d) 4M(r + 1) + O(r) (4 + ")M(r + 1).
• Hence, M(d) (4 + ")sM
�(d + 2s+1 � 2)/2s
�.
• Take s = blog2 dc � C (with C big). Then 2s � d/2C+1.
• Conclude, M(d) ⌧ (4 + ")log2 d = dlog(4+")/ log 2.
Theorem. M(d) ⌧ d (log d) log log d.
Multiplication
How fast do we multiply two numbers n and m?
How fast can we multiply two numbers n and m?
Definition. Let M(d) denote the number of steps required tomultiply two numbers with d bits.
Theorem. M(d) ⌧ d2.
Can we do better? Yes
How can we see “easily” that something better is possible?
• Suppose M(d) � d1.5.
• Let d be large, and let " > 0.
• Let n and m have d bits, and write n = an ⇥ 2r + bn
and m = am ⇥ 2r + bm, where r = bd/2c and the aj andbj are integers with bj < 2r.
• From nm = anbn22r + (anbm + ambn)2r + bnbm, deduceM(d) 4M(r + 1) + O(r) (4 + ")M(r + 1).
• Hence, M(d) (4 + ")sM
�(d + 2s+1 � 2)/2s
�.
• Take s = blog2 dc � C (with C big). Then 2s � d/2C+1.
• Conclude, M(d) ⌧ (4 + ")log2 d = dlog(4+")/ log 2.
Theorem. M(d) ⌧ d (log d) log log d.
Multiplication
How fast do we multiply two numbers n and m?
How fast can we multiply two numbers n and m?
Definition. Let M(d) denote the number of steps required tomultiply two numbers with d bits.
Theorem. M(d) ⌧ d2.
Can we do better? Yes
How can we see “easily” that something better is possible?
• Suppose M(d) � d1.5.
• Let d be large, and let " > 0.
• Let n and m have d bits, and write n = an ⇥ 2r + bn
and m = am ⇥ 2r + bm, where r = bd/2c and the aj andbj are integers with bj < 2r.
• From nm = anbn22r + (anbm + ambn)2r + bnbm, deduceM(d) 4M(r + 1) + O(r) (4 + ")M(r + 1).
• Hence, M(d) (4 + ")sM
�(d + 2s+1 � 2)/2s
�.
• Take s = blog2 dc � C (with C big). Then 2s � d/2C+1.
• Conclude, M(d) ⌧ (4 + ")log2 d = dlog(4+")/ log 2.
Theorem. M(d) ⌧ d (log d) log log d.
Attempt 1
• Suppose M(d) � d1.5.
• Let d be large, and let " > 0.
• Let n and m have d bits, and write n = an ⇥ 2r + bn
and m = am ⇥ 2r + bm, where r = bd/2c and the aj andbj are integers with bj < 2r.
• From nm = anbn22r + (anbm + ambn)2r + bnbm, deduceM(d) 4M(r + 1) + O(r) (4 + ")M(r + 1).
• Hence, M(d) (4 + ")sM
�(d + 2s+1 � 2)/2s
�.
• Take s = blog2 dc � C (with C big). Then 2s � d/2C+1.
• Conclude, M(d) ⌧ (4 + ")log2 d = dlog(4+")/ log 2.
Theorem. M(d) ⌧ d (log d) log log d.
Attempt 1
• Suppose M(d) � d1.5.
• Let d be large, and let " > 0.
• Let n and m have d bits, and write n = an ⇥ 2r + bn
and m = am ⇥ 2r + bm, where r = bd/2c and the aj andbj are integers with bj < 2r.
• From nm = anbn22r + (anbm + ambn)2r + bnbm, deduceM(d) 4M(r + 1) + O(r) (4 + ")M(r + 1).
• Hence, M(d) (4 + ")sM
�(d + 2s+1 � 2)/2s
�.
• Take s = blog2 dc � C (with C big). Then 2s � d/2C+1.
• Conclude, M(d) ⌧ (4 + ")log2 d = dlog(4+")/ log 2.
Theorem. M(d) ⌧ d (log d) log log d.
Attempt 1
• Suppose M(d) � d1.5.
• Let d be large, and let " > 0.
• Let n and m have d bits, and write n = an ⇥ 2r + bn
and m = am ⇥ 2r + bm, where r = bd/2c and the aj andbj are integers with bj < 2r.
• From nm = anbn22r + (anbm + ambn)2r + bnbm, deduceM(d) 4M(r + 1) + O(r) (4 + ")M(r + 1).
• Hence, M(d) (4 + ")sM
�(d + 2s+1 � 2)/2s
�.
• Take s = blog2 dc � C (with C big). Then 2s � d/2C+1.
• Conclude, M(d) ⌧ (4 + ")log2 d = dlog(4+")/ log 2.
Theorem. M(d) ⌧ d (log d) log log d.
Attempt 1
• Suppose M(d) � d1.5.
• Let d be large, and let " > 0.
• Let n and m have d bits, and write n = an ⇥ 2r + bn
and m = am ⇥ 2r + bm, where r = bd/2c and the aj andbj are integers with bj < 2r.
• From nm = anbn22r + (anbm + ambn)2r + bnbm, deduceM(d) 4M(r + 1) + O(r) (4 + ")M(r + 1).
• Hence, M(d) (4 + ")sM
�(d + 2s+1 � 2)/2s
�.
• Take s = blog2 dc � C (with C big). Then 2s � d/2C+1.
• Conclude, M(d) ⌧ (4 + ")log2 d = dlog(4+")/ log 2.
Theorem. M(d) ⌧ d (log d) log log d.
Attempt 2
• Suppose M(d) � d1.5.
• Let d be large, and let " > 0.
• Let n and m have d bits, and write n = an ⇥ 2r + bn
and m = am ⇥ 2r + bm, where r = bd/2c and the aj andbj are integers with bj < 2r.
• From nm = ??????????????????????????????????, deduceM(d) 3M(r + 1) + O(r) (3 + ")M(r + 1).
• Hence, M(d) (3 + ")sM
�(d + 2s+1 � 2)/2s
�.
• Take s = blog2 dc � C (with C big). Then 2s � d/2C+1.
• Conclude, M(d) ⌧ (3 + ")log2 d = dlog(3+")/ log 2.
Theorem. M(d) ⌧ d (log d) log log d.
Attempt 2
• Suppose M(d) � d1.5.
• Let d be large, and let " > 0.
• Let n and m have d bits, and write n = an ⇥ 2r + bn
and m = am ⇥ 2r + bm, where r = bd/2c and the aj andbj are integers with bj < 2r.
• From
nm = anam22r+�(an+bn)(am+bm)�anam�bnbm
�2r+bnbm,
deduce M(d) 3M(r + 2) + O(r) (3 + ")M(r + 2).
• Hence, M(d) (3 + ")sM
�(d + 2s+1 � 2)/2s
�.
• Take s = blog2 dc � C (with C big). Then 2s � d/2C+1.
• Conclude, M(d) ⌧ (3 + ")log2 d = dlog(3+")/ log 2.
Attempt 2
• Suppose M(d) � d1.5.
• Let d be large, and let " > 0.
• Let n and m have d bits, and write n = an ⇥ 2r + bn
and m = am ⇥ 2r + bm, where r = bd/2c and the aj andbj are integers with bj < 2r.
• From
nm = anam22r+�(an+bn)(am+bm)�anam�bnbm
�2r+bnbm,
deduce M(d) 3M(r + 2) + O(r) (3 + ")M(r + 2).
• Hence, M(d) (3 + ")sM
�(d + 2s+1 � 2)/2s
�.
• Take s = blog2 dc � C (with C big). Then 2s � d/2C+1.
• Conclude, M(d) ⌧ (3 + ")log2 d = dlog(3+")/ log 2.
Attempt 2
• Suppose M(d) � d1.5.
• Let d be large, and let " > 0.
• Let n and m have d bits, and write n = an ⇥ 2r + bn
and m = am ⇥ 2r + bm, where r = bd/2c and the aj andbj are integers with bj < 2r.
• From
nm = anam22r+�(an+bn)(am+bm)�anam�bnbm
�2r+bnbm,
deduce M(d) 3M(r + 2) + O(r) (3 + ")M(r + 2).
• Hence, M(d) (3 + ")sM
�(d + 2s+2 � 4)/2s
�.
• Take s = blog2 dc � C (with C big). Then 2s � d/2C+1.
• Conclude, M(d) ⌧ (3 + ")log2 d = dlog(3+")/ log 2.
Multiplication
How fast do we multiply two numbers n and m?
How fast can we multiply two numbers n and m?
Definition. Let M(d) denote the number of steps required tomultiply two numbers with d bits.
Theorem. M(d) ⌧ d2.
Can we do better? Yes
How can we see “easily” that something better is possible?
• Suppose M(d) � d1.5.
• Let d be large, and let " > 0.
• Let n and m have d bits, and write n = an ⇥ 2r + bn
and m = am ⇥ 2r + bm, where r = bd/2c and the aj andbj are integers with bj < 2r.
• From nm = anbn22r + (anbm + ambn)2r + bnbm, deduceM(d) 4M(r + 1) + O(r) (4 + ")M(r + 1).
• Hence, M(d) (4 + ")sM
�(d + 2s+1 � 2)/2s
�.
• Take s = blog2 dc � C (with C big). Then 2s � d/2C+1.
• Conclude, M(d) ⌧ (4 + ")log2 d = dlog(4+")/ log 2.
Theorem. M(d) ⌧ d (log d) log log d.
log 3
log 2= 1.5849625
Theorem. M(d) ⌧ d1.585.
Attempt 2
• Suppose M(d) � d1.5.
• Let d be large, and let " > 0.
• Let n and m have d bits, and write n = an ⇥ 2r + bn
and m = am ⇥ 2r + bm, where r = bd/2c and the aj andbj are integers with bj < 2r.
• From nm = ??????????????????????????????????, deduceM(d) 3M(r + 1) + O(r) (3 + ")M(r + 1).
• Hence, M(d) (3 + ")sM
�(d + 2s+1 � 2)/2s
�.
• Take s = blog2 dc � C (with C big). Then 2s � d/2C+1.
• Conclude, M(d) ⌧ (3 + ")log2 d = dlog(3+")/ log 2.
Theorem. M(d) ⌧ d (log d) log log d.
log 3
log 2= 1.5849625
Theorem. M(d) ⌧ d1.585.
Multiplication
How fast do we multiply two numbers n and m?
How fast can we multiply two numbers n and m?
Definition. Let M(d) denote the number of steps required tomultiply two numbers with d bits.
Theorem. M(d) ⌧ d2.
Can we do better? Yes
How can we see “easily” that something better is possible?
• Suppose M(d) � d1.5.
• Let d be large, and let " > 0.
• Let n and m have d bits, and write n = an ⇥ 2r + bn
and m = am ⇥ 2r + bm, where r = bd/2c and the aj andbj are integers with bj < 2r.
• From nm = anbn22r + (anbm + ambn)2r + bnbm, deduceM(d) 4M(r + 1) + O(r) (4 + ")M(r + 1).
• Hence, M(d) (4 + ")sM
�(d + 2s+1 � 2)/2s
�.
• Take s = blog2 dc � C (with C big). Then 2s � d/2C+1.
• Conclude, M(d) ⌧ (4 + ")log2 d = dlog(4+")/ log 2.
Theorem. M(d) ⌧ d (log d) log log d.
HW: Due January 31 (Friday)
Page 3, Problems 1 and 2
Page 5, unnumbered homework (first set)
(you may use (log 5/ log 3) + " instead of log 5/ log 3)
September 7
Attempt 1
• Suppose M(d) � d1.5.
• Let d be large, and let " > 0.
• Let n and m have d bits, and write n = an ⇥ 2r + bn
and m = am ⇥ 2r + bm, where r = bd/2c and the aj andbj are integers with bj < 2r.
• From nm = anbn22r + (anbm + ambn)2r + bnbm, deduceM(d) 4M(r + 1) + O(r) (4 + ")M(r + 1).
• Hence, M(d) (4 + ")sM
�(d + 2s+1 � 2)/2s
�.
• Take s = blog2 dc � C (with C big). Then 2s � d/2C+1.
• Conclude, M(d) ⌧ (4 + ")log2 d = dlog(4+")/ log 2.
Theorem. M(d) ⌧ d (log d) log log d.
Attempt 2
• Suppose M(d) � d1.5.
• Let d be large, and let " > 0.
• Let n and m have d bits, and write n = an ⇥ 2r + bn
and m = am ⇥ 2r + bm, where r = bd/2c and the aj andbj are integers with bj < 2r.
• From
nm = anam22r+�(an+bn)(am+bm)�anam�bnbm
�2r+bnbm,
deduce M(d) 3M(r + 2) + O(r) (3 + ")M(r + 2).
• Hence, M(d) (3 + ")sM
�(d + 2s+1 � 2)/2s
�.
• Take s = blog2 dc � C (with C big). Then 2s � d/2C+1.
• Conclude, M(d) ⌧ (3 + ")log2 d = dlog(3+")/ log 2.
log 3
log 2= 1.5849625
Theorem. M(d) ⌧ d1.585.
Idea for Doing Better
log 3
log 2= 1.5849625
Theorem. M(d) ⌧ d1.585.
Idea for Doing Better
Think in terms of writing
n = an22r + bn2
r + cn and m = am22r + bm2r + cm,
where r = bd/3c.
How many multiplications does it take to expand nm ?
log 3
log 2= 1.5849625
Theorem. M(d) ⌧ d1.585.
Idea for Doing Better
Think in terms of writing
n = an22r + bn2
r + cn and m = am22r + bm2r + cm,
where r = bd/3c.
How many multiplications does it take to expand nm ?
Homework
(3) The value of f(n) =nX
k=1
1/k can be estimated by com-
paring it’s value to an integral. For example, by comparingthe sum of the areas of the rectangles indicated in the graphbelow with the area under the graph of y = 1/x, one obtains
f(9) �Z 10
1
1
xdx = log 10.
(c) Prove that f(n) ⇠ log n.
Theorem. M(d) ⌧ d (log d) log log d.Theorem. For every " > 0, we have M(d) ⌧" d
1+".
Theorem. Given distinct numbers x0, x1, . . . , xk and num-bers y0, y1, . . . , yk, there is a unique polynomial f of degree k such that f(xj) = yj for all j.
Theorem. For every " > 0, we have M(d) ⌧" d1+".
Theorem. Given distinct numbers x0, x1, . . . , xk and num-bers y0, y1, . . . , yk, there is a unique polynomial f of degree k such that f(xj) = yj for all j.
Lagrange Interpolation:
f(x) =kX
i=0
✓ Y
0jk
j 6=i
x � xj
xi � xj
◆yi
Theorem. For every " > 0, we have M(d) ⌧" d1+".
Theorem. Given distinct numbers x0, x1, . . . , xk and num-bers y0, y1, . . . , yk, there is a unique polynomial f of degree k such that f(xj) = yj for all j.
Lagrange Interpolation:
f(x) =kX
i=0
✓ Y
0jk
j 6=i
x � xj
xi � xj
◆yi
Theorem. For every " > 0, we have M(d) ⌧" d1+".
Theorem. Given distinct numbers x0, x1, . . . , xk and num-bers y0, y1, . . . , yk, there is a unique polynomial f of degree k such that f(xj) = yj for all j.
Lagrange Interpolation:
f(x) =kX
i=0
✓ Y
0jk
j 6=i
x � xj
xi � xj
◆yi
• Suppose n and m have kr digits. Write
n =
k�1X
u=0
au2ur
and m =
k�1X
v=0
bv2vr
.
• Then nm = f(2r), where
f(x) =
✓ k�1X
u=0
auxu
◆✓ k�1X
v=0
bvxv
◆.
• Compute the 2k�1 numbers yj = f(j), for 0 j 2k�2,
using 2k�1 multiplications of two r+ck digit numbers.
• Compute the coe�cients of f(x) expanded, using Lagrange
interpolation, in Ok(r) steps.
• Deduce M(kr) (2k � 1)M(r + ck) + c0kr so that
M(d) ⌧ (2k � 1)logk d ⌧ d
log(2k�1)/ log k.
• Suppose n and m have kr digits. Write
n =
k�1X
u=0
au2ur
and m =
k�1X
v=0
bv2vr
.
• Then nm = f(2r), where
f(x) =
✓ k�1X
u=0
auxu
◆✓ k�1X
v=0
bvxv
◆.
• Compute the 2k�1 numbers yj = f(j), for 0 j 2k�2,
using 2k�1 multiplications of two r+ck digit numbers.
• Compute the coe�cients of f(x) expanded, using Lagrange
interpolation, in Ok(r) steps.
• Deduce M(kr) (2k � 1)M(r + ck) + c0kr so that
M(d) ⌧ (2k � 1)logk d ⌧ d
log(2k�1)/ log k.
• Suppose n and m have kr digits. Write
n =
k�1X
u=0
au2ur
and m =
k�1X
v=0
bv2vr
.
• Then nm = f(2r), where f(x) =
✓ k�1X
u=0
auxu
◆✓ k�1X
v=0
bvxv
◆.
• Compute the 2k�1 numbers yj = f(j), for 0 j 2k�2,
using 2k�1 multiplications of two r+ck digit numbers.
• Compute the coe�cients of f(x) expanded, using Lagrange
interpolation, in Ok(r) steps.
• Deduce M(kr) (2k � 1)M(r + ck) + c0kr so that
M(d) ⌧ (2k � 1)logk d ⌧ d
log(2k�1)/ log k.
Theorem. For every " > 0, we have M(d) ⌧" d1+".
Theorem. Given distinct numbers x0, x1, . . . , xk and num-bers y0, y1, . . . , yk, there is a unique polynomial f of degree k such that f(xj) = yj for all j.
Lagrange Interpolation:
f(x) =kX
i=0
✓ Y
0jk
j 6=i
x � xj
xi � xj
◆yi
• Suppose n and m have kr digits. Write
n =
k�1X
u=0
au2ur
and m =
k�1X
v=0
bv2vr
.
• Then nm = f(2r), where
f(x) =
✓ k�1X
u=0
auxu
◆✓ k�1X
v=0
bvxv
◆.
• Compute the 2k�1 numbers yj = f(j), for 0 j 2k�2,
using 2k�1 multiplications of two r+ck digit numbers.
• Compute the coe�cients of f(x) expanded, using Lagrange
interpolation, in Ok(r) steps.
• Deduce M(kr) (2k � 1)M(r + ck) + c0kr so that
M(d) ⌧ (2k � 1)logk d ⌧ d
log(2k�1)/ log k.
• Suppose n and m have kr digits. Write
n =
k�1X
u=0
au2ur
and m =
k�1X
v=0
bv2vr
.
• Then nm = f(2r), where
f(x) =
✓ k�1X
u=0
auxu
◆✓ k�1X
v=0
bvxv
◆.
• Compute the 2k�1 numbers yj = f(j), for 0 j 2k�2,
using 2k�1 multiplications of two r+ck digit numbers.
• Compute the coe�cients of f(x) expanded, using Lagrange
interpolation, in Ok(r) steps.
• Deduce M(kr) (2k � 1)M(r + ck) + c0kr so that
M(d) ⌧ (2k � 1)logk d ⌧ d
log(2k�1)/ log k.
• Suppose n and m have kr digits. Write
n =
k�1X
u=0
au2ur
and m =
k�1X
v=0
bv2vr
.
• Then nm = f(2r), where
f(x) =
✓ k�1X
u=0
auxu
◆✓ k�1X
v=0
bvxv
◆.
• Compute the 2k�1 numbers yj = f(j), for 0 j 2k�2,
using 2k�1 multiplications of two r+ck digit numbers.
• Compute the coe�cients of f(x) expanded, using Lagrange
interpolation, in Ok(r) steps.
• Deduce M(kr) (2k � 1)M(r + ck) + c0kr so that
M(d) ⌧ (2k � 1)logk d ⌧ d
log(2k�1)/ log k.
• Suppose n and m have kr digits. Write
n =
k�1X
u=0
au2ur
and m =
k�1X
v=0
bv2vr
.
• Then nm = f(2r), where f(x) =
✓ k�1X
u=0
auxu
◆✓ k�1X
v=0
bvxv
◆.
• Compute the 2k�1 numbers yj = f(j), for 0 j 2k�2,
using 2k�1 multiplications of two r+ck digit numbers.
• Compute the coe�cients of f(x) expanded, using Lagrange
interpolation, in Ok(r) steps.
• Deduce M(kr) (2k � 1)M(r + ck) + c0kr so that
M(d) ⌧ (2k � 1)logk d ⌧ d
log(2k�1)/ log k.
Theorem. For every " > 0, we have M(d) ⌧" d1+".
Theorem. Given distinct numbers x0, x1, . . . , xk and num-bers y0, y1, . . . , yk, there is a unique polynomial f of degree k such that f(xj) = yj for all j.
Lagrange Interpolation:
f(x) =kX
i=0
✓ Y
0jk
j 6=i
x � xj
xi � xj
◆yi
Theorem. For every " > 0, we have M(d) ⌧" d1+".
Theorem. Given distinct numbers x0, x1, . . . , xk and num-bers y0, y1, . . . , yk, there is a unique polynomial f of degree k such that f(xj) = yj for all j.
Lagrange Interpolation:
f(x) =kX
i=0
✓ Y
0jk
j 6=i
x � xj
xi � xj
◆yi
• Suppose n and m have kr digits. Write
n =
k�1X
u=0
au2ur
and m =
k�1X
v=0
bv2vr
.
• Then nm = f(2r), where
f(x) =
✓ k�1X
u=0
auxu
◆✓ k�1X
v=0
bvxv
◆.
• Compute the 2k�1 numbers yj = f(j), for 0 j 2k�2,
using 2k�1 multiplications of two r+ck digit numbers.
• Compute the coe�cients of f(x) expanded, using Lagrange
interpolation, in Ok(r) steps.
• Deduce M(kr) (2k � 1)M(r + ck) + c0kr so that
M(d) ⌧ (2k � 1)logk d ⌧ d
log(2k�1)/ log k.
• Suppose n and m have kr digits. Write
n =
k�1X
u=0
au2ur
and m =
k�1X
v=0
bv2vr
.
• Then nm = f(2r), where f(x) =
✓ k�1X
u=0
auxu
◆✓ k�1X
v=0
bvxv
◆.
• Compute the 2k�1 numbers yj = f(j), for 0 j 2k�2,
using 2k�1 multiplications of two r+ck digit numbers.
• Compute the coe�cients of f(x) expanded, using Lagrange
interpolation, in Ok(r) steps.
• Deduce M(kr) (2k � 1)M(r + ck) + c0kr so that
M(d) ⌧ (2k � 1)logk d ⌧ d
log(2k�1)/ log k.
• Suppose n and m have kr digits. Write
n =
k�1X
u=0
au2ur
and m =
k�1X
v=0
bv2vr
.
• Then nm = f(2r), where f(x) =
✓ k�1X
u=0
auxu
◆✓ k�1X
v=0
bvxv
◆.
• Compute the 2k�1 numbers yj = f(j), for 0 j 2k�2,
using 2k�1 multiplications of two r+ck digit numbers.
• Compute the coe�cients of f(x) expanded, using Lagrange
interpolation, in Ok(r) steps.
• Deduce M(kr) (2k � 1)M(r + ck) + c0kr so that
M(d) ⌧ (2k � 1)logk d ⌧ d
log(2k�1)/ log k.
• Suppose n and m have kr digits. Write
n =
k�1X
u=0
au2ur
and m =
k�1X
v=0
bv2vr
.
• Then nm = f(2r), where
f(x) =
✓ k�1X
u=0
auxu
◆✓ k�1X
v=0
bvxv
◆.
• Compute the 2k�1 numbers yj = f(j), for 0 j 2k�2,
using 2k�1 multiplications of two r+ck digit numbers.
• Compute the coe�cients of f(x) expanded, using Lagrange
interpolation, in Ok(r) steps.
• Deduce M(kr) (2k � 1)M(r + ck) + c0kr so that
M(d) ⌧ (2k � 1)logk d ⌧ d
log(2k�1)/ log k.
• Suppose n and m have kr digits. Write
n =
k�1X
u=0
au2ur
and m =
k�1X
v=0
bv2vr
.
• Then nm = f(2r), where
f(x) =
✓ k�1X
u=0
auxu
◆✓ k�1X
v=0
bvxv
◆.
• Compute the 2k�1 numbers yj = f(j), for 0 j 2k�2,
using 2k�1 multiplications of two r+ck digit numbers.
• Compute the coe�cients of f(x) expanded, using Lagrange
interpolation, in Ok(r) steps.
• Deduce M(kr) (2k � 1)M(r + ck) + c0kr so that
M(d) ⌧ (2k � 1)logk d ⌧ d
log(2k�1)/ log k.
Division
Problem: Given two positive integers n and m, determine
the quotient q and the remainder r when n is divided by m.
These should be integers satisfying
n = mq + r and 0 r < m.
Definition. Let M0(d) denote an upper bound on the number
of steps required to multiply two numbers with d bits. Let
D0(d) denote an upper bound on the number of steps required
to obtain q and r given n and m each have d binary digits.
Theorem. Suppose M0(d) has the form df(d) where f(d) is
an increasing function of d. Then D0(d) ⌧ M
0(d).
We need only compute 1/m to su�cient accuracy.
Suppose n and m have s digits. If 1/m = 0.d1d2d3d4...
(base 2) with d1, . . . , ds known, then
n
m=
1
2s(n ⇥ d1d2 . . . ds) + ✓, where 0 ✓ 1.
Write this in the form
n
m=
1
2s(q
02
s+ q
00) + ✓,
so n = mq0+✓
0where 0 ✓
0< 2m. Try q = q
0and q = q
0+1.
Division
Problem: Given two positive integers n and m, determine
the quotient q and the remainder r when n is divided by m.
These should be integers satisfying
n = mq + r and 0 r < m.
Definition. Let M0(d) denote an upper bound on the number
of steps required to multiply two numbers with d bits. Let
D0(d) denote an upper bound on the number of steps required
to obtain q and r given n and m each have d binary digits.
Theorem. Suppose M0(d) has the form df(d) where f(d) is
an increasing function of d. Then D0(d) ⌧ M
0(d).
We need only compute 1/m to su�cient accuracy.
Suppose n and m have s digits. If 1/m = 0.d1d2d3d4...
(base 2) with d1, . . . , ds known, then
n
m=
1
2s(n ⇥ d1d2 . . . ds) + ✓, where 0 ✓ 1.
Write this in the form
n
m=
1
2s(q
02
s+ q
00) + ✓,
so n = mq0+✓
0where 0 ✓
0< 2m. Try q = q
0and q = q
0+1.
Division
Problem: Given two positive integers n and m, determine
the quotient q and the remainder r when n is divided by m.
These should be integers satisfying
n = mq + r and 0 r < m.
Definition. Let M0(d) denote an upper bound on the number
of steps required to multiply two numbers with d bits. Let
D0(d) denote an upper bound on the number of steps required
to obtain q and r given n and m each have d binary digits.
Theorem. Suppose M0(d) has the form df(d) where f(d) is
an increasing function of d. Then D0(d) ⌧ M
0(d).
We need only compute 1/m to su�cient accuracy.
Suppose n and m have s digits. If 1/m = 0.d1d2d3d4...
(base 2) with d1, . . . , ds known, then
n
m=
1
2s(n ⇥ d1d2 . . . ds) + ✓, where 0 ✓ 1.
Write this in the form
n
m=
1
2s(q
02
s+ q
00) + ✓,
so n = mq0+✓
0where 0 ✓
0< 2m. Try q = q
0and q = q
0+1.
Division
Problem: Given two positive integers n and m, determine
the quotient q and the remainder r when n is divided by m.
These should be integers satisfying
n = mq + r and 0 r < m.
Definition. Let M0(d) denote an upper bound on the number
of steps required to multiply two numbers with d bits. Let
D0(d) denote an upper bound on the number of steps required
to obtain q and r given n and m each have d binary digits.
Theorem. Suppose M0(d) has the form df(d) where f(d) is
an increasing function of d. Then D0(d) ⌧ M
0(d).
We need only compute 1/m to su�cient accuracy.
Suppose n and m have s digits. If 1/m = 0.d1d2d3d4...
(base 2) with d1, . . . , ds known, then
n
m=
1
2s(n ⇥ d1d2 . . . ds) + ✓, where 0 ✓ 1.
Write this in the form
n
m=
1
2s(q
02
s+ q
00) + ✓,
so n = mq0+✓
0where 0 ✓
0< 2m. Try q = q
0and q = q
0+1.
Division
Problem: Given two positive integers n and m, determine
the quotient q and the remainder r when n is divided by m.
These should be integers satisfying
n = mq + r and 0 r < m.
Definition. Let M0(d) denote an upper bound on the number
of steps required to multiply two numbers with d bits. Let
D0(d) denote an upper bound on the number of steps required
to obtain q and r given n and m each have d binary digits.
Theorem. Suppose M0(d) has the form df(d) where f(d) is
an increasing function of d. Then D0(d) ⌧ M
0(d).
We need only compute 1/m to su�cient accuracy.
Suppose n and m have s digits. If 1/m = 0.d1d2d3d4...
(base 2) with d1, . . . , ds known, then
n
m=
1
2s(n ⇥ d1d2 . . . ds) + ✓, where 0 ✓ 1.
Write this in the form
n
m=
1
2s(q
02
s+ q
00) + ✓,
so n = mq0+✓
0where 0 ✓
0< 2m. Try q = q
0and q = q
0+1.
Division
Problem: Given two positive integers n and m, determine
the quotient q and the remainder r when n is divided by m.
These should be integers satisfying
n = mq + r and 0 r < m.
Definition. Let M0(d) denote an upper bound on the number
of steps required to multiply two numbers with d bits. Let
D0(d) denote an upper bound on the number of steps required
to obtain q and r given n and m each have d binary digits.
Theorem. Suppose M0(d) has the form df(d) where f(d) is
an increasing function of d. Then D0(d) ⌧ M
0(d).
We need only compute 1/m to su�cient accuracy.
Suppose n and m have s digits. If 1/m = 0.d1d2d3d4...
(base 2) with d1, . . . , ds known, then
n
m=
1
2s(n ⇥ d1d2 . . . ds) + ✓, where 0 ✓ 1.
Write this in the form
n
m=
1
2s(q
02
s+ q
00) + ✓,
so n = mq0+✓
0where 0 ✓
0< 2m. Try q = q
0and q = q
0+1.
Division
Problem: Given two positive integers n and m, determine
the quotient q and the remainder r when n is divided by m.
These should be integers satisfying
n = mq + r and 0 r < m.
Definition. Let M0(d) denote an upper bound on the number
of steps required to multiply two numbers with d bits. Let
D0(d) denote an upper bound on the number of steps required
to obtain q and r given n and m each have d binary digits.
Theorem. Suppose M0(d) has the form df(d) where f(d) is
an increasing function of d. Then D0(d) ⌧ M
0(d).
We need only compute 1/m to su�cient accuracy.
Suppose n and m have s digits. If 1/m = 0.d1d2d3d4...
(base 2) with d1, . . . , ds known, then
n
m=
1
2s(n ⇥ d1d2 . . . ds) + ✓, where 0 ✓ 1.
Write this in the form
n
m=
1
2s(q
02
s+ q
00) + ✓,
so n = mq0+✓
0where 0 ✓
0< 2m. Try q = q
0and q = q
0+1.
Division
Problem: Given two positive integers n and m, determine
the quotient q and the remainder r when n is divided by m.
These should be integers satisfying
n = mq + r and 0 r < m.
Definition. Let M0(d) denote an upper bound on the number
of steps required to multiply two numbers with d bits. Let
D0(d) denote an upper bound on the number of steps required
to obtain q and r given n and m each have d binary digits.
Theorem. Suppose M0(d) has the form df(d) where f(d) is
an increasing function of d. Then D0(d) ⌧ M
0(d).
We need only compute 1/m to su�cient accuracy.
Suppose n and m have s digits. If 1/m = 0.d1d2d3d4...
(base 2) with d1, . . . , ds known, then
n
m=
1
2s(n ⇥ d1d2 . . . ds) + ✓, where 0 ✓ 1.
Write this in the form
n
m=
1
2s(q
02
s+ q
00) + ✓,
so n = mq0+✓
0where 0 ✓
0< 2m. Try q = q
0and q = q
0+1.
Division
Problem: Given two positive integers n and m, determine
the quotient q and the remainder r when n is divided by m.
These should be integers satisfying
n = mq + r and 0 r < m.
Definition. Let M0(d) denote an upper bound on the number
of steps required to multiply two numbers with d bits. Let
D0(d) denote an upper bound on the number of steps required
to obtain q and r given n and m each have d binary digits.
Theorem. Suppose M0(d) has the form df(d) where f(d) is
an increasing function of d. Then D0(d) ⌧ M
0(d).
We need only compute 1/m to su�cient accuracy.
Suppose n and m have s digits. If 1/m = 0.d1d2d3d4...
(base 2) with d1, . . . , ds known, then
n
m=
1
2s(n ⇥ d1d2 . . . ds) + ✓, where 0 ✓ 1.
Write this in the form
n
m=
1
2s(q
02
s+ q
00) + ✓,
so n = mq0+✓
0where 0 ✓
0< 2m. Try q = q
0and q = q
0+1.
Division
Problem: Given two positive integers n and m, determine
the quotient q and the remainder r when n is divided by m.
These should be integers satisfying
n = mq + r and 0 r < m.
Definition. Let M0(d) denote an upper bound on the number
of steps required to multiply two numbers with d bits. Let
D0(d) denote an upper bound on the number of steps required
to obtain q and r given n and m each have d binary digits.
Theorem. Suppose M0(d) has the form df(d) where f(d) is
an increasing function of d. Then D0(d) ⌧ M
0(d).
We need only compute 1/m to su�cient accuracy.
Suppose n and m have s digits. If 1/m = 0.d1d2d3d4...
(base 2) with d1, . . . , ds known, then
n
m=
1
2s(n ⇥ d1d2 . . . ds) + ✓, where 0 ✓ 1.
Write this in the form
n
m=
1
2s(q
02
s+ q
00) + ✓,
so n = mq0+✓
0where 0 ✓
0< 2m. Try q = q
0and q = q
0+1.
Newton’s Method
Say we want to compute 1/m. Take a function f(x) which
has root 1/m. If x0
is an approximation to the root, then
how can we get a better approximation? Take f(x) = m �1/x. Starting with x
0= x0, this leads to the approximations
xn+1 = 2xn � mx2
n.
Note that if xn = (1 � ")/m, then xn+1 = (1 � "2)/m.
Newton’s Method
Say we want to compute 1/m. Take a function f(x) which
has root 1/m. If x0
is an approximation to the root, then
how can we get a better approximation? Take
f(x) = m � 1/x.
Starting with x0= x0, this leads to the approximations
xn+1 = 2xn � mx2
n.
Note that if xn = (1 � ")/m, then xn+1 = (1 � "2)/m.
Newton’s Method
Say we want to compute 1/m. Take a function f(x) which
has root 1/m. If x0
is an approximation to the root, then
how can we get a better approximation? Take f(x) = m �1/x. Starting with x
0= x0, this leads to the approximations
xn+1 = 2xn � mx2
n.
Note that if xn = (1 � ")/m, then xn+1 = (1 � "2)/m.
Newton’s Method
Say we want to compute 1/m. Take a function f(x) which
has root 1/m. If x0
is an approximation to the root, then
how can we get a better approximation? Take
f(x) = m � 1/x.
Starting with x0= x0, this leads to the approximations
xn+1 = 2xn � mx2
n.
Note that if xn = (1 � ")/m, then xn+1 = (1 � "2)/m.
Newton’s Method
Say we want to compute 1/m. Take a function f(x) which
has root 1/m. If x0
is an approximation to the root, then
how can we get a better approximation? Take
f(x) = m � 1/x.
Starting with x0= x0, this leads to the approximations
xn+1 = 2xn � mx2
n.
Note that if xn = (1 � ")/m, then xn+1 = (1 � "2)/m.
Algorithm from Knuth, Vol. 2, pp. 295-6
Algorithm R. Let v in binary be v = (0.v1v2v3 . . . )2, with
v1 = 1. The algorithm outputs z satisfying
|z � 1/v| 2�n
.
R1. [Initialize] Set z 1
4b32/(4v1 + 2v2 + v3)c and k 0.
R2. [Newton iteration] (At this point, z 2 has the binary
form (⇤⇤.⇤⇤ · · · ⇤)2 with 2k+1 places after the radix point.)
Calculate z2
exactly. Then calculate Vkz2
exactly, where
Vk = (0.v1v2 . . . v2k+1+3
)2. Then set z 2z � Vkz2
+ r,
where 0 r < 2�2
k+1�1is added if needed to “round up”
z so that it is a multiple of 2�2
k+1�1. Finally, set k k+1.
R3. [End Test] If 2k
< n, go back to step R2; otherwise the
algorithm terminates.
Algorithm from Knuth, Vol. 2, pp. 295-6
Algorithm R. Let v in binary be v = (0.v1v2v3 . . . )2, with
v1 = 1. The algorithm outputs z satisfying
|z � 1/v| 2�n
.
R1. [Initialize] Set z 1
4b32/(4v1 + 2v2 + v3)c and k 0.
R2. [Newton iteration] (At this point, z 2 has the binary
form (⇤⇤.⇤⇤ · · · ⇤)2 with 2k+1 places after the radix point.)
Calculate z2
exactly. Then calculate Vkz2
exactly, where
Vk = (0.v1v2 . . . v2k+1+3
)2. Then set z 2z � Vkz2
+ r,
where 0 r < 2�2
k+1�1is added if needed to “round up”
z so that it is a multiple of 2�2
k+1�1. Finally, set k k+1.
R3. [End Test] If 2k
< n, go back to step R2; otherwise the
algorithm terminates.
Algorithm from Knuth, Vol. 2, pp. 295-6
Algorithm R. Let v in binary be v = (0.v1v2v3 . . . )2, with
v1 = 1. The algorithm outputs z satisfying
|z � 1/v| 2�n
.
R1. [Initialize] Set z 1
4b32/(4v1 + 2v2 + v3)c and k 0.
R2. [Newton iteration] (At this point, z 2 has the binary
form (⇤⇤.⇤⇤ · · · ⇤)2 with 2k+1 places after the radix point.)
Calculate z2
exactly. Then calculate Vkz2
exactly, where
Vk = (0.v1v2 . . . v2k+1+3
)2. Then set z 2z � Vkz2
+ r,
where 0 r < 2�2
k+1�1is added if needed to “round up”
z so that it is a multiple of 2�2
k+1�1. Finally, set k k+1.
R3. [End Test] If 2k
< n, go back to step R2; otherwise the
algorithm terminates.
z 2 [0, 2]