{-# OPTIONS_GHC -Wall -Werror #-}
module Documentation.SBV.Examples.Queries.Interpolants where
import Data.SBV
import Data.SBV.Control
exampleMathSAT :: Symbolic String
exampleMathSAT :: Symbolic String
exampleMathSAT = do
SInteger
x <- String -> Symbolic SInteger
sInteger String
"x"
SInteger
y <- String -> Symbolic SInteger
sInteger String
"y"
SInteger
z <- String -> Symbolic SInteger
sInteger String
"z"
SMTOption -> SymbolicT IO ()
forall (m :: * -> *). SolverContext m => SMTOption -> m ()
setOption (SMTOption -> SymbolicT IO ()) -> SMTOption -> SymbolicT IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> SMTOption
ProduceInterpolants Bool
True
[(String, String)] -> SBool -> SymbolicT IO ()
forall (m :: * -> *).
SolverContext m =>
[(String, String)] -> SBool -> m ()
constrainWithAttribute [(String
":interpolation-group", String
"A")] (SBool -> SymbolicT IO ()) -> SBool -> SymbolicT IO ()
forall a b. (a -> b) -> a -> b
$ SInteger
x SInteger -> SInteger -> SInteger
forall a. Num a => a -> a -> a
- SInteger
3SInteger -> SInteger -> SInteger
forall a. Num a => a -> a -> a
*SInteger
y SInteger -> SInteger -> SBool
forall a. OrdSymbolic a => a -> a -> SBool
.>= -SInteger
1
[(String, String)] -> SBool -> SymbolicT IO ()
forall (m :: * -> *).
SolverContext m =>
[(String, String)] -> SBool -> m ()
constrainWithAttribute [(String
":interpolation-group", String
"A")] (SBool -> SymbolicT IO ()) -> SBool -> SymbolicT IO ()
forall a b. (a -> b) -> a -> b
$ SInteger
x SInteger -> SInteger -> SInteger
forall a. Num a => a -> a -> a
+ SInteger
y SInteger -> SInteger -> SBool
forall a. OrdSymbolic a => a -> a -> SBool
.>= SInteger
0
[(String, String)] -> SBool -> SymbolicT IO ()
forall (m :: * -> *).
SolverContext m =>
[(String, String)] -> SBool -> m ()
constrainWithAttribute [(String
":interpolation-group", String
"B")] (SBool -> SymbolicT IO ()) -> SBool -> SymbolicT IO ()
forall a b. (a -> b) -> a -> b
$ SInteger
z SInteger -> SInteger -> SInteger
forall a. Num a => a -> a -> a
- SInteger
2SInteger -> SInteger -> SInteger
forall a. Num a => a -> a -> a
*SInteger
x SInteger -> SInteger -> SBool
forall a. OrdSymbolic a => a -> a -> SBool
.>= SInteger
3
[(String, String)] -> SBool -> SymbolicT IO ()
forall (m :: * -> *).
SolverContext m =>
[(String, String)] -> SBool -> m ()
constrainWithAttribute [(String
":interpolation-group", String
"B")] (SBool -> SymbolicT IO ()) -> SBool -> SymbolicT IO ()
forall a b. (a -> b) -> a -> b
$ SInteger
2SInteger -> SInteger -> SInteger
forall a. Num a => a -> a -> a
*SInteger
z SInteger -> SInteger -> SBool
forall a. OrdSymbolic a => a -> a -> SBool
.<= SInteger
1
Query String -> Symbolic String
forall a. Query a -> Symbolic a
query (Query String -> Symbolic String)
-> Query String -> Symbolic String
forall a b. (a -> b) -> a -> b
$ do CheckSatResult
cs <- Query CheckSatResult
checkSat
case CheckSatResult
cs of
CheckSatResult
Unsat -> [String] -> Query String
getInterpolantMathSAT [String
"A"]
DSat{} -> String -> Query String
forall a. HasCallStack => String -> a
error String
"Unexpected delta-sat result!"
CheckSatResult
Sat -> String -> Query String
forall a. HasCallStack => String -> a
error String
"Unexpected sat result!"
CheckSatResult
Unk -> String -> Query String
forall a. HasCallStack => String -> a
error String
"Unexpected unknown result!"
evenOdd :: Symbolic String
evenOdd :: Symbolic String
evenOdd = do
SInteger
x <- String -> Symbolic SInteger
sInteger String
"x"
SInteger
y <- String -> Symbolic SInteger
sInteger String
"y"
SInteger
z <- String -> Symbolic SInteger
sInteger String
"z"
Query String -> Symbolic String
forall a. Query a -> Symbolic a
query (Query String -> Symbolic String)
-> Query String -> Symbolic String
forall a b. (a -> b) -> a -> b
$ [SBool] -> Query String
getInterpolantZ3 [SInteger
y SInteger -> SInteger -> SBool
forall a. EqSymbolic a => a -> a -> SBool
.== SInteger
2SInteger -> SInteger -> SInteger
forall a. Num a => a -> a -> a
*SInteger
x, SInteger
y SInteger -> SInteger -> SBool
forall a. EqSymbolic a => a -> a -> SBool
.== SInteger
2SInteger -> SInteger -> SInteger
forall a. Num a => a -> a -> a
*SInteger
zSInteger -> SInteger -> SInteger
forall a. Num a => a -> a -> a
+SInteger
1]