hasmtlib-1.3.0: A monad for interfacing with external SMT solvers
Safe HaskellSafe-Inferred
LanguageGHC2021

Language.Hasmtlib.Type.MonadSMT

Synopsis

Documentation

class MonadState s m => MonadSMT s m where Source #

A MonadState that holds an SMT-Problem.

Methods

smtvar' :: forall t. KnownSMTSort t => Proxy t -> m (SMTVar t) Source #

Construct a variable. This is mainly intended for internal use. In the API use var' instead.

x :: SMTVar RealType <- smtvar' (Proxy @RealType)

var' :: forall t. KnownSMTSort t => Proxy t -> m (Expr t) Source #

Construct a variable as expression.

x :: Expr RealType <- var' (Proxy @RealType)

assert :: Expr BoolSort -> m () Source #

Assert a boolean expression.

x :: Expr IntType <- var @IntType
assert $ x + 5 === 42

setOption :: SMTOption -> m () Source #

Set an SMT-Solver-Option.

setOption $ Incremental True

setLogic :: String -> m () Source #

Set the logic for the SMT-Solver to use.

setLogic "QF_LRA"

Instances

Instances details
(MonadState Pipe m, MonadIO m) => MonadSMT Pipe m Source # 
Instance details

Defined in Language.Hasmtlib.Type.Pipe

Methods

smtvar' :: forall (t :: SMTSort). KnownSMTSort t => Proxy t -> m (SMTVar t) Source #

var' :: forall (t :: SMTSort). KnownSMTSort t => Proxy t -> m (Expr t) Source #

assert :: Expr 'BoolSort -> m () Source #

setOption :: SMTOption -> m () Source #

setLogic :: String -> m () Source #

MonadState SMT m => MonadSMT SMT m Source # 
Instance details

Defined in Language.Hasmtlib.Type.SMT

Methods

smtvar' :: forall (t :: SMTSort). KnownSMTSort t => Proxy t -> m (SMTVar t) Source #

var' :: forall (t :: SMTSort). KnownSMTSort t => Proxy t -> m (Expr t) Source #

assert :: Expr 'BoolSort -> m () Source #

setOption :: SMTOption -> m () Source #

setLogic :: String -> m () Source #

var :: forall t s m. (KnownSMTSort t, MonadSMT s m) => m (Expr t) Source #

Wrapper for var' which hides the Proxy.

smtvar :: forall t s m. (KnownSMTSort t, MonadSMT s m) => m (SMTVar t) Source #

Wrapper for smtvar' which hides the Proxy. This is mainly intended for internal use. In the API use var instead.

constant :: KnownSMTSort t => HaskellType t -> Expr t Source #

Create a constant.

>>> constant True
    Constant (BoolValue True)
>>> let x :: Integer = 10 ; constant x
    Constant (IntValue 10)
>>> constant @IntType 5
    Constant (IntValue 5)
>>> constant @(BvType 8) 5
    Constant (BvValue 0000101)

quantify :: MonadSMT s m => Expr t -> m (Expr t) Source #

Assign quantified variables to all quantified subexpressions of an expression. This shall only be used internally. Usually before rendering an assert.

class MonadSMT s m => MonadIncrSMT s m | m -> s where Source #

A MonadSMT that allows incremental solving.

Methods

push :: m () Source #

Push a new context (one) to the solvers context-stack.

pop :: m () Source #

Pop the solvers context-stack by one.

checkSat :: m Result Source #

Run check-sat on the current problem.

getModel :: m Solution Source #

Run get-model on the current problem. This can be used to decode temporary models within the SMT-Problem.

x <- var @RealSort
y <- var
assert $ x >? y && y <? (-1)
res <- checkSat
case res of
  Unsat -> print "Unsat. Cannot get model."
  r     -> do
    model <- getModel
    liftIO $ print $ decode model x

getValue :: KnownSMTSort t => Expr t -> m (Maybe (Decoded (Expr t))) Source #

Evaluate any expressions value in the solvers model. Requires a Sat or Unknown check-sat response beforehand.

x <- var @RealSort
assert $ x >? 10
res <- checkSat
case res of
  Unsat -> print "Unsat. Cannot get value for x."
  r     -> do
    x' <- getValue x
    liftIO $ print $ show r ++ ": x = " ++ show x'

Instances

Instances details
(MonadState Pipe m, MonadIO m) => MonadIncrSMT Pipe m Source # 
Instance details

Defined in Language.Hasmtlib.Type.Pipe

Methods

push :: m () Source #

pop :: m () Source #

checkSat :: m Result Source #

getModel :: m Solution Source #

getValue :: forall (t :: SMTSort). KnownSMTSort t => Expr t -> m (Maybe (Decoded (Expr t))) Source #

solve :: (MonadIncrSMT s m, MonadIO m) => m (Result, Solution) Source #

First run checkSat and then getModel on the current problem.