Skip to content

Draft: Extend Truth based Solver/Prover Assertions#625

Open
baierd wants to merge 3 commits intomasterfrom
extend_smt_assertions
Open

Draft: Extend Truth based Solver/Prover Assertions#625
baierd wants to merge 3 commits intomasterfrom
extend_smt_assertions

Conversation

@baierd
Copy link
Copy Markdown
Contributor

@baierd baierd commented Mar 24, 2026

I also noticed that it is helpful to have a assertThat... implementation that actually uses multiple assertions, e.g. for HORN solving. A conjunction of multiple formulas is no equal to asserting them on their own for Z3! This PR is intended to discuss and implement extensions to our current API that only allows the assertion and solving/comparing of a single BooleanFormula.

Note: the current implementation is based on a Collection of BooleanFormulas. Instead, a conjunction could automatically be broken up using our conjunction flattening API. But i decided against this, as we might split formulas that we don't want to assert individually, and a Collection based approach seemed more easy to debug/maintain.

Also, it is most likely a good idea to reflect how we add the assertions to the prover in the API name, but since the ending method, e.g. isSatisfiable(), is actually controlling this, it seems weird to write isSatisfiableAssertedIndiviually() or so. @kfriedberger do you know whether there is API to add in between? Something like assertThatFormulas(collection).addedAsProverConstraintsIndividually().isSatisfiable()?

Ideas:

  • assertThatFormulaWithTimeout
  • assertThatFormulaWithConfiguration

baierd added 3 commits March 21, 2026 19:37
…tension based on Truth that allows for more than 1 BooleanFormula argument, intended for multiple assertions
… multi BooleanFormula argument methods in some existing test-cases
@baierd baierd self-assigned this Mar 24, 2026
Copy link
Copy Markdown
Member

@kfriedberger kfriedberger left a comment

Choose a reason for hiding this comment

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

The idea to have a improved subject implementation is nice. I assume that the class is used in user-application, too, so we need to be carefully with API design.

We could support chained usage like:

  • assertThatFormulas(...).asConjunction().isSatisfiable().withModel(...)
  • assertThatFormulas(...).asConjunction().isSatisfiable().withModelAssignment(x, 3).withModelAssignment(y, 5)
  • assertThatFormulas(...).asConjunction().implies(...)
  • assertThatFormulas(...).asDisjunction().implies(...)
  • assertThatFormulas(...).asDisjunction().withTimeout(30).implies(...)
  • ...

Each command should read like natural language, and avoid technical parts.

I have not yet tried more examples, so I will not yet approve.

constraints.add(imgr.lessOrEquals(symbol, four));
}
assertThatFormula(bmgr.and(imgr.distinct(symbols), bmgr.and(constraints))).isSatisfiable();
assertThatFormulas(imgr.distinct(symbols), bmgr.and(constraints)).isSatisfiable();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I find that not very readable, because it seems to be a broken sentence:
assert that formulas A, B, C is satisfiable.
As a developer, I would need to look up whether one, any, all, or the conjunction of all formulas is actually checked.

Maybe find a new name for the method, such as assertThatConjunctionOf(...).isSatisfiable().

*/
protected final BooleanFormulaSubjects assertThatFormulas(
BooleanFormula formula1, BooleanFormula formula2) {
return assertThatFormulas(ImmutableList.of(formula1, formula2));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we need the case for 2/3 formulas explicitly? Java allows var-args. Just use them.


/**
* Use this for checking assertions about the conjunction of {@link BooleanFormula}s with Truth:
* <code>assertThatFormulas(Collection).are...()</code>.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

docu: is or are?

smgr.prefix(prefix, concat),
smgr.suffix(suffix, concat),
imgr.equal(smgr.length(concat), imgr.add(smgr.length(prefix), smgr.length(suffix))))
.imply(smgr.equal(concat, smgr.concat(prefix, suffix)));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The method imply points the developer towards any of those formulas implies, instead of conjunction of formula implies. Naming is not optimal here.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants