{
  "artifactId": "artifact.library.mathlib.wilson-theorem.v001",
  "candidateOnly": false,
  "category": "Number theory",
  "claimBoundary": "This target indexes Mathlib's equivalence for every natural number n ≠ 1: n is prime exactly when the cast of (n−1)! in ZMod n equals −1. The prime direction includes n = 2, where 1 and −1 are the same residue. The converse handles n = 0 separately before treating the remaining nonprime case. It does not assert a fast primality algorithm, a result for n = 1, or a new proof.",
  "collectionSlug": "landmark-theorems-in-mathlib",
  "exactFormalStatement": "theorem Nat.prime_iff_fac_equiv_neg_one {n : ℕ} (h : n ≠ 1) : Nat.Prime n ↔ ((n - 1)! : ZMod n) = -1",
  "family": "Prime congruences",
  "id": "library.mathlib.wilson-theorem.v001",
  "links": {
    "collection": "/collections/landmark-theorems-in-mathlib/",
    "collectionData": "/data/collections/mathlib-landmarks.json",
    "entry": "/library-theorems/wilson-theorem/",
    "entryData": "/data/library-theorems/wilson-theorem.json",
    "evidence": "/proofs/artifact.library.mathlib.wilson-theorem.v001.html",
    "evidenceData": "/data/proofs/artifact.library.mathlib.wilson-theorem.v001.evidence.json",
    "source": "/sources/upstream/wilson-theorem/"
  },
  "landmark": {
    "completeFormalType": "theorem Nat.prime_iff_fac_equiv_neg_one {n : ℕ} (h : n ≠ 1) : Nat.Prime n ↔ ((n - 1)! : ZMod n) = -1",
    "concepts": [
      "Wilson's theorem",
      "prime characterization",
      "factorials",
      "modular arithmetic",
      "unit inverses"
    ],
    "plainLanguage": "For each natural number n other than 1, n is prime exactly when the natural-number factorial (n−1)!, cast into ZMod n, equals −1. The n = 0 case uses Lean's natural subtraction and factorial conventions and is handled separately, rather than by informal predecessor-product notation.",
    "poster": {
      "alt": "An ivory number-theory poster places primality and the factorial residue minus one on equal sides of a two-way relation, with unit inverse pairings above and the zero case followed by a proper-divisor contradiction below.",
      "byteSize": 2263335,
      "caption": "The product of all nonzero residues modulo a prime is −1, and the same factorial congruence rules out compositeness when n ≠ 1.",
      "description": "The exact equivalence is supported by two distinct source movements: the prime direction identifies the factorial with the product of all units and pairs inverses, while the converse handles n = 0 separately before using a proper divisor to contradict residue −1.",
      "derivatives": [
        {
          "byteSize": 101238,
          "height": 960,
          "mediaType": "image/webp",
          "publicPath": "/assets/library-theorems/wilson-theorem/theorem-poster-v2-640.webp",
          "sha256": "sha256:d17ba7af6c74eb5137571e7c183ddfd8fc59600255d8b6f39409f2908753a65c",
          "width": 640
        },
        {
          "byteSize": 201224,
          "height": 1536,
          "mediaType": "image/webp",
          "publicPath": "/assets/library-theorems/wilson-theorem/theorem-poster-v2-1024.webp",
          "sha256": "sha256:d7ef4711a640f9cb814a91cab070270a639e53f8a8b78594d5fc780a20d6dbc2",
          "width": 1024
        }
      ],
      "generatedAt": "2026-07-25T12:00:00.000Z",
      "height": 1536,
      "mediaType": "image/png",
      "modelRequested": "gpt-image-2",
      "publicPath": "/assets/library-theorems/wilson-theorem/theorem-poster-v2.png",
      "sha256": "sha256:5b7cd88bd7ce56913953bd5e289a0ae57866e37793a3c8113abcd349550a445a",
      "title": "Wilson's Theorem — an exact factorial characterization of primes",
      "width": 1024,
      "kind": "theorem_poster",
      "transcript": "NUMBER THEORY · FACTORIAL CONGRUENCE\nWILSON'S THEOREM\nn ≠ 1\nn is prime ⇔ (n − 1)! = −1 in ZMod n\nONE CONGRUENCE, TWO DIRECTIONS\nPRIME ⇒ FACTORIAL RESIDUE\nThe nonzero residues are units; inverse pairs cancel and the product is −1.\nFACTORIAL RESIDUE ⇒ PRIME\nHandle n = 0 first; otherwise a proper divisor of composite n contradicts residue −1.\nHOW THE CHECKED ROUTE MOVES\n1 · Rewrite the factorial as the product of residues 1 through n − 1\n2 · Identify those residues with the units modulo a prime\n3 · Pair inverse units to obtain −1\n4 · For the converse, handle n = 0 first\n5 · Otherwise use a proper divisor to force a contradiction\nEXACT SCOPE\nThe hypothesis is n ≠ 1. This is an equivalence, not an efficiency claim or a theorem at n = 1."
    },
    "visual": {
      "alt": "A balanced Wilson-theorem schematic separates the prime direction into the single self-inverse unit at p = 2 and inverse pairing for odd primes, and separates the converse into the direct n = 0 contradiction and the proper-divisor argument for composite n > 1.",
      "byteSize": 2584456,
      "caption": "Inverse pairing gives the factorial residue for primes, with 1 = −1 at p = 2; the converse handles n = 0 first and then uses a proper divisor for composite n > 1.",
      "description": "For odd primes, non-fixed units pair with their inverses and the distinct fixed residues are 1 and −1; in ZMod 2 these are one residue. Conversely, the source rejects n = 0 directly. For a remaining nonprime n > 1, a divisor m with 1 < m < n divides (n−1)!, and the asserted residue equality would force m ∣ 1.",
      "derivatives": [
        {
          "byteSize": 41534,
          "height": 427,
          "mediaType": "image/webp",
          "publicPath": "/assets/library-theorems/wilson-theorem/theorem-schematic-v3-640.webp",
          "sha256": "sha256:a3a3decad97e4b5f58b68cd1b3e56234a4295cc9855c28959edb5f5e0c522eaa",
          "width": 640
        },
        {
          "byteSize": 115562,
          "height": 800,
          "mediaType": "image/webp",
          "publicPath": "/assets/library-theorems/wilson-theorem/theorem-schematic-v3-1200.webp",
          "sha256": "sha256:bad1cd50e2f2ab6da4d2a9a22d8a2765b2724fc5e6f37db3bc9778b88f7887c2",
          "width": 1200
        }
      ],
      "generatedAt": null,
      "height": 1024,
      "mediaType": "image/png",
      "modelRequested": "gpt-image-2",
      "publicPath": "/assets/library-theorems/wilson-theorem/theorem-schematic-v3.png",
      "sha256": "sha256:aa5e702c2b4ae06fa9cff856ded3e81d3fb9acaefae510ec131a55a3be094485",
      "title": "Wilson's equivalence, including the prime-two and zero cases",
      "width": 1536
    },
    "walkthrough": null,
    "whyLandmark": "Wilson's theorem gives one of the classical exact characterizations of prime numbers and connects elementary factorial arithmetic to the multiplicative structure of finite residue rings."
  },
  "nonClaims": [
    "The exact theorem assumes n ≠ 1; it does not silently replace that hypothesis by n > 1.",
    "The equivalence includes the converse direction and must not be presented as only prime implies factorial congruence.",
    "The theorem is a characterization, not a claim of computational efficiency.",
    "ProofAtlas is indexing an existing Mathlib theorem, not claiming new mathematics."
  ],
  "publicExportEligible": true,
  "relationship": "upstream_direct",
  "schemaVersion": "library-theorem-entry-data.v1",
  "statementId": "statement.library.mathlib.wilson-theorem.v001",
  "statusAxes": {
    "acceptedAtlasResult": "Not recorded for the preferred artifact",
    "locallyReproduced": "Exact upstream declaration replayed",
    "reviewedPage": "Current public presentation reviewed",
    "upstreamIndexed": "Pinned source bytes verified locally"
  },
  "summary": "For n ≠ 1, primality is equivalent to the cast of (n−1)! being −1 in ZMod n.",
  "targetId": "target.library.mathlib.wilson-theorem.v001",
  "title": "Wilson's Theorem",
  "upstreamOrigin": {
    "declarationName": "Nat.prime_iff_fac_equiv_neg_one",
    "immutableSourceUrl": "https://github.com/leanprover-community/mathlib4/blob/5e932f97dd25535344f80f9dd8da3aab83df0fe6/Mathlib/NumberTheory/Wilson.lean#L97",
    "packageName": "mathlib",
    "repositoryUrl": "https://github.com/leanprover-community/mathlib4",
    "sourceArtifactHash": "sha256:7bd6ec0e909f037f8632e1b495f9647a61fe950f3bfe3af98a5a22914622aeb7",
    "sourceByteLength": 3405,
    "sourceCommit": "5e932f97dd25535344f80f9dd8da3aab83df0fe6",
    "sourceFile": "Mathlib/NumberTheory/Wilson.lean",
    "sourceLine": 97,
    "verificationKind": "git_worktree"
  },
  "publicPresentationReview": {
    "status": "reviewed"
  }
}
