mirror of
https://github.com/Z3Prover/z3
synced 2025-04-12 12:08:18 +00:00
add visitor example, fix double conversion
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
4fc64ab578
commit
a990e7f02e
|
@ -802,11 +802,19 @@ void tactic_qe() {
|
||||||
std::cout << s.get_model() << "\n";
|
std::cout << s.get_model() << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void visit(expr const & e) {
|
void visit(std::vector<bool>& visited, expr const & e) {
|
||||||
|
if (visited.size() <= e.id()) {
|
||||||
|
visited.resize(e.id()+1, false);
|
||||||
|
}
|
||||||
|
if (visited[e.id()]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
visited[e.id()] = true;
|
||||||
|
|
||||||
if (e.is_app()) {
|
if (e.is_app()) {
|
||||||
unsigned num = e.num_args();
|
unsigned num = e.num_args();
|
||||||
for (unsigned i = 0; i < num; i++) {
|
for (unsigned i = 0; i < num; i++) {
|
||||||
visit(e.arg(i));
|
visit(visited, e.arg(i));
|
||||||
}
|
}
|
||||||
// do something
|
// do something
|
||||||
// Example: print the visited expression
|
// Example: print the visited expression
|
||||||
|
@ -814,7 +822,7 @@ void visit(expr const & e) {
|
||||||
std::cout << "application of " << f.name() << ": " << e << "\n";
|
std::cout << "application of " << f.name() << ": " << e << "\n";
|
||||||
}
|
}
|
||||||
else if (e.is_quantifier()) {
|
else if (e.is_quantifier()) {
|
||||||
visit(e.body());
|
visit(visited, e.body());
|
||||||
// do something
|
// do something
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -830,12 +838,13 @@ void tst_visit() {
|
||||||
expr x = c.int_const("x");
|
expr x = c.int_const("x");
|
||||||
expr y = c.int_const("y");
|
expr y = c.int_const("y");
|
||||||
expr z = c.int_const("z");
|
expr z = c.int_const("z");
|
||||||
expr f = x*x - y*y >= 0;
|
expr f = x*x + x*x - y*y >= 0;
|
||||||
|
std::vector<bool> visited;
|
||||||
visit(f);
|
visit(visited, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_numeral() {
|
void tst_numeral() {
|
||||||
|
std::cout << "numeral example\n";
|
||||||
context c;
|
context c;
|
||||||
expr x = c.real_val("1/3");
|
expr x = c.real_val("1/3");
|
||||||
double d = 0;
|
double d = 0;
|
||||||
|
|
|
@ -239,13 +239,21 @@ extern "C" {
|
||||||
expr* e = to_expr(a);
|
expr* e = to_expr(a);
|
||||||
fpa_util & fu = mk_c(c)->fpautil();
|
fpa_util & fu = mk_c(c)->fpautil();
|
||||||
scoped_mpf tmp(fu.fm());
|
scoped_mpf tmp(fu.fm());
|
||||||
if (!mk_c(c)->fpautil().is_numeral(e, tmp) ||
|
if (mk_c(c)->fpautil().is_numeral(e, tmp)) {
|
||||||
tmp.get().get_ebits() > 11 ||
|
if (tmp.get().get_ebits() > 11 ||
|
||||||
tmp.get().get_sbits() > 53) {
|
tmp.get().get_sbits() > 53) {
|
||||||
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
|
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
|
||||||
return NAN;
|
return NAN;
|
||||||
|
}
|
||||||
|
return fu.fm().to_double(tmp);
|
||||||
}
|
}
|
||||||
return fu.fm().to_double(tmp);
|
rational r;
|
||||||
|
arith_util & u = mk_c(c)->autil();
|
||||||
|
if (u.is_numeral(e, r)) {
|
||||||
|
return r.get_double();
|
||||||
|
}
|
||||||
|
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
|
||||||
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Z3_string Z3_API Z3_get_numeral_decimal_string(Z3_context c, Z3_ast a, unsigned precision) {
|
Z3_string Z3_API Z3_get_numeral_decimal_string(Z3_context c, Z3_ast a, unsigned precision) {
|
||||||
|
|
Loading…
Reference in a new issue