Repository navigation
Description
Since #1548 (32d23b4), List.all(~a, ~A, ~f, h <> t) unfolds to List.all.go(~a, ~A, ~f, t, f(h)), and .go matches the list before the flag. When f(h) is False{} the result is known, but the term stays stuck until t is a constructor. If t is erased, that never happens: an erased binder can't be matched (a live scrutinee (a - scrutinee matches only in a dead region)), and {==} doesn't apply. So a statement whose list tail is erased no longer has a proof. List.any, List.find and List.contains do the same when the head decides the result.
What you did
bend head_fails.bend --check-only
The file
import Base
def head_fails(-t: List<Nat>) -> {List.all(~&1, ~Nat, ~(n => Nat.is_le(n, 3n)), 5n <> t) == False{} : Bool}:
{==}
def main() -> Bool:
List.all(~&1, ~Nat, ~(n => Nat.is_le(n, 3n)), [5n, 1n])What happened
At 234cb9b:
SOME PROOFS FAIL
Error:
- expected : List.all.go(&1, Nat, n => Cmp.is_le(Nat.cmp(n, 3n)), t, False{})
- observed : False{}
Context:
- t : List<&1, Nat>
Location: head_fails
3 | def head_fails(-t: List<Nat>) -> {List.all(~&1, ~Nat, ~(n => Nat.is_le(n, 3n)), 5n <> t) == False{} : Bool}:
4>| {==}
| ^^^^
5 |
On v2.0.37 the same file prints ALL PROOFS CHECK. These fail the same way at 234cb9b and pass on v2.0.37, each proved by {==} with -t erased:
{List.any(~&1, ~Nat, ~(n => Nat.is_le(n, 3n)), 1n <> t) == True{} : Bool},t : List<Nat>{List.find(~Nat, ~(n => Nat.is_le(n, 3n)), 1n <> t) == Some{1n} : Maybe<&2, Nat>},t : List<&2, Nat>{List.contains(~Nat, ~Nat.is_eq, 3n <> t, 3n) == True{} : Bool},t : List<&2, Nat>
Where it bites
bend-mathlib 0.7.3.0 on BendHub has an append-only API. At 234cb9b, 23 definitions in its list.bend (proofs and their helpers) stop checking. I stubbed each failing one in turn, so later failures show too:
- 14 check again through small lemmas about the
.goloops, proved by a case split on the flag or an induction that carries it. - 7 have no proof, because the statement erases the tail where the search stops:
all_append,any_append,contains_append(-ys);mem_cons_self,mem_cons_of_mem(-xs);sorted_cons_cons_elim_le,sorted_cons_cons_elim_tail(-t, wheresorted_byisList.alloverList.zip(x <> y <> t, y <> t)). - 2, the accumulator helpers behind
all_reverseandany_reverseoverA: Kind(a), I couldn't prove: every invariant I tried needs the reversed prefix or the accumulator twice after a false head, and the elements are affine.
What I tried
A loop that reads the flag before the list would keep the early stop and the tail call, and would reduce go(t, False{}) for any t. I couldn't write one:
- As a user def, it fails the decreasing-call check: the flag changes before the list shrinks.
- In a scratch
base.bend, theString.starts_with.ifshape (a helper that calls alawfilled below it, bend.ts accepts books the Lean kernel refuses: base-file live calls to later-filled laws, and non-Tree bodies #793) fails the same check atList.all.if~0for these template defs, with the flag before or after the list.
So this is a report, not a patch.
bend --version
bend 2.0.37, and main at 234cb9b
uname -sm
Linux x86_64
clang --version (the first line)
Ubuntu clang version 21.1.8 (6ubuntu1)
Activity
MuhDur commentedon Oct 16, 2026
Folded into the description.
mathlib: unfold List.all/any/find/contains and String.order only thro…
mathlib: route find_append, the any/all dualities, contains_reverse a…
MuhDur commentedon Oct 16, 2026
Folded into the description, with the count corrected: 23 definitions, not 21.
[-]Base since #1548: List.all/any/find of h <> t stays stuck when h decides the result, so lemmas over an erased tail have no proof[/-][+]Since #1548, List.all/any/find/contains of `h <> t` stay stuck when `h` decides the result, so a lemma over an erased tail has no proof[/+]Lorenzobattistela commentedon Oct 16, 2026
Thanks for the detailed report @MuhDur. We're reverting #1548 in #1629.
#1548 rewrote these searches as tail-recursive helpers that carry the result so far. That made them match the tail before using the head's result, so with an erased tail (
h <> t) they stay stuck even when the head already decides the answer. We tried a Base-only version that checks the head first. It fixed one-element cases like5n <> t, but not1n <> 5n <> t. Doing it properly would need a checker change, so we're going back to the previous definitions, which proved all of these.The trade-off is that very long lists can overflow the host stack again. That's a known limit (see WONTFIX.txt).
research: keep only the String.order bridge proofs after upstream rev…