what4-1.0: Solver-agnostic symbolic values support for issuing queries

Copyright(c) Galois Inc 2014-2020
LicenseBSD3
MaintainerRob Dockins <rdockins@galois.com>
Stabilityprovisional
Safe HaskellNone
LanguageHaskell2010

What4.Protocol.SMTLib2

Contents

Description

This module defines operations for producing SMTLib2-compatible queries useful for interfacing with solvers that accecpt SMTLib2 as an input language.

Synopsis

Documentation

data Writer a Source #

Instances
SMTLib2Tweaks a => SMTReadWriter (Writer a) Source # 
Instance details

Defined in What4.Protocol.SMTLib2

SMTLib2Tweaks a => SMTWriter (Writer a) Source # 
Instance details

Defined in What4.Protocol.SMTLib2

Methods

forallExpr :: [(Text, Some TypeMap)] -> Term (Writer a) -> Term (Writer a) Source #

existsExpr :: [(Text, Some TypeMap)] -> Term (Writer a) -> Term (Writer a) Source #

arrayConstant :: Maybe (ArrayConstantFn (Term (Writer a))) Source #

arraySelect :: Term (Writer a) -> [Term (Writer a)] -> Term (Writer a) Source #

arrayUpdate :: Term (Writer a) -> [Term (Writer a)] -> Term (Writer a) -> Term (Writer a) Source #

commentCommand :: f (Writer a) -> Builder -> Command (Writer a) Source #

assertCommand :: f (Writer a) -> Term (Writer a) -> Command (Writer a) Source #

assertNamedCommand :: f (Writer a) -> Term (Writer a) -> Text -> Command (Writer a) Source #

pushCommand :: f (Writer a) -> Command (Writer a) Source #

popCommand :: f (Writer a) -> Command (Writer a) Source #

popManyCommands :: f (Writer a) -> Int -> [Command (Writer a)] Source #

resetCommand :: f (Writer a) -> Command (Writer a) Source #

checkCommands :: f (Writer a) -> [Command (Writer a)] Source #

checkWithAssumptionsCommands :: f (Writer a) -> [Text] -> [Command (Writer a)] Source #

getUnsatAssumptionsCommand :: f (Writer a) -> Command (Writer a) Source #

getUnsatCoreCommand :: f (Writer a) -> Command (Writer a) Source #

setOptCommand :: f (Writer a) -> Text -> Text -> Command (Writer a) Source #

declareCommand :: f (Writer a) -> Text -> Assignment TypeMap args -> TypeMap rtp -> Command (Writer a) Source #

defineCommand :: f (Writer a) -> Text -> [(Text, Some TypeMap)] -> TypeMap rtp -> Term (Writer a) -> Command (Writer a) Source #

declareStructDatatype :: WriterConn t (Writer a) -> Assignment TypeMap args -> IO () Source #

structCtor :: Assignment TypeMap args -> [Term (Writer a)] -> Term (Writer a) Source #

structProj :: Assignment TypeMap args -> Index args tp -> Term (Writer a) -> Term (Writer a) Source #

stringTerm :: ByteString -> Term (Writer a) Source #

stringLength :: Term (Writer a) -> Term (Writer a) Source #

stringIndexOf :: Term (Writer a) -> Term (Writer a) -> Term (Writer a) -> Term (Writer a) Source #

stringContains :: Term (Writer a) -> Term (Writer a) -> Term (Writer a) Source #

stringIsPrefixOf :: Term (Writer a) -> Term (Writer a) -> Term (Writer a) Source #

stringIsSuffixOf :: Term (Writer a) -> Term (Writer a) -> Term (Writer a) Source #

stringSubstring :: Term (Writer a) -> Term (Writer a) -> Term (Writer a) -> Term (Writer a) Source #

stringAppend :: [Term (Writer a)] -> Term (Writer a) Source #

resetDeclaredStructs :: WriterConn t (Writer a) -> IO () Source #

writeCommand :: WriterConn t (Writer a) -> Command (Writer a) -> IO () Source #

OnlineSolver (Writer Z3) Source # 
Instance details

Defined in What4.Solver.Z3

OnlineSolver (Writer STP) Source # 
Instance details

Defined in What4.Solver.STP

OnlineSolver (Writer CVC4) Source # 
Instance details

Defined in What4.Solver.CVC4

OnlineSolver (Writer Boolector) Source # 
Instance details

Defined in What4.Solver.Boolector

type Command (Writer a) Source # 
Instance details

Defined in What4.Protocol.SMTLib2

type Term (Writer a) Source # 
Instance details

Defined in What4.Protocol.SMTLib2

type Term (Writer a) = Term

class Show a => SMTLib2Tweaks a where Source #

This class exists so that solvers supporting the SMTLib2 format can support features that go slightly beyond the standard.

In particular, there is no standardized syntax for constant arrays (arrays which map every index to the same value). Solvers that support the theory of arrays and have custom syntax for constant arrays should implement smtlib2arrayConstant. In addition, solvers may override the default representation of complex numbers if necessary. The default is to represent complex numbers as "(Array Bool Real)" and to build instances by updating a constant array.

Minimal complete definition

smtlib2tweaks

Methods

smtlib2tweaks :: a Source #

smtlib2arrayType :: [Sort] -> Sort -> Sort Source #

Return a representation of the type associated with a (multi-dimensional) symbolic array.

By default, we encode symbolic arrays using a nested representation. If the solver, supports tuples/structs it may wish to change this.

smtlib2arrayConstant :: Maybe ([Sort] -> Sort -> Term -> Term) Source #

smtlib2arraySelect :: Term -> [Term] -> Term Source #

smtlib2arrayUpdate :: Term -> [Term] -> Term -> Term Source #

smtlib2StringSort :: Sort Source #

smtlib2StringTerm :: ByteString -> Term Source #

smtlib2StringLength :: Term -> Term Source #

smtlib2StringAppend :: [Term] -> Term Source #

smtlib2StringContains :: Term -> Term -> Term Source #

smtlib2StringIndexOf :: Term -> Term -> Term -> Term Source #

smtlib2StringIsPrefixOf :: Term -> Term -> Term Source #

smtlib2StringIsSuffixOf :: Term -> Term -> Term Source #

smtlib2StringSubstring :: Term -> Term -> Term -> Term Source #

smtlib2StructSort :: [Sort] -> Sort Source #

The sort of structs with the given field types.

By default, this uses SMTLIB2 datatypes and are not primitive to the language.

smtlib2StructCtor :: [Term] -> Term Source #

Construct a struct value from the given field values

smtlib2StructProj Source #

Arguments

:: Int

number of fields in the struct

-> Int

0-based index of the struct field

-> Term

struct term to project from

-> Term 

Construct a struct field projection term

smtlib2declareStructCmd :: Int -> Maybe Command Source #

Instances
SMTLib2Tweaks () Source # 
Instance details

Defined in What4.Protocol.SMTLib2

SMTLib2Tweaks Z3 Source # 
Instance details

Defined in What4.Solver.Z3

SMTLib2Tweaks STP Source # 
Instance details

Defined in What4.Solver.STP

SMTLib2Tweaks DReal Source # 
Instance details

Defined in What4.Solver.DReal

SMTLib2Tweaks CVC4 Source # 
Instance details

Defined in What4.Solver.CVC4

SMTLib2Tweaks Boolector Source # 
Instance details

Defined in What4.Solver.Boolector

newWriter Source #

Arguments

:: a 
-> OutputStream Text

Stream to write queries onto

-> InputStream Text

Input stream to read responses from (may be the nullInput stream if no responses are expected)

-> AcknowledgementAction t (Writer a)

Action to run for consuming acknowledgement messages

-> String

Name of solver for reporting purposes.

-> Bool

Flag indicating if it is permitted to use "define-fun" when generating SMTLIB

-> ProblemFeatures

Indicates what features are supported by the solver

-> Bool

Indicates if quantifiers are supported.

-> SymbolVarBimap t

Variable bindings for names.

-> IO (WriterConn t (Writer a)) 

writeCheckSat :: SMTLib2Tweaks a => WriterConn t (Writer a) -> IO () Source #

Write check sat command

writeExit :: forall a t. SMTLib2Tweaks a => WriterConn t (Writer a) -> IO () Source #

runCheckSat Source #

Arguments

:: SMTLib2Tweaks b 
=> Session t b 
-> (SatResult (GroundEvalFn t, Maybe (ExprRangeBindings t)) () -> IO a)

Function for evaluating model. The evaluation should be complete before

-> IO a 

This function runs a check sat command

asSMT2Type :: forall a tp. SMTLib2Tweaks a => TypeMap tp -> Sort Source #

versionResult :: SMTReadWriter h => f h -> InputStream Text -> IO Text Source #

Get the result of a version query

nameResult :: SMTReadWriter h => f h -> InputStream Text -> IO Text Source #

Get the result of a version query

setProduceModels :: SMTLib2Tweaks a => WriterConn t (Writer a) -> Bool -> IO () Source #

Set the produce models option (We typically want this)

Logic

newtype Logic Source #

Identifies the set of predefined sorts and operators available.

Constructors

Logic Builder 

qf_bv :: Logic Source #

Use the QF_BV logic

allSupported :: Logic Source #

Set the logic to all supported logics.

all_supported :: Logic Source #

Deprecated: Use allSupported

Set the logic to all supported logics.

Type

newtype Sort Source #

Sort for SMTLIB expressions

Constructors

Sort 

Fields

arraySort :: Sort -> Sort -> Sort Source #

arraySort a b denotes the set of functions from a to be b.

Term

newtype Term Source #

Denotes an expression in the SMT solver

Constructors

T 

Fields

Instances
Num Term Source # 
Instance details

Defined in What4.Protocol.SMTLib2

Methods

(+) :: Term -> Term -> Term #

(-) :: Term -> Term -> Term #

(*) :: Term -> Term -> Term #

negate :: Term -> Term #

abs :: Term -> Term #

signum :: Term -> Term #

fromInteger :: Integer -> Term #

IsString Term Source # 
Instance details

Defined in What4.Protocol.SMTLib2.Syntax

Methods

fromString :: String -> Term #

Semigroup Term Source # 
Instance details

Defined in What4.Protocol.SMTLib2.Syntax

Methods

(<>) :: Term -> Term -> Term #

sconcat :: NonEmpty Term -> Term #

stimes :: Integral b => b -> Term -> Term #

Monoid Term Source # 
Instance details

Defined in What4.Protocol.SMTLib2.Syntax

Methods

mempty :: Term #

mappend :: Term -> Term -> Term #

mconcat :: [Term] -> Term #

SupportTermOps Term Source # 
Instance details

Defined in What4.Protocol.SMTLib2

Methods

boolExpr :: Bool -> Term Source #

notExpr :: Term -> Term Source #

andAll :: [Term] -> Term Source #

orAll :: [Term] -> Term Source #

(.&&) :: Term -> Term -> Term Source #

(.||) :: Term -> Term -> Term Source #

(.==) :: Term -> Term -> Term Source #

(./=) :: Term -> Term -> Term Source #

impliesExpr :: Term -> Term -> Term Source #

letExpr :: [(Text, Term)] -> Term -> Term Source #

ite :: Term -> Term -> Term -> Term Source #

sumExpr :: [Term] -> Term Source #

termIntegerToReal :: Term -> Term Source #

termRealToInteger :: Term -> Term Source #

integerTerm :: Integer -> Term Source #

rationalTerm :: Rational -> Term Source #

(.<=) :: Term -> Term -> Term Source #

(.<) :: Term -> Term -> Term Source #

(.>) :: Term -> Term -> Term Source #

(.>=) :: Term -> Term -> Term Source #

intAbs :: Term -> Term Source #

intDiv :: Term -> Term -> Term Source #

intMod :: Term -> Term -> Term Source #

intDivisible :: Term -> Natural -> Term Source #

bvTerm :: NatRepr w -> BV w -> Term Source #

bvNeg :: Term -> Term Source #

bvAdd :: Term -> Term -> Term Source #

bvSub :: Term -> Term -> Term Source #

bvMul :: Term -> Term -> Term Source #

bvSLe :: Term -> Term -> Term Source #

bvULe :: Term -> Term -> Term Source #

bvSLt :: Term -> Term -> Term Source #

bvULt :: Term -> Term -> Term Source #

bvUDiv :: Term -> Term -> Term Source #

bvURem :: Term -> Term -> Term Source #

bvSDiv :: Term -> Term -> Term Source #

bvSRem :: Term -> Term -> Term Source #

bvAnd :: Term -> Term -> Term Source #

bvOr :: Term -> Term -> Term Source #

bvXor :: Term -> Term -> Term Source #

bvNot :: Term -> Term Source #

bvShl :: Term -> Term -> Term Source #

bvLshr :: Term -> Term -> Term Source #

bvAshr :: Term -> Term -> Term Source #

bvConcat :: Term -> Term -> Term Source #

bvExtract :: NatRepr w -> Natural -> Natural -> Term -> Term Source #

bvTestBit :: NatRepr w -> Natural -> Term -> Term Source #

bvSumExpr :: NatRepr w -> [Term] -> Term Source #

floatPZero :: FloatPrecisionRepr fpp -> Term Source #

floatNZero :: FloatPrecisionRepr fpp -> Term Source #

floatNaN :: FloatPrecisionRepr fpp -> Term Source #

floatPInf :: FloatPrecisionRepr fpp -> Term Source #

floatNInf :: FloatPrecisionRepr fpp -> Term Source #

floatNeg :: Term -> Term Source #

floatAbs :: Term -> Term Source #

floatSqrt :: RoundingMode -> Term -> Term Source #

floatAdd :: RoundingMode -> Term -> Term -> Term Source #

floatSub :: RoundingMode -> Term -> Term -> Term Source #

floatMul :: RoundingMode -> Term -> Term -> Term Source #

floatDiv :: RoundingMode -> Term -> Term -> Term Source #

floatRem :: Term -> Term -> Term Source #

floatMin :: Term -> Term -> Term Source #

floatMax :: Term -> Term -> Term Source #

floatFMA :: RoundingMode -> Term -> Term -> Term -> Term Source #

floatEq :: Term -> Term -> Term Source #

floatFpEq :: Term -> Term -> Term Source #

floatLe :: Term -> Term -> Term Source #

floatLt :: Term -> Term -> Term Source #

floatIsNaN :: Term -> Term Source #

floatIsInf :: Term -> Term Source #

floatIsZero :: Term -> Term Source #

floatIsPos :: Term -> Term Source #

floatIsNeg :: Term -> Term Source #

floatIsSubnorm :: Term -> Term Source #

floatIsNorm :: Term -> Term Source #

floatCast :: FloatPrecisionRepr fpp -> RoundingMode -> Term -> Term Source #

floatRound :: RoundingMode -> Term -> Term Source #

floatFromBinary :: FloatPrecisionRepr fpp -> Term -> Term Source #

bvToFloat :: FloatPrecisionRepr fpp -> RoundingMode -> Term -> Term Source #

sbvToFloat :: FloatPrecisionRepr fpp -> RoundingMode -> Term -> Term Source #

realToFloat :: FloatPrecisionRepr fpp -> RoundingMode -> Term -> Term Source #

floatToBV :: Natural -> RoundingMode -> Term -> Term Source #

floatToSBV :: Natural -> RoundingMode -> Term -> Term Source #

floatToReal :: Term -> Term Source #

realIsInteger :: Term -> Term Source #

realDiv :: Term -> Term -> Term Source #

realSin :: Term -> Term Source #

realCos :: Term -> Term Source #

realATan2 :: Term -> Term -> Term Source #

realSinh :: Term -> Term Source #

realCosh :: Term -> Term Source #

realExp :: Term -> Term Source #

realLog :: Term -> Term Source #

smtFnApp :: Term -> [Term] -> Term Source #

smtFnUpdate :: Maybe (Term -> [Term] -> Term -> Term) Source #

lambdaTerm :: Maybe ([(Text, Some TypeMap)] -> Term -> Term) Source #

fromText :: Text -> Term Source #

Solvers and External interface

data Session t a Source #

This is an interactive session with an SMT solver

Constructors

Session 

class (SMTLib2Tweaks a, Show a) => SMTLib2GenericSolver a where Source #

Instances
SMTLib2GenericSolver Z3 Source # 
Instance details

Defined in What4.Solver.Z3

SMTLib2GenericSolver STP Source # 
Instance details

Defined in What4.Solver.STP

SMTLib2GenericSolver CVC4 Source # 
Instance details

Defined in What4.Solver.CVC4

SMTLib2GenericSolver Boolector Source # 
Instance details

Defined in What4.Solver.Boolector

writeDefaultSMT2 Source #

Arguments

:: SMTLib2Tweaks a 
=> a 
-> String

Name of solver for reporting.

-> ProblemFeatures

Features supported by solver

-> ExprBuilder t st fs 
-> Handle 
-> [BoolExpr t] 
-> IO () 

A default method for writing SMTLib2 problems without any solver-specific tweaks.

startSolver Source #

Arguments

:: SMTLib2GenericSolver a 
=> a 
-> AcknowledgementAction t (Writer a)

Action for acknowledging command responses

-> (WriterConn t (Writer a) -> IO ())

Action for setting start-up-time options and logic

-> ProblemFeatures 
-> Maybe Handle 
-> ExprBuilder t st fs 
-> IO (SolverProcess t (Writer a)) 

Solver version

ppSolverVersionCheckError :: SolverVersionCheckError -> Doc Source #

ppSolverVersionError :: SolverVersionError -> Doc Source #

checkSolverVersion :: SMTLib2Tweaks solver => SolverProcess scope (Writer solver) -> IO (Either SolverVersionCheckError (Maybe SolverVersionError)) Source #

Ensure the solver's version falls within a known-good range.

checkSolverVersion' Source #

Arguments

:: SMTLib2Tweaks solver 
=> Map String Version

min version bounds (inclusive)

-> Map String Version

max version bounds (non-inclusive)

-> SolverProcess scope (Writer solver) 
-> IO (Either SolverVersionCheckError (Maybe SolverVersionError)) 

Ensure the solver's version falls within a known-good range.

queryErrorBehavior :: SMTLib2Tweaks a => WriterConn t (Writer a) -> InputStream Text -> IO ErrorBehavior Source #

Query the solver's error behavior setting

Re-exports

data WriterConn t (h :: Type) Source #

assume :: SMTWriter h => WriterConn t h -> BoolExpr t -> IO () Source #

Write assume formula predicates for asserting predicate holds.

supportedFeatures :: WriterConn t h -> ProblemFeatures Source #

Indicates features supported by the solver.

nullAcknowledgementAction :: AcknowledgementAction t h Source #

An acknowledgement action that does nothing

Orphan instances

Num Term Source # 
Instance details

Methods

(+) :: Term -> Term -> Term #

(-) :: Term -> Term -> Term #

(*) :: Term -> Term -> Term #

negate :: Term -> Term #

abs :: Term -> Term #

signum :: Term -> Term #

fromInteger :: Integer -> Term #

SupportTermOps Term Source # 
Instance details

Methods

boolExpr :: Bool -> Term Source #

notExpr :: Term -> Term Source #

andAll :: [Term] -> Term Source #

orAll :: [Term] -> Term Source #

(.&&) :: Term -> Term -> Term Source #

(.||) :: Term -> Term -> Term Source #

(.==) :: Term -> Term -> Term Source #

(./=) :: Term -> Term -> Term Source #

impliesExpr :: Term -> Term -> Term Source #

letExpr :: [(Text, Term)] -> Term -> Term Source #

ite :: Term -> Term -> Term -> Term Source #

sumExpr :: [Term] -> Term Source #

termIntegerToReal :: Term -> Term Source #

termRealToInteger :: Term -> Term Source #

integerTerm :: Integer -> Term Source #

rationalTerm :: Rational -> Term Source #

(.<=) :: Term -> Term -> Term Source #

(.<) :: Term -> Term -> Term Source #

(.>) :: Term -> Term -> Term Source #

(.>=) :: Term -> Term -> Term Source #

intAbs :: Term -> Term Source #

intDiv :: Term -> Term -> Term Source #

intMod :: Term -> Term -> Term Source #

intDivisible :: Term -> Natural -> Term Source #

bvTerm :: NatRepr w -> BV w -> Term Source #

bvNeg :: Term -> Term Source #

bvAdd :: Term -> Term -> Term Source #

bvSub :: Term -> Term -> Term Source #

bvMul :: Term -> Term -> Term Source #

bvSLe :: Term -> Term -> Term Source #

bvULe :: Term -> Term -> Term Source #

bvSLt :: Term -> Term -> Term Source #

bvULt :: Term -> Term -> Term Source #

bvUDiv :: Term -> Term -> Term Source #

bvURem :: Term -> Term -> Term Source #

bvSDiv :: Term -> Term -> Term Source #

bvSRem :: Term -> Term -> Term Source #

bvAnd :: Term -> Term -> Term Source #

bvOr :: Term -> Term -> Term Source #

bvXor :: Term -> Term -> Term Source #

bvNot :: Term -> Term Source #

bvShl :: Term -> Term -> Term Source #

bvLshr :: Term -> Term -> Term Source #

bvAshr :: Term -> Term -> Term Source #

bvConcat :: Term -> Term -> Term Source #

bvExtract :: NatRepr w -> Natural -> Natural -> Term -> Term Source #

bvTestBit :: NatRepr w -> Natural -> Term -> Term Source #

bvSumExpr :: NatRepr w -> [Term] -> Term Source #

floatPZero :: FloatPrecisionRepr fpp -> Term Source #

floatNZero :: FloatPrecisionRepr fpp -> Term Source #

floatNaN :: FloatPrecisionRepr fpp -> Term Source #

floatPInf :: FloatPrecisionRepr fpp -> Term Source #

floatNInf :: FloatPrecisionRepr fpp -> Term Source #

floatNeg :: Term -> Term Source #

floatAbs :: Term -> Term Source #

floatSqrt :: RoundingMode -> Term -> Term Source #

floatAdd :: RoundingMode -> Term -> Term -> Term Source #

floatSub :: RoundingMode -> Term -> Term -> Term Source #

floatMul :: RoundingMode -> Term -> Term -> Term Source #

floatDiv :: RoundingMode -> Term -> Term -> Term Source #

floatRem :: Term -> Term -> Term Source #

floatMin :: Term -> Term -> Term Source #

floatMax :: Term -> Term -> Term Source #

floatFMA :: RoundingMode -> Term -> Term -> Term -> Term Source #

floatEq :: Term -> Term -> Term Source #

floatFpEq :: Term -> Term -> Term Source #

floatLe :: Term -> Term -> Term Source #

floatLt :: Term -> Term -> Term Source #

floatIsNaN :: Term -> Term Source #

floatIsInf :: Term -> Term Source #

floatIsZero :: Term -> Term Source #

floatIsPos :: Term -> Term Source #

floatIsNeg :: Term -> Term Source #

floatIsSubnorm :: Term -> Term Source #

floatIsNorm :: Term -> Term Source #

floatCast :: FloatPrecisionRepr fpp -> RoundingMode -> Term -> Term Source #

floatRound :: RoundingMode -> Term -> Term Source #

floatFromBinary :: FloatPrecisionRepr fpp -> Term -> Term Source #

bvToFloat :: FloatPrecisionRepr fpp -> RoundingMode -> Term -> Term Source #

sbvToFloat :: FloatPrecisionRepr fpp -> RoundingMode -> Term -> Term Source #

realToFloat :: FloatPrecisionRepr fpp -> RoundingMode -> Term -> Term Source #

floatToBV :: Natural -> RoundingMode -> Term -> Term Source #

floatToSBV :: Natural -> RoundingMode -> Term -> Term Source #

floatToReal :: Term -> Term Source #

realIsInteger :: Term -> Term Source #

realDiv :: Term -> Term -> Term Source #

realSin :: Term -> Term Source #

realCos :: Term -> Term Source #

realATan2 :: Term -> Term -> Term Source #

realSinh :: Term -> Term Source #

realCosh :: Term -> Term Source #

realExp :: Term -> Term Source #

realLog :: Term -> Term Source #

smtFnApp :: Term -> [Term] -> Term Source #

smtFnUpdate :: Maybe (Term -> [Term] -> Term -> Term) Source #

lambdaTerm :: Maybe ([(Text, Some TypeMap)] -> Term -> Term) Source #

fromText :: Text -> Term Source #