mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 09:05:31 +00:00
Merge remote-tracking branch 'upstream/master' into lackr
This commit is contained in:
commit
613edfc107
29 changed files with 275 additions and 101 deletions
|
@ -891,6 +891,7 @@ namespace datalog {
|
|||
}
|
||||
|
||||
lbool context::rel_query(unsigned num_rels, func_decl * const* rels) {
|
||||
m_last_answer = 0;
|
||||
ensure_engine();
|
||||
return m_engine->query(num_rels, rels);
|
||||
}
|
||||
|
|
|
@ -282,6 +282,8 @@ namespace datalog {
|
|||
|
||||
|
||||
func_decl* rule_manager::mk_query(expr* query, rule_set& rules) {
|
||||
TRACE("dl", tout << mk_pp(query, m) << "\n";);
|
||||
|
||||
ptr_vector<sort> vars;
|
||||
svector<symbol> names;
|
||||
app_ref_vector body(m);
|
||||
|
@ -290,6 +292,7 @@ namespace datalog {
|
|||
// Add implicit variables.
|
||||
// Remove existential prefix.
|
||||
bind_variables(query, false, q);
|
||||
|
||||
quantifier_hoister qh(m);
|
||||
qh.pull_quantifier(false, q, 0, &names);
|
||||
// retrieve free variables.
|
||||
|
@ -358,6 +361,7 @@ namespace datalog {
|
|||
if (!vars.empty()) {
|
||||
rule_expr = m.mk_forall(vars.size(), vars.c_ptr(), names.c_ptr(), impl);
|
||||
}
|
||||
TRACE("dl", tout << rule_expr << "\n";);
|
||||
|
||||
scoped_proof_mode _sc(m, m_ctx.generate_proof_trace()?PGM_FINE:PGM_DISABLED);
|
||||
proof_ref pr(m);
|
||||
|
|
|
@ -325,9 +325,10 @@ private:
|
|||
|
||||
void eliminate_disjunctions(expr_ref_vector::element_ref& body, proof_ref_vector& proofs) {
|
||||
expr* b = body.get();
|
||||
expr* e1;
|
||||
expr* e1, *e2;
|
||||
bool negate_args = false;
|
||||
bool is_disj = false;
|
||||
expr_ref_vector _body(m);
|
||||
unsigned num_disj = 0;
|
||||
expr* const* disjs = 0;
|
||||
if (!contains_predicate(b)) {
|
||||
|
@ -346,6 +347,14 @@ private:
|
|||
num_disj = to_app(e1)->get_num_args();
|
||||
disjs = to_app(e1)->get_args();
|
||||
}
|
||||
if (m.is_implies(b, e1, e2)) {
|
||||
is_disj = true;
|
||||
_body.push_back(mk_not(m, e1));
|
||||
_body.push_back(e2);
|
||||
disjs = _body.c_ptr();
|
||||
num_disj = 2;
|
||||
negate_args = false;
|
||||
}
|
||||
if (is_disj) {
|
||||
app* old_head = 0;
|
||||
if (m_memoize_disj.find(b, old_head)) {
|
||||
|
|
|
@ -114,9 +114,16 @@ struct dl_context {
|
|||
}
|
||||
}
|
||||
|
||||
bool collect_query(expr* q) {
|
||||
bool collect_query(func_decl* q) {
|
||||
if (m_collected_cmds) {
|
||||
expr_ref qr = m_context->bind_vars(q, false);
|
||||
ast_manager& m = m_cmd.m();
|
||||
expr_ref qr(m);
|
||||
expr_ref_vector args(m);
|
||||
for (unsigned i = 0; i < q->get_arity(); ++i) {
|
||||
args.push_back(m.mk_var(i, q->get_domain(i)));
|
||||
}
|
||||
qr = m.mk_app(q, args.size(), args.c_ptr());
|
||||
qr = m_context->bind_vars(qr, false);
|
||||
m_collected_cmds->m_queries.push_back(qr);
|
||||
m_trail.push(push_back_vector<dl_context, expr_ref_vector>(m_collected_cmds->m_queries));
|
||||
return true;
|
||||
|
@ -187,30 +194,30 @@ public:
|
|||
virtual void finalize(cmd_context & ctx) {
|
||||
}
|
||||
virtual void execute(cmd_context & ctx) {
|
||||
m_dl_ctx->add_rule(m_t, m_name, m_bound);
|
||||
m_dl_ctx->add_rule(m_t, m_name, m_bound);
|
||||
}
|
||||
};
|
||||
|
||||
class dl_query_cmd : public parametric_cmd {
|
||||
ref<dl_context> m_dl_ctx;
|
||||
expr* m_target;
|
||||
func_decl* m_target;
|
||||
public:
|
||||
dl_query_cmd(dl_context * dl_ctx):
|
||||
parametric_cmd("query"),
|
||||
m_dl_ctx(dl_ctx),
|
||||
m_target(0) {
|
||||
}
|
||||
virtual char const * get_usage() const { return "(exists (q) (and body))"; }
|
||||
virtual char const * get_usage() const { return "predicate"; }
|
||||
virtual char const * get_main_descr() const {
|
||||
return "pose a query based on the Horn rules.";
|
||||
return "pose a query to a predicate based on the Horn rules.";
|
||||
}
|
||||
|
||||
virtual cmd_arg_kind next_arg_kind(cmd_context & ctx) const {
|
||||
if (m_target == 0) return CPK_EXPR;
|
||||
if (m_target == 0) return CPK_FUNC_DECL;
|
||||
return parametric_cmd::next_arg_kind(ctx);
|
||||
}
|
||||
|
||||
virtual void set_next_arg(cmd_context & ctx, expr * t) {
|
||||
virtual void set_next_arg(cmd_context & ctx, func_decl* t) {
|
||||
m_target = t;
|
||||
}
|
||||
|
||||
|
@ -239,7 +246,7 @@ public:
|
|||
scoped_timer timer(timeout, &eh);
|
||||
cmd_context::scoped_watch sw(ctx);
|
||||
try {
|
||||
status = dlctx.query(m_target);
|
||||
status = dlctx.rel_query(1, &m_target);
|
||||
}
|
||||
catch (z3_error & ex) {
|
||||
ctx.regular_stream() << "(error \"query failed: " << ex.msg() << "\")" << std::endl;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue