siddhant
siddhant

Reputation: 837

Signed division not working in z3py

I was trying to work with z3py. I came across a strange problem. I read that the operation / is treated as signed division for bit vectors in z3py. I was trying to give the following commands:

a = z3.BitVec('a',2)

b = z3.BitVec('b',2)

solver = z3.Solver()

solver.add((a + b)/2 == 3)

solver.check()

The result z3 gives is unsat

In my views this is not correct because it has a solution a = 2, b = 0, a = 2 in 2's complement means a = -2, so (a+b)/2 must be equal to -1 i.e. 3 by signed representation.

Can anyone please help me what is wrong here?

Upvotes: 3

Views: 480

Answers (1)

siddhant
siddhant

Reputation: 837

I finally found the solution myself!

The problem is in expression (a+b)/2. Here a and b are Bit Vectors of size 2. So the denominator 2 of the expression is also treated as a 2-bit Bit Vector by z3. So the 2 in denominator is actually -2. Thus the constraint I was trying to solve was (a+b)/(-2) == -1 This is actually unsat.

Upvotes: 2

Related Questions