3

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!

Malte Schwerhoff
  • 12,684
  • 4
  • 41
  • 71
user311703
  • 1,113
  • 2
  • 14
  • 25
  • Perhaps the following version solves what you want: http://rise4fun.com/Z3Py/75E9 – Nikolaj Bjorner Jun 13 '13 at 14:34
  • Nikolaj, this does not really do what I want, since I want to find the "Assumption" in your solution as well. In my code, you can see that I print out the model to find out the value of "a" that can make "f" and "g" equivalent. Thanks – user311703 Jun 13 '13 at 14:54

1 Answers1

0

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.

Nikolaj Bjorner
  • 8,229
  • 14
  • 15