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.

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

the exponent, and so on. Let us first summarize the categories of powering<br />

ladders:<br />

(1) Recursive powering ladder (Algorithm 2.1.5).<br />

(2) Left-right and right-left “unrolled” binary ladders.<br />

(3) Windowing ladders, to take advantage of certain bit patterns or of<br />

alternative base expansions, a simple example of which being what is<br />

essentially a ternary method in Algorithm 7.2.7, step [Loop over bits ...],<br />

although one can generally do somewhat better [Müller 1997], [De Win et<br />

al. 1998], [Crandall 1999b].<br />

(4) Fixed-x ladders, to compute x y for various y but fixed x.<br />

(5) Addition chains and Lucas ladders, as in Algorithm 3.6.7, interesting<br />

references being such as [Montgomery 1992b], [Müller 1998].<br />

(6) Modern methods based on actual compression of exponent bit-streams, as<br />

in [Yacobi 1999].<br />

The current section starts with basic binary ladders (and even for these,<br />

various options exist); then we turn to the windowing, alternative-base, and<br />

fixed-x ladders.<br />

9.3.1 Basic binary ladders<br />

We next give two forms of explicit binary ladders. The first, a “left-right”<br />

form (equivalent to Algorithm 2.1.5), is comparable in complexity (except<br />

when arguments are constrained in certain ways) to a second, “right-left”<br />

form.<br />

Algorithm 9.3.1 (Binary ladder exponentiation (left-right form)).<br />

This algorithm computes x y . We assume the binary expansion (y0,...,yD−1)<br />

of y>0, where yD−1 =1is the high bit.<br />

1. [Initialize]<br />

z = x;<br />

2. [Loop over bits of y, starting with next-to-highest]<br />

for(D − 2 ≥ j ≥ 0) {<br />

z = z 2 ; // For modular arithmetic, do modN here.<br />

if(yj == 1) z = zx; // For modular arithmetic, do modN here.<br />

}<br />

return z;<br />

This algorithm constructs the power x y by running through the bits of the<br />

exponent y. Indeed, the number of squarings is (D − 1), and the number of<br />

operations z = z ∗ x is clearly one less than the number of 1 bits in the<br />

exponent y. Note that the operations turn out to be those of Algorithm 2.1.5.<br />

A mnemonic for remembering which of the left-right or right-left ladder forms<br />

is equivalent to the recursive form is to note that both Algorithms 9.3.1 and<br />

2.1.5 involve multiplications exclusively by the steady multiplier x.

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

Saved successfully!

Ooh no, something went wrong!