Skip to content

Structural Nat.min/max with direct order laws and split lemmas - #860

Closed
nbardy wants to merge 1 commit into
bendlang:mainfrom
nbardy:stdlib/structural-nat-max
Closed

nbardy wants to merge 1 commit into
bendlang:mainfrom
nbardy:stdlib/structural-nat-max

Conversation

@nbardy

@nbardy nbardy commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Replaces the Bool.pick-over-computed-test Nat.min/max with structural recursion unfolding in lockstep with Nat.cmp (same values on all inputs: four constructor cases + induction; nothing in Base unfolds the old bodies).

Why: the pick form is proof-opaque (Bend cannot match on a computed test), so no order law over Nat.max/min was provable by case analysis. Structural bodies unlock Nat.cmp_refl/ge_refl/max_ge_l/max_ge_r, proved here adjacent to the defs.

Honest cost note: old form returns an existing node (O(1) allocation after O(min) compare); new form rebuilds O(min) Succ nodes. Provability outweighs the allocation on unary Nats.

Also adds Bool.split/Cmp.split decision lemmas (case analysis with the equation remembered) — the root fix for all 46 staging helpers.

Verification: full base.bend prints 'All terms check' under the source-built checker (bun bend2/main.ts). Prior bridge proofs over the old bodies (pick_succ machinery) become obsolete on this change; migration is one cong per arm.

Draft status: seeking maintainer read on direction before final polish.

Replace Bool.pick-over-computed-test min/max with structural
recursion unfolding in lockstep with Nat.cmp (same values, stated
O(min)-allocation cost). Add Nat.cmp_refl/ge_refl/max_ge_l/max_ge_r
and Bool/Cmp.split decision lemmas. Full Base green under the
source-built checker.
VictorTaelin added a commit that referenced this pull request Sep 19, 2026
…ve by cases (#860)

Integrates PR #860: the min/max match keeps three rows (0n _, 1n+ap 0n,
1n+ap 1n+bp); Nat.ge_refl proves by direct induction, so Nat.cmp_refl and
its Equal.cong go; the unused Bool.split/Cmp.split and the two comment
blocks go; base.bend stays under its 24500 ttok cap. nat_ops covers min/max
in both orders, against 0n, and on equal Nats past the literal bound.
@VictorTaelin

Copy link
Copy Markdown
Contributor

Shipped in 2.0.17. Your base was 80 commits behind, so the work was cherry-picked rather than merged, and trimmed to fit base.bend's size budget: the two comment essays and the two unused lemmas (Bool.split, Cmp.split) came out. The structural Nat.min/Nat.max and the order laws are in as you wrote them; equivalence with the old definitions was checked on a 41x41 grid and at values past the literal bound. Thank you.

Note: this reply was written by an AI after it reported the issue to me and I made the decision. If anything here is wrong, reply and I will review it myself.

@jeromelaurens jeromelaurens mentioned this pull request Sep 24, 2026
Phylliida pushed a commit to Phylliida/bend that referenced this pull request Sep 27, 2026
…ve by cases (bendlang#860)

Integrates PR bendlang#860: the min/max match keeps three rows (0n _, 1n+ap 0n,
1n+ap 1n+bp); Nat.ge_refl proves by direct induction, so Nat.cmp_refl and
its Equal.cong go; the unused Bool.split/Cmp.split and the two comment
blocks go; base.bend stays under its 24500 ttok cap. nat_ops covers min/max
in both orders, against 0n, and on equal Nats past the literal bound.
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