Skip to content

fix(verdict): preserve Base-free large Nat literals - #1337

Merged
nicolas-abril merged 9 commits into
bendlang:mainfrom
oxura:fix/nat-literal-provenance
Oct 8, 2026
Merged

nicolas-abril merged 9 commits into
bendlang:mainfrom
oxura:fix/nat-literal-provenance

Conversation

@oxura

@oxura oxura commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1330.

  • Compact large Nat literals through Nat.mul/Nat.add only when Nat and both operations originate in Base.
  • Emit a structural Zero/Succ literal for user-defined Nat, preserving the checked constructor quantities.
  • Add Base-free regressions with misleading arithmetic and no arithmetic. A two-successor claim distinguishes 4097 from the previous incorrect 1; the literal is also exercised in claim types.

Verification (local, Bun 1.3.13; real BendTT kernel built with Lean 4.34.0):

  • Both new fixtures: --verdict -> ALL PROOFS CHECK, actual CLI execution -> 4097n. Both fail against unchanged main's elaborator.
  • Structural 4096 boundary and Base compact 9000 control: verdict passes and values remain 4096n/9000n.
  • No gate/core-language/cap changes. Cluster gates were not run.

@oxura

oxura commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Strengthened the permanent regression: claim now compares id(~4097n) with Succ{grow(12n, Zero{})}, where grow constructs 2^12 successors without any large literal or Nat arithmetic. The actual Lean 4.34.0-built kernel accepts this independent 4097 value oracle, and the CLI still prints 4097n. This avoids relying on equality between two literals that could both be mistranslated.

@oxura

oxura commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Joint local verification of #1337–#1341 against main 565d7fd, including the constructor-model correction in #1338:

  • Combined repository gate: PASS 50 / 50; original caps/core-language/gates unchanged.
  • Actual Lean 4.34.0 BendTT kernel accepts all six positive new proof fixtures, existing vec_safe_lookup, Base's Type-model control and compact 9000 Nat control. The 4097 regression uses an independent 2^12+1 structural value oracle.
  • User-defined parameterized/def Unit remains explicitly out of elaboration scope (no model for idt~A), not a claimed kernel success.
  • Versioned kernel cache works with no Lean on PATH. The earlier incompatible 4.32/source-only-cache and explicit BENDTT controls were also exercised.
  • Combined emitted HTTP JS retains ABC across fragmented headers and six receives. Individual HTTP smoke additionally used actual TCP under Bun/native C and an exact 65536-character response split into 65536 one-character receives.
  • Combined generated CUDA C reports cuInit(0) failed: CUDA_ERROR_UNKNOWN when forced under fault injection; automatic CPU fallback prints 2147450880 without diagnostics.
  • Code changes merge automatically. Only additive Unreleased CHANGELOG entries needed combining in the local integration checkout.

No physical GPU, macOS/Metal runtime, or mini-cluster gate was exercised. Separate PR source branches remain independent; the integration branch is local verification only.

oxura and others added 3 commits October 6, 2026 00:29
…eads

ctr_term took a bare Ctr term where it expects the Ctr variant (a new
tsc error), and Zero has no fields, so pack_ctr builds the same tuple.
nat_literal reads no scope and emits no live-dependent term, so its
scope and live parameters go.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nicolas-abril
nicolas-abril force-pushed the fix/nat-literal-provenance branch from 71ad49e to 1b701da Compare October 5, 2026 22:46
@nicolas-abril

Copy link
Copy Markdown
Collaborator

Thanks for this! I rebased the branch onto current main (your two commits applied cleanly) and added one small commit on top: nat_literal now starts from pack_ctr("Zero", []), which fixes a new tsc error from passing a bare Ctr term to ctr_term, and it drops the scope/live parameters it didn't use.

Checked on the rebased branch:

@oxura

oxura commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @nicolas-abril. I kept your rebase and pack_ctr fix, rebuilt the kernel from this branch with Lean 4.34.0, and checked both new fixtures: --verdict passes and execution prints 4097n. The repository gate passes 50/50. Commit a41f605 only removes our Unreleased entry, following the release-note convention clarified in the rest of the batch; no evaluator change or force-push. Future PRs will leave CHANGELOG.md to releases.

@nicolas-abril nicolas-abril self-assigned this Oct 8, 2026
nicolas-abril and others added 5 commits October 8, 2026 09:22
…ne vouches for Nat.mul and Nat.add, as a build trusts base's names

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…g one of a file's own Nat takes nat_literal

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…tays base's Nat.mul and Nat.add: the chain is what lit_step builds, without a recursion per unit

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… only when it builds one

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…e's; a file's own Nat unfolds like any literal, so nat_literal and pack_ctr go

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@nicolas-abril

Copy link
Copy Markdown
Collaborator

Thanks again, @oxura! Before merging I cut this down to the core fix, which is now one line in safe.ts plus your two tests:

-      if (x.k === "Nat" && x.v > NAT_MAX) {
+      if (x.k === "Nat" && x.v > NAT_MAX && e.book.tlds.Nat?.b === true) {

Why:

  • One guard covers it. Nat.mul and Nat.add are the only names safe.ts inserts by itself. If Nat is Base's, Base is imported, and then those two can't be redefined (a duplicate declaration is an error). So checking Nat alone is enough, the same way comp.ts trusts the Base names it relies on.
  • nat_literal wasn't needed. Without the compact form, a user Nat literal takes the same path as every other literal (lit_step, then ctr_term), which builds the same constructor chain. Across the 597 tests with literals, the kernel output is byte-for-byte identical with and without nat_literal.
  • It didn't prevent the stack overflow either. A later safe.ts pass recurses once per layer over the finished term anyway. With plain recursion, nat_literal, or a general loop-built lowering, a user Nat literal of about 10,000 overflows at the same size. Around that size the checker overflows first anyway. So keeping it added a second way to build literals without making anything work that didn't before.

Very large literals of a user-defined Nat (and very long strings) still overflow the stack. That's a separate issue: some recursions in the checker and in safe.ts go one level per layer. It also crashes rather than accepting anything wrong, so it isn't unsound.

Checked: both new tests and 9000n under Base pass --verdict, and gates/_run.ts gives repo 50/50 and test 1578/1578.

@nicolas-abril
nicolas-abril merged commit d3cacb7 into bendlang:main Oct 8, 2026
1 check passed
@oxura

oxura commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for reducing this to the Base-Nat guard and retaining the two behavioral regressions. Agreed that user literals should keep the existing constructor-lowering path; I will preserve the merged simplification. I have recorded the remaining large-user-Nat/long-string stack overflow as a separate checker/traversal limitation, not as something this PR fixes.

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

Labels

None yet

Projects

None yet

2 participants