AKS PRIMALITY TEST:
First we describe a characterization of prime numbers that will provide the conceptual mathematical foundation for our polynomial time algorithm.
Lemma 3.1: Let a∈ Z, n ∈ N, such that (a, n) = 1. Then n is prime iff (x+a)n ≡ xn +a (mod n).
Proof:
By the Binomial theorem we have:
If n is prime then
is divisible by n according to the binomial theorem. By Fermat's little theorem, we have an ≡ a (mod n) and hence the equivalence in the above equation holds.
If n is composite, then let q be a prime divisor of n with qs | n . The coefficient of xn-q in the binomial expansion of (x + a)n is
aq . The numerator is divisible by qs but not by qs+1. The denominator is divisible by q. Hence
aq≠ 0(mod n). Since (a,n) = 1, implies (a,qs) = 1, implies (aq, qs) = 1, implies
aq ≠ 0(mod n).
Therefore (x+a)n ≠ xn + a (mod n)
The above identity suggests a simple method for testing the primality of an integer n. We can choose an integer a such that (a, n) = 1 and calculate f(x) = (x + a)n - (xn + a). If this function is equal to 0 (mod n) then n is prime, else n is composite. Although this is certainly a valid primality test, it is horribly inefficient as it involves the computation of n coefficients. The trick however is in choosing a suitable integer a. The simplest method for reducing the number of coefficients that need to be computed is to evaluate f(x) modulo n and modulo some polynomial of small degree, say (xr - 1).
Although it is clear that all primes p satisfy (x + a)p - (xp + a) ≡ 0 mod (p, xr -1), some composite numbers may satisfy this equation for all values of a and r. It turns out that for a judiciously chosen r, if the above identity is satisfied for several values of a, then n can be shown to be a prime power. The number of a's and the appropriate value of r are bounded by log(n). Therefore we have just described a deterministic polynomial time primality testing algorithm.