Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Language.Hasmtlib.Type.Solver
Synopsis
- class WithSolver a where
- withSolver :: Solver -> Bool -> a
- solveWith :: (Default s, Monad m, Codec a) => Solver s m -> StateT s m a -> m (Result, Maybe (Decoded a))
- interactiveWith :: (WithSolver s, MonadIO m) => (Solver, Handle) -> StateT s m () -> m ()
- debugInteractiveWith :: (WithSolver s, MonadIO m) => (Solver, Handle) -> StateT s m () -> m ()
- solveMinimized :: (MonadIncrSMT Pipe m, MonadIO m, KnownSMTSort t, Orderable (Expr t)) => Expr t -> m (Result, Solution)
- solveMinimizedDebug :: (MonadIncrSMT Pipe m, MonadIO m, KnownSMTSort t, Orderable (Expr t)) => (Solution -> IO ()) -> Expr t -> m (Result, Solution)
- solveMaximized :: (MonadIncrSMT Pipe m, MonadIO m, KnownSMTSort t, Orderable (Expr t)) => Expr t -> m (Result, Solution)
- solveMaximizedDebug :: (MonadIncrSMT Pipe m, MonadIO m, KnownSMTSort t, Orderable (Expr t)) => (Solution -> IO ()) -> Expr t -> m (Result, Solution)
Documentation
class WithSolver a where Source #
Data that can have a Solver
which may be debugged.
Methods
withSolver :: Solver -> Bool -> a Source #
Instances
WithSolver Pipe Source # | |
Defined in Language.Hasmtlib.Type.Solver |
solveWith :: (Default s, Monad m, Codec a) => Solver s m -> StateT s m a -> m (Result, Maybe (Decoded a)) Source #
solves a SMT problem solveWith
solver probprob
with the given
solver
. It returns a pair consisting of:
- A
Result
that indicates ifprob
is satisfiable (Sat
), unsatisfiable (Unsat
), or if the solver could not determine any results (Unknown
). - A
Decoded
answer that was decoded using the solution toprob
. Note that this answer is only meaningful if theResult
isSat
orUnknown
and the answer value is in aJust
.
Here is a small example of how to use solveWith
:
import Language.Hasmtlib
main :: IO ()
main = do
res <- solveWith SMT (solver cvc5) $ do
setLogic "QF_LIA"
x <- var
IntSort
assert $ x >? 0
return x
print res
interactiveWith :: (WithSolver s, MonadIO m) => (Solver, Handle) -> StateT s m () -> m () Source #
Pipes an SMT-problem interactively to the solver. Enables incremental solving by default. Here is a small example of how to use it for solving a problem utilizing the solvers incremental stack:
import Language.Hasmtlib
import Control.Monad.IO.Class
main :: IO ()
main = do
cvc5Living <- interactiveSolver cvc5
interactiveWith Pipe cvc5Living $ do
setOption $ Incremental True
setOption $ ProduceModels True
setLogic "QF_LIA"
x <- var
IntSort
assert $ x >? 0
(res, sol) <- solve
liftIO $ print res
liftIO $ print $ decode sol x
push
y <- var @IntSort
assert $ y <? 0
assert $ x === y
res' <- checkSat
liftIO $ print res'
pop
res'' <- checkSat
liftIO $ print res''
return ()
debugInteractiveWith :: (WithSolver s, MonadIO m) => (Solver, Handle) -> StateT s m () -> m () Source #
Like interactiveWith
but it prints all communication with the solver to console.
solveMinimized :: (MonadIncrSMT Pipe m, MonadIO m, KnownSMTSort t, Orderable (Expr t)) => Expr t -> m (Result, Solution) Source #
Solves the current problem with respect to a minimal solution for a given numerical expression.
Does not rely on MaxSMT/OMT. Instead uses iterative refinement.
If you want access to intermediate results, use solveMinimizedDebug
instead.
solveMinimizedDebug :: (MonadIncrSMT Pipe m, MonadIO m, KnownSMTSort t, Orderable (Expr t)) => (Solution -> IO ()) -> Expr t -> m (Result, Solution) Source #
Like solveMinimized
but with access to intermediate results.
solveMaximized :: (MonadIncrSMT Pipe m, MonadIO m, KnownSMTSort t, Orderable (Expr t)) => Expr t -> m (Result, Solution) Source #
Solves the current problem with respect to a maximal solution for a given numerical expression.
Does not rely on MaxSMT/OMT. Instead uses iterative refinement.
If you want access to intermediate results, use solveMaximizedDebug
instead.
solveMaximizedDebug :: (MonadIncrSMT Pipe m, MonadIO m, KnownSMTSort t, Orderable (Expr t)) => (Solution -> IO ()) -> Expr t -> m (Result, Solution) Source #
Like solveMaximized
but with access to intermediate results.