← Back to Pull requests

feat(Boole): add verified queue and deque examples #539

Open
Robertboy18 opened this pull request with 447 lines diff across 8 files
View on GitHub
Robertboy18 Robertboy18 commented on May 03, 2026 04:04 UTC
Author

I wanted to keep building out the Boole examples, so this adds three verified data-structure examples: an array-backed FIFO queue, a circular queue and an array-backed deque. It also sets up cvc5 in CI so the Strata.Boole.verify "cvc5" checks can run, and notes in two_sum and seq_slicing why smt is left out of their fallback chains.

The sandbox has moved to Lean 4.34 since I opened this, so I merged the current Boole-sandbox in. The queue examples, two_sum and seq_slicing build with --wfail --iofail against it, using cvc5 from the cvc5 package. While rechecking, bubble_sort and loop_simple failed that build because if_pos and if_neg are now deprecated, so they use ite_eq_left and ite_eq_right instead.

I had a bit of AI help with the merge and the 4.34 fixes. Let me know if you have any questions :)

Diff: 447 lines (+439 / -8) across 8 files Reviewer: Arleee1 Review duration: 279631m
All Vouch review confidence checks passed
Residual risk 0.08 = Change Risk (0.57) × (1 − Review Confidence (0.86)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.57 · 447 lines diff across 8 files
0.57
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.92 · 5 substantive comment(s)
0.92
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
85%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.365
Real PR Conversation Timeline
11 items
copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on May 03, 2026 04:25 UTC
Reviewer

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Arleee1 Arleee1 commented on code on May 03, 2026 18:54 UTC
Code Review
Cslib/Languages/Boole/examples/circular_queue.lean:1
@@ -0,0 +1,141 @@
+import Strata.MetaVerifier
+
+------------------------------------------------------------
+namespace Strata
+
+-- Circular-buffer queue.
+--
+-- The queue is represented by an array `Q`, a capacity `n`, a head pointer, a
+-- tail pointer, and a live element count.  Unlike `queue_array_based.lean`,
+-- `head` and `tail` wrap back to zero when they reach the capacity.  We model
+-- that wraparound with a small `NextIndex` function instead of `mod`, so the
+-- verification conditions remain simple arithmetic plus map-update reasoning.
+private def circularQueuePgm :=
+#strata
+program Boole;
+
+type Array := Map int int;
+
+// `NextIndex(i, n)` is `(i + 1) mod n`, axiomatized without using `mod`.
+function NextIndex(i : int, n : int) : int;
+
+axiom (∀ i : int, n : int ::
+  n > 0 && 0 <= i && i < n ==> 0 <= NextIndex(i, n) && NextIndex(i, n) < n);
+axiom (∀ n : int :: n > 0 ==> NextIndex(n - 1, n) == 0);
+axiom (∀ i : int, n : int ::
+  n > 0 && 0 <= i && i + 1 < n ==> NextIndex(i, n) == i + 1);

This seems to be the same as if i + 1 == n then 0 else i + 1, is there a reason why the axiomatic definition is preferred?

Robertboy18 Robertboy18 commented on code on May 03, 2026 20:10 UTC
Code Review
Cslib/Languages/Boole/examples/circular_queue.lean:1
@@ -0,0 +1,141 @@
+import Strata.MetaVerifier
+
+------------------------------------------------------------
+namespace Strata
+
+-- Circular-buffer queue.
+--
+-- The queue is represented by an array `Q`, a capacity `n`, a head pointer, a
+-- tail pointer, and a live element count.  Unlike `queue_array_based.lean`,
+-- `head` and `tail` wrap back to zero when they reach the capacity.  We model
+-- that wraparound with a small `NextIndex` function instead of `mod`, so the
+-- verification conditions remain simple arithmetic plus map-update reasoning.
+private def circularQueuePgm :=
+#strata
+program Boole;
+
+type Array := Map int int;
+
+// `NextIndex(i, n)` is `(i + 1) mod n`, axiomatized without using `mod`.
+function NextIndex(i : int, n : int) : int;
+
+axiom (∀ i : int, n : int ::
+  n > 0 && 0 <= i && i < n ==> 0 <= NextIndex(i, n) && NextIndex(i, n) < n);
+axiom (∀ n : int :: n > 0 ==> NextIndex(n - 1, n) == 0);
+axiom (∀ i : int, n : int ::
+  n > 0 && 0 <= i && i + 1 < n ==> NextIndex(i, n) == i + 1);

Yes, that’s exactly the intended meaning! I originally wrote it axiomatically because the direct Boole conditional version currently triggers a VC-generation/elaboration issue for integer-valued if branches: the generated VC contains something like ite (tail + 1 = n) 0 ..., and Lean reports that the 0 has type Int but a Prop was expected. So NextIndex is just a workaround for expressing the same circular successor while keeping the example verifiable. I agree the conditional version is clearer, and I’m happy to switch once that VC issue is fixed or add a short comment explaining the helper.

Arleee1 Arleee1 commented on code on May 04, 2026 00:39 UTC
Code Review
Cslib/Languages/Boole/examples/circular_queue.lean:1
@@ -0,0 +1,141 @@
+import Strata.MetaVerifier
+
+------------------------------------------------------------
+namespace Strata
+
+-- Circular-buffer queue.
+--
+-- The queue is represented by an array `Q`, a capacity `n`, a head pointer, a
+-- tail pointer, and a live element count.  Unlike `queue_array_based.lean`,
+-- `head` and `tail` wrap back to zero when they reach the capacity.  We model
+-- that wraparound with a small `NextIndex` function instead of `mod`, so the
+-- verification conditions remain simple arithmetic plus map-update reasoning.
+private def circularQueuePgm :=
+#strata
+program Boole;
+
+type Array := Map int int;
+
+// `NextIndex(i, n)` is `(i + 1) mod n`, axiomatized without using `mod`.
+function NextIndex(i : int, n : int) : int;
+
+axiom (∀ i : int, n : int ::
+  n > 0 && 0 <= i && i < n ==> 0 <= NextIndex(i, n) && NextIndex(i, n) < n);
+axiom (∀ n : int :: n > 0 ==> NextIndex(n - 1, n) == 0);
+axiom (∀ i : int, n : int ::
+  n > 0 && 0 <= i && i + 1 < n ==> NextIndex(i, n) == i + 1);

Thanks! I understand now. Maybe it would be helpful if you added a quick bit about that in the comment too, because it explains why mod doesn't work but not the issue with the if/else, which seems to be the other obvious non-axiomatic approach (compared to mod).

Robertboy18 Robertboy18 commented on code on May 04, 2026 20:40 UTC
Code Review
Cslib/Languages/Boole/examples/circular_queue.lean:1
@@ -0,0 +1,141 @@
+import Strata.MetaVerifier
+
+------------------------------------------------------------
+namespace Strata
+
+-- Circular-buffer queue.
+--
+-- The queue is represented by an array `Q`, a capacity `n`, a head pointer, a
+-- tail pointer, and a live element count.  Unlike `queue_array_based.lean`,
+-- `head` and `tail` wrap back to zero when they reach the capacity.  We model
+-- that wraparound with a small `NextIndex` function instead of `mod`, so the
+-- verification conditions remain simple arithmetic plus map-update reasoning.
+private def circularQueuePgm :=
+#strata
+program Boole;
+
+type Array := Map int int;
+
+// `NextIndex(i, n)` is `(i + 1) mod n`, axiomatized without using `mod`.
+function NextIndex(i : int, n : int) : int;
+
+axiom (∀ i : int, n : int ::
+  n > 0 && 0 <= i && i < n ==> 0 <= NextIndex(i, n) && NextIndex(i, n) < n);
+axiom (∀ n : int :: n > 0 ==> NextIndex(n - 1, n) == 0);
+axiom (∀ i : int, n : int ::
+  n > 0 && 0 <= i && i + 1 < n ==> NextIndex(i, n) == i + 1);

I just pushed the comment! Thanks

arademaker arademaker commented on Jun 11, 2026 19:57 UTC
Contributor

@Robertboy18 can you solve the conflicts? We don't have too much constraints to accept this PR in the Boole-sandbox branch, it the conflict is solved.

Robertboy18 Robertboy18 commented on Aug 04, 2026 14:49 UTC
Author

@arademaker conflicts should be fixed now :) I also updated the examples to the current Boole verifier API and built all three examples locally.

Robertboy18 Robertboy18 commented on Aug 05, 2026 17:52 UTC
Author

conflicts are fixed now! the CI failure looks unrelated to this PR: the runner can’t find cvc5, and the existing Boole-sandbox runs seem to fail for the same reason. the examples build locally with cvc5 installed :)

Robertboy18 Robertboy18 commented on Nov 03, 2026 20:26 UTC
Author

Hi @arademaker! I merged the latest Boole-sandbox (Lean 4.34) into this, and the queue examples verify with cvc5. CI now passes Build and Test, after I swapped the deprecated if_pos/if_neg in bubble_sort and loop_simple. Lint still fails on missing docstrings in some older examples like MaxExample, but that's already the case on the branch, so I'm happy to fix it in a separate PR :) Could you take another look when you have a moment?

Robertboy18 Robertboy18 commented on Nov 07, 2026 00:45 UTC
Author

The last CI run got cut off by a runner shutdown during lake lint. Could someone re-run it? :)

Reviewers
Assignees
Robertboy18 Robertboy18
Labels
risk: low confidence: 86.0% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 56.8% (MEDIUM) · Higher = larger blast radius
56.8%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 86.0% · Lower = rushed or shallow review
86.0%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 8.0% · Safe to merge
8.0%