Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Z3Prover/z3
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolajBjorner committed Aug 26, 2022
2 parents 159026b + 458f417 commit dd91fab
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 71 deletions.
39 changes: 8 additions & 31 deletions src/sat/sat_drat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ namespace sat {
if (s.get_config().m_drat_binary)
std::swap(m_out, m_bout);
}
// m_print_clause = nullptr;
}

drat::~drat() {
Expand Down Expand Up @@ -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) {
TRACE("sat_drat", pp(tout, st) << " " << c << "\n";);
for (literal lit : c) declare(lit);
Expand Down Expand Up @@ -684,14 +658,15 @@ namespace sat {
verify(0, nullptr);
SASSERT(m_inconsistent);
}
if (m_print_clause) m_print_clause->on_clause(0, nullptr, status::redundant());
}
void drat::add(literal l, bool learned) {
++m_stats.m_num_add;
status st = get_status(learned);
if (m_out) dump(1, &l, st);
if (m_bout) bdump(1, &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) {
if (st.is_deleted())
Expand All @@ -702,7 +677,7 @@ namespace sat {
if (m_out) dump(2, ls, st);
if (m_bout) bdump(2, ls, 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) {
if (st.is_deleted())
Expand All @@ -712,7 +687,7 @@ namespace sat {
if (m_out) dump(c.size(), c.begin(), st);
if (m_bout) bdump(c.size(), c.begin(), 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) {
Expand All @@ -734,7 +709,8 @@ namespace sat {
if (m_out)
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) {
Expand All @@ -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) {
Expand Down
18 changes: 9 additions & 9 deletions src/sat/sat_drat.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ namespace sat {
class justification;
class clause;

struct print_clause {
virtual ~print_clause() {}
virtual void on_clause(unsigned, literal const*, status) = 0;
};

class drat {
struct stats {
unsigned m_num_drup = 0;
Expand All @@ -73,7 +78,7 @@ namespace sat {
watched_clause(clause* c, literal l1, literal 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;
typedef svector<unsigned> watch;
solver& s;
Expand Down Expand Up @@ -140,21 +145,16 @@ namespace sat {
void add(literal_vector const& c); // add learned clause
void add(unsigned sz, literal const* lits, status st);

void set_print_clause(std::function<void(unsigned, literal const*, status)>& print_clause) {
// m_print_clause = print_clause;
void set_print_clause(print_clause& print_clause) {
m_print_clause = &print_clause;
}

// support for SMT - connect Boolean variables with AST nodes
// 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
void def_begin(char id, unsigned n, std::string const& name);
void def_add_arg(unsigned arg);
void def_end();
std::ostream* out() { return m_out; }

// ad-hoc logging until a format is developed
void log_adhoc(std::function<void(std::ostream&)>& fn);

bool is_cleaned(clause& c) const;
void del(literal l);
Expand Down
62 changes: 44 additions & 18 deletions src/sat/smt/euf_proof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,31 @@ namespace euf {
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) {
for (unsigned i = f->get_num_parameters(); i-- > 0; ) {
auto const& p = f->get_parameter(i);
Expand All @@ -39,23 +64,24 @@ namespace euf {
drat_log_decl(to_func_decl(a));
}
}

void solver::drat_log_expr1(expr* e) {
if (is_app(e)) {
app* a = to_app(e);
drat_log_params(a->get_decl());
drat_log_decl(a->get_decl());
std::stringstream strm;
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)
get_drat().def_add_arg(arg->get_id());
get_drat().def_end();
def_add_arg(arg->get_id());
def_end();
}
else if (is_var(e)) {
var* v = to_var(e);
get_drat().def_begin('v', v->get_id(), "" + mk_pp(e->get_sort(), m));
get_drat().def_add_arg(v->get_idx());
get_drat().def_end();
def_begin('v', v->get_id(), "" + mk_pp(e->get_sort(), m));
def_add_arg(v->get_idx());
def_end();
}
else if (is_quantifier(e)) {
quantifier* q = to_quantifier(e);
Expand All @@ -64,9 +90,9 @@ namespace euf {
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 << ")";
get_drat().def_begin('q', q->get_id(), strm.str());
get_drat().def_add_arg(q->get_expr()->get_id());
get_drat().def_end();
def_begin('q', q->get_id(), strm.str());
def_add_arg(q->get_expr()->get_id());
def_end();
}
else
UNREACHABLE();
Expand Down Expand Up @@ -103,7 +129,7 @@ namespace euf {
if (!use_drat())
return;
drat_log_expr(e);
get_drat().bool_def(v, e->get_id());
bool_def(v, e->get_id());
}


Expand All @@ -117,8 +143,8 @@ namespace euf {
std::ostringstream strm;
smt2_pp_environment_dbg env(m);
ast_smt2_pp(strm, f, env);
get_drat().def_begin('f', f->get_small_id(), strm.str());
get_drat().def_end();
def_begin('f', f->get_small_id(), strm.str());
def_end();
}

/**
Expand Down Expand Up @@ -187,14 +213,14 @@ namespace euf {
VERIFY(m.is_eq(eq, a, b));
drat_log_expr(a);
drat_log_expr(b);
get_drat().def_begin('e', eq->get_id(), std::string("="));
get_drat().def_add_arg(a->get_id());
get_drat().def_add_arg(b->get_id());
get_drat().def_end();
get_drat().bool_def(lit.var(), eq->get_id());
def_begin('e', eq->get_id(), std::string("="));
def_add_arg(a->get_id());
def_add_arg(b->get_id());
def_end();
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)
return;
if (!st.is_redundant() && !st.is_asserted())
Expand Down
9 changes: 2 additions & 7 deletions src/sat/smt/euf_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,8 @@ namespace euf {
for (auto* s : m_solvers)
s->init_search();

if (get_config().m_lemmas2console) {
std::function<void(unsigned, sat::literal const*, sat::status)> on_clause =
[&](unsigned n, sat::literal const* lits, sat::status st) {
log_clause(n, lits, st);
};
get_drat().set_print_clause(on_clause);
}
if (get_config().m_lemmas2console)
get_drat().set_print_clause(*this);
}

bool solver::is_external(bool_var v) {
Expand Down
8 changes: 6 additions & 2 deletions src/sat/smt/euf_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace euf {
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;
friend class ackerman;
class user_sort;
Expand Down Expand Up @@ -183,7 +183,10 @@ namespace euf {
bool m_drat_initialized{ false };
void init_drat();
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
Expand Down Expand Up @@ -349,6 +352,7 @@ namespace euf {
void drat_bool_def(sat::bool_var v, expr* n);
void drat_eq_def(sat::literal lit, expr* eq);
void drat_log_expr(expr* n);
void bool_def(bool_var v, unsigned n);
bool visit_clause(unsigned n, literal const* lits);
void display_clause(unsigned n, literal const* lits);
void visit_expr(expr* e);
Expand Down
7 changes: 3 additions & 4 deletions src/sat/smt/pb_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1430,10 +1430,9 @@ namespace pb {
IF_VERBOSE(0, verbose_stream() << *c << "\n");
VERIFY(c->well_formed());
if (m_solver && m_solver->get_config().m_drat) {
std::function<void(std::ostream& out)> fn = [&](std::ostream& out) {
out << "c ba constraint " << *c << " 0\n";
};
m_solver->get_drat().log_adhoc(fn);
auto * out = s().get_drat().out();
if (out)
*out << "c ba constraint " << *c << " 0\n";
}
}

Expand Down

0 comments on commit dd91fab

Please sign in to comment.