mirror of
https://github.com/Z3Prover/z3
synced 2025-04-14 04:48:45 +00:00
Merge branch 'dl_transforms' of https://git01.codeplex.com/z3 into unstable
This commit is contained in:
commit
155f629d96
|
@ -7,7 +7,7 @@ Module Name:
|
|||
|
||||
Abstract:
|
||||
|
||||
<abstract>
|
||||
Functor for bit-blasting a rule set
|
||||
|
||||
Author:
|
||||
|
||||
|
@ -19,31 +19,16 @@ Revision History:
|
|||
#ifndef _DL_MK_BIT_BLAST_H_
|
||||
#define _DL_MK_BIT_BLAST_H_
|
||||
|
||||
#include<utility>
|
||||
|
||||
#include"map.h"
|
||||
#include"obj_pair_hashtable.h"
|
||||
#include"dl_context.h"
|
||||
#include"dl_rule_set.h"
|
||||
#include"dl_rule_transformer.h"
|
||||
|
||||
namespace datalog {
|
||||
|
||||
/**
|
||||
\brief Functor for bit-blasting a rule set.
|
||||
*/
|
||||
|
||||
class mk_bit_blast : public rule_transformer::plugin {
|
||||
class impl;
|
||||
|
||||
impl* m_impl;
|
||||
void blast(expr_ref& b);
|
||||
void reset();
|
||||
|
||||
impl* m_impl;
|
||||
public:
|
||||
mk_bit_blast(context & ctx, unsigned priority = 35000);
|
||||
~mk_bit_blast();
|
||||
|
||||
~mk_bit_blast();
|
||||
rule_set * operator()(rule_set const & source);
|
||||
};
|
||||
|
||||
|
|
|
@ -204,7 +204,7 @@ namespace datalog {
|
|||
m_inner_ctx.ensure_opened();
|
||||
it = source.begin();
|
||||
for (; it != end; ++it) {
|
||||
rule_ref r(*it, m_ctx.get_rule_manager());
|
||||
rule_ref r(*it, m_inner_ctx.get_rule_manager());
|
||||
m_inner_ctx.add_rule(r);
|
||||
m_inner_ctx.register_predicate(r->get_decl());
|
||||
}
|
||||
|
|
113
src/muz_qe/dl_mk_loop_counter.cpp
Normal file
113
src/muz_qe/dl_mk_loop_counter.cpp
Normal file
|
@ -0,0 +1,113 @@
|
|||
/*++
|
||||
Copyright (c) 2013 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
dl_mk_loop_counter.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
Add loop counter argument to relations.
|
||||
|
||||
Author:
|
||||
|
||||
Nikolaj Bjorner (nbjorner) 2013-03-31
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
|
||||
#include"dl_mk_loop_counter.h"
|
||||
#include"dl_context.h"
|
||||
|
||||
namespace datalog {
|
||||
|
||||
mk_loop_counter::mk_loop_counter(context & ctx, unsigned priority):
|
||||
plugin(priority),
|
||||
m(ctx.get_manager()),
|
||||
a(m),
|
||||
m_refs(m) {
|
||||
}
|
||||
|
||||
mk_loop_counter::~mk_loop_counter() { }
|
||||
|
||||
app_ref mk_loop_counter::add_arg(app* fn, unsigned idx) {
|
||||
expr_ref_vector args(m);
|
||||
func_decl* new_fn, *old_fn = fn->get_decl();
|
||||
args.append(fn->get_num_args(), fn->get_args());
|
||||
args.push_back(m.mk_var(idx, a.mk_int()));
|
||||
|
||||
if (!m_old2new.find(old_fn, new_fn)) {
|
||||
ptr_vector<sort> domain;
|
||||
domain.append(fn->get_num_args(), old_fn->get_domain());
|
||||
domain.push_back(a.mk_int());
|
||||
new_fn = m.mk_func_decl(old_fn->get_name(), domain.size(), domain.c_ptr(), old_fn->get_range());
|
||||
m_old2new.insert(old_fn, new_fn);
|
||||
m_new2old.insert(new_fn, old_fn);
|
||||
m_refs.push_back(new_fn);
|
||||
}
|
||||
return app_ref(m.mk_app(new_fn, args.size(), args.c_ptr()), m);
|
||||
}
|
||||
|
||||
rule_set * mk_loop_counter::operator()(rule_set const & source) {
|
||||
m_refs.reset();
|
||||
m_old2new.reset();
|
||||
m_new2old.reset();
|
||||
context& ctx = source.get_context();
|
||||
rule_manager& rm = source.get_rule_manager();
|
||||
rule_set * result = alloc(rule_set, 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, ++cnt) {
|
||||
tail.push_back(add_arg(r.get_tail(j), cnt));
|
||||
neg.push_back(r.is_neg_tail(j));
|
||||
ctx.register_predicate(tail.back()->get_decl());
|
||||
}
|
||||
for (unsigned j = utsz; j < tsz; ++j) {
|
||||
tail.push_back(r.get_tail(j));
|
||||
neg.push_back(false);
|
||||
}
|
||||
head = add_arg(r.get_head(), cnt);
|
||||
ctx.register_predicate(head->get_decl());
|
||||
// set the loop counter to be an increment of the previous
|
||||
bool found = false;
|
||||
unsigned last = head->get_num_args()-1;
|
||||
for (unsigned j = 0; !found && j < utsz; ++j) {
|
||||
if (head->get_decl() == tail[j]->get_decl()) {
|
||||
tail.push_back(m.mk_eq(head->get_arg(last),
|
||||
a.mk_add(tail[j]->get_arg(last),
|
||||
a.mk_numeral(rational(1), true))));
|
||||
neg.push_back(false);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
// initialize loop counter to 0 if none was found.
|
||||
if (!found) {
|
||||
expr_ref_vector args(m);
|
||||
args.append(head->get_num_args(), head->get_args());
|
||||
args[last] = a.mk_numeral(rational(0), true);
|
||||
head = m.mk_app(head->get_decl(), args.size(), args.c_ptr());
|
||||
}
|
||||
|
||||
new_rule = rm.mk(head, tail.size(), tail.c_ptr(), neg.c_ptr(), r.name(), true);
|
||||
result->add_rule(new_rule);
|
||||
}
|
||||
|
||||
// model converter: remove references to extra argument.
|
||||
// proof converter: remove references to extra argument as well.
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
};
|
47
src/muz_qe/dl_mk_loop_counter.h
Normal file
47
src/muz_qe/dl_mk_loop_counter.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*++
|
||||
Copyright (c) 2013 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
dl_mk_loop_counter.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Add loop counter argument to relations.
|
||||
|
||||
Author:
|
||||
|
||||
Nikolaj Bjorner (nbjorner) 2013-03-31
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
#ifndef _DL_MK_LOOP_COUNTER_H_
|
||||
#define _DL_MK_LOOP_COUNTER_H_
|
||||
|
||||
#include"dl_rule_transformer.h"
|
||||
#include"arith_decl_plugin.h"
|
||||
|
||||
namespace datalog {
|
||||
|
||||
class mk_loop_counter : public rule_transformer::plugin {
|
||||
ast_manager& m;
|
||||
arith_util a;
|
||||
func_decl_ref_vector m_refs;
|
||||
obj_map<func_decl, func_decl*> m_new2old;
|
||||
obj_map<func_decl, func_decl*> m_old2new;
|
||||
|
||||
app_ref add_arg(app* fn, unsigned idx);
|
||||
public:
|
||||
mk_loop_counter(context & ctx, unsigned priority = 33000);
|
||||
~mk_loop_counter();
|
||||
|
||||
rule_set * operator()(rule_set const & source);
|
||||
|
||||
func_decl* get_old(func_decl* f) const { return m_new2old.find(f); }
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif /* _DL_MK_LOOP_COUNTER_H_ */
|
||||
|
Loading…
Reference in a new issue