Skip to content

sort.bend fails bend --verdict on 2.0.36 (bend#1182, bend#1483), so it cannot be imported by a --verdict gate #25

Closed

Description

@nohzafk

bend-mathlib's sort.bend type-checks but does not pass bend --verdict on bend 2.0.36 (checked on mathlib 0.6.0.0, 0.7.0.0, 0.7.1.0 and 0.7.2.0):

bend sort.bend --check-only   # passes
bend sort.bend --verdict      # "mismatch between the TypeScript implementation and the formalized BendTT kernel"

So a downstream project whose gate is --verdict cannot import sort.bend at all; the import alone fails the file.

bend sort.bend -o x.bendtt lists 25 defs as out of scope, for two causes, both bend bugs:

  1. no model for ...~le_total: hits insert_by_sorted, isort_by_sorted and their helpers. A template parameter whose type is an equality that the translation's default model makes false has no model, so the def is dropped. Reported upstream as BendTT mismatch for opaque higher-order template with dependent equality result bendlang/bend#1182 (smaller repro added in BendTT mismatch for opaque higher-order template with dependent equality result bendlang/bend#1182 (comment)).
  2. a template argument that depends on a run-time value: hits merge_by_sorted, msort_by_sorted and their helpers, through internal_least, which writes List.all(~&2, ~A, ~(y => le(lo, y)), xs) inside a type with lo a run-time variable. Reported as --verdict: a template lambda that captures a run-time value inside a type is out of scope for BendTT, but bend2 accepts it bendlang/bend#1483.

Suggestions, either of which would help until bend fixes them:

  • Run --verdict in the mathlib gate, so a module that cannot be imported under --verdict is caught here.
  • Restate the affected lemmas to avoid both forms, e.g. a plain recursive "every element is >= lo" predicate instead of the List.all template lambda in internal_least. A downstream copy that does this, specialised to one element type, checks under --verdict on 2.0.36.

Activity

  1. MuhDur commented on Oct 12, 2026

    @MuhDur
    Contributor

    Thanks for the careful report. I reproduced both points on bend 2.0.36: sort.bend from 0.6.0.0, 0.7.0.0, 0.7.1.0 and 0.7.2.0 checks and fails --verdict, and a file that imports sort.bend and uses nothing from it fails --verdict too, while the same file importing list.bend passes.

    bend-mathlib 0.7.3.0 (0xf8a2f05bbfb67041ce3d1eaece892a1a) takes your second suggestion. internal_least is now a recursive Bool def instead of List.all with a lambda over lo. Only internal helpers changed; every public statement is the same. On 2.0.36 that removes all 20 defs that were out of scope for bendlang/bend#1483. sort_by_sorted_nat, msort_by_sorted_nat and merge_by_sorted_nat now translate to BendTT, as isort_by_sorted_nat already did.

    It does not make sort.bend importable under --verdict yet. 13 defs are still out of scope, all with no model for an abstract ~le_trans or ~le_total: the generic insert_by_sorted, isort_by_sorted, merge_by_sorted, msort_by_sorted, sort_by_sorted and their helpers. Those hypotheses are part of the published signatures, so I can't drop them without breaking callers. With the model search from bendlang/bend#1263 (closed upstream; I ran its branch, which is based on 2.0.35), 0.7.3.0 gets ALL PROOFS CHECK from --verdict for sort, algebra, order and all. So bendlang/bend#1182 is now the only thing between this package and a clean --verdict.

    On your first suggestion: CI already runs --verdict on every module. nat, bool, list, string, maybe, equal and perm must pass. algebra, order, sort and all are on a list that fails as soon as one of them starts passing, so it gets moved up. From this release that list also fails if any of them is out of scope for a reason other than no model, so a bendlang/bend#1483-style term can't come back unnoticed. The README and the agent skill now say which modules a --verdict project can import.

    I'll keep this open until a bend release fixes bendlang/bend#1182, then move sort to the must-pass list. If a sort module that imports cleanly under --verdict today would help you (Nat only, no ~le_* hypotheses), tell me which element types you need. I didn't want to duplicate the proofs without knowing someone would use it.

  2. MuhDur commented on Oct 18, 2026

    @MuhDur
    Contributor

    Update: Bend's main branch now has bendlang/bend#1580 (merged, not yet in a release), which takes a ~ constant's model from a concrete call of the law. With Nat calls of the remaining laws added in f571950, every bend-mathlib module, sort.bend included, prints ALL PROOFS CHECK under bend --verdict at bend main e5527d5.

    On the released bend 2.0.37 nothing changes yet: algebra, order, sort and all are still out of scope only by "no model", and CI now runs the kernel on the rest of those files. When the next Bend release ships, I'll move the pin, put all four modules on CI's must-pass --verdict list, release bend-mathlib 0.7.4.0 and close this issue.

  3. MuhDur commented on Oct 21, 2026

    @MuhDur
    Contributor

    Fixed in bend-mathlib 0.7.4.0, which works with Bend 2.0.38. That release includes bendlang/bend#1580, which takes a ~ constant's model from concrete calls of its law, so every module passes bend --verdict, including sort, algebra, order and all. A project that checks with --verdict can now import any of them:

    import bend-mathlib@0.7.4.0/sort.bend as MSort

    I checked this from an empty package cache: a file importing nat, sort and all from the hub prints ALL PROOFS CHECK under --verdict. CI and release.ts now require --verdict on every module, so this stays true. Thanks for reporting it, and for the 2.0.38 port in #26.

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