Skip to content

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 #1616

Closed

Description

@MuhDur

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 .go loops, 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, where sorted_by is List.all over List.zip(x <> y <> t, y <> t)).
  • 2, the accumulator helpers behind all_reverse and any_reverse over A: 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:

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

  1. MuhDur commented on Oct 16, 2026

    @MuhDur
    Author

    Folded into the description.

  2. MuhDur commented on Oct 16, 2026

    @MuhDur
    Author

    Folded into the description, with the count corrected: 23 definitions, not 21.

  3. changed the title [-]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[/+] on Oct 16, 2026
  4. Lorenzobattistela commented on Oct 16, 2026

    @Lorenzobattistela
    Collaborator

    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 like 5n <> t, but not 1n <> 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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