Prime Numbers

Prime Numbers Prime Numbers

thales.doa.fmph.uniba.sk
from thales.doa.fmph.uniba.sk More from this publisher
10.12.2012 Views

9.5 Large-integer multiplication 505 and similarly for the Yj. It is evident that the (total of) 2m X,Y polynomials can be stored in two arrays that are (r, m)-transpositions of x, y arrays respectively. Next we multiply x(t)y(t) by performing the cyclic convolution Z =(X0,X1,...,Xm−1, 0,...,0) × (Y0,Y1,...,Ym−1, 0,...,0) , where each operand signal here has been zero-padded to total length 2m. The key point here is that Z canbeevaluatedbyasymbolic DFT, using what we know to be a primitive 2m-throotofunity,namelyz r/m . What this means is that the usual FFT butterfly operations now involve mere shuttling around of polynomials, because multiplications by powers of the primitive root just translate coefficient polynomials. In other words the polynomial arithmetic now proceeds along the lines of Theorem 9.2.12, in that multiplication by a power of the relevant root is equivalent to a kind of shift operation. At a key juncture of the usual DFT-based convolution method, namely the dyadic (elementwise) multiply step, the dyadic operations can be seen to be themselves length-r negacyclic convolutions. This is evident on the observation that each of the polynomials Xj,Yj hasdegree(r − 1) in the variable z = t m , and so z r = t D = −1. To complete the Z convolution, a final, inverse DFT, with root z −r/m , is to be used. The result of this zero-padded convolution is seen to be a product in the ring S: x(t)y(t) = 2m−2 j=0 Zj(t m )t j , (9.37) from which we extract the negacyclic elements of x ×− y as the coefficients of thepowersoft. Algorithm 9.5.25 (Nussbaumer convolution, cyclic and negacyclic). Assume length-(D =2 k ) signals x, y whose elements belong to a ring R, which ring also admits of cancellation-by-2. This algorithm returns either the cyclic (x×y) or negacyclic (x×− y) convolution. Inside the negacyclic function neg is a “small” negacyclic routine smallneg, for example a grammar-school or Karatsuba version, which is called below a certain length threshold. 1. [Initialize] r =2 ⌈k/2⌉ ; m = D/r; // Now m divides r. blen =16; // Tune this small-negacyclic breakover length to taste. 2. [Cyclic convolution function cyc, recursive] cyc(x, y) { By calling half-length cyclic and negacyclic convolutions, return the desired cyclic, via identity (9.36); } 3. [Negacyclic convolution function neg, recursive] neg(x, y) { if(len(x) ≤ blen) return smallneg(x, y);

506 Chapter 9 FAST ALGORITHMS FOR LARGE-INTEGER ARITHMETIC 4. [Transposition step] Create a total of 2m arrays Xj,Yj each of length r; Zero-pad the X, Y collections so each collection has 2m polynomials; Using root g = z r/m , perform (symbolically) two length-2m DFTs to get the transforms ˆ X, ˆ Y ; 5. [Recursive dyadic operation] for(0 ≤ h

9.5 Large-integer multiplication 505<br />

and similarly for the Yj. It is evident that the (total of) 2m X,Y polynomials<br />

can be stored in two arrays that are (r, m)-transpositions of x, y arrays<br />

respectively. Next we multiply x(t)y(t) by performing the cyclic convolution<br />

Z =(X0,X1,...,Xm−1, 0,...,0) × (Y0,Y1,...,Ym−1, 0,...,0) ,<br />

where each operand signal here has been zero-padded to total length 2m. The<br />

key point here is that Z canbeevaluatedbyasymbolic DFT, using what we<br />

know to be a primitive 2m-throotofunity,namelyz r/m . What this means is<br />

that the usual FFT butterfly operations now involve mere shuttling around<br />

of polynomials, because multiplications by powers of the primitive root just<br />

translate coefficient polynomials. In other words the polynomial arithmetic<br />

now proceeds along the lines of Theorem 9.2.12, in that multiplication by a<br />

power of the relevant root is equivalent to a kind of shift operation.<br />

At a key juncture of the usual DFT-based convolution method, namely the<br />

dyadic (elementwise) multiply step, the dyadic operations can be seen to be<br />

themselves length-r negacyclic convolutions. This is evident on the observation<br />

that each of the polynomials Xj,Yj hasdegree(r − 1) in the variable z = t m ,<br />

and so z r = t D = −1. To complete the Z convolution, a final, inverse DFT,<br />

with root z −r/m , is to be used. The result of this zero-padded convolution is<br />

seen to be a product in the ring S:<br />

x(t)y(t) =<br />

2m−2 <br />

j=0<br />

Zj(t m )t j , (9.37)<br />

from which we extract the negacyclic elements of x ×− y as the coefficients of<br />

thepowersoft.<br />

Algorithm 9.5.25 (Nussbaumer convolution, cyclic and negacyclic).<br />

Assume length-(D =2 k ) signals x, y whose elements belong to a ring R, which<br />

ring also admits of cancellation-by-2. This algorithm returns either the cyclic<br />

(x×y) or negacyclic (x×− y) convolution. Inside the negacyclic function neg is a<br />

“small” negacyclic routine smallneg, for example a grammar-school or Karatsuba<br />

version, which is called below a certain length threshold.<br />

1. [Initialize]<br />

r =2 ⌈k/2⌉ ;<br />

m = D/r; // Now m divides r.<br />

blen =16; // Tune this small-negacyclic breakover length to taste.<br />

2. [Cyclic convolution function cyc, recursive]<br />

cyc(x, y) {<br />

By calling half-length cyclic and negacyclic convolutions, return the<br />

desired cyclic, via identity (9.36);<br />

}<br />

3. [Negacyclic convolution function neg, recursive]<br />

neg(x, y) {<br />

if(len(x) ≤ blen) return smallneg(x, y);

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

Saved successfully!

Ooh no, something went wrong!