--verdict: a lambda whose variable is used twice does not convert to the same lambda passed for an abstract function, under a stuck call
What you did
bend twice.bend && bend twice.bend --verdictWhat happened
$ bend twice.bend
ALL PROOFS CHECK
Use --verdict for mathematical validity.
$ bend twice.bend --verdict
SOME PROOFS FAIL
Sorry - this is a mismatch between the TypeScript implementation, and the formalized BendTT kernel. [...]
$ bend twice.bend -o twice.bendtt && bendtt twice.bendtt # kernel built by --verdict for 2.0.34
SOME PROOFS FAIL
In t:
expected: ((apply x0) λx1 => ({λ+x2 => ((Nat.add x2) x2) : ∀x2 : Nat -> Nat} x1))
observed: (code x0)With a => Nat.add(a, 1n) in both places (the variable used once), both
commands print ALL PROOFS CHECK.
The file
import Base
def apply(m: Maybe<&2, Nat>, f: Nat -> Nat) -> Nat:
match m:
case None{}: 0n
case Some{n}: f(n)
def code(m: Maybe<&2, Nat>) -> Nat:
apply(m, +a => Nat.add(a, a))
def same(m: Maybe<&2, Nat>, -f: Nat -> Nat, e: {apply(m, f) == code(m) : Nat}) -> Unit:
Unit{}
def t(+m: Maybe<&2, Nat>) -> Unit:
same(m, +a => Nat.add(a, a), {==})apply(m, _) is stuck on the abstract m, so the conversion compares the
two function arguments. In the emitted book, same states
(apply x0 λx2 => (x1 x2)) == (code x0): its f is eta-expanded as a plain
λx => f x, while code has λ+x1 => (Nat.add x1 x1) (the variable is used
twice). Instantiated at t, the kernel's expected side keeps the redex
({λ+x2 => … : ∀x2 : Nat -> Nat} x1) under the plain λ, and does not identify
it with code's λ+. bend2 does.
We met it proving that a do chain over Result returns only what it
checked: the continuation of a +x : A <- m binding is such a λ+, and an
inversion lemma for Result.bind takes the continuation as an abstract
f. We worked around it with one inversion lemma per binding, stating the
continuation literally.
bend --version
bend 2.0.34
uname -sm
Darwin arm64
clang --version (the first line)
Apple clang version 21.0.0 (clang-2100.3.34.2)
Source: HigherOrderCO/Bend