0
from z3 import *
x = Int('x') #declaration
y = Int('y') #declaration
solve((x ^ y)==2) #solving

i was unable to perform xor operation in z3 using python.please help tell what is the correct way of writing if i am doing it wrong else suggest some other way of doing it.please reply as soon as possible.

Kijewski
  • 25,517
  • 12
  • 101
  • 143
user2534232
  • 15
  • 2
  • 4
  • Had to look it up: http://z3.codeplex.com/ – YXD Jun 29 '13 at 13:13
  • I don't know z3, but I can tell you that there are infinite many pairs of x, y such that x^2 == 2. Won't that pose a problem? – Kijewski Jun 29 '13 at 13:33
  • 1
    @Kay: I don't know z3 either, but apparently not. It would happily solve it, saying that x=0 and y=2 was the solution. Which of course is correct. In z3 there would be just 2^n solutions though, where n is the declared length of the BitVec. But, but that's details. ;-) – Lennart Regebro Jun 29 '13 at 14:14

1 Answers1

3

You can use ^ on integers in Python:

>>> 2^3
1

However, z3 does not use integers, but their own Int objects, and they don't support xor. You have to use the BitVec type.

x = BitVec('x', 32)
y = BitVec('y', 32)

solve(x^y==2, show=True)
Lennart Regebro
  • 167,292
  • 41
  • 224
  • 251