I'm using SymPy expressions to compute expressions such as a + 3 * b
that then I want to verify with Z3 (for example, a + 3 * b > 0
for all positive a, b
).
I can't find a way to replace a, b
and in general SymPy symbols with Z3 objects.
import sympy
from z3 import *
a = sympy.Symbol('a')
b = sympy.Symbol('b')
t = Real('t')
w = Real('w')
e = a + 3 * b
e = e.subs({a:t, b:w}) # does nothing?
e = e.replace(a, t).replace(b, w) # e = t + 3 * w
And(True, e > 0) # raises z3.z3types.Z3Exception
The exception is thrown also by replacing 3
with RealVal('3')
.
I'm currently operating on strings and finally using exec
to change types and expressions as above, but I'm planning to stop using exec
.