mirror of
https://github.com/Z3Prover/z3
synced 2025-04-24 01:25:31 +00:00
core opt
This commit is contained in:
parent
127af83c53
commit
386c511f54
8 changed files with 182 additions and 56 deletions
|
@ -698,6 +698,33 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
lbool check_uninterpreted() {
|
||||
func_decl_ref_vector funs(m);
|
||||
m_goal2sat.get_interpreted_funs(funs);
|
||||
|
||||
if (!funs.empty()) {
|
||||
m_has_uninterpreted = true;
|
||||
std::stringstream strm;
|
||||
strm << "(sat.giveup interpreted functions sent to SAT solver " << funs <<")";
|
||||
TRACE("sat", tout << strm.str() << "\n";);
|
||||
IF_VERBOSE(1, verbose_stream() << strm.str() << "\n";);
|
||||
set_reason_unknown(strm.str());
|
||||
return l_undef;
|
||||
}
|
||||
return l_true;
|
||||
}
|
||||
|
||||
lbool internalize_goal(unsigned sz, expr* const* fmls) {
|
||||
m_solver.pop_to_base_level();
|
||||
if (m_solver.inconsistent())
|
||||
return l_false;
|
||||
m_pc.reset();
|
||||
m_goal2sat(m, sz, fmls, m_params, m_solver, m_map, m_dep2asm, is_incremental());
|
||||
if (!m_sat_mc) m_sat_mc = alloc(sat2goal::mc, m);
|
||||
m_sat_mc->flush_smc(m_solver, m_map);
|
||||
return check_uninterpreted();
|
||||
}
|
||||
|
||||
lbool internalize_goal(goal_ref& g) {
|
||||
m_solver.pop_to_base_level();
|
||||
if (m_solver.inconsistent())
|
||||
|
@ -712,12 +739,14 @@ private:
|
|||
}
|
||||
SASSERT(!g->proofs_enabled());
|
||||
TRACE("sat", m_solver.display(tout); g->display(tout););
|
||||
|
||||
try {
|
||||
if (m_is_cnf) {
|
||||
m_subgoals.push_back(g.get());
|
||||
}
|
||||
else {
|
||||
(*m_preprocess)(g, m_subgoals);
|
||||
m_is_cnf = true;
|
||||
}
|
||||
}
|
||||
catch (tactic_exception & ex) {
|
||||
|
@ -737,8 +766,8 @@ private:
|
|||
IF_VERBOSE(0, verbose_stream() << "size of subgoals is not 1, it is: " << m_subgoals.size() << "\n");
|
||||
return l_undef;
|
||||
}
|
||||
|
||||
g = m_subgoals[0];
|
||||
func_decl_ref_vector funs(m);
|
||||
m_pc = g->pc();
|
||||
m_mcs.set(m_mcs.size()-1, concat(m_mcs.back(), g->mc()));
|
||||
TRACE("sat", g->display_with_dependencies(tout););
|
||||
|
@ -746,19 +775,10 @@ private:
|
|||
// ensure that if goal is already internalized, then import mc from m_solver.
|
||||
|
||||
m_goal2sat(*g, m_params, m_solver, m_map, m_dep2asm, is_incremental());
|
||||
m_goal2sat.get_interpreted_funs(funs);
|
||||
|
||||
if (!m_sat_mc) m_sat_mc = alloc(sat2goal::mc, m);
|
||||
m_sat_mc->flush_smc(m_solver, m_map);
|
||||
if (!funs.empty()) {
|
||||
m_has_uninterpreted = true;
|
||||
std::stringstream strm;
|
||||
strm << "(sat.giveup interpreted functions sent to SAT solver " << funs <<")";
|
||||
TRACE("sat", tout << strm.str() << "\n";);
|
||||
IF_VERBOSE(1, verbose_stream() << strm.str() << "\n";);
|
||||
set_reason_unknown(strm.str());
|
||||
return l_undef;
|
||||
}
|
||||
return l_true;
|
||||
return check_uninterpreted();
|
||||
}
|
||||
|
||||
lbool internalize_assumptions(unsigned sz, expr* const* asms) {
|
||||
|
@ -766,17 +786,30 @@ private:
|
|||
m_asms.shrink(0);
|
||||
return l_true;
|
||||
}
|
||||
for (unsigned i = 0; i < sz; ++i)
|
||||
m_is_cnf &= is_literal(asms[i]);
|
||||
for (unsigned i = 0; i < get_num_assumptions(); ++i)
|
||||
m_is_cnf &= is_literal(get_assumption(i));
|
||||
|
||||
if (m_is_cnf) {
|
||||
// std::cout << "assumptions " << sz << " " << get_num_assumptions() << " " << m_fmls_head << " " << m_fmls.size() << "\n";
|
||||
expr_ref_vector fmls(m);
|
||||
fmls.append(sz, asms);
|
||||
for (unsigned i = 0; i < get_num_assumptions(); ++i)
|
||||
fmls.push_back(get_assumption(i));
|
||||
m_goal2sat.assumptions(m, fmls.size(), fmls.data(), m_params, m_solver, m_map, m_dep2asm, is_incremental());
|
||||
extract_assumptions(fmls.size(), fmls.data());
|
||||
return l_true;
|
||||
}
|
||||
|
||||
goal_ref g = alloc(goal, m, true, true); // models and cores are enabled.
|
||||
for (unsigned i = 0; i < sz; ++i) {
|
||||
for (unsigned i = 0; i < sz; ++i)
|
||||
g->assert_expr(asms[i], m.mk_leaf(asms[i]));
|
||||
}
|
||||
for (unsigned i = 0; i < get_num_assumptions(); ++i) {
|
||||
for (unsigned i = 0; i < get_num_assumptions(); ++i)
|
||||
g->assert_expr(get_assumption(i), m.mk_leaf(get_assumption(i)));
|
||||
}
|
||||
lbool res = internalize_goal(g);
|
||||
if (res == l_true) {
|
||||
if (res == l_true)
|
||||
extract_assumptions(sz, asms);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -905,18 +938,25 @@ private:
|
|||
}
|
||||
|
||||
lbool internalize_formulas() {
|
||||
if (m_fmls_head == m_fmls.size()) {
|
||||
if (m_fmls_head == m_fmls.size())
|
||||
return l_true;
|
||||
|
||||
lbool res;
|
||||
|
||||
if (m_is_cnf) {
|
||||
std::cout << "cnf\n";
|
||||
res = internalize_goal(m_fmls.size() - m_fmls_head, m_fmls.data() + m_fmls_head);
|
||||
}
|
||||
goal_ref g = alloc(goal, m, true, false); // models, maybe cores are enabled
|
||||
for (unsigned i = m_fmls_head ; i < m_fmls.size(); ++i) {
|
||||
expr* fml = m_fmls.get(i);
|
||||
g->assert_expr(fml);
|
||||
else {
|
||||
goal_ref g = alloc(goal, m, true, false); // models, maybe cores are enabled
|
||||
for (unsigned i = m_fmls_head ; i < m_fmls.size(); ++i) {
|
||||
expr* fml = m_fmls.get(i);
|
||||
g->assert_expr(fml);
|
||||
}
|
||||
res = internalize_goal(g);
|
||||
}
|
||||
lbool res = internalize_goal(g);
|
||||
if (res != l_undef) {
|
||||
if (res != l_undef)
|
||||
m_fmls_head = m_fmls.size();
|
||||
}
|
||||
m_internalized_converted = false;
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -894,16 +894,36 @@ struct goal2sat::imp : public sat::sat_internalizer {
|
|||
m_result_stack.pop_back();
|
||||
}
|
||||
|
||||
struct scoped_reset {
|
||||
imp& i;
|
||||
scoped_reset(imp& i) :i(i) {}
|
||||
~scoped_reset() {
|
||||
i.m_interface_vars.reset();
|
||||
i.m_app2lit.reset();
|
||||
i.m_lit2app.reset();
|
||||
}
|
||||
};
|
||||
|
||||
void operator()(unsigned n, expr* const* fmls) {
|
||||
scoped_reset _reset(*this);
|
||||
// collect_boolean_interface(g, m_interface_vars);
|
||||
for (unsigned i = 0; i < n; ++i)
|
||||
process(fmls[i]);
|
||||
}
|
||||
|
||||
void assumptions(unsigned n, expr* const* fmls) {
|
||||
scoped_reset _reset(*this);
|
||||
// collect_boolean_interface(g, m_interface_vars);
|
||||
for (unsigned i = 0; i < n; ++i) {
|
||||
expr* f = fmls[i];
|
||||
expr* f1 = f;
|
||||
bool sign = m.is_not(f, f1);
|
||||
insert_dep(f, f1, sign);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void operator()(goal const & g) {
|
||||
struct scoped_reset {
|
||||
imp& i;
|
||||
scoped_reset(imp& i) :i(i) {}
|
||||
~scoped_reset() {
|
||||
i.m_interface_vars.reset();
|
||||
i.m_app2lit.reset();
|
||||
i.m_lit2app.reset();
|
||||
}
|
||||
};
|
||||
scoped_reset _reset(*this);
|
||||
collect_boolean_interface(g, m_interface_vars);
|
||||
unsigned size = g.size();
|
||||
|
@ -1002,16 +1022,30 @@ void goal2sat::collect_param_descrs(param_descrs & r) {
|
|||
r.insert("ite_extra", CPK_BOOL, "(default: true) add redundant clauses (that improve unit propagation) when encoding if-then-else formulas");
|
||||
}
|
||||
|
||||
|
||||
void goal2sat::operator()(goal const & g, params_ref const & p, sat::solver_core & t, atom2bool_var & m, dep2asm_map& dep2asm, bool default_external) {
|
||||
void goal2sat::init(ast_manager& m, params_ref const & p, sat::solver_core & t, atom2bool_var & map, dep2asm_map& dep2asm, bool default_external) {
|
||||
if (!m_imp) {
|
||||
m_imp = alloc(imp, g.m(), p, t, m, dep2asm, default_external);
|
||||
m_imp = alloc(imp, m, p, t, map, dep2asm, default_external);
|
||||
for (unsigned i = 0; i < m_scopes; ++i)
|
||||
m_imp->user_push();
|
||||
}
|
||||
}
|
||||
|
||||
void goal2sat::operator()(goal const & g, params_ref const & p, sat::solver_core & t, atom2bool_var & m, dep2asm_map& dep2asm, bool default_external) {
|
||||
init(g.m(), p, t, m, dep2asm, default_external);
|
||||
(*m_imp)(g);
|
||||
}
|
||||
|
||||
void goal2sat::operator()(ast_manager& m, unsigned n, expr* const* fmls, params_ref const & p, sat::solver_core & t, atom2bool_var & map, dep2asm_map& dep2asm, bool default_external) {
|
||||
init(m, p, t, map, dep2asm, default_external);
|
||||
(*m_imp)(n, fmls);
|
||||
}
|
||||
|
||||
void goal2sat::assumptions(ast_manager& m, unsigned n, expr* const* fmls, params_ref const & p, sat::solver_core & t, atom2bool_var & map, dep2asm_map& dep2asm, bool default_external) {
|
||||
init(m, p, t, map, dep2asm, default_external);
|
||||
m_imp->assumptions(n, fmls);
|
||||
}
|
||||
|
||||
|
||||
void goal2sat::get_interpreted_funs(func_decl_ref_vector& funs) {
|
||||
if (m_imp)
|
||||
funs.append(m_imp->interpreted_funs());
|
||||
|
|
|
@ -34,15 +34,19 @@ Notes:
|
|||
#include "sat/smt/sat_internalizer.h"
|
||||
|
||||
class goal2sat {
|
||||
public:
|
||||
typedef obj_map<expr, sat::literal> dep2asm_map;
|
||||
private:
|
||||
struct imp;
|
||||
imp * m_imp;
|
||||
unsigned m_scopes { 0 };
|
||||
unsigned m_scopes = 0;
|
||||
|
||||
void init(ast_manager& m, params_ref const & p, sat::solver_core & t, atom2bool_var & map, dep2asm_map& dep2asm, bool default_external);
|
||||
|
||||
public:
|
||||
goal2sat();
|
||||
~goal2sat();
|
||||
|
||||
typedef obj_map<expr, sat::literal> dep2asm_map;
|
||||
|
||||
static void collect_param_descrs(param_descrs & r);
|
||||
|
||||
|
@ -60,6 +64,10 @@ public:
|
|||
*/
|
||||
void operator()(goal const & g, params_ref const & p, sat::solver_core & t, atom2bool_var & m, dep2asm_map& dep2asm, bool default_external = false);
|
||||
|
||||
void operator()(ast_manager& m, unsigned n, expr* const* fmls, params_ref const & p, sat::solver_core & t, atom2bool_var & map, dep2asm_map& dep2asm, bool default_external = false);
|
||||
|
||||
void assumptions(ast_manager& m, unsigned n, expr* const* fmls, params_ref const & p, sat::solver_core & t, atom2bool_var & map, dep2asm_map& dep2asm, bool default_external = false);
|
||||
|
||||
void get_interpreted_funs(func_decl_ref_vector& funs);
|
||||
|
||||
bool has_interpreted_funs() const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue