{
  "aliases": null,
  "backlinks": null,
  "body": "\n## Proof\n\n1. Let $p$ be a [[prime number|0SN0MAEKYX]]. If $p = 2$, then $(p - 1)! = 1$, and $2$ [[divides|096PW7Q014]] $1 - (-1) = 2$. So $(p - 1)! \\equiv -1 \\pmod p$. From now on let $p \\ge 3$.\n2. Let $R = \\{ 1, 2, \\dots, p - 1 \\}$. Each $a \\in R$ satisfies $p \\nmid a$, so the [[greatest common divisor|02WF878BH1]] $\\gcd(a, p)$ is a positive divisor of $p$ other than $p$. Thus $\\gcd(a, p) = 1$.\n3. Let $a \\in R$. By step 2 and the [[existence of inverses modulo n|0M67FWZWPQ]], $a$ has a [[modular multiplicative inverse|00GXTQMY8Z]] $x$, so $a x \\equiv 1 \\pmod p$.\n4. By the [[division algorithm|0CHQKZFK5S]], $x = q p + a'$ with $0 \\le a' \u003c p$. Then $a a' \\equiv a x \\equiv 1 \\pmod p$. Since $a \\cdot 0 = 0 \\not\\equiv 1 \\pmod p$, we get $a' \\ne 0$, so $a' \\in R$.\n5. If $b \\in R$ and $a b \\equiv 1 \\pmod p$, then $a b \\equiv a a' \\pmod p$. By [[cancellation|09RDZZGJZ9]] with $\\gcd(a, p) = 1$, $b \\equiv a' \\pmod p$. Both lie in $R$, so $b = a'$.\n6. So each $a \\in R$ has exactly one $a' \\in R$ with $a a' \\equiv 1 \\pmod p$. Since $a' a \\equiv 1 \\pmod p$, step 5 applied to $a'$ gives $(a')' = a$.\n7. Let $a \\in R$. Then $a' = a$ if and only if $a^2 \\equiv 1 \\pmod p$, that is, $p \\mid (a - 1)(a + 1)$.\n8. By [[Euclid's lemma|051VYKA1EX]], this holds if and only if $p \\mid a - 1$ or $p \\mid a + 1$. Since $0 \\le a - 1 \\le p - 2$ and $2 \\le a + 1 \\le p$, this means $a = 1$ or $a = p - 1$.\n9. Let $T = \\{ 2, 3, \\dots, p - 2 \\}$, which is empty when $p = 3$. Let $a \\in T$. If $a' = 1$, then $a \\equiv a a' \\equiv 1 \\pmod p$, so $a = 1$. If $a' = p - 1$, then $-a \\equiv a a' \\equiv 1$, so $a = p - 1$. Both contradict $a \\in T$.\n10. So $a \\mapsto a'$ maps $T$ to $T$. By steps 6 and 8, it is its own inverse and has no fixed point in $T$.\n11. Hence $T$ splits into disjoint pairs $\\{ a, a' \\}$ with $a \\ne a'$. Each pair has product $a a' \\equiv 1 \\pmod p$.\n12. By [[compatibility with multiplication|072D5G4SK6]], $(p - 2)! = 1 \\cdot \\prod_{a \\in T} a \\equiv 1 \\pmod p$. This also holds when $T$ is empty.\n13. Then $(p - 1)! = (p - 1) \\cdot (p - 2)! \\equiv (-1) \\cdot 1 = -1 \\pmod p$, by compatibility with multiplication and $p - 1 \\equiv -1 \\pmod p$.\n\n## Idea\n\nModulo a prime, every nonzero residue has a unique inverse. Only $1$ and $-1$ are their own inverses, so all the other factors of $(p - 1)!$ cancel in pairs. What remains is $1 \\cdot (p - 1) \\equiv -1$.\n",
  "commit": "4a3290d299c8b2cd6493fce2296920ba7f82d942",
  "front": {
    "kind": "proof",
    "methods": [
      "0WCP0PVET6"
    ],
    "msc": [
      "11A07"
    ],
    "name": "Proof of Wilson's theorem by pairing inverses",
    "proves": "03KGGKTB2E",
    "sources": [
      {
        "locator": "Elementary proof",
        "url": "https://en.wikipedia.org/wiki/Wilson%27s_theorem"
      }
    ],
    "tag": "RPE4ET6Y7B",
    "uses": [
      "0SN0MAEKYX",
      "0TPW25CBN6",
      "096PW7Q014",
      "02WF878BH1",
      "0M67FWZWPQ",
      "00GXTQMY8Z",
      "0CHQKZFK5S",
      "051VYKA1EX",
      "09RDZZGJZ9",
      "072D5G4SK6"
    ]
  },
  "kind": "proof",
  "link": "https://math2.tamnd.com/node/RPE4ET6Y7B/",
  "links": [
    {
      "field": "proves",
      "target": "03KGGKTB2E"
    },
    {
      "field": "uses",
      "target": "0SN0MAEKYX"
    },
    {
      "field": "uses",
      "target": "0TPW25CBN6"
    },
    {
      "field": "uses",
      "target": "096PW7Q014"
    },
    {
      "field": "uses",
      "target": "02WF878BH1"
    },
    {
      "field": "uses",
      "target": "0M67FWZWPQ"
    },
    {
      "field": "uses",
      "target": "00GXTQMY8Z"
    },
    {
      "field": "uses",
      "target": "0CHQKZFK5S"
    },
    {
      "field": "uses",
      "target": "051VYKA1EX"
    },
    {
      "field": "uses",
      "target": "09RDZZGJZ9"
    },
    {
      "field": "uses",
      "target": "072D5G4SK6"
    },
    {
      "field": "methods",
      "target": "0WCP0PVET6"
    }
  ],
  "markdown": "https://math2.tamnd.com/node/RPE4ET6Y7B.md",
  "msc": [
    "11A07"
  ],
  "name": "Proof of Wilson's theorem by pairing inverses",
  "prov": null,
  "role": "",
  "source": "https://github.com/tamnd/math2/blob/main/nodes/RPE/RPE4ET6Y7B.md",
  "status": null,
  "tag": "RPE4ET6Y7B",
  "uri": "m2://RPE4ET6Y7B",
  "url": "https://math2.tamnd.com/wiki/proof-of-wilsons-theorem-by-pairing-inverses/",
  "writing": {
    "tag": "RPE4ET6Y7B",
    "kind": "proof",
    "level": "W0",
    "next": [
      {
        "what": "an inventory row",
        "note": "the row of the inventory that the node accounts for",
        "have": 0,
        "want": 1
      }
    ]
  }
}
