Purpose: Decide primality in deterministic polynomial time, with no randomness and no unproven hypotheses. Agrawal-Kayal-Saxena, 2002 — the paper that finally put PRIMES in P.
The Idea
Everything rests on a polynomial identity. For :
The forward direction is the freshman’s dream, valid mod a prime because every binomial coefficient for is divisible by . Checking this identity directly costs coefficients — far too many. AKS’s contribution is showing it suffices to check it modulo a small polynomial , for a suitably chosen small , and for a bounded range of .
Algorithm
- If for some , output composite.
- Find the smallest such that .
- For : if , output composite.
- If , output prime.
- For : if
output composite. - Output prime.
Complexity
- Original paper:
- With Lenstra-Pomerance improvements:
- Space: polynomial
Why nobody uses it
with a large hidden constant is astronomically slower than Miller-Rabin for every input anyone will ever test. For 64-bit numbers, deterministic Miller-Rabin with 12 fixed bases finishes in under a microsecond; AKS takes seconds. For cryptographic sizes, ECPP produces a certificate far faster.
| Test | Time | Deterministic? | Practical? |
|---|---|---|---|
| Trial division | yes | only for tiny | |
| Miller-Rabin, fixed bases | yes for 64-bit | yes | |
| Miller-Rabin, random bases | no ( error) | yes | |
| Baillie-PSW | no counterexample known | yes | |
| ECPP | heuristic | yes, with certificate | yes, for huge |
| AKS | yes | no |
Why it still matters
AKS resolved a decades-old open question: primality testing is in P, unconditionally. Before it, deterministic polynomial-time primality was known only under the generalised Riemann hypothesis (Miller’s original result). It is a landmark in complexity theory even though it is a footnote in practice — a good reminder that “polynomial time” and “fast” are different claims.
Variants / Use Cases
- Miller-Rabin — what you should actually write
- Lucas-Lehmer — specialised deterministic test for Mersenne numbers
- Primality Testing — the topic page comparing all of these
- Complexity Theory — where PRIMES ∈ P sits in the landscape