Is there any limitations in functions declaring?
For example, this piece of code returning unsat.
from z3 import *
def one_op (op, arg1, arg2):
if op==1:
return arg1*arg2
if op==2:
return arg1-arg2
if op==3:
return arg1+arg2
return arg1+arg2 # default
s=Solver()
arg1, arg2, result, unk_op=Ints ('arg1 arg2 result unk_op')
s.add (unk_op>=1, unk_op<=3)
s.add (arg1==1)
s.add (arg2==2)
s.add (result==3)
s.add (one_op(unk_op, arg1, arg2)==result)
print s.check()
How Z3Py interpret declared function? Is it just calling it some times or some hidden machinery also here?
In the function call
one_op(unk_op, arg1, arg2),unk_opis a Z3 expression. Then, expressions such asop==1andop==2(in the definition ofone_op) are also Z3 symbolic expressions. Sinceop==1is not the Python Boolean expressionFalse. The functionone_opwill always return the Z3 expressionarg1*arg2. We can check that by executingprint one_op(unk_op, arg1, arg2). Note that theifstatements in the definition ofone_opare Python statements.I believe your true intention is to return a Z3 expression that contains conditional expressions. You can accomplish that by defining
one_opas:Now, the command
Ifbuilds a Z3 conditional expression. By using, this definition, we can find a satisfying solution. Here is the complete example:The result is: