mirror of
https://github.com/Z3Prover/z3
synced 2025-06-28 08:58:44 +00:00
reduce boilerplate in qe_lite
This commit is contained in:
parent
3760107bb8
commit
e920648c1e
1 changed files with 80 additions and 104 deletions
|
@ -2213,7 +2213,6 @@ namespace fm {
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
class qe_lite::impl {
|
class qe_lite::impl {
|
||||||
public:
|
|
||||||
struct elim_cfg : public default_rewriter_cfg {
|
struct elim_cfg : public default_rewriter_cfg {
|
||||||
impl& m_imp;
|
impl& m_imp;
|
||||||
ast_manager& m;
|
ast_manager& m;
|
||||||
|
@ -2403,107 +2402,57 @@ void qe_lite::operator()(uint_set const& index_set, bool index_of_bound, expr_re
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
class qe_lite_tactic : public tactic {
|
class qe_lite_tactic : public tactic {
|
||||||
|
ast_manager& m;
|
||||||
|
params_ref m_params;
|
||||||
|
qe_lite m_qe;
|
||||||
|
|
||||||
struct imp {
|
void checkpoint() {
|
||||||
ast_manager& m;
|
if (m.canceled())
|
||||||
qe_lite m_qe;
|
throw tactic_exception(m.limit().get_cancel_msg());
|
||||||
|
}
|
||||||
|
|
||||||
imp(ast_manager& m, params_ref const & p):
|
#if 0
|
||||||
m(m),
|
void debug_diff(expr* a, expr* b) {
|
||||||
m_qe(m, p, true)
|
ptr_vector<expr> as, bs;
|
||||||
{}
|
as.push_back(a);
|
||||||
|
bs.push_back(b);
|
||||||
void checkpoint() {
|
expr* a1, *a2, *b1, *b2;
|
||||||
if (m.canceled())
|
while (!as.empty()) {
|
||||||
throw tactic_exception(m.limit().get_cancel_msg());
|
a = as.back();
|
||||||
}
|
b = bs.back();
|
||||||
|
as.pop_back();
|
||||||
void debug_diff(expr* a, expr* b) {
|
bs.pop_back();
|
||||||
ptr_vector<expr> as, bs;
|
if (a == b) {
|
||||||
as.push_back(a);
|
continue;
|
||||||
bs.push_back(b);
|
}
|
||||||
expr* a1, *a2, *b1, *b2;
|
else if (is_forall(a) && is_forall(b)) {
|
||||||
while (!as.empty()) {
|
as.push_back(to_quantifier(a)->get_expr());
|
||||||
a = as.back();
|
bs.push_back(to_quantifier(b)->get_expr());
|
||||||
b = bs.back();
|
}
|
||||||
as.pop_back();
|
else if (m.is_and(a, a1, a2) && m.is_and(b, b1, b2)) {
|
||||||
bs.pop_back();
|
as.push_back(a1);
|
||||||
if (a == b) {
|
as.push_back(a2);
|
||||||
continue;
|
bs.push_back(b1);
|
||||||
}
|
bs.push_back(b2);
|
||||||
else if (is_forall(a) && is_forall(b)) {
|
}
|
||||||
as.push_back(to_quantifier(a)->get_expr());
|
else if (m.is_eq(a, a1, a2) && m.is_eq(b, b1, b2)) {
|
||||||
bs.push_back(to_quantifier(b)->get_expr());
|
as.push_back(a1);
|
||||||
}
|
as.push_back(a2);
|
||||||
else if (m.is_and(a, a1, a2) && m.is_and(b, b1, b2)) {
|
bs.push_back(b1);
|
||||||
as.push_back(a1);
|
bs.push_back(b2);
|
||||||
as.push_back(a2);
|
}
|
||||||
bs.push_back(b1);
|
else {
|
||||||
bs.push_back(b2);
|
TRACE("qe", tout << mk_pp(a, m) << " != " << mk_pp(b, m) << "\n";);
|
||||||
}
|
|
||||||
else if (m.is_eq(a, a1, a2) && m.is_eq(b, b1, b2)) {
|
|
||||||
as.push_back(a1);
|
|
||||||
as.push_back(a2);
|
|
||||||
bs.push_back(b1);
|
|
||||||
bs.push_back(b2);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
TRACE("qe", tout << mk_pp(a, m) << " != " << mk_pp(b, m) << "\n";);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
void operator()(goal_ref const & g,
|
#endif
|
||||||
goal_ref_buffer & result) {
|
|
||||||
SASSERT(g->is_well_sorted());
|
|
||||||
tactic_report report("qe-lite", *g);
|
|
||||||
proof_ref new_pr(m);
|
|
||||||
expr_ref new_f(m);
|
|
||||||
|
|
||||||
unsigned sz = g->size();
|
|
||||||
for (unsigned i = 0; i < sz; i++) {
|
|
||||||
checkpoint();
|
|
||||||
if (g->inconsistent())
|
|
||||||
break;
|
|
||||||
expr * f = g->form(i);
|
|
||||||
if (!has_quantifiers(f))
|
|
||||||
continue;
|
|
||||||
new_f = f;
|
|
||||||
m_qe(new_f, new_pr);
|
|
||||||
if (new_pr) {
|
|
||||||
expr* fact = m.get_fact(new_pr);
|
|
||||||
if (to_app(fact)->get_arg(0) != to_app(fact)->get_arg(1)) {
|
|
||||||
new_pr = m.mk_modus_ponens(g->pr(i), new_pr);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
new_pr = g->pr(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (f != new_f) {
|
|
||||||
TRACE("qe", tout << mk_pp(f, m) << "\n" << new_f << "\n";);
|
|
||||||
g->update(i, new_f, new_pr, g->dep(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
g->inc_depth();
|
|
||||||
result.push_back(g.get());
|
|
||||||
TRACE("qe", g->display(tout););
|
|
||||||
SASSERT(g->is_well_sorted());
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
params_ref m_params;
|
|
||||||
imp * m_imp;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
qe_lite_tactic(ast_manager & m, params_ref const & p):
|
qe_lite_tactic(ast_manager & m, params_ref const & p):
|
||||||
m_params(p) {
|
m(m),
|
||||||
m_imp = alloc(imp, m, p);
|
m_params(p),
|
||||||
}
|
m_qe(m, p, true) {}
|
||||||
|
|
||||||
~qe_lite_tactic() override {
|
|
||||||
dealloc(m_imp);
|
|
||||||
}
|
|
||||||
|
|
||||||
tactic * translate(ast_manager & m) override {
|
tactic * translate(ast_manager & m) override {
|
||||||
return alloc(qe_lite_tactic, m, m_params);
|
return alloc(qe_lite_tactic, m, m_params);
|
||||||
|
@ -2514,14 +2463,45 @@ public:
|
||||||
// m_imp->updt_params(p);
|
// m_imp->updt_params(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void collect_param_descrs(param_descrs & r) override {
|
void collect_param_descrs(param_descrs & r) override {
|
||||||
// m_imp->collect_param_descrs(r);
|
// m_imp->collect_param_descrs(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator()(goal_ref const & in,
|
void operator()(goal_ref const & g,
|
||||||
goal_ref_buffer & result) override {
|
goal_ref_buffer & result) override {
|
||||||
(*m_imp)(in, result);
|
SASSERT(g->is_well_sorted());
|
||||||
|
tactic_report report("qe-lite", *g);
|
||||||
|
proof_ref new_pr(m);
|
||||||
|
expr_ref new_f(m);
|
||||||
|
|
||||||
|
unsigned sz = g->size();
|
||||||
|
for (unsigned i = 0; i < sz; i++) {
|
||||||
|
checkpoint();
|
||||||
|
if (g->inconsistent())
|
||||||
|
break;
|
||||||
|
expr * f = g->form(i);
|
||||||
|
if (!has_quantifiers(f))
|
||||||
|
continue;
|
||||||
|
new_f = f;
|
||||||
|
m_qe(new_f, new_pr);
|
||||||
|
if (new_pr) {
|
||||||
|
expr* fact = m.get_fact(new_pr);
|
||||||
|
if (to_app(fact)->get_arg(0) != to_app(fact)->get_arg(1)) {
|
||||||
|
new_pr = m.mk_modus_ponens(g->pr(i), new_pr);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
new_pr = g->pr(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (f != new_f) {
|
||||||
|
TRACE("qe", tout << mk_pp(f, m) << "\n" << new_f << "\n";);
|
||||||
|
g->update(i, new_f, new_pr, g->dep(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g->inc_depth();
|
||||||
|
result.push_back(g.get());
|
||||||
|
TRACE("qe", g->display(tout););
|
||||||
|
SASSERT(g->is_well_sorted());
|
||||||
}
|
}
|
||||||
|
|
||||||
void collect_statistics(statistics & st) const override {
|
void collect_statistics(statistics & st) const override {
|
||||||
|
@ -2533,16 +2513,12 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanup() override {
|
void cleanup() override {
|
||||||
ast_manager & m = m_imp->m;
|
m_qe.~qe_lite();
|
||||||
m_imp->~imp();
|
new (&m_qe) qe_lite(m, m_params, true);
|
||||||
m_imp = new (m_imp) imp(m, m_params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
tactic * mk_qe_lite_tactic(ast_manager & m, params_ref const & p) {
|
tactic * mk_qe_lite_tactic(ast_manager & m, params_ref const & p) {
|
||||||
return alloc(qe_lite_tactic, m, p);
|
return alloc(qe_lite_tactic, m, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
template class rewriter_tpl<qe_lite::impl::elim_cfg>;
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue