Skip to content

Reject singleton operand lists in leftAssocOp and leftAssocOpBitVec#1110

Open
tautschnig wants to merge 3 commits intomainfrom
fix-smt-translate-leftassocop-singleton
Open

Reject singleton operand lists in leftAssocOp and leftAssocOpBitVec#1110
tautschnig wants to merge 3 commits intomainfrom
fix-smt-translate-leftassocop-singleton

Conversation

@tautschnig
Copy link
Copy Markdown
Contributor

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.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 leftAssocOp and leftAssocOpBitVec to 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.

Comment thread Strata/DL/SMT/Translate.lean
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>
@tautschnig
Copy link
Copy Markdown
Contributor Author

@keyboardDrummer-bot Please resolve git conflicts.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants