perf(hex-primality-mathlib): bound negative rho search - #9841
Merged
Conversation
added 11 commits
August 30, 2026 18:00
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.
Fixes #9803
Summary
2^16Brent cycle stepsnderiveNotPrimeterms, and bounded exhaustion with no trial-division fallthroughAccepted contract for #9800
The opt-in
Nat.Primenorm_numnegative route runs only after bounded certificate search returns.composite. Certificate search starts fromHex.Rand.ofSeed n; factor search resumes the returned state withHex.Nat.Internal.rhoFactorCountedWith? n f.rand natPrimeRhoRestartBudget natPrimeRhoStepBudget, where the named budgets are one restart and2^16Brent cycle steps per restart throughout the supported range of at most 512 input bits. The current root-composite preflight consumes zero attempts and leaves the seed state unchanged. The primitive parity preflight can return factor 2 without consuming a restart. Every returned candidate is revalidated as1 < d,d < n, andn % d = 0beforederiveNotPrimeemits an independently kernel-checked proper-factor proof. Exhaustion makes the Hex extension decline; the guarded trial alias also declines at and above2^24, so exhaustion never starts total/unbounded trial division.Measurements
Final source-matched release-quality sweep after rebasing onto #9842; CPU 22, six balanced samples per row, 10-second absolute fresh-module gate:
release_quality=true; no exceptions, violations, or exhausted sample pairs. Null robust spread/build ratios were 12.51% and 2.69%. The contract is explicitly absolute-only: import-subtracted deltas remain diagnostic and may be unresolved. Report:reports/bench-results/hex-primality-negative-policy-issue-9803-chungus2.json.The old production-scaled policy was rejected during pilot work: one adversarial 82-bit restart took about 26 s, while the former 16-restart 512-bit search exceeded two minutes. The fixed
2^16cap removes that scaling while retaining small-factor capability.Independent review
The requested Opus review confirmed the soundness and no-fallback boundaries, then identified the original 64-bit input-width cliff, unresolved-relative-measurement presentation, missing SPEC/CI wiring, and seed-resume convention. This revision replaces the cliff with bounded work across all widths, makes the absolute contract explicit, updates SPEC and CI, adds 65/512-bit odd-factor probes, and resumes
f.randwith exact state replay conformance.Verification
lake build HexPrimalityMathlib HexConformance HexPrimalityElabProbe(10,373 jobs)python3 -m unittest scripts.bench.test_primality_negative_sweeppython3 scripts/bench/check_factor_sweep_freshness.pygit diff --check origin/main...HEAD