module Language.Hasmtlib.Type.MonadSMT where
import Language.Hasmtlib.Internal.Expr
import Language.Hasmtlib.Type.Option
import Language.Hasmtlib.Type.SMTSort
import Language.Hasmtlib.Type.Solution
import Language.Hasmtlib.Codec
import Data.Proxy
import Control.Monad
import Control.Monad.State
class MonadState s m => MonadSMT s m where
smtvar' :: forall t. KnownSMTSort t => Proxy t -> m (SMTVar t)
var' :: forall t. KnownSMTSort t => Proxy t -> m (Expr t)
assert :: Expr BoolSort -> m ()
setOption :: SMTOption -> m ()
setLogic :: String -> m ()
var :: forall t s m. (KnownSMTSort t, MonadSMT s m) => m (Expr t)
var :: forall (t :: SMTSort) s (m :: * -> *).
(KnownSMTSort t, MonadSMT s m) =>
m (Expr t)
var = Proxy t -> m (Expr t)
forall s (m :: * -> *) (t :: SMTSort).
(MonadSMT s m, KnownSMTSort t) =>
Proxy t -> m (Expr t)
forall (t :: SMTSort). KnownSMTSort t => Proxy t -> m (Expr t)
var' (forall {k} (t :: k). Proxy t
forall (t :: SMTSort). Proxy t
Proxy @t)
{-# INLINE var #-}
smtvar :: forall t s m. (KnownSMTSort t, MonadSMT s m) => m (SMTVar t)
smtvar :: forall (t :: SMTSort) s (m :: * -> *).
(KnownSMTSort t, MonadSMT s m) =>
m (SMTVar t)
smtvar = Proxy t -> m (SMTVar t)
forall s (m :: * -> *) (t :: SMTSort).
(MonadSMT s m, KnownSMTSort t) =>
Proxy t -> m (SMTVar t)
forall (t :: SMTSort). KnownSMTSort t => Proxy t -> m (SMTVar t)
smtvar' (forall {k} (t :: k). Proxy t
forall (t :: SMTSort). Proxy t
Proxy @t)
{-# INLINE smtvar #-}
constant :: KnownSMTSort t => HaskellType t -> Expr t
constant :: forall (t :: SMTSort). KnownSMTSort t => HaskellType t -> Expr t
constant = Value t -> Expr t
forall (t :: SMTSort). Value t -> Expr t
Constant (Value t -> Expr t)
-> (HaskellType t -> Value t) -> HaskellType t -> Expr t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HaskellType t -> Value t
forall (t :: SMTSort). KnownSMTSort t => HaskellType t -> Value t
wrapValue
{-# INLINE constant #-}
assertMaybe :: MonadSMT s m => Maybe (Expr BoolSort) -> m ()
assertMaybe :: forall s (m :: * -> *).
MonadSMT s m =>
Maybe (Expr 'BoolSort) -> m ()
assertMaybe Maybe (Expr 'BoolSort)
Nothing = () -> m ()
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
assertMaybe (Just Expr 'BoolSort
expr) = Expr 'BoolSort -> m ()
forall s (m :: * -> *). MonadSMT s m => Expr 'BoolSort -> m ()
assert Expr 'BoolSort
expr
quantify :: MonadSMT s m => Expr t -> m (Expr t)
quantify :: forall s (m :: * -> *) (t :: SMTSort).
MonadSMT s m =>
Expr t -> m (Expr t)
quantify (Not Expr t
x) = (Expr t -> Expr t) -> m (Expr t) -> m (Expr t)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Expr t -> Expr t
forall (t :: SMTSort). Boolean (HaskellType t) => Expr t -> Expr t
Not (Expr t -> m (Expr t)
forall s (m :: * -> *) (t :: SMTSort).
MonadSMT s m =>
Expr t -> m (Expr t)
quantify Expr t
x)
quantify (And Expr t
x Expr t
y) = (Expr t -> Expr t -> Expr t)
-> m (Expr t) -> m (Expr t) -> m (Expr t)
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 Expr t -> Expr t -> Expr t
forall (t :: SMTSort).
Boolean (HaskellType t) =>
Expr t -> Expr t -> Expr t
And (Expr t -> m (Expr t)
forall s (m :: * -> *) (t :: SMTSort).
MonadSMT s m =>
Expr t -> m (Expr t)
quantify Expr t
x) (Expr t -> m (Expr t)
forall s (m :: * -> *) (t :: SMTSort).
MonadSMT s m =>
Expr t -> m (Expr t)
quantify Expr t
y)
quantify (Or Expr t
x Expr t
y) = (Expr t -> Expr t -> Expr t)
-> m (Expr t) -> m (Expr t) -> m (Expr t)
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 Expr t -> Expr t -> Expr t
forall (t :: SMTSort).
Boolean (HaskellType t) =>
Expr t -> Expr t -> Expr t
Or (Expr t -> m (Expr t)
forall s (m :: * -> *) (t :: SMTSort).
MonadSMT s m =>
Expr t -> m (Expr t)
quantify Expr t
x) (Expr t -> m (Expr t)
forall s (m :: * -> *) (t :: SMTSort).
MonadSMT s m =>
Expr t -> m (Expr t)
quantify Expr t
y)
quantify (Impl Expr t
x Expr t
y) = (Expr t -> Expr t -> Expr t)
-> m (Expr t) -> m (Expr t) -> m (Expr t)
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 Expr t -> Expr t -> Expr t
forall (t :: SMTSort).
Boolean (HaskellType t) =>
Expr t -> Expr t -> Expr t
Impl (Expr t -> m (Expr t)
forall s (m :: * -> *) (t :: SMTSort).
MonadSMT s m =>
Expr t -> m (Expr t)
quantify Expr t
x) (Expr t -> m (Expr t)
forall s (m :: * -> *) (t :: SMTSort).
MonadSMT s m =>
Expr t -> m (Expr t)
quantify Expr t
y)
quantify (Xor Expr t
x Expr t
y) = (Expr t -> Expr t -> Expr t)
-> m (Expr t) -> m (Expr t) -> m (Expr t)
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 Expr t -> Expr t -> Expr t
forall (t :: SMTSort).
Boolean (HaskellType t) =>
Expr t -> Expr t -> Expr t
Xor (Expr t -> m (Expr t)
forall s (m :: * -> *) (t :: SMTSort).
MonadSMT s m =>
Expr t -> m (Expr t)
quantify Expr t
x) (Expr t -> m (Expr t)
forall s (m :: * -> *) (t :: SMTSort).
MonadSMT s m =>
Expr t -> m (Expr t)
quantify Expr t
y)
quantify (Ite Expr 'BoolSort
p Expr t
t Expr t
f) = (Expr 'BoolSort -> Expr t -> Expr t -> Expr t)
-> m (Expr 'BoolSort) -> m (Expr t) -> m (Expr t) -> m (Expr t)
forall (m :: * -> *) a1 a2 a3 r.
Monad m =>
(a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r
liftM3 Expr 'BoolSort -> Expr t -> Expr t -> Expr t
forall (t :: SMTSort). Expr 'BoolSort -> Expr t -> Expr t -> Expr t
Ite (Expr 'BoolSort -> m (Expr 'BoolSort)
forall s (m :: * -> *) (t :: SMTSort).
MonadSMT s m =>
Expr t -> m (Expr t)
quantify Expr 'BoolSort
p) (Expr t -> m (Expr t)
forall s (m :: * -> *) (t :: SMTSort).
MonadSMT s m =>
Expr t -> m (Expr t)
quantify Expr t
t) (Expr t -> m (Expr t)
forall s (m :: * -> *) (t :: SMTSort).
MonadSMT s m =>
Expr t -> m (Expr t)
quantify Expr t
f)
quantify (ForAll Maybe (SMTVar t1)
_ Expr t1 -> Expr 'BoolSort
f) = do
SMTVar t1
qVar <- m (SMTVar t1)
forall (t :: SMTSort) s (m :: * -> *).
(KnownSMTSort t, MonadSMT s m) =>
m (SMTVar t)
smtvar
Expr 'BoolSort
qBody <- Expr 'BoolSort -> m (Expr 'BoolSort)
forall s (m :: * -> *) (t :: SMTSort).
MonadSMT s m =>
Expr t -> m (Expr t)
quantify (Expr 'BoolSort -> m (Expr 'BoolSort))
-> Expr 'BoolSort -> m (Expr 'BoolSort)
forall a b. (a -> b) -> a -> b
$ Expr t1 -> Expr 'BoolSort
f (Expr t1 -> Expr 'BoolSort) -> Expr t1 -> Expr 'BoolSort
forall a b. (a -> b) -> a -> b
$ SMTVar t1 -> Expr t1
forall (t :: SMTSort). SMTVar t -> Expr t
Var SMTVar t1
qVar
Expr 'BoolSort -> m (Expr 'BoolSort)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Expr 'BoolSort -> m (Expr 'BoolSort))
-> Expr 'BoolSort -> m (Expr 'BoolSort)
forall a b. (a -> b) -> a -> b
$ Maybe (SMTVar t1) -> (Expr t1 -> Expr 'BoolSort) -> Expr 'BoolSort
forall (t1 :: SMTSort).
KnownSMTSort t1 =>
Maybe (SMTVar t1) -> (Expr t1 -> Expr 'BoolSort) -> Expr 'BoolSort
ForAll (SMTVar t1 -> Maybe (SMTVar t1)
forall a. a -> Maybe a
Just SMTVar t1
qVar) (Expr 'BoolSort -> Expr t1 -> Expr 'BoolSort
forall a b. a -> b -> a
const Expr 'BoolSort
qBody)
quantify (Exists Maybe (SMTVar t1)
_ Expr t1 -> Expr 'BoolSort
f) = do
SMTVar t1
qVar <- m (SMTVar t1)
forall (t :: SMTSort) s (m :: * -> *).
(KnownSMTSort t, MonadSMT s m) =>
m (SMTVar t)
smtvar
Expr 'BoolSort
qBody <- Expr 'BoolSort -> m (Expr 'BoolSort)
forall s (m :: * -> *) (t :: SMTSort).
MonadSMT s m =>
Expr t -> m (Expr t)
quantify (Expr 'BoolSort -> m (Expr 'BoolSort))
-> Expr 'BoolSort -> m (Expr 'BoolSort)
forall a b. (a -> b) -> a -> b
$ Expr t1 -> Expr 'BoolSort
f (Expr t1 -> Expr 'BoolSort) -> Expr t1 -> Expr 'BoolSort
forall a b. (a -> b) -> a -> b
$ SMTVar t1 -> Expr t1
forall (t :: SMTSort). SMTVar t -> Expr t
Var SMTVar t1
qVar
Expr 'BoolSort -> m (Expr 'BoolSort)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Expr 'BoolSort -> m (Expr 'BoolSort))
-> Expr 'BoolSort -> m (Expr 'BoolSort)
forall a b. (a -> b) -> a -> b
$ Maybe (SMTVar t1) -> (Expr t1 -> Expr 'BoolSort) -> Expr 'BoolSort
forall (t1 :: SMTSort).
KnownSMTSort t1 =>
Maybe (SMTVar t1) -> (Expr t1 -> Expr 'BoolSort) -> Expr 'BoolSort
Exists (SMTVar t1 -> Maybe (SMTVar t1)
forall a. a -> Maybe a
Just SMTVar t1
qVar) (Expr 'BoolSort -> Expr t1 -> Expr 'BoolSort
forall a b. a -> b -> a
const Expr 'BoolSort
qBody)
quantify Expr t
expr = Expr t -> m (Expr t)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Expr t
expr
class MonadSMT s m => MonadIncrSMT s m where
push :: m ()
pop :: m ()
checkSat :: m Result
getModel :: m Solution
getValue :: KnownSMTSort t => Expr t -> m (Maybe (Decoded (Expr t)))
solve :: (MonadIncrSMT s m, MonadIO m) => m (Result, Solution)
solve :: forall s (m :: * -> *).
(MonadIncrSMT s m, MonadIO m) =>
m (Result, Solution)
solve = (Result -> Solution -> (Result, Solution))
-> m Result -> m Solution -> m (Result, Solution)
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 (,) m Result
forall s (m :: * -> *). MonadIncrSMT s m => m Result
checkSat m Solution
forall s (m :: * -> *). MonadIncrSMT s m => m Solution
getModel
class MonadSMT s m => MonadOMT s m where
minimize :: (KnownSMTSort t, Num (Expr t)) => Expr t -> m ()
maximize :: (KnownSMTSort t, Num (Expr t)) => Expr t -> m ()
assertSoft :: Expr BoolSort -> Maybe Double -> Maybe String -> m ()
assertSoftWeighted :: MonadOMT s m => Expr BoolSort -> Double -> m ()
assertSoftWeighted :: forall s (m :: * -> *).
MonadOMT s m =>
Expr 'BoolSort -> Double -> m ()
assertSoftWeighted Expr 'BoolSort
expr Double
w = Expr 'BoolSort -> Maybe Double -> Maybe String -> m ()
forall s (m :: * -> *).
MonadOMT s m =>
Expr 'BoolSort -> Maybe Double -> Maybe String -> m ()
assertSoft Expr 'BoolSort
expr (Double -> Maybe Double
forall a. a -> Maybe a
Just Double
w) Maybe String
forall a. Maybe a
Nothing