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.

202 Chapter 4 PRIMALITY PROVING<br />

Algorithm 4.5.1 (Agrawal–Kayal–Saxena (AKS) primality test). We are<br />

given an integer n ≥ 2. This deterministic algorithm decides whether n is prime<br />

or composite.<br />

1. [Power test]<br />

If n is a square or higher power, return “n is composite”;<br />

2. [Setup]<br />

Find the least integer r with the order of n in Z ∗ r exceeding lg 2 n;<br />

If n has a proper factor in [2, ϕ(r)lgn], return “n is composite”;<br />

// ϕ is Euler’s function.<br />

3. [Binomial congruences]<br />

for(1 ≤ a ≤ ϕ(r)lgn) {<br />

if((x + a) n ≡ x n + a (mod x r − 1,n)) return “n is composite”;<br />

}<br />

Return “n is prime”;<br />

Square testing in Step [Power test] may be done by Algorithm 9.2.11,<br />

and higher-power testing may be done by a similar Newton iteration, cf.<br />

Exercise 4.11. Note that one has only to test that n is in the form a b for<br />

b ≤ lg n. (Note too that from Exercise 4.28, Step [Power test] may actually be<br />

skipped entirely!) The integer r in Step [Setup] may be found by sequential<br />

search over the integers exceeding lg 2 n. In this search, if a value of r is found<br />

for which 1 < gcd(r, n) ϕ(r)lgn. Since Step [Setup]<br />

involves a search for small divisors of n, it may occur that all possibilities up<br />

to √ n are accounted for, and so n is proved prime. In this case, of course, one<br />

need not continue to Step [Binomial congruences], but this event can occur<br />

only for fairly small values of n. See the end of Section 4.5.4 for more notes<br />

on AKS implementation.<br />

We shall return to the issue of the size of r when we discuss the complexity<br />

of the algorithm, but first we will discuss why the algorithm is correct.<br />

Algorithm 4.5.1 is based principally on the following beautiful criterion.<br />

Theorem 4.5.2 (Agrawal, Kayal, Saxena). Suppose n is an integer with<br />

n ≥ 2, r is a positive integer coprime to n such that the order of n in Z ∗ r<br />

is larger than lg 2 n,and<br />

(x + a) n ≡ x n + a (mod x r − 1,n) (4.26)<br />

holds for each integer a with 0 ≤ a ≤ ϕ(r)lgn. Ifn has a prime factor<br />

p> ϕ(r)lgn, then n = p m for some positive integer m. In particular, if n<br />

has no prime factors in [1, ϕ(r)lgn] and n is not a proper power, then n is<br />

prime.

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

Saved successfully!

Ooh no, something went wrong!