Repository navigation
Nat bounds: drop 2^48 limit and zero-divisor tests that static bounds rule out - #48
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…p exit Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…unds widen after 64 walks (isqrt's Newton step keeps y >= 1) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
nicolas-abril
added a commit
that referenced
this pull request
Dec 1, 2026
…33, #34, #36, #39, #44, #61-#68): record their heads Each is a port onto main of integration's own branch, its content already here (integration keeps the original commits; the ports add type fixes, line wraps, moved pieces and #68's book_passes, applied in the previous commit). Groups: #61 (#9 #11 #15 #32 #41 #42), #62 (#26 #56), #63 (#48 #50 and compile-time), #64 (#19 #20 #45), #67 (#55 #58), #68 (#54); par-defer (#43) is now part of #34, lazy-startup's parts are in #16 and #34. This merge records their heads (-s ours: no content change). Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Merged into integration at 283a904 (
opt/nat-testsa71fa62, after merging integration 4561e97; lane statuses equal to integration's plus the 7 new tests: nat_range_edge passes, the other 6 print their expected stdout, stderr andexit 1, the kind the lane counts as FAIL; 242 of 244 benchmark programs print expected at 1 thread and the 98 parallel ports at 10, the same two as integration exceed the memory caps).Static bounds for
Natvalues let the C lane drop the 2^48-1 limit test on adds, muls and successors that cannot reach the limit, and the zero-divisor test ofNat.div/Nat.modby a variable proven positive.comp.tsonly (section "Nv"), plus seven tests.How
nv_bookruns once afterfile_bookand computes, for every reachable def:FL.fids,main) takes anything;The rules:
U32.to_natand literals.small.y + n / y >= 2, so isqrt'sy >= 1.The emitter carries a word's bounds on its
Val(nv). These come from the native's parameters, from literals, ops and call results, and from match fields.Soundness. Every Nat is at most 2^48-1, and a test is dropped only when the bounds of its operands keep the result there. So a wrong bound would wrap silently. The tests below each target one way the analysis could trust a bound it should not.
Results
On
opt/integration5a4a9f5. 49 of the 244 programs' C changes. Instructions are from one run; cycles are the median of 5 runs at 1 thread.45 programs outside the bendlang#2180 hoist set: geomean 0.9530x cycles, 0.9318x instructions. The 4 programs in the hoist set are level. No output is wrong.
Losses over 5% in cycles:
osprey/collatz/bend-par+5.4% (16-placement sweep: +3.5% median, +1.8% to +6.2%). The only C change is the two100 * xmuls in its setup, which lose their tests. Clang then lays out the hot loop differently (+7.5% instructions). The sequential port, with the same change, is −7.5% (sweep: −2.9% median).respelled/mutual+11.7% at −0.2% instructions. This is placement: the 16-position sweep is level, median 0.996, spread 0.86 to 1.21.Also placement, under 5%:
koka-extra/splay+2.8% (sweep median 0.982).Test sites across the 22 Osprey kernels go from 314 to 136. Examples: powmod 69→2, exprtree 84→23, listops 28→6, factorial 10→2, isqrt 8→2, digitsum 6→2. In bend-runtime and polybench, no Nat test sits in a hot loop; their only one is
List.length's counter.Osprey board (hyperfine, ms):
In isqrt the zero-divisor test is gone too:
n / ywithy >= 1. The Newton step runs at the C reference's speed or better.Checks
opt/integration; 111 tests' C changes.-DBEND_POISON, 0 live words at 1 and 8 threads on those 111 and the new tests.expected.txtat 1 thread; the parallel ports also at 10 threads.--gpu onand--gpu off. No bend-runtime program and notrespelled/queenschanges.tests/run/nat_range_*:edge: sums that land exactly on 2^48-1;modzero: a remainder by a divisor in 0..2;rel: a Bool relation broken at one call site;escape: a def passed as a closure;steps: a self-call that does not step the parameter down;mid: an overflow in the middle of a loop that prints as it goes;wrap: 2^40 × 2^40, which wraps to 0 in a u64.comp.tsgrows by about 8,400 tokens: roughly 8,620 added, 260 removed.Not in this PR
Testing an accumulator only at loop exit (and every 2^15 turns, so its word cannot wrap) is on branch
opt/nat-tests-sink.3n+1test in collatz has no static bound, and stays.2026-11-30 (97674ad): compile time — nv_book's relation rounds walk only a def whose own relations moved since its last walk (the only state such a walk reads), so the confirming round is mostly skipped. Same C on the 2,129-program corpus.
🤖 Generated with Claude Code