mirror of
https://github.com/Z3Prover/z3
synced 2025-06-04 21:31:22 +00:00
Moved extension_converter func_interp entry compression to func_interp.
Relates to #547
This commit is contained in:
parent
3b82604590
commit
ccd18283e7
4 changed files with 53 additions and 52 deletions
|
@ -105,10 +105,53 @@ void func_interp::reset_interp_cache() {
|
||||||
m_interp = 0;
|
m_interp = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool func_interp::is_fi_entry_expr(expr * e, ptr_vector<expr> & args) {
|
||||||
|
args.reset();
|
||||||
|
if (!is_app(e) || !m().is_ite(to_app(e)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
app * a = to_app(e);
|
||||||
|
expr * c = a->get_arg(0);
|
||||||
|
expr * t = a->get_arg(1);
|
||||||
|
expr * f = a->get_arg(2);
|
||||||
|
|
||||||
|
if ((m_arity == 0) ||
|
||||||
|
(m_arity == 1 && (!m().is_eq(c) || to_app(c)->get_num_args() != 2)) ||
|
||||||
|
(m_arity > 1 && (!m().is_and(c) || to_app(c)->get_num_args() != m_arity)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
args.resize(m_arity, 0);
|
||||||
|
for (unsigned i = 0; i < m_arity; i++) {
|
||||||
|
expr * ci = (m_arity == 1 && i == 0) ? to_app(c) : to_app(c)->get_arg(i);
|
||||||
|
|
||||||
|
if (!m().is_eq(ci) || to_app(ci)->get_num_args() != 2)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
expr * a0 = to_app(ci)->get_arg(0);
|
||||||
|
expr * a1 = to_app(ci)->get_arg(1);
|
||||||
|
if (is_var(a0) && to_var(a0)->get_idx() == i)
|
||||||
|
args[i] = a1;
|
||||||
|
else if (is_var(a1) && to_var(a1)->get_idx() == i)
|
||||||
|
args[i] = a0;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void func_interp::set_else(expr * e) {
|
void func_interp::set_else(expr * e) {
|
||||||
reset_interp_cache();
|
reset_interp_cache();
|
||||||
m_manager.inc_ref(e);
|
|
||||||
m_manager.dec_ref(m_else);
|
m_manager.dec_ref(m_else);
|
||||||
|
|
||||||
|
ptr_vector<expr> args;
|
||||||
|
while (is_fi_entry_expr(e, args)) {
|
||||||
|
TRACE("func_interp", tout << "fi entry expr: " << mk_ismt2_pp(e, m()) << std::endl;);
|
||||||
|
insert_entry(args.c_ptr(), to_app(e)->get_arg(1));
|
||||||
|
e = to_app(e)->get_arg(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_manager.inc_ref(e);
|
||||||
m_else = e;
|
m_else = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,6 +110,9 @@ public:
|
||||||
expr * get_interp() const;
|
expr * get_interp() const;
|
||||||
|
|
||||||
func_interp * translate(ast_translation & translator) const;
|
func_interp * translate(ast_translation & translator) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool is_fi_entry_expr(expr * e, ptr_vector<expr> & args);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -43,41 +43,6 @@ static void display_decls_info(std::ostream & out, model_ref & md) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool extension_model_converter::is_fi_entry_expr(expr * e, unsigned arity, ptr_vector<expr> & args) {
|
|
||||||
args.reset();
|
|
||||||
if (!is_app(e) || !m().is_ite(to_app(e)))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
app * a = to_app(e);
|
|
||||||
expr * c = a->get_arg(0);
|
|
||||||
expr * t = a->get_arg(1);
|
|
||||||
expr * f = a->get_arg(2);
|
|
||||||
|
|
||||||
if ((arity == 0) ||
|
|
||||||
(arity == 1 && (!m().is_eq(c) || to_app(c)->get_num_args() != 2)) ||
|
|
||||||
(arity > 1 && (!m().is_and(c) || to_app(c)->get_num_args() != arity)))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
args.resize(arity, 0);
|
|
||||||
for (unsigned i = 0; i < arity; i++) {
|
|
||||||
expr * ci = (arity == 1 && i == 0) ? to_app(c) : to_app(c)->get_arg(i);
|
|
||||||
|
|
||||||
if (!m().is_eq(ci) || to_app(ci)->get_num_args() != 2)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
expr * a0 = to_app(ci)->get_arg(0);
|
|
||||||
expr * a1 = to_app(ci)->get_arg(1);
|
|
||||||
if (is_var(a0) && to_var(a0)->get_idx() == i)
|
|
||||||
args[i] = a1;
|
|
||||||
else if (is_var(a1) && to_var(a1)->get_idx() == i)
|
|
||||||
args[i] = a0;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void extension_model_converter::operator()(model_ref & md, unsigned goal_idx) {
|
void extension_model_converter::operator()(model_ref & md, unsigned goal_idx) {
|
||||||
SASSERT(goal_idx == 0);
|
SASSERT(goal_idx == 0);
|
||||||
TRACE("extension_mc", model_v2_pp(tout, *md); display_decls_info(tout, md););
|
TRACE("extension_mc", model_v2_pp(tout, *md); display_decls_info(tout, md););
|
||||||
|
@ -97,14 +62,7 @@ void extension_model_converter::operator()(model_ref & md, unsigned goal_idx) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
func_interp * new_fi = alloc(func_interp, m(), arity);
|
func_interp * new_fi = alloc(func_interp, m(), arity);
|
||||||
expr * e = val.get();
|
new_fi->set_else(val);
|
||||||
ptr_vector<expr> args;
|
|
||||||
while (is_fi_entry_expr(e, arity, args)) {
|
|
||||||
TRACE("extension_mc", tout << "fi entry: " << mk_ismt2_pp(e, m()) << std::endl;);
|
|
||||||
new_fi->insert_entry(args.c_ptr(), to_app(e)->get_arg(1));
|
|
||||||
e = to_app(e)->get_arg(2);
|
|
||||||
}
|
|
||||||
new_fi->set_else(e);
|
|
||||||
md->register_decl(f, new_fi);
|
md->register_decl(f, new_fi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,9 +43,6 @@ public:
|
||||||
void insert(func_decl * v, expr * def);
|
void insert(func_decl * v, expr * def);
|
||||||
|
|
||||||
virtual model_converter * translate(ast_translation & translator);
|
virtual model_converter * translate(ast_translation & translator);
|
||||||
|
|
||||||
private:
|
|
||||||
bool is_fi_entry_expr(expr * e, unsigned arity, ptr_vector<expr> & args);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue