3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 09:05:31 +00:00
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2019-03-28 16:11:16 -07:00
parent 7a6823aef1
commit 1c694fd42f
7 changed files with 130 additions and 63 deletions

View file

@ -2122,6 +2122,7 @@ public:
app * mk_or(expr * arg1, expr * arg2) { return mk_app(m_basic_family_id, OP_OR, arg1, arg2); }
app * mk_and(expr * arg1, expr * arg2) { return mk_app(m_basic_family_id, OP_AND, arg1, arg2); }
app * mk_or(expr * arg1, expr * arg2, expr * arg3) { return mk_app(m_basic_family_id, OP_OR, arg1, arg2, arg3); }
app * mk_or(expr* a, expr* b, expr* c, expr* d) { expr* args[4] = { a, b, c, d }; return mk_app(m_basic_family_id, OP_OR, 4, args); }
app * mk_and(expr * arg1, expr * arg2, expr * arg3) { return mk_app(m_basic_family_id, OP_AND, arg1, arg2, arg3); }
app * mk_implies(expr * arg1, expr * arg2) { return mk_app(m_basic_family_id, OP_IMPLIES, arg1, arg2); }
app * mk_not(expr * n) { return mk_app(m_basic_family_id, OP_NOT, n); }

View file

@ -52,28 +52,50 @@ expr_pattern_match::match_quantifier(quantifier* qf, app_ref_vector& patterns, u
}
m_regs[0] = qf->get_expr();
for (unsigned i = 0; i < m_precompiled.size(); ++i) {
quantifier* qf2 = m_precompiled[i].get();
if (qf2->get_kind() != qf->get_kind() || is_lambda(qf)) {
continue;
}
if (qf2->get_num_decls() != qf->get_num_decls()) {
continue;
}
subst s;
if (match(qf->get_expr(), m_first_instrs[i], s)) {
for (unsigned j = 0; j < qf2->get_num_patterns(); ++j) {
app* p = static_cast<app*>(qf2->get_pattern(j));
expr_ref p_result(m_manager);
instantiate(p, qf->get_num_decls(), s, p_result);
patterns.push_back(to_app(p_result.get()));
}
weight = qf2->get_weight();
return true;
if (match_quantifier(i, qf, patterns, weight))
return true;
}
return false;
}
bool
expr_pattern_match::match_quantifier(unsigned i, quantifier* qf, app_ref_vector& patterns, unsigned& weight) {
quantifier* qf2 = m_precompiled[i].get();
if (qf2->get_kind() != qf->get_kind() || is_lambda(qf)) {
return false;
}
if (qf2->get_num_decls() != qf->get_num_decls()) {
return false;
}
subst s;
if (match(qf->get_expr(), m_first_instrs[i], s)) {
for (unsigned j = 0; j < qf2->get_num_patterns(); ++j) {
app* p = static_cast<app*>(qf2->get_pattern(j));
expr_ref p_result(m_manager);
instantiate(p, qf->get_num_decls(), s, p_result);
patterns.push_back(to_app(p_result.get()));
}
weight = qf2->get_weight();
return true;
}
return false;
}
bool expr_pattern_match::match_quantifier_index(quantifier* qf, app_ref_vector& patterns, unsigned& index) {
if (m_regs.empty()) return false;
m_regs[0] = qf->get_expr();
for (unsigned i = 0; i < m_precompiled.size(); ++i) {
unsigned weight = 0;
if (match_quantifier(i, qf, patterns, weight)) {
index = i;
return true;
}
}
return false;
}
void
expr_pattern_match::instantiate(expr* a, unsigned num_bound, subst& s, expr_ref& result) {
bound b;
@ -399,8 +421,16 @@ expr_pattern_match::initialize(char const * spec_string) {
TRACE("expr_pattern_match", display(tout); );
}
void
expr_pattern_match::display(std::ostream& out) const {
unsigned expr_pattern_match::initialize(quantifier* q) {
if (m_instrs.empty()) {
m_instrs.push_back(instr(BACKTRACK));
}
compile(q);
return m_precompiled.size() - 1;
}
void expr_pattern_match::display(std::ostream& out) const {
for (unsigned i = 0; i < m_instrs.size(); ++i) {
display(out, m_instrs[i]);
}

View file

@ -131,11 +131,14 @@ class expr_pattern_match {
public:
expr_pattern_match(ast_manager & manager);
~expr_pattern_match();
virtual bool match_quantifier(quantifier * qf, app_ref_vector & patterns, unsigned & weight);
virtual void initialize(char const * database);
bool match_quantifier(quantifier * qf, app_ref_vector & patterns, unsigned & weight);
bool match_quantifier_index(quantifier* qf, app_ref_vector & patterns, unsigned& index);
unsigned initialize(quantifier* qf);
void initialize(char const * database);
void display(std::ostream& out) const;
private:
bool match_quantifier(unsigned i, quantifier * qf, app_ref_vector & patterns, unsigned & weight);
void instantiate(expr* a, unsigned num_bound, subst& s, expr_ref& result);
void compile(expr* q);
bool match(expr* a, unsigned init, subst& s);

View file

@ -93,4 +93,5 @@ void func_decl_replace::reset() {
m_cache.reset();
m_subst.reset();
m_refs.reset();
m_funs.reset();
}

View file

@ -27,13 +27,14 @@ class func_decl_replace {
ast_manager& m;
obj_map<func_decl, func_decl*> m_subst;
obj_map<expr, expr*> m_cache;
ptr_vector<expr> m_todo, m_args;
expr_ref_vector m_refs;
ptr_vector<expr> m_todo, m_args;
expr_ref_vector m_refs;
func_decl_ref_vector m_funs;
public:
func_decl_replace(ast_manager& m): m(m), m_refs(m) {}
func_decl_replace(ast_manager& m): m(m), m_refs(m), m_funs(m) {}
void insert(func_decl* src, func_decl* dst) { m_subst.insert(src, dst); }
void insert(func_decl* src, func_decl* dst) { m_subst.insert(src, dst); m_funs.push_back(src), m_funs.push_back(dst); }
expr_ref operator()(expr* e);