-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TG-592 Implemented the correct instantiation procedure for not contai…
…ns constraints The method of insantiating not contains constraints is correct, see TG-591. This involved a localized change to `string_constraint_instantiation.cpp:instantiate_not_contains`, but also involved the activation of counter-examples in `string_refinementt`. The reason for this is that the new (correct) instances are relatively weak, and the solver will end up with an empty index set. The current behavior of returning SAT in this case is incorrect, and will be fixed shortly by TG-672. Additionally, the choice of indices at which to instantiate not contains constraints has been changed to be more sensible. Finally, the relevant unit tests have been updated.
- Loading branch information
Showing
5 changed files
with
101 additions
and
83 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,61 +11,46 @@ Author: Jesse Sigal, [email protected] | |
|
||
#include <solvers/refinement/string_constraint_instantiation.h> | ||
|
||
#include <solvers/refinement/string_constraint.h> | ||
#include <solvers/refinement/string_constraint_generator.h> | ||
#include <solvers/refinement/string_refinement.h> | ||
|
||
/// Instantiates a quantified formula representing `not_contains` by | ||
/// substituting the quantifiers and generating axioms. | ||
/// \related string_refinementt | ||
/// \param [in] axiom: the axiom to instantiate | ||
/// \param [in] index_set0: the index set for `axiom.s0()` | ||
/// \param [in] index_set1: the index set for `axiom.s1()` | ||
/// \param [in] index_pairs: the pairs of indices to at which to instantiate | ||
/// \param [in] generator: generator to be used to get `axiom`'s witness | ||
/// \return the lemmas produced through instantiation | ||
std::vector<exprt> instantiate_not_contains( | ||
const string_not_contains_constraintt &axiom, | ||
const std::set<exprt> &index_set0, | ||
const std::set<exprt> &index_set1, | ||
const std::set<std::pair<exprt, exprt>> &index_pairs, | ||
const string_constraint_generatort &generator) | ||
{ | ||
std::vector<exprt> lemmas; | ||
|
||
const string_exprt s0=to_string_expr(axiom.s0()); | ||
const string_exprt s1=to_string_expr(axiom.s1()); | ||
|
||
for(const auto &i0 : index_set0) | ||
for(const auto &i1 : index_set1) | ||
{ | ||
const minus_exprt val(i0, i1); | ||
const exprt witness=generator.get_witness_of(axiom, val); | ||
const and_exprt prem_and_is_witness( | ||
axiom.premise(), | ||
equal_exprt(witness, i1)); | ||
|
||
const not_exprt differ(equal_exprt(s0[i0], s1[i1])); | ||
const implies_exprt lemma(prem_and_is_witness, differ); | ||
lemmas.push_back(lemma); | ||
|
||
// we put bounds on the witnesses: | ||
// 0 <= v <= |s0| - |s1| ==> 0 <= v+w[v] < |s0| && 0 <= w[v] < |s1| | ||
const exprt zero=from_integer(0, val.type()); | ||
const binary_relation_exprt c1(zero, ID_le, plus_exprt(val, witness)); | ||
const binary_relation_exprt c2( | ||
s0.length(), ID_gt, plus_exprt(val, witness)); | ||
const binary_relation_exprt c3(s1.length(), ID_gt, witness); | ||
const binary_relation_exprt c4(zero, ID_le, witness); | ||
|
||
const minus_exprt diff(s0.length(), s1.length()); | ||
|
||
const and_exprt premise( | ||
binary_relation_exprt(zero, ID_le, val), | ||
binary_relation_exprt(diff, ID_ge, val)); | ||
const implies_exprt witness_bounds( | ||
premise, | ||
and_exprt(and_exprt(c1, c2), and_exprt(c3, c4))); | ||
lemmas.push_back(witness_bounds); | ||
} | ||
const string_exprt &s0=to_string_expr(axiom.s0()); | ||
const string_exprt &s1=to_string_expr(axiom.s1()); | ||
|
||
for(const auto &pair : index_pairs) | ||
{ | ||
// We have s0[x+f(x)] and s1[f(x)], so to have i0 indexing s0 and i1 | ||
// indexing s1, we need x = i0 - i1 and f(i0 - i1) = f(x) = i1. | ||
const exprt &i0=pair.first; | ||
const exprt &i1=pair.second; | ||
const minus_exprt val(i0, i1); | ||
const and_exprt universal_bound( | ||
binary_relation_exprt(axiom.univ_lower_bound(), ID_le, val), | ||
binary_relation_exprt(axiom.univ_upper_bound(), ID_gt, val)); | ||
const exprt f=generator.get_witness_of(axiom, val); | ||
const equal_exprt relevancy(f, i1); | ||
const and_exprt premise(relevancy, axiom.premise(), universal_bound); | ||
|
||
const notequal_exprt differ(s0[i0], s1[i1]); | ||
const and_exprt existential_bound( | ||
binary_relation_exprt(axiom.exists_lower_bound(), ID_le, i1), | ||
binary_relation_exprt(axiom.exists_upper_bound(), ID_gt, i1)); | ||
const and_exprt body(differ, existential_bound); | ||
|
||
const implies_exprt lemma(premise, body); | ||
lemmas.push_back(lemma); | ||
} | ||
|
||
return lemmas; | ||
} |
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,8 +17,7 @@ Author: Jesse Sigal, [email protected] | |
|
||
std::vector<exprt> instantiate_not_contains( | ||
const string_not_contains_constraintt &axiom, | ||
const std::set<exprt> &index_set0, | ||
const std::set<exprt> &index_set1, | ||
const std::set<std::pair<exprt, exprt>> &index_pairs, | ||
const string_constraint_generatort &generator); | ||
|
||
#endif // CPROVER_SOLVERS_REFINEMENT_STRING_CONSTRAINT_INSTANTIATION_H |
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