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

  1. If for some , output composite.
  2. Find the smallest such that .
  3. For : if , output composite.
  4. If , output prime.
  5. For : if

    output composite.
  6. 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.

TestTimeDeterministic?Practical?
Trial divisionyesonly for tiny
Miller-Rabin, fixed basesyes for 64-bityes
Miller-Rabin, random basesno ( error)yes
Baillie-PSWno counterexample knownyes
ECPPheuristic yes, with certificateyes, for huge
AKSyesno

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