Repository navigation
feat(AKS): the word-RAM AKS program and PRIMES ∈ P - #1902
Conversation
) Euclid's gcd, the integer k-th root by binary search with a capped power, the perfect-power test (AKS step 1), and multiplication modulo X^r - 1 and n on coefficient arrays, each with an explicit instruction bound that does not depend on the word size. The coefficient formulas are identified with the ring operations of (Z/n)[X]/(X^r - 1) in Foundations/NumberTheory/AKS/Coefficients, and IsPerfectPower becomes decidable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Fill writes the coefficients of X^e + a modulo X^r - 1 and n into a block, over arbitrary prior contents; Compare tests two blocks for equality. Both are linear in r. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Wrap the 101-character line in ComplexityTests/WordRAMAKS.lean that failed lake test --wfail. Correct the Compare bound in the PolyArray summary (11 r + 5) and distinguish the n-dependent value bound of NatNthRoot.exec from its k-dependent counters. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
PolyPow raises a coefficient array modulo X^r - 1 and n to the power e by repeated squaring in Nat.size e rounds, reusing PolyMul and ArrayCopy. Congruence tests (X + a)^n = X^n + a (mod X^r - 1, n) for one a by Fill, PolyPow and Compare, and its flag is exactly Cslib.AKS.Congruence n r a. Both have instruction bounds independent of the word size. Adds Cslib.AKS.toQuot_congr. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
IntegerVariant states the AKS tests with c = ceil(log2 n): PassesUpTo n r A checks the congruence for 1 <= a <= A, and prime_iff_passesUpTo proves n.Prime <-> PassesUpTo n r A when ord_r(n) > c^2 and A >= numTests n r, from Theorem 4.1 (prime_iff_passes). lt_orderOf_iff decides the order condition by small powers. On the word RAM, OrderSearch finds r with that condition and GcdTotient runs step 3 and computes phi(r), each with a word-size-independent instruction bound. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
CongruenceLoop runs the one-a congruence test for a = 1, ..., A and clears a flag when one fails; its flag is 1 exactly when the congruence holds for every 1 <= a <= A, within A * (Congruence.time r n + 6) + 6 instructions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Brings in #1836 (word-RAM polynomial time gives Turing-machine polynomial time). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…-893 #1869 merged; this brings its squashed commit into the branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG # Conflicts: # Complexity/Foundations/NumberTheory/AKS/Coefficients.lean
The base #1891 merged main after #1869 landed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
The top-level program's decision certificate, the transfer to P through mem_P_of_width at width 8 (|encNat n| + 1), concrete runs through each early exit, and removal of the completed ROADMAP entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…arch (#893) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
edemaine
left a comment
There was a problem hiding this comment.
reviewer-codex-edemaine: REQUEST_CHANGES at bf2d042 (independent agent review).
The own layer is clean. Before approval, carry in #1898's remaining reuse fix: put PassesUpTo in Criterion and specialize Passes to it, retaining one test definition. That duplication is still present here. The OrderSearch hygiene fix is correct; retain the completed mathematical coverage for the remaining delta.
Read the complete five-file layer, actual contracts and earlier stack reviews. One fixed 36-register program handles all naturals, preserves parameters across renamed subroutines, and fits counters, polynomial blocks and arithmetic into w ≥ 8(size n+1). The integer-threshold AKS variant matches the checked Annals mapping. The new bound time s ≤ 4096(s+1)^15 is sound. The binary-input P transfer uses the previously reviewed, unchanged #1836 bridge: width is computed in unary, input conversion is charged, and checked operations have ordinary multi-tape polynomial-time implementations. This proves conventional P membership; the degree-15 bound concerns RAM instructions.
Tests contain checked early-exit runs and prime/composite theorem instances; step 5 is covered by the universal assembly proof and inherited subroutine tests. Width arithmetic checks through n=4096, whitespace and the 3,200-module inventory pass. No existing curated abstract changes. Author reports six local gates; no reviewer Lean build. At this head, Lean CI and Guide are pending; title checks passed. Live head rechecked immediately before posting.
|
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Move `PassesUpTo` and `passesUpTo_of_prime` from `IntegerVariant.lean` into `Criterion.lean`, and define `Passes n r := PassesUpTo n r (numTests n r)`, so the AKS tests have one definition. `passes_of_prime` now specializes `passesUpTo_of_prime`. No statement changes; no aliases. Also state the `GcdTotient.exec` flag condition literally (`gcd(a, n)` is `1` or `n`) and qualify the `1 < gcd(a, n) < n` reading by `n ≥ 1`, and test the `Passes`/`PassesUpTo` specialization. Addresses reviewer-codex-edemaine's review of 71b9b9c on #1898. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
|
Validation at 69dc7b2: |
edemaine
left a comment
There was a problem hiding this comment.
reviewer-codex-edemaine (independent, non-author agent): APPROVE at 69dc7b2.
The inherited reuse finding is resolved: Criterion, IntegerVariant and GcdTotient exactly match approved #1898. Verified the five-file own-layer patch is unchanged, including the aggregate and roadmap edits, and rechecked the program's uses of PassesUpTo and its correctness lemmas. The completed mathematical/encoding/resource review carries forward; this remains conventional binary-input PRIMES ∈ P, with the explicit degree-15 bound applying to RAM instructions.
At the single current-head CI inspection, Lean CI, Guide and title passed. Author reports all six local gates; whitespace checks pass. No reviewer Lean build or change to this layer's abstract-impact assessment. Live head rechecked immediately before posting.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
|
|
|
Carry-forward record ( |
worker-claude-e6cf7b0d-aks-3(Claude Code, Opus), undercoordinator-claude-e6cf7b0d. Part of #893 (M4). Stacked on #1898 → #1891: review the diff againstclaude/aks-program-893.This completes PRIMES ∈ P on the binary encoding: the AKS algorithm as one word-RAM program, its correctness and polynomial instruction bound, and the transfer to
Pthrough #1836.What is proved
Cslib.Algorithms.WordRAM.AKS.programcomposes the stacked subroutines. It readsnfrom memory cell 1 and answers0ifn < 2ornis a perfect power. It then computesc = ⌈log₂ n⌉andL = c², searches forr, and runs step 3 together withφ(r). It answers0if step 3 fails and1ifn ≤ r. Otherwise it computesA = ⌊√(φ(r) L)⌋and tests the congruences for1 ≤ a ≤ A, with the polynomial blocks at0,rand2r.answers: at every word sizew ≥ 8 (size n + 1), the program leaves1inansifnis prime and0otherwise, withintime (size n)instructions.time_le:time s ≤ 4096 (s + 1)¹⁵, which givespolynomiallyBounded_time. Step 5 dominates: at most2 s⁴values ofa, each takingsrounds of schoolbook multiplication of polynomials withr ≤ 4 s⁵coefficients.decidesInTime: the compiled program is aProgram.DecidesInTimecertificate for{n | n.Prime}on the one-word input[n].Cslib.Complexity.primes_mem_P : {n : ℕ | n.Prime} ∈ P encNat, from feat(WordRAM): word-RAM polynomial time gives Turing-machine polynomial time #1836'smem_P_of_widthat the width8 (|encNat n| + 1).Source mapping
[AKS2004] = Agrawal, Kayal, Saxena, PRIMES is in P, Annals of Math. 160 (2004).
prime_iff_passesUpTo_numTestsNat).exists_lt_orderOf,r ≤ 4 ⌈log₂ n⌉⁵).c = ⌈log₂ n⌉in place oflog₂ n. Step 2 requiresord_r(n) > c², and step 5 tests everya ≤ ⌊√(φ(r) c²)⌋. This tests at least the paper's values ofa, and primes pass every congruence, so correctness is preserved.Õ(log^{21/2} n)using fast multiplication. Here the cost is unit-cost word-RAM instructions with schoolbook multiplication. I checked these locators against the Annals PDF.Limits
Ptheorem states no exponent.4 c⁵bound onr.r ≥ 2with the order property, but the correctness theorem does not use leastness.Tests
ComplexityTests/WordRAMAKSProgram.leancontains:n = 0, 1(step 0),4(step 1),6(step 3, atr = 11) and2(step 4);answerson the prime 7 and the composite 91;Pstatement.Abstract impact and docs
No existing abstract changes. A curated abstract candidate,
{n | n.Prime} ∈ Pover the shared foundations, is in #1904, for Samuel to select.ROADMAP.mddrops the PRIMES ∈ P entry.Existing notions considered
The library had no PRIMES or prime-language definition; the statement uses
{n : ℕ | n.Prime}directly.PisCslib.Complexity.P.lowand the register names are local to the program.Validation
All six gates passed locally at
0c9483d0;--quickfell back to the full run because of the ROADMAP change. The later commits addtime_leand merge #1898's hygiene fix (7bf57c7). Their modules, the tests andcheck_hygiene.py --check-simppass locally, and CI covers the head.🤖 Generated with Claude Code
https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG