Multiplying Big Integers in Time O(n1.59)

[a variant of Karatsuba's method; see Knuth Vol.2, pp.294-5 or AHU pp.62-64]

The traditional method to multiply two n-bit numbers requires O(n2) bit operations.  We shall do better.

Let x and y be two n-bit numbers, with n = 2m.
Then   x   can be expressed as   a 2n/2 + b,   and   y   can be expressed as   c 2n/2 + d.

We can evaluate z as the product of x and y by

z  =  x*y
   =  (a 2n/2 + b) * (c 2n/2 + d)
   =  a*c 2n + (a*d + b*c) 2n/2 + b*d

This approach uses 4 multiplications of n/2-bit integers, plus some adds and shifts.
(These mults are shown with *.)

Consider the following alternative calculation:

	K := (a-b)*(c-d)
	L := a*c
	M := b*d
	z := L 2n + (L+M-K) 2n/2 + M

This approach uses only 3 multiplications of n/2-bit integers, plus some (k) adds, subtracts and shifts. 
(These mults are shown with *.)  Adds, subtracts and shifts of n-bit numbers take time O(n). 
So we obtain the following recurrence for T(n), the time required to multiply two n-bit numbers:

	T(1) < k
	T(n) = 3T(n/2) + kn, when n > 1

If we let T(1) = k, then...

Claim  the recurrence is solved by:         T(n) = 3knlg 3 - 2kn.

Proof  by induction on n = 2m.

Basis:   when n = 1, the Claim is true by inspection.

Induction step:   Assume that the Claim is true for n, to show that the Claim is true for 2n.
(Note that 3 = 2lg 3.)
T(2n) = 3T(n) + k(2n)
    = 3[3knlg 3 - 2kn] + 2kn
    = 3k(2n)lg 3 - 2k(2n), and therefore the Claim is true for 2n.


Last modified: Mar 18, 2003