mirror of
https://github.com/Z3Prover/z3
synced 2025-04-14 04:48:45 +00:00
add abstraction and instantiation
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
155f629d96
commit
3d486c4c98
|
@ -100,3 +100,9 @@ void expr_safe_replace::operator()(expr* e, expr_ref& res) {
|
|||
}
|
||||
res = cache.find(e);
|
||||
}
|
||||
|
||||
void expr_safe_replace::reset() {
|
||||
m_src.reset();
|
||||
m_dst.reset();
|
||||
m_subst.reset();
|
||||
}
|
||||
|
|
|
@ -38,6 +38,8 @@ public:
|
|||
void operator()(expr_ref& e) { (*this)(e.get(), e); }
|
||||
|
||||
void operator()(expr* src, expr_ref& e);
|
||||
|
||||
void reset();
|
||||
};
|
||||
|
||||
#endif /* __EXPR_SAFE_REPLACE_H__ */
|
||||
|
|
|
@ -46,6 +46,7 @@ Revision History:
|
|||
#include"dl_mk_bit_blast.h"
|
||||
#include"dl_mk_array_blast.h"
|
||||
#include"dl_mk_karr_invariants.h"
|
||||
#include"dl_mk_quantifier_abstraction.h"
|
||||
#include"datatype_decl_plugin.h"
|
||||
#include"expr_abstract.h"
|
||||
|
||||
|
@ -905,6 +906,9 @@ namespace datalog {
|
|||
m_transf.register_plugin(alloc(datalog::mk_rule_inliner, *this, 34890));
|
||||
m_transf.register_plugin(alloc(datalog::mk_subsumption_checker, *this, 34880));
|
||||
|
||||
|
||||
m_transf.register_plugin(alloc(datalog::mk_quantifier_abstraction, *this, 33000));
|
||||
|
||||
m_transf.register_plugin(alloc(datalog::mk_bit_blast, *this, 35000));
|
||||
m_transf.register_plugin(alloc(datalog::mk_array_blast, *this, 36000));
|
||||
m_transf.register_plugin(alloc(datalog::mk_karr_invariants, *this, 36010));
|
||||
|
|
206
src/muz_qe/dl_mk_quantifier_abstraction.cpp
Normal file
206
src/muz_qe/dl_mk_quantifier_abstraction.cpp
Normal file
|
@ -0,0 +1,206 @@
|
|||
/*++
|
||||
Copyright (c) 2013 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
dl_mk_quantifier_abstraction.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
Create quantified Horn clauses from benchmarks with arrays.
|
||||
|
||||
Author:
|
||||
|
||||
Ken McMillan
|
||||
Andrey Rybalchenko
|
||||
Nikolaj Bjorner (nbjorner) 2013-04-02
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
|
||||
#include "dl_mk_quantifier_abstraction.h"
|
||||
#include "dl_context.h"
|
||||
|
||||
namespace datalog {
|
||||
|
||||
mk_quantifier_abstraction::mk_quantifier_abstraction(
|
||||
context & ctx, unsigned priority):
|
||||
plugin(priority),
|
||||
m(ctx.get_manager()),
|
||||
m_ctx(ctx),
|
||||
a(m),
|
||||
m_refs(m) {
|
||||
}
|
||||
|
||||
mk_quantifier_abstraction::~mk_quantifier_abstraction() {
|
||||
|
||||
}
|
||||
|
||||
func_decl* mk_quantifier_abstraction::declare_pred(func_decl* old_p) {
|
||||
|
||||
unsigned sz = old_p->get_arity();
|
||||
unsigned num_arrays = 0;
|
||||
for (unsigned i = 0; i < sz; ++i) {
|
||||
if (a.is_array(old_p->get_domain(i))) {
|
||||
num_arrays++;
|
||||
}
|
||||
}
|
||||
if (num_arrays == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
func_decl* new_p = 0;
|
||||
if (!m_old2new.find(old_p, new_p)) {
|
||||
sort_ref_vector domain(m);
|
||||
for (unsigned i = 0; i < sz; ++i) {
|
||||
sort* s = old_p->get_domain(i);
|
||||
while (a.is_array(s)) {
|
||||
unsigned arity = get_array_arity(s);
|
||||
for (unsigned j = 0; j < arity; ++j) {
|
||||
domain.push_back(get_array_domain(s, j));
|
||||
}
|
||||
s = get_array_range(s);
|
||||
}
|
||||
domain.push_back(s);
|
||||
}
|
||||
SASSERT(old_p->get_range() == m.mk_bool_sort());
|
||||
new_p = m.mk_func_decl(old_p->get_name(), domain.size(), domain.c_ptr(), old_p->get_range());
|
||||
m_refs.push_back(new_p);
|
||||
m_ctx.register_predicate(new_p);
|
||||
}
|
||||
return new_p;
|
||||
}
|
||||
|
||||
app_ref mk_quantifier_abstraction::mk_head(app* p, unsigned idx) {
|
||||
func_decl* new_p = declare_pred(p->get_decl());
|
||||
if (!new_p) {
|
||||
return app_ref(p, m);
|
||||
}
|
||||
expr_ref_vector args(m);
|
||||
expr_ref arg(m);
|
||||
unsigned sz = p->get_num_args();
|
||||
for (unsigned i = 0; i < sz; ++i) {
|
||||
arg = p->get_arg(i);
|
||||
sort* s = m.get_sort(arg);
|
||||
while (a.is_array(s)) {
|
||||
unsigned arity = get_array_arity(s);
|
||||
for (unsigned j = 0; j < arity; ++j) {
|
||||
args.push_back(m.mk_var(idx++, get_array_domain(s, j)));
|
||||
}
|
||||
ptr_vector<expr> args2;
|
||||
args2.push_back(arg);
|
||||
args2.append(arity, args.c_ptr()-arity);
|
||||
arg = a.mk_select(args2.size(), args2.c_ptr());
|
||||
s = get_array_range(s);
|
||||
}
|
||||
args.push_back(arg);
|
||||
}
|
||||
return app_ref(m.mk_app(new_p, args.size(), args.c_ptr()), m);
|
||||
}
|
||||
|
||||
app_ref mk_quantifier_abstraction::mk_tail(app* p) {
|
||||
func_decl* old_p = p->get_decl();
|
||||
func_decl* new_p = declare_pred(old_p);
|
||||
if (!new_p) {
|
||||
return app_ref(p, m);
|
||||
}
|
||||
SASSERT(new_p->get_arity() > old_p->get_arity());
|
||||
unsigned num_extra_args = new_p->get_arity() - old_p->get_arity();
|
||||
var_shifter shift(m);
|
||||
expr_ref p_shifted(m);
|
||||
shift(p, num_extra_args, p_shifted);
|
||||
app* ps = to_app(p_shifted);
|
||||
expr_ref_vector args(m);
|
||||
app_ref_vector pats(m);
|
||||
sort_ref_vector vars(m);
|
||||
svector<symbol> names;
|
||||
expr_ref arg(m);
|
||||
unsigned idx = 0;
|
||||
unsigned sz = p->get_num_args();
|
||||
for (unsigned i = 0; i < sz; ++i) {
|
||||
arg = ps->get_arg(i);
|
||||
sort* s = m.get_sort(arg);
|
||||
bool is_pattern = false;
|
||||
while (a.is_array(s)) {
|
||||
is_pattern = true;
|
||||
unsigned arity = get_array_arity(s);
|
||||
for (unsigned j = 0; j < arity; ++j) {
|
||||
vars.push_back(get_array_domain(s, j));
|
||||
names.push_back(symbol(idx));
|
||||
args.push_back(m.mk_var(idx++, vars.back()));
|
||||
}
|
||||
ptr_vector<expr> args2;
|
||||
args2.push_back(arg);
|
||||
args2.append(arity, args.c_ptr()-arity);
|
||||
arg = a.mk_select(args2.size(), args2.c_ptr());
|
||||
s = get_array_range(s);
|
||||
}
|
||||
if (is_pattern) {
|
||||
pats.push_back(to_app(arg));
|
||||
}
|
||||
args.push_back(arg);
|
||||
}
|
||||
expr* pat = 0;
|
||||
expr_ref pattern(m);
|
||||
pattern = m.mk_pattern(pats.size(), pats.c_ptr());
|
||||
pat = pattern.get();
|
||||
app_ref result(m);
|
||||
symbol qid, skid;
|
||||
result = m.mk_app(new_p, args.size(), args.c_ptr());
|
||||
result = m.mk_eq(m.mk_forall(vars.size(), vars.c_ptr(), names.c_ptr(), result, 1, qid, skid, 1, &pat), m.mk_true());
|
||||
return result;
|
||||
}
|
||||
|
||||
rule_set * mk_quantifier_abstraction::operator()(rule_set const & source) {
|
||||
if (!m_ctx.get_params().quantify_arrays()) {
|
||||
return 0;
|
||||
}
|
||||
m_refs.reset();
|
||||
m_old2new.reset();
|
||||
m_new2old.reset();
|
||||
rule_manager& rm = source.get_rule_manager();
|
||||
rule_set * result = alloc(rule_set, m_ctx);
|
||||
unsigned sz = source.get_num_rules();
|
||||
rule_ref new_rule(rm);
|
||||
app_ref_vector tail(m);
|
||||
app_ref head(m);
|
||||
svector<bool> neg;
|
||||
rule_counter& vc = rm.get_counter();
|
||||
|
||||
for (unsigned i = 0; i < sz; ++i) {
|
||||
tail.reset();
|
||||
neg.reset();
|
||||
rule & r = *source.get_rule(i);
|
||||
unsigned cnt = vc.get_max_rule_var(r)+1;
|
||||
unsigned utsz = r.get_uninterpreted_tail_size();
|
||||
unsigned tsz = r.get_tail_size();
|
||||
for (unsigned j = 0; j < utsz; ++j) {
|
||||
tail.push_back(mk_tail(r.get_tail(j)));
|
||||
neg.push_back(r.is_neg_tail(j));
|
||||
}
|
||||
for (unsigned j = utsz; j < tsz; ++j) {
|
||||
tail.push_back(r.get_tail(j));
|
||||
neg.push_back(false);
|
||||
}
|
||||
head = mk_head(r.get_head(), cnt);
|
||||
|
||||
new_rule = rm.mk(head, tail.size(), tail.c_ptr(), neg.c_ptr(), r.name(), true);
|
||||
result->add_rule(new_rule);
|
||||
|
||||
}
|
||||
|
||||
// model converter: TBD.
|
||||
// proof converter: TBD.
|
||||
|
||||
if (m_old2new.empty()) {
|
||||
dealloc(result);
|
||||
result = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
61
src/muz_qe/dl_mk_quantifier_abstraction.h
Normal file
61
src/muz_qe/dl_mk_quantifier_abstraction.h
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*++
|
||||
Copyright (c) 2013 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
dl_mk_quantifier_abstraction.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Convert clauses with array arguments to predicates
|
||||
into Quantified Horn clauses.
|
||||
|
||||
Author:
|
||||
|
||||
Ken McMillan
|
||||
Andrey Rybalchenko
|
||||
Nikolaj Bjorner (nbjorner) 2013-04-02
|
||||
|
||||
Revision History:
|
||||
|
||||
Based on approach suggested in SAS 2013 paper
|
||||
"On Solving Universally Quantified Horn Clauses"
|
||||
|
||||
--*/
|
||||
#ifndef _DL_MK_QUANTIFIER_ABSTRACTION_H_
|
||||
#define _DL_MK_QUANTIFIER_ABSTRACTION_H_
|
||||
|
||||
|
||||
#include"dl_rule_transformer.h"
|
||||
#include"array_decl_plugin.h"
|
||||
|
||||
namespace datalog {
|
||||
|
||||
class context;
|
||||
|
||||
class mk_quantifier_abstraction : public rule_transformer::plugin {
|
||||
ast_manager& m;
|
||||
context& m_ctx;
|
||||
array_util a;
|
||||
func_decl_ref_vector m_refs;
|
||||
obj_map<func_decl, func_decl*> m_new2old;
|
||||
obj_map<func_decl, func_decl*> m_old2new;
|
||||
|
||||
func_decl* declare_pred(func_decl* old_p);
|
||||
app_ref mk_head(app* p, unsigned idx);
|
||||
app_ref mk_tail(app* p);
|
||||
|
||||
public:
|
||||
mk_quantifier_abstraction(context & ctx, unsigned priority);
|
||||
|
||||
virtual ~mk_quantifier_abstraction();
|
||||
|
||||
rule_set * operator()(rule_set const & source);
|
||||
};
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif /* _DL_MK_QUANTIFIER_ABSTRACTION_H_ */
|
||||
|
295
src/muz_qe/dl_mk_quantifier_instantiation.cpp
Normal file
295
src/muz_qe/dl_mk_quantifier_instantiation.cpp
Normal file
|
@ -0,0 +1,295 @@
|
|||
/*++
|
||||
Copyright (c) 2013 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
dl_mk_quantifier_instantiation.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
Convert Quantified Horn clauses into non-quantified clauses using
|
||||
instantiation.
|
||||
|
||||
Author:
|
||||
|
||||
Ken McMillan
|
||||
Andrey Rybalchenko
|
||||
Nikolaj Bjorner (nbjorner) 2013-04-02
|
||||
|
||||
Revision History:
|
||||
|
||||
Based on approach suggested in SAS 2013 paper
|
||||
"On Solving Universally Quantified Horn Clauses"
|
||||
|
||||
--*/
|
||||
|
||||
#include "dl_mk_quantifier_instantiation.h"
|
||||
#include "dl_context.h"
|
||||
|
||||
namespace datalog {
|
||||
|
||||
mk_quantifier_instantiation::mk_quantifier_instantiation(
|
||||
context & ctx, unsigned priority):
|
||||
plugin(priority),
|
||||
m(ctx.get_manager()),
|
||||
m_ctx(ctx),
|
||||
m_var2cnst(m),
|
||||
m_cnst2var(m),
|
||||
a(m) {
|
||||
}
|
||||
|
||||
mk_quantifier_instantiation::~mk_quantifier_instantiation() {
|
||||
|
||||
}
|
||||
|
||||
void mk_quantifier_instantiation::extract_quantifiers(rule& r, expr_ref_vector& conjs, quantifier_ref_vector& qs) {
|
||||
conjs.reset();
|
||||
qs.reset();
|
||||
unsigned tsz = r.get_tail_size();
|
||||
for (unsigned j = 0; j < tsz; ++j) {
|
||||
conjs.push_back(r.get_tail(j));
|
||||
|
||||
}
|
||||
datalog::flatten_and(conjs);
|
||||
for (unsigned j = 0; j < conjs.size(); ++j) {
|
||||
expr* e = conjs[j].get();
|
||||
quantifier* q;
|
||||
if (rule_manager::is_forall(m, e, q)) {
|
||||
qs.push_back(q);
|
||||
conjs[j] = conjs.back();
|
||||
conjs.pop_back();
|
||||
--j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mk_quantifier_instantiation::instantiate_quantifier(quantifier* q, expr_ref_vector & conjs) {
|
||||
expr_ref qe(m);
|
||||
qe = q;
|
||||
m_var2cnst(qe);
|
||||
q = to_quantifier(qe);
|
||||
unsigned num_patterns = q->get_num_patterns();
|
||||
for (unsigned i = 0; i < num_patterns; ++i) {
|
||||
expr * pat = q->get_pattern(i);
|
||||
SASSERT(m.is_pattern(pat));
|
||||
instantiate_quantifier(q, to_app(pat), conjs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void mk_quantifier_instantiation::instantiate_quantifier(quantifier* q, app* pat, expr_ref_vector & conjs) {
|
||||
unsigned sz = pat->get_num_args();
|
||||
m_binding.reset();
|
||||
m_binding.resize(q->get_num_decls());
|
||||
term_pairs todo;
|
||||
match(0, pat, 0, todo, q, conjs);
|
||||
}
|
||||
|
||||
void mk_quantifier_instantiation::match(unsigned i, app* pat, unsigned j, term_pairs& todo, quantifier* q, expr_ref_vector& conjs) {
|
||||
while (j < todo.size()) {
|
||||
expr* p = todo[j].first;
|
||||
expr* t = todo[j].second;
|
||||
if (is_var(p)) {
|
||||
unsigned idx = to_var(p)->get_idx();
|
||||
expr* t2 = m_binding[idx];
|
||||
if (!t2) {
|
||||
m_binding[idx] = t;
|
||||
match(i, pat, j + 1, todo, q, conjs);
|
||||
m_binding[idx] = 0;
|
||||
return;
|
||||
}
|
||||
else if (m_uf.find(t2->get_id()) != m_uf.find(t->get_id())) {
|
||||
// matching failed.
|
||||
return;
|
||||
}
|
||||
j += 1;
|
||||
continue;
|
||||
}
|
||||
if (!is_app(p)) {
|
||||
return;
|
||||
}
|
||||
app* a1 = to_app(p);
|
||||
unsigned id = t->get_id();
|
||||
unsigned next_id = id;
|
||||
unsigned sz = todo.size();
|
||||
do {
|
||||
expr* t2 = m_terms[next_id];
|
||||
if (is_app(t2)) {
|
||||
app* a2 = to_app(t2);
|
||||
if (a1->get_decl() == a2->get_decl() &&
|
||||
a1->get_num_args() == a2->get_num_args()) {
|
||||
for (unsigned k = 0; k < a1->get_num_args(); ++k) {
|
||||
todo.push_back(std::make_pair(a1->get_arg(k), a2->get_arg(k)));
|
||||
}
|
||||
match(i, pat, j + 1, todo, q, conjs);
|
||||
todo.resize(sz);
|
||||
}
|
||||
}
|
||||
next_id = m_uf.next(id);
|
||||
}
|
||||
while (next_id != id);
|
||||
return;
|
||||
}
|
||||
|
||||
if (i == pat->get_num_args()) {
|
||||
yield_binding(q, conjs);
|
||||
return;
|
||||
}
|
||||
expr* arg = pat->get_arg(i);
|
||||
ptr_vector<expr>* terms = 0;
|
||||
|
||||
if (m_funs.find(to_app(arg)->get_decl(), terms)) {
|
||||
for (unsigned k = 0; k < terms->size(); ++k) {
|
||||
todo.push_back(std::make_pair(arg, (*terms)[k]));
|
||||
match(i + 1, pat, j, todo, q, conjs);
|
||||
todo.pop_back();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mk_quantifier_instantiation::yield_binding(quantifier* q, expr_ref_vector& conjs) {
|
||||
DEBUG_CODE(
|
||||
for (unsigned i = 0; i < m_binding.size(); ++i) {
|
||||
SASSERT(m_binding[i]);
|
||||
});
|
||||
m_binding.reverse();
|
||||
expr_ref res(m);
|
||||
instantiate(m, q, m_binding.c_ptr(), res);
|
||||
m_binding.reverse();
|
||||
conjs.push_back(res);
|
||||
}
|
||||
|
||||
void mk_quantifier_instantiation::merge(expr* e1, expr* e2) {
|
||||
unsigned i1 = e1->get_id();
|
||||
unsigned i2 = e2->get_id();
|
||||
unsigned n = std::max(i1, i2);
|
||||
while (n >= m_uf.get_num_vars()) {
|
||||
m_uf.mk_var();
|
||||
}
|
||||
m_uf.merge(i1, i2);
|
||||
}
|
||||
|
||||
void mk_quantifier_instantiation::collect_egraph(expr* e) {
|
||||
expr* e1, *e2;
|
||||
m_todo.push_back(e);
|
||||
expr_fast_mark1 visited;
|
||||
while (!m_todo.empty()) {
|
||||
e = m_todo.back();
|
||||
m_todo.pop_back();
|
||||
if (visited.is_marked(e)) {
|
||||
continue;
|
||||
}
|
||||
if (e->get_id() >= m_terms.size()) {
|
||||
m_terms.resize(e->get_id()+1);
|
||||
}
|
||||
m_terms[e->get_id()] = e;
|
||||
visited.mark(e);
|
||||
if (m.is_eq(e, e1, e2) || m.is_iff(e, e1, e2)) {
|
||||
merge(e1, e2);
|
||||
}
|
||||
if (is_app(e)) {
|
||||
app* ap = to_app(e);
|
||||
ptr_vector<expr>* terms = 0;
|
||||
if (m_funs.find(ap->get_decl(), terms)) {
|
||||
terms = alloc(ptr_vector<expr>);
|
||||
m_funs.insert(ap->get_decl(), terms);
|
||||
}
|
||||
terms->push_back(e);
|
||||
m_todo.append(ap->get_num_args(), ap->get_args());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mk_quantifier_instantiation::instantiate_rule(rule& r, expr_ref_vector& conjs, quantifier_ref_vector& qs, rule_set& rules) {
|
||||
rule_manager& rm = m_ctx.get_rule_manager();
|
||||
expr_ref fml(m), cnst(m);
|
||||
var_ref var(m);
|
||||
ptr_vector<sort> sorts;
|
||||
r.get_vars(sorts);
|
||||
m_uf.reset();
|
||||
m_terms.reset();
|
||||
m_var2cnst.reset();
|
||||
m_cnst2var.reset();
|
||||
fml = m.mk_and(conjs.size(), conjs.c_ptr());
|
||||
|
||||
for (unsigned i = 0; i < sorts.size(); ++i) {
|
||||
if (!sorts[i]) {
|
||||
sorts[i] = m.mk_bool_sort();
|
||||
}
|
||||
var = m.mk_var(i, sorts[i]);
|
||||
cnst = m.mk_fresh_const("C", sorts[i]);
|
||||
m_var2cnst.insert(var, cnst);
|
||||
m_cnst2var.insert(cnst, var);
|
||||
}
|
||||
|
||||
fml = m.mk_and(conjs.size(), conjs.c_ptr());
|
||||
m_var2cnst(fml);
|
||||
collect_egraph(fml);
|
||||
|
||||
for (unsigned i = 0; i < qs.size(); ++i) {
|
||||
instantiate_quantifier(qs[i].get(), conjs);
|
||||
}
|
||||
obj_map<func_decl, ptr_vector<expr>*>::iterator it = m_funs.begin(), end = m_funs.end();
|
||||
for (; it != end; ++it) {
|
||||
dealloc(it->m_value);
|
||||
}
|
||||
m_funs.reset();
|
||||
|
||||
fml = m.mk_and(conjs.size(), conjs.c_ptr());
|
||||
fml = m.mk_implies(fml, r.get_head());
|
||||
|
||||
rule_ref_vector added_rules(rm);
|
||||
proof_ref pr(m); // proofs are TBD.
|
||||
rm.mk_rule(fml, pr, added_rules);
|
||||
rules.add_rules(added_rules.size(), added_rules.c_ptr());
|
||||
}
|
||||
|
||||
rule_set * mk_quantifier_instantiation::operator()(rule_set const & source) {
|
||||
if (!m_ctx.get_params().instantiate_quantifiers()) {
|
||||
return 0;
|
||||
}
|
||||
bool has_quantifiers = false;
|
||||
unsigned sz = source.get_num_rules();
|
||||
for (unsigned i = 0; !has_quantifiers && i < sz; ++i) {
|
||||
rule& r = *source.get_rule(i);
|
||||
has_quantifiers = has_quantifiers || r.has_quantifiers();
|
||||
if (r.has_negation()) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (!has_quantifiers) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
expr_ref_vector conjs(m);
|
||||
quantifier_ref_vector qs(m);
|
||||
rule_set * result = alloc(rule_set, m_ctx);
|
||||
|
||||
bool instantiated = false;
|
||||
|
||||
for (unsigned i = 0; i < sz; ++i) {
|
||||
rule * r = source.get_rule(i);
|
||||
extract_quantifiers(*r, conjs, qs);
|
||||
if (qs.empty()) {
|
||||
result->add_rule(r);
|
||||
}
|
||||
else {
|
||||
instantiate_rule(*r, conjs, qs, *result);
|
||||
instantiated = true;
|
||||
}
|
||||
}
|
||||
|
||||
// model converter: TBD.
|
||||
// proof converter: TBD.
|
||||
|
||||
if (!instantiated) {
|
||||
dealloc(result);
|
||||
result = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
120
src/muz_qe/dl_mk_quantifier_instantiation.h
Normal file
120
src/muz_qe/dl_mk_quantifier_instantiation.h
Normal file
|
@ -0,0 +1,120 @@
|
|||
/*++
|
||||
Copyright (c) 2013 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
dl_mk_quantifier_instantiation.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Convert Quantified Horn clauses into non-quantified clauses using
|
||||
instantiation.
|
||||
|
||||
Author:
|
||||
|
||||
Ken McMillan
|
||||
Andrey Rybalchenko
|
||||
Nikolaj Bjorner (nbjorner) 2013-04-02
|
||||
|
||||
Revision History:
|
||||
|
||||
Based on approach suggested in SAS 2013 paper
|
||||
"On Solving Universally Quantified Horn Clauses"
|
||||
|
||||
--*/
|
||||
#ifndef _DL_MK_QUANTIFIER_INSTANTIATION_H_
|
||||
#define _DL_MK_QUANTIFIER_INSTANTIATION_H_
|
||||
|
||||
|
||||
#include"dl_rule_transformer.h"
|
||||
#include"array_decl_plugin.h"
|
||||
#include"expr_safe_replace.h"
|
||||
|
||||
|
||||
namespace datalog {
|
||||
|
||||
class context;
|
||||
|
||||
class mk_quantifier_instantiation : public rule_transformer::plugin {
|
||||
typedef svector<std::pair<expr*,expr*> > term_pairs;
|
||||
|
||||
class union_find {
|
||||
unsigned_vector m_find;
|
||||
unsigned_vector m_size;
|
||||
unsigned_vector m_next;
|
||||
public:
|
||||
unsigned mk_var() {
|
||||
unsigned r = m_find.size();
|
||||
m_find.push_back(r);
|
||||
m_size.push_back(1);
|
||||
m_next.push_back(r);
|
||||
return r;
|
||||
}
|
||||
unsigned get_num_vars() const { return m_find.size(); }
|
||||
|
||||
unsigned find(unsigned v) const {
|
||||
while (true) {
|
||||
unsigned new_v = m_find[v];
|
||||
if (new_v == v)
|
||||
return v;
|
||||
v = new_v;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned next(unsigned v) const { return m_next[v]; }
|
||||
|
||||
bool is_root(unsigned v) const { return m_find[v] == v; }
|
||||
|
||||
void merge(unsigned v1, unsigned v2) {
|
||||
unsigned r1 = find(v1);
|
||||
unsigned r2 = find(v2);
|
||||
if (r1 == r2)
|
||||
return;
|
||||
if (m_size[r1] > m_size[r2])
|
||||
std::swap(r1, r2);
|
||||
m_find[r1] = r2;
|
||||
m_size[r2] += m_size[r1];
|
||||
std::swap(m_next[r1], m_next[r2]);
|
||||
}
|
||||
|
||||
void reset() {
|
||||
m_find.reset();
|
||||
m_next.reset();
|
||||
m_size.reset();
|
||||
}
|
||||
};
|
||||
ast_manager& m;
|
||||
context& m_ctx;
|
||||
expr_safe_replace m_var2cnst;
|
||||
expr_safe_replace m_cnst2var;
|
||||
array_util a;
|
||||
union_find m_uf;
|
||||
ptr_vector<expr> m_todo;
|
||||
ptr_vector<expr> m_terms;
|
||||
ptr_vector<expr> m_binding;
|
||||
obj_map<func_decl, ptr_vector<expr>*> m_funs;
|
||||
|
||||
|
||||
void merge(expr* e1, expr* e2);
|
||||
void extract_quantifiers(rule& r, expr_ref_vector& conjs, quantifier_ref_vector& qs);
|
||||
void collect_egraph(expr* e);
|
||||
void instantiate_rule(rule& r, expr_ref_vector& conjs, quantifier_ref_vector& qs, rule_set& rules);
|
||||
void instantiate_quantifier(quantifier* q, expr_ref_vector & conjs);
|
||||
void mk_quantifier_instantiation::instantiate_quantifier(quantifier* q, app* pat, expr_ref_vector & conjs);
|
||||
void mk_quantifier_instantiation::match(unsigned i, app* pat, unsigned j, term_pairs& todo, quantifier* q, expr_ref_vector& conjs);
|
||||
void mk_quantifier_instantiation::yield_binding(quantifier* q, expr_ref_vector& conjs);
|
||||
|
||||
public:
|
||||
mk_quantifier_instantiation(context & ctx, unsigned priority);
|
||||
|
||||
virtual ~mk_quantifier_instantiation();
|
||||
|
||||
rule_set * operator()(rule_set const & source);
|
||||
};
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif /* _DL_MK_QUANTIFIER_INSTANTIATION_H_ */
|
||||
|
|
@ -42,6 +42,8 @@ def_module_params('fixedpoint',
|
|||
('simplify_formulas_post', BOOL, False, "PDR: simplify derived formulas after inductive propagation"),
|
||||
('slice', BOOL, True, "PDR: simplify clause set using slicing"),
|
||||
('karr', BOOL, False, "Add linear invariants to clauses using Karr's method"),
|
||||
('quantify_arrays', BOOL, False, "create quantified Horn clauses from clauses with arrays"),
|
||||
('instantiate_quantifiers', BOOL, False, "instantiate quantified Horn clauses using E-matching heuristic"),
|
||||
('coalesce_rules', BOOL, False, "BMC: coalesce rules"),
|
||||
('use_multicore_generalizer', BOOL, False, "PDR: extract multiple cores for blocking states"),
|
||||
('use_inductive_generalizer', BOOL, True, "PDR: generalize lemmas using induction strengthening"),
|
||||
|
|
Loading…
Reference in a new issue