Skip to content

A λ that copies its variable goes to BendTT as a plain λ over a λ+ redex, so it converts with the η-long abstract function it stands for (#1189) - #1223

Closed
nicolas-abril wants to merge 1 commit into
bendlang:mainfrom
nicolas-abril:lam-copy-eta

Conversation

@nicolas-abril

Copy link
Copy Markdown
Collaborator

Closes #1189.

Cause

tree() in safe.ts promoted a q=1 λ whose body uses its variable twice to a λ+. The kernel types a λ+ at a q=1 ∀, because Term.check only asks that liveness matches. Conversion is stricter: Term.parts pairs two λs only at the same quantity, and there is no η. The declarative Par.lam keeps q too, so this is the theory, not just the executable check.

An abstract f : Nat -> Nat in a type goes out η-long as a plain λx => (f x). Instantiated at +a => Nat.add(a, a), it becomes λx => ({λ+a => … : ∀} x). The call site emitted λ+a => …, so the kernel failed at the heads before it reached the redex. bend2 compares λs by η and accepts the file.

Change

A λ term that copies its variable now goes out the way η-expansion shapes it:

λx1 => ({λ+x2 => (Nat.add x2 x2) : ∀x2 : Nat -> Nat} x1)

Both sides are plain λs, and their bodies reduce to the same term. A new Scope.lam flag limits this to λ terms, which term() lowers. A def's case tree (arm()) keeps its λ+, since the kernel walks those λs to decide when the def unfolds and to check that recursive calls descend. o_up shifts the body's levels under the new outer binder. The change adds 290 ttok to safe.ts (20,497 / 24,000).

Checks

  • tests/proof/lam_copy_eta.bend holds the issue's case and the used-once case. It fails --verdict on main with the issue's error and passes here.
  • --verdict on all 1,526 files under tests/, run locally against main with the same kernel build: 974 vs. 973 check and 552 fail on both. The one extra pass is the new test, and every other file's output is byte-identical.
  • Extra probes that check here and fail on main:
    • nested copying continuations (the do-chain shape from the issue)
    • a copying λ after a match in a def's case tree, compared through its η-expansion
  • gates/repo.ts: PASS 49 / 49.
  • gates/test.ts and gates/safe.ts did not run: the cluster refused my SSH key from this session. The change only affects the --verdict and -o .bendtt output.

🤖 Generated with Claude Code

…dex, so it converts with the η-long abstract function it stands for (bendlang#1189)

safe.ts promoted a q=1 λ whose body uses its variable twice to a λ+.
The kernel types a λ+ at a q=1 ∀ (only liveness must match), but
converts two λs only at the same quantity, and has no η. An abstract
f : Nat -> Nat goes out η-long as a plain λx => (f x), so once
instantiated at +a => Nat.add(a, a) it became λx => ({λ+a => ..} x),
which the kernel never identified with the λ+ the call site emitted;
bend2 compares λs by η and accepts it.

A λ term (not a def's case tree, whose λs the kernel walks to unfold
and to check descent) now goes out as λx => ({λ+y => f : ∀y:A -> B} x),
the shape η-expansion gives it, so both sides are plain λs whose bodies
reduce to the same term.

Closes bendlang#1189

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

Copy link
Copy Markdown
Collaborator Author

Superseded by #1224, which fixes #1189 in the kernel: BendTT now converts a λ+ as a λ, as its typing already treats them. This PR's elaborator workaround is no longer needed.

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

1 participant