3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-08-22 11:07:51 +00:00

Merge branch 'master' of https://github.com/z3prover/z3 into xor

This commit is contained in:
Nikolaj Bjorner 2022-11-10 10:42:38 -08:00
commit 08a925323c
67 changed files with 1057 additions and 379 deletions

View file

@ -49,6 +49,7 @@ z3_add_component(core_tactics
reduce_invertible_tactic.h
simplify_tactic.h
solve_eqs_tactic.h
solve_eqs2_tactic.h
special_relations_tactic.h
split_clause_tactic.h
symmetry_reduce_tactic.h

View file

@ -29,10 +29,15 @@ public:
}
};
inline tactic * mk_solve_eqs2_tactic(ast_manager& m, params_ref const& p) {
return alloc(dependent_expr_state_tactic, m, p, alloc(solve_eqs2_tactic_factory), "solve-eqs2");
inline tactic * mk_solve_eqs2_tactic(ast_manager& m, params_ref const& p = params_ref()) {
return alloc(dependent_expr_state_tactic, m, p, alloc(solve_eqs2_tactic_factory), "solve-eqs");
}
#if 1
inline tactic * mk_solve_eqs_tactic(ast_manager & m, params_ref const & p = params_ref()) {
return mk_solve_eqs2_tactic(m, p);
}
#endif
/*
ADD_TACTIC("solve-eqs2", "solve for variables.", "mk_solve_eqs2_tactic(m, p)")

View file

@ -425,6 +425,7 @@ class solve_eqs_tactic : public tactic {
else
pr = m().mk_modus_ponens(g.pr(idx), pr);
}
IF_VERBOSE(11, verbose_stream() << mk_bounded_pp(var, m()) << " -> " << mk_bounded_pp(def, m()) << "\n");
m_subst->insert(var, def, pr, g.dep(idx));
}
@ -479,52 +480,11 @@ class solve_eqs_tactic : public tactic {
ptr_vector<expr> m_todo;
void mark_occurs(expr_mark& occ, goal const& g, expr* v) {
expr_fast_mark2 visited;
occ.mark(v, true);
visited.mark(v, true);
for (unsigned j = 0; j < g.size(); ++j) {
m_todo.push_back(g.form(j));
}
while (!m_todo.empty()) {
expr* e = m_todo.back();
if (visited.is_marked(e)) {
m_todo.pop_back();
continue;
}
if (is_app(e)) {
bool does_occur = false;
bool all_visited = true;
for (expr* arg : *to_app(e)) {
if (!visited.is_marked(arg)) {
m_todo.push_back(arg);
all_visited = false;
}
else {
does_occur |= occ.is_marked(arg);
}
}
if (all_visited) {
occ.mark(e, does_occur);
visited.mark(e, true);
m_todo.pop_back();
}
}
else if (is_quantifier(e)) {
expr* body = to_quantifier(e)->get_expr();
if (visited.is_marked(body)) {
visited.mark(e, true);
occ.mark(e, occ.is_marked(body));
m_todo.pop_back();
}
else {
m_todo.push_back(body);
}
}
else {
visited.mark(e, true);
m_todo.pop_back();
}
}
SASSERT(m_todo.empty());
for (unsigned j = 0; j < g.size(); ++j)
m_todo.push_back(g.form(j));
::mark_occurs(m_todo, v, occ);
SASSERT(m_todo.empty());
}
expr_mark m_compatible_tried;
@ -661,9 +621,11 @@ class solve_eqs_tactic : public tactic {
expr* arg = args.get(i), *lhs = nullptr, *rhs = nullptr;
if (m().is_eq(arg, lhs, rhs) && !m().is_bool(lhs)) {
if (trivial_solve1(lhs, rhs, var, def, pr) && is_compatible(g, idx, path, var, arg)) {
IF_VERBOSE(11, verbose_stream() << "nested " << mk_bounded_pp(var.get(), m()) << " -> " << mk_bounded_pp(def, m()) << "\n");
insert_solution(g, idx, arg, var, def, pr);
}
else if (trivial_solve1(rhs, lhs, var, def, pr) && is_compatible(g, idx, path, var, arg)) {
IF_VERBOSE(11, verbose_stream() << "nested " << mk_bounded_pp(var.get(), m()) << " -> " << mk_bounded_pp(def, m()) << "\n");
insert_solution(g, idx, arg, var, def, pr);
}
else {
@ -1022,6 +984,10 @@ class solve_eqs_tactic : public tactic {
unsigned get_num_eliminated_vars() const {
return m_num_eliminated_vars;
}
void collect_statistics(statistics& st) {
st.update("solve eqs elim vars", get_num_eliminated_vars());
}
//
// TBD: rewrite the tactic to first apply a topological sorting that
@ -1031,6 +997,8 @@ class solve_eqs_tactic : public tactic {
//
void operator()(goal_ref const & g, goal_ref_buffer & result) {
model_converter_ref mc;
std::function<void(statistics&)> coll = [&](statistics& st) { collect_statistics(st); };
statistics_report sreport(coll);
tactic_report report("solve_eqs", *g);
TRACE("goal", g->display(tout););
m_produce_models = g->models_enabled();
@ -1074,6 +1042,8 @@ class solve_eqs_tactic : public tactic {
g->inc_depth();
g->add(mc.get());
result.push_back(g.get());
}
};
@ -1107,7 +1077,6 @@ public:
void operator()(goal_ref const & in,
goal_ref_buffer & result) override {
(*m_imp)(in, result);
report_tactic_progress(":num-elim-vars", m_imp->get_num_eliminated_vars());
}
void cleanup() override {
@ -1126,7 +1095,7 @@ public:
}
void collect_statistics(statistics & st) const override {
st.update("eliminated vars", m_imp->get_num_eliminated_vars());
m_imp->collect_statistics(st);
}
void reset_statistics() override {
@ -1135,6 +1104,7 @@ public:
};
tactic * mk_solve_eqs_tactic(ast_manager & m, params_ref const & p) {
tactic * mk_solve_eqs1_tactic(ast_manager & m, params_ref const & p) {
return clean(alloc(solve_eqs_tactic, m, p, mk_expr_simp_replacer(m, p), true));
}

View file

@ -22,10 +22,17 @@ Revision History:
class ast_manager;
class tactic;
tactic * mk_solve_eqs_tactic(ast_manager & m, params_ref const & p = params_ref());
tactic * mk_solve_eqs1_tactic(ast_manager & m, params_ref const & p = params_ref());
#if 0
inline tactic * mk_solve_eqs_tactic(ast_manager & m, params_ref const & p = params_ref()) {
return mk_solve_eqs1_tactic(m, p);
}
#endif
/*
ADD_TACTIC("solve-eqs", "eliminate variables by solving equations.", "mk_solve_eqs_tactic(m, p)")
ADD_TACTIC("solve-eqs", "eliminate variables by solving equations.", "mk_solve_eqs1_tactic(m, p)")
*/

View file

@ -22,14 +22,21 @@ class dependent_expr_state_tactic : public tactic, public dependent_expr_state {
ast_manager& m;
params_ref m_params;
std::string m_name;
ref<dependent_expr_simplifier_factory> m_factory;
scoped_ptr<dependent_expr_simplifier> m_simp;
trail_stack m_trail;
goal_ref m_goal;
dependent_expr m_dep;
statistics m_st;
ref<dependent_expr_simplifier_factory> m_factory;
scoped_ptr<dependent_expr_simplifier> m_simp;
scoped_ptr<model_reconstruction_trail> m_model_trail;
void init() {
if (!m_simp)
if (!m_simp) {
m_simp = m_factory->mk(m, m_params, *this);
m_st.reset();
}
if (!m_model_trail)
m_model_trail = alloc(model_reconstruction_trail, m, m_trail);
}
public:
@ -39,7 +46,7 @@ public:
m_params(p),
m_name(name),
m_factory(f),
m_simp(f->mk(m, p, *this)),
m_simp(nullptr),
m_dep(m, m.mk_true(), nullptr)
{}
@ -60,6 +67,10 @@ public:
bool inconsistent() override {
return m_goal->inconsistent();
}
model_reconstruction_trail& model_trail() override {
return *m_model_trail;
}
char const* name() const override { return m_name.c_str(); }
@ -75,29 +86,39 @@ public:
void operator()(goal_ref const & in,
goal_ref_buffer & result) override {
if (in->proofs_enabled())
throw tactic_exception("tactic does not support low level proofs");
init();
statistics_report sreport(*this);
tactic_report report(name(), *in);
m_goal = in.get();
m_simp->reduce();
if (!in->proofs_enabled())
m_simp->reduce();
m_goal->elim_true();
m_goal->inc_depth();
if (in->models_enabled())
in->set(m_simp->get_model_converter().get());
result.push_back(in.get());
in->add(m_model_trail->get_model_converter().get());
result.push_back(in.get());
cleanup();
}
void cleanup() override {
if (m_simp)
m_simp->collect_statistics(m_st);
m_simp = nullptr;
m_model_trail = nullptr;
}
void collect_statistics(statistics & st) const override {
if (m_simp)
if (m_simp)
m_simp->collect_statistics(st);
else
st.copy(m_st);
}
void reset_statistics() override {
if (m_simp)
m_simp->reset_statistics();
m_st.reset();
}
};

View file

@ -18,6 +18,7 @@ Notes:
--*/
#include "ast/normal_forms/nnf.h"
#include "tactic/core/solve_eqs_tactic.h"
#include "tactic/core/solve_eqs2_tactic.h"
#include "tactic/bv/bv_size_reduction_tactic.h"
#include "tactic/bv/max_bv_sharing_tactic.h"
#include "tactic/core/simplify_tactic.h"

View file

@ -17,6 +17,7 @@ Notes:
--*/
#include "tactic/core/solve_eqs_tactic.h"
#include "tactic/core/solve_eqs2_tactic.h"
#include "tactic/core/simplify_tactic.h"
#include "tactic/core/propagate_values_tactic.h"
#include "tactic/bv/bit_blaster_tactic.h"

View file

@ -21,6 +21,7 @@ Notes:
#include "tactic/core/propagate_values_tactic.h"
#include "tactic/arith/propagate_ineqs_tactic.h"
#include "tactic/core/solve_eqs_tactic.h"
#include "tactic/core/solve_eqs2_tactic.h"
#include "tactic/core/elim_uncnstr_tactic.h"
#include "tactic/smtlogics/smt_tactic.h"

View file

@ -20,6 +20,7 @@ Notes:
#include "tactic/core/simplify_tactic.h"
#include "tactic/core/propagate_values_tactic.h"
#include "tactic/core/solve_eqs_tactic.h"
#include "tactic/core/solve_eqs2_tactic.h"
#include "tactic/core/elim_uncnstr_tactic.h"
#include "tactic/bv/bit_blaster_tactic.h"
#include "tactic/bv/bv1_blaster_tactic.h"
@ -39,6 +40,9 @@ static tactic * mk_qfbv_preamble(ast_manager& m, params_ref const& p) {
// conservative gaussian elimination.
solve_eq_p.set_uint("solve_eqs_max_occs", 2);
params_ref flat_and_or_p = p;
flat_and_or_p.set_bool("flat_and_or", false);
params_ref simp2_p = p;
simp2_p.set_bool("som", true);
simp2_p.set_bool("pull_cheap_ite", true);
@ -47,15 +51,17 @@ static tactic * mk_qfbv_preamble(ast_manager& m, params_ref const& p) {
simp2_p.set_uint("local_ctx_limit", 10000000);
simp2_p.set_bool("flat", true); // required by som
simp2_p.set_bool("hoist_mul", false); // required by som
simp2_p.set_bool("flat_and_or", false);
params_ref hoist_p;
hoist_p.set_bool("hoist_mul", true);
hoist_p.set_bool("som", false);
hoist_p.set_bool("flat_and_or", false);
return
and_then(
mk_simplify_tactic(m),
mk_propagate_values_tactic(m),
using_params(mk_simplify_tactic(m), flat_and_or_p),
using_params(mk_propagate_values_tactic(m), flat_and_or_p),
using_params(mk_solve_eqs_tactic(m), solve_eq_p),
mk_elim_uncnstr_tactic(m),
if_no_proofs(if_no_unsat_cores(mk_bv_size_reduction_tactic(m))),
@ -87,6 +93,7 @@ static tactic * mk_qfbv_tactic(ast_manager& m, params_ref const & p, tactic* sat
params_ref local_ctx_p = p;
local_ctx_p.set_bool("local_ctx", true);
local_ctx_p.set_bool("flat", false);
local_ctx_p.set_bool("flat_and_or", false);
params_ref solver_p;
solver_p.set_bool("preprocess", false); // preprocessor of smt::context is not needed.

View file

@ -21,6 +21,7 @@ Notes:
#include "tactic/core/propagate_values_tactic.h"
#include "tactic/arith/propagate_ineqs_tactic.h"
#include "tactic/core/solve_eqs_tactic.h"
#include "tactic/core/solve_eqs2_tactic.h"
#include "tactic/core/elim_uncnstr_tactic.h"
#include "tactic/arith/normalize_bounds_tactic.h"
#include "tactic/arith/fix_dl_var_tactic.h"

View file

@ -22,6 +22,7 @@ Notes:
#include "tactic/arith/propagate_ineqs_tactic.h"
#include "tactic/arith/normalize_bounds_tactic.h"
#include "tactic/core/solve_eqs_tactic.h"
#include "tactic/core/solve_eqs2_tactic.h"
#include "tactic/core/elim_uncnstr_tactic.h"
#include "tactic/arith/add_bounds_tactic.h"
#include "tactic/arith/pb2bv_tactic.h"

View file

@ -21,6 +21,7 @@ Notes:
#include "tactic/core/simplify_tactic.h"
#include "tactic/core/symmetry_reduce_tactic.h"
#include "tactic/core/solve_eqs_tactic.h"
#include "tactic/core/solve_eqs2_tactic.h"
#include "tactic/core/propagate_values_tactic.h"
#include "tactic/smtlogics/smt_tactic.h"

View file

@ -21,6 +21,7 @@ Notes:
#include "tactic/core/simplify_tactic.h"
#include "tactic/core/propagate_values_tactic.h"
#include "tactic/core/solve_eqs_tactic.h"
#include "tactic/core/solve_eqs2_tactic.h"
#include "tactic/core/elim_uncnstr_tactic.h"
#include "tactic/bv/max_bv_sharing_tactic.h"
#include "tactic/bv/bv_size_reduction_tactic.h"
@ -136,22 +137,23 @@ private:
};
static tactic * mk_qfufbv_preamble1(ast_manager & m, params_ref const & p) {
params_ref simp2_p = p;
params_ref simp2_p = p, flat_and_or_p = p;
flat_and_or_p.set_bool("flat_and_or", false);
simp2_p.set_bool("pull_cheap_ite", true);
simp2_p.set_bool("push_ite_bv", false);
simp2_p.set_bool("local_ctx", true);
simp2_p.set_uint("local_ctx_limit", 10000000);
simp2_p.set_bool("ite_extra_rules", true);
simp2_p.set_bool("mul2concat", true);
simp2_p.set_bool("flat_and_or", false);
params_ref ctx_simp_p;
ctx_simp_p.set_uint("max_depth", 32);
ctx_simp_p.set_uint("max_steps", 5000000);
return and_then(
mk_simplify_tactic(m),
mk_propagate_values_tactic(m),
using_params(mk_simplify_tactic(m), flat_and_or_p),
using_params(mk_propagate_values_tactic(m), flat_and_or_p),
if_no_proofs(if_no_unsat_cores(mk_bv_bound_chk_tactic(m))),
//using_params(mk_ctx_simplify_tactic(m_m), ctx_simp_p),
mk_solve_eqs_tactic(m),
@ -163,8 +165,10 @@ static tactic * mk_qfufbv_preamble1(ast_manager & m, params_ref const & p) {
}
static tactic * mk_qfufbv_preamble(ast_manager & m, params_ref const & p) {
return and_then(mk_simplify_tactic(m),
mk_propagate_values_tactic(m),
params_ref simp2_p = p, flat_and_or_p = p;
flat_and_or_p.set_bool("flat_and_or", false);
return and_then(using_params(mk_simplify_tactic(m), flat_and_or_p),
using_params(mk_propagate_values_tactic(m), flat_and_or_p),
mk_solve_eqs_tactic(m),
mk_elim_uncnstr_tactic(m),
if_no_proofs(if_no_unsat_cores(mk_reduce_args_tactic(m))),

View file

@ -20,6 +20,7 @@ Revision History:
#include "tactic/core/simplify_tactic.h"
#include "tactic/core/propagate_values_tactic.h"
#include "tactic/core/solve_eqs_tactic.h"
#include "tactic/core/solve_eqs2_tactic.h"
#include "tactic/core/elim_uncnstr_tactic.h"
#include "qe/lite/qe_lite.h"
#include "qe/qsat.h"

View file

@ -75,6 +75,18 @@ void report_tactic_progress(char const * id, unsigned val) {
}
}
statistics_report::~statistics_report() {
statistics st;
if (m_tactic)
m_tactic->collect_statistics(st);
else if (m_collector)
m_collector(st);
if (st.size() == 0)
return;
IF_VERBOSE(TACTIC_VERBOSITY_LVL, st.display_smt2(verbose_stream()));
}
void skip_tactic::operator()(goal_ref const & in, goal_ref_buffer& result) {
result.push_back(in.get());
}

View file

@ -115,6 +115,15 @@ public:
void report_tactic_progress(char const * id, unsigned val);
class statistics_report {
tactic* m_tactic = nullptr;
std::function<void(statistics& st)> m_collector;
public:
statistics_report(tactic& t):m_tactic(&t) {}
statistics_report(std::function<void(statistics&)>& coll): m_collector(coll) {}
~statistics_report();
};
class skip_tactic : public tactic {
public:
void operator()(goal_ref const & in, goal_ref_buffer& result) override;

View file

@ -20,6 +20,7 @@ Notes:
#include "tactic/core/simplify_tactic.h"
#include "tactic/core/propagate_values_tactic.h"
#include "tactic/core/solve_eqs_tactic.h"
#include "tactic/core/solve_eqs2_tactic.h"
#include "tactic/core/distribute_forall_tactic.h"
#include "tactic/core/der_tactic.h"
#include "tactic/core/reduce_args_tactic.h"