next up previous
Next: 1.2 Multiplication Algorithm Up: 1 Multiple Precision Arithmetic Previous: 1 Multiple Precision Arithmetic

1.1 Addition and Subtraction Algorithm

We now write the addition recipe using the usual method

  u1 u2 ... up
  v1 v2 ... vp
$\displaystyle \rho$ w1 w2 ... wp

Or more concisely

(u1 ... up) + (v1 ... vp) = (w1 ... wp) + $\displaystyle \rho$Mp = ($\displaystyle \rho$w1 ... wp)

The identities that are satisfied are
(wp,$\displaystyle \rho_{0}^{}$) = $\displaystyle \tt add$ (up, vp, 0)  
(wp - i,$\displaystyle \rho_{i}^{}$) = $\displaystyle \tt add$ (up - i, vp - i,$\displaystyle \rho_{i-1}^{}$)  

We can clearly write these identities quite concisely by defining $ \rho_{-1}^{}$ = 0. It is thus clear how to calculate this inductively for all i upto i = p. At the last stage the carry over is the extra $ \rho$ = $ \rho_{p}^{}$ in the answer.

A similar technique applies to the subtraction method. We write the identity

(u1 ... up) - (v1 ... vp) = (w1 ... wp) - $\displaystyle \rho$Mp

And find the identities
(wp,$\displaystyle \rho_{0}^{}$) = $\displaystyle \tt sub$ (up, vp, 0)  
(wp - i,$\displaystyle \rho_{i}^{}$) = $\displaystyle \tt sub$ (up - i, vp - i,$\displaystyle \rho_{i-1}^{}$)  

Again, putting $ \rho_{-1}^{}$ = 0 combines the identities and we can easily compute these inductively. Note that $ \rho$ = $ \rho_{p}^{}$ is the ``extra'' borrow element and so if this is non-zero then (v1 ... vp) is in fact more than (u1 ... up). We will see that this calculation is useful even in this case.

We note that the number of steps taken by both methods is equal to p.


next up previous
Next: 1.2 Multiplication Algorithm Up: 1 Multiple Precision Arithmetic Previous: 1 Multiple Precision Arithmetic
Kapil Hari Paranjape 2002-10-20