Issue #1631: bounds walk: shift, xor and heap-index arithmetic form no goal (14 solver sites)

Open and answer this issue on GitHub.

ready, solver · opened 2026-11-15 · updated 2026-11-22 · 6 comments

Part of #1053. From the run of #1531 (table in its comment): 14 sites of sv_sat.nika where the walk forms no goal or lacks an operator rule (groups B and G). No new decision: the facts are D21/D25 element bounds and plain arithmetic the walk does not yet read.

To build

  1. Shift and xor on a literal: l >> 1 < n from 0 <= l < 2n; p ^ 1 < 2n from 0 <= p < 2n with 2n even. Sites (B, 11): sv_sat.nika 345-347, 361, 369, 391, 570-573, 809, together with the element bounds of trail, watch_blocker (< 2 * activity.len(), D25) and heap (< activity.len(), D21).
  2. Quotient and doubling index (G, 3): (i - 1) / 2 < i for i >= 1, 2 * i + 1 under left < len; sv_sat.nika 963 (self.heap[parent], trace forms no goal), 980.
  3. Tests in tests/compiler/ with .bounds for each shape.

Done when

The tests are green and lower-std --bounds proves the 14 sites (or the report names each one left and why).


Generated by Claude Code

Comments

keywan-ghadami, 2026-11-15

Brief queued: issue-1631


agent: builder model: opus max_turns: 200 budget_usd: 30 effort: medium —

Issue #1631

Your work order is issue #1631, inlined below with its comments. There is no brief written around it: plan your own steps from its To build list, build them in order, commit after each finished step, and end when its Done when holds (or at the limits of builder.md, reporting what is left). The facts in your prompt are Core of docs/builder-facts.md; more on a topic: nikaia run scripts/syntax.nika -- KEYWORD, a probe: nikaia run scripts/probe.nika -- SNIPPET.

Measure the issue against docs/issues.md while you work: what it lacked, what was wrong in it. That answer goes into the report’s Issue: field. A finding, a changed plan or a finished item also goes into the issue as a comment (gh api repos/Nikaia-Foundation/Nikaia/issues/1631/comments -F body=@file, ending with the Claude Code footer), rule I13.

Rules (CLAUDE.md; shared checkout)

Report (at most 15 lines, to exactly /home/user/Nikaia/docs/briefs/prover/issue-1631.md.report.md)

Fields: Result, Files, Commit, Body (optional), Fixes, Pushed, Tests, Gate, Deviation, Found, Needs, Changelog, Issue, Owner (a question for the owner), Disk freed, and last Attribution: with your commit trailer lines below it.


Generated by Claude Code

keywan-ghadami, 2026-11-15

Run: issue-1631, Result: done

Tokens: input 256, cache read 9667361, cache write 252695, output 74636 Cost: 11.47 USD, time 60 min 22 s, turns 128

Report

Result: done Files: crates/nikaia-std/src/compiler/bounds_walk.nika crates/nikaia-std/src/compiler/lowered/bounds_walk.rs crates/nikaia-std/src/compiler/lowered/comptime_driver.rs crates/nikaia-std/src/compiler/lowered/emit_needs.rs crates/nikaia-std/src/compiler/lowered/parser_leaves.rs crates/nikaia-std/src/compiler/lowered/sv_row.rs crates/nikaia-std/src/compiler/lowered/sv_sat.rs examples/json/nikaia.proofs examples/trend/nikaia.proofs packages/json/nikaia.proofs packages/yaml/nikaia.proofs tests/compiler/tests/a_shift_a_flip_and_a_quotient_are_numbers_the_walk_bounds.nika tests/compiler/tests/a_shift_a_flip_and_a_quotient_are_numbers_the_walk_bounds.stdout tests/compiler/tests/a_shift_a_flip_and_a_quotient_are_numbers_the_walk_bounds.bounds tests/compiler/tests/a_heap_parent_lies_below_its_child.nika tests/compiler/tests/a_heap_parent_lies_below_its_child.stdout tests/compiler/tests/a_heap_parent_lies_below_its_child.bounds Commit: bounds walk: / by a constant, >> by a constant and ^ 1 are linear terms with a fresh number Body: bounding_combined gives l / c, l >> k and l ^ 1 a fresh var (quotient#N, shifted#N, half#N) defined against l in walk.defining (only for the statement being walked; bounding_push pulls the definitions into the facts with what reads the var, bounding_settle puts them there before an assign/let forgets the name, so they never speak of a new value). bounding_range meets the solver’s range with the interval rules where a term reads such a var, bounding_fits falls back to them, bounding_let/assign keep that range. i = other counts as a falling counter (#1329) where bounding_set_lower proves value <= name: heap_up’s i = parent keeps i < heap.len(). lower-std –bounds: sv_sat 68->70 indexes proved, sv_row +2/+2, comptime_driver +1/+2, parser_leaves +1/+2, emit_needs +0/+1, bounds_walk +1 op; no file lost a proof (the 80 .bounds tests’ reports are unchanged). Part: #1631 Pushed: local caf60b0d8cd8cb3285fa61a16c65777352d986fb Tests: 2 new tests green –both-settings, both FAILED on the before binary (shift test 0/5 proved, heap test 4/6); –bounds report of all 80 .bounds tests old vs new: only the 2 new differ; clippy –all-targets green; lower-std fixpoint clean; ledgers –check stale in 4 (new walk questions) -> refreshed and committed Gate: green Deviation: 1 of the 14 sites proved (963 heap[parent]); the issue’s Done-when allows naming the rest: 345-347, 361, 369 (assign/assign_unit’s l has only l >= 0; a derived claim cannot say l < 2 * value.len() or name watch_clause, which the body does not index), 391, 570-573 (trail elements carry no bound: they come from that l, D21), 809 (heap elements carry no bound below value.len(), D21), 980 (2*i+1 needs i < n at heap_down’s head through i = child, an if-value the walk does not read). The goal now forms at every site (trace), it is open for those facts. Found: derived preconditions (ADR-391) only take p < list.len() of a list the body indexes, no factor: sv_sat assign(l) needs l < self.watch_clause.len() or l < 2 * self.value.len() (probe: fn f(xs: ref Vec[i64], l: i64) { xs[l >> 1] } called with l < 2 * xs.len()); collections::BTreeMap has no clear (walk.defining is reassigned collections::BTreeMap(), the existing idiom in bounds_frame/bounds_proven) Needs: none Changelog: bounds walk: a quotient by a constant, a shift right and ^ 1 are numbers the walk bounds - xs[l >> 1], pairs[l ^ 1], heap[(i - 1) / 2] and a heap’s sift-up are written without their check (#1631) Issue: meets I1-I13; its premise that all 14 sites only lacked the shift/xor/quotient forms is half right: 345-391, 570-573 and 809 also need the element bounds it names as a dependency, and 980 needs if-values read Owner: none Disk freed: none needed; target/nikaia-project-tests 4.0G, / 10G free (75%), no new cache entry over 100 MB Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDwk9ubq9teP7QCErff

Debrief

  1. Most cost: soundness and regressions in the walk. Recording the fresh-variable definitions left stale facts after an assign or let changed the name. A definition that read itself recursively overflowed the stack. sv_smt and sv_fast regressed. Each of these took a full lower-std and build cycle to find. Then the 14 sites turned out to need facts that are not there: element bounds (D21) and preconditions of the form l < 2*len.
  2. Looked up: how bounding_combined, bounding_push and bounding_range fit together, and how falling counters work (#1329). I also needed to know that derived claims (ADR-391, derived_claims) only take p < xs.len() for a list the body indexes. And I had to find that BTreeMap has no clear. The brief could have stated the ADR-391 limit and the D21 dependency for each site.
  3. Checks I ran: the fast build, lower-std and its fixpoint, lower-std --bounds before and after, the --bounds reports of all 80 tests diffed old against new, both new tests with --both-settings and against the old binary, clippy, fmt, pre-push, and ledgers.nika --check/--refresh. Wasted: one or two build cycles caused by the recursion overflow and by missing .clone() calls that cargo check would have caught first.
  4. The change that would have saved most: a probe matrix in the brief, one small program for each site with the facts it needs. That would have shown at the start that 12 of the 14 sites also need element bounds or preconditions with a factor.
  5. What the issue lacked:
    • It names no dependency on D21 element bounds or on derived preconditions with a factor for sites 345-391, 570-573 and 809. broke I5 (dependencies and premises).
    • It says the shift/xor/quotient forms alone would prove the 14 sites; only site 963 is proved. wrong I4.
    • Site 980 needs the walk to read if-values (heap_down’s i = child); the issue does not mention this. broke I5.
    • It says nothing about the 4 committed nikaia.proofs ledgers going stale. rules-gap.
  6. Traps the next builder will meet:
    • Fact: lowering collections::BTreeMap has no clear; reset it with = collections::BTreeMap().
    • Fact: Core A walk change that asks the solver new questions makes examples/* and packages/* nikaia.proofs stale; run scripts/ledgers.nika -- --refresh and commit them.
    • Fact: bounds A fact keyed on a variable must be written into the facts before an assign or let rebinds that variable (bounding_settle), or it describes the old value.
    • Fact: bounds Derived preconditions (ADR-391) cannot say p < k*xs.len() or name a list the body does not index; a param bound like that stays unproved.

Correction to my report: it says Result: done. The Done-when allows naming the sites left, but only 1 of the 14 sites is proved, so partial would be the more honest word. The commit says Part of #1631.


Generated by Claude Code

keywan-ghadami, 2026-11-22

Brief queued: issue-1631


agent: builder model: opus max_turns: 200 budget_usd: 30 effort: medium —

Issue #1631

Your work order is issue #1631, inlined below with its comments. There is no brief written around it: plan your own steps from its To build list, build them in order, commit after each finished step, and end when its Done when holds (or at the limits of builder.md, reporting what is left). The facts in your prompt are Core of docs/builder-facts.md; more on a topic: nikaia run scripts/syntax.nika -- KEYWORD, a probe: nikaia run scripts/probe.nika -- SNIPPET.

Measure the issue against docs/issues.md while you work: what it lacked, what was wrong in it. That answer goes into the report’s Issue: field. A finding, a changed plan or a finished item also goes into the issue as a comment (gh api repos/Nikaia-Foundation/Nikaia/issues/1631/comments -F body=@file, ending with the Claude Code footer), rule I13.

Rules (CLAUDE.md; shared checkout)

Report (at most 15 lines, to exactly /home/user/Nikaia/docs/briefs/solver/issue-1631.md.report.md)

Fields: Result, Files, Commit, Body (optional), Fixes, Pushed, Tests, Gate, Deviation, Found, Needs, Changelog, Issue, Owner (a question for the owner), Comment (#N <text>, what to say on another issue; the driver posts it, one line each), Friction, Disk freed, and last Attribution: with your commit trailer lines below it.


Generated by Claude Code

keywan-ghadami, 2026-11-22

Run: issue-1631, Result: partial: of the 14 sites, group G (963, 980) and the operator rules of B were built by the earlier run (caf60b0d8); this run proves the heap’s element bound past a truncate; the 11 literal sites of B (345-347, 361, 369, 391, 570-573) and 809 stay checked, reasons in Body

Tokens: input 168, cache read 7011245, cache write 129612, output 33268 Cost: 3.28 USD, time 6 min 59 s, turns 84

Report

Result: partial: of the 14 sites, group G (963, 980) and the operator rules of B were built by the earlier run (caf60b0d8); this run proves the heap’s element bound past a truncate; the 11 literal sites of B (345-347, 361, 369, 391, 570-573) and 809 stay checked, reasons in Body Files: crates/nikaia-std/src/compiler/bounds_rules.nika crates/nikaia-std/src/compiler/bounds_walk.nika crates/nikaia-std/src/compiler/lowered.rs crates/nikaia-std/src/compiler/lowered/bounds_rules.rs crates/nikaia-std/src/compiler/lowered/bounds_walk.rs packages/logic/nikaia.contracts packages/logic/nikaia.proofs tests/compiler/tests/a_value_read_before_a_truncate_keeps_its_element_bound.nika tests/compiler/tests/a_value_read_before_a_truncate_keeps_its_element_bound.stdout tests/compiler/tests/a_value_read_before_a_truncate_keeps_its_element_bound.bounds Commit: bounds walk: a value read out of a list keeps its element bound when the list shrinks afterwards Body: rules_element_facts stated a read element’s rule facts with bounding_each_guarded’s guard len(list) <= 0 || fact; the read proves the list not empty, so bounding_each_unguarded (bounds_walk.nika) drops that guard. Before, a later truncate/pop of the list (bounding_forget_length) dropped the fact: heap_pop’s top = heap[0] read before heap.truncate(last) lost top < place.len(). check –bounds packages/logic/src/sv_sat.nika (2026-11-22, this commit): indexes 61 -> 69 proved (933, 934 above, 949, 951, 968, 972, 995, 999), none lost; lower-std –bounds on the toolchain identical old/new. Left: the B literal sites need l < 2 * activity.len() on assign/assign_unit’s literal and an element rule on trail; their callers pass clause literals from outside data (add_input’s kept[0], sv_smt.nika’s units[i], arena words), which nothing bounds, so no derived precondition can hold (the shift/xor rule itself proves: assert(l < 2 * self.value.len()) then self.value[sv_sat_var(l)] proves). 809 (self.value[heap_pop()] in pick): the index heap …/result heap_pop … rules stand in heap_pop’s walk but not in pick’s (trace 809 lists no heap rule even before the call); a reduced probe of pick+pop proves, cause not found in this run. Also: SvSat.value has no length activity value rule while a scratch rename of the field to vvalue gets it (+3 sites): a bare name value recorded as changed beside (bounds_frame.nika fields_mark fallback) suspected; a two-file probe did not reproduce it Pushed: local 899735f29bf98d6ecaaa71205322a8783343f74b Tests: new a_value_read_before_a_truncate_keeps_its_element_bound (.bounds, .stdout): on $NIKAIA_OLD line 36 self.place[top as i64] is checked, now proved; all 192 tests with a .bounds file green (target/fast/nikaia test, one –filter each); ledgers –check: only packages/logic stale, refreshed (heap_pop, heap_down, above now panics = false) Gate: green Deviation: none Found: none Needs: none Changelog: bounds walk: a value read out of a list keeps what the list’s rule says of it after the list shrinks - a binary heap’s pop reads its top’s place without a check (#1631) Issue: broke I7: the issue named “shift and xor” as the missing operator rules for group B, but the operator rules were not the gap: the literals those sites read have no bound at all, since they come from clause input no code checks against the variable count Comment: #1631 Left after this run: B’s 11 literal sites need a bound on clause literals (l < 2 * vars), which no code establishes (input from sv_smt/add_input); 809 needs the heap rules to stand in pick (they stand in heap_pop, not in pick: trace 809 shows none), cause open Friction: none Disk freed: none (cache 1.8G, / 5.6G free) Reviewed: c933b2bcd9e607c308791de3037bbfcaf246e95346ad7e6acf0008a10ef2c37b Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDwk9ubq9teP7QCErff

Debrief

  1. What cost the most: tracing why the shift/xor sites stayed checked. The --bounds-trace output was too large for one tool output and had to be narrowed with sed/cut. Line 809 (pick) took a long time and ended at the time limit with the cause unknown. The rename test on SvSat.value also cost turns and found nothing that held up.
  2. What I looked up: where element rules are stated (rules_element_facts), how bounding_each_guarded builds its guard, and that bounding_forget_length drops facts on a truncate. I also had to find that commit caf60b0d8 had already proved the two index sites. A section on how the bounds walk is built, with these names, would have saved most of it.
  3. Checks: the build and lower-std fixpoint, the 192 .bounds tests, check --bounds on sv_sat (61 to 69), lower-std --bounds with the old and new binary, the new test on the old binary, ledgers --check, and pre-push. None was wasted. Wasted: the scratch rename of value and the two-file test, which did not reproduce it.
  4. Change that would save the most: the brief should say to run check --bounds on the target file with the HEAD binary first, and list which sites are still checked. Two of the 14 were already proved before I started.
  5. What the issue lacked:
    • wrong I7: it blamed missing shift/xor rules for the 11 shift/xor sites. The real gap is that clause literals have no bound at all.
    • broke I5: it had no probe per site showing which fact was missing.
    • knowledge: Ledger and bounds proofs | an element fact read from a list was stated guarded by len(list) <= 0, so a later truncate dropped it (fixed in 899735f2)
  6. Traps the next builder will meet:
    • Fact: Ledger and bounds proofs | --bounds-trace LINE on a large file overflows the tool output; pipe it through sed -n and cut -c1-200.
    • Fact: Ledger and bounds proofs | a change to the bounds walk changes the contracts and proofs of packages/logic; refresh them with scripts/ledgers.nika -- --refresh before committing.
  7. For the next builder in Ledger and bounds proofs:
    • Fact: Ledger and bounds proofs | measure with target/fast/nikaia check --bounds packages/logic/src/sv_sat.nika: 69 indexes proved, 2026-11-22, commit 899735f2 (was 61).
    • Fact: Ledger and bounds proofs | element rules live in rules_element_facts (bounds_rules.nika), guards in bounding_each_guarded/bounding_each_unguarded (bounds_walk.nika).
    • Fact: Ledger and bounds proofs | sv_sat 809: the heap rules hold in heap_pop's walk but not in pick's; cause open as of 2026-11-22, commit 899735f2.

Generated by Claude Code

keywan-ghadami, 2026-11-22

From the report of the run of issue-1631 (#1631):

Left after this run: B’s 11 literal sites need a bound on clause literals (l < 2 * vars), which no code establishes (input from sv_smt/add_input); 809 needs the heap rules to stand in pick (they stand in heap_pop, not in pick: trace 809 shows none), cause open


Generated by Claude Code

keywan-ghadami, 2026-11-22

Supervisor, 2026-11-22: I accept the partial run (899735f2). Here is what is done and what is left.

Moved out: site 809 (pick / heap_pop) and the value/vvalue field rule now belong to “bounds walk: the result rule of heap_pop does not stand in its caller pick (sv_sat.nika 809)” (#2777).

Left here: the 11 literal sites of group B (345-347, 361, 369, 391, 570-573). The prover is not missing anything for them, because the shift/xor rule already proves once l < 2 * value.len() is known. Nothing proves that bound today: the literals come from clause input (add_input’s kept[0], units[i] in sv_smt.nika, arena words), and no code checks them against the variable count.

The next run builds: a check in sv_sat.nika where literals enter the solver (add_input and the unit path), so that the solver states l < 2 * vars once. A clause literal past the variable count is refused there as invalid input, and from there the derived preconditions of assign / assign_unit hold. The 11 sites must then show as proved in check --bounds packages/logic/src/sv_sat.nika.


Generated by Claude Code

Back to Open Issues