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.

9.3 Exponentiation 459<br />

But there is a kind of complementary way to effect the powering. This<br />

alternative is exemplified in the relation<br />

x 13 = x ∗ (x 2 ) 2 ∗ (x 4 ) 2 ,<br />

where there are again 2 multiplications and 3 squarings (because x 4 was<br />

actually obtained as the middle term (x 2 ) 2 ). In fact, in this example we see<br />

more directly the binary expansion of the exponent. The general formula<br />

would be<br />

x y j<br />

yj2<br />

= x = x y0 (x 2 ) y1 (x 4 ) y2 ···, (9.16)<br />

where the yj are the bits of y. The corresponding algorithm is a “right-left”<br />

ladder in which we keep track of successive squarings of x:<br />

Algorithm 9.3.2 (Binary ladder exponentiation (right-left 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; a =1;<br />

2. [Loop over bits of y, starting with lowest]<br />

for(0 ≤ j

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

Saved successfully!

Ooh no, something went wrong!