I would like to visit a z3::expr
. The examples directory provides this snippet:
void visit(expr const & e) {
if (e.is_app()) {
unsigned num = e.num_args();
for (unsigned i = 0; i < num; i++) {
visit(e.arg(i));
}
// do something
// Example: print the visited expression
func_decl f = e.decl();
std::cout << "application of " << f.name() << ": " << e << "\n";
}
else if (e.is_quantifier()) {
visit(e.body());
// do something
}
else {
assert(e.is_var());
// do something
}
}
I am ok with the function application part, but I miss some piece when I encounter quantifiers.
When
e.is_quantifier()
is true, how to I get which quantifier (exists or for all) I have?I understand that Z3 internally uses De Bruijn indices, and I am ok with them. But how do I get the index when
e.is_var()
is true?Less important, but Z3 still retains the name of the bound variable, even if knowing the De Bruijn index technically makes it redundant, because if I send the expression to std::cout the variable name appears. How do I get it? Can I assume that they are consistent, i.e., if I blindly subtitute each variable with its name, then variables bind in the correct way? (if I am not mistaken, this amounts to the fact that no variable is quantified again between its usage and its original binding site)