Skip to content

BendTT converts a λ+ as a λ: a q=2 binder says how a λ runs, not what it is (#1189) - #1224

Merged
nicolas-abril merged 7 commits into
bendlang:mainfrom
nicolas-abril:lam-lin-conv
Oct 5, 2026
Merged

nicolas-abril merged 7 commits into
bendlang:mainfrom
nicolas-abril:lam-lin-conv

Conversation

@nicolas-abril

@nicolas-abril nicolas-abril commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1189. Replaces #1223, which patched safe.ts instead.

Cause

The kernel's typing and conversion disagree about a λ's quantity:

  • Typing: a λ's quantity only has to match its ∀ in liveness. Term.check and Typed.lam accept a λ+ at a q=1 ∀, plus a Data domain for the λ+.
  • Conversion: the quantity is part of the λ's identity. Term.parts paired two λs only when q = p, and Par.lam kept q.

bend2 is consistent with the typing side. The checked book drops a λ's quantity, and compare_go compares λs by η, with no quantity involved.

In #1189 this surfaces as follows. safe.ts emits +a => Nat.add(a, a) as λ+a => …, and the abstract f in same's type goes out η-long as a plain λx => (f x). Instantiated, that is λx => ({λ+a => … : ∀} x). The kernel stopped at λ vs λ+ before reducing the redex. bend2 accepts the file.

Change (kernel: bendtt.lean)

  • Quan.lin: sends Q2 to Q1 and leaves the others alone. A λ+ copies its argument, which is how it runs, not what it is.
  • Term.parts: pairs two λs when q.lin = p.lin. On Q0/Q1/Q2 that is the same as one liveness, the test typing, Walk and Eval use, and it is stated in the same terms as Par.
  • Par.lam: takes p = q ∨ p = q.lin, so a λ+ may reduce to a λ and never back. That direction keeps subject reduction: the λ keeps its liveness and needs no Data domain.
  • Term.dev: sends each λ to its lin.
  • Proofs:
    • par_refl and the triangle lemma get one more alternative each.
    • parts_conv gets a new conv_lam, and sr gets a one-line λ case.
  • Unchanged: no Claim statement, and evaluation and the live check, which don't use Par.

Rebased onto #1203, which had left bendtt.lean at 63,985 ttok. The rule adds 353, so a second commit shortens proofs elsewhere, with no def, inductive or Claim changes:

  • qmin_eq, conv_typ_enu, closed_app, index_lt, called_iff, walk_total and eval_decreases were unused or are inlined into their single uses.
  • crefl replaces spelled-out reflexive joins.
  • The twin cases of fits_at, at_trans, wnf_pars's fire, ev and gsl share one script.

A third commit shortens proofs throughout, to leave room under the cap for later kernel rules. Again, every def, inductive and Claim is byte-identical; only the single-use unlhs tactic macro goes.

  • Fourteen single-use lemmas are inlined into their callers.
  • value_form (a closed value has its type's former) replaces canon_pair and fits_former.
  • live_sub, uses_sub, chk's check cases, ev and bud_once each share one script across their cases.

A fourth commit shortens proofs again (61,151 → 59,701 ttok), with every def, inductive and Claim byte-identical except RenOk, a predicate only typed_ren used:

  • typed_ren goes; substok_up proves the weakening it needs locally.
  • snd_wnf2, pars_all, sl_mid and index_key are inlined.
  • uses_unspine replaces uses_spine and spine_unspine, and vm_up and bud_up become one lemma.
  • chk's check side covers the scrutinee's wnf once, and sr, ev, fits_at and qmin_par/qmin_map each share one script across cases.

The shared scripts made Lean's check of the file about 17% slower than main, so a fifth commit puts main's per-case proofs back for the slowest ones (live_sub, ev, bud_once, qmin_par, qmin_map, fits_all, head_used, and pos_ok's Tup case), with qmin_eq and sl_mid restored for them.

bendtt.lean ends at 60,457 ttok and 3,839 lines, 3,543 under its cap. lean bendtt.lean takes about 7.5 s wall and 17.3 s CPU, against 7.1 s and 16.5 s on main. The compiled kernel's code differs from main only in Term.parts's λ case. safe.ts is unchanged.

The paper's Metatheory (bend2/docs/BendTT/main.typ) now says that parallel reduction also steps $λ^2$ to $λ^1$. Its Confluence section says the complete development does that step too. Its Subject Reduction section says this step can lose the live check on a closed term, which is harmless because the live claims are about evaluation, and $↦$ never takes it. Its Mechanization section now says bendtt.lean is about 4,000 lines instead of giving an exact count. paper/BendTT.pdf is rebuilt from it with typst 0.15.1 (typst compile --root bend2/docs bend2/docs/BendTT/main.typ).

An elaborator fix (#1223) has to decide for each λ whether it is a value or part of a def's case tree. At a def root it breaks the case tree: 75 tests regress when that fix drops the distinction. It also misses a curried +a => +b => … unless it runs at every λ of a value. The kernel rule covers all of these.

Checks

  • Proofs: lean bendtt.lean builds with no errors or warnings under both the pinned v4.34.0 and v4.34.1. #print axioms for consistent, sr, confluent, progress and halts lists only propext, Classical.choice and Quot.sound.
  • New test: tests/proof/lam_copy_eta.bend holds the issue's case and the used-once case. It fails --verdict on main and passes here.
  • Full --verdict over tests/: run locally on main (1cce4999) and on this branch. Main checks 1,004 of 1,570 files; here 1,005 of 1,571 check, the extra one being the new test, and every other output is byte-identical.
  • Probes: these check here, and all but the first fail on main:
    • a copying λ after a match in a def's case tree
    • a recursive def whose copying λ contains the self-call
    • nested copying continuations (the do-chain shape from the issue)
    • a curried copying λ
  • gates/repo.ts: PASS 50 / 50.
  • Not run: the cluster gates gates/test.ts and gates/safe.ts.

Review

  • This changes the trusted kernel, so it may need Taelin's sign-off.

🤖 Generated with Claude Code

@Lorenzobattistela Lorenzobattistela left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I merged this onto main 1159f0b0 and ran the gates over BEND_HOC. Everything passes, and the fix does what it says.

Gates on the merge

  • gates/_run.ts: repo PASS 50 / 50, test PASS 1547 / 1547, perf PASS 124 / 124, ping PASS 46 / 46, in 20.6 s.
  • gates/safe.ts tests, this PR's kernel against main's:
    • main: 1,557 files; 992 agree, 71 u, 491 bend2 rejects, 2 out of scope, 1 false reject (agree_32, out of fuel, already there on main).
    • this PR: 1,558 files; 993 agree, everything else the same.
    • The one extra agree is tests/proof/lam_copy_eta.bend. Every other file's output is byte-identical to main.
  • bendtt.lean also builds with no errors under the pinned Lean v4.34.0 (the description says v4.34.1).

1. No gate catches a revert

tests/proof/lam_copy_eta.bend prints ALL PROOFS CHECK on main as well, because gates/test.ts runs it without --verdict. Under --verdict, main prints SOME PROOFS FAIL and still exits 0. gates/safe.ts lists that as ! and also exits 0. So reverting the change in Term.parts and Par.lam would leave every gate green. This isn't something to fix in this PR, since the gates are Taelin's, but it's worth knowing that the test documents the fix without guarding it.

2. The paper's subject-reduction paragraph (main.typ, Subject Reduction) now undersells the problem

It says that reduction of open terms does not preserve the live check, and then gives the reason: BendTT evaluates closed terms only. With the new step, a closed term loses the live check too. λ² x. (x, x) is closed and passes the live check, but ⇒ now steps it to λ¹ x. (x, x), which uses a q=1 variable twice. This is still sound, because Progress and the live claims use ↦, which never takes the λ step. The paragraph should say so: parallel reduction may also lose the live check on closed terms, by the λ² ⇒ λ¹ step, and that is harmless because the live claims are about evaluation.

3. The paper's account of the development (main.typ, Confluence) no longer matches Term.dev

"The complete development $t^*$ reduces every redex of $t$ at once." Term.dev now also sends every λ² to λ¹, which is not a redex. That needs one clause there, for example "and steps every $λ^2$ to $λ^1$", so the text matches the triangle proof.

nicolas-abril and others added 2 commits October 5, 2026 16:37
… it is (bendlang#1189)

Rebased onto bendlang#1203. Par steps a λ+ to a λ and never back; Term.parts
pairs two λs when their Quan.lin agree (the same as one liveness on
Q0/Q1/Q2), so conv_lam closes without a lemma relating .live and .lin.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Proof-only: qmin_eq, conv_typ_enu, closed_app, index_lt, called_iff,
walk_total and eval_decreases are inlined into their single uses or
were unused; crefl replaces spelled-out reflexive joins; the twin cases
of fits_at, at_trans, wnf_pars's fire, ev and gsl share one script.
No def, inductive or Claim changes. 63,506 ttok, 4,118 lines.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
nicolas-abril and others added 5 commits October 5, 2026 17:25
… 64k cap

Proof-only: every def, inductive and Claim is byte-identical; only the
single-use unlhs tactic macro goes. Single-use lemmas are inlined
(cmp_size, get_le, good_top, pad_le, ok_let, wnf_fits, conv_lam,
takes_sub, value_call, kindof_live, no_kind2, conv_eql, conv_inst,
canon_fun); value_form (a closed value has its type's former) replaces
canon_pair and fits_former; live_sub, uses_sub, chk's check cases, ev
and bud_once share one script across their cases. 3,924 lines;
BendTT.pdf rebuilt with the new count.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Proof-only: every def, inductive and Claim is byte-identical but RenOk,
a predicate only typed_ren used; typed_ren goes, and substok_up proves
the weakening it needs locally. snd_wnf2, pars_all, sl_mid, index_key
and the uses_spine/spine_unspine pair (now uses_unspine) go; vm_up and
bud_up are one lemma; chk's check side covers the scrutinee's wnf once;
sr, ev, fits_at and qmin_par/qmin_map share one script across cases.
3,803 lines, build time unchanged (~9.5 s); BendTT.pdf rebuilt.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
live_sub, ev, bud_once, qmin_par, qmin_map, fits_all, head_used and
pos_ok's Tup case get their per-case proofs from main back, with
qmin_eq and sl_mid restored for them: elaboration was ~17% slower than
main, now within ~5% (7.5 s vs 7.1 s wall, 17.3 s vs 16.5 s CPU), for
756 ttok (60,457, 3,839 lines). Proof-only; BendTT.pdf rebuilt.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… step may lose the live check

From the review of bendlang#1224: Confluence now says t* also steps every λ² to
λ¹, as Term.dev does, and Subject Reduction says parallel reduction can
lose the live check on a closed term too (λ² x. (x, x) ⇒ λ¹ x. (x, x)),
harmless since the live claims are about ↦, which never takes that step.
BendTT.pdf rebuilt.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The 64k ttok cap keeps the file near that size, so the paper no longer
needs a rebuild each time a proof changes length.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

--verdict: a lambda whose variable is used twice does not convert to the same lambda passed for an abstract function, under a stuck call

2 participants