Z3_substitute
APIを使用できます。次に例を示します。
void substitute_example() {
std::cout << "substitute example\n";
context c;
expr x(c);
x = c.int_const("x");
expr f(c);
f = (x == 2) || (x == 1);
std::cout << f << std::endl;
expr two(c), three(c);
two = c.int_val(2);
three = c.int_val(3);
Z3_ast from[] = { two };
Z3_ast to[] = { three };
expr new_f(c);
// Replaces the expressions in from with to in f.
// The third argument is the size of the arrays from and to.
new_f = to_expr(c, Z3_substitute(c, f, 1, from, to));
std::cout << new_f << std::endl;
}
更新数式で置換x == 2
したい場合は、書く必要があります。x == 3
void substitute_example() {
std::cout << "substitute example\n";
context c;
expr x(c), y(c);
x = c.int_const("x");
y = c.int_const("y");
expr f(c);
f = (x == 2) || (y == 2);
std::cout << f << std::endl;
expr from(c), to(c);
from = x == 2;
to = x == 3;
Z3_ast _from[] = { from };
Z3_ast _to[] = { to };
expr new_f(c);
// Replaces the expressions in from with to in f.
// The third argument is the size of the arrays from and to.
new_f = to_expr(c, Z3_substitute(c, f, 1, _from, _to));
std::cout << new_f << std::endl;
}