refactor(primes): explicit MAX_RULES_PER_PARTITION cap + documented bounds - #53
Open
discreteds wants to merge 1 commit into
Open
refactor(primes): explicit MAX_RULES_PER_PARTITION cap + documented bounds#53discreteds wants to merge 1 commit into
discreteds wants to merge 1 commit into
Conversation
…two bounds Replace the opaque _sieve(3572) magic (which silently meant '500 primes') with a named MAX_RULES_PER_PARTITION constant (raised to 10_000) and a _first_n_primes(n) helper that sizes the sieve by prime count via the Rosser bound. The table is still computed at import (an instant bounded sieve) — a precomputed literal/file buys nothing, and a table 'up to 2**64' is impossible and the wrong dimension (we index by rule count, not prime magnitude). Document the two independent limits: the intrinsic width-15 combination bound (primorial <= int64, enforced by checked_multiply) vs the rules-per-partition table-size cap (enforced by get_prime). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
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.



Explicit prime-table cap + documented bounds
Replaces the opaque
_sieve(3572)(which silently meant "the first 500 primes")with an auditable, named limit.
What changed
MAX_RULES_PER_PARTITION = 10_000— a named constant is now the table size / max rules per partition (was an arbitrary, undocumented 500 encoded as the sieve limit3572)._first_n_primes(n)— sizes the sieve by prime count (Rosser boundp_n < n(ln n + ln ln n)), so the cap is expressed in the dimension that matters (rules), not a magnitude.get_primeover-index error now namesMAX_RULES_PER_PARTITIONand points at the CONTEXT_KEY remediation.checked_multiply/LatticeWidthExceededError.get_prime.Why not a precomputed literal / data file
The sieve runs once at import in microseconds — a literal list or a file buys no speed and adds packaging/IO surface. A table "up to 2⁶⁴" is impossible (~4.2×10¹⁷ primes ≈ exabytes) and the wrong dimension anyway: primes are indexed by rule position, never by magnitude.
Testing
tests/accumulator/test_primes.py: table-size-equals-cap invariant,_first_n_primes(empty/small/exact-count/boundary 10000th=104729), over-capget_primeerror names the constant. 19 passed.🤖 Generated with Claude Code