mirror of
https://github.com/Z3Prover/z3
synced 2025-06-28 00:48:45 +00:00
fix pdd_stack for gc on reduce, add unit test for linear_simplify
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
78feac4465
commit
5a68fc8c07
5 changed files with 333 additions and 100 deletions
|
@ -1,6 +1,13 @@
|
|||
#include "util/rlimit.h"
|
||||
#include "math/grobner/pdd_grobner.h"
|
||||
|
||||
#include "ast/bv_decl_plugin.h"
|
||||
#include "ast/ast_pp.h"
|
||||
#include "ast/reg_decl_plugins.h"
|
||||
#include "tactic/goal.h"
|
||||
#include "tactic/tactic.h"
|
||||
#include "tactic/bv/bit_blaster_tactic.h"
|
||||
|
||||
namespace dd {
|
||||
void print_eqs(ptr_vector<grobner::equation> const& eqs) {
|
||||
std::cout << "eqs\n";
|
||||
|
@ -65,8 +72,97 @@ namespace dd {
|
|||
|
||||
//
|
||||
}
|
||||
|
||||
void add_def(unsigned_vector const& id2var, app* e, ast_manager& m, pdd_manager& p, grobner& g) {
|
||||
expr* a, *b;
|
||||
pdd v1 = p.mk_var(id2var[e->get_id()]);
|
||||
if (m.is_and(e)) {
|
||||
pdd r = p.one();
|
||||
for (expr* arg : *e) r *= p.mk_var(id2var[arg->get_id()]);
|
||||
g.add(v1 + r + 1);
|
||||
}
|
||||
else if (m.is_or(e)) {
|
||||
pdd r = p.zero();
|
||||
for (expr* arg : *e) r |= p.mk_var(id2var[arg->get_id()]);
|
||||
g.add(v1 + r + 1);
|
||||
}
|
||||
else if (m.is_not(e, a)) {
|
||||
pdd v2 = p.mk_var(id2var[a->get_id()]);
|
||||
g.add(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()]);
|
||||
g.add(v1 + v2 + v3 + 1);
|
||||
}
|
||||
else if (is_uninterp_const(e)) {
|
||||
// pass
|
||||
}
|
||||
else {
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
void collect_id2var(unsigned_vector& id2var, expr_ref_vector const& fmls) {
|
||||
svector<std::pair<unsigned, unsigned>> ds;
|
||||
unsigned maxid = 0;
|
||||
for (expr* e : subterms(fmls)) {
|
||||
ds.push_back(std::make_pair(to_app(e)->get_depth(), e->get_id()));
|
||||
maxid = std::max(maxid, e->get_id());
|
||||
}
|
||||
std::sort(ds.begin(), ds.end());
|
||||
unsigned v = 1;
|
||||
id2var.resize(maxid + 1);
|
||||
for (auto p : ds) {
|
||||
id2var[p.second] = v++;
|
||||
}
|
||||
}
|
||||
|
||||
void test_simplify(expr_ref_vector& fmls) {
|
||||
ast_manager& m = fmls.get_manager();
|
||||
unsigned_vector id2var;
|
||||
|
||||
collect_id2var(id2var, fmls);
|
||||
pdd_manager p(id2var.size());
|
||||
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.simplify_linear();
|
||||
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(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);
|
||||
goal_ref g = alloc(goal, m);
|
||||
g->assert_expr(eq);
|
||||
goal_ref_buffer res;
|
||||
tactic_ref tac = mk_bit_blaster_tactic(m);
|
||||
(*tac)(g, res);
|
||||
g = res[0];
|
||||
|
||||
expr_ref_vector fmls(m);
|
||||
for (unsigned i = 0; i < g->size(); ++i) {
|
||||
fmls.push_back(g->form(i));
|
||||
}
|
||||
test_simplify(fmls);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void tst_pdd_grobner() {
|
||||
dd::test1();
|
||||
dd::test2();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue