I am struggling with the attempt to generate a correct assertion in SMTlib. The QV_BV (Bitvectors) theory is used. I use Python to generate the temp.smt2
file and then run it using z3
. The goal is to assert that among an arbitrary number of vectors:
- Pairwise conjunction must be
#b0000000...00
, i.e all zeroes - Total disjunction must be
#b1111111...11
, i.e all ones
Roughly speaking, each vector represents the timetable of an employee, and the requirements are that all timetable slots must be taken by only one employee at a time, but all slots must be taken.
Examples are as follows:
(1) | (2) | (3)
| |
1010 | 1000 | 1000
1001 | 0100 | 0110
0100 | 0010 | 0001
---- | ---- | ---- <--- "disjunction"
1111 | 1110 | 1111
| |
fail | fail | sat!
Example 1 is UNSAT, because, despite the fact that all slots are occupied, there is a collision between the first two bit-vectors
Example 2 is UNSAT because not all the slots are taken. The LSB of a result is 0.
Example 3 is SAT because all slots are taken and no collisions.
I attempted the following approach (N and M are arbitrary numbers):
(set-logic QF_BV)
(declare-const x0 (_ BitVec M))
(declare-const x1 (_ BitVec M))
...
(declare-const xN (_ BitVec M))
(assert (= #b00000...00 (bvand x0 x1 ... xN)))
(assert (= #b11111...11 (bvor x0 x1 ... xN)))
(check-sat)
(get-model)
Only later did I notice that this is insufficient. The disjunction (OR-ing) of overlapping ones is allowed. Then I considered other bitwise operations I got lost quickly. For example, XOR-ing more than one term can be unpredictable, since:
xor(1, 0, 1, 0, 1) == xor(1, xor(0, xor(1, xor(0, 1)))) == 0
xor(1, 0, 1, 1) == xor(1, xor(0, xor(1, 1))) == 1
I can use Python to generate each pairwise assertion in the smt2 file. But since I have arbitrary many bit-vectors, it may lead to high complexity. For example, given 100 bit-vectors, there are 4950 pairs, therefore 4950 assertions. I hope we can do better than that.
So what is a possible solution? Thank you!
Edit: Note that I am not using z3py. I am writing to .smt2 file