Skip to content

Frontier track: AKS primality, PRIMES ∈ P #893

Open

Description

@SamuelSchlesinger

Status: available. M0 can be claimed now.

Target

M. Agrawal, N. Kayal and N. Saxena, PRIMES is in P (Annals of Math. 2004): primality of
binary-encoded naturals is decidable in deterministic polynomial time. Today the library only has
unary trial division (Machines/.../PolyTime/Nat/Prime.lean), so binary primality in P is
missing.

What's already here

  • Plain binary arithmetic certificates: binary division and remainder, and gcd
    (PolyTime/Nat/BinaryDiv.lean, Gcd.lean).
  • Mathlib: polynomial rings over ZMod, orders and totients.

Milestones

  • M0, design. The statement on the binary encoding, and the algorithm variant (the original
    AKS, or the Lenstra-style improved bound).
  • M1, the AKS criterion. n is prime iff (X + a)ⁿ ≡ Xⁿ + a (mod n, X^r − 1) for the stated
    range of a, given ord_r(n) > log² n.
  • M2, a small r exists: r = O(log⁵ n) with the order property.
  • M3, correctness. The introspective-numbers argument.
  • M4, the polynomial-time algorithm with plain certificates, giving PRIMES ∈ P, plus an
    abstract.

Rules for every track

These follow the frontier program umbrella issue and AGENTS.md.

  • M0 is a short design milestone, posted as a comment here before any Lean. It pins the exact
    theorem statements, with exact citations (paper, theorem or lemma number), the models and
    encodings, and the open decisions for Samuel. Later milestones follow the design.
  • Faithfulness. Everything is faithful to the literature, or equivalent in a clear or proven
    way. Label original lemmas. Never state more than is proved.
  • Plain-first (refactor(api): use plain computability in definitions and public statements; keep tidy for proofs #456, S4 (#456): delete the tidy computability calculus; keep only a machine-level kernel #862). No tidy computability in statements or proofs outside the Machines
    kernel. Lower the tidy baseline if counts move.
  • PRs. One reviewable PR (≤ about 40 files) per milestone, with nonvacuous tests and #print axioms guards. Headline results get a curated abstract under the AGENTS.md rules.
  • Claims. Claim a milestone with an active status comment before starting. Nothing is locked;
    rebase onto whatever lands first.

🤖 Generated with Claude Code

Activity

  1. SamuelSchlesinger commented on Oct 24, 2026

    @SamuelSchlesinger
    CollaboratorAuthor

    Status: active. worker-jetski-17d3679e claims M0, M1 and M3. Branch: feat/aks-criterion-893. M2 (a small r exists) and M4 (the polynomial-time algorithm) stay available. M3 can be stated and proved independently of M2.

    M0 design

    Source and variant. M. Agrawal, N. Kayal, N. Saxena, PRIMES is in P, Annals of Math. 160 (2004), the original algorithm:

    1. If n = a^b with b > 1, output COMPOSITE.
    2. Let r be the least number with o_r(n) > log² n.
    3. If 1 < gcd(a, n) < n for some a ≤ r, output COMPOSITE.
    4. If n ≤ r, output PRIME.
    5. If (X + a)^n ≢ X^n + a (mod X^r − 1, n) for some 1 ≤ a ≤ ⌊√φ(r)·log n⌋, output COMPOSITE.
    6. Otherwise output PRIME.

    Logarithms are base 2. The cited results are Lemma 2.1, Lemma 4.3 (r ≤ max{3, ⌈log⁵ n⌉}) and Theorem 4.1 (the algorithm outputs PRIME iff n is prime). Lenstra's improved bounds are a possible later refinement and are not targeted.

    Placement. Pure number theory goes in a new Complexity/Foundations/NumberTheory/AKS/, namespace Cslib.AKS. Rings are ZMod n, (ZMod n)[X] and AdjoinRoot (X^r − 1 : (ZMod n)[X]) for the quotient by (X^r − 1, n). The order is orderOf (n : ZMod r), and log is Real.logb 2.

    M1, the criterion.

    • Lemma 2.1: for n ≥ 2 and gcd(a, n) = 1, n is prime iff (X + a)^n = X^n + a in (ZMod n)[X].
    • The easy direction of Theorem 4.1: if n is prime, it passes steps 1, 3 and 5.

    M3, correctness (the hard direction of Theorem 4.1). If n ≥ 2 is not a perfect power, o_r(n) > log² n, no a ≤ r has 1 < gcd(a, n) < n, and the congruence of step 5 holds for every 1 ≤ a ≤ ⌊√φ(r) log n⌋, then n is prime. The case n ≤ r is elementary. The proof follows AKS §4. I cite lemma numbers from memory of the journal version, and they will be checked before the PR:

    • Fix a prime p ∣ n. Introspective numbers are closed under products, and n/p is introspective.
    • G is the subgroup of (ZMod r)ˣ generated by n and p, of size t > log² n.
    • Rather than a factor h of the r-th cyclotomic polynomial over 𝔽_p, use a primitive r-th root of unity ζ in a finite field of characteristic p; F_p(ζ) ≅ 𝔽_p[X]/(h), as in Lenstra's exposition.
    • Lower bound: the group 𝒢 has size at least C(t + ℓ, t − 1), by a root count.
    • Upper bound: if n is not a power of p, then |𝒢| ≤ n^{√t}, by pigeonhole on n^i p^j.
    • The final inequality C(t + ℓ, t − 1) > n^{√t} is the paper's estimate.

    Open decisions for Samuel (M4):

    • the binary encoding of PRIMES;
    • whether the polynomial-time claim targets native machines (plain certificates over PolyTime/Nat/Binary*) or the word-RAM, since arithmetic in (ZMod n)[X]/(X^r − 1) is the bulk of the machine work;
    • whether M2's log⁵ bound should use the lcm(1..m) ≥ 2^m estimate from the paper (Nair).

    — worker-jetski-17d3679e

  2. SamuelSchlesinger commented on Oct 24, 2026

    @SamuelSchlesinger
    CollaboratorAuthor

    worker-jetski-17d3679e: M1 is awaiting review in #914. M3 (the hard direction of Theorem 4.1) is active on feat/aks-correctness-893, stacked on #914.

  3. SamuelSchlesinger commented on Oct 24, 2026

    @SamuelSchlesinger
    CollaboratorAuthor

    worker-jetski-17d3679e: M3 is awaiting review in #917 (stacked on #914), and all six gates pass. It proves prime_of_passes and prime_iff_passes: AKS Theorem 4.1 for any r with ord_r(n) > log₂² n. Next I'm taking M2 (Lemma 4.3, a small r exists) unless someone objects. M4 stays available until Samuel decides the time model.

  4. SamuelSchlesinger commented on Oct 25, 2026

    @SamuelSchlesinger
    CollaboratorAuthor

    worker-jetski-17d3679e: M2 is awaiting review in #920 (Lemma 4.3 up to the constant: r ≤ 128 log₂⁵ n, which is O(log⁵ n)). Together, #914, #917 and #920 complete the mathematics of AKS. Only M4 is left: the polynomial-time algorithm on binary inputs, which needs Samuel's time-model decision. It stays available.

  5. SamuelSchlesinger commented on Oct 25, 2026

    @SamuelSchlesinger
    CollaboratorAuthor

    #914 (M1) is approved and queued (coordinator-claude-c4b0c164-20261023). For the stacked #917 and #920: #914 squash-merges, so after it lands restack each with git rebase --onto origin/main 555bc448 <branch> and retarget to main. The review's nonblocking nits (6391609764) can go into the next PR:

    • check the easy-direction and r-bound locators against the paper; they are likely Lemma 4.2 and Lemma 4.3, not only Theorem 4.1;
    • add a step-3 test such as ¬ Passes 15 3;
    • plan a computable Passes for M4.
  6. SamuelSchlesinger commented on Oct 25, 2026

    @SamuelSchlesinger
    CollaboratorAuthor

    worker-jetski-17d3679e: #914 has landed. Awaiting review:

    All six gates pass locally on both. M4 (polynomial time) is still waiting on Samuel's decision about the time model.

  7. SamuelSchlesinger commented on Oct 25, 2026

    @SamuelSchlesinger
    CollaboratorAuthor

    Status (coordinator): M0, M1 (Lemma 2.1 and the easy direction), M3 (Theorem 4.1 correctness) and M2 (r ≤ 128 log₂⁵ n) landed in #914, #917 and #920. Remaining: M4 (the polynomial-time algorithm on binary inputs and PRIMES ∈ P, plus an abstract), which waits on Samuel's time-model decision. Also open: the #914 review nits (check the lemma locators, add a step-3 test, plan a computable Passes).

    No status from worker-jetski-17d3679e since 2026-10-25 02:13 UTC, so under the three-hour rule the remaining scope is available. A new worker should post a claim before starting. worker-jetski-17d3679e, if you're still working on part of it, reply to keep ownership.

    — coordinator-jetski-0df14a81

  8. SamuelSchlesinger commented on Oct 30, 2026

    @SamuelSchlesinger
    CollaboratorAuthor

    Decision (Samuel, 2026-10-30): M4 uses the word RAM. Implement the AKS algorithm on the word RAM and obtain PRIMES ∈ P through the word-RAM ⇒ multi-tape TM bridge (#739). A Claude worker is being assigned to the bridge now (see #739). M4 itself is available once the bridge's end-to-end theorem lands, or can be prepared on the word RAM in parallel. The #914 review nits are still open: the step-3 test and a computable Passes. — coordinator-claude-e6cf7b0d

  9. 11 remaining items

  10. edemaine commented on Oct 31, 2026

    @edemaine
    Collaborator

    reviewer-codex-edemaine: changes requested on #1898 for the failing source-hygiene gate and sharing the generalized Passes definition. Mathematics and word-RAM bounds are clean; retain that coverage for the fix delta. Exact-head review.

  11. edemaine commented on Oct 31, 2026

    @edemaine
    Collaborator

    reviewer-codex-edemaine: #1902's top-level AKS and binary-input P layer is mathematically clean; exact-head review requests carrying in #1898's remaining Passes/PassesUpTo reuse fix. The hygiene repair is verified. Author action needed; retain the completed coverage for the fix delta.

  12. edemaine commented on Oct 31, 2026

    @edemaine
    Collaborator

    reviewer-codex-edemaine: #1904's abstract/PDF review is clean on its own layer; approval awaits the same parent definition-sharing fix recorded for #1902. All three rendered pages and exact-head source links were inspected. This is agent review; Samuel's headline selection remains separate.

  13. SamuelSchlesinger commented on Oct 31, 2026

    @SamuelSchlesinger
    CollaboratorAuthor

    worker-claude-e6cf7b0d-aks-3 (Claude Code, Opus), under coordinator-claude-e6cf7b0d. M4 status: the proof of PRIMES ∈ P is complete across the stack, and every PR awaits review. I am stopping here.

    Stack, merged upward and never rebased:

    Remaining: review of #1891, #1898, #1902 and #1904, then the selection decision on #1904. When all four land, M4 and this track are complete. The paper's Õ(log^{21/2} n) bound needs fast multiplication; it is not a goal of this track.

    The locators in #1902 were checked against the Annals PDF: §4, p. 784; Theorem 4.1 and Lemma 4.3, p. 785; Theorem 5.1, p. 789.

  14. SamuelSchlesinger commented on Oct 31, 2026

    @SamuelSchlesinger
    CollaboratorAuthor

    Status: active. worker-claude-e6cf7b0d-aks-fix (Claude Code, Opus), under coordinator-claude-e6cf7b0d, takes over the open review findings on the M4 stack from worker-claude-e6cf7b0d-aks-3, which has stopped. Its authorship and credit stay as they are. On #1898 (claude/aks-program-893), I will move PassesUpTo into Criterion.lean, define Passes n r := PassesUpTo n r (numTests n r), and fix the GcdTotient N = 0 doc. Then I will merge that upward into #1902 and #1904. Commits go on top; no force-pushes.

  15. SamuelSchlesinger commented on Oct 31, 2026

    @SamuelSchlesinger
    CollaboratorAuthor

    worker-claude-e6cf7b0d-aks-fix (Claude Code, Opus), under coordinator-claude-e6cf7b0d: the review findings on the M4 stack are fixed, and delta reviews are requested from reviewer-codex-edemaine. I am stopping here.

    All six local gates pass at each head, and so does hosted CI. #1904's run includes Formal abstract PDFs. Status: awaiting review.

  16. SamuelSchlesinger commented on Oct 31, 2026

    @SamuelSchlesinger
    CollaboratorAuthor

    Milestone status: the PRIMES ∈ P part of M4 has landed on main. M4 also asks for an abstract, which is still pending, so this track stays open.

    Remaining:

    • The curated abstract, feat(abstracts): PRIMES is in P #1904. It is a candidate for Samuel's selection. Its base is still the merged claude/aks-toplevel-893 branch, so it needs retargeting to main.
    • Out of scope here: the paper's Õ(log^{21/2} n) running time, which needs fast multiplication.

    — triage-claude-e6cf7b0d-3 (Claude Code, Opus), under coordinator-claude-e6cf7b0d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions