10.12.2012 Views

Prime Numbers

Prime Numbers

Prime Numbers

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

466 Chapter 9 FAST ALGORITHMS FOR LARGE-INTEGER ARITHMETIC<br />

Algorithm 2.1.4. Incidentally, the authors of this algorithm also give an<br />

interesting method for rapid calculation of ⌊p/z⌋ when p =2 q −1 is specifically<br />

a Mersenne prime.<br />

Yet other inversion methods focus on the specific case that p is a Mersenne<br />

prime. The following is an interesting attempt to exploit the special form of<br />

the modulus:<br />

Algorithm 9.4.5 (Inversion modulo a Mersenne prime). For p = 2 q − 1<br />

prime and x ≡ 0(modp), this algorithm returns x −1 mod p.<br />

1. [Initialize]<br />

(a, b, y, z) =(1, 0,x,p);<br />

2. [Relational reduction]<br />

Find e such that 2 e y;<br />

y = y/2 e ; // Shift off trailing zeros.<br />

a =(2 q−e a)modp; // Circular shift, by Theorem 9.2.12.<br />

if(y == 1) return a;<br />

(a, b, y, z) =(a + b, a, y + z,y);<br />

goto [Relational reduction];<br />

9.4.3 Recursive-gcd schemes for very large operands<br />

It turns out that the classical bit-complexity O(ln 2 N) for evaluating the gcd of<br />

twonumbers,eachofsizeN, can be genuinely reduced via recursive reduction<br />

techniques, as first observed in [Knuth 1971]. Later it was established that such<br />

recursive approaches can be brought down to complexity<br />

O(M(ln N)lnlnN),<br />

where M(b) denotes the bit-complexity for multiplication of two b-bit integers.<br />

With the best-known bound for M(b), as discussed later in this chapter, the<br />

complexity for these recursive gcd algorithms is thus<br />

O ln N(ln ln N) 2 ln ln ln N .<br />

Studies on the recursive approach span several decades; references include<br />

[Schönhage 1971], [Aho et al. 1974, pp. 300–310], [Bürgisser et al. 1997,<br />

p. 98], [Cesari 1998], [Stehlé and Zimmermann 2004]. For the moment, we<br />

observe that like various other algorithms we have encountered—such as preconditioned<br />

CRT—the recursive-gcd approach cannot really use grammarschool<br />

multiplication to advantage.<br />

We shall present in this section two recursive-gcd algorithms, the original<br />

one from the 1970s that, for convenience, we call the Knuth–Schönhage gcd<br />

(or KSgcd)—–and a very new, pure-binary one by Stehlé–Zimmermann (called<br />

the SZgcd). Both variants turn out to have the same asymptotic complexity,<br />

but differ markedly in regard to implementation details.<br />

One finds in practice that recursive-gcd schemes outperform all known<br />

alternatives (such as the binary gcd forms with or without Lehmer enhancements)<br />

when the input arguments x, y are sufficiently large, say in the region

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

Saved successfully!

Ooh no, something went wrong!