sambayless / monosat

MonoSAT - An SMT solver for Monotonic Theories
MIT License
106 stars 29 forks source link

Misbehavior of bitvector methods in python bindings #27

Closed xieyangxu closed 4 years ago

xieyangxu commented 4 years ago

methods such as LessEq and GreaterEq are not working properly for bitvectors, e.g., LessEq(bv1, bv2) leads to a different result with (bv1 <= bv2), the latter is working as expected.

sambayless commented 4 years ago

Good catch! I've reproduced this locally, thank you for noticing this!

Logic.LessEq/GreaterEq/LessThan/GreaterThan apply to comparisons between lists of literals, not bitvectors (those methods actually predate bitvector support in monosat). Now that MonoSAT also has bitvectors, that behaviour is very unintuitive.

On the subject of bitvectors in monosat: One thing to keep in mind is that in monosat (unlike other SMT solvers), Bitvectors are constrained not to overflow/underflow (this is required to ensure they have monotonic semantics). As a result, the formula will be UNSAT in monosat (but SAT in other SMT solvers)

bv1 = BitVector(4)
assert(Solve())
# 15 is the largest value representable in a 4 bit unsigned bitvector
Assert(bv1==15)
# In MonoSAT, bitvectors cannot overflow
bv2 = bv1 + 1
# so bv2 = 15 + 1 will be UNSAT (whereas in other SMT solvers this might be SAT)
assert(not Solve())

Also, all bitvectors in MonoSAT are unsigned.

sambayless commented 4 years ago

Resolved by https://github.com/sambayless/monosat/commit/e8b232b6ef3f61fc6778bfb3fa364471096e57ff