AKS primality test
The AKS primality test is a deterministic primality-proving algorithm created and published by Manindra Agrawal, Neeraj Kayal, and Nitin Saxena, computer scientists at the Indian Institute of Technology Kanpur, on August 6, 2002, in an article titled "PRIMES is in P". The algorithm was the first that can provably determine whether any given number is prime or composite within polynomial time, without relying on the generalized Riemann hypothesis, or any mathematical conjecture. The proof is also notable for not relying on the field of analysis. The authors received the 2006 Gödel Prize and the 2006 Fulkerson Prize for this work.
Importance
AKS is the first primality-proving algorithm to be simultaneously general, polynomial, deterministic, and unconditional. Previous algorithms had been developed for centuries and achieved three of these properties at most, but not all four.- The AKS algorithm can be used to verify the primality of any general number given. Many fast primality tests are known that work only for numbers with certain properties. For example, the Lucas–Lehmer test works only for Mersenne numbers, while Pépin's test can be applied to Fermat numbers only.
- The maximum running time of the algorithm can be expressed as a polynomial over the number of digits in the target number. ECPP and APR conclusively prove or disprove that a given number is prime, but are not known to have polynomial time bounds for all inputs.
- The algorithm is guaranteed to distinguish deterministically whether the target number is prime or composite. Randomized tests, such as Miller–Rabin and Baillie–PSW, can test any given number for primality in polynomial time, but are known to produce only a probabilistic result.
- The correctness of AKS is not conditional on any subsidiary unproven hypothesis. In contrast, Miller's version of the Miller–Rabin test is fully deterministic and runs in polynomial time over all inputs, but its correctness depends on the truth of the yet-unproven generalized Riemann hypothesis.
Concepts
The AKS primality test is based upon the following theorem: Given an integer and integer coprime to, is prime if and only if the polynomial congruence relationholds. Note that should be understood as a formal symbol.
This theorem is a generalization to polynomials of Fermat's little theorem. In one direction it can easily be proven using the binomial theorem together with the following property of the binomial coefficient:
While the relation constitutes a primality test in itself, verifying it takes exponential time: the brute force approach would require the expansion of the polynomial and a reduction of the resulting coefficients.
The congruence is an equality in the polynomial ring. Evaluating in a quotient ring of creates an upper bound for the degree of the polynomials involved. The AKS evaluates the equality in, making the computational complexity dependent on the size of. For clarity, this is expressed as the congruence
which is the same as:
for some polynomials and.
Note that all primes satisfy this relation gives, which holds for prime). This congruence can be checked in polynomial time when is polynomial to the digits of. The AKS algorithm evaluates this congruence for a large set of values, whose size is polynomial to the digits of. The proof of validity of the AKS algorithm shows that one can find an and a set of values with the above properties such that if the congruences hold then is a power of a prime.
History and running time
In the first version of the above-cited paper, the authors proved the asymptotic time complexity of the algorithm to be —the twelfth power of the number of digits in n times a factor that is polylogarithmic in the number of digits. However, this upper bound was rather loose; a widely-held conjecture about the distribution of the Sophie Germain primes would, if true, immediately cut the worst case down to.In the months following the discovery, new variants appeared, which improved the speed of computation greatly. Owing to the existence of the many variants, Crandall and Papadopoulos refer to the "AKS-class" of algorithms in their scientific paper "On the implementation of AKS-class primality tests", published in March 2003.
In response to some of these variants, and to other feedback, the paper "PRIMES is in P" was updated with a new formulation of the AKS algorithm and of its proof of correctness. While the basic idea remained the same, r was chosen in a new manner, and the proof of correctness was more coherently organized. The new proof relied almost exclusively on the behavior of cyclotomic polynomials over finite fields. The new upper bound on time complexity was, later reduced using additional results from sieve theory to.
In 2005, Pomerance and Lenstra demonstrated a variant of AKS that runs in operations, leading to another updated version of the paper. Agrawal, Kayal and Saxena proposed a variant which would run in if Agrawal's conjecture were true; however, a heuristic argument by Pomerance and Lenstra suggested that it is probably false.
The algorithm
The algorithm is as follows:- Check if n is a perfect power: if for integers and, output composite.
- Find the smallest r such that.
- For all 2 ≤ a ≤ min, check that a does not divide n: If a|n for some 2 ≤ a ≤ min, output composite.
- If n ≤ r, output prime.
- For to do
- : if n≠ Xn+a, output composite;
- Output prime.
Step 3 is shown in the paper as checking 1 < < n for all a ≤ r. It can be seen this is equivalent to trial division up to r, which can be done very efficiently without using gcd. Similarly the comparison in step 4 can be replaced by having the trial division return prime once it has checked all values up to and including
Once beyond very small inputs, step 5 dominates the time taken. Most improvements made to the algorithm have concentrated on reducing the size of r which makes the core operation in step 5 faster, and in reducing the size of s, the number of loops performed in step 5. Typically these changes do not change the computational complexity, but can lead to many orders of magnitude less time taken, e.g. Bernstein's final version has a theoretical speedup by a factor of over 2 million.
Proof of validity outline
For the algorithm to be correct, all steps that identify n must be correct. Steps 1, 3 and 4 are trivially correct, since they are based on direct tests of the divisibility of n. Step 5 is also correct: since is true for any choice of a coprime to n and r if n is prime, an inequality means that n must be composite.The difficult case of the algorithm is step 6. Its proof of correctness is based on the upper and lower bounds of a multiplicative group in ℤn constructed from the binomials that are tested in step 5. Step 4 guarantees that these binomials are distinct elements of ℤn. For the particular choice of r, the bounds produce a contradiction unless n is prime or a power of a prime. Together with the test of step 1, this implies that n is always prime at step 6.