Reputation: 403
I'm writing some codes by calling Z3 to calculate division but I found the model result is not correct. Basically what I want to do is to the get value of a
and b
satisfying a/b == 1
. So I manually wrote an input file like following to check whether it's my code's problem or Z3's.
(declare-const a Int)
(declare-const b Int)
(assert (= (div a b) 1))
(assert (not (= b 0)))
(check-sat)
(get-model)
Result from this in my machine is a =77 b = 39
instead of some equalized value of a and b. Is this a bug or did I do something wrong?
Upvotes: 3
Views: 1283
Reputation: 2884
Using /
instead of div
will yield the desired behavior (rise4fun link: http://rise4fun.com/Z3/itdK ):
(declare-const a Int)
(declare-const b Int)
(assert (not (= b 0)))
(push)
(assert (= (div a b) 1)) ; gives a=2473,b=1237
(check-sat)
(get-model)
(pop)
(push)
(assert (= (/ a b) 1))
(check-sat)
(get-model) ; gives a=-1,b=-1
(pop)
However, there may be some confusion here, I didn't see /
defined in the integer theory ( http://smtlib.cs.uiowa.edu/theories/Ints.smt2 ) only div
(but it would appear to be assumed in the QF_NIA
logic http://smtlib.cs.uiowa.edu/logics/QF_NIA.smt2 since /
is mentioned to be excluded from QF_LIA
http://smtlib.cs.uiowa.edu/logics/QF_LIA.smt2 ), so I was a little confused, or maybe it's related to the recent real/int typing issues brought up here: Why does 0 = 0.5?
Upvotes: 3