gh-153222: Add math.integer.isprime() and math.integer.primes()#153224
Open
serhiy-storchaka wants to merge 1 commit into
Open
gh-153222: Add math.integer.isprime() and math.integer.primes()#153224serhiy-storchaka wants to merge 1 commit into
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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