mirror of
https://github.com/Z3Prover/z3
synced 2025-04-24 01:25:31 +00:00
Merge branch 'master' into regex-develop
This commit is contained in:
commit
49b810e00f
108 changed files with 899 additions and 1457 deletions
|
@ -663,7 +663,6 @@ basic_decl_plugin::basic_decl_plugin():
|
|||
m_not_or_elim_decl(nullptr),
|
||||
m_rewrite_decl(nullptr),
|
||||
m_pull_quant_decl(nullptr),
|
||||
m_pull_quant_star_decl(nullptr),
|
||||
m_push_quant_decl(nullptr),
|
||||
m_elim_unused_vars_decl(nullptr),
|
||||
m_der_decl(nullptr),
|
||||
|
@ -827,7 +826,6 @@ func_decl * basic_decl_plugin::mk_proof_decl(basic_op_kind k, unsigned num_paren
|
|||
case PR_REWRITE: return mk_proof_decl("rewrite", k, 0, m_rewrite_decl);
|
||||
case PR_REWRITE_STAR: return mk_proof_decl("rewrite*", k, num_parents, m_rewrite_star_decls);
|
||||
case PR_PULL_QUANT: return mk_proof_decl("pull-quant", k, 0, m_pull_quant_decl);
|
||||
case PR_PULL_QUANT_STAR: return mk_proof_decl("pull-quant*", k, 0, m_pull_quant_star_decl);
|
||||
case PR_PUSH_QUANT: return mk_proof_decl("push-quant", k, 0, m_push_quant_decl);
|
||||
case PR_ELIM_UNUSED_VARS: return mk_proof_decl("elim-unused", k, 0, m_elim_unused_vars_decl);
|
||||
case PR_DER: return mk_proof_decl("der", k, 0, m_der_decl);
|
||||
|
@ -844,8 +842,6 @@ func_decl * basic_decl_plugin::mk_proof_decl(basic_op_kind k, unsigned num_paren
|
|||
case PR_IFF_OEQ: return mk_proof_decl("iff~", k, 1, m_iff_oeq_decl);
|
||||
case PR_NNF_POS: return mk_proof_decl("nnf-pos", k, num_parents, m_nnf_pos_decls);
|
||||
case PR_NNF_NEG: return mk_proof_decl("nnf-neg", k, num_parents, m_nnf_neg_decls);
|
||||
case PR_NNF_STAR: return mk_proof_decl("nnf*", k, num_parents, m_nnf_star_decls);
|
||||
case PR_CNF_STAR: return mk_proof_decl("cnf*", k, num_parents, m_cnf_star_decls);
|
||||
case PR_SKOLEMIZE: return mk_proof_decl("sk", k, 0, m_skolemize_decl);
|
||||
case PR_MODUS_PONENS_OEQ: return mk_proof_decl("mp~", k, 2, m_mp_oeq_decl);
|
||||
case PR_TH_LEMMA: return mk_proof_decl("th-lemma", k, num_parents, m_th_lemma_decls);
|
||||
|
@ -949,7 +945,6 @@ void basic_decl_plugin::finalize() {
|
|||
DEC_REF(m_not_or_elim_decl);
|
||||
DEC_REF(m_rewrite_decl);
|
||||
DEC_REF(m_pull_quant_decl);
|
||||
DEC_REF(m_pull_quant_star_decl);
|
||||
DEC_REF(m_push_quant_decl);
|
||||
DEC_REF(m_elim_unused_vars_decl);
|
||||
DEC_REF(m_der_decl);
|
||||
|
@ -975,8 +970,6 @@ void basic_decl_plugin::finalize() {
|
|||
DEC_ARRAY_REF(m_apply_def_decls);
|
||||
DEC_ARRAY_REF(m_nnf_pos_decls);
|
||||
DEC_ARRAY_REF(m_nnf_neg_decls);
|
||||
DEC_ARRAY_REF(m_nnf_star_decls);
|
||||
DEC_ARRAY_REF(m_cnf_star_decls);
|
||||
|
||||
DEC_ARRAY_REF(m_th_lemma_decls);
|
||||
DEC_REF(m_hyper_res_decl0);
|
||||
|
@ -1532,32 +1525,39 @@ void ast_manager::copy_families_plugins(ast_manager const & from) {
|
|||
tout << "fid: " << fid << " fidname: " << get_family_name(fid) << "\n";
|
||||
});
|
||||
ast_translation trans(const_cast<ast_manager&>(from), *this, false);
|
||||
// Inheriting plugins can create new family ids. Since new family ids are
|
||||
// assigned in the order that they are created, this can result in differing
|
||||
// family ids. To avoid this, we first assign all family ids and only then inherit plugins.
|
||||
for (family_id fid = 0; from.m_family_manager.has_family(fid); fid++) {
|
||||
SASSERT(from.is_builtin_family_id(fid) == is_builtin_family_id(fid));
|
||||
SASSERT(!from.is_builtin_family_id(fid) || m_family_manager.has_family(fid));
|
||||
symbol fid_name = from.get_family_name(fid);
|
||||
TRACE("copy_families_plugins", tout << "copying: " << fid_name << ", src fid: " << fid
|
||||
<< ", target has_family: " << m_family_manager.has_family(fid) << "\n";
|
||||
if (m_family_manager.has_family(fid)) tout << get_family_id(fid_name) << "\n";);
|
||||
if (!m_family_manager.has_family(fid)) {
|
||||
family_id new_fid = mk_family_id(fid_name);
|
||||
(void)new_fid;
|
||||
TRACE("copy_families_plugins", tout << "new target fid created: " << new_fid << " fid_name: " << fid_name << "\n";);
|
||||
}
|
||||
TRACE("copy_families_plugins", tout << "target fid: " << get_family_id(fid_name) << "\n";);
|
||||
SASSERT(fid == get_family_id(fid_name));
|
||||
if (from.has_plugin(fid) && !has_plugin(fid)) {
|
||||
decl_plugin * new_p = from.get_plugin(fid)->mk_fresh();
|
||||
register_plugin(fid, new_p);
|
||||
SASSERT(new_p->get_family_id() == fid);
|
||||
SASSERT(has_plugin(fid));
|
||||
}
|
||||
if (from.has_plugin(fid)) {
|
||||
get_plugin(fid)->inherit(from.get_plugin(fid), trans);
|
||||
}
|
||||
SASSERT(from.m_family_manager.has_family(fid) == m_family_manager.has_family(fid));
|
||||
SASSERT(from.get_family_id(fid_name) == get_family_id(fid_name));
|
||||
SASSERT(!from.has_plugin(fid) || has_plugin(fid));
|
||||
symbol fid_name = from.get_family_name(fid);
|
||||
if (!m_family_manager.has_family(fid)) {
|
||||
family_id new_fid = mk_family_id(fid_name);
|
||||
(void)new_fid;
|
||||
TRACE("copy_families_plugins", tout << "new target fid created: " << new_fid << " fid_name: " << fid_name << "\n";);
|
||||
}
|
||||
}
|
||||
for (family_id fid = 0; from.m_family_manager.has_family(fid); fid++) {
|
||||
SASSERT(from.is_builtin_family_id(fid) == is_builtin_family_id(fid));
|
||||
SASSERT(!from.is_builtin_family_id(fid) || m_family_manager.has_family(fid));
|
||||
symbol fid_name = from.get_family_name(fid);
|
||||
(void)fid_name;
|
||||
TRACE("copy_families_plugins", tout << "copying: " << fid_name << ", src fid: " << fid
|
||||
<< ", target has_family: " << m_family_manager.has_family(fid) << "\n";
|
||||
if (m_family_manager.has_family(fid)) tout << get_family_id(fid_name) << "\n";);
|
||||
TRACE("copy_families_plugins", tout << "target fid: " << get_family_id(fid_name) << "\n";);
|
||||
SASSERT(fid == get_family_id(fid_name));
|
||||
if (from.has_plugin(fid) && !has_plugin(fid)) {
|
||||
decl_plugin * new_p = from.get_plugin(fid)->mk_fresh();
|
||||
register_plugin(fid, new_p);
|
||||
SASSERT(new_p->get_family_id() == fid);
|
||||
SASSERT(has_plugin(fid));
|
||||
}
|
||||
if (from.has_plugin(fid)) {
|
||||
get_plugin(fid)->inherit(from.get_plugin(fid), trans);
|
||||
}
|
||||
SASSERT(from.m_family_manager.has_family(fid) == m_family_manager.has_family(fid));
|
||||
SASSERT(from.get_family_id(fid_name) == get_family_id(fid_name));
|
||||
SASSERT(!from.has_plugin(fid) || has_plugin(fid));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2837,12 +2837,6 @@ proof * ast_manager::mk_pull_quant(expr * e, quantifier * q) {
|
|||
return mk_app(m_basic_family_id, PR_PULL_QUANT, mk_iff(e, q));
|
||||
}
|
||||
|
||||
proof * ast_manager::mk_pull_quant_star(expr * e, quantifier * q) {
|
||||
if (proofs_disabled())
|
||||
return nullptr;
|
||||
return mk_app(m_basic_family_id, PR_PULL_QUANT_STAR, mk_iff(e, q));
|
||||
}
|
||||
|
||||
proof * ast_manager::mk_push_quant(quantifier * q, expr * e) {
|
||||
if (proofs_disabled())
|
||||
return nullptr;
|
||||
|
@ -3087,15 +3081,6 @@ proof * ast_manager::mk_nnf_neg(expr * s, expr * t, unsigned num_proofs, proof *
|
|||
return mk_app(m_basic_family_id, PR_NNF_NEG, args.size(), args.c_ptr());
|
||||
}
|
||||
|
||||
proof * ast_manager::mk_nnf_star(expr * s, expr * t, unsigned num_proofs, proof * const * proofs) {
|
||||
if (proofs_disabled())
|
||||
return nullptr;
|
||||
ptr_buffer<expr> args;
|
||||
args.append(num_proofs, (expr**) proofs);
|
||||
args.push_back(mk_oeq(s, t));
|
||||
return mk_app(m_basic_family_id, PR_NNF_STAR, args.size(), args.c_ptr());
|
||||
}
|
||||
|
||||
proof * ast_manager::mk_skolemization(expr * q, expr * e) {
|
||||
if (proofs_disabled())
|
||||
return nullptr;
|
||||
|
@ -3104,15 +3089,6 @@ proof * ast_manager::mk_skolemization(expr * q, expr * e) {
|
|||
return mk_app(m_basic_family_id, PR_SKOLEMIZE, mk_oeq(q, e));
|
||||
}
|
||||
|
||||
proof * ast_manager::mk_cnf_star(expr * s, expr * t, unsigned num_proofs, proof * const * proofs) {
|
||||
if (proofs_disabled())
|
||||
return nullptr;
|
||||
ptr_buffer<expr> args;
|
||||
args.append(num_proofs, (expr**) proofs);
|
||||
args.push_back(mk_oeq(s, t));
|
||||
return mk_app(m_basic_family_id, PR_CNF_STAR, args.size(), args.c_ptr());
|
||||
}
|
||||
|
||||
proof * ast_manager::mk_and_elim(proof * p, unsigned i) {
|
||||
if (proofs_disabled())
|
||||
return nullptr;
|
||||
|
|
|
@ -1042,11 +1042,11 @@ enum basic_op_kind {
|
|||
|
||||
PR_UNDEF, PR_TRUE, PR_ASSERTED, PR_GOAL, PR_MODUS_PONENS, PR_REFLEXIVITY, PR_SYMMETRY, PR_TRANSITIVITY, PR_TRANSITIVITY_STAR, PR_MONOTONICITY, PR_QUANT_INTRO,
|
||||
PR_DISTRIBUTIVITY, PR_AND_ELIM, PR_NOT_OR_ELIM, PR_REWRITE, PR_REWRITE_STAR, PR_PULL_QUANT,
|
||||
PR_PULL_QUANT_STAR, PR_PUSH_QUANT, PR_ELIM_UNUSED_VARS, PR_DER, PR_QUANT_INST,
|
||||
PR_PUSH_QUANT, PR_ELIM_UNUSED_VARS, PR_DER, PR_QUANT_INST,
|
||||
|
||||
PR_HYPOTHESIS, PR_LEMMA, PR_UNIT_RESOLUTION, PR_IFF_TRUE, PR_IFF_FALSE, PR_COMMUTATIVITY, PR_DEF_AXIOM,
|
||||
|
||||
PR_DEF_INTRO, PR_APPLY_DEF, PR_IFF_OEQ, PR_NNF_POS, PR_NNF_NEG, PR_NNF_STAR, PR_SKOLEMIZE, PR_CNF_STAR,
|
||||
PR_DEF_INTRO, PR_APPLY_DEF, PR_IFF_OEQ, PR_NNF_POS, PR_NNF_NEG, PR_SKOLEMIZE,
|
||||
PR_MODUS_PONENS_OEQ, PR_TH_LEMMA, PR_HYPER_RESOLVE, LAST_BASIC_PR
|
||||
};
|
||||
|
||||
|
@ -1080,7 +1080,6 @@ protected:
|
|||
func_decl * m_not_or_elim_decl;
|
||||
func_decl * m_rewrite_decl;
|
||||
func_decl * m_pull_quant_decl;
|
||||
func_decl * m_pull_quant_star_decl;
|
||||
func_decl * m_push_quant_decl;
|
||||
func_decl * m_elim_unused_vars_decl;
|
||||
func_decl * m_der_decl;
|
||||
|
@ -1106,8 +1105,6 @@ protected:
|
|||
ptr_vector<func_decl> m_apply_def_decls;
|
||||
ptr_vector<func_decl> m_nnf_pos_decls;
|
||||
ptr_vector<func_decl> m_nnf_neg_decls;
|
||||
ptr_vector<func_decl> m_nnf_star_decls;
|
||||
ptr_vector<func_decl> m_cnf_star_decls;
|
||||
|
||||
ptr_vector<func_decl> m_th_lemma_decls;
|
||||
func_decl * m_hyper_res_decl0;
|
||||
|
@ -2182,7 +2179,6 @@ public:
|
|||
proof * mk_oeq_rewrite(expr * s, expr * t);
|
||||
proof * mk_rewrite_star(expr * s, expr * t, unsigned num_proofs, proof * const * proofs);
|
||||
proof * mk_pull_quant(expr * e, quantifier * q);
|
||||
proof * mk_pull_quant_star(expr * e, quantifier * q);
|
||||
proof * mk_push_quant(quantifier * q, expr * e);
|
||||
proof * mk_elim_unused_vars(quantifier * q, expr * r);
|
||||
proof * mk_der(quantifier * q, expr * r);
|
||||
|
@ -2201,9 +2197,8 @@ public:
|
|||
|
||||
proof * mk_nnf_pos(expr * s, expr * t, unsigned num_proofs, proof * const * proofs);
|
||||
proof * mk_nnf_neg(expr * s, expr * t, unsigned num_proofs, proof * const * proofs);
|
||||
proof * mk_nnf_star(expr * s, expr * t, unsigned num_proofs, proof * const * proofs);
|
||||
proof * mk_skolemization(expr * q, expr * e);
|
||||
proof * mk_cnf_star(expr * s, expr * t, unsigned num_proofs, proof * const * proofs);
|
||||
|
||||
|
||||
proof * mk_and_elim(proof * p, unsigned i);
|
||||
proof * mk_not_or_elim(proof * p, unsigned i);
|
||||
|
|
|
@ -38,6 +38,7 @@ void ast_pp_util::collect(expr_ref_vector const& es) {
|
|||
void ast_pp_util::display_decls(std::ostream& out) {
|
||||
smt2_pp_environment_dbg env(m);
|
||||
ast_smt_pp pp(m);
|
||||
coll.order_deps();
|
||||
unsigned n = coll.get_num_sorts();
|
||||
for (unsigned i = 0; i < n; ++i) {
|
||||
pp.display_ast_smt2(out, coll.get_sorts()[i], 0, 0, nullptr);
|
||||
|
@ -45,13 +46,18 @@ void ast_pp_util::display_decls(std::ostream& out) {
|
|||
n = coll.get_num_decls();
|
||||
for (unsigned i = 0; i < n; ++i) {
|
||||
func_decl* f = coll.get_func_decls()[i];
|
||||
if (f->get_family_id() == null_family_id) {
|
||||
if (f->get_family_id() == null_family_id && !m_removed.contains(f)) {
|
||||
ast_smt2_pp(out, f, env);
|
||||
out << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ast_pp_util::remove_decl(func_decl* f) {
|
||||
m_removed.insert(f);
|
||||
}
|
||||
|
||||
|
||||
void ast_pp_util::display_asserts(std::ostream& out, expr_ref_vector const& fmls, bool neat) {
|
||||
if (neat) {
|
||||
smt2_pp_environment_dbg env(m);
|
||||
|
|
|
@ -20,9 +20,11 @@ Revision History:
|
|||
#define AST_PP_UTIL_H_
|
||||
|
||||
#include "ast/decl_collector.h"
|
||||
#include "util/obj_hashtable.h"
|
||||
|
||||
class ast_pp_util {
|
||||
ast_manager& m;
|
||||
obj_hashtable<func_decl> m_removed;
|
||||
public:
|
||||
|
||||
decl_collector coll;
|
||||
|
@ -35,6 +37,8 @@ class ast_pp_util {
|
|||
|
||||
void collect(expr_ref_vector const& es);
|
||||
|
||||
void remove_decl(func_decl* f);
|
||||
|
||||
void display_decls(std::ostream& out);
|
||||
|
||||
void display_asserts(std::ostream& out, expr_ref_vector const& fmls, bool neat = true);
|
||||
|
|
|
@ -952,6 +952,10 @@ void ast_smt_pp::display_smt2(std::ostream& strm, expr* n) {
|
|||
strm << "; " << m_attributes.c_str();
|
||||
}
|
||||
|
||||
#if 0
|
||||
decls.display_decls(strm);
|
||||
#else
|
||||
decls.order_deps();
|
||||
ast_mark sort_mark;
|
||||
for (unsigned i = 0; i < decls.get_num_sorts(); ++i) {
|
||||
sort* s = decls.get_sorts()[i];
|
||||
|
@ -978,18 +982,19 @@ void ast_smt_pp::display_smt2(std::ostream& strm, expr* n) {
|
|||
strm << "\n";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
for (unsigned i = 0; i < m_assumptions.size(); ++i) {
|
||||
for (expr* a : m_assumptions) {
|
||||
smt_printer p(strm, m, ql, rn, m_logic, false, true, m_simplify_implies, 1);
|
||||
strm << "(assert\n ";
|
||||
p(m_assumptions[i].get());
|
||||
p(a);
|
||||
strm << ")\n";
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < m_assumptions_star.size(); ++i) {
|
||||
for (expr* a : m_assumptions_star) {
|
||||
smt_printer p(strm, m, ql, rn, m_logic, false, true, m_simplify_implies, 1);
|
||||
strm << "(assert\n ";
|
||||
p(m_assumptions_star[i].get());
|
||||
p(a);
|
||||
strm << ")\n";
|
||||
}
|
||||
|
||||
|
|
|
@ -791,6 +791,14 @@ namespace datatype {
|
|||
return res;
|
||||
}
|
||||
|
||||
|
||||
func_decl * util::get_constructor_is(func_decl * con) {
|
||||
SASSERT(is_constructor(con));
|
||||
sort * datatype = con->get_range();
|
||||
parameter ps[1] = { parameter(con)};
|
||||
return m.mk_func_decl(m_family_id, OP_DT_IS, 1, ps, 1, &datatype);
|
||||
}
|
||||
|
||||
func_decl * util::get_constructor_recognizer(func_decl * con) {
|
||||
SASSERT(is_constructor(con));
|
||||
func_decl * d = nullptr;
|
||||
|
@ -1040,15 +1048,11 @@ namespace datatype {
|
|||
sort* s = todo.back();
|
||||
todo.pop_back();
|
||||
out << s->get_name() << " =\n";
|
||||
|
||||
ptr_vector<func_decl> const& cnstrs = *get_datatype_constructors(s);
|
||||
for (unsigned i = 0; i < cnstrs.size(); ++i) {
|
||||
func_decl* cns = cnstrs[i];
|
||||
func_decl* rec = get_constructor_recognizer(cns);
|
||||
out << " " << cns->get_name() << " :: " << rec->get_name() << " :: ";
|
||||
for (func_decl * cns : cnstrs) {
|
||||
out << " " << cns->get_name() << " :: ";
|
||||
ptr_vector<func_decl> const & accs = *get_constructor_accessors(cns);
|
||||
for (unsigned j = 0; j < accs.size(); ++j) {
|
||||
func_decl* acc = accs[j];
|
||||
for (func_decl* acc : accs) {
|
||||
sort* s1 = acc->get_range();
|
||||
out << "(" << acc->get_name() << ": " << s1->get_name() << ") ";
|
||||
if (is_datatype(s1) && are_siblings(s1, s0) && !mark.is_marked(s1)) {
|
||||
|
|
|
@ -368,6 +368,7 @@ namespace datatype {
|
|||
sort* get_datatype_parameter_sort(sort * ty, unsigned idx);
|
||||
func_decl * get_non_rec_constructor(sort * ty);
|
||||
func_decl * get_constructor_recognizer(func_decl * constructor);
|
||||
func_decl * get_constructor_is(func_decl * constructor);
|
||||
ptr_vector<func_decl> const * get_constructor_accessors(func_decl * constructor);
|
||||
func_decl * get_accessor_constructor(func_decl * accessor);
|
||||
func_decl * get_recognizer_constructor(func_decl * recognizer) const;
|
||||
|
|
|
@ -18,6 +18,7 @@ Revision History:
|
|||
|
||||
--*/
|
||||
#include "ast/decl_collector.h"
|
||||
#include "ast/ast_pp.h"
|
||||
|
||||
void decl_collector::visit_sort(sort * n) {
|
||||
family_id fid = n->get_family_id();
|
||||
|
@ -25,19 +26,21 @@ void decl_collector::visit_sort(sort * n) {
|
|||
m_sorts.push_back(n);
|
||||
if (fid == m_dt_fid) {
|
||||
m_sorts.push_back(n);
|
||||
|
||||
unsigned num_cnstr = m_dt_util.get_datatype_num_constructors(n);
|
||||
for (unsigned i = 0; i < num_cnstr; i++) {
|
||||
func_decl * cnstr = m_dt_util.get_datatype_constructors(n)->get(i);
|
||||
m_decls.push_back(cnstr);
|
||||
m_todo.push_back(cnstr);
|
||||
ptr_vector<func_decl> const & cnstr_acc = *m_dt_util.get_constructor_accessors(cnstr);
|
||||
unsigned num_cas = cnstr_acc.size();
|
||||
for (unsigned j = 0; j < num_cas; j++) {
|
||||
func_decl * accsr = cnstr_acc.get(j);
|
||||
m_decls.push_back(accsr);
|
||||
m_todo.push_back(cnstr_acc.get(j));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (unsigned i = n->get_num_parameters(); i-- > 0; ) {
|
||||
parameter const& p = n->get_parameter(i);
|
||||
if (p.is_ast()) m_todo.push_back(p.get_ast());
|
||||
}
|
||||
}
|
||||
|
||||
bool decl_collector::is_bool(sort * s) {
|
||||
|
@ -63,43 +66,43 @@ decl_collector::decl_collector(ast_manager & m, bool preds):
|
|||
}
|
||||
|
||||
void decl_collector::visit(ast* n) {
|
||||
ptr_vector<ast> todo;
|
||||
todo.push_back(n);
|
||||
while (!todo.empty()) {
|
||||
n = todo.back();
|
||||
todo.pop_back();
|
||||
datatype_util util(m());
|
||||
m_todo.push_back(n);
|
||||
while (!m_todo.empty()) {
|
||||
n = m_todo.back();
|
||||
m_todo.pop_back();
|
||||
if (!m_visited.is_marked(n)) {
|
||||
m_visited.mark(n, true);
|
||||
switch(n->get_kind()) {
|
||||
case AST_APP: {
|
||||
app * a = to_app(n);
|
||||
for (unsigned i = 0; i < a->get_num_args(); ++i) {
|
||||
todo.push_back(a->get_arg(i));
|
||||
for (expr* arg : *a) {
|
||||
m_todo.push_back(arg);
|
||||
}
|
||||
todo.push_back(a->get_decl());
|
||||
m_todo.push_back(a->get_decl());
|
||||
break;
|
||||
}
|
||||
case AST_QUANTIFIER: {
|
||||
quantifier * q = to_quantifier(n);
|
||||
unsigned num_decls = q->get_num_decls();
|
||||
for (unsigned i = 0; i < num_decls; ++i) {
|
||||
todo.push_back(q->get_decl_sort(i));
|
||||
m_todo.push_back(q->get_decl_sort(i));
|
||||
}
|
||||
todo.push_back(q->get_expr());
|
||||
m_todo.push_back(q->get_expr());
|
||||
for (unsigned i = 0; i < q->get_num_patterns(); ++i) {
|
||||
todo.push_back(q->get_pattern(i));
|
||||
m_todo.push_back(q->get_pattern(i));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case AST_SORT:
|
||||
case AST_SORT:
|
||||
visit_sort(to_sort(n));
|
||||
break;
|
||||
case AST_FUNC_DECL: {
|
||||
func_decl * d = to_func_decl(n);
|
||||
for (unsigned i = 0; i < d->get_arity(); ++i) {
|
||||
todo.push_back(d->get_domain(i));
|
||||
m_todo.push_back(d->get_domain(i));
|
||||
}
|
||||
todo.push_back(d->get_range());
|
||||
m_todo.push_back(d->get_range());
|
||||
visit_func(d);
|
||||
break;
|
||||
}
|
||||
|
@ -112,5 +115,44 @@ void decl_collector::visit(ast* n) {
|
|||
}
|
||||
}
|
||||
|
||||
void decl_collector::order_deps() {
|
||||
top_sort<sort> st;
|
||||
for (sort * s : m_sorts) st.insert(s, collect_deps(s));
|
||||
st.topological_sort();
|
||||
m_sorts.reset();
|
||||
for (sort* s : st.top_sorted()) m_sorts.push_back(s);
|
||||
}
|
||||
|
||||
decl_collector::sort_set* decl_collector::collect_deps(sort* s) {
|
||||
sort_set* set = alloc(sort_set);
|
||||
collect_deps(s, *set);
|
||||
set->remove(s);
|
||||
return set;
|
||||
}
|
||||
|
||||
void decl_collector::collect_deps(sort* s, sort_set& set) {
|
||||
if (set.contains(s)) return;
|
||||
set.insert(s);
|
||||
if (s->is_sort_of(m_dt_util.get_family_id(), DATATYPE_SORT)) {
|
||||
unsigned num_sorts = m_dt_util.get_datatype_num_parameter_sorts(s);
|
||||
for (unsigned i = 0; i < num_sorts; ++i) {
|
||||
set.insert(m_dt_util.get_datatype_parameter_sort(s, i));
|
||||
}
|
||||
unsigned num_cnstr = m_dt_util.get_datatype_num_constructors(s);
|
||||
for (unsigned i = 0; i < num_cnstr; i++) {
|
||||
func_decl * cnstr = m_dt_util.get_datatype_constructors(s)->get(i);
|
||||
set.insert(cnstr->get_range());
|
||||
for (unsigned j = 0; j < cnstr->get_arity(); ++j)
|
||||
set.insert(cnstr->get_domain(j));
|
||||
}
|
||||
}
|
||||
|
||||
for (unsigned i = s->get_num_parameters(); i-- > 0; ) {
|
||||
parameter const& p = s->get_parameter(i);
|
||||
if (p.is_ast() && is_sort(p.get_ast())) {
|
||||
set.insert(to_sort(p.get_ast()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ Revision History:
|
|||
#ifndef SMT_DECL_COLLECTOR_H_
|
||||
#define SMT_DECL_COLLECTOR_H_
|
||||
|
||||
#include "util/top_sort.h"
|
||||
#include "ast/ast.h"
|
||||
#include "ast/datatype_decl_plugin.h"
|
||||
|
||||
|
@ -33,11 +34,17 @@ class decl_collector {
|
|||
family_id m_basic_fid;
|
||||
family_id m_dt_fid;
|
||||
datatype_util m_dt_util;
|
||||
ptr_vector<ast> m_todo;
|
||||
|
||||
void visit_sort(sort* n);
|
||||
bool is_bool(sort* s);
|
||||
void visit_func(func_decl* n);
|
||||
|
||||
typedef obj_hashtable<sort> sort_set;
|
||||
sort_set* collect_deps(sort* s);
|
||||
void collect_deps(top_sort<sort>& st);
|
||||
void collect_deps(sort* s, sort_set& set);
|
||||
|
||||
|
||||
public:
|
||||
// if preds == true, then predicates are stored in a separate collection.
|
||||
|
@ -48,9 +55,12 @@ public:
|
|||
void visit(unsigned n, expr* const* es);
|
||||
void visit(expr_ref_vector const& es);
|
||||
|
||||
void order_deps();
|
||||
|
||||
unsigned get_num_sorts() const { return m_sorts.size(); }
|
||||
unsigned get_num_decls() const { return m_decls.size(); }
|
||||
unsigned get_num_preds() const { return m_preds.size(); }
|
||||
|
||||
sort * const * get_sorts() const { return m_sorts.c_ptr(); }
|
||||
func_decl * const * get_func_decls() const { return m_decls.c_ptr(); }
|
||||
func_decl * const * get_pred_decls() const { return m_preds.c_ptr(); }
|
||||
|
|
|
@ -25,7 +25,7 @@ Notes:
|
|||
#include "ast/fpa/fpa2bv_converter.h"
|
||||
#include "ast/rewriter/fpa_rewriter.h"
|
||||
|
||||
#define BVULT(X,Y,R) { expr_ref bvult_eq(m), bvult_not(m); m_simp.mk_eq(X, Y, bvult_eq); m_simp.mk_not(bvult_eq, bvult_not); expr_ref t(m); t = m_bv_util.mk_ule(X,Y); m_simp.mk_and(t, bvult_not, R); }
|
||||
#define BVULT(X,Y,R) { expr_ref t(m); t = m_bv_util.mk_ule(Y,X); m_simp.mk_not(t, R); }
|
||||
|
||||
fpa2bv_converter::fpa2bv_converter(ast_manager & m) :
|
||||
m(m),
|
||||
|
@ -4085,7 +4085,7 @@ void fpa2bv_converter::round(sort * s, expr_ref & rm, expr_ref & sgn, expr_ref &
|
|||
TRACE("fpa2bv_round", tout << "ROUND = " << mk_ismt2_pp(result, m) << std::endl; );
|
||||
}
|
||||
|
||||
void fpa2bv_converter::reset(void) {
|
||||
void fpa2bv_converter::reset() {
|
||||
dec_ref_map_key_values(m, m_const2bv);
|
||||
dec_ref_map_key_values(m, m_rm_const2bv);
|
||||
dec_ref_map_key_values(m, m_uf2bvuf);
|
||||
|
|
|
@ -150,7 +150,7 @@ public:
|
|||
void mk_max(func_decl * f, unsigned num, expr * const * args, expr_ref & result);
|
||||
expr_ref mk_min_max_unspecified(func_decl * f, expr * x, expr * y);
|
||||
|
||||
void reset(void);
|
||||
void reset();
|
||||
|
||||
void dbg_decouple(const char * prefix, expr_ref & e);
|
||||
expr_ref_vector m_extra_assertions;
|
||||
|
|
|
@ -160,7 +160,7 @@ bool fpa_decl_plugin::is_rm_numeral(expr * n, mpf_rounding_mode & val) {
|
|||
return true;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool fpa_decl_plugin::is_rm_numeral(expr * n) {
|
||||
|
|
|
@ -91,7 +91,7 @@ public:
|
|||
void operator()(var * n) { m_bitset.set(n->get_idx(), true); }
|
||||
void operator()(quantifier * n) {}
|
||||
void operator()(app * n) {}
|
||||
bool all_used(void) {
|
||||
bool all_used() {
|
||||
for (unsigned i = 0; i < m_bitset.size() ; i++)
|
||||
if (!m_bitset.get(i))
|
||||
return false;
|
||||
|
|
|
@ -440,16 +440,6 @@ bool proof_checker::check1_basic(proof* p, expr_ref_vector& side_conditions) {
|
|||
IF_VERBOSE(0, verbose_stream() << "Expected proof of equivalence with a quantifier:\n" << mk_bounded_pp(p, m););
|
||||
return false;
|
||||
}
|
||||
case PR_PULL_QUANT_STAR: {
|
||||
if (match_proof(p) &&
|
||||
match_fact(p, fact) &&
|
||||
match_iff(fact.get(), t1, t2)) {
|
||||
// TBD: check the enchilada.
|
||||
return true;
|
||||
}
|
||||
IF_VERBOSE(0, verbose_stream() << "Expected proof of equivalence:\n" << mk_bounded_pp(p, m););
|
||||
return false;
|
||||
}
|
||||
case PR_PUSH_QUANT: {
|
||||
if (match_proof(p) &&
|
||||
match_fact(p, fact) &&
|
||||
|
@ -730,10 +720,6 @@ bool proof_checker::check1_basic(proof* p, expr_ref_vector& side_conditions) {
|
|||
// TBD:
|
||||
return true;
|
||||
}
|
||||
case PR_NNF_STAR: {
|
||||
// TBD:
|
||||
return true;
|
||||
}
|
||||
case PR_SKOLEMIZE: {
|
||||
// (exists ?x (p ?x y)) -> (p (sk y) y)
|
||||
// (not (forall ?x (p ?x y))) -> (not (p (sk y) y))
|
||||
|
@ -755,19 +741,6 @@ bool proof_checker::check1_basic(proof* p, expr_ref_vector& side_conditions) {
|
|||
UNREACHABLE();
|
||||
return false;
|
||||
}
|
||||
case PR_CNF_STAR: {
|
||||
for (unsigned i = 0; i < proofs.size(); ++i) {
|
||||
if (match_op(proofs[i].get(), PR_DEF_INTRO, terms)) {
|
||||
// ok
|
||||
}
|
||||
else {
|
||||
UNREACHABLE();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// coarse grain CNF conversion.
|
||||
return true;
|
||||
}
|
||||
case PR_MODUS_PONENS_OEQ: {
|
||||
if (match_fact(p, fact) &&
|
||||
match_proof(p, p0, p1) &&
|
||||
|
@ -922,7 +895,7 @@ void proof_checker::set_false(expr_ref& e, unsigned position, expr_ref& lit) {
|
|||
}
|
||||
}
|
||||
|
||||
bool proof_checker::match_fact(proof* p, expr_ref& fact) {
|
||||
bool proof_checker::match_fact(proof const* p, expr_ref& fact) const {
|
||||
if (m.is_proof(p) &&
|
||||
m.has_fact(p)) {
|
||||
fact = m.get_fact(p);
|
||||
|
@ -938,13 +911,13 @@ void proof_checker::add_premise(proof* p) {
|
|||
}
|
||||
}
|
||||
|
||||
bool proof_checker::match_proof(proof* p) {
|
||||
bool proof_checker::match_proof(proof const* p) const {
|
||||
return
|
||||
m.is_proof(p) &&
|
||||
m.get_num_parents(p) == 0;
|
||||
}
|
||||
|
||||
bool proof_checker::match_proof(proof* p, proof_ref& p0) {
|
||||
bool proof_checker::match_proof(proof const* p, proof_ref& p0) const {
|
||||
if (m.is_proof(p) &&
|
||||
m.get_num_parents(p) == 1) {
|
||||
p0 = m.get_parent(p, 0);
|
||||
|
@ -953,7 +926,7 @@ bool proof_checker::match_proof(proof* p, proof_ref& p0) {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool proof_checker::match_proof(proof* p, proof_ref& p0, proof_ref& p1) {
|
||||
bool proof_checker::match_proof(proof const* p, proof_ref& p0, proof_ref& p1) const {
|
||||
if (m.is_proof(p) &&
|
||||
m.get_num_parents(p) == 2) {
|
||||
p0 = m.get_parent(p, 0);
|
||||
|
@ -963,7 +936,7 @@ bool proof_checker::match_proof(proof* p, proof_ref& p0, proof_ref& p1) {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool proof_checker::match_proof(proof* p, proof_ref_vector& parents) {
|
||||
bool proof_checker::match_proof(proof const* p, proof_ref_vector& parents) const {
|
||||
if (m.is_proof(p)) {
|
||||
for (unsigned i = 0; i < m.get_num_parents(p); ++i) {
|
||||
parents.push_back(m.get_parent(p, i));
|
||||
|
@ -974,7 +947,7 @@ bool proof_checker::match_proof(proof* p, proof_ref_vector& parents) {
|
|||
}
|
||||
|
||||
|
||||
bool proof_checker::match_binary(expr* e, func_decl_ref& d, expr_ref& t1, expr_ref& t2) {
|
||||
bool proof_checker::match_binary(expr const* e, func_decl_ref& d, expr_ref& t1, expr_ref& t2) const {
|
||||
if (e->get_kind() == AST_APP &&
|
||||
to_app(e)->get_num_args() == 2) {
|
||||
d = to_app(e)->get_decl();
|
||||
|
@ -986,7 +959,7 @@ bool proof_checker::match_binary(expr* e, func_decl_ref& d, expr_ref& t1, expr_r
|
|||
}
|
||||
|
||||
|
||||
bool proof_checker::match_app(expr* e, func_decl_ref& d, expr_ref_vector& terms) {
|
||||
bool proof_checker::match_app(expr const* e, func_decl_ref& d, expr_ref_vector& terms) const {
|
||||
if (e->get_kind() == AST_APP) {
|
||||
d = to_app(e)->get_decl();
|
||||
for (unsigned i = 0; i < to_app(e)->get_num_args(); ++i) {
|
||||
|
@ -997,9 +970,9 @@ bool proof_checker::match_app(expr* e, func_decl_ref& d, expr_ref_vector& terms)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool proof_checker::match_quantifier(expr* e, bool& is_univ, sort_ref_vector& sorts, expr_ref& body) {
|
||||
bool proof_checker::match_quantifier(expr const* e, bool& is_univ, sort_ref_vector& sorts, expr_ref& body) const {
|
||||
if (is_quantifier(e)) {
|
||||
quantifier* q = to_quantifier(e);
|
||||
quantifier const* q = to_quantifier(e);
|
||||
is_univ = q->is_forall();
|
||||
body = q->get_expr();
|
||||
for (unsigned i = 0; i < q->get_num_decls(); ++i) {
|
||||
|
@ -1010,7 +983,7 @@ bool proof_checker::match_quantifier(expr* e, bool& is_univ, sort_ref_vector& so
|
|||
return false;
|
||||
}
|
||||
|
||||
bool proof_checker::match_op(expr* e, decl_kind k, expr_ref& t1, expr_ref& t2) {
|
||||
bool proof_checker::match_op(expr const* e, decl_kind k, expr_ref& t1, expr_ref& t2) const {
|
||||
if (e->get_kind() == AST_APP &&
|
||||
to_app(e)->get_family_id() == m.get_basic_family_id() &&
|
||||
to_app(e)->get_decl_kind() == k &&
|
||||
|
@ -1022,7 +995,7 @@ bool proof_checker::match_op(expr* e, decl_kind k, expr_ref& t1, expr_ref& t2) {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool proof_checker::match_op(expr* e, decl_kind k, expr_ref_vector& terms) {
|
||||
bool proof_checker::match_op(expr const* e, decl_kind k, expr_ref_vector& terms) const {
|
||||
if (e->get_kind() == AST_APP &&
|
||||
to_app(e)->get_family_id() == m.get_basic_family_id() &&
|
||||
to_app(e)->get_decl_kind() == k) {
|
||||
|
@ -1035,7 +1008,7 @@ bool proof_checker::match_op(expr* e, decl_kind k, expr_ref_vector& terms) {
|
|||
}
|
||||
|
||||
|
||||
bool proof_checker::match_op(expr* e, decl_kind k, expr_ref& t) {
|
||||
bool proof_checker::match_op(expr const* e, decl_kind k, expr_ref& t) const {
|
||||
if (e->get_kind() == AST_APP &&
|
||||
to_app(e)->get_family_id() == m.get_basic_family_id() &&
|
||||
to_app(e)->get_decl_kind() == k &&
|
||||
|
@ -1046,39 +1019,39 @@ bool proof_checker::match_op(expr* e, decl_kind k, expr_ref& t) {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool proof_checker::match_not(expr* e, expr_ref& t) {
|
||||
bool proof_checker::match_not(expr const* e, expr_ref& t) const {
|
||||
return match_op(e, OP_NOT, t);
|
||||
}
|
||||
|
||||
bool proof_checker::match_or(expr* e, expr_ref_vector& terms) {
|
||||
bool proof_checker::match_or(expr const* e, expr_ref_vector& terms) const {
|
||||
return match_op(e, OP_OR, terms);
|
||||
}
|
||||
|
||||
bool proof_checker::match_and(expr* e, expr_ref_vector& terms) {
|
||||
bool proof_checker::match_and(expr const* e, expr_ref_vector& terms) const {
|
||||
return match_op(e, OP_AND, terms);
|
||||
}
|
||||
|
||||
bool proof_checker::match_iff(expr* e, expr_ref& t1, expr_ref& t2) {
|
||||
bool proof_checker::match_iff(expr const* e, expr_ref& t1, expr_ref& t2) const {
|
||||
return match_op(e, OP_IFF, t1, t2);
|
||||
}
|
||||
|
||||
bool proof_checker::match_equiv(expr* e, expr_ref& t1, expr_ref& t2) {
|
||||
bool proof_checker::match_equiv(expr const* e, expr_ref& t1, expr_ref& t2) const {
|
||||
return match_oeq(e, t1, t2) || match_eq(e, t1, t2);
|
||||
}
|
||||
|
||||
bool proof_checker::match_implies(expr* e, expr_ref& t1, expr_ref& t2) {
|
||||
bool proof_checker::match_implies(expr const* e, expr_ref& t1, expr_ref& t2) const {
|
||||
return match_op(e, OP_IMPLIES, t1, t2);
|
||||
}
|
||||
|
||||
bool proof_checker::match_eq(expr* e, expr_ref& t1, expr_ref& t2) {
|
||||
bool proof_checker::match_eq(expr const* e, expr_ref& t1, expr_ref& t2) const {
|
||||
return match_op(e, OP_EQ, t1, t2) || match_iff(e, t1, t2);
|
||||
}
|
||||
|
||||
bool proof_checker::match_oeq(expr* e, expr_ref& t1, expr_ref& t2) {
|
||||
bool proof_checker::match_oeq(expr const* e, expr_ref& t1, expr_ref& t2) const {
|
||||
return match_op(e, OP_OEQ, t1, t2);
|
||||
}
|
||||
|
||||
bool proof_checker::match_negated(expr* a, expr* b) {
|
||||
bool proof_checker::match_negated(expr const* a, expr* b) const {
|
||||
expr_ref t(m);
|
||||
return
|
||||
(match_not(a, t) && t.get() == b) ||
|
||||
|
@ -1186,14 +1159,14 @@ void proof_checker::get_hypotheses(proof* p, expr_ref_vector& ante) {
|
|||
|
||||
}
|
||||
|
||||
bool proof_checker::match_nil(expr* e) const {
|
||||
bool proof_checker::match_nil(expr const* e) const {
|
||||
return
|
||||
is_app(e) &&
|
||||
to_app(e)->get_family_id() == m_hyp_fid &&
|
||||
to_app(e)->get_decl_kind() == OP_NIL;
|
||||
}
|
||||
|
||||
bool proof_checker::match_cons(expr* e, expr_ref& a, expr_ref& b) const {
|
||||
bool proof_checker::match_cons(expr const* e, expr_ref& a, expr_ref& b) const {
|
||||
if (is_app(e) &&
|
||||
to_app(e)->get_family_id() == m_hyp_fid &&
|
||||
to_app(e)->get_decl_kind() == OP_CONS) {
|
||||
|
@ -1205,7 +1178,7 @@ bool proof_checker::match_cons(expr* e, expr_ref& a, expr_ref& b) const {
|
|||
}
|
||||
|
||||
|
||||
bool proof_checker::match_atom(expr* e, expr_ref& a) const {
|
||||
bool proof_checker::match_atom(expr const* e, expr_ref& a) const {
|
||||
if (is_app(e) &&
|
||||
to_app(e)->get_family_id() == m_hyp_fid &&
|
||||
to_app(e)->get_decl_kind() == OP_ATOM) {
|
||||
|
@ -1227,7 +1200,7 @@ expr* proof_checker::mk_nil() {
|
|||
return m_nil.get();
|
||||
}
|
||||
|
||||
bool proof_checker::is_hypothesis(proof* p) const {
|
||||
bool proof_checker::is_hypothesis(proof const* p) const {
|
||||
return
|
||||
m.is_proof(p) &&
|
||||
p->get_decl_kind() == PR_HYPOTHESIS;
|
||||
|
@ -1253,7 +1226,7 @@ expr* proof_checker::mk_hyp(unsigned num_hyps, expr * const * hyps) {
|
|||
}
|
||||
}
|
||||
|
||||
void proof_checker::dump_proof(proof * pr) {
|
||||
void proof_checker::dump_proof(proof const* pr) {
|
||||
if (!m_dump_lemmas)
|
||||
return;
|
||||
SASSERT(m.has_fact(pr));
|
||||
|
|
|
@ -77,39 +77,39 @@ private:
|
|||
bool check1_spc(proof* p, expr_ref_vector& side_conditions);
|
||||
bool check_arith_proof(proof* p);
|
||||
bool check_arith_literal(bool is_pos, app* lit, rational const& coeff, expr_ref& sum, bool& is_strict);
|
||||
bool match_fact(proof* p, expr_ref& fact);
|
||||
bool match_fact(proof const* p, expr_ref& fact) const;
|
||||
void add_premise(proof* p);
|
||||
bool match_proof(proof* p);
|
||||
bool match_proof(proof* p, proof_ref& p0);
|
||||
bool match_proof(proof* p, proof_ref& p0, proof_ref& p1);
|
||||
bool match_proof(proof* p, proof_ref_vector& parents);
|
||||
bool match_binary(expr* e, func_decl_ref& d, expr_ref& t1, expr_ref& t2);
|
||||
bool match_op(expr* e, decl_kind k, expr_ref& t1, expr_ref& t2);
|
||||
bool match_op(expr* e, decl_kind k, expr_ref& t);
|
||||
bool match_op(expr* e, decl_kind k, expr_ref_vector& terms);
|
||||
bool match_iff(expr* e, expr_ref& t1, expr_ref& t2);
|
||||
bool match_implies(expr* e, expr_ref& t1, expr_ref& t2);
|
||||
bool match_eq(expr* e, expr_ref& t1, expr_ref& t2);
|
||||
bool match_oeq(expr* e, expr_ref& t1, expr_ref& t2);
|
||||
bool match_not(expr* e, expr_ref& t);
|
||||
bool match_or(expr* e, expr_ref_vector& terms);
|
||||
bool match_and(expr* e, expr_ref_vector& terms);
|
||||
bool match_app(expr* e, func_decl_ref& d, expr_ref_vector& terms);
|
||||
bool match_quantifier(expr*, bool& is_univ, sort_ref_vector&, expr_ref& body);
|
||||
bool match_negated(expr* a, expr* b);
|
||||
bool match_equiv(expr* a, expr_ref& t1, expr_ref& t2);
|
||||
bool match_proof(proof const* p) const;
|
||||
bool match_proof(proof const* p, proof_ref& p0) const;
|
||||
bool match_proof(proof const* p, proof_ref& p0, proof_ref& p1) const;
|
||||
bool match_proof(proof const* p, proof_ref_vector& parents) const;
|
||||
bool match_binary(expr const* e, func_decl_ref& d, expr_ref& t1, expr_ref& t2) const;
|
||||
bool match_op(expr const* e, decl_kind k, expr_ref& t1, expr_ref& t2) const;
|
||||
bool match_op(expr const* e, decl_kind k, expr_ref& t) const;
|
||||
bool match_op(expr const* e, decl_kind k, expr_ref_vector& terms) const;
|
||||
bool match_iff(expr const* e, expr_ref& t1, expr_ref& t2) const;
|
||||
bool match_implies(expr const* e, expr_ref& t1, expr_ref& t2) const;
|
||||
bool match_eq(expr const* e, expr_ref& t1, expr_ref& t2) const;
|
||||
bool match_oeq(expr const* e, expr_ref& t1, expr_ref& t2) const;
|
||||
bool match_not(expr const* e, expr_ref& t) const;
|
||||
bool match_or(expr const* e, expr_ref_vector& terms) const;
|
||||
bool match_and(expr const* e, expr_ref_vector& terms) const;
|
||||
bool match_app(expr const* e, func_decl_ref& d, expr_ref_vector& terms) const;
|
||||
bool match_quantifier(expr const*, bool& is_univ, sort_ref_vector&, expr_ref& body) const;
|
||||
bool match_negated(expr const* a, expr* b) const;
|
||||
bool match_equiv(expr const* a, expr_ref& t1, expr_ref& t2) const;
|
||||
void get_ors(expr* e, expr_ref_vector& ors);
|
||||
void get_hypotheses(proof* p, expr_ref_vector& ante);
|
||||
|
||||
bool match_nil(expr* e) const;
|
||||
bool match_cons(expr* e, expr_ref& a, expr_ref& b) const;
|
||||
bool match_atom(expr* e, expr_ref& a) const;
|
||||
bool match_nil(expr const* e) const;
|
||||
bool match_cons(expr const* e, expr_ref& a, expr_ref& b) const;
|
||||
bool match_atom(expr const* e, expr_ref& a) const;
|
||||
expr* mk_nil();
|
||||
expr* mk_cons(expr* a, expr* b);
|
||||
expr* mk_atom(expr* e);
|
||||
bool is_hypothesis(proof* p) const;
|
||||
bool is_hypothesis(proof const* p) const;
|
||||
expr* mk_hyp(unsigned num_hyps, expr * const * hyps);
|
||||
void dump_proof(proof * pr);
|
||||
void dump_proof(proof const* pr);
|
||||
void dump_proof(unsigned num_antecedents, expr * const * antecedents, expr * consequent);
|
||||
|
||||
void set_false(expr_ref& e, unsigned idx, expr_ref& lit);
|
||||
|
|
|
@ -25,7 +25,6 @@ z3_add_component(rewriter
|
|||
pb_rewriter.cpp
|
||||
pb2bv_rewriter.cpp
|
||||
push_app_ite.cpp
|
||||
pull_ite_tree.cpp
|
||||
quant_hoist.cpp
|
||||
rewriter.cpp
|
||||
seq_rewriter.cpp
|
||||
|
|
|
@ -1,221 +0,0 @@
|
|||
/*++
|
||||
Copyright (c) 2006 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
pull_ite_tree.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
<abstract>
|
||||
|
||||
Author:
|
||||
|
||||
Leonardo de Moura (leonardo) 2008-06-22.
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
#include "ast/rewriter/pull_ite_tree.h"
|
||||
#include "ast/recurse_expr_def.h"
|
||||
#include "ast/for_each_expr.h"
|
||||
#include "ast/ast_pp.h"
|
||||
|
||||
pull_ite_tree::pull_ite_tree(ast_manager & m):
|
||||
m_manager(m),
|
||||
m_rewriter(m),
|
||||
m_cache(m) {
|
||||
}
|
||||
|
||||
void pull_ite_tree::cache_result(expr * n, expr * r, proof * pr) {
|
||||
m_cache.insert(n, r, pr);
|
||||
}
|
||||
|
||||
void pull_ite_tree::visit(expr * n, bool & visited) {
|
||||
if (!is_cached(n)) {
|
||||
m_todo.push_back(n);
|
||||
visited = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool pull_ite_tree::visit_children(expr * n) {
|
||||
if (m_manager.is_ite(n)) {
|
||||
bool visited = true;
|
||||
visit(to_app(n)->get_arg(1), visited);
|
||||
visit(to_app(n)->get_arg(2), visited);
|
||||
return visited;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void pull_ite_tree::reduce(expr * n) {
|
||||
// Remark: invoking the simplifier to build the new expression saves a lot of memory.
|
||||
if (m_manager.is_ite(n)) {
|
||||
expr * c = to_app(n)->get_arg(0);
|
||||
expr * t_old = to_app(n)->get_arg(1);
|
||||
expr * e_old = to_app(n)->get_arg(2);
|
||||
expr * t = nullptr;
|
||||
proof * t_pr = nullptr;
|
||||
expr * e = nullptr;
|
||||
proof * e_pr = nullptr;
|
||||
get_cached(t_old, t, t_pr);
|
||||
get_cached(e_old, e, e_pr);
|
||||
expr_ref r(m_manager);
|
||||
expr * args[3] = {c, t, e};
|
||||
r = m_rewriter.mk_app(to_app(n)->get_decl(), 3, args);
|
||||
if (!m_manager.proofs_enabled()) {
|
||||
// expr * r = m_manager.mk_ite(c, t, e);
|
||||
cache_result(n, r, nullptr);
|
||||
}
|
||||
else {
|
||||
// t_pr is a proof for (m_p ... t_old ...) == t
|
||||
// e_pr is a proof for (m_p ... e_old ...) == e
|
||||
expr_ref old(m_manager);
|
||||
expr_ref p_t_old(m_manager);
|
||||
expr_ref p_e_old(m_manager);
|
||||
old = mk_p_arg(n); // (m_p ... n ...) where n is (ite c t_old e_old)
|
||||
p_t_old = mk_p_arg(t_old); // (m_p ... t_old ...)
|
||||
p_e_old = mk_p_arg(e_old); // (m_p ... e_old ...)
|
||||
expr_ref tmp1(m_manager);
|
||||
tmp1 = m_manager.mk_ite(c, p_t_old, p_e_old); // (ite c (m_p ... t_old ...) (m_p ... e_old ...))
|
||||
proof * pr1 = m_manager.mk_rewrite(old, tmp1); // proof for (m_p ... (ite c t_old e_old) ...) = (ite c (m_p ... t_old ...) (m_p ... e_old ...))
|
||||
expr_ref tmp2(m_manager);
|
||||
tmp2 = m_manager.mk_ite(c, t, e); // (ite c t e)
|
||||
proof * pr2 = nullptr; // it will contain a proof for (ite c (m_p ... t_old ...) (m_p ... e_old ...)) = (ite c t e)
|
||||
proof * pr3 = nullptr; // it will contain a proof for (m_p ... (ite c t_old e_old) ...) = (ite c t e)
|
||||
proof * proofs[2];
|
||||
unsigned num_proofs = 0;
|
||||
if (t_pr != nullptr) {
|
||||
proofs[num_proofs] = t_pr;
|
||||
num_proofs++;
|
||||
}
|
||||
if (e_pr != nullptr) {
|
||||
proofs[num_proofs] = e_pr;
|
||||
num_proofs++;
|
||||
}
|
||||
if (num_proofs > 0) {
|
||||
pr2 = m_manager.mk_congruence(to_app(tmp1), to_app(tmp2), num_proofs, proofs);
|
||||
pr3 = m_manager.mk_transitivity(pr1, pr2);
|
||||
}
|
||||
else {
|
||||
pr3 = pr1;
|
||||
}
|
||||
proof * pr4 = nullptr; // it will contain a proof for (ite c t e) = r
|
||||
proof * pr5 = nullptr; // it will contain a proof for (m_p ... (ite c t_old e_old) ...) = r
|
||||
if (tmp2 != r) {
|
||||
pr4 = m_manager.mk_rewrite(tmp2, r);
|
||||
pr5 = m_manager.mk_transitivity(pr3, pr4);
|
||||
}
|
||||
else {
|
||||
pr5 = pr3;
|
||||
}
|
||||
cache_result(n, r, pr5);
|
||||
}
|
||||
}
|
||||
else {
|
||||
expr_ref r(m_manager);
|
||||
m_args[m_arg_idx] = n;
|
||||
r = m_rewriter.mk_app(m_p, m_args.size(), m_args.c_ptr());
|
||||
if (!m_manager.proofs_enabled()) {
|
||||
// expr * r = m_manager.mk_app(m_p, m_args.size(), m_args.c_ptr());
|
||||
cache_result(n, r, nullptr);
|
||||
}
|
||||
else {
|
||||
expr_ref old(m_manager);
|
||||
proof * p;
|
||||
old = mk_p_arg(n);
|
||||
if (old == r)
|
||||
p = nullptr;
|
||||
else
|
||||
p = m_manager.mk_rewrite(old, r);
|
||||
cache_result(n, r, p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pull_ite_tree::operator()(app * n, app_ref & r, proof_ref & pr) {
|
||||
unsigned num_args = n->get_num_args();
|
||||
m_args.resize(num_args);
|
||||
m_p = n->get_decl();
|
||||
expr * ite = nullptr;
|
||||
for (unsigned i = 0; i < num_args; i++) {
|
||||
expr * arg = n->get_arg(i);
|
||||
if (ite) {
|
||||
m_args[i] = arg;
|
||||
}
|
||||
else if (m_manager.is_ite(arg)) {
|
||||
m_arg_idx = i;
|
||||
m_args[i] = 0;
|
||||
ite = arg;
|
||||
}
|
||||
else {
|
||||
m_args[i] = arg;
|
||||
}
|
||||
}
|
||||
if (!ite) {
|
||||
r = n;
|
||||
pr = nullptr;
|
||||
return;
|
||||
}
|
||||
m_todo.push_back(ite);
|
||||
while (!m_todo.empty()) {
|
||||
expr * n = m_todo.back();
|
||||
if (is_cached(n))
|
||||
m_todo.pop_back();
|
||||
else if (visit_children(n)) {
|
||||
m_todo.pop_back();
|
||||
reduce(n);
|
||||
}
|
||||
}
|
||||
SASSERT(is_cached(ite));
|
||||
expr * _r = nullptr;
|
||||
proof * _pr = nullptr;
|
||||
get_cached(ite, _r, _pr);
|
||||
r = to_app(_r);
|
||||
pr = _pr;
|
||||
m_cache.reset();
|
||||
m_todo.reset();
|
||||
}
|
||||
|
||||
|
||||
|
||||
pull_ite_tree_cfg::pull_ite_tree_cfg(ast_manager & m):
|
||||
m(m),
|
||||
m_trail(m),
|
||||
m_proc(m) {
|
||||
}
|
||||
|
||||
bool pull_ite_tree_cfg::get_subst(expr * n, expr* & r, proof* & p) {
|
||||
if (is_app(n) && is_target(to_app(n))) {
|
||||
app_ref tmp(m);
|
||||
proof_ref pr(m);
|
||||
m_proc(to_app(n), tmp, pr);
|
||||
if (tmp != n) {
|
||||
r = tmp;
|
||||
p = pr;
|
||||
m_trail.push_back(r);
|
||||
m_trail.push_back(p);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool pull_cheap_ite_tree_cfg::is_target(app * n) const {
|
||||
bool r =
|
||||
n->get_num_args() == 2 &&
|
||||
n->get_family_id() != null_family_id &&
|
||||
m.is_bool(n) &&
|
||||
(m.is_value(n->get_arg(0)) || m.is_value(n->get_arg(1))) &&
|
||||
(m.is_term_ite(n->get_arg(0)) || m.is_term_ite(n->get_arg(1)));
|
||||
TRACE("pull_ite_target", tout << mk_pp(n, m) << "\nresult: " << r << "\n";);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,113 +0,0 @@
|
|||
/*++
|
||||
Copyright (c) 2006 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
pull_ite_tree.h
|
||||
|
||||
Abstract:
|
||||
|
||||
<abstract>
|
||||
|
||||
Author:
|
||||
|
||||
Leonardo de Moura (leonardo) 2008-06-22.
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
#ifndef PULL_ITE_TREE_H_
|
||||
#define PULL_ITE_TREE_H_
|
||||
|
||||
#include "ast/ast.h"
|
||||
#include "ast/rewriter/rewriter.h"
|
||||
#include "ast/rewriter/th_rewriter.h"
|
||||
#include "ast/expr_map.h"
|
||||
#include "ast/recurse_expr.h"
|
||||
#include "util/obj_hashtable.h"
|
||||
|
||||
/**
|
||||
\brief Functor for applying the following transformation
|
||||
F[(p (ite c t1 t2) args)] = F'[(ite c t1 t2), p, args]
|
||||
|
||||
F'[(ite c t1 t2), p, args] = (ite c F'[t1, p, args] F'[t2, p, args])
|
||||
F'[t, p, args] = (p t args)
|
||||
*/
|
||||
class pull_ite_tree {
|
||||
ast_manager & m_manager;
|
||||
th_rewriter m_rewriter;
|
||||
func_decl * m_p;
|
||||
ptr_vector<expr> m_args;
|
||||
unsigned m_arg_idx; //!< position of the ite argument
|
||||
expr_map m_cache;
|
||||
ptr_vector<expr> m_todo;
|
||||
|
||||
bool is_cached(expr * n) const { return m_cache.contains(n); }
|
||||
void get_cached(expr * n, expr * & r, proof * & p) const { m_cache.get(n, r, p); }
|
||||
void cache_result(expr * n, expr * r, proof * pr);
|
||||
void visit(expr * n, bool & visited);
|
||||
bool visit_children(expr * n);
|
||||
void reduce(expr * n);
|
||||
/**
|
||||
\brief Creante an application (m_p ... n ...) where n is the argument m_arg_idx and the other arguments
|
||||
are in m_args.
|
||||
*/
|
||||
expr * mk_p_arg(expr * n) {
|
||||
m_args[m_arg_idx] = n;
|
||||
return m_manager.mk_app(m_p, m_args.size(), m_args.c_ptr());
|
||||
}
|
||||
public:
|
||||
pull_ite_tree(ast_manager & m);
|
||||
/**
|
||||
\brief Apply the transformation above if n contains an ite-expression.
|
||||
Store the result in r. If n does not contain an ite-expression, then
|
||||
store n in r.
|
||||
|
||||
When proof generation is enabled, pr is a proof for n = r.
|
||||
*/
|
||||
void operator()(app * n, app_ref & r, proof_ref & pr);
|
||||
};
|
||||
|
||||
/**
|
||||
\brief Functor for applying the pull_ite_tree on subexpressions n that
|
||||
satisfy the is_target virtual predicate.
|
||||
*/
|
||||
class pull_ite_tree_cfg : public default_rewriter_cfg {
|
||||
protected:
|
||||
ast_manager& m;
|
||||
expr_ref_vector m_trail;
|
||||
pull_ite_tree m_proc;
|
||||
public:
|
||||
pull_ite_tree_cfg(ast_manager & m);
|
||||
virtual ~pull_ite_tree_cfg() {}
|
||||
virtual bool is_target(app * n) const = 0;
|
||||
bool get_subst(expr * n, expr* & r, proof* & p);
|
||||
};
|
||||
|
||||
/**
|
||||
\brief Apply pull_ite_tree on predicates of the form
|
||||
(p ite v) and (p v ite)
|
||||
|
||||
where:
|
||||
- p is an interpreted predicate
|
||||
- ite is an ite-term expression
|
||||
- v is a value
|
||||
*/
|
||||
class pull_cheap_ite_tree_cfg : public pull_ite_tree_cfg {
|
||||
public:
|
||||
pull_cheap_ite_tree_cfg(ast_manager & m):pull_ite_tree_cfg(m) {}
|
||||
~pull_cheap_ite_tree_cfg() override {}
|
||||
bool is_target(app * n) const override;
|
||||
};
|
||||
|
||||
class pull_cheap_ite_tree_rw : public rewriter_tpl<pull_cheap_ite_tree_cfg> {
|
||||
pull_cheap_ite_tree_cfg m_cfg;
|
||||
public:
|
||||
pull_cheap_ite_tree_rw(ast_manager& m):
|
||||
rewriter_tpl<pull_cheap_ite_tree_cfg>(m, m.proofs_enabled(), m_cfg),
|
||||
m_cfg(m)
|
||||
{}
|
||||
};
|
||||
|
||||
#endif /* PULL_ITE_TREE_H_ */
|
||||
|
|
@ -358,7 +358,7 @@ void rewriter_tpl<Config>::process_app(app * t, frame & fr) {
|
|||
if (ProofGen) {
|
||||
NOT_IMPLEMENTED_YET();
|
||||
// We do not support the use of bindings in proof generation mode.
|
||||
// Thus we have to apply the subsitution here, and
|
||||
// Thus we have to apply the substitution here, and
|
||||
// beta_reducer subst(m());
|
||||
// subst.set_bindings(new_num_args, new_args);
|
||||
// expr_ref r2(m());
|
||||
|
|
|
@ -1478,9 +1478,7 @@ br_status seq_rewriter::mk_re_star(expr* a, expr_ref& result) {
|
|||
return BR_DONE;
|
||||
}
|
||||
if (m_util.re.is_full_char(a)) {
|
||||
sort* seq_sort = nullptr;
|
||||
VERIFY(m_util.is_re(a, seq_sort));
|
||||
result = m_util.re.mk_full_seq(seq_sort);
|
||||
result = m_util.re.mk_full_seq(m().get_sort(a));
|
||||
return BR_DONE;
|
||||
}
|
||||
if (m_util.re.is_empty(a)) {
|
||||
|
|
|
@ -671,9 +671,7 @@ func_decl * seq_decl_plugin::mk_func_decl(decl_kind k, unsigned num_parameters,
|
|||
return m.mk_func_decl(m_sigs[k]->m_name, arity, domain, rng, func_decl_info(m_family_id, k));
|
||||
|
||||
case _OP_REGEXP_FULL_CHAR:
|
||||
if (!range) {
|
||||
range = m_re;
|
||||
}
|
||||
if (!range) range = m_re;
|
||||
match(*m_sigs[k], arity, domain, range, rng);
|
||||
return m.mk_func_decl(symbol("re.allchar"), arity, domain, rng, func_decl_info(m_family_id, OP_RE_FULL_CHAR_SET));
|
||||
|
||||
|
@ -690,9 +688,7 @@ func_decl * seq_decl_plugin::mk_func_decl(decl_kind k, unsigned num_parameters,
|
|||
return m.mk_func_decl(m_sigs[k]->m_name, arity, domain, range, func_decl_info(m_family_id, k));
|
||||
|
||||
case _OP_REGEXP_EMPTY:
|
||||
if (!range) {
|
||||
range = m_re;
|
||||
}
|
||||
if (!range) range = m_re;
|
||||
match(*m_sigs[k], arity, domain, range, rng);
|
||||
return m.mk_func_decl(symbol("re.nostr"), arity, domain, rng, func_decl_info(m_family_id, OP_RE_EMPTY_SET));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue