3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 17:15:31 +00:00

reduce simplification

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2019-12-26 01:32:36 -08:00
parent 991e587950
commit 50873c8094
5 changed files with 98 additions and 44 deletions

View file

@ -81,21 +81,26 @@ namespace dd {
if (m.is_and(e)) {
pdd r = p.one();
for (expr* arg : *e) r *= p.mk_var(id2var[arg->get_id()]);
q = v1 + r;
q = v1 - r;
}
else if (m.is_or(e)) {
pdd r = p.zero();
for (expr* arg : *e) r |= p.mk_var(id2var[arg->get_id()]);
q = v1 + r;
q = v1 - r;
}
else if (m.is_not(e, a)) {
pdd v2 = p.mk_var(id2var[a->get_id()]);
q = v1 + v2 + 1;
q = v1 + v2 - 1;
}
else if (m.is_eq(e, a, b)) {
pdd v2 = p.mk_var(id2var[a->get_id()]);
pdd v3 = p.mk_var(id2var[b->get_id()]);
q = v1 + v2 + v3 + 1;
// v1 = (v2 = v3)
// 111, 100 = 0
// 001, 010 = 0
// 000, 011 = 1
// 110, 101 = 1
q = v1 - v2 - v3 + 1 + 2*v2*v3 - 2*v1*v2*v3;
}
else if (is_uninterp_const(e)) {
return;
@ -121,34 +126,34 @@ namespace dd {
}
}
void test_simplify(expr_ref_vector& fmls) {
void test_simplify(expr_ref_vector& fmls, bool use_mod2) {
ast_manager& m = fmls.get_manager();
unsigned_vector id2var;
collect_id2var(id2var, fmls);
pdd_manager p(id2var.size());
p.set_mod2_semantics();
if (use_mod2) p.set_mod2_semantics();
grobner g(m.limit(), p);
for (expr* e : subterms(fmls)) {
add_def(id2var, to_app(e), m, p, g);
}
for (expr* e : fmls) {
g.add(p.mk_var(id2var[e->get_id()]) + 1);
g.add(1 - p.mk_var(id2var[e->get_id()]));
}
g.display(std::cout);
g.simplify();
g.display(std::cout);
g.saturate();
g.display(std::cout);
//g.saturate();
//g.display(std::cout);
}
void test2() {
ast_manager m;
reg_decl_plugins(m);
bv_util bv(m);
expr_ref x(m.mk_const("x", bv.mk_sort(3)), m);
expr_ref y(m.mk_const("y", bv.mk_sort(3)), m);
expr_ref x(m.mk_const("x", bv.mk_sort(4)), m);
expr_ref y(m.mk_const("y", bv.mk_sort(4)), m);
expr_ref xy(bv.mk_bv_mul(x, y), m);
expr_ref yx(bv.mk_bv_mul(y, x), m);
expr_ref eq(m.mk_not(m.mk_eq(xy,yx)), m);
@ -163,7 +168,8 @@ namespace dd {
for (unsigned i = 0; i < g->size(); ++i) {
fmls.push_back(g->form(i));
}
test_simplify(fmls);
test_simplify(fmls, true);
test_simplify(fmls, false);
}
}