Exception from Z3 running minimize example for Data.SBV

139 views Asked by At

When running the example for the optimize function in the Data.SBV library for Haskell:

problem :: Goal
problem = optimize Lexicographic $  do [x1, x2] <- mapM sReal ["x1", "x2"]

         constrain $ x1 + x2 .<= 10
         constrain $ x1 - x2 .>= 3
         constrain $ 5*x1 + 4*x2 .<= 35
         constrain $ x1 .>= 0
         constrain $ x2 .>= 0

         maximize "goal" $ 5 * x1 + 6 * x2
main = optimize Lexicographic problem

I get the following error:

*** Exception: 
*** Data.SBV: Unexpected response from the solver.
***    Context : set-option
***    Sent    : (set-option :pp.decimal false)
***    Expected: success
***    Received: unsupported
***              success

CallStack (from HasCallStack):
  error, called at ./Data/SBV/Control/Utils.hs:590:9 in sbv-7.3-35rX062AGHeFmuyHxSBaTE:Data.SBV.Control.Utils

Similarly the following code:

test = optimize Lexicographic $ do
                  x <- sInteger "x"
                  y <- sInteger "y"
                  maximize "goal" $ x + 2 * y

Produces the error:

*** Exception: 
*** Data.SBV: Unexpected response from the solver.
***    Context : getModel
***    Sent    : (get-value (s0))
***    Expected: a value binding for kind: SInteger
***    Received: unsupported
***              ((s0 0))

CallStack (from HasCallStack):
  error, called at ./Data/SBV/Control/Utils.hs:590:9 in sbv-7.3-35rX062AGHeFmuyHxSBaTE:Data.SBV.Control.Utils

This error also occurs with the minimize combinator as the last expression.

I am using GHC version 8.0.2 with stack version 1.5 and SBV version 7.3 I am using Z3 as my solver and it is version 4.5.1 64-bit running on MacOS.

Calling sat and prove work as expected. Any ideas? Thanks!

1

There are 1 answers

1
alias On BEST ANSWER

You are most likely using an old version of Z3. Optimization features in SBV rely on some not-yet-officially-released features of Z3. Can you download one from here:

https://github.com/Z3Prover/bin/tree/master/nightly

and give it a try?

(There's an open ticket for Z3 to have a new release precisely for this problem, but it isn't clear when they'll get around to it: https://github.com/Z3Prover/z3/issues/1231)