mirror of
https://github.com/Z3Prover/z3
synced 2025-06-20 04:43:39 +00:00
Merge branch 'master' of https://github.com/Z3Prover/z3
This commit is contained in:
commit
dd91fab6f4
6 changed files with 72 additions and 71 deletions
|
@ -35,7 +35,6 @@ namespace sat {
|
||||||
if (s.get_config().m_drat_binary)
|
if (s.get_config().m_drat_binary)
|
||||||
std::swap(m_out, m_bout);
|
std::swap(m_out, m_bout);
|
||||||
}
|
}
|
||||||
// m_print_clause = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
drat::~drat() {
|
drat::~drat() {
|
||||||
|
@ -256,31 +255,6 @@ namespace sat {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void drat::bool_def(bool_var v, unsigned n) {
|
|
||||||
if (m_out)
|
|
||||||
(*m_out) << "b " << v << " " << n << " 0\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
void drat::def_begin(char id, unsigned n, std::string const& name) {
|
|
||||||
if (m_out)
|
|
||||||
(*m_out) << id << " " << n << " " << name;
|
|
||||||
}
|
|
||||||
|
|
||||||
void drat::def_add_arg(unsigned arg) {
|
|
||||||
if (m_out)
|
|
||||||
(*m_out) << " " << arg;
|
|
||||||
}
|
|
||||||
|
|
||||||
void drat::def_end() {
|
|
||||||
if (m_out)
|
|
||||||
(*m_out) << " 0\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
void drat::log_adhoc(std::function<void(std::ostream&)>& fn) {
|
|
||||||
if (m_out)
|
|
||||||
fn(*m_out);
|
|
||||||
}
|
|
||||||
|
|
||||||
void drat::append(clause& c, status st) {
|
void drat::append(clause& c, status st) {
|
||||||
TRACE("sat_drat", pp(tout, st) << " " << c << "\n";);
|
TRACE("sat_drat", pp(tout, st) << " " << c << "\n";);
|
||||||
for (literal lit : c) declare(lit);
|
for (literal lit : c) declare(lit);
|
||||||
|
@ -684,6 +658,7 @@ namespace sat {
|
||||||
verify(0, nullptr);
|
verify(0, nullptr);
|
||||||
SASSERT(m_inconsistent);
|
SASSERT(m_inconsistent);
|
||||||
}
|
}
|
||||||
|
if (m_print_clause) m_print_clause->on_clause(0, nullptr, status::redundant());
|
||||||
}
|
}
|
||||||
void drat::add(literal l, bool learned) {
|
void drat::add(literal l, bool learned) {
|
||||||
++m_stats.m_num_add;
|
++m_stats.m_num_add;
|
||||||
|
@ -691,7 +666,7 @@ namespace sat {
|
||||||
if (m_out) dump(1, &l, st);
|
if (m_out) dump(1, &l, st);
|
||||||
if (m_bout) bdump(1, &l, st);
|
if (m_bout) bdump(1, &l, st);
|
||||||
if (m_check) append(l, st);
|
if (m_check) append(l, st);
|
||||||
//if (m_print_clause) m_print_clause(1, &l, st);
|
if (m_print_clause) m_print_clause->on_clause(1, &l, st);
|
||||||
}
|
}
|
||||||
void drat::add(literal l1, literal l2, status st) {
|
void drat::add(literal l1, literal l2, status st) {
|
||||||
if (st.is_deleted())
|
if (st.is_deleted())
|
||||||
|
@ -702,7 +677,7 @@ namespace sat {
|
||||||
if (m_out) dump(2, ls, st);
|
if (m_out) dump(2, ls, st);
|
||||||
if (m_bout) bdump(2, ls, st);
|
if (m_bout) bdump(2, ls, st);
|
||||||
if (m_check) append(l1, l2, st);
|
if (m_check) append(l1, l2, st);
|
||||||
//if (m_print_clause) m_print_clause(2, ls, st);
|
if (m_print_clause) m_print_clause->on_clause(2, ls, st);
|
||||||
}
|
}
|
||||||
void drat::add(clause& c, status st) {
|
void drat::add(clause& c, status st) {
|
||||||
if (st.is_deleted())
|
if (st.is_deleted())
|
||||||
|
@ -712,7 +687,7 @@ namespace sat {
|
||||||
if (m_out) dump(c.size(), c.begin(), st);
|
if (m_out) dump(c.size(), c.begin(), st);
|
||||||
if (m_bout) bdump(c.size(), c.begin(), st);
|
if (m_bout) bdump(c.size(), c.begin(), st);
|
||||||
if (m_check) append(mk_clause(c), st);
|
if (m_check) append(mk_clause(c), st);
|
||||||
//if (m_print_clause) m_print_clause(c.size(), c.begin(), st);
|
if (m_print_clause) m_print_clause->on_clause(c.size(), c.begin(), st);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drat::add(literal_vector const& lits, status st) {
|
void drat::add(literal_vector const& lits, status st) {
|
||||||
|
@ -734,7 +709,8 @@ namespace sat {
|
||||||
if (m_out)
|
if (m_out)
|
||||||
dump(sz, lits, st);
|
dump(sz, lits, st);
|
||||||
|
|
||||||
//if (m_print_clause) m_print_clause(sz, lits, st);
|
if (m_print_clause)
|
||||||
|
m_print_clause->on_clause(sz, lits, st);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drat::add(literal_vector const& c) {
|
void drat::add(literal_vector const& c) {
|
||||||
|
@ -754,7 +730,8 @@ namespace sat {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if (m_print_clause) m_print_clause(c.size(), c.data(), status::redundant());
|
if (m_print_clause)
|
||||||
|
m_print_clause->on_clause(c.size(), c.data(), status::redundant());
|
||||||
}
|
}
|
||||||
|
|
||||||
void drat::del(literal l) {
|
void drat::del(literal l) {
|
||||||
|
|
|
@ -60,6 +60,11 @@ namespace sat {
|
||||||
class justification;
|
class justification;
|
||||||
class clause;
|
class clause;
|
||||||
|
|
||||||
|
struct print_clause {
|
||||||
|
virtual ~print_clause() {}
|
||||||
|
virtual void on_clause(unsigned, literal const*, status) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
class drat {
|
class drat {
|
||||||
struct stats {
|
struct stats {
|
||||||
unsigned m_num_drup = 0;
|
unsigned m_num_drup = 0;
|
||||||
|
@ -73,7 +78,7 @@ namespace sat {
|
||||||
watched_clause(clause* c, literal l1, literal l2):
|
watched_clause(clause* c, literal l1, literal l2):
|
||||||
m_clause(c), m_l1(l1), m_l2(l2) {}
|
m_clause(c), m_l1(l1), m_l2(l2) {}
|
||||||
};
|
};
|
||||||
std::function<void(unsigned, literal const*, status)> m_print_clause;
|
print_clause* m_print_clause = nullptr;
|
||||||
svector<watched_clause> m_watched_clauses;
|
svector<watched_clause> m_watched_clauses;
|
||||||
typedef svector<unsigned> watch;
|
typedef svector<unsigned> watch;
|
||||||
solver& s;
|
solver& s;
|
||||||
|
@ -140,21 +145,16 @@ namespace sat {
|
||||||
void add(literal_vector const& c); // add learned clause
|
void add(literal_vector const& c); // add learned clause
|
||||||
void add(unsigned sz, literal const* lits, status st);
|
void add(unsigned sz, literal const* lits, status st);
|
||||||
|
|
||||||
void set_print_clause(std::function<void(unsigned, literal const*, status)>& print_clause) {
|
void set_print_clause(print_clause& print_clause) {
|
||||||
// m_print_clause = print_clause;
|
m_print_clause = &print_clause;
|
||||||
}
|
}
|
||||||
|
|
||||||
// support for SMT - connect Boolean variables with AST nodes
|
// support for SMT - connect Boolean variables with AST nodes
|
||||||
// associate AST node id with Boolean variable v
|
// associate AST node id with Boolean variable v
|
||||||
void bool_def(bool_var v, unsigned n);
|
|
||||||
|
|
||||||
// declare AST node n with 'name' and arguments arg
|
// declare AST node n with 'name' and arguments arg
|
||||||
void def_begin(char id, unsigned n, std::string const& name);
|
std::ostream* out() { return m_out; }
|
||||||
void def_add_arg(unsigned arg);
|
|
||||||
void def_end();
|
|
||||||
|
|
||||||
// ad-hoc logging until a format is developed
|
|
||||||
void log_adhoc(std::function<void(std::ostream&)>& fn);
|
|
||||||
|
|
||||||
bool is_cleaned(clause& c) const;
|
bool is_cleaned(clause& c) const;
|
||||||
void del(literal l);
|
void del(literal l);
|
||||||
|
|
|
@ -29,6 +29,31 @@ namespace euf {
|
||||||
m_drat_initialized = true;
|
m_drat_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void solver::def_add_arg(unsigned arg) {
|
||||||
|
auto* out = get_drat().out();
|
||||||
|
if (out)
|
||||||
|
(*out) << " " << arg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void solver::def_end() {
|
||||||
|
auto* out = get_drat().out();
|
||||||
|
if (out)
|
||||||
|
(*out) << " 0\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void solver::def_begin(char id, unsigned n, std::string const& name) {
|
||||||
|
auto* out = get_drat().out();
|
||||||
|
if (out)
|
||||||
|
(*out) << id << " " << n << " " << name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void solver::bool_def(bool_var v, unsigned n) {
|
||||||
|
auto* out = get_drat().out();
|
||||||
|
if (out)
|
||||||
|
(*out) << "b " << v << " " << n << " 0\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void solver::drat_log_params(func_decl* f) {
|
void solver::drat_log_params(func_decl* f) {
|
||||||
for (unsigned i = f->get_num_parameters(); i-- > 0; ) {
|
for (unsigned i = f->get_num_parameters(); i-- > 0; ) {
|
||||||
auto const& p = f->get_parameter(i);
|
auto const& p = f->get_parameter(i);
|
||||||
|
@ -39,6 +64,7 @@ namespace euf {
|
||||||
drat_log_decl(to_func_decl(a));
|
drat_log_decl(to_func_decl(a));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void solver::drat_log_expr1(expr* e) {
|
void solver::drat_log_expr1(expr* e) {
|
||||||
if (is_app(e)) {
|
if (is_app(e)) {
|
||||||
app* a = to_app(e);
|
app* a = to_app(e);
|
||||||
|
@ -46,16 +72,16 @@ namespace euf {
|
||||||
drat_log_decl(a->get_decl());
|
drat_log_decl(a->get_decl());
|
||||||
std::stringstream strm;
|
std::stringstream strm;
|
||||||
strm << mk_ismt2_func(a->get_decl(), m);
|
strm << mk_ismt2_func(a->get_decl(), m);
|
||||||
get_drat().def_begin('e', e->get_id(), strm.str());
|
def_begin('e', e->get_id(), strm.str());
|
||||||
for (expr* arg : *a)
|
for (expr* arg : *a)
|
||||||
get_drat().def_add_arg(arg->get_id());
|
def_add_arg(arg->get_id());
|
||||||
get_drat().def_end();
|
def_end();
|
||||||
}
|
}
|
||||||
else if (is_var(e)) {
|
else if (is_var(e)) {
|
||||||
var* v = to_var(e);
|
var* v = to_var(e);
|
||||||
get_drat().def_begin('v', v->get_id(), "" + mk_pp(e->get_sort(), m));
|
def_begin('v', v->get_id(), "" + mk_pp(e->get_sort(), m));
|
||||||
get_drat().def_add_arg(v->get_idx());
|
def_add_arg(v->get_idx());
|
||||||
get_drat().def_end();
|
def_end();
|
||||||
}
|
}
|
||||||
else if (is_quantifier(e)) {
|
else if (is_quantifier(e)) {
|
||||||
quantifier* q = to_quantifier(e);
|
quantifier* q = to_quantifier(e);
|
||||||
|
@ -64,9 +90,9 @@ namespace euf {
|
||||||
for (unsigned i = 0; i < q->get_num_decls(); ++i)
|
for (unsigned i = 0; i < q->get_num_decls(); ++i)
|
||||||
strm << " (" << q->get_decl_name(i) << " " << mk_pp(q->get_decl_sort(i), m) << ")";
|
strm << " (" << q->get_decl_name(i) << " " << mk_pp(q->get_decl_sort(i), m) << ")";
|
||||||
strm << ")";
|
strm << ")";
|
||||||
get_drat().def_begin('q', q->get_id(), strm.str());
|
def_begin('q', q->get_id(), strm.str());
|
||||||
get_drat().def_add_arg(q->get_expr()->get_id());
|
def_add_arg(q->get_expr()->get_id());
|
||||||
get_drat().def_end();
|
def_end();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
|
@ -103,7 +129,7 @@ namespace euf {
|
||||||
if (!use_drat())
|
if (!use_drat())
|
||||||
return;
|
return;
|
||||||
drat_log_expr(e);
|
drat_log_expr(e);
|
||||||
get_drat().bool_def(v, e->get_id());
|
bool_def(v, e->get_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,8 +143,8 @@ namespace euf {
|
||||||
std::ostringstream strm;
|
std::ostringstream strm;
|
||||||
smt2_pp_environment_dbg env(m);
|
smt2_pp_environment_dbg env(m);
|
||||||
ast_smt2_pp(strm, f, env);
|
ast_smt2_pp(strm, f, env);
|
||||||
get_drat().def_begin('f', f->get_small_id(), strm.str());
|
def_begin('f', f->get_small_id(), strm.str());
|
||||||
get_drat().def_end();
|
def_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -187,14 +213,14 @@ namespace euf {
|
||||||
VERIFY(m.is_eq(eq, a, b));
|
VERIFY(m.is_eq(eq, a, b));
|
||||||
drat_log_expr(a);
|
drat_log_expr(a);
|
||||||
drat_log_expr(b);
|
drat_log_expr(b);
|
||||||
get_drat().def_begin('e', eq->get_id(), std::string("="));
|
def_begin('e', eq->get_id(), std::string("="));
|
||||||
get_drat().def_add_arg(a->get_id());
|
def_add_arg(a->get_id());
|
||||||
get_drat().def_add_arg(b->get_id());
|
def_add_arg(b->get_id());
|
||||||
get_drat().def_end();
|
def_end();
|
||||||
get_drat().bool_def(lit.var(), eq->get_id());
|
bool_def(lit.var(), eq->get_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
void solver::log_clause(unsigned n, literal const* lits, sat::status st) {
|
void solver::on_clause(unsigned n, literal const* lits, sat::status st) {
|
||||||
if (!get_config().m_lemmas2console)
|
if (!get_config().m_lemmas2console)
|
||||||
return;
|
return;
|
||||||
if (!st.is_redundant() && !st.is_asserted())
|
if (!st.is_redundant() && !st.is_asserted())
|
||||||
|
|
|
@ -171,13 +171,8 @@ namespace euf {
|
||||||
for (auto* s : m_solvers)
|
for (auto* s : m_solvers)
|
||||||
s->init_search();
|
s->init_search();
|
||||||
|
|
||||||
if (get_config().m_lemmas2console) {
|
if (get_config().m_lemmas2console)
|
||||||
std::function<void(unsigned, sat::literal const*, sat::status)> on_clause =
|
get_drat().set_print_clause(*this);
|
||||||
[&](unsigned n, sat::literal const* lits, sat::status st) {
|
|
||||||
log_clause(n, lits, st);
|
|
||||||
};
|
|
||||||
get_drat().set_print_clause(on_clause);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool solver::is_external(bool_var v) {
|
bool solver::is_external(bool_var v) {
|
||||||
|
|
|
@ -60,7 +60,7 @@ namespace euf {
|
||||||
std::ostream& display(std::ostream& out) const;
|
std::ostream& display(std::ostream& out) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class solver : public sat::extension, public th_internalizer, public th_decompile {
|
class solver : public sat::extension, public th_internalizer, public th_decompile, public sat::print_clause {
|
||||||
typedef top_sort<euf::enode> deps_t;
|
typedef top_sort<euf::enode> deps_t;
|
||||||
friend class ackerman;
|
friend class ackerman;
|
||||||
class user_sort;
|
class user_sort;
|
||||||
|
@ -183,7 +183,10 @@ namespace euf {
|
||||||
bool m_drat_initialized{ false };
|
bool m_drat_initialized{ false };
|
||||||
void init_drat();
|
void init_drat();
|
||||||
ast_pp_util m_clause_visitor;
|
ast_pp_util m_clause_visitor;
|
||||||
void log_clause(unsigned n, literal const* lits, sat::status st);
|
void on_clause(unsigned n, literal const* lits, sat::status st) override;
|
||||||
|
void def_add_arg(unsigned arg);
|
||||||
|
void def_end();
|
||||||
|
void def_begin(char id, unsigned n, std::string const& name);
|
||||||
|
|
||||||
|
|
||||||
// relevancy
|
// relevancy
|
||||||
|
@ -349,6 +352,7 @@ namespace euf {
|
||||||
void drat_bool_def(sat::bool_var v, expr* n);
|
void drat_bool_def(sat::bool_var v, expr* n);
|
||||||
void drat_eq_def(sat::literal lit, expr* eq);
|
void drat_eq_def(sat::literal lit, expr* eq);
|
||||||
void drat_log_expr(expr* n);
|
void drat_log_expr(expr* n);
|
||||||
|
void bool_def(bool_var v, unsigned n);
|
||||||
bool visit_clause(unsigned n, literal const* lits);
|
bool visit_clause(unsigned n, literal const* lits);
|
||||||
void display_clause(unsigned n, literal const* lits);
|
void display_clause(unsigned n, literal const* lits);
|
||||||
void visit_expr(expr* e);
|
void visit_expr(expr* e);
|
||||||
|
|
|
@ -1430,10 +1430,9 @@ namespace pb {
|
||||||
IF_VERBOSE(0, verbose_stream() << *c << "\n");
|
IF_VERBOSE(0, verbose_stream() << *c << "\n");
|
||||||
VERIFY(c->well_formed());
|
VERIFY(c->well_formed());
|
||||||
if (m_solver && m_solver->get_config().m_drat) {
|
if (m_solver && m_solver->get_config().m_drat) {
|
||||||
std::function<void(std::ostream& out)> fn = [&](std::ostream& out) {
|
auto * out = s().get_drat().out();
|
||||||
out << "c ba constraint " << *c << " 0\n";
|
if (out)
|
||||||
};
|
*out << "c ba constraint " << *c << " 0\n";
|
||||||
m_solver->get_drat().log_adhoc(fn);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue