Next: 1.3 Long Division Algorithm
Up: 1 Multiple Precision Arithmetic
Previous: 1.1 Addition and Subtraction
As is to be expected, multiplication is more complicated. The usual
method of multiplication requires simultaneous summation of multiple
rows of decimal numbers. The carry over from addition thus becomes
quite large, whereas our basic routines can only handle a carry of 0
or 1. It is best to proceed slowly!
First of all we look at a procedure to multiply by a single ``digit''
u and perform the calculation,
u×(v_{1}^{ ... }v_{p}) = (w_{0}w_{1}^{ ... }w_{p}).
Actually we will need the more general ``linear form'' operation
(we will assume that q p + 1 by padding t by zeros if necessary)
u×(v_{1}^{ ... }v_{p}) + (t_{0}^{ ... }t_{q}) = (w_{0}^{ ... }w_{q + 1})
More diagrammatically,



v_{1} 
v_{2} 
^{ ... } 
v_{p  1} 
v_{p} 
× 






u 
+ 
t_{0} 
t_{1} 
t_{2} 
t_{3} 
^{ ... } 
t_{q  1} 
t_{q} 


x_{1} 
x_{2} 
x_{3} 
^{ ... } 
x_{p} 




y_{1} 
y_{2} 
^{ ... } 
y_{p  1} 
y_{p} 
z_{0} 
z_{1} 
z_{2} 
z_{3} 
^{ ... } 
z_{q  1} 
z_{q} 
z_{q + 1} 
w_{0} 
w_{1} 
w_{1} 
w_{2} 
^{ ... } 
w_{q  1} 
w_{q} 
w_{q + 1} 
The usual multiplication procedures leads to certain intermediate
digits which we denote by x, y, z as above. We obtain
the identities
(x_{p}, y_{p}) 
= 
(u, v_{p}) 

(w_{q + 1},) 
= 
(t_{p}, y_{0}, 0) 

(z_{q},) 
= 
(t_{q  1}, x_{p}, 0) 

(x_{p  i}, y_{p  i}) 
= 
(u, v_{p  i}) 

(w_{q + 1  i},) 
= 
(z_{q + 1  i}, y_{p  i},) 

(z_{q  i},) 
= 
(t_{q  i  1}, x_{p  i},) 

As before the first three steps are a special case of the latter three
when we put
= 0 = and z_{p} = t_{p}. There are q + 2 cycles.
The
operation actually takes place only in the first p cycles
(in the remaining cases x_{j} and y_{j} are zero). The last
operation does not take place on the last cycle. Thus, are at most
p + 2q + 3 steps.
Now we use the above routine repeatedly to obtain the general linear
form, (where as before we assume that
s p + q + 1)
(u_{1}^{ ... }u_{p})×(v_{1}^{ ... }v_{q}) + (t_{0}^{ ... }t_{s  1}) = (w_{0}^{ ... }w_{s})
We see that this is achieved by intermediate computations of the form
u_{p}×(v_{1}^{ ... }v_{q}) + (t_{0}^{ ... }t_{s  1}) 
= 
(z_{0, p}^{ ... }z_{s, p}) 

u_{p  i}×(v_{1}^{ ... }v_{q}) + (z_{0, p  i + 1}^{ ... }z_{s  i, p  i + 1}) 
= 
(z_{0, p  i}^{ ... }z_{s  i, p  i}) 

Then
w_{s  i} = z_{s  i, p  i} since the (s  i)th ``digit''
z_{s  i, p  i} is not affected by subsequent computations. If we
initialise
(z_{0, p + 1}^{ ... }z_{s, p + 1}) to be equal to
(t_{0},^{ ... }t_{s  1}), then first computation is a special case of the second. We
will perform p cycles, each a linear form as above of the length
q + 2s + 3. Thus the number of steps is order of pq + 2ps + 3p steps.
While this looks a bit complex, it is still not the most efficient
when the p and q are large enough to allow us to use more (order
linear in p and q) ``bookkeeping'' steps in exchange for
efficiency.
Next: 1.3 Long Division Algorithm
Up: 1 Multiple Precision Arithmetic
Previous: 1.1 Addition and Subtraction
Kapil Hari Paranjape
20021020