Skip to content

--verdict mismatch: an η-expanded argument keeps old binder levels in its inner annotations (Bool where Nat is expected) #1665

Closed

Description

@aaaxn

What you did

bun bend2/main.ts repro.bend --check-only, then bun bend2/main.ts repro.bend --verdict

What happened

On main (e5527d5):

$ bun bend2/main.ts repro.bend --check-only
ALL PROOFS CHECK
Use --verdict for mathematical validity.
$ bun bend2/main.ts repro.bend --verdict
SOME PROOFS FAIL
In passed:
expected: Nat
observed: Σx3 : <False, True> -> (Bool.arms x3)
Sorry - this is a mismatch between the TypeScript implementation, and the formalized BendTT kernel. Your proofs may or may not be correct, and we cannot validate them yet. This will be addressed in a future update. Meanwhile, feel free to open an issue to report this bug.

The file

import Base

type Fact<-P: Type> is Data:
  Fact{-proof: P}

type Box<-P: Type> is Data:
  Box{}

def Cells() -> Type:
  @+b: Bool -> {b == b : Bool}

def cells(-keeps: @+n: Nat -> {n == n : Nat}) -> Fact<Cells()>:
  Fact{b => {==}}

def take(-p: Cells()) -> Box<Cells()>:
  Box{}

def passed(-kf: @+n: Nat -> Fact<{n == n : Nat}>) -> Box<Cells()>:
  take({\{Fact: q => q} : Fact<Cells()> -> Cells()}(
    cells(n => {\{Fact: q => q} : Fact<{n == n : Nat}> -> {n == n : Nat}}(kf(n)))))

bend --version

2.0.37 (tag v2.0.37, 4ff8545). Same result on main at e5527d5 and on PR #1657 at 4d5f662. Each version's kernel was built from its own bendtt.lean with Lean 4.34.0 (the PR doesn't change bendtt.lean). On 2.0.37, --verdict fails the same way, but without the In passed: expected/observed lines.

uname -sm

Linux x86_64

clang --version (the first line)

No clang on PATH; clang-19 --version: Ubuntu clang version 19.1.1 (1ubuntu1~24.04.2). --verdict doesn't use it: it returns at main.ts:308, before cc_find.

Diagnosis

The argument of take is an application, and its type Cells() is a function type. So arg_term makes it η-long: safe.ts:1332-1340 calls eta (safe.ts:953-955), which wraps the argument in a new binder, λ+x1 : Bool. That moves the inner n => ... down one level, from x1 to x2. Its body moves with it. The Nat annotations on the inner eliminator don't move and still say x1, which is now the Bool. From -o:

passed = λ-x0 => (take -λ+x1 => ({…} : ∀x2 : (Fact -Cells) -> Cells}
  (cells -λ+x2 => ({…} : ∀x3 : (Fact -{x1 == x1 : Nat}) -> {x1 == x1 : Nat}} (x0 +x2))) +x1))

The η-expanded form written by hand (below) emits the same term, character for character, except for {x2 == x2 : Nat} in those two places, and it passes. So the kernel is right to reject this term: it really is ill-typed.

To find where the stale level comes from, I dumped the argument at arg_term's eta branch. The λ bodies in it use whatever variable they are instantiated with. But the annotations bend2 attached to the inner eliminator (Var("_", -1) with v set) hold n as Var(n, 1), a fixed level. I didn't trace where bend.ts writes those annotations.

Here the stale level gives an ill-typed term, so a valid proof gets rejected. I didn't look for a case where the stale level lands on a binder whose type fits and the term is accepted.

tree also calls eta, at safe.ts:772 and safe.ts:879. I didn't test those paths.

Workaround

Writing the η-expanded argument by hand passes --check-only and --verdict on all three versions above:

  take(b => {\{Fact: q => q} : Fact<Cells()> -> Cells()}(
    cells(n => {\{Fact: q => q} : Fact<{n == n : Nat}> -> {n == n : Nat}}(kf(n))))(b))

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions