3

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?

Min Gao
  • 383
  • 4
  • 16

1 Answers1

3

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?

Community
  • 1
  • 1
Taylor T. Johnson
  • 2,834
  • 16
  • 17
  • That works for me for writing input files. In my code I'm using `Z3::expr`[link](http://research.microsoft.com/en-us/um/redmond/projects/z3/classz3_1_1expr.html) to assemble expressions. It does have operator `/` but this operator seems to be transformed into `div` while solving. Maybe I should find a way to let `/` show up. Any suggestions on that? – Min Gao Jul 22 '14 at 20:10
  • `z3::expr` operator `/` in **z3++.h** is implemented by Z3 C API function `Z3_mk_div` which has a description _Create an AST node representing arg1 **div** arg2._ – Min Gao Jul 22 '14 at 20:32