-
Notifications
You must be signed in to change notification settings - Fork 274
Cleanup boolbv quantifier instantiation #3926
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
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 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CORE | ||
main.c | ||
--cover location | ||
^\*\* 1 of 46 covered \(2.2%\) | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
-- | ||
All assertions are unreachable as each of the __CPROVER_assume evaluate to false | ||
(!exists i. i>=0 && i<2 ==> ... is equivalent to forall i. i>=0 && i<2 && ..., | ||
where neither i>=0 nor i<2 is actually true for all values of i). |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
KNOWNBUG | ||
CORE | ||
main.c | ||
|
||
^\*\* Results:$ | ||
|
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
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
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
KNOWNBUG | ||
CORE | ||
main.c | ||
|
||
^\*\* Results:$ | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,28 +9,23 @@ Author: Daniel Kroening, [email protected] | |
#include "boolbv.h" | ||
|
||
#include <util/arith_tools.h> | ||
#include <util/expr_util.h> | ||
#include <util/invariant.h> | ||
#include <util/optional.h> | ||
#include <util/replace_expr.h> | ||
#include <util/simplify_expr.h> | ||
|
||
/// A method to detect equivalence between experts that can contain typecast | ||
bool expr_eq(const exprt &expr1, const exprt &expr2) | ||
static bool expr_eq(const exprt &expr1, const exprt &expr2) | ||
{ | ||
exprt e1=expr1, e2=expr2; | ||
if(expr1.id()==ID_typecast) | ||
e1=expr1.op0(); | ||
if(expr2.id()==ID_typecast) | ||
e2=expr2.op0(); | ||
return e1==e2; | ||
return skip_typecast(expr1) == skip_typecast(expr2); | ||
} | ||
|
||
/// To obtain the min value for the quantifier variable of the specified | ||
/// forall/exists operator. The min variable is in the form of "!(var_expr > | ||
/// constant)". | ||
exprt get_quantifier_var_min( | ||
const exprt &var_expr, | ||
const exprt &quantifier_expr) | ||
static exprt | ||
get_quantifier_var_min(const exprt &var_expr, const exprt &quantifier_expr) | ||
{ | ||
PRECONDITION(quantifier_expr.id() == ID_or || quantifier_expr.id() == ID_and); | ||
|
||
|
@@ -75,9 +70,8 @@ exprt get_quantifier_var_min( | |
|
||
/// To obtain the max value for the quantifier variable of the specified | ||
/// forall/exists operator. | ||
exprt get_quantifier_var_max( | ||
const exprt &var_expr, | ||
const exprt &quantifier_expr) | ||
static exprt | ||
get_quantifier_var_max(const exprt &var_expr, const exprt &quantifier_expr) | ||
{ | ||
PRECONDITION(quantifier_expr.id() == ID_or || quantifier_expr.id() == ID_and); | ||
exprt res = false_exprt(); | ||
|
@@ -132,27 +126,25 @@ exprt get_quantifier_var_max( | |
return res; | ||
} | ||
|
||
optionalt<exprt> | ||
static optionalt<exprt> | ||
instantiate_quantifier(const quantifier_exprt &expr, const namespacet &ns) | ||
{ | ||
PRECONDITION(expr.id() == ID_forall || expr.id() == ID_exists); | ||
martin-cs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const symbol_exprt &var_expr = expr.symbol(); | ||
|
||
/** | ||
* We need to rewrite the forall/exists quantifier into | ||
* an OR/AND expr. | ||
**/ | ||
|
||
const exprt &re = simplify_expr(expr.where(), ns); | ||
const exprt re = simplify_expr(expr.where(), ns); | ||
|
||
if(re.is_true() || re.is_false()) | ||
{ | ||
return re; | ||
} | ||
|
||
const exprt &min_i = get_quantifier_var_min(var_expr, re); | ||
const exprt &max_i = get_quantifier_var_max(var_expr, re); | ||
const exprt min_i = get_quantifier_var_min(var_expr, re); | ||
const exprt max_i = get_quantifier_var_max(var_expr, re); | ||
|
||
if(min_i.is_false() || max_i.is_false()) | ||
return nullopt; | ||
|
@@ -175,50 +167,57 @@ instantiate_quantifier(const quantifier_exprt &expr, const namespacet &ns) | |
|
||
if(expr.id()==ID_forall) | ||
{ | ||
return conjunction(expr_insts); | ||
// maintain the domain constraint if it isn't guaranteed by the | ||
// instantiations (for a disjunction the domain constraint is implied by the | ||
// instantiations) | ||
if(re.id() == ID_and) | ||
{ | ||
expr_insts.push_back(binary_predicate_exprt( | ||
var_expr, ID_gt, from_integer(lb, var_expr.type()))); | ||
expr_insts.push_back(binary_predicate_exprt( | ||
var_expr, ID_le, from_integer(ub, var_expr.type()))); | ||
} | ||
return simplify_expr(conjunction(expr_insts), ns); | ||
} | ||
else if(expr.id() == ID_exists) | ||
{ | ||
return disjunction(expr_insts); | ||
// maintain the domain constraint if it isn't trivially satisfied by the | ||
// instantiations (for a conjunction the instantiations are stronger | ||
// constraints) | ||
if(re.id() == ID_or) | ||
{ | ||
expr_insts.push_back(binary_predicate_exprt( | ||
var_expr, ID_gt, from_integer(lb, var_expr.type()))); | ||
expr_insts.push_back(binary_predicate_exprt( | ||
var_expr, ID_le, from_integer(ub, var_expr.type()))); | ||
} | ||
return simplify_expr(disjunction(expr_insts), ns); | ||
} | ||
|
||
UNREACHABLE; | ||
return nullopt; | ||
} | ||
|
||
literalt boolbvt::convert_quantifier(const quantifier_exprt &src) | ||
{ | ||
PRECONDITION(src.id() == ID_forall || src.id() == ID_exists); | ||
|
||
quantifier_exprt expr(src); | ||
const auto res = instantiate_quantifier(expr, ns); | ||
const auto res = instantiate_quantifier(src, ns); | ||
|
||
if(!res) | ||
{ | ||
return SUB::convert_rest(src); | ||
} | ||
|
||
quantifiert quantifier; | ||
quantifier.expr = *res; | ||
quantifier_list.push_back(quantifier); | ||
if(res) | ||
return convert_bool(*res); | ||
|
||
literalt l=prop.new_variable(); | ||
quantifier_list.back().l=l; | ||
// we failed to instantiate here, need to pass to post-processing | ||
quantifier_list.emplace_back(quantifiert(src, prop.new_variable())); | ||
|
||
return l; | ||
return quantifier_list.back().l; | ||
} | ||
|
||
void boolbvt::post_process_quantifiers() | ||
{ | ||
std::set<exprt> instances; | ||
|
||
if(quantifier_list.empty()) | ||
return; | ||
|
||
for(auto it=quantifier_list.begin(); | ||
it!=quantifier_list.end(); | ||
++it) | ||
{ | ||
prop.set_equal(convert_bool(it->expr), it->l); | ||
} | ||
// we do not yet have any elaborate post-processing | ||
for(const auto &q : quantifier_list) | ||
conversion_failed(q.expr); | ||
} |
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.
I like it already!