mirror of
https://github.com/Z3Prover/z3
synced 2025-08-03 18:00:23 +00:00
int<->real coercions.
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
c48bd1e8de
commit
75457e1393
9 changed files with 184 additions and 21 deletions
|
@ -943,6 +943,42 @@ br_status arith_rewriter::mk_to_int_core(expr * arg, expr_ref & result) {
|
|||
return BR_DONE;
|
||||
}
|
||||
else {
|
||||
if (m_util.is_add(arg) || m_util.is_mul(arg) || m_util.is_power(arg)) {
|
||||
// Try to apply simplifications such as:
|
||||
// (to_int (+ 1.0 (to_real x))) --> (+ 1 x)
|
||||
|
||||
// if all arguments of arg are
|
||||
// - integer numerals, OR
|
||||
// - to_real applications
|
||||
// then, to_int can be eliminated
|
||||
unsigned num_args = to_app(arg)->get_num_args();
|
||||
unsigned i = 0;
|
||||
for (; i < num_args; i++) {
|
||||
expr * c = to_app(arg)->get_arg(i);
|
||||
if (m_util.is_numeral(c, a) && a.is_int())
|
||||
continue;
|
||||
if (m_util.is_to_real(c))
|
||||
continue;
|
||||
break; // failed
|
||||
}
|
||||
if (i == num_args) {
|
||||
// simplification can be applied
|
||||
expr_ref_buffer new_args(m());
|
||||
for (i = 0; i < num_args; i++) {
|
||||
expr * c = to_app(arg)->get_arg(i);
|
||||
if (m_util.is_numeral(c, a) && a.is_int()) {
|
||||
new_args.push_back(m_util.mk_numeral(a, true));
|
||||
}
|
||||
else {
|
||||
SASSERT(m_util.is_to_real(c));
|
||||
new_args.push_back(to_app(c)->get_arg(0));
|
||||
}
|
||||
}
|
||||
SASSERT(num_args == new_args.size());
|
||||
result = m().mk_app(get_fid(), to_app(arg)->get_decl()->get_decl_kind(), new_args.size(), new_args.c_ptr());
|
||||
return BR_REWRITE1;
|
||||
}
|
||||
}
|
||||
return BR_FAILED;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue