Reputation: 47
stackoverflow-ers(?),
I'm playing with z3, and I'm trying to solve the following restrictions:
(declare-const A (_ BitVec 32))
(declare-const B (_ BitVec 32))
(declare-const C (_ BitVec 32))
(declare-const D (_ BitVec 32))
(declare-const E (_ BitVec 32))
(declare-const F (_ BitVec 32))
(assert (<= A #xFFFFFFFF))
(assert (<= B #xFFFFFFFF))
(assert (<= C #xFFFFFFFF))
(assert (> A #x00000000))
;(Commented) Restriction #1 (assert (> B #x00000000))
(assert (> C #x00000000))
(assert (= D (bvand (bvmul (bvmul A B) #x00000008) #xFFFFFFFF) ))
(assert (<= D #xFFFFFFFF))
(assert (= E (bvand (bvmul (bvmul A C) #x00000008) #xFFFFFFFF)))
(assert (<= D E))
(assert (= F (bvand (bvmul A #x00000008) #xFFFFFFFF)))
;(Uncommented) Restriction #2
(assert (> (bvand (bvmul F B) #xFFFFFFFF) D))
(assert (< (bvand (bvmul A B) #xFFFFFFFF) #x7FFFFFFF))
(assert (< (bvand (bvmul A C) #xFFFFFFFF) #x7FFFFFFF))
(assert (< D #x01000000))
(check-sat)
(get-value(A))
(get-value(B))
(get-value(C))
(get-value(D))
(get-value(F))
I've got some troubles with these constraints: a) The first problem is that z3 is ignoring "Restriction #2"
(assert (> (bvand (bvmul F B) #xFFFFFFFF) D))
,the values I get are the followings:
A: #x000070e0
B: #x0000000a
C: #x00000014
D: #x00234600
F: #x00038700
and F*B = D in spite of the restriction.
b) if I uncomment "Restriction #1"
(assert (> B #x00000000))
I'm getting the following result:
A: #x0000a000
B: #x00000007
C: #x00000000
is it a chair - keyboard interface bug? what am I doing wrong?
Thanks in advance!
Upvotes: 2
Views: 489
Reputation: 30418
For comparing bit-vectors, you should always use the corresponding signed/unsigned variants: bvult
, bvugt
, bvule
, bvuge
for unsigned, and bvslt
, bvsgt
, bvsle
, bvsge
for signed. The use of <
, >
etc. is not valid. So, your "restrictions" are actually currently being simply ignored. If I run your benchmark on the command line, I get the following output:
(error "line 8 column 24: Sort mismatch at argument #1 for function (declare-fun <= (Int Int) Bool) supplied sort is (_ BitVec 32)")
(error "line 9 column 24: Sort mismatch at argument #1 for function (declare-fun <= (Int Int) Bool) supplied sort is (_ BitVec 32)")
(error "line 10 column 24: Sort mismatch at argument #1 for function (declare-fun <= (Int Int) Bool) supplied sort is (_ BitVec 32)")
(error "line 13 column 23: Sort mismatch at argument #1 for function (declare-fun > (Int Int) Bool) supplied sort is (_ BitVec 32)")
(error "line 16 column 24: Sort mismatch at argument #1 for function (declare-fun > (Int Int) Bool) supplied sort is (_ BitVec 32)")
(error "line 19 column 24: Sort mismatch at argument #1 for function (declare-fun <= (Int Int) Bool) supplied sort is (_ BitVec 32)")
(error "line 22 column 15: Sort mismatch at argument #1 for function (declare-fun <= (Int Int) Bool) supplied sort is (_ BitVec 32)")
(error "line 27 column 44: Sort mismatch at argument #1 for function (declare-fun > (Int Int) Bool) supplied sort is (_ BitVec 32)")
(error "line 29 column 52: Sort mismatch at argument #1 for function (declare-fun < (Int Int) Bool) supplied sort is (_ BitVec 32)")
(error "line 30 column 52: Sort mismatch at argument #1 for function (declare-fun < (Int Int) Bool) supplied sort is (_ BitVec 32)")
(error "line 33 column 23: Sort mismatch at argument #1 for function (declare-fun < (Int Int) Bool) supplied sort is (_ BitVec 32)")
sat
((A #x00000000))
((B #x00000000))
((C #x00000000))
((D #x00000000))
((F #x00000000))
I'm not sure why the "online" solver isn't similarly complaining.
Upvotes: 3