mirror of
https://github.com/Z3Prover/z3
synced 2025-07-19 10:52:02 +00:00
Merge branch 'master' of https://github.com/Z3Prover/z3
This commit is contained in:
commit
3edf147213
11 changed files with 932 additions and 567 deletions
|
@ -111,8 +111,8 @@ namespace datalog {
|
|||
|
||||
void filter_interpreted(app* cond) {
|
||||
rational one(1), mone(-1);
|
||||
expr* e1, *e2, *en;
|
||||
var* v, *w;
|
||||
expr* e1 = 0, *e2 = 0, *en = 0;
|
||||
var* v = 0, *w = 0;
|
||||
rational n1, n2;
|
||||
expr_ref_vector conjs(m);
|
||||
flatten_and(cond, conjs);
|
||||
|
|
|
@ -284,7 +284,7 @@ namespace smt {
|
|||
}
|
||||
|
||||
lbool reduce_cond(model_ref& model, expr* e) {
|
||||
expr* e1, *e2;
|
||||
expr* e1 = 0, *e2 = 0;
|
||||
if (m.is_eq(e, e1, e2) && m_array_util.is_as_array(e1) && m_array_util.is_as_array(e2)) {
|
||||
if (e1 == e2) {
|
||||
return l_true;
|
||||
|
|
|
@ -689,7 +689,7 @@ namespace smt {
|
|||
SASSERT(!ctx().b_internalized(atom));
|
||||
bool_var bv = ctx().mk_bool_var(atom);
|
||||
ctx().set_var_theory(bv, get_id());
|
||||
expr* n1, *n2;
|
||||
expr* n1 = 0, *n2 = 0;
|
||||
rational r;
|
||||
lra_lp::bound_kind k;
|
||||
theory_var v = null_theory_var;
|
||||
|
@ -721,7 +721,7 @@ namespace smt {
|
|||
SASSERT(!ctx().b_internalized(atom));
|
||||
bool_var bv = ctx().mk_bool_var(atom);
|
||||
ctx().set_var_theory(bv, get_id());
|
||||
expr* n1, *n2;
|
||||
expr* n1 = 0, *n2 = 0;
|
||||
rational r;
|
||||
lra_lp::bound_kind k;
|
||||
theory_var v = null_theory_var;
|
||||
|
@ -862,7 +862,7 @@ namespace smt {
|
|||
|
||||
void relevant_eh(app* n) {
|
||||
TRACE("arith", tout << mk_pp(n, m) << "\n";);
|
||||
expr* n1, *n2;
|
||||
expr* n1 = 0, *n2 = 0;
|
||||
if (a.is_mod(n, n1, n2))
|
||||
mk_idiv_mod_axioms(n1, n2);
|
||||
else if (a.is_rem(n, n1, n2))
|
||||
|
|
|
@ -18,6 +18,7 @@ Author:
|
|||
|
||||
#include "tactic/bv/bv_bounds_tactic.h"
|
||||
#include "tactic/core/ctx_simplify_tactic.h"
|
||||
#include "tactic/core/dom_simplify_tactic.h"
|
||||
#include "ast/bv_decl_plugin.h"
|
||||
#include "ast/ast_pp.h"
|
||||
#include <climits>
|
||||
|
@ -29,7 +30,7 @@ static uint64 uMaxInt(unsigned sz) {
|
|||
|
||||
namespace {
|
||||
|
||||
struct interval {
|
||||
struct interval {
|
||||
// l < h: [l, h]
|
||||
// l > h: [0, h] U [l, UMAX_INT]
|
||||
uint64 l, h;
|
||||
|
@ -70,11 +71,13 @@ struct interval {
|
|||
if (is_wrapped()) {
|
||||
// l >= b.l >= b.h >= h
|
||||
return b.is_wrapped() && h <= b.h && l >= b.l;
|
||||
} else if (b.is_wrapped()) {
|
||||
}
|
||||
else if (b.is_wrapped()) {
|
||||
// b.l > b.h >= h >= l
|
||||
// h >= l >= b.l > b.h
|
||||
return h <= b.h || l >= b.l;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
//
|
||||
return l >= b.l && h <= b.h;
|
||||
}
|
||||
|
@ -103,7 +106,8 @@ struct interval {
|
|||
} else {
|
||||
return b.intersect(*this, result);
|
||||
}
|
||||
} else if (b.is_wrapped()) {
|
||||
}
|
||||
else if (b.is_wrapped()) {
|
||||
// ... b.h ... l ... h ... b.l ..
|
||||
if (h < b.l && l > b.h) {
|
||||
return false;
|
||||
|
@ -146,24 +150,24 @@ struct interval {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
#ifdef _TRACE
|
||||
std::ostream& operator<<(std::ostream& o, const interval& I) {
|
||||
std::ostream& operator<<(std::ostream& o, const interval& I) {
|
||||
o << "[" << I.l << ", " << I.h << "]";
|
||||
return o;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
struct undo_bound {
|
||||
struct undo_bound {
|
||||
expr* e;
|
||||
interval b;
|
||||
bool fresh;
|
||||
undo_bound(expr* e, const interval& b, bool fresh) : e(e), b(b), fresh(fresh) {}
|
||||
};
|
||||
};
|
||||
|
||||
class bv_bounds_simplifier : public ctx_simplify_tactic::simplifier {
|
||||
class bv_bounds_simplifier : public ctx_simplify_tactic::simplifier {
|
||||
typedef obj_map<expr, interval> map;
|
||||
typedef obj_map<expr, bool> expr_set;
|
||||
typedef obj_map<expr, unsigned> expr_cnt;
|
||||
|
@ -188,7 +192,7 @@ class bv_bounds_simplifier : public ctx_simplify_tactic::simplifier {
|
|||
|
||||
bool is_bound(expr *e, expr*& v, interval& b) const {
|
||||
uint64 n;
|
||||
expr *lhs, *rhs;
|
||||
expr *lhs = 0, *rhs = 0;
|
||||
unsigned sz;
|
||||
|
||||
if (m_bv.is_bv_ule(e, lhs, rhs)) {
|
||||
|
@ -204,7 +208,8 @@ class bv_bounds_simplifier : public ctx_simplify_tactic::simplifier {
|
|||
v = lhs;
|
||||
return true;
|
||||
}
|
||||
} else if (m_bv.is_bv_sle(e, lhs, rhs)) {
|
||||
}
|
||||
else if (m_bv.is_bv_sle(e, lhs, rhs)) {
|
||||
if (is_number(lhs, n, sz)) { // C sle x <=> x sge C
|
||||
if (m_bv.is_numeral(rhs))
|
||||
return false;
|
||||
|
@ -293,7 +298,7 @@ class bv_bounds_simplifier : public ctx_simplify_tactic::simplifier {
|
|||
}
|
||||
#endif
|
||||
|
||||
public:
|
||||
public:
|
||||
bv_bounds_simplifier(ast_manager& m, params_ref const& p) : m(m), m_params(p), m_bv(m) {
|
||||
updt_params(p);
|
||||
}
|
||||
|
@ -526,10 +531,284 @@ public:
|
|||
virtual unsigned scope_level() const {
|
||||
return m_scopes.size();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
class dom_bv_bounds_simplifier : public dom_simplifier {
|
||||
typedef obj_map<expr, interval> map;
|
||||
typedef obj_map<expr, bool> expr_set;
|
||||
typedef obj_map<expr, unsigned> expr_cnt;
|
||||
|
||||
ast_manager& m;
|
||||
params_ref m_params;
|
||||
bool m_propagate_eq;
|
||||
bv_util m_bv;
|
||||
vector<undo_bound> m_scopes;
|
||||
map m_bound;
|
||||
svector<expr_set*> m_expr_vars;
|
||||
svector<expr_cnt*> m_bound_exprs;
|
||||
|
||||
bool is_number(expr *e, uint64& n, unsigned& sz) const {
|
||||
rational r;
|
||||
if (m_bv.is_numeral(e, r, sz) && sz <= 64) {
|
||||
n = r.get_uint64();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool is_bound(expr *e, expr*& v, interval& b) const {
|
||||
uint64 n;
|
||||
expr *lhs = 0, *rhs = 0;
|
||||
unsigned sz = 0;
|
||||
|
||||
if (m_bv.is_bv_ule(e, lhs, rhs)) {
|
||||
if (is_number(lhs, n, sz)) { // C ule x <=> x uge C
|
||||
if (m_bv.is_numeral(rhs))
|
||||
return false;
|
||||
b = interval(n, uMaxInt(sz), sz, true);
|
||||
v = rhs;
|
||||
return true;
|
||||
}
|
||||
if (is_number(rhs, n, sz)) { // x ule C
|
||||
b = interval(0, n, sz, true);
|
||||
v = lhs;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (m_bv.is_bv_sle(e, lhs, rhs)) {
|
||||
if (is_number(lhs, n, sz)) { // C sle x <=> x sge C
|
||||
if (m_bv.is_numeral(rhs))
|
||||
return false;
|
||||
b = interval(n, (1ull << (sz-1)) - 1, sz, true);
|
||||
v = rhs;
|
||||
return true;
|
||||
}
|
||||
if (is_number(rhs, n, sz)) { // x sle C
|
||||
b = interval(1ull << (sz-1), n, sz, true);
|
||||
v = lhs;
|
||||
return true;
|
||||
}
|
||||
} else if (m.is_eq(e, lhs, rhs)) {
|
||||
if (is_number(lhs, n, sz)) {
|
||||
if (m_bv.is_numeral(rhs))
|
||||
return false;
|
||||
b = interval(n, n, sz, true);
|
||||
v = rhs;
|
||||
return true;
|
||||
}
|
||||
if (is_number(rhs, n, sz)) {
|
||||
b = interval(n, n, sz, true);
|
||||
v = lhs;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
dom_bv_bounds_simplifier(ast_manager& m, params_ref const& p) : m(m), m_params(p), m_bv(m) {
|
||||
updt_params(p);
|
||||
}
|
||||
|
||||
virtual void updt_params(params_ref const & p) {
|
||||
m_propagate_eq = p.get_bool("propagate_eq", false);
|
||||
}
|
||||
|
||||
static void get_param_descrs(param_descrs& r) {
|
||||
r.insert("propagate-eq", CPK_BOOL, "(default: false) propagate equalities from inequalities");
|
||||
}
|
||||
|
||||
virtual ~dom_bv_bounds_simplifier() {
|
||||
for (unsigned i = 0, e = m_expr_vars.size(); i < e; ++i) {
|
||||
dealloc(m_expr_vars[i]);
|
||||
}
|
||||
for (unsigned i = 0, e = m_bound_exprs.size(); i < e; ++i) {
|
||||
dealloc(m_bound_exprs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool assert_expr(expr * t, bool sign) {
|
||||
while (m.is_not(t, t)) {
|
||||
sign = !sign;
|
||||
}
|
||||
|
||||
interval b;
|
||||
expr* t1;
|
||||
if (is_bound(t, t1, b)) {
|
||||
SASSERT(!m_bv.is_numeral(t1));
|
||||
if (sign)
|
||||
VERIFY(b.negate(b));
|
||||
|
||||
TRACE("bv", tout << (sign?"(not ":"") << mk_pp(t, m) << (sign ? ")" : "") << ": " << mk_pp(t1, m) << " in " << b << "\n";);
|
||||
map::obj_map_entry* e = m_bound.find_core(t1);
|
||||
if (e) {
|
||||
interval& old = e->get_data().m_value;
|
||||
interval intr;
|
||||
if (!old.intersect(b, intr))
|
||||
return false;
|
||||
if (old == intr)
|
||||
return true;
|
||||
m_scopes.insert(undo_bound(t1, old, false));
|
||||
old = intr;
|
||||
} else {
|
||||
m_bound.insert(t1, b);
|
||||
m_scopes.insert(undo_bound(t1, interval(), true));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void operator()(expr_ref& r) {
|
||||
expr* t1, * t = r;
|
||||
interval b;
|
||||
|
||||
if (m_bound.find(t, b) && b.is_singleton()) {
|
||||
r = m_bv.mk_numeral(b.l, m_bv.get_bv_size(t));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m.is_bool(t))
|
||||
return;
|
||||
|
||||
bool sign = false;
|
||||
while (m.is_not(t, t)) {
|
||||
sign = !sign;
|
||||
}
|
||||
|
||||
if (!is_bound(t, t1, b))
|
||||
return;
|
||||
|
||||
if (sign && b.tight) {
|
||||
sign = false;
|
||||
if (!b.negate(b)) {
|
||||
r = m.mk_false();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
interval ctx, intr;
|
||||
bool was_updated = true;
|
||||
if (b.is_full() && b.tight) {
|
||||
r = m.mk_true();
|
||||
} else if (m_bound.find(t1, ctx)) {
|
||||
if (ctx.implies(b)) {
|
||||
r = m.mk_true();
|
||||
}
|
||||
else if (!b.intersect(ctx, intr)) {
|
||||
r = m.mk_false();
|
||||
}
|
||||
else if (m_propagate_eq && intr.is_singleton()) {
|
||||
r = m.mk_eq(t1, m_bv.mk_numeral(rational(intr.l, rational::ui64()),
|
||||
m.get_sort(t1)));
|
||||
}
|
||||
}
|
||||
else {
|
||||
was_updated = false;
|
||||
}
|
||||
|
||||
CTRACE("bv", was_updated, tout << mk_pp(t, m) << " " << b << " (ctx: " << ctx << ") (intr: " << intr << "): " << r << "\n";);
|
||||
if (sign && was_updated)
|
||||
r = m.mk_not(r);
|
||||
}
|
||||
|
||||
// check if t contains v
|
||||
ptr_vector<expr> todo;
|
||||
bool contains(expr* t, expr* v) {
|
||||
ast_fast_mark1 mark;
|
||||
todo.push_back(t);
|
||||
while (!todo.empty()) {
|
||||
t = todo.back();
|
||||
todo.pop_back();
|
||||
if (mark.is_marked(t)) {
|
||||
continue;
|
||||
}
|
||||
if (t == v) {
|
||||
todo.reset();
|
||||
return true;
|
||||
}
|
||||
mark.mark(t);
|
||||
|
||||
if (!is_app(t)) {
|
||||
continue;
|
||||
}
|
||||
app* a = to_app(t);
|
||||
todo.append(a->get_num_args(), a->get_args());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool contains_bound(expr* t) {
|
||||
ast_fast_mark1 mark1;
|
||||
ast_fast_mark2 mark2;
|
||||
|
||||
todo.push_back(t);
|
||||
while (!todo.empty()) {
|
||||
t = todo.back();
|
||||
todo.pop_back();
|
||||
if (mark1.is_marked(t)) {
|
||||
continue;
|
||||
}
|
||||
mark1.mark(t);
|
||||
|
||||
if (!is_app(t)) {
|
||||
continue;
|
||||
}
|
||||
interval b;
|
||||
expr* e;
|
||||
if (is_bound(t, e, b)) {
|
||||
if (mark2.is_marked(e)) {
|
||||
todo.reset();
|
||||
return true;
|
||||
}
|
||||
mark2.mark(e);
|
||||
if (m_bound.contains(e)) {
|
||||
todo.reset();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
app* a = to_app(t);
|
||||
todo.append(a->get_num_args(), a->get_args());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void pop(unsigned num_scopes) {
|
||||
TRACE("bv", tout << "pop: " << num_scopes << "\n";);
|
||||
if (m_scopes.empty())
|
||||
return;
|
||||
unsigned target = m_scopes.size() - num_scopes;
|
||||
if (target == 0) {
|
||||
m_bound.reset();
|
||||
m_scopes.reset();
|
||||
return;
|
||||
}
|
||||
for (unsigned i = m_scopes.size()-1; i >= target; --i) {
|
||||
undo_bound& undo = m_scopes[i];
|
||||
SASSERT(m_bound.contains(undo.e));
|
||||
if (undo.fresh) {
|
||||
m_bound.erase(undo.e);
|
||||
} else {
|
||||
m_bound.insert(undo.e, undo.b);
|
||||
}
|
||||
}
|
||||
m_scopes.shrink(target);
|
||||
}
|
||||
|
||||
virtual dom_simplifier * translate(ast_manager & m) {
|
||||
return alloc(dom_bv_bounds_simplifier, m, m_params);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
tactic * mk_bv_bounds_tactic(ast_manager & m, params_ref const & p) {
|
||||
return clean(alloc(ctx_simplify_tactic, m, alloc(bv_bounds_simplifier, m, p), p));
|
||||
}
|
||||
|
||||
tactic * mk_dom_bv_bounds_tactic(ast_manager & m, params_ref const & p) {
|
||||
return clean(alloc(dom_simplify_tactic, m, alloc(dom_bv_bounds_simplifier, m, p), p));
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ z3_add_component(core_tactics
|
|||
ctx_simplify_tactic.cpp
|
||||
der_tactic.cpp
|
||||
distribute_forall_tactic.cpp
|
||||
dom_simplify_tactic.cpp
|
||||
elim_term_ite_tactic.cpp
|
||||
elim_uncnstr_tactic.cpp
|
||||
injectivity_tactic.cpp
|
||||
|
@ -32,6 +33,7 @@ z3_add_component(core_tactics
|
|||
ctx_simplify_tactic.h
|
||||
der_tactic.h
|
||||
distribute_forall_tactic.h
|
||||
dom_simplify_tactic.h
|
||||
elim_term_ite_tactic.h
|
||||
elim_uncnstr_tactic.h
|
||||
injectivity_tactic.h
|
||||
|
|
|
@ -83,30 +83,39 @@ expr* expr_dominators::intersect(expr* x, expr * y) {
|
|||
return x;
|
||||
}
|
||||
|
||||
void expr_dominators::compute_dominators() {
|
||||
bool expr_dominators::compute_dominators() {
|
||||
expr * e = m_root;
|
||||
SASSERT(m_doms.empty());
|
||||
m_doms.insert(e, e);
|
||||
bool change = true;
|
||||
unsigned iterations = 1;
|
||||
while (change) {
|
||||
change = false;
|
||||
SASSERT(m_post2expr.back() == e);
|
||||
for (unsigned i = 0; i < m_post2expr.size() - 1; ++i) {
|
||||
SASSERT(m_post2expr.empty() || m_post2expr.back() == e);
|
||||
for (unsigned i = 0; i + 1 < m_post2expr.size(); ++i) {
|
||||
expr * child = m_post2expr[i];
|
||||
ptr_vector<expr> const& p = m_parents[child];
|
||||
SASSERT(!p.empty());
|
||||
expr * new_idom = p[0], * idom2 = 0;
|
||||
for (unsigned j = 1; j < p.size(); ++j) {
|
||||
if (m_doms.find(p[j], idom2)) {
|
||||
expr * new_idom = 0, *idom2 = 0;
|
||||
for (unsigned j = 0; j < p.size(); ++j) {
|
||||
if (!new_idom) {
|
||||
m_doms.find(p[j], new_idom);
|
||||
}
|
||||
else if (m_doms.find(p[j], idom2)) {
|
||||
new_idom = intersect(new_idom, idom2);
|
||||
}
|
||||
}
|
||||
if (!m_doms.find(child, idom2) || idom2 != new_idom) {
|
||||
if (new_idom && (!m_doms.find(child, idom2) || idom2 != new_idom)) {
|
||||
m_doms.insert(child, new_idom);
|
||||
change = true;
|
||||
}
|
||||
}
|
||||
iterations *= 2;
|
||||
if (change && iterations > m_post2expr.size()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void expr_dominators::extract_tree() {
|
||||
|
@ -115,17 +124,18 @@ void expr_dominators::extract_tree() {
|
|||
}
|
||||
}
|
||||
|
||||
void expr_dominators::compile(expr * e) {
|
||||
bool expr_dominators::compile(expr * e) {
|
||||
reset();
|
||||
m_root = e;
|
||||
compute_post_order();
|
||||
compute_dominators();
|
||||
if (!compute_dominators()) return false;
|
||||
extract_tree();
|
||||
return true;
|
||||
}
|
||||
|
||||
void expr_dominators::compile(unsigned sz, expr * const* es) {
|
||||
bool expr_dominators::compile(unsigned sz, expr * const* es) {
|
||||
expr_ref e(m.mk_and(sz, es), m);
|
||||
compile(e);
|
||||
return compile(e);
|
||||
}
|
||||
|
||||
void expr_dominators::reset() {
|
||||
|
@ -164,14 +174,13 @@ void dom_simplify_tactic::operator()(
|
|||
void dom_simplify_tactic::cleanup() {
|
||||
m_trail.reset();
|
||||
m_args.reset();
|
||||
m_args2.reset();
|
||||
m_result.reset();
|
||||
m_dominators.reset();
|
||||
}
|
||||
|
||||
expr_ref dom_simplify_tactic::simplify_ite(app * ite) {
|
||||
expr_ref r(m);
|
||||
expr * c = 0, * t = 0, * e = 0;
|
||||
expr * c = 0, *t = 0, *e = 0;
|
||||
VERIFY(m.is_ite(ite, c, t, e));
|
||||
unsigned old_lvl = scope_level();
|
||||
expr_ref new_c = simplify(c);
|
||||
|
@ -182,13 +191,24 @@ expr_ref dom_simplify_tactic::simplify_ite(app * ite) {
|
|||
r = simplify(e);
|
||||
}
|
||||
else {
|
||||
expr_ref new_t = simplify(t);
|
||||
for (expr * child : tree(ite)) {
|
||||
if (is_subexpr(child, t) && !is_subexpr(child, e)) {
|
||||
simplify(child);
|
||||
}
|
||||
}
|
||||
|
||||
pop(scope_level() - old_lvl);
|
||||
expr_ref new_t = simplify(t);
|
||||
if (!assert_expr(new_c, true)) {
|
||||
return new_t;
|
||||
}
|
||||
expr_ref new_e = simplify(e);
|
||||
for (expr * child : tree(ite)) {
|
||||
if (is_subexpr(child, e) && !is_subexpr(child, t)) {
|
||||
simplify(child);
|
||||
}
|
||||
}
|
||||
pop(scope_level() - old_lvl);
|
||||
expr_ref new_e = simplify(e);
|
||||
if (c == new_c && t == new_t && e == new_e) {
|
||||
r = ite;
|
||||
}
|
||||
|
@ -197,7 +217,7 @@ expr_ref dom_simplify_tactic::simplify_ite(app * ite) {
|
|||
}
|
||||
else {
|
||||
TRACE("tactic", tout << new_c << "\n" << new_t << "\n" << new_e << "\n";);
|
||||
r = m.mk_ite(new_c, new_t, new_c);
|
||||
r = m.mk_ite(new_c, new_t, new_e);
|
||||
}
|
||||
}
|
||||
return r;
|
||||
|
@ -224,12 +244,9 @@ expr_ref dom_simplify_tactic::simplify(expr * e0) {
|
|||
r = simplify_or(to_app(e));
|
||||
}
|
||||
else {
|
||||
expr_dominators::tree_t const& t = m_dominators.get_tree();
|
||||
if (auto children = t.find_core(e)) {
|
||||
for (expr * child : children->get_data().m_value) {
|
||||
for (expr * child : tree(e)) {
|
||||
simplify(child);
|
||||
}
|
||||
}
|
||||
if (is_app(e)) {
|
||||
m_args.reset();
|
||||
for (expr* arg : *to_app(e)) {
|
||||
|
@ -245,45 +262,52 @@ expr_ref dom_simplify_tactic::simplify(expr * e0) {
|
|||
cache(e0, r);
|
||||
TRACE("simplify", tout << "depth: " << m_depth << " " << mk_pp(e0, m) << " -> " << r << "\n";);
|
||||
--m_depth;
|
||||
m_subexpr_cache.reset();
|
||||
return r;
|
||||
}
|
||||
|
||||
expr_ref dom_simplify_tactic::simplify_and_or(bool is_and, app * e) {
|
||||
expr_ref r(m);
|
||||
unsigned old_lvl = scope_level();
|
||||
m_args.reset();
|
||||
|
||||
auto is_subexpr_arg = [&](expr * child, expr * except) {
|
||||
if (!is_subexpr(child, except))
|
||||
return false;
|
||||
for (expr * arg : *e) {
|
||||
r = simplify(arg);
|
||||
if (!assert_expr(r, !is_and)) {
|
||||
r = is_and ? m.mk_false() : m.mk_true();
|
||||
if (arg != except && is_subexpr(child, arg))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
expr_ref_vector args(m);
|
||||
for (expr * arg : *e) {
|
||||
for (expr * child : tree(arg)) {
|
||||
if (is_subexpr_arg(child, arg)) {
|
||||
simplify(child);
|
||||
}
|
||||
}
|
||||
r = simplify(arg);
|
||||
args.push_back(r);
|
||||
if (!assert_expr(simplify(arg), !is_and)) {
|
||||
r = is_and ? m.mk_false() : m.mk_true();
|
||||
return r;
|
||||
}
|
||||
m_args.push_back(r);
|
||||
}
|
||||
pop(scope_level() - old_lvl);
|
||||
m_args.reverse();
|
||||
m_args2.reset();
|
||||
for (expr * arg : m_args) {
|
||||
r = simplify(arg);
|
||||
if (!assert_expr(r, !is_and)) {
|
||||
r = is_and ? m.mk_false() : m.mk_true();
|
||||
}
|
||||
m_args2.push_back(r);
|
||||
}
|
||||
pop(scope_level() - old_lvl);
|
||||
m_args2.reverse();
|
||||
r = is_and ? mk_and(m_args2) : mk_or(m_args2);
|
||||
r = is_and ? mk_and(args) : mk_or(args);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
void dom_simplify_tactic::init(goal& g) {
|
||||
bool dom_simplify_tactic::init(goal& g) {
|
||||
expr_ref_vector args(m);
|
||||
unsigned sz = g.size();
|
||||
for (unsigned i = 0; i < sz; ++i) args.push_back(g.form(i));
|
||||
expr_ref fml = mk_and(args);
|
||||
m_result.reset();
|
||||
m_trail.reset();
|
||||
m_dominators.compile(fml);
|
||||
return m_dominators.compile(fml);
|
||||
}
|
||||
|
||||
void dom_simplify_tactic::simplify_goal(goal& g) {
|
||||
|
@ -295,7 +319,7 @@ void dom_simplify_tactic::simplify_goal(goal& g) {
|
|||
change = false;
|
||||
|
||||
// go forwards
|
||||
init(g);
|
||||
if (!init(g)) return;
|
||||
unsigned sz = g.size();
|
||||
for (unsigned i = 0; !g.inconsistent() && i < sz; ++i) {
|
||||
expr_ref r = simplify(g.form(i));
|
||||
|
@ -312,7 +336,7 @@ void dom_simplify_tactic::simplify_goal(goal& g) {
|
|||
pop(scope_level());
|
||||
|
||||
// go backwards
|
||||
init(g);
|
||||
if (!init(g)) return;
|
||||
sz = g.size();
|
||||
for (unsigned i = sz; !g.inconsistent() && i > 0; ) {
|
||||
--i;
|
||||
|
@ -332,11 +356,36 @@ void dom_simplify_tactic::simplify_goal(goal& g) {
|
|||
SASSERT(scope_level() == 0);
|
||||
}
|
||||
|
||||
bool dom_simplify_tactic::is_subexpr(expr * a, expr * b) {
|
||||
if (a == b)
|
||||
return true;
|
||||
|
||||
bool r;
|
||||
if (m_subexpr_cache.find(a, b, r))
|
||||
return r;
|
||||
|
||||
for (expr * e : tree(b)) {
|
||||
if (is_subexpr(a, e)) {
|
||||
m_subexpr_cache.insert(a, b, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
m_subexpr_cache.insert(a, b, false);
|
||||
return false;
|
||||
}
|
||||
|
||||
ptr_vector<expr> const & dom_simplify_tactic::tree(expr * e) {
|
||||
if (auto p = m_dominators.get_tree().find_core(e))
|
||||
return p->get_data().get_value();
|
||||
return m_empty;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------
|
||||
// expr_substitution_simplifier
|
||||
|
||||
bool expr_substitution_simplifier::assert_expr(expr * t, bool sign) {
|
||||
m_scoped_substitution.push();
|
||||
expr* tt;
|
||||
if (!sign) {
|
||||
update_substitution(t, 0);
|
||||
|
@ -388,6 +437,8 @@ void expr_substitution_simplifier::update_substitution(expr* n, proof* pr) {
|
|||
if (is_ground(n) && (m.is_eq(n, lhs, rhs) || m.is_iff(n, lhs, rhs))) {
|
||||
compute_depth(lhs);
|
||||
compute_depth(rhs);
|
||||
m_trail.push_back(lhs);
|
||||
m_trail.push_back(rhs);
|
||||
if (is_gt(lhs, rhs)) {
|
||||
TRACE("propagate_values", tout << "insert " << mk_pp(lhs, m) << " -> " << mk_pp(rhs, m) << "\n";);
|
||||
m_scoped_substitution.insert(lhs, rhs, pr);
|
||||
|
@ -439,3 +490,7 @@ void expr_substitution_simplifier::compute_depth(expr* e) {
|
|||
m_expr2depth.insert(e, d + 1);
|
||||
}
|
||||
}
|
||||
|
||||
tactic * mk_dom_simplify_tactic(ast_manager & m, params_ref const & p) {
|
||||
return clean(alloc(dom_simplify_tactic, m, alloc(expr_substitution_simplifier, m), p));
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ Notes:
|
|||
#include "ast/ast.h"
|
||||
#include "ast/expr_substitution.h"
|
||||
#include "tactic/tactic.h"
|
||||
#include "tactic/tactical.h"
|
||||
#include "util/obj_pair_hashtable.h"
|
||||
|
||||
|
||||
class expr_dominators {
|
||||
|
@ -43,24 +45,24 @@ private:
|
|||
|
||||
void compute_post_order();
|
||||
expr* intersect(expr* x, expr * y);
|
||||
void compute_dominators();
|
||||
bool compute_dominators();
|
||||
void extract_tree();
|
||||
|
||||
public:
|
||||
expr_dominators(ast_manager& m): m(m), m_root(m) {}
|
||||
|
||||
void compile(expr * e);
|
||||
void compile(unsigned sz, expr * const* es);
|
||||
bool compile(expr * e);
|
||||
bool compile(unsigned sz, expr * const* es);
|
||||
tree_t const& get_tree() { return m_tree; }
|
||||
void reset();
|
||||
|
||||
};
|
||||
|
||||
class dom_simplify_tactic : public tactic {
|
||||
public:
|
||||
class simplifier {
|
||||
class dom_simplifier {
|
||||
public:
|
||||
virtual ~simplifier() {}
|
||||
dom_simplifier() {}
|
||||
|
||||
virtual ~dom_simplifier() {}
|
||||
/**
|
||||
\brief assert_expr performs an implicit push
|
||||
*/
|
||||
|
@ -76,19 +78,24 @@ public:
|
|||
*/
|
||||
virtual void pop(unsigned num_scopes) = 0;
|
||||
|
||||
virtual simplifier * translate(ast_manager & m);
|
||||
virtual dom_simplifier * translate(ast_manager & m) = 0;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
class dom_simplify_tactic : public tactic {
|
||||
public:
|
||||
private:
|
||||
ast_manager& m;
|
||||
simplifier* m_simplifier;
|
||||
dom_simplifier* m_simplifier;
|
||||
params_ref m_params;
|
||||
expr_ref_vector m_trail, m_args, m_args2;
|
||||
expr_ref_vector m_trail, m_args;
|
||||
obj_map<expr, expr*> m_result;
|
||||
expr_dominators m_dominators;
|
||||
unsigned m_scope_level;
|
||||
unsigned m_depth;
|
||||
unsigned m_max_depth;
|
||||
ptr_vector<expr> m_empty;
|
||||
obj_pair_map<expr, expr, bool> m_subexpr_cache;
|
||||
|
||||
expr_ref simplify(expr* t);
|
||||
expr_ref simplify_ite(app * ite);
|
||||
|
@ -97,19 +104,23 @@ private:
|
|||
expr_ref simplify_and_or(bool is_and, app * ite);
|
||||
void simplify_goal(goal& g);
|
||||
|
||||
expr_ref get_cached(expr* t) { expr* r = 0; if (!m_result.find(r, r)) r = t; return expr_ref(r, m); }
|
||||
bool is_subexpr(expr * a, expr * b);
|
||||
|
||||
expr_ref get_cached(expr* t) { expr* r = 0; if (!m_result.find(t, r)) r = t; return expr_ref(r, m); }
|
||||
void cache(expr *t, expr* r) { m_result.insert(t, r); m_trail.push_back(r); }
|
||||
|
||||
ptr_vector<expr> const & tree(expr * e);
|
||||
|
||||
unsigned scope_level() { return m_scope_level; }
|
||||
void pop(unsigned n) { SASSERT(n <= m_scope_level); m_scope_level -= n; m_simplifier->pop(n); }
|
||||
bool assert_expr(expr* f, bool sign) { m_scope_level++; return m_simplifier->assert_expr(f, sign); }
|
||||
|
||||
void init(goal& g);
|
||||
bool init(goal& g);
|
||||
|
||||
public:
|
||||
dom_simplify_tactic(ast_manager & m, simplifier* s, params_ref const & p = params_ref()):
|
||||
dom_simplify_tactic(ast_manager & m, dom_simplifier* s, params_ref const & p = params_ref()):
|
||||
m(m), m_simplifier(s), m_params(p),
|
||||
m_trail(m), m_args(m), m_args2(m),
|
||||
m_trail(m), m_args(m),
|
||||
m_dominators(m),
|
||||
m_scope_level(0), m_depth(0), m_max_depth(1024) {}
|
||||
|
||||
|
@ -130,11 +141,12 @@ public:
|
|||
virtual void cleanup();
|
||||
};
|
||||
|
||||
class expr_substitution_simplifier : public dom_simplify_tactic::simplifier {
|
||||
class expr_substitution_simplifier : public dom_simplifier {
|
||||
ast_manager& m;
|
||||
expr_substitution m_subst;
|
||||
scoped_expr_substitution m_scoped_substitution;
|
||||
obj_map<expr, unsigned> m_expr2depth;
|
||||
expr_ref_vector m_trail;
|
||||
|
||||
// move from asserted_formulas to here..
|
||||
void compute_depth(expr* e);
|
||||
|
@ -142,7 +154,7 @@ class expr_substitution_simplifier : public dom_simplify_tactic::simplifier {
|
|||
unsigned depth(expr* e) { return m_expr2depth[e]; }
|
||||
|
||||
public:
|
||||
expr_substitution_simplifier(ast_manager& m): m(m), m_subst(m), m_scoped_substitution(m_subst) {}
|
||||
expr_substitution_simplifier(ast_manager& m): m(m), m_subst(m), m_scoped_substitution(m_subst), m_trail(m) {}
|
||||
virtual ~expr_substitution_simplifier() {}
|
||||
virtual bool assert_expr(expr * t, bool sign);
|
||||
|
||||
|
@ -152,12 +164,17 @@ public:
|
|||
|
||||
virtual void pop(unsigned num_scopes) { m_scoped_substitution.pop(num_scopes); }
|
||||
|
||||
virtual simplifier * translate(ast_manager & m) {
|
||||
virtual dom_simplifier * translate(ast_manager & m) {
|
||||
SASSERT(m_subst.empty());
|
||||
return alloc(expr_substitution_simplifier, m);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
tactic * mk_dom_simplify_tactic(ast_manager & m, params_ref const & p = params_ref());
|
||||
|
||||
/*
|
||||
ADD_TACTIC("dom-simplify", "apply dominator simplification rules.", "mk_dom_simplify_tactic(m, p)")
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
|
|
@ -417,6 +417,8 @@ public:
|
|||
|
||||
for (unsigned i : m_rows_with_changed_bounds.m_index) {
|
||||
calculate_implied_bounds_for_row(i, bp);
|
||||
if (settings().get_cancel_flag())
|
||||
return;
|
||||
}
|
||||
m_rows_with_changed_bounds.clear();
|
||||
if (!use_tableau()) {
|
||||
|
|
|
@ -188,9 +188,18 @@ unsigned lp_primal_core_solver<T, X>::solve_with_tableau() {
|
|||
&&
|
||||
this->total_iterations() <= this->m_settings.max_total_number_of_iterations
|
||||
&&
|
||||
!(this->current_x_is_feasible() && this->m_look_for_feasible_solution_only));
|
||||
!(this->current_x_is_feasible() && this->m_look_for_feasible_solution_only)
|
||||
&&
|
||||
this->m_settings.get_cancel_flag() == false);
|
||||
|
||||
SASSERT(this->get_status() == FLOATING_POINT_ERROR
|
||||
if (this->m_settings.get_cancel_flag()) {
|
||||
this->set_status(CANCELLED);
|
||||
}
|
||||
|
||||
SASSERT(
|
||||
this->get_status() == FLOATING_POINT_ERROR
|
||||
||
|
||||
this->get_status() == CANCELLED
|
||||
||
|
||||
this->current_x_is_feasible() == false
|
||||
||
|
||||
|
|
|
@ -61,7 +61,8 @@ enum lp_status {
|
|||
TIME_EXHAUSTED,
|
||||
ITERATIONS_EXHAUSTED,
|
||||
EMPTY,
|
||||
UNSTABLE
|
||||
UNSTABLE,
|
||||
CANCELLED
|
||||
};
|
||||
|
||||
// when the ratio of the vector lenth to domain size to is greater than the return value we switch to solve_By_for_T_indexed_only
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue