Two formulas a1 == a + b
and a1 == b
are equivalent if a == 0
. I want to find this required condition (a == 0
) with Z3 python. I wrote the code below:
from z3 import *
def equivalence(F, G):
s = Solver()
s.add(Not(F == G))
r = s.check()
if r == unsat:
print 'Equ'
print s.model()
else:
print 'Not Equ'
a, b = BitVecs('a b', 32)
g = True
tmp = BitVec('tmp', 32)
g = And(g, tmp == a)
tmp1 = BitVec('tmp1', 32)
g = And(g, tmp1 == b)
tmp2 = BitVec('tmp2', 32)
g = And(g, tmp2 == (tmp1 + tmp))
a1 = BitVec('a1', 32)
g = And(g, a1 == tmp2)
f = True
f = And(f, a1 == b)
equivalence(Exists([a], g), f)
However, the above code always returns "Not Equ"
as the output. Then obviously I cannot get the model (a === 0
) as the condition for "f"
and "g"
to be equivalent, either.
Any idea on where the code is wrong, and how to fix it? Thanks so much!
The code in the post does not correspond to the question that is asked. A similar question was asked and answered on the smt-lib mailing list.