3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 09:05:31 +00:00

Moved is_int_expr into arith_recognizers

This commit is contained in:
Arie Gurfinkel 2018-06-05 17:11:19 -07:00
parent cb683389f6
commit 8b689ae27f
3 changed files with 253 additions and 250 deletions

View file

@ -81,7 +81,7 @@ app * arith_decl_plugin::mk_numeral(algebraic_numbers::anum const & val, bool is
return mk_numeral(rval, is_int);
}
else {
if (is_int) {
if (is_int) {
m_manager->raise_exception("invalid irrational value passed as an integer");
}
unsigned idx = aw().mk_id(val);
@ -638,6 +638,35 @@ bool arith_recognizers::is_numeral(expr const * n, rational & val, bool & is_int
return true;
}
#define IS_INT_EXPR_DEPTH_LIMIT 100
bool arith_recognizers::is_int_expr(expr const *e) const {
if (is_int(e)) return true;
if (is_uninterp(e)) return false;
ptr_buffer<const expr> todo;
todo.push_back(e);
rational r;
unsigned i = 0;
while (!todo.empty()) {
++i;
if (i > IS_INT_EXPR_DEPTH_LIMIT) {return false;}
e = todo.back();
todo.pop_back();
if (is_to_real(e)) {
// pass
}
else if (is_numeral(e, r) && r.is_int()) {
// pass
}
else if (is_add(e) || is_mul(e)) {
todo.append(to_app(e)->get_num_args(), to_app(e)->get_args());
}
else {
return false;
}
}
return true;
}
arith_util::arith_util(ast_manager & m):
arith_recognizers(m.mk_family_id("arith")),
m_manager(m),

View file

@ -244,6 +244,8 @@ public:
return false;
}
bool is_int_expr(expr const * e) const;
bool is_le(expr const * n) const { return is_app_of(n, m_afid, OP_LE); }
bool is_ge(expr const * n) const { return is_app_of(n, m_afid, OP_GE); }
bool is_lt(expr const * n) const { return is_app_of(n, m_afid, OP_LT); }
@ -533,4 +535,3 @@ inline app_ref operator>(app_ref const& x, app_ref const& y) {
}
#endif /* ARITH_DECL_PLUGIN_H_ */