{-# OPTIONS_GHC -Wall -Werror #-}
module Documentation.SBV.Examples.Misc.ModelExtract where
import Data.SBV
outside :: [Integer] -> IO SatResult
outside :: [Integer] -> IO SatResult
outside [Integer]
disallow = forall a. Provable a => a -> IO SatResult
sat forall a b. (a -> b) -> a -> b
$ do SInteger
x <- String -> Symbolic SInteger
sInteger String
"x"
let notEq :: Integer -> m ()
notEq Integer
i = forall (m :: * -> *). SolverContext m => SBool -> m ()
constrain forall a b. (a -> b) -> a -> b
$ SInteger
x forall a. EqSymbolic a => a -> a -> SBool
./= forall a. SymVal a => a -> SBV a
literal Integer
i
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ forall {m :: * -> *}. SolverContext m => Integer -> m ()
notEq [Integer]
disallow
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ SInteger
x forall a. OrdSymbolic a => a -> a -> SBool
.>= SInteger
0
genVals :: IO [Integer]
genVals :: IO [Integer]
genVals = [Integer] -> [Integer] -> IO [Integer]
go [] []
where go :: [Integer] -> [Integer] -> IO [Integer]
go [Integer]
_ [Integer]
model
| forall (t :: * -> *) a. Foldable t => t a -> Int
length [Integer]
model forall a. Ord a => a -> a -> Bool
>= Int
10 = forall (m :: * -> *) a. Monad m => a -> m a
return [Integer]
model
go [Integer]
disallow [Integer]
model
= do SatResult
res <- [Integer] -> IO SatResult
outside [Integer]
disallow
case String
"x" forall a b. (Modelable a, SymVal b) => String -> a -> Maybe b
`getModelValue` SatResult
res of
Just Integer
c -> [Integer] -> [Integer] -> IO [Integer]
go ([Integer
cforall a. Num a => a -> a -> a
-Integer
4 .. Integer
cforall a. Num a => a -> a -> a
+Integer
4] forall a. [a] -> [a] -> [a]
++ [Integer]
disallow) (Integer
c forall a. a -> [a] -> [a]
: [Integer]
model)
Maybe Integer
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return [Integer]
model