سؤال

I have this code in Z3 python:

x = Bool('x')
y = Bool('y')
z = Bool('z')
z == (x xor y)
s = Solver()
s.add(z == True)
print s.check()

But this code reports below error when running:

c.py(4): error: invalid syntax

If I replace xor with and, there is no problem. So this means XOR is not supported?

هل كانت مفيدة؟

المحلول

You should use Xor(a, b). Moreover, to create the Z3 expression that represents the formula a and b, we must use And(a, b). In Python, we can't overload the operators and and or. Here is an example with the Xor (available online at rise4fun).

x = Bool('x')
y = Bool('y')
z = Xor(x, y)
s = Solver()
s.add(z)
print s.check()
print s.model()
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top