Repository navigation
fix(demos): keep the sort and sum specs outside the editable programs - #1932
Merged
Lorenzobattistela merged 2 commits intoOct 29, 2026
Merged
Conversation
…ec's SPEC.bend no longer reaches into the program: main.bend defines pow2 again, and pow2_same proves Spec.pow2(d) == Par.pow2(d) for tree_is_seq. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Lorenzobattistela
approved these changes
Oct 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1931.
As in #1915, each demo gets a
SPEC.bendbesideLAWS.bend, withBOARD.bend's header. It holds every definition the laws' meaning needs, andLAWS.bendandPROOF.bendread them from there.I named all three
SPEC.bendsince they play the same part in each demo, so the name says what the file is for.BOARD.bendkeeps its name here.SPEC.bendmain.bendproof_insertion_sortLE,Sorted.from,Sorted,bump,countle_caseanddecuseSpec.LEpure_par_sumpow2,seqsumusesSpec.pow2pure_par_sortsumsum, nothing elseLEandpow2move too: moving onlySorted,countandseqleaves the laws standing on definitions inmain.bend, and an edit there still passes (the issue has both). The programs import them, sole_casenow returns evidence ofSPEC.bend's order, andsumsplits its range withSPEC.bend'spow2. Those twoSPEC.bendfiles say so in their header.One choice is yours:
pow2is both part of what the law means (2^d numbers) and howsumsplits its range. The other way is a copy ofpow2inSPEC.bendand a lemmaPar.pow2(d) == Spec.pow2(d)inPROOF.bend, so the split stays the program's and onlySPEC.bendreads the program, as in #1915, for one more induction. I'm happy to switch to that.pure_par_sort'sSPEC.bendreadsSort.Tree, the type the program sorts.Spec.sumchecks only if a leaf is aNatand a node a pair of trees, so a differentTreefails inSPEC.bendrather than changing what the sum means.The proofs change only in names (
Sort.LEtoSpec.LE,Par.seqtoSpec.seq, and so on). No checker, kernel, gate or other demo changes.What I checked
On 4f99f4c, macOS arm64:
bend PROOF.bendandbend PROOF.bend --verdict(Lean 4.34.0) print ALL PROOFS CHECK in each demo, andbend SPEC.bendchecks.[1n, 2n, 3n](interpreted and C),2147450880(C, on Metal and with+RTS --gpu off),sorted(C, on Metal and with+RTS --gpu off).pure_par_sort,mixreturningx: expectedNat.add(Spec.sum(d, x), Spec.sum(d, y)), observedNat.add(Spec.sum(d, x), Spec.sum(d, x)).pure_par_sum,sumreturning0n, with or without its ownpow2returning0n: expected0n, observedSpec.seq(Spec.pow2(d), i).proof_insertion_sort,sortreturningxs, with or without its ownLEasUnit: expectedSpec.LE(lo, h), observedUnit.def Spec.seqinmain.bendorPROOF.bendis refused ("Spec is an import's alias"). Adef SPEC.seqthere is accepted, but the law still readsSPEC.bend's: withsumreturning0nit fails as above, and it checks only whenSPEC.bend's ownseqreturns0n.gates/repo.ts's allow list, and demos have no token cap. I couldn't run the gate itself here (nottok).Not run: the cluster gates, Linux.