I want to solve constraints that contain quantifiers using Z3 C API. I am struggling to use the functions like "Z3_mk_exists()" as I don't find any example either online or in the test examples in the tar file. I don't exactly understand all the arguments required by these functions and exact significance of them. Can anyone help?
Thanks. Kaustubh.
Here is a complete example with universal quantifiers. Comments are inline:
We create an uninterpreted function for fibonacci:
fib(n)
. We'll specify its meaning with a universal quantifier.We're starting to specify the meaning of
fib(n)
. The base cases don't require quantifiers. We havefib(0) = 0
andfib(1) = 1
.This is a bound variable. They're used within quantified expressions. Indices should start from
0
. We have only one in this case.This represents
fib(_)
, where_
is the bound variable.The pattern is what will trigger the instantiation. We use
fib(_)
again. This means (more or less) that Z3 will instantiate the axiom whenever it seesfib("some term")
.This symbol is only used for debugging as far as I understand. It gives a name to the
_
.This is now the body of the axiom. It says:
_ > 1 => (fib(_) = fib(_ - 1) + fib(_ - 2)
, where _ is the bound variable.At last we can build a quantifier tree, using the pattern, the bound variable, its name and the axiom body. (
Z3_TRUE
says its a forall quantifier). The0
in the argument list specifies the priority. The Z3 doc recommends to use0
if you don't know what to put.We finally add the axiom(s) the to context.