|
29 | 29 | #include <util/simplify_expr.h>
|
30 | 30 | #include <solvers/sat/satcheck.h>
|
31 | 31 | #include <solvers/refinement/string_refinement_invariant.h>
|
| 32 | +#include <solvers/refinement/string_constraint_instantiation.h> |
32 | 33 | #include <langapi/language_util.h>
|
33 | 34 | #include <java_bytecode/java_types.h>
|
34 | 35 |
|
@@ -606,8 +607,8 @@ decision_proceduret::resultt string_refinementt::dec_solve()
|
606 | 607 | for(unsigned i=0; i<not_contains_axioms.size(); i++)
|
607 | 608 | {
|
608 | 609 | debug()<< "constraint " << i << eom;
|
609 |
| - std::list<exprt> lemmas; |
610 |
| - instantiate_not_contains(not_contains_axioms[i], lemmas); |
| 610 | + const std::vector<exprt> lemmas= |
| 611 | + instantiate_not_contains(not_contains_axioms[i]); |
611 | 612 | for(const exprt &lemma : lemmas)
|
612 | 613 | add_lemma(lemma);
|
613 | 614 | }
|
@@ -1603,60 +1604,23 @@ exprt string_refinementt::instantiate(
|
1603 | 1604 | return implies_exprt(bounds, instance);
|
1604 | 1605 | }
|
1605 | 1606 |
|
1606 |
| -/// instantiate a quantified formula representing `not_contains` by substituting |
1607 |
| -/// the quantifiers and generating axioms |
1608 |
| -/// \par parameters: a quantified formula representing `not_contains`, and a |
1609 |
| -/// list to which to add the created lemmas to |
1610 |
| -void string_refinementt::instantiate_not_contains( |
1611 |
| - const string_not_contains_constraintt &axiom, std::list<exprt> &new_lemmas) |
| 1607 | +/// Instantiates a quantified formula representing `not_contains` by |
| 1608 | +/// substituting the quantifiers and generating axioms. |
| 1609 | +/// \param [in] axiom: the axiom to instantiate |
| 1610 | +/// \return the lemmas produced through instantiation |
| 1611 | +std::vector<exprt> string_refinementt::instantiate_not_contains( |
| 1612 | + const string_not_contains_constraintt &axiom) |
1612 | 1613 | {
|
1613 |
| - exprt s0=axiom.s0(); |
1614 |
| - exprt s1=axiom.s1(); |
| 1614 | + const string_exprt s0=to_string_expr(axiom.s0()); |
| 1615 | + const string_exprt s1=to_string_expr(axiom.s1()); |
1615 | 1616 |
|
1616 | 1617 | debug() << "instantiate not contains " << from_expr(ns, "", s0) << " : "
|
1617 | 1618 | << from_expr(ns, "", s1) << eom;
|
1618 |
| - expr_sett index_set0=index_set[to_string_expr(s0).content()]; |
1619 |
| - expr_sett index_set1=index_set[to_string_expr(s1).content()]; |
| 1619 | + const expr_sett index_set0=index_set[s0.content()]; |
| 1620 | + const expr_sett index_set1=index_set[s1.content()]; |
1620 | 1621 |
|
1621 |
| - for(auto it0 : index_set0) |
1622 |
| - for(auto it1 : index_set1) |
1623 |
| - { |
1624 |
| - debug() << from_expr(ns, "", it0) << " : " << from_expr(ns, "", it1) |
1625 |
| - << eom; |
1626 |
| - exprt val=minus_exprt(it0, it1); |
1627 |
| - exprt witness=generator.get_witness_of(axiom, val); |
1628 |
| - and_exprt prem_and_is_witness( |
1629 |
| - axiom.premise(), |
1630 |
| - equal_exprt(witness, it1)); |
1631 |
| - |
1632 |
| - not_exprt differ( |
1633 |
| - equal_exprt( |
1634 |
| - to_string_expr(s0)[it0], |
1635 |
| - to_string_expr(s1)[it1])); |
1636 |
| - exprt lemma=implies_exprt(prem_and_is_witness, differ); |
1637 |
| - |
1638 |
| - new_lemmas.push_back(lemma); |
1639 |
| - // we put bounds on the witnesses: |
1640 |
| - // 0 <= v <= |s0| - |s1| ==> 0 <= v+w[v] < |s0| && 0 <= w[v] < |s1| |
1641 |
| - exprt zero=from_integer(0, val.type()); |
1642 |
| - binary_relation_exprt c1(zero, ID_le, plus_exprt(val, witness)); |
1643 |
| - binary_relation_exprt c2 |
1644 |
| - (to_string_expr(s0).length(), ID_gt, plus_exprt(val, witness)); |
1645 |
| - binary_relation_exprt c3(to_string_expr(s1).length(), ID_gt, witness); |
1646 |
| - binary_relation_exprt c4(zero, ID_le, witness); |
1647 |
| - |
1648 |
| - minus_exprt diff( |
1649 |
| - to_string_expr(s0).length(), |
1650 |
| - to_string_expr(s1).length()); |
1651 |
| - |
1652 |
| - and_exprt premise( |
1653 |
| - binary_relation_exprt(zero, ID_le, val), |
1654 |
| - binary_relation_exprt(diff, ID_ge, val)); |
1655 |
| - exprt witness_bounds=implies_exprt( |
1656 |
| - premise, |
1657 |
| - and_exprt(and_exprt(c1, c2), and_exprt(c3, c4))); |
1658 |
| - new_lemmas.push_back(witness_bounds); |
1659 |
| - } |
| 1622 | + return ::instantiate_not_contains( |
| 1623 | + axiom, index_set0, index_set1, generator); |
1660 | 1624 | }
|
1661 | 1625 |
|
1662 | 1626 | /// replace array-lists by 'with' expressions
|
|
0 commit comments