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.1 Tour of “grammar-school” methods 445<br />

where δn is 0 for n odd, else x2 n/2 for n even. It is clear that each column<br />

component wn involves about half the size-B multiplies required for the<br />

general multiplication algorithm. Of course, final carry operations must be<br />

performedonthewn, togetthefinaldigitsznof the product z = x2 , but<br />

in most practical instances, this squaring is indeed roughly twice as fast as a<br />

multiple-precision multiply. There exist in the literature some very readable<br />

expositions of the squaring algorithm and related algorithms. See, for example,<br />

[Menezes et al. 1997].<br />

There is an elegant, if simple, argument showing that general multiplication<br />

has no more than twice the complexity of squaring. One invokes the<br />

identity<br />

4xy =(x + y) 2 − (x − y) 2 , (9.4)<br />

which indicates that a multiplication can be effected by two squarings and a<br />

divide by four, this final divide presumed trivial (as, say, a right-shift by two<br />

bits). This observation is not just academic, for in certain practical scenarios<br />

this algebraic rule may be exploited (see Exercise 9.6).<br />

9.1.3 Div and mod<br />

Div and mod operations are omnipresent in prime-number and factorization<br />

studies. These operations often occur in combination with multiplication, in<br />

fact, this symbiosis is exploited in some of the algorithms we shall describe.<br />

It is quite common that one spends computation effort on operations such as<br />

xy (mod p), for primes p, or in factorization studies xy (mod N) whereN is<br />

to be factored.<br />

It is a primary observation that the mod operation can hinge on the<br />

div operation. We shall use, as before, the notation x mod N to denote the<br />

operation that results in the least nonnegative residue of x (mod N), while<br />

the greatest integer in x/N, denoted by ⌊x/N⌋, isthedivresult.(Insome<br />

computer languages these operations are written “x%N” and“x div N,”<br />

respectively, while in others the integer divide “x/N” means just div, while<br />

in yet others the div is “Floor[x/N],” and so on.) For integers x and positive<br />

integers N, a basic relation in our present notation is<br />

x mod N = x − N⌊x/N⌋. (9.5)<br />

Note that this relation is equivalent to the quotient–remainder decomposition<br />

x = qN + r, with q, r being respectively the div and mod results under<br />

consideration. So the div operation begets the mod, and we can proceed with<br />

algorithm descriptions for div.<br />

Analogous to “grammar-school” multiplication is, of course, the elementary<br />

method of long division. It is fruitful to contemplate even this simple<br />

long division algorithm, with a view to enhancements. In the normal execution<br />

of long division in a given base B, the divisor N is first justified to the<br />

left, with respect to the dividend x. Thatistosay,apowerB b of the base<br />

is found such that m = B b N ≤ x

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

Saved successfully!

Ooh no, something went wrong!