Repository navigation
Description
What you did
Three files, none of which imports Base (below): bend LAWS.bend; bend PROOF.bend --verdict; bend PROOF.bend -o p.bendtt
What happened
$ bend LAWS.bend
SOME PROOFS FAIL
Error: 1 TODO found.
The code is incomplete, and not a valid proof yet.
(what a correct LAWS.bend with its law still open prints)
$ bend PROOF.bend --verdict
ALL PROOFS CHECK
$ bend PROOF.bend -o p.bendtt (excerpt)
LAWS.Empty : *2 =
Σx0 : <> -> (LAWS.Empty.arms x0)
Empty : *2 =
Σx0 : <Boom> -> (Empty.arms x0)
LAWS.f_ne_g : ∀x0 : main.T -> ∀x1 : {(main.f x0) == (main.g x0) : main.T} -> Empty =
λx0 => λx1 => (.Boom, ())
f and g both return A{}, so the law is false as LAWS.bend states it, over its own empty Empty.
The certified != negates into PROOF.bend's one-constructor Empty; LAWS.Empty is emitted unused.
If PROOF.bend declares no Empty, it fails at LAWS.bend's law line:
- expected : a defined name / - observed : Empty (caret on the !=).
If the law is written {Code.f(x) == Code.g(x) : Code.T} -> Empty instead of with !=, the same PROOF.bend
fails: - expected : Laws.Empty / - observed : Empty.
With import Base, LAWS.bend's own type Empty is already a duplicate declaration.
The file
# ---- main.bend ----
type T is Data:
A{}
B{}
def f(x: T) -> T:
A{}
def g(x: T) -> T:
A{}
# ---- LAWS.bend ----
import ./main.bend as Code
type Empty is Data:
# LAW: f and g never agree
law f_ne_g:
for x: Code.T
{Code.f(x) != Code.g(x) : Code.T}
# ---- PROOF.bend ----
import ./LAWS.bend as Laws
type Empty is Data:
Boom{}
def Laws.f_ne_g(x):
e => Boom{}bend --version
bend 2.0.35 (source checkout of main at 565d7fd, bun bend2/main.ts)
uname -sm
Linux x86_64 (WSL2)
clang --version (the first line)
No response
bend.ts writes sugar, and the constructors of a literal, as raw, unqualified names that never go through
parse_reso:
!=isRef("Empty")
(bend.ts#L1902).exs/whereisRef("Exists")(L2171, L2571, L2576).- A Nat literal unfolds to
Zero/Succ(lit_step, L1098, called by check-lit). Nn+Twith n > 256 isRef("Nat.add")(L2226).a || bisBool.or(a, b)(the INFIX table; run, below).- By reading, the same holds for list literals,
Array.new, and the INFIX table's other named entries
(Pair,Or,Bool.and,Con,String.append).
The checker looks each one up by bare key
(bend.ts#L3284-L3287;
3301-3304 on main) after every file is parsed. With Base loaded anywhere, those keys are Base's, and
parse_fresh stops anyone from redeclaring them. Without Base, the only namespace-"" declarations are
the entry file's, so PROOF.bend supplies the meaning of LAWS.bend's != and exs. A written Empty in
LAWS.bend is not captured: parse_reso makes it LAWS.bend's own name. Only the sugar is, so a LAWS.bend
that declares its own Empty checks alone (as the entry, its Empty is the bare key) and loses it once
imported (its Empty becomes LAWS.Empty).
Literals have a fail-closed face. A Base-free module's literal checks when the module is the entry, and
is refused when another file imports it: - expected : a declared constructor (lib.Nat declares lib.Zero, lib.Succ) / - observed : 2n. The literal's bare Zero/Succ never match the module's
qualified constructors. There is also a single-file face. With a Nat.add(-a, b) that returns b,
200n+one runs to 201n and 300n+one runs to 1n, and both pass --verdict. With no Nat.add, only
the second is refused.
The capture can also carry a literal across files into #1330 's split. Take an imported LAWS.bend with
law l: 5000n || 800n, under a PROOF.bend that declares its own Nat, a Nat.add(-a, b) that returns
b, and def Bool.or(a: Nat, b: Nat) -> Type: {gt(a, b) == True{} : Bool}. bend PROOF.bend --verdict
passes, and the certified LAWS.l is Bool.or(Nat.add(Nat.mul(1, 4096), 904), 800): a claim about 904,
where bend2 checked one about 5000.
where goes the same way. A Base-free LAWS.bend that uses where has to declare its own Exists to
check at all. Imported, that declaration is LAWS.Exists, while the sugar still asks for the bare key.
Here the law is false: g is constantly X{} and f constantly Y{}. A PROOF.bend that declares
LAWS.bend's own Sig-based Exists is refused (expected : D.Y{} / observed : D.X{}). This one makes
Exists an empty type, so the law's binder ranges over nothing, and an empty match proves it:
# ---- d.bend ----
type Two is Data:
X{}
Y{}
def f(t: Two) -> Two:
Y{}
def g(t: Two) -> Two:
X{}
# ---- LAWS.bend ----
import ./d.bend as D
type Sig<a, b, -A: Kind(a), -B: @-x: A -> Kind(b)> is Kind(a <&> b):
Tup{fst: A, snd: B(fst)}
def Exists(-A: Type, -B: @-x: A -> Type) -> Type:
Sig<&1, &1, A, B>
# LAW: for every w with g(w) = X, f(X) is X.
law holds_when_gx:
for w: D.Two where {D.g(w) == D.X{} : D.Two}
{D.f(D.X{}) == D.X{} : D.Two}
# ---- PROOF.bend ----
import ./LAWS.bend as Laws
import ./d.bend as D
type Vd is Data:
def Exists(-A: Type, -B: @-x: A -> Type) -> Type:
Vd
def Laws.holds_when_gx(w):
match w:bend LAWS.bend prints 1 TODO found. and bend PROOF.bend --verdict prints ALL PROOFS CHECK. In the
certified law, w ranges over PROOF.bend's Exists, and LAWS.Exists is emitted unused:
Exists : ∀-x0 : *1 -> ∀-x1 : ∀-x1 : x0 -> *1 -> *1 =
λ-x0 => λ-x1 => Vd
LAWS.holds_when_gx : ∀x0 : (Exists -d.Two -λ-x0 => {(d.g x0) == (.d.X, ()) : d.Two}) -> {(d.f (.d.X, ())) == (.d.X, ()) : d.Two} =
λ{(,): λ{}}
bend.ts's header says "an unknown name is the file's own, unless its bare spelling is Base's", and the
2.0.28 notes (#1042) say a local file cannot register names in another file's namespace. GUIDE.md says
bend PROOF.bend prints SOME PROOFS FAIL while any law is open or false.
Fix direction (not tested). Bind sugar to Base only: have the checker require
book.tlds[k]?.b === true for a name that sugar introduced, as the foreign-def check does for IO, and
otherwise fail with "!= needs import Base". Alternatively, resolve sugar through parse_reso in the
file where it is written. For literals, use the target datatype's own Zero/Succ, or refuse with a
message, together with #1330 's guard in safe.ts. Either option closes both repros above. Resolving
through parse_reso keeps a Base-free LAWS.bend's own Empty/Exists working; binding to Base refuses
!=/where in a Base-free book outright.
This is not a proof of Empty. The kernel certified the entry's inhabited Empty (Σx0 : <Boom> -> …),
not <>, and with Base loaded the entry cannot declare Empty. The where case certifies a law under an
empty hypothesis: vacuity, not an inhabitant of <>.
Activity
The != and where sugar mean the Empty and Exists of the file they are…