Repository navigation
gh-153222: Add math.integer.isprime() and math.integer.primes() - #153224
serhiy-storchaka wants to merge 1 commit into
Conversation
Documentation build overview
|
Draft implementation of prime-number functionality for the math.integer
module (deferred out of the initial PEP 791 scope), supporting integers
less than 2**64.
isprime() uses the deterministic Miller-Rabin test: bases {2, 7, 61}
below 4759123141, Jim Sinclair's seven bases up to 2**64 (verified
against the Feitsma-Galway list of base-2 strong pseudoprimes). The
result is exact for the whole supported range; larger arguments raise
OverflowError.
primes(start=2, stop=None) returns an iterator of the primes in
[start, stop), unbounded if stop is None.
Neither function is mirrored into the math namespace (PEP 791).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
92c57fe to
81e40f0
Compare
|
This PR is stale because it has been open for 90 days with no activity. |
|
This has a lot of conflicts. I suggest deferring I'm happy to review CC @mdickinson |
|
I wrote a slightly modified implementation giving a nice speedup (also drops |
Add prime-number functions to the math.integer module, supporting integers less than 2**64 (larger arguments raise
OverflowError, leaving room to extend support to larger integers later in a backward compatible way):isprime(n, /)-- deterministic Miller-Rabin primality test (bases {2, 7, 61} below 4759123141, Jim Sinclair's seven bases up to 2**64, verified against the Feitsma-Galway list of base-2 strong pseudoprimes). The result is always exact.primes(start=2, stop=None)-- iterator of the primes in [start, stop), unbounded if stop is None, with O(1) memory.Issue: Add math.integer.isprime() and math.integer.primes() #153222
🤖 Generated with Claude Code