-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
decision_proceduret API with assumptions #7979
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,13 +11,21 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include "decision_procedure.h" | ||
|
||
#include <util/std_expr.h> | ||
|
||
decision_proceduret::~decision_proceduret() | ||
{ | ||
} | ||
|
||
decision_proceduret::resultt decision_proceduret::operator()() | ||
{ | ||
return dec_solve(); | ||
return dec_solve(nil_exprt()); | ||
} | ||
|
||
decision_proceduret::resultt | ||
decision_proceduret::operator()(const exprt &assumption) | ||
{ | ||
return dec_solve(assumption); | ||
} | ||
|
||
void decision_proceduret::set_to_true(const exprt &expr) | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,18 +17,19 @@ Author: Daniel Kroening, [email protected] | |
|
||
class exprt; | ||
|
||
/// An interface for a decision procedure for satisfiability problems. | ||
class decision_proceduret | ||
{ | ||
public: | ||
/// For a Boolean expression \p expr, add the constraint 'expr' if \p value | ||
/// is `true`, otherwise add 'not expr' | ||
virtual void set_to(const exprt &expr, bool value) = 0; | ||
virtual void set_to(const exprt &, bool value) = 0; | ||
|
||
/// For a Boolean expression \p expr, add the constraint 'expr' | ||
void set_to_true(const exprt &expr); | ||
void set_to_true(const exprt &); | ||
|
||
/// For a Boolean expression \p expr, add the constraint 'not expr' | ||
void set_to_false(const exprt &expr); | ||
void set_to_false(const exprt &); | ||
|
||
/// Generate a handle, which is an expression that | ||
/// has the same value as the argument in any model | ||
|
@@ -37,7 +38,7 @@ class decision_proceduret | |
/// \ref set_to. | ||
/// The returned expression may be the expression itself or a more compact | ||
/// but solver-specific representation. | ||
virtual exprt handle(const exprt &expr) = 0; | ||
virtual exprt handle(const exprt &) = 0; | ||
|
||
/// Result of running the decision procedure | ||
enum class resultt | ||
|
@@ -48,12 +49,18 @@ class decision_proceduret | |
}; | ||
|
||
/// Run the decision procedure to solve the problem | ||
/// This corresponds to SMT-LIB's check-sat. | ||
resultt operator()(); | ||
|
||
/// Run the decision procedure to solve the problem under | ||
/// the given assumption. | ||
/// This corresponds to SMT-LIB's check-sat-assuming. | ||
resultt operator()(const exprt &assumption); | ||
|
||
/// Return \p expr with variables replaced by values from satisfying | ||
/// assignment if available. | ||
/// Return `nil` if not available | ||
virtual exprt get(const exprt &expr) const = 0; | ||
virtual exprt get(const exprt &) const = 0; | ||
|
||
/// Print satisfying assignment to \p out | ||
virtual void print_assignment(std::ostream &out) const = 0; | ||
|
@@ -67,8 +74,8 @@ class decision_proceduret | |
virtual ~decision_proceduret(); | ||
|
||
protected: | ||
/// Run the decision procedure to solve the problem | ||
virtual resultt dec_solve() = 0; | ||
/// Implementation of the decision procedure. | ||
virtual resultt dec_solve(const exprt &assumption) = 0; | ||
}; | ||
|
||
/// Add Boolean constraint \p src to decision procedure \p dest | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/*******************************************************************\ | ||
|
||
Module: Unit tests for boolbvt | ||
|
||
Author: Daniel Kroening | ||
|
||
\*******************************************************************/ | ||
|
||
/// \file | ||
/// Unit tests for boolbvt | ||
|
||
#include <util/arith_tools.h> | ||
#include <util/bitvector_types.h> | ||
#include <util/cout_message.h> | ||
#include <util/namespace.h> | ||
#include <util/std_expr.h> | ||
#include <util/symbol_table.h> | ||
|
||
#include <solvers/flattening/boolbv.h> | ||
#include <solvers/sat/satcheck.h> | ||
#include <testing-utils/use_catch.h> | ||
|
||
SCENARIO("boolbvt", "[core][solvers][flattening][boolbvt]") | ||
{ | ||
console_message_handlert message_handler; | ||
message_handler.set_verbosity(0); | ||
|
||
GIVEN("A satisfiable bit-vector formula f") | ||
{ | ||
satcheckt satcheck(message_handler); | ||
symbol_tablet symbol_table; | ||
namespacet ns(symbol_table); | ||
boolbvt boolbv(ns, satcheck, message_handler); | ||
|
||
unsignedbv_typet u32(32); | ||
boolbv << equal_exprt(symbol_exprt("x", u32), from_integer(10, u32)); | ||
|
||
THEN("is indeed satisfiable") | ||
{ | ||
REQUIRE(boolbv() == decision_proceduret::resultt::D_SATISFIABLE); | ||
} | ||
THEN("is unsatisfiable under an inconsistent assumption") | ||
{ | ||
auto assumption = | ||
equal_exprt(symbol_exprt("x", u32), from_integer(11, u32)); | ||
REQUIRE( | ||
boolbv(assumption) == decision_proceduret::resultt::D_UNSATISFIABLE); | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
solvers/flattening | ||
solvers/sat | ||
testing-utils | ||
util |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My preference would be to use std::optional at the interface rather than nil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was reluctant to do so since that can't avoid copying the expression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't
const std::optional<exprt> &
do the trick?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, you'd still need to copy the expression into the optional when creating the optional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::optional< std::reference_wrapper<exprt> >
would work, but then it's getting more verbose.