3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-12 12:08:18 +00:00

fix bugs in elim-unconstr2 and fix bugs in intblast_solver

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2023-12-17 17:42:55 -08:00
parent 4867073290
commit bb99f44214
4 changed files with 70 additions and 53 deletions

View file

@ -400,6 +400,7 @@ class bv_expr_inverter : public iexpr_inverter {
} }
bool process_concat(func_decl* f, unsigned num, expr* const* args, expr_ref& r) { bool process_concat(func_decl* f, unsigned num, expr* const* args, expr_ref& r) {
// return false;
if (num == 0) if (num == 0)
return false; return false;
if (!uncnstr(num, args)) if (!uncnstr(num, args))

View file

@ -66,7 +66,6 @@ bool elim_unconstrained::is_var_lt(int v1, int v2) const {
} }
void elim_unconstrained::eliminate() { void elim_unconstrained::eliminate() {
while (!m_heap.empty()) { while (!m_heap.empty()) {
expr_ref r(m); expr_ref r(m);
int v = m_heap.erase_min(); int v = m_heap.erase_min();
@ -86,7 +85,12 @@ void elim_unconstrained::eliminate() {
n.m_refcount = 0; n.m_refcount = 0;
continue; continue;
} }
if (m_heap.contains(root(e))) {
IF_VERBOSE(11, verbose_stream() << "already in heap " << mk_bounded_pp(e, m) << "\n");
continue;
}
app* t = to_app(e); app* t = to_app(e);
TRACE("elim_unconstrained", tout << "eliminating " << mk_pp(t, m) << "\n";);
unsigned sz = m_args.size(); unsigned sz = m_args.size();
for (expr* arg : *to_app(t)) for (expr* arg : *to_app(t))
m_args.push_back(reconstruct_term(get_node(arg))); m_args.push_back(reconstruct_term(get_node(arg)));
@ -99,6 +103,7 @@ void elim_unconstrained::eliminate() {
proof * pr = m.mk_apply_def(s, r, pr1); proof * pr = m.mk_apply_def(s, r, pr1);
m_trail.push_back(pr); m_trail.push_back(pr);
} }
expr_ref rr(m.mk_app(t->get_decl(), t->get_num_args(), m_args.data() + sz), m);
n.m_refcount = 0; n.m_refcount = 0;
m_args.shrink(sz); m_args.shrink(sz);
if (!inverted) { if (!inverted) {
@ -106,6 +111,8 @@ void elim_unconstrained::eliminate() {
continue; continue;
} }
IF_VERBOSE(11, verbose_stream() << "replace " << mk_pp(t, m) << " / " << rr << " -> " << r << "\n");
TRACE("elim_unconstrained", tout << mk_pp(t, m) << " -> " << r << "\n"); TRACE("elim_unconstrained", tout << mk_pp(t, m) << " -> " << r << "\n");
SASSERT(r->get_sort() == t->get_sort()); SASSERT(r->get_sort() == t->get_sort());
m_stats.m_num_eliminated++; m_stats.m_num_eliminated++;
@ -119,7 +126,8 @@ void elim_unconstrained::eliminate() {
get_node(e).m_term = r; get_node(e).m_term = r;
get_node(e).m_proof = pr; get_node(e).m_proof = pr;
get_node(e).m_refcount++; get_node(e).m_refcount++;
IF_VERBOSE(11, verbose_stream() << mk_bounded_pp(e, m) << "\n"); get_node(e).m_dirty = false;
IF_VERBOSE(11, verbose_stream() << "set " << &get_node(e) << " " << root(e) << " " << mk_bounded_pp(e, m) << " := " << mk_bounded_pp(r, m) << "\n");
SASSERT(!m_heap.contains(root(e))); SASSERT(!m_heap.contains(root(e)));
if (is_uninterp_const(r)) if (is_uninterp_const(r))
m_heap.insert(root(e)); m_heap.insert(root(e));
@ -283,13 +291,22 @@ expr_ref elim_unconstrained::reconstruct_term(node& n0) {
expr* t = n0.m_term; expr* t = n0.m_term;
if (!n0.m_dirty) if (!n0.m_dirty)
return expr_ref(t, m); return expr_ref(t, m);
if (!is_node(t))
return expr_ref(t, m);
ptr_vector<expr> todo; ptr_vector<expr> todo;
todo.push_back(t); todo.push_back(t);
while (!todo.empty()) { while (!todo.empty()) {
t = todo.back(); t = todo.back();
if (!is_node(t)) {
UNREACHABLE();
}
node& n = get_node(t); node& n = get_node(t);
unsigned sz0 = todo.size(); unsigned sz0 = todo.size();
if (is_app(t)) { if (is_app(t)) {
if (n.m_term != t) {
todo.pop_back();
continue;
}
for (expr* arg : *to_app(t)) for (expr* arg : *to_app(t))
if (get_node(arg).m_dirty || !get_node(arg).m_term) if (get_node(arg).m_dirty || !get_node(arg).m_term)
todo.push_back(arg); todo.push_back(arg);
@ -300,7 +317,6 @@ expr_ref elim_unconstrained::reconstruct_term(node& n0) {
for (expr* arg : *to_app(t)) for (expr* arg : *to_app(t))
m_args.push_back(get_node(arg).m_term); m_args.push_back(get_node(arg).m_term);
n.m_term = m.mk_app(to_app(t)->get_decl(), to_app(t)->get_num_args(), m_args.data() + sz); n.m_term = m.mk_app(to_app(t)->get_decl(), to_app(t)->get_num_args(), m_args.data() + sz);
m_args.shrink(sz); m_args.shrink(sz);
} }
else if (is_quantifier(t)) { else if (is_quantifier(t)) {
@ -410,7 +426,7 @@ void elim_unconstrained::reduce() {
generic_model_converter_ref mc = alloc(generic_model_converter, m, "elim-unconstrained"); generic_model_converter_ref mc = alloc(generic_model_converter, m, "elim-unconstrained");
m_inverter.set_model_converter(mc.get()); m_inverter.set_model_converter(mc.get());
m_created_compound = true; m_created_compound = true;
for (unsigned rounds = 0; m_created_compound && rounds < 3; ++rounds) { for (unsigned rounds = 0; m_created_compound && rounds < 1; ++rounds) {
m_created_compound = false; m_created_compound = false;
init_nodes(); init_nodes();
eliminate(); eliminate();

View file

@ -182,11 +182,11 @@ std::ostream& model_reconstruction_trail::display(std::ostream& out) const {
out << "hide " << t->m_decl->get_name() << "\n"; out << "hide " << t->m_decl->get_name() << "\n";
else if (t->is_def()) { else if (t->is_def()) {
for (auto const& [f, def, dep] : t->m_defs) for (auto const& [f, def, dep] : t->m_defs)
out << f->get_name() << " <- " << mk_pp(def, m) << "\n"; out << "def: " << f->get_name() << " <- " << mk_pp(def, m) << "\n";
} }
else { else {
for (auto const& [v, def] : t->m_subst->sub()) for (auto const& [v, def] : t->m_subst->sub())
out << mk_pp(v, m) << " <- " << mk_pp(def, m) << "\n"; out << "sub: " << mk_pp(v, m) << " -> " << mk_pp(def, m) << "\n";
} }
for (auto const& d : t->m_removed) for (auto const& d : t->m_removed)
out << "rm: " << d << "\n"; out << "rm: " << d << "\n";

View file

@ -347,10 +347,12 @@ namespace intblast {
continue; continue;
if (sib->get_arg(0)->get_root() == r1) if (sib->get_arg(0)->get_root() == r1)
continue; continue;
auto a = eq_internalize(n, sib); if (sib->get_arg(0)->get_sort() != n->get_arg(0)->get_sort())
auto b = eq_internalize(sib->get_arg(0), n->get_arg(0)); continue;
ctx.mark_relevant(a); auto a = eq_internalize(n, sib);
ctx.mark_relevant(b); auto b = eq_internalize(sib->get_arg(0), n->get_arg(0));
ctx.mark_relevant(a);
ctx.mark_relevant(b);
add_clause(~a, b, nullptr); add_clause(~a, b, nullptr);
return sat::check_result::CR_CONTINUE; return sat::check_result::CR_CONTINUE;
} }
@ -368,8 +370,8 @@ namespace intblast {
auto nBv2int = ctx.get_enode(bv2int); auto nBv2int = ctx.get_enode(bv2int);
auto nxModN = ctx.get_enode(xModN); auto nxModN = ctx.get_enode(xModN);
if (nBv2int->get_root() != nxModN->get_root()) { if (nBv2int->get_root() != nxModN->get_root()) {
auto a = eq_internalize(nBv2int, nxModN); auto a = eq_internalize(nBv2int, nxModN);
ctx.mark_relevant(a); ctx.mark_relevant(a);
add_unit(a); add_unit(a);
return sat::check_result::CR_CONTINUE; return sat::check_result::CR_CONTINUE;
} }
@ -536,7 +538,7 @@ namespace intblast {
r = a.mk_add(hi, lo); r = a.mk_add(hi, lo);
} }
return r; return r;
}; };
expr* bv_expr = e; expr* bv_expr = e;
expr* r = nullptr; expr* r = nullptr;
@ -635,7 +637,7 @@ namespace intblast {
} }
case OP_BSHL: { case OP_BSHL: {
if (!a.is_numeral(arg(0)) && !a.is_numeral(arg(1))) if (!a.is_numeral(arg(0)) && !a.is_numeral(arg(1)))
r = a.mk_shl(bv.get_bv_size(e), arg(0),arg(1)); r = a.mk_shl(bv.get_bv_size(e), arg(0), arg(1));
else { else {
expr* x = arg(0), * y = umod(e, 1); expr* x = arg(0), * y = umod(e, 1);
r = a.mk_int(0); r = a.mk_int(0);
@ -671,15 +673,15 @@ namespace intblast {
// //
unsigned sz = bv.get_bv_size(e); unsigned sz = bv.get_bv_size(e);
rational N = bv_size(e); rational N = bv_size(e);
expr* x = umod(e, 0), *y = umod(e, 1); expr* x = umod(e, 0), * y = umod(e, 1);
expr* signx = a.mk_ge(x, a.mk_int(N / 2)); expr* signx = a.mk_ge(x, a.mk_int(N / 2));
r = m.mk_ite(signx, a.mk_int(- 1), a.mk_int(0)); r = m.mk_ite(signx, a.mk_int(-1), a.mk_int(0));
IF_VERBOSE(1, verbose_stream() << "ashr " << mk_bounded_pp(e, m) << " " << bv.get_bv_size(e) << "\n"); IF_VERBOSE(1, verbose_stream() << "ashr " << mk_bounded_pp(e, m) << " " << bv.get_bv_size(e) << "\n");
for (unsigned i = 0; i < sz; ++i) { for (unsigned i = 0; i < sz; ++i) {
expr* d = a.mk_idiv(x, a.mk_int(rational::power_of_two(i))); expr* d = a.mk_idiv(x, a.mk_int(rational::power_of_two(i)));
r = m.mk_ite(m.mk_eq(y, a.mk_int(i)), r = m.mk_ite(m.mk_eq(y, a.mk_int(i)),
m.mk_ite(signx, a.mk_add(d, a.mk_int(- rational::power_of_two(sz-i))), d), m.mk_ite(signx, a.mk_add(d, a.mk_int(-rational::power_of_two(sz - i))), d),
r); r);
} }
} }
break; break;
@ -745,10 +747,10 @@ namespace intblast {
break; break;
case OP_BSMOD_I: case OP_BSMOD_I:
case OP_BSMOD: { case OP_BSMOD: {
expr* x = umod(e, 0), *y = umod(e, 1); expr* x = umod(e, 0), * y = umod(e, 1);
rational N = bv_size(e); rational N = bv_size(e);
expr* signx = a.mk_ge(x, a.mk_int(N/2)); expr* signx = a.mk_ge(x, a.mk_int(N / 2));
expr* signy = a.mk_ge(y, a.mk_int(N/2)); expr* signy = a.mk_ge(y, a.mk_int(N / 2));
expr* u = a.mk_mod(x, y); expr* u = a.mk_mod(x, y);
// u = 0 -> 0 // u = 0 -> 0
// y = 0 -> x // y = 0 -> x
@ -812,7 +814,7 @@ namespace intblast {
r = rotate_left(sz - n); r = rotate_left(sz - n);
break; break;
} }
case OP_EXT_ROTATE_LEFT: { case OP_EXT_ROTATE_LEFT: {
unsigned sz = bv.get_bv_size(e); unsigned sz = bv.get_bv_size(e);
expr* y = umod(e, 1); expr* y = umod(e, 1);
r = a.mk_int(0); r = a.mk_int(0);
@ -897,7 +899,7 @@ namespace intblast {
} }
bool solver::add_dep(euf::enode* n, top_sort<euf::enode>& dep) { bool solver::add_dep(euf::enode* n, top_sort<euf::enode>& dep) {
if (!is_app(n->get_expr())) if (!is_app(n->get_expr()))
return false; return false;
app* e = to_app(n->get_expr()); app* e = to_app(n->get_expr());
if (n->num_args() == 0) { if (n->num_args() == 0) {
@ -957,7 +959,6 @@ namespace intblast {
rational r; rational r;
VERIFY(av.get_value(b2i->get_expr(), r)); VERIFY(av.get_value(b2i->get_expr(), r));
value = bv.mk_numeral(r, bv.get_bv_size(n->get_expr())); value = bv.mk_numeral(r, bv.get_bv_size(n->get_expr()));
verbose_stream() << ctx.bpp(n) << " := " << value << "\n";
} }
values.set(n->get_root_id(), value); values.set(n->get_root_id(), value);
TRACE("model", tout << "add_value " << ctx.bpp(n) << " := " << value << "\n"); TRACE("model", tout << "add_value " << ctx.bpp(n) << " := " << value << "\n");
@ -981,9 +982,8 @@ namespace intblast {
continue; continue;
verbose_stream() << "value mismatch : " << mk_bounded_pp(e, m) << " := " << val1 << "\n"; verbose_stream() << "value mismatch : " << mk_bounded_pp(e, m) << " := " << val1 << "\n";
verbose_stream() << mk_bounded_pp(f, m) << " := " << r2 << "\n"; verbose_stream() << mk_bounded_pp(f, m) << " := " << r2 << "\n";
for (expr* arg : *to_app(e)) { for (expr* arg : *to_app(e))
verbose_stream() << mk_bounded_pp(arg, m) << " := " << mdl(arg) << "\n"; verbose_stream() << mk_bounded_pp(arg, m) << " := " << mdl(arg) << "\n";
}
} }
} }
} }