Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module defines types and operations for generating SMTLIB2 files.
It does not depend on the rest of What4 so that it can be used directly by clients interested in generating SMTLIB without depending on the What4 formula interface. All the type constructors are exposed so that clients can generate new values that are not exposed through this interface.
Synopsis
- newtype Command = Cmd Builder
- setLogic :: Logic -> Command
- setOption :: Text -> Text -> Command
- setProduceModels :: Bool -> Command
- data SMTInfoFlag
- getInfo :: SMTInfoFlag -> Command
- getVersion :: Command
- getName :: Command
- getErrorBehavior :: Command
- exit :: Command
- declareSort :: Symbol -> Integer -> Command
- defineSort :: Symbol -> [Symbol] -> Sort -> Command
- declareConst :: Text -> Sort -> Command
- declareFun :: Text -> [Sort] -> Sort -> Command
- defineFun :: Text -> [(Text, Sort)] -> Sort -> Term -> Command
- type Symbol = Text
- checkSat :: Command
- checkSatAssuming :: [Term] -> Command
- checkSatWithAssumptions :: [Text] -> Command
- getModel :: Command
- getValue :: [Term] -> Command
- push :: Integer -> Command
- pop :: Integer -> Command
- resetAssertions :: Command
- assert :: Term -> Command
- assertNamed :: Term -> Text -> Command
- getUnsatAssumptions :: Command
- getUnsatCore :: Command
- getAbduct :: Text -> Term -> Command
- getAbductNext :: Command
- synthFun :: Text -> [(Text, Sort)] -> Sort -> Command
- declareVar :: Text -> Sort -> Command
- constraint :: Term -> Command
- checkSynth :: Command
- newtype Logic = Logic Builder
- qf_bv :: Logic
- allSupported :: Logic
- allLogic :: Logic
- hornLogic :: Logic
- newtype Sort = Sort {}
- boolSort :: Sort
- bvSort :: Natural -> Sort
- intSort :: Sort
- realSort :: Sort
- varSort :: Symbol -> Sort
- newtype Term = T {}
- un_app :: Builder -> Term -> Term
- bin_app :: Builder -> Term -> Term -> Term
- term_app :: Builder -> [Term] -> Term
- pairwise_app :: Builder -> [Term] -> Term
- namedTerm :: Term -> Text -> Term
- builder_list :: [Builder] -> Builder
- true :: Term
- false :: Term
- not :: Term -> Term
- implies :: [Term] -> Term -> Term
- and :: [Term] -> Term
- or :: [Term] -> Term
- xor :: [Term] -> Term
- eq :: [Term] -> Term
- distinct :: [Term] -> Term
- ite :: Term -> Term -> Term -> Term
- forall_ :: [(Text, Sort)] -> Term -> Term
- exists_ :: [(Text, Sort)] -> Term -> Term
- letBinder :: [(Text, Term)] -> Term -> Term
- negate :: Term -> Term
- numeral :: Integer -> Term
- decimal :: Integer -> Term
- sub :: Term -> [Term] -> Term
- add :: [Term] -> Term
- mul :: [Term] -> Term
- div :: Term -> [Term] -> Term
- (./) :: Term -> [Term] -> Term
- mod :: Term -> Term -> Term
- abs :: Term -> Term
- le :: [Term] -> Term
- lt :: [Term] -> Term
- ge :: [Term] -> Term
- gt :: [Term] -> Term
- toReal :: Term -> Term
- toInt :: Term -> Term
- isInt :: Term -> Term
- concat :: Term -> Term -> Term
- extract :: Natural -> Natural -> Term -> Term
- bvnot :: Term -> Term
- bvand :: Term -> [Term] -> Term
- bvor :: Term -> [Term] -> Term
- bvxor :: Term -> [Term] -> Term
- bvneg :: Term -> Term
- bvadd :: Term -> [Term] -> Term
- bvsub :: Term -> Term -> Term
- bvmul :: Term -> [Term] -> Term
- bvudiv :: Term -> Term -> Term
- bvurem :: Term -> Term -> Term
- bvshl :: Term -> Term -> Term
- bvlshr :: Term -> Term -> Term
- bvult :: Term -> Term -> Term
- bit0 :: Term
- bit1 :: Term
- bvbinary :: 1 <= w => NatRepr w -> BV w -> Term
- bvdecimal :: 1 <= w => NatRepr w -> BV w -> Term
- bvhexadecimal :: 1 <= w => NatRepr w -> BV w -> Term
- bvashr :: Term -> Term -> Term
- bvslt :: Term -> Term -> Term
- bvsle :: Term -> Term -> Term
- bvule :: Term -> Term -> Term
- bvsgt :: Term -> Term -> Term
- bvsge :: Term -> Term -> Term
- bvugt :: Term -> Term -> Term
- bvuge :: Term -> Term -> Term
- bvsdiv :: Term -> Term -> Term
- bvsrem :: Term -> Term -> Term
- bvsignExtend :: Integer -> Term -> Term
- bvzeroExtend :: Integer -> Term -> Term
- arraySort :: Sort -> Sort -> Sort
- arrayConst :: Sort -> Sort -> Term -> Term
- select :: Term -> Term -> Term
- store :: Term -> Term -> Term -> Term
Commands
setOption :: Text -> Text -> Command Source #
Set an option in the SMT solver
The name should not need to be prefixed with a colon."
setProduceModels :: Bool -> Command Source #
Set option to produce models
This is a widely used option so, we we have a custom command to make it.
data SMTInfoFlag Source #
This is a subtype of the type of the same name in Data.SBV.Control.
Instances
getInfo :: SMTInfoFlag -> Command Source #
A get-info
command
getVersion :: Command Source #
Declarations
declareSort :: Symbol -> Integer -> Command Source #
Declare an uninterpreted sort with the given number of sort parameters.
Define a sort in terms of other sorts
declareConst :: Text -> Sort -> Command Source #
Declare a constant with the given name and return types.
declareFun :: Text -> [Sort] -> Sort -> Command Source #
Declare a function with the given name, argument types, and return type.
defineFun :: Text -> [(Text, Sort)] -> Sort -> Term -> Command Source #
Declare a function with the given name, argument types, and return type.
Assertions and checking
checkSatAssuming :: [Term] -> Command Source #
Check the satisfiability of the current assertions and the additional ones in the list.
checkSatWithAssumptions :: [Text] -> Command Source #
Check satisfiability of the given atomic assumptions in the current context.
NOTE! The names of variables passed to this function MUST be generated using a `declare-fun` statement, and NOT a `define-fun` statement. Thus, if you want to bind an arbitrary term, you must declare a new term and assert that it is equal to it's definition. Yes, this is quite irritating.
getValue :: [Term] -> Command Source #
Get the values associated with the terms from the last call to check-sat
.
resetAssertions :: Command Source #
Empties the assertion stack and remove all global assertions and declarations.
assertNamed :: Term -> Text -> Command Source #
Assert the predicate holds in the current context, and assign it a name so it can appear in unsatisfiable core results.
getAbduct :: Text -> Term -> Command Source #
Get an abduct that entails the formula, and bind it to the name
getAbductNext :: Command Source #
Get the next command, called after a get-abduct command
SyGuS
synthFun :: Text -> [(Text, Sort)] -> Sort -> Command Source #
Declare a SyGuS function to synthesize with the given name, arguments, and return type.
declareVar :: Text -> Sort -> Command Source #
Declare a SyGuS variable with the given name and type.
constraint :: Term -> Command Source #
Add the SyGuS constraint to the current synthesis problem.
checkSynth :: Command Source #
Ask the SyGuS solver to find a solution for the synthesis problem corresponding to the current functions-to-synthesize, variables and constraints.
Logic
allSupported :: Logic Source #
Deprecated: Use allLogic instead
Set the logic to all supported logics.
Sort
Term
Denotes an expression in the SMT solver
Instances
un_app :: Builder -> Term -> Term Source #
Construct an expression with the given operator and single argument.
bin_app :: Builder -> Term -> Term -> Term Source #
Construct an expression with the given operator and two arguments.
term_app :: Builder -> [Term] -> Term Source #
Construct an expression with the given operator and list of arguments.
pairwise_app :: Builder -> [Term] -> Term Source #
Construct a chainable term with the given relation
pairwise_app p [x1, x2, ..., xn]
is equivalent to
forall_{i,j} p x_i x_j@.
namedTerm :: Term -> Text -> Term Source #
Append a "name" to a term so that it will be printed when
(get-assignment)
is called.
builder_list :: [Builder] -> Builder Source #
Core theory
forall_ :: [(Text, Sort)] -> Term -> Term Source #
forall_ vars t
denotes a predicate that holds if t
for every valuation of the
variables in vars
.
exists_ :: [(Text, Sort)] -> Term -> Term Source #
exists_ vars t
denotes a predicate that holds if t
for some valuation of the
variables in vars
.
letBinder :: [(Text, Term)] -> Term -> Term Source #
Create a let binding. NOTE: SMTLib2 defines this to be a "parallel" let, which means that the bound variables are NOT in scope in the right-hand sides of other bindings, even syntactically-later ones.
Ints
, Reals
, Reals_Ints
theories
sub :: Term -> [Term] -> Term Source #
sub x1 [x2, ..., xn]
with n >= 1 returns
x1
minus x2 + ... + xn
.
The terms are expected to have type Int
or Real
.
add :: [Term] -> Term Source #
add [x1, x2, ..., xn]
with n >= 2 returns
x1
minus x2 + ... + xn
.
The terms are expected to have type Int
or Real
.
mul :: [Term] -> Term Source #
add [x1, x2, ..., xn]
with n >= 2 returns
x1
minus x2 + ... + xn
.
The terms are expected to have type Int
or Real
.
div :: Term -> [Term] -> Term Source #
div x1 [x2, ..., xn]
with n >= 1 returns
x1
div x2 * ... * xn
.
The terms are expected to have type Int
.
mod :: Term -> Term -> Term Source #
mod x1 x2
returns x1 - x2 * (x1 div
[x2])@.
The terms are expected to have type Int
.
abs x1
returns the absolute value of x1
.
The term is expected to have type Int
.
Less than or equal over a chained list of terms.
le [x1, x2, ..., xn]
is equivalent to
x1 <= x2 x2 <= x3 ... / x(n-1) <= xn
.
This is defined in the Reals, Ints, and Reals_Ints theories, and the number of elements must be at least 2.
With a strict interpretation of the SMTLIB standard, the terms should be all of the same type (i.e. Int or Real"), but existing solvers appear to implicitly all mixed terms.
Less than over a chained list of terms.
lt [x1, x2, ..., xn]
is equivalent to
x1 < x2 x2 < x3 ... / x(n-1) < xn
.
With a strict interpretation of the SMTLIB standard, the terms should be all of the same type (i.e. Int or Real"), but existing solvers appear to implicitly all mixed terms.
Greater than or equal over a chained list of terms.
ge [x1, x2, ..., xn]
is equivalent to
x1 >= x2 x2 >= x3 ... / x(n-1) >= xn
.
With a strict interpretation of the SMTLIB standard, the terms should be all of the same type (i.e. Int or Real"), but existing solvers appear to implicitly all mixed terms.
Greater than over a chained list of terms.
gt [x1, x2, ..., xn]
is equivalent to
x1 > x2 x2 > x3 ... / x(n-1) > xn
.
With a strict interpretation of the SMTLIB standard, the terms should be all of the same type (i.e. Int or Real"), but existing solvers appear to implicitly all mixed terms.
Bitvector theory and extensions
concat :: Term -> Term -> Term Source #
concat x y
returns the bitvector with the bits of x
followed by the bits of y
.
extract :: Natural -> Natural -> Term -> Term Source #
extract i j x
returns the bitvector containing the bits [j..i]
.
bvudiv :: Term -> Term -> Term Source #
bvudiv x y
returns floor (to_nat x / to_nat y)
when y != 0
.
When y = 0
, this returns not (from_nat 0)
.
bvurem :: Term -> Term -> Term Source #
bvurem x y
returns x - y * bvudiv x y
when y != 0
.
When y = 0
, this returns from_nat 0
.
bvshl :: Term -> Term -> Term Source #
bvshl x y
shifts the bits in x
to the left by to_nat u
bits.
The new bits are zeros (false)
bvlshr :: Term -> Term -> Term Source #
bvlshr x y
shifts the bits in x
to the right by to_nat u
bits.
The new bits are zeros (false)
bvult :: Term -> Term -> Term Source #
bvult x y
returns a Boolean term that is true if to_nat x < to_nat y
.
Extensions provided by QF_BV
bvbinary :: 1 <= w => NatRepr w -> BV w -> Term Source #
bvbinary w x
constructs a bitvector term with width w
equal
to x
.mod
2^w
The width w
must be positive.
The literal uses a binary notation.
bvdecimal :: 1 <= w => NatRepr w -> BV w -> Term Source #
bvdecimal x w
constructs a bitvector term with width w
equal to x
.mod
2^w
The width w
must be positive.
The literal uses a decimal notation.
bvhexadecimal :: 1 <= w => NatRepr w -> BV w -> Term Source #
bvhexadecimal x w
constructs a bitvector term with width w
equal to x
.mod
2^w
The width w
must be a positive multiple of 4.
The literal uses hex notation.
bvashr :: Term -> Term -> Term Source #
bvashr x y
shifts the bits in x
to the right by to_nat u
bits.
The new bits are the same as the most-significant bit of x
.
Note. This is in QF_BV
, but not the bitvector theory.
bvslt :: Term -> Term -> Term Source #
bvslt x y
returns a Boolean term that is true if to_int x < to_int y
.
Note. This is in QF_BV
, but not the bitvector theory.
bvsle :: Term -> Term -> Term Source #
bvsle x y
returns a Boolean term that is true if to_int x <= to_int y
.
Note. This is in QF_BV
, but not the bitvector theory.
bvule :: Term -> Term -> Term Source #
bvule x y
returns a Boolean term that is true if to_nat x <= to_nat y
.
Note. This is in QF_BV
, but not the bitvector theory.
bvsgt :: Term -> Term -> Term Source #
bvsgt x y
returns a Boolean term that is true if to_int x < to_int y
.
Note. This is in QF_BV
, but not the bitvector theory.
bvsge :: Term -> Term -> Term Source #
bvsge x y
returns a Boolean term that is true if to_int x <= to_int y
.
Note. This is in QF_BV
, but not the bitvector theory.
bvugt :: Term -> Term -> Term Source #
bvugt x y
returns a Boolean term that is true if to_nat x < to_nat y
.
Note. This is in QF_BV
, but not the bitvector theory.
bvuge :: Term -> Term -> Term Source #
bvuge x y
returns a Boolean term that is true if to_nat x <= to_nat y
.
Note. This is in QF_BV
, but not the bitvector theory.
bvsdiv :: Term -> Term -> Term Source #
bvsdiv x y
returns round_to_zero (to_int x / to_int y)
when y != 0
.
When y = 0
, this returns not (from_nat 0)
.
Note. This is in QF_BV
, but not the bitvector theory.
bvsrem :: Term -> Term -> Term Source #
bvsrem x y
returns x - y * bvsdiv x y
when y != 0
.
When y = 0
, this returns from_nat 0
.
Note. This is in QF_BV
, but not the bitvector theory.
bvsignExtend :: Integer -> Term -> Term Source #
bvsignExtend w x
adds an additional w
bits to the most
significant bits of x
by sign extending x
.
Note. This is in QF_BV
, but not the bitvector theory.
bvzeroExtend :: Integer -> Term -> Term Source #
bvzeroExtend w x
adds an additional w
zero bits to the most
significant bits of x
.
Note. This is in QF_BV
, but not the bitvector theory.
Array theory
arraySort :: Sort -> Sort -> Sort Source #
arraySort a b
denotes the set of functions from a
to be b
.