Skip to content

test(proof): the U32 bit lemmas an Array law on perfect trees needs (#2059) - #2142

Closed
YidaWeng wants to merge 1 commit into
bendlang:mainfrom
YidaWeng:test/u32-bits
Closed

YidaWeng wants to merge 1 commit into
bendlang:mainfrom
YidaWeng:test/u32-bits

Conversation

@YidaWeng

@YidaWeng YidaWeng commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Part of #2059. This does not close it.

This lands the proved part of adeerkhan's draft from #2059 as tests/proof/u32_bits.bend, with a main instance (shl_p2 at 8 bits). The lemmas are the ones that do not need Nat.sub or the Word.sub/Word.cmp laws:

  • shr_shl
  • ctop_eq
  • top_shl
  • shl_p2
  • top_p2

plus the helper defs and def-theorems they rest on (ctop, top, init, zeros, p2, ctop_p_eq, top_zeros, ...).

Why tests/proof, not Base: Base carries the operations and U32.add_comm only; these proofs need local helper defs, nothing in Base consumes them yet, and adding them to the prelude would slow every check. tests/proof is the established home for proven laws that are not yet in Base (bool_algebra.bend says the same). They can move into Base when the four Array facts are complete and a consumer uses them.

Verification on upstream/main 9162bfe9:

  • bun bend2/main.ts tests/proof/u32_bits.bend --verdict -> ALL PROOFS CHECK (Lean 4.34.0 kernel)
  • bun bend2/main.ts tests/proof/u32_bits.bend -> {==}
  • bun bend2/main.ts tests/proof/u32_bits.bend -o u32_bits.js -o u32_bits -> the C and JS lanes both print {==}
  • bun gates/repo.ts -> PASS: 56 / 56

The proofs are adeerkhan's draft; this PR adds the test wrapper and re-verifies them on current main.

Still missing for #2059: Nat.add(d, Nat.sub(32, d)) == 32 for d <= 32, then the borrow chain through Word.adc/Word.sub/Word.cmp, the mask fact, the branch bit, and the subtraction bound. I'd be glad to continue on those once this lands.

If maintainers would rather have these lemmas in Base now, say so and I'll move them.

@Lorenzobattistela

Copy link
Copy Markdown
Collaborator

Closing as superseded by #2213, which is merged: tests/proof/array_perfect_tree.bend proves the four U32 facts of #2059 (mask, halving shift, branch bit, right-half index) and the 2^d word lemmas they need, so this file would be a second, partial copy with nothing using it. Thank you for re-verifying the draft and turning it into a test; it kept the issue moving.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants