{
  "aliases": null,
  "backlinks": [
    {
      "field": "uses",
      "target": "YPE65X5HJ4"
    }
  ],
  "body": "\n## Statement\n\nLet $n \\ge 2$ be an integer and let $r \\ge 2$ be an integer.\nAssume that $n$ has no [[prime|01826KMG2H]] factor $p \\le r$.\nThen $\\gcd(n, r) = 1$, so the [[multiplicative order|02RRHJ7R98]] $\\ord_r(n)$ of $n$ modulo $r$ is defined.\nAssume also that $\\ord_r(n) \u003e (\\log_2 n)^2$.\nLet $\\varphi$ be [[Euler's totient function|0DAMHCT17R]] and let $\\ell = \\floor{\\sqrt{\\varphi(r)} \\log_2 n}$.\nThen the following hold.\n\n1. The integer $n$ is prime if and only if $n$ is not a perfect power and\n$$(X + a)^n \\equiv X^n + a \\pmod{X^r - 1,\\ n}$$\nfor every integer $a$ with $1 \\le a \\le \\ell$.\nHere the congruence is an equality in the [[quotient ring|0076HWHGHQ]] $\\Z[X]/(X^r - 1, n)$ of the [[polynomial ring|0SDC934R52]] $\\Z[X]$.\nA perfect power is an integer $m^k$ with integers $m, k \\ge 2$.\n2. For every $n \\ge 2$ there is an integer $r \\le \\max\\set{3, \\ceil{(\\log_2 n)^5}}$ with $\\ord_r(n) \u003e (\\log_2 n)^2$ or $\\gcd(n, r) \u003e 1$.\n3. Hence a deterministic algorithm decides whether $n$ is prime with a number of bit operations polynomial in $\\log n$.\n\n## Remarks\n\nThe algorithm is due to Manindra Agrawal, Neeraj Kayal and Nitin Saxena, in the paper \"PRIMES is in P\".\nIt starts from a simple fact: for $\\gcd(a, n) = 1$, the integer $n$ is prime if and only if $(X + a)^n \\equiv X^n + a \\pmod n$ in $\\Z[X]$.\nThe direct check of this identity costs about $n$ operations, so the test reduces it modulo $X^r - 1$ for a small $r$.\nIf $n$ is composite with a prime factor $p$, the congruences for all $a \\le \\ell$ give a group of polynomials modulo $p$.\nThis group is forced to be both small and large at once, unless $n$ is a power of $p$.\nThe algorithm finds the smallest suitable $r$, checks $\\gcd(a, n)$ for $a \\le r$, tests for perfect powers, and then checks the $\\ell$ congruences.\n\nFor $n$ prime, part 1 holds by [[Fermat's little theorem|0M25PRN3WQ]] and the [[freshman's dream|0396VGFA78]] $(X + a)^p = X^p + a^p$ in characteristic $p$.\nThe test needs no unproved hypothesis and is never wrong, unlike the [[Miller–Rabin primality test|0SZCSYHW60]], which is randomised.\n\n## Explanations\n\n### L1 human\n\nThe AKS test decides whether a whole number is prime, and it is always right.\nIts running time grows only like a power of the number of digits of $n$, not like $n$ itself.\nBefore it, no known test was at the same time deterministic, free of unproved conjectures and polynomial in the number of digits.\nIt answered the old question whether primality can be decided in polynomial time.\n\n### L2 human\n\nThe test turns the binomial identity $(X + a)^p = X^p + a$ modulo $p$ into a criterion that is cheap to check.\nThe working ring $\\Z[X]/(X^r - 1, n)$ has elements of size about $r \\log n$ bits, and $r$ is polynomial in $\\log n$ by part 2.\nThe proof uses only elementary algebra of finite fields and cyclotomic polynomials, together with a bound on the least common multiple of $1, \\ldots, m$.\nIn practice the test is slower than the [[Miller–Rabin primality test|0SZCSYHW60]] or elliptic curve methods, so its importance is mainly theoretical.\nIt is a [[primality test|0EGJZHZ02C]], and it does not find factors; the [[integer factorization|YPE65X5HJ4]] problem is believed to be much harder.\n",
  "commit": "5fc425f97f1f6b11da5892c2948ef8c5d8805665",
  "front": {
    "about": [
      "0EGJZHZ02C",
      "01826KMG2H"
    ],
    "kind": "statement",
    "msc": [
      "11Y11",
      "11A51",
      "68Q25"
    ],
    "name": "AKS primality test",
    "role": "theorem",
    "same_as": {
      "wikidata": "Q294284",
      "wikipedia": "AKS primality test"
    },
    "sources": [
      {
        "url": "https://en.wikipedia.org/wiki/AKS_primality_test"
      }
    ],
    "tag": "XMHQCDWZW1",
    "uses": [
      "01826KMG2H",
      "02RRHJ7R98",
      "0DAMHCT17R",
      "0SDC934R52",
      "0076HWHGHQ",
      "0M25PRN3WQ",
      "0396VGFA78",
      "0SZCSYHW60"
    ]
  },
  "kind": "statement",
  "link": "https://math2.tamnd.com/node/XMHQCDWZW1/",
  "links": [
    {
      "field": "about",
      "target": "0EGJZHZ02C"
    },
    {
      "field": "about",
      "target": "01826KMG2H"
    },
    {
      "field": "uses",
      "target": "01826KMG2H"
    },
    {
      "field": "uses",
      "target": "02RRHJ7R98"
    },
    {
      "field": "uses",
      "target": "0DAMHCT17R"
    },
    {
      "field": "uses",
      "target": "0SDC934R52"
    },
    {
      "field": "uses",
      "target": "0076HWHGHQ"
    },
    {
      "field": "uses",
      "target": "0M25PRN3WQ"
    },
    {
      "field": "uses",
      "target": "0396VGFA78"
    },
    {
      "field": "uses",
      "target": "0SZCSYHW60"
    }
  ],
  "markdown": "https://math2.tamnd.com/node/XMHQCDWZW1.md",
  "msc": [
    "11Y11",
    "11A51",
    "68Q25"
  ],
  "name": "AKS primality test",
  "prov": null,
  "role": "theorem",
  "source": "https://github.com/tamnd/math2/blob/main/nodes/XMH/XMHQCDWZW1.md",
  "status": null,
  "tag": "XMHQCDWZW1",
  "uri": "m2://XMHQCDWZW1",
  "url": "https://math2.tamnd.com/wiki/aks-primality-test/",
  "writing": {
    "tag": "XMHQCDWZW1",
    "kind": "statement",
    "level": "W0",
    "next": [
      {
        "what": "a source with a locator",
        "have": 0,
        "want": 1
      }
    ]
  }
}
