Closed daejunpark closed 3 years ago
This is quite unfortunate. If (div -4 3)
is -2
, that means that Z3 division is rounding to negative infinity, whereas /Int
and %Int
round to zero, and divInt
and modInt
are euclidean division (ie the remainder is always positive). it should be possible to change the smtlib attribute to an if-then-else expression that computes the correct value for negative numbers, but this does mean that divInt and modInt also have incorrect smtlib expressions and also need to be corrected. Take a look at powmod for the syntax of using an expression in the smtlib attribute.
Since this is a problem in the K prelude, I can take care of it at some point if you don't want to work on it, but it will have to wait until I get the llvm backend delivered to IOHK, so since it's a simple change, you might want to do it yourself.
Just for a reference: https://github.com/kframework/k/pull/240#issuecomment-453702596
@daejunpark is this still a problem?
Close this for now: https://github.com/kframework/k/pull/240#issuecomment-469931127
Currently,
/Int
and%Int
have the attributesmtlib(div)
andsmtlib(mod)
, respectively: https://github.com/kframework/k/blob/6bc147f6097afd3aa3c6a6c6d472201614ff7ef5/k-distribution/include/builtin/domains.k#L359-L360According to the SMT-LIB integer theory, however, they do not agree on negative numbers. For example,
-4 /Int 3
is -1, while(div -4 3)
is -2.