Skip to content

gh-153222: Add math.integer.isprime() and math.integer.primes()#153224

Open
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:math-integer-isprime-u64
Open

gh-153222: Add math.integer.isprime() and math.integer.primes()#153224
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:math-integer-isprime-u64

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

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

@read-the-docs-community

read-the-docs-community Bot commented Jul 6, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33465270 | 📁 Comparing 81e40f0 against main (3a1b547)

  🔍 Preview build  

3 files changed
± library/math.integer.html
± whatsnew/3.16.html
± whatsnew/changelog.html

@serhiy-storchaka serhiy-storchaka requested a review from tim-one July 6, 2026 18:17
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>
@serhiy-storchaka serhiy-storchaka force-pushed the math-integer-isprime-u64 branch from 92c57fe to 81e40f0 Compare July 6, 2026 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant