10.12.2012 Views

Prime Numbers

Prime Numbers

Prime Numbers

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

9.5 Large-integer multiplication 503<br />

if(Cj > (j + 1)22M ) Cj = Cj − (2n′ +1);<br />

} // Cj now possibly negative.<br />

9. [Composition]<br />

Perform carry operations as in steps [Adjust carry in base B] forB =2 M<br />

(the original decomposition base) and [Final modular adjustment] of<br />

Algorithm 9.5.17 to return the desired sum:<br />

xy mod (2 n +1)= D−1<br />

j=0 Cj2 jM mod (2 n +1);<br />

Note that in the [Decomposition] step, AD−1 or BD−1 may equal 2 M and<br />

have M + 1 bits in the case where x or y equal 2 n . In Step [Prepare<br />

DWT ...], each multiply can be done using shifts and subtractions only, as<br />

2n′ ≡−1( mod 2n′ +1). In Step [Dyadic stage], one can use any multiplication<br />

algorithm, for example a grammar-school stage, Karatsuba algorithm, or this<br />

very Schönhage algorithm recursively. In Step [Normalization], the divisions<br />

by a power of two again can be done using shifts and subtractions only. Thus<br />

the only multiplication per se is in Step [Dyadic stage], and this is why the<br />

method can attain, in principle, such low complexity. Note also that the two<br />

FFTs required for the negacyclic result signal C can be performed in the order<br />

DIF, DIT, for example by using parts of Algorithm 9.5.5 in proper order, thus<br />

obviating the need for any bit-scrambling procedure.<br />

As it stands, Algorithm 9.5.23 will multiply two integers modulo any<br />

Fermat number, and such application is an important one, as explained in<br />

other sections of this book. For general multiplication of two integers x and<br />

y, one may call the Schönhage algorithm with n ≥⌈lg x⌉ + ⌈lg y⌉, and zeropadding<br />

x, y accordingly, whence the product xy mod 2n +1 equals the integer<br />

product. (In a word, the negacyclic convolution of appropriately zero-padded<br />

sequences is the acyclic convolution—the product in essence. ) In practice,<br />

Schönhage suggests using what he calls “suitable numbers,” i.e., n = ν2k with k − 1 ≤ ν ≤ 2k − 1. For example, 688128 = 21 · 215 is a suitable number.<br />

Such numbers enjoy the property that if k = ⌈n/2⌉ +1, then n ′ = ⌈ ν+1<br />

2 ⌉2k<br />

is also a suitable number; here we get indeed n ′ =11· 2 8 = 2816. Of course,<br />

one loses a factor of two initially with respect to modular multiplication, but<br />

in the recursive calls all computations are performed modulo some 2 M +1, so<br />

the asymptotic complexity is still that reported in Section 9.5.8.<br />

9.5.7 Nussbaumer method<br />

It is an important observation that a cyclic convolution of some even length<br />

D can be cast in terms of a pair of convolutions, a cyclic and a negacyclic,<br />

each of length D. The relevant identity is<br />

2(x × y) =[(u+ × v+)+(u− ×− v−)] ∪ [(u+ × v+) − (u− ×− v−)], (9.36)<br />

where u, v signals depend in turn on half-signals:<br />

u± = L(x) ± H(x),<br />

v± = L(y) ± H(y).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!