Reject singleton operand lists in leftAssocOp and leftAssocOpBitVec#1110
Open
tautschnig wants to merge 3 commits intomainfrom
Open
Reject singleton operand lists in leftAssocOp and leftAssocOpBitVec#1110tautschnig wants to merge 3 commits intomainfrom
tautschnig wants to merge 3 commits intomainfrom
Conversation
Both helpers' error message already said 'expected at least two arguments', but the destructuring `let a :: as := as | throw ...` only rejected the empty list: a singleton like `.app .add [x]` or `.app .bvadd [x]` silently returned just `x`. This diverged from `Denote.leftAssoc`, which uses `let t₁ :: t₂ :: ts := ts | none` and returns `none` for fewer than two operands. Tighten the pattern to `a :: b :: as := as | throw ...` and seed the `foldl` with `mkApp2 op a b` so the helper's semantics now match the existing error message and `Denote.leftAssoc`. Empty-operand lists continue to throw with the same message as before. This affects every variadic caller: `.app .and`, `.app .or`, `.app .add`, `.app .sub`, `.app .mul`, `.app .div`, `.app .mod`, plus `.app .bvadd`, `.app .bvsub`, `.app .bvmul`, `.app .bvand`, `.app .bvor`, `.app .bvxor`. The Strata Core SMT encoder does not produce singleton applications of any of these ops (ripgrep'd across `SMTEncoder.lean`, `Factory.lean`, and `B3/Verifier/Expression.lean`: every construction passes at least two operands), so well-formed queries are unaffected. Zero-operand placeholders like `Term.app Op.and [] .bool` that appear as "unreachable" fallbacks in `SMTEncoder.lean` were already rejected by `translateTerm` before this change, and remain rejected. Regression tests in StrataTest/DL/SMT/TranslateTests.lean cover: - singleton `.app .add`, `.app .and`, `.app .bvadd`, `.app .bvand` (one per helper+typeclass combination), - empty-operand `.app .add` (unchanged behaviour), - ternary `.app .add` producing `1 + 2 + 3 = 6` (preserves left associativity past the new 2-operand seed). Each singleton-rejection test fails on the previous commit (the term silently translates to its sole operand) and passes here. Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens SMT term translation so left-associative helpers reject singleton operand lists instead of silently returning the lone operand, bringing translation behavior closer to the existing semantic model.
Changes:
- Updated
leftAssocOpandleftAssocOpBitVecto require at least two operands and seed folds with the first two translated terms. - Added regression tests for singleton rejection, preserved empty-list rejection, and a multi-operand happy path.
- Kept existing error messages and overall left-associative folding behavior for valid inputs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
Strata/DL/SMT/Translate.lean |
Tightens operand-pattern matching in the left-associative SMT translation helpers. |
StrataTest/DL/SMT/TranslateTests.lean |
Adds regression coverage for singleton/empty operand errors and valid multi-operand translation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Addresses the review comment on PR #1110. `leftAssocOp mkIntMod as` accepted any arity ≥ 2 and silently lowered e.g. `.app .mod [10, 3, 2]` to `(10 % 3) % 2`. This diverged from: - the SMT-Lib `Ints` theory, which defines `mod` as strictly binary, - `Denote.denoteTerm`, which pattern-matches `.app .mod [x, y]` only (and returns `none` for any other arity), - `Factory.intMod`, which only constructs `.app .mod [t₁, t₂]`. None of the other variadic callers of `leftAssocOp` / `leftAssocOpBitVec` share this problem: `.add`/`.sub`/`.mul`/`.div` and the bitvec analogues are all treated as n-ary by `Denote.lean`, sometimes intentionally stretching past the SMT-Lib spec (see the inline comments in `Denote` around `bvsub` and `bvxor`). So the fix is scoped to `.mod`. Replace the `leftAssocOp` delegation with a dedicated binary arm and an explicit catch-all arm that produces an actionable error for all other arities (unary / zero-ary / 3+-ary in one message), preferred over letting malformed `mod` fall through to the generic "unsupported term" branch. Regression tests added: - binary `10 % 3 = 1` (happy path, unchanged semantically), - ternary `.app .mod [10, 3, 2]` — now throws instead of silently producing `10 % 3 % 2 = 1`. The ternary test fails on the previous commit on this branch (and on `origin/main`) and passes here; the binary test passes in both. Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Contributor
Author
|
@keyboardDrummer-bot Please resolve git conflicts. |
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.
Both helpers' error message already said 'expected at least two arguments', but the destructuring
let a :: as := as | throw ...only rejected the empty list: a singleton like.app .add [x]or.app .bvadd [x]silently returned justx. This diverged fromDenote.leftAssoc, which useslet t₁ :: t₂ :: ts := ts | noneand returnsnonefor fewer than two operands.Tighten the pattern to
a :: b :: as := as | throw ...and seed thefoldlwithmkApp2 op a bso the helper's semantics now match the existing error message andDenote.leftAssoc. Empty-operand lists continue to throw with the same message as before.This affects every variadic caller:
.app .and,.app .or,.app .add,.app .sub,.app .mul,.app .div,.app .mod, plus.app .bvadd,.app .bvsub,.app .bvmul,.app .bvand,.app .bvor,.app .bvxor. The Strata Core SMT encoder does not produce singleton applications of any of these ops (ripgrep'd acrossSMTEncoder.lean,Factory.lean, andB3/Verifier/Expression.lean: every construction passes at least two operands), so well-formed queries are unaffected. Zero-operand placeholders likeTerm.app Op.and [] .boolthat appear as "unreachable" fallbacks inSMTEncoder.leanwere already rejected bytranslateTermbefore this change, and remain rejected.Regression tests in StrataTest/DL/SMT/TranslateTests.lean cover:
.app .add,.app .and,.app .bvadd,.app .bvand(one per helper+typeclass combination),.app .add(unchanged behaviour),.app .addproducing1 + 2 + 3 = 6(preserves left associativity past the new 2-operand seed).Each singleton-rejection test fails on the previous commit (the term silently translates to its sole operand) and passes here.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.