grisette-0.1.0.0: Symbolic evaluation as a library
Copyright(c) Sirui Lu 2021-2023
LicenseBSD-3-Clause (see the LICENSE file)
Maintainersiruilu@cs.washington.edu
StabilityExperimental
PortabilityGHC only
Safe HaskellTrustworthy
LanguageHaskell2010

Grisette.Core

Description

 
Synopsis

Note for the examples

The examples may assume a z3 solver available in PATH.

Symbolic values

Grisette is a tool for performing symbolic evaluation on programs. Symbolic evaluation is a technique that allows us to analyze all possible runs of a program by representing inputs (or the program itself) as symbolic values and evaluating the program to produce symbolic constraints over these values. These constraints can then be used to find concrete assignments to the symbolic values that meet certain criteria, such as triggering a bug in a verification task or satisfying a specification in a synthesis task.

One of the challenges of symbolic evaluation is the well-known path explosion problem, which occurs when traditions symbolic evaluation techniques evaluate and reason about the possible paths one-by-one. This can lead to exponential growth in the number of paths that need to be analyzed, making the process impractical for many tasks. To address this issue, Grisette uses a technique called "path merging". In path merging, symbolic values are merged together in order to reduce the number of paths that need to be explored simultaneously. This can significantly improve the performance of symbolic evaluation, especially for tasks such as program synthesis that are prone to the path explosion problem.

In Grisette, we make a distinction between two kinds of symbolic values: solvable types and unsolvable types. These two types of values are merged differently.

Solvable types are types that are directly supported by the underlying solver and are represented as symbolic formulas. Examples include symbolic Booleans, integers and bit vectors. The values of solvable types can be fully merged into a single value, which can significantly reduce the number of paths that need to be explored.

For example, there are three symbolic Booleans a, b and c, in the following code, and a symbolic Boolean x is defined to be the result of a conditional expression:

x = if a then b else c -- pseudo code, not real Grisette code

The result would be a single symbolic Boolean formula:

-- result: x is (ite a b c)

If we further add 1 to x, we will not have to split to two paths, but we can directly construct a formula with the merged state:

x + 1
-- result (+ 1 (ite a b c))

Unsolvable types, on the other hand, are types that are not directly supported by the solver and cannot be fully merged into a single formula. Examples include lists, algebraic data types, and concrete Haskell integer types. To symbolically evaluate values in unsolvable types, Grisette provides a symbolic union container, which is a set of values guarded by their path conditions. The values of unsolvable types are partially merged in a symbolic union, which is essentially an if-then-else tree.

For example, assume that the lists have the type [SymBool]. In the following example, the result shows that [b] and [c] can be merged together in the same symbolic union because they have the same length:

x = if a then [b] else [c] -- pseudo code, not real Grisette code
-- result: Single [(ite a b c)]

The second example shows that [b] and [c,d] cannot be merged together because they have different lengths:

if a then [b] else [c, d] -- pseudo code, not real Grisette code
-- result: If a (Single [b]) (Single [c,d])

The following example is more complicated. To make the merging efficient, Grisette would maintain a representation invariant of the symbolic unions. In this case, the lists with length 1 should be placed at the then branch, and the lists with length 2 should be placed at the else branch.

if a1 then [b] else if a2 then [c, d] else [f] -- pseudo code, not real Grisette code
-- result: If (|| a1 (! a2)) (Single [(ite a1 b f)]) (Single [c,d])

When we further operate on this partially merged values, we will need to split into multiple paths. For example, when we apply head onto the last result, we will distribute head among the branches:

head (if a1 then [b] else if a2 then [c, d] else [f]) -- pseudo code, not real Grisette code
-- intermediate result: If (|| a1 (! a2)) (Single (head [(ite a1 b f)])) (Single (head [c,d]))
-- intermediate result: If (|| a1 (! a2)) (Single (ite a1 b f)) (Single c)

Then the result would be further merged into a single value:

-- final result: Single (ite (|| a1 (! a2)) (ite a1 b f) c)

Generally, merging the possible branches in a symbolic union can reduce the number of paths to be explored in the future, but can make the path conditions larger and harder to solve. To have a good balance between this, Grisette has built a hierarchical merging algorithm, which is configurable via MergingStrategy. For algebraic data types, we have prebuilt merging strategies via the derivation of the Mergeable type class. You only need to know the details of the merging algorithm if you are going to work with non-algebraic data types.

Solvable types

A solvable type is a type that can be represented as a formula and is directly supported by the underlying constraint solvers. Grisette currently provides an implementation for the following solvable types:

  • SymBool or Sym Bool (symbolic Booleans)
  • SymInteger or Sym Integer (symbolic unbounded integers)
  • SymIntN n or Sym (IntN n) (symbolic signed bit vectors of length n)
  • SymWordN n or Sym (WordN n) (symbolic unsigned bit vectors of length n)

Values of a solvable type can consist of concrete values, symbolic constants (placeholders for concrete values that can be assigned by a solver to satisfy a formula), and complex symbolic formulas with symbolic operations. The Solvable type class provides a way to construct concrete values and symbolic constants.

Examples:

>>> import Grisette
>>> con True :: SymBool -- a concrete value
true
>>> ssym "a" :: SymBool -- a symbolic constant
a

With the OverloadedStrings GHC extension enabled, symbolic constants can also be constructed from strings.

>>> :set -XOverloadedStrings
>>> "a" :: SymBool
a

Symbolic operations are provided through a set of type classes, such as SEq, SOrd, and Num. Please check out the documentation for more details.

Examples:

>>> let a = "a" :: SymInteger
>>> let b = "b" :: SymInteger
>>> a ==~ b
(= a b)

Creation of solvable type values

class IsString t => Solvable c t | t -> c where Source #

The class defines the creation and pattern matching of solvable type values.

Methods

con :: c -> t Source #

Wrap a concrete value in a symbolic value.

>>> con True :: SymBool
true

conView :: t -> Maybe c Source #

Extract the concrete value from a symbolic value.

>>> conView (con True :: SymBool)
Just True
>>> conView (ssym "a" :: SymBool)
Nothing

ssym :: String -> t Source #

Generate simply-named symbolic constants.

Two symbolic constants with the same name are the same symbolic constant, and will always be assigned with the same value by the solver.

>>> ssym "a" :: SymBool
a
>>> (ssym "a" :: SymBool) == ssym "a"
True
>>> (ssym "a" :: SymBool) == ssym "b"
False
>>> (ssym "a" :: SymBool) &&~ ssym "a"
a

isym :: String -> Int -> t Source #

Generate indexed symbolic constants.

Two symbolic constants with the same name but different indices are not the same symbolic constants.

>>> isym "a" 1 :: SymBool
a@1

sinfosym :: (Typeable a, Ord a, Lift a, NFData a, Show a, Hashable a) => String -> a -> t Source #

Generate simply-named symbolic constants with some extra information for disambiguation.

Two symbolic constants with the same name but different extra information (including info with different types) are considered to be different.

>>> sinfosym "a" "someInfo" :: SymInteger
a:"someInfo"

iinfosym :: (Typeable a, Ord a, Lift a, NFData a, Show a, Hashable a) => String -> Int -> a -> t Source #

Generate indexed symbolic constants with some extra information for disambiguation.

Two symbolic constants with the same name and index but different extra information (including info with different types) are considered to be different.

>>> iinfosym "a" 1 "someInfo" :: SymInteger
a@1:"someInfo"

Instances

Instances details
SupportedPrim a => Solvable a (Sym a) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

con :: a -> Sym a Source #

conView :: Sym a -> Maybe a Source #

ssym :: String -> Sym a Source #

isym :: String -> Int -> Sym a Source #

sinfosym :: (Typeable a0, Ord a0, Lift a0, NFData a0, Show a0, Hashable a0) => String -> a0 -> Sym a Source #

iinfosym :: (Typeable a0, Ord a0, Lift a0, NFData a0, Show a0, Hashable a0) => String -> Int -> a0 -> Sym a Source #

(Solvable c t, Mergeable t) => Solvable c (UnionM t) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

con :: c -> UnionM t Source #

conView :: UnionM t -> Maybe c Source #

ssym :: String -> UnionM t Source #

isym :: String -> Int -> UnionM t Source #

sinfosym :: (Typeable a, Ord a, Lift a, NFData a, Show a, Hashable a) => String -> a -> UnionM t Source #

iinfosym :: (Typeable a, Ord a, Lift a, NFData a, Show a, Hashable a) => String -> Int -> a -> UnionM t Source #

pattern Con :: Solvable c t => c -> t Source #

Extract the concrete value from a solvable value with conView.

>>> case con True :: SymBool of Con v -> v
True

slocsym :: Solvable c s => String -> SpliceQ s Source #

Generate simply-named symbolic variables. The file location will be attached to the identifier.

>>> $$(slocsym "a") :: SymBool
a:<interactive>:...

Calling slocsymb with the same name at different location will always generate different symbolic constants. Calling slocsymb at the same location for multiple times will generate the same symbolic constants.

>>> ($$(slocsym "a") :: SymBool) == $$(slocsym "a")
False
>>> let f _ = $$(slocsym "a") :: SymBool
>>> f () == f ()
True

ilocsym :: Solvable c s => String -> Int -> SpliceQ s Source #

Generate indexed symbolic variables. The file location will be attached to identifier.

>>> $$(ilocsym "a" 1) :: SymBool
a@1:<interactive>:...

Calling ilocsymb with the same name and index at different location will always generate different symbolic constants. Calling slocsymb at the same location for multiple times will generate the same symbolic constants.

Symbolic operators

class LogicalOp b where Source #

Symbolic logical operators for symbolic booleans.

>>> let t = con True :: SymBool
>>> let f = con False :: SymBool
>>> let a = "a" :: SymBool
>>> let b = "b" :: SymBool
>>> t ||~ f
true
>>> a ||~ t
true
>>> a ||~ f
a
>>> a ||~ b
(|| a b)
>>> t &&~ f
false
>>> a &&~ t
a
>>> a &&~ f
false
>>> a &&~ b
(&& a b)
>>> nots t
false
>>> nots f
true
>>> nots a
(! a)
>>> t `xors` f
true
>>> t `xors` t
false
>>> a `xors` t
(! a)
>>> a `xors` f
a
>>> a `xors` b
(|| (&& (! a) b) (&& a (! b)))

Minimal complete definition

(||~), nots | (&&~), nots

Methods

(||~) :: b -> b -> b infixr 2 Source #

Symbolic disjunction

(&&~) :: b -> b -> b infixr 3 Source #

Symbolic conjunction

nots :: b -> b Source #

Symbolic negation

xors :: b -> b -> b Source #

Symbolic exclusive disjunction

implies :: b -> b -> b Source #

Symbolic implication

Instances

Instances details
LogicalOp Bool Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

(LogicalOp a, Mergeable a) => LogicalOp (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

(||~) :: UnionM a -> UnionM a -> UnionM a Source #

(&&~) :: UnionM a -> UnionM a -> UnionM a Source #

nots :: UnionM a -> UnionM a Source #

xors :: UnionM a -> UnionM a -> UnionM a Source #

implies :: UnionM a -> UnionM a -> UnionM a Source #

LogicalOp (Sym Bool) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

class ITEOp v where Source #

ITE operator for solvable (see Grisette.Core)s, including symbolic boolean, integer, etc.

>>> let a = "a" :: SymBool
>>> let b = "b" :: SymBool
>>> let c = "c" :: SymBool
>>> ites a b c
(ite a b c)

Methods

ites :: SymBool -> v -> v -> v Source #

Instances

Instances details
(ITEOp a, Mergeable a) => ITEOp (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

ites :: SymBool -> UnionM a -> UnionM a -> UnionM a Source #

SupportedPrim a => ITEOp (Sym a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

Methods

ites :: SymBool -> Sym a -> Sym a -> Sym a Source #

class SEq a where Source #

Symbolic equality. Note that we can't use Haskell's Eq class since symbolic comparison won't necessarily return a concrete Bool value.

>>> let a = 1 :: SymInteger
>>> let b = 2 :: SymInteger
>>> a ==~ b
false
>>> a /=~ b
true
>>> let a = "a" :: SymInteger
>>> let b = "b" :: SymInteger
>>> a /=~ b
(! (= a b))
>>> a /=~ b
(! (= a b))

Note: This type class can be derived for algebraic data types. You may need the DerivingVia and DerivingStrategies extensions.

data X = ... deriving Generic deriving SEq via (Default X)

Minimal complete definition

(==~) | (/=~)

Methods

(==~) :: a -> a -> SymBool infix 4 Source #

(/=~) :: a -> a -> SymBool infix 4 Source #

Instances

Instances details
SEq Int16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

SEq Int32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

SEq Int64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

SEq Int8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

SEq Word16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

SEq Word32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

SEq Word64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

SEq ByteString Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

SEq AssertionError Source # 
Instance details

Defined in Grisette.Core.Control.Exception

SEq VerificationConditions Source # 
Instance details

Defined in Grisette.Core.Control.Exception

SEq Word8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

SEq Integer Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

SEq () Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

Methods

(==~) :: () -> () -> SymBool Source #

(/=~) :: () -> () -> SymBool Source #

SEq Bool Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

SEq Char Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

SEq Int Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

Methods

(==~) :: Int -> Int -> SymBool Source #

(/=~) :: Int -> Int -> SymBool Source #

SEq Word Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

SEq a => SEq (Identity a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

(Generic a, SEq' (Rep a)) => SEq (Default a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

SEq a => SEq (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

(==~) :: UnionM a -> UnionM a -> SymBool Source #

(/=~) :: UnionM a -> UnionM a -> SymBool Source #

SupportedPrim (IntN n) => SEq (Sym (IntN n)) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

(==~) :: Sym (IntN n) -> Sym (IntN n) -> SymBool Source #

(/=~) :: Sym (IntN n) -> Sym (IntN n) -> SymBool Source #

SupportedPrim (WordN n) => SEq (Sym (WordN n)) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

(==~) :: Sym (WordN n) -> Sym (WordN n) -> SymBool Source #

(/=~) :: Sym (WordN n) -> Sym (WordN n) -> SymBool Source #

SupportedPrim Integer => SEq (Sym Integer) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

SupportedPrim Bool => SEq (Sym Bool) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

SEq a => SEq (Maybe a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

Methods

(==~) :: Maybe a -> Maybe a -> SymBool Source #

(/=~) :: Maybe a -> Maybe a -> SymBool Source #

SEq a => SEq [a] Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

Methods

(==~) :: [a] -> [a] -> SymBool Source #

(/=~) :: [a] -> [a] -> SymBool Source #

(SEq e, SEq a) => SEq (Either e a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

Methods

(==~) :: Either e a -> Either e a -> SymBool Source #

(/=~) :: Either e a -> Either e a -> SymBool Source #

(SEq e, SEq a) => SEq (CBMCEither e a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

SEq (m (Maybe a)) => SEq (MaybeT m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

Methods

(==~) :: MaybeT m a -> MaybeT m a -> SymBool Source #

(/=~) :: MaybeT m a -> MaybeT m a -> SymBool Source #

(SEq a, SEq b) => SEq (a, b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

Methods

(==~) :: (a, b) -> (a, b) -> SymBool Source #

(/=~) :: (a, b) -> (a, b) -> SymBool Source #

SEq (m (CBMCEither e a)) => SEq (CBMCExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

(==~) :: CBMCExceptT e m a -> CBMCExceptT e m a -> SymBool Source #

(/=~) :: CBMCExceptT e m a -> CBMCExceptT e m a -> SymBool Source #

SEq (m (Either e a)) => SEq (ExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

Methods

(==~) :: ExceptT e m a -> ExceptT e m a -> SymBool Source #

(/=~) :: ExceptT e m a -> ExceptT e m a -> SymBool Source #

SEq (m a) => SEq (IdentityT m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

Methods

(==~) :: IdentityT m a -> IdentityT m a -> SymBool Source #

(/=~) :: IdentityT m a -> IdentityT m a -> SymBool Source #

SEq (m (a, s)) => SEq (WriterT s m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

Methods

(==~) :: WriterT s m a -> WriterT s m a -> SymBool Source #

(/=~) :: WriterT s m a -> WriterT s m a -> SymBool Source #

SEq (m (a, s)) => SEq (WriterT s m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

Methods

(==~) :: WriterT s m a -> WriterT s m a -> SymBool Source #

(/=~) :: WriterT s m a -> WriterT s m a -> SymBool Source #

(SEq a, SEq b, SEq c) => SEq (a, b, c) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

Methods

(==~) :: (a, b, c) -> (a, b, c) -> SymBool Source #

(/=~) :: (a, b, c) -> (a, b, c) -> SymBool Source #

(SEq (f a), SEq (g a)) => SEq (Sum f g a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

Methods

(==~) :: Sum f g a -> Sum f g a -> SymBool Source #

(/=~) :: Sum f g a -> Sum f g a -> SymBool Source #

(SEq a, SEq b, SEq c, SEq d) => SEq (a, b, c, d) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

Methods

(==~) :: (a, b, c, d) -> (a, b, c, d) -> SymBool Source #

(/=~) :: (a, b, c, d) -> (a, b, c, d) -> SymBool Source #

(SEq a, SEq b, SEq c, SEq d, SEq e) => SEq (a, b, c, d, e) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

Methods

(==~) :: (a, b, c, d, e) -> (a, b, c, d, e) -> SymBool Source #

(/=~) :: (a, b, c, d, e) -> (a, b, c, d, e) -> SymBool Source #

(SEq a, SEq b, SEq c, SEq d, SEq e, SEq f) => SEq (a, b, c, d, e, f) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

Methods

(==~) :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> SymBool Source #

(/=~) :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> SymBool Source #

(SEq a, SEq b, SEq c, SEq d, SEq e, SEq f, SEq g) => SEq (a, b, c, d, e, f, g) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

Methods

(==~) :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> SymBool Source #

(/=~) :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> SymBool Source #

(SEq a, SEq b, SEq c, SEq d, SEq e, SEq f, SEq g, SEq h) => SEq (a, b, c, d, e, f, g, h) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

Methods

(==~) :: (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> SymBool Source #

(/=~) :: (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> SymBool Source #

class (SimpleMergeable b, SEq b, Eq b, LogicalOp b, Solvable Bool b, ITEOp b) => SymBoolOp b Source #

Aggregation for the operations on symbolic boolean types

Instances

Instances details
SymBoolOp (Sym Bool) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

class SEq a => SOrd a where Source #

Symbolic total order. Note that we can't use Haskell's Ord class since symbolic comparison won't necessarily return a concrete Bool or Ordering value.

>>> let a = 1 :: SymInteger
>>> let b = 2 :: SymInteger
>>> a <~ b
true
>>> a >~ b
false
>>> let a = "a" :: SymInteger
>>> let b = "b" :: SymInteger
>>> a <~ b
(< a b)
>>> a <=~ b
(<= a b)
>>> a >~ b
(< b a)
>>> a >=~ b
(<= b a)

For symCompare, Ordering is not a solvable type, and the result would be wrapped in a union-like monad. See UnionMBase and UnionLike for more information.

>>> a `symCompare` b :: UnionM Ordering -- UnionM is UnionMBase specialized with SymBool
{If (< a b) LT (If (= a b) EQ GT)}

Note: This type class can be derived for algebraic data types. You may need the DerivingVia and DerivingStrategies extensions.

data X = ... deriving Generic deriving SOrd via (Default X)

Minimal complete definition

(<=~)

Methods

(<~) :: a -> a -> SymBool infix 4 Source #

(<=~) :: a -> a -> SymBool infix 4 Source #

(>~) :: a -> a -> SymBool infix 4 Source #

(>=~) :: a -> a -> SymBool infix 4 Source #

symCompare :: a -> a -> UnionM Ordering Source #

Instances

Instances details
SOrd Int16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

SOrd Int32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

SOrd Int64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

SOrd Int8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

SOrd Word16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

SOrd Word32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

SOrd Word64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

SOrd ByteString Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

SOrd AssertionError Source # 
Instance details

Defined in Grisette.Core.Control.Exception

SOrd VerificationConditions Source # 
Instance details

Defined in Grisette.Core.Control.Exception

SOrd Word8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

SOrd Integer Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

SOrd () Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

Methods

(<~) :: () -> () -> SymBool Source #

(<=~) :: () -> () -> SymBool Source #

(>~) :: () -> () -> SymBool Source #

(>=~) :: () -> () -> SymBool Source #

symCompare :: () -> () -> UnionM Ordering Source #

SOrd Bool Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

SOrd Char Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

SOrd Int Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

SOrd Word Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

SOrd a => SOrd (Identity a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

(SEq a, Generic a, SOrd' (Rep a)) => SOrd (Default a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

SOrd a => SOrd (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

SupportedPrim (IntN n) => SOrd (Sym (IntN n)) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

(<~) :: Sym (IntN n) -> Sym (IntN n) -> SymBool Source #

(<=~) :: Sym (IntN n) -> Sym (IntN n) -> SymBool Source #

(>~) :: Sym (IntN n) -> Sym (IntN n) -> SymBool Source #

(>=~) :: Sym (IntN n) -> Sym (IntN n) -> SymBool Source #

symCompare :: Sym (IntN n) -> Sym (IntN n) -> UnionM Ordering Source #

SupportedPrim (WordN n) => SOrd (Sym (WordN n)) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

(<~) :: Sym (WordN n) -> Sym (WordN n) -> SymBool Source #

(<=~) :: Sym (WordN n) -> Sym (WordN n) -> SymBool Source #

(>~) :: Sym (WordN n) -> Sym (WordN n) -> SymBool Source #

(>=~) :: Sym (WordN n) -> Sym (WordN n) -> SymBool Source #

symCompare :: Sym (WordN n) -> Sym (WordN n) -> UnionM Ordering Source #

SupportedPrim Integer => SOrd (Sym Integer) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

SOrd (Sym Bool) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

SOrd a => SOrd (Maybe a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

SOrd a => SOrd [a] Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

Methods

(<~) :: [a] -> [a] -> SymBool Source #

(<=~) :: [a] -> [a] -> SymBool Source #

(>~) :: [a] -> [a] -> SymBool Source #

(>=~) :: [a] -> [a] -> SymBool Source #

symCompare :: [a] -> [a] -> UnionM Ordering Source #

(SOrd a, SOrd b) => SOrd (Either a b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

Methods

(<~) :: Either a b -> Either a b -> SymBool Source #

(<=~) :: Either a b -> Either a b -> SymBool Source #

(>~) :: Either a b -> Either a b -> SymBool Source #

(>=~) :: Either a b -> Either a b -> SymBool Source #

symCompare :: Either a b -> Either a b -> UnionM Ordering Source #

(SOrd a, SOrd b) => SOrd (CBMCEither a b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

SOrd (m (Maybe a)) => SOrd (MaybeT m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

Methods

(<~) :: MaybeT m a -> MaybeT m a -> SymBool Source #

(<=~) :: MaybeT m a -> MaybeT m a -> SymBool Source #

(>~) :: MaybeT m a -> MaybeT m a -> SymBool Source #

(>=~) :: MaybeT m a -> MaybeT m a -> SymBool Source #

symCompare :: MaybeT m a -> MaybeT m a -> UnionM Ordering Source #

(SOrd a, SOrd b) => SOrd (a, b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

Methods

(<~) :: (a, b) -> (a, b) -> SymBool Source #

(<=~) :: (a, b) -> (a, b) -> SymBool Source #

(>~) :: (a, b) -> (a, b) -> SymBool Source #

(>=~) :: (a, b) -> (a, b) -> SymBool Source #

symCompare :: (a, b) -> (a, b) -> UnionM Ordering Source #

SOrd (m (CBMCEither e a)) => SOrd (CBMCExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

SOrd (m (Either e a)) => SOrd (ExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

Methods

(<~) :: ExceptT e m a -> ExceptT e m a -> SymBool Source #

(<=~) :: ExceptT e m a -> ExceptT e m a -> SymBool Source #

(>~) :: ExceptT e m a -> ExceptT e m a -> SymBool Source #

(>=~) :: ExceptT e m a -> ExceptT e m a -> SymBool Source #

symCompare :: ExceptT e m a -> ExceptT e m a -> UnionM Ordering Source #

SOrd (m a) => SOrd (IdentityT m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

SOrd (m (a, s)) => SOrd (WriterT s m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

Methods

(<~) :: WriterT s m a -> WriterT s m a -> SymBool Source #

(<=~) :: WriterT s m a -> WriterT s m a -> SymBool Source #

(>~) :: WriterT s m a -> WriterT s m a -> SymBool Source #

(>=~) :: WriterT s m a -> WriterT s m a -> SymBool Source #

symCompare :: WriterT s m a -> WriterT s m a -> UnionM Ordering Source #

SOrd (m (a, s)) => SOrd (WriterT s m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

Methods

(<~) :: WriterT s m a -> WriterT s m a -> SymBool Source #

(<=~) :: WriterT s m a -> WriterT s m a -> SymBool Source #

(>~) :: WriterT s m a -> WriterT s m a -> SymBool Source #

(>=~) :: WriterT s m a -> WriterT s m a -> SymBool Source #

symCompare :: WriterT s m a -> WriterT s m a -> UnionM Ordering Source #

(SOrd a, SOrd b, SOrd c) => SOrd (a, b, c) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

Methods

(<~) :: (a, b, c) -> (a, b, c) -> SymBool Source #

(<=~) :: (a, b, c) -> (a, b, c) -> SymBool Source #

(>~) :: (a, b, c) -> (a, b, c) -> SymBool Source #

(>=~) :: (a, b, c) -> (a, b, c) -> SymBool Source #

symCompare :: (a, b, c) -> (a, b, c) -> UnionM Ordering Source #

(SOrd (f a), SOrd (g a)) => SOrd (Sum f g a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

Methods

(<~) :: Sum f g a -> Sum f g a -> SymBool Source #

(<=~) :: Sum f g a -> Sum f g a -> SymBool Source #

(>~) :: Sum f g a -> Sum f g a -> SymBool Source #

(>=~) :: Sum f g a -> Sum f g a -> SymBool Source #

symCompare :: Sum f g a -> Sum f g a -> UnionM Ordering Source #

(SOrd a, SOrd b, SOrd c, SOrd d) => SOrd (a, b, c, d) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

Methods

(<~) :: (a, b, c, d) -> (a, b, c, d) -> SymBool Source #

(<=~) :: (a, b, c, d) -> (a, b, c, d) -> SymBool Source #

(>~) :: (a, b, c, d) -> (a, b, c, d) -> SymBool Source #

(>=~) :: (a, b, c, d) -> (a, b, c, d) -> SymBool Source #

symCompare :: (a, b, c, d) -> (a, b, c, d) -> UnionM Ordering Source #

(SOrd a, SOrd b, SOrd c, SOrd d, SOrd e) => SOrd (a, b, c, d, e) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

Methods

(<~) :: (a, b, c, d, e) -> (a, b, c, d, e) -> SymBool Source #

(<=~) :: (a, b, c, d, e) -> (a, b, c, d, e) -> SymBool Source #

(>~) :: (a, b, c, d, e) -> (a, b, c, d, e) -> SymBool Source #

(>=~) :: (a, b, c, d, e) -> (a, b, c, d, e) -> SymBool Source #

symCompare :: (a, b, c, d, e) -> (a, b, c, d, e) -> UnionM Ordering Source #

(SOrd a, SOrd b, SOrd c, SOrd d, SOrd e, SOrd f) => SOrd (a, b, c, d, e, f) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

Methods

(<~) :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> SymBool Source #

(<=~) :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> SymBool Source #

(>~) :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> SymBool Source #

(>=~) :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> SymBool Source #

symCompare :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> UnionM Ordering Source #

(SOrd a, SOrd b, SOrd c, SOrd d, SOrd e, SOrd f, SOrd g) => SOrd (a, b, c, d, e, f, g) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

Methods

(<~) :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> SymBool Source #

(<=~) :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> SymBool Source #

(>~) :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> SymBool Source #

(>=~) :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> SymBool Source #

symCompare :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> UnionM Ordering Source #

(SOrd a, SOrd b, SOrd c, SOrd d, SOrd e, SOrd f, SOrd g, SOrd h) => SOrd (a, b, c, d, e, f, g, h) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

Methods

(<~) :: (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> SymBool Source #

(<=~) :: (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> SymBool Source #

(>~) :: (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> SymBool Source #

(>=~) :: (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> SymBool Source #

symCompare :: (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> UnionM Ordering Source #

class BVConcat bv1 bv2 bv3 | bv1 bv2 -> bv3 where Source #

Bitwise concatenation (bvconcat) of the given bit vector values.

Methods

bvconcat :: bv1 -> bv2 -> bv3 Source #

Bitwise concatenation of the given bit vector values.

>>> bvconcat (0b101 :: SymIntN 3) (0b010 :: SymIntN 3)
0b101010

Instances

Instances details
(KnownNat n, 1 <= n, KnownNat m, 1 <= m, KnownNat w, 1 <= w, w ~ (n + m)) => BVConcat (IntN n) (IntN m) (IntN w) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.BV

Methods

bvconcat :: IntN n -> IntN m -> IntN w Source #

(KnownNat n, 1 <= n, KnownNat m, 1 <= m, KnownNat w, 1 <= w, w ~ (n + m)) => BVConcat (WordN n) (WordN m) (WordN w) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.BV

Methods

bvconcat :: WordN n -> WordN m -> WordN w Source #

(KnownNat w', KnownNat n, KnownNat w, w' ~ (n + w), 1 <= n, 1 <= w, 1 <= w') => BVConcat (Sym (IntN n)) (Sym (IntN w)) (Sym (IntN w')) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

bvconcat :: Sym (IntN n) -> Sym (IntN w) -> Sym (IntN w') Source #

(KnownNat w', KnownNat n, KnownNat w, w' ~ (n + w), 1 <= n, 1 <= w, 1 <= w') => BVConcat (Sym (WordN n)) (Sym (WordN w)) (Sym (WordN w')) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

bvconcat :: Sym (WordN n) -> Sym (WordN w) -> Sym (WordN w') Source #

class BVExtend bv1 (n :: Nat) bv2 | bv1 n -> bv2 where Source #

Bitwise extension of the given bit vector values.

Methods

bvzeroExtend Source #

Arguments

:: proxy n

Desired output width

-> bv1

Bit vector to extend

-> bv2 

Bitwise zero extension of the given bit vector values.

>>> bvzeroExtend (Proxy @6) (0b101 :: SymIntN 3)
0b000101

bvsignExtend Source #

Arguments

:: proxy n

Desired output width

-> bv1

Bit vector to extend

-> bv2 

Bitwise signed extension of the given bit vector values.

>>> bvsignExtend (Proxy @6) (0b101 :: SymIntN 3)
0b111101

bvextend Source #

Arguments

:: proxy n

Desired output width

-> bv1

Bit vector to extend

-> bv2 

Bitwise extension of the given bit vector values. Signedness is determined by the input bit vector type.

>>> bvextend (Proxy @6) (0b101 :: SymIntN 3)
0b111101
>>> bvextend (Proxy @6) (0b001 :: SymIntN 3)
0b000001
>>> bvextend (Proxy @6) (0b101 :: SymWordN 3)
0b000101
>>> bvextend (Proxy @6) (0b001 :: SymWordN 3)
0b000001

Instances

Instances details
(KnownNat n, 1 <= n, KnownNat r, n <= r) => BVExtend (IntN n) r (IntN r) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.BV

Methods

bvzeroExtend :: proxy r -> IntN n -> IntN r Source #

bvsignExtend :: proxy r -> IntN n -> IntN r Source #

bvextend :: proxy r -> IntN n -> IntN r Source #

(KnownNat n, 1 <= n, KnownNat r, n <= r) => BVExtend (WordN n) r (WordN r) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.BV

Methods

bvzeroExtend :: proxy r -> WordN n -> WordN r Source #

bvsignExtend :: proxy r -> WordN n -> WordN r Source #

bvextend :: proxy r -> WordN n -> WordN r Source #

(KnownNat w, KnownNat w', 1 <= w, 1 <= w', w <= w', (w + 1) <= w', 1 <= (w' - w), KnownNat (w' - w)) => BVExtend (Sym (IntN w)) w' (Sym (IntN w')) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

bvzeroExtend :: proxy w' -> Sym (IntN w) -> Sym (IntN w') Source #

bvsignExtend :: proxy w' -> Sym (IntN w) -> Sym (IntN w') Source #

bvextend :: proxy w' -> Sym (IntN w) -> Sym (IntN w') Source #

(KnownNat w, KnownNat w', 1 <= w, 1 <= w', (w + 1) <= w', w <= w', 1 <= (w' - w), KnownNat (w' - w)) => BVExtend (Sym (WordN w)) w' (Sym (WordN w')) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

bvzeroExtend :: proxy w' -> Sym (WordN w) -> Sym (WordN w') Source #

bvsignExtend :: proxy w' -> Sym (WordN w) -> Sym (WordN w') Source #

bvextend :: proxy w' -> Sym (WordN w) -> Sym (WordN w') Source #

class BVSelect bv1 (ix :: Nat) (w :: Nat) bv2 | bv1 w -> bv2 where Source #

Slicing out a smaller bit vector from a larger one, selecting a slice with width w starting from index ix.

Methods

bvselect Source #

Arguments

:: proxy ix

Index to start selecting from

-> proxy w

Desired output width, 0 <= ix and ix + w < n must hold where n is the size of the input bit vector

-> bv1

Bit vector to select from

-> bv2 

Slicing out a smaller bit vector from a larger one, selecting a slice with width w starting from index ix.

The indices are counting from zero from the least significant bit.

>>> bvselect (Proxy @1) (Proxy @3) (con 0b001010 :: SymIntN 6)
0b101

Instances

Instances details
(KnownNat n, 1 <= n, KnownNat ix, KnownNat w, 1 <= w, (ix + w) <= n) => BVSelect (IntN n) ix w (IntN w) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.BV

Methods

bvselect :: proxy ix -> proxy w -> IntN n -> IntN w Source #

(KnownNat n, 1 <= n, KnownNat ix, KnownNat w, 1 <= w, (ix + w) <= n) => BVSelect (WordN n) ix w (WordN w) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.BV

Methods

bvselect :: proxy ix -> proxy w -> WordN n -> WordN w Source #

(KnownNat ix, KnownNat w, KnownNat ow, (ix + w) <= ow, 1 <= ow, 1 <= w) => BVSelect (Sym (IntN ow)) ix w (Sym (IntN w)) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

bvselect :: proxy ix -> proxy w -> Sym (IntN ow) -> Sym (IntN w) Source #

(KnownNat ix, KnownNat w, KnownNat ow, (ix + w) <= ow, 1 <= ow, 1 <= w) => BVSelect (Sym (WordN ow)) ix w (Sym (WordN w)) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

bvselect :: proxy ix -> proxy w -> Sym (WordN ow) -> Sym (WordN w) Source #

bvextract Source #

Arguments

:: forall proxy i j bv1 bv2. BVSelect bv1 j ((i - j) + 1) bv2 
=> proxy i

The start position to extract from, 0 <= i < n must hold where n is the size of the output bit vector

-> proxy j

The end position to extract from, 0 <= j <= i must hold

-> bv1

Bit vector to extract from

-> bv2 

Extract a smaller bit vector from a larger one from bits i down to j.

The indices are counting from zero from the least significant bit. >>> bvextract (Proxy 3) (Proxy 1) (con 0b001010 :: SymIntN 6) 0b101

class SignedDivMod a where Source #

Safe signed div and mod with monadic error handling in multi-path execution. These procedures show throw DivideByZero exception when the divisor is zero. The result should be able to handle errors with MonadError, and the error type should be compatible with ArithException (see TransformError for more details).

Methods

divs :: (MonadError e uf, MonadUnion uf, TransformError ArithException e) => a -> a -> uf a Source #

Safe signed div with monadic error handling in multi-path execution.

>>> divs (ssym "a") (ssym "b") :: ExceptT AssertionError UnionM SymInteger
ExceptT {If (= b 0) (Left AssertionError) (Right (div a b))}

mods :: (MonadError e uf, MonadUnion uf, TransformError ArithException e) => a -> a -> uf a Source #

Safe signed mod with monadic error handling in multi-path execution.

>>> mods (ssym "a") (ssym "b") :: ExceptT AssertionError UnionM SymInteger
ExceptT {If (= b 0) (Left AssertionError) (Right (mod a b))}

class UnsignedDivMod a where Source #

Safe unsigned div and mod with monadic error handling in multi-path execution. These procedures show throw DivideByZero exception when the divisor is zero. The result should be able to handle errors with MonadError, and the error type should be compatible with ArithException (see TransformError for more details).

Methods

udivs :: (MonadError e uf, MonadUnion uf, TransformError ArithException e) => a -> a -> uf a Source #

umods :: (MonadError e uf, MonadUnion uf, TransformError ArithException e) => a -> a -> uf a Source #

class SignedQuotRem a where Source #

Safe signed quot and rem with monadic error handling in multi-path execution. These procedures show throw DivideByZero exception when the divisor is zero. The result should be able to handle errors with MonadError, and the error type should be compatible with ArithException (see TransformError for more details).

Methods

quots :: (MonadError e uf, MonadUnion uf, TransformError ArithException e) => a -> a -> uf a Source #

rems :: (MonadError e uf, MonadUnion uf, TransformError ArithException e) => a -> a -> uf a Source #

class (Num a, SEq a, SOrd a, Solvable Integer a) => SymIntegerOp a Source #

Aggregation for the operations on symbolic integer types

Instances

Instances details
SymIntegerOp (Sym Integer) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

class Function f where Source #

Abstraction for function-like types.

Associated Types

type Arg f Source #

Argument type

type Ret f Source #

Return type

Methods

(#) :: f -> Arg f -> Ret f infixl 9 Source #

Function application operator.

The operator is not right associated (like ($)). It is left associated, and you can provide many arguments with this operator once at a time.

>>> (+1) # 2
3
>>> (+) # 2 # 3
5

Instances

Instances details
(Function f, Mergeable f, Mergeable a, Ret f ~ a) => Function (UnionM f) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Associated Types

type Arg (UnionM f) Source #

type Ret (UnionM f) Source #

Methods

(#) :: UnionM f -> Arg (UnionM f) -> Ret (UnionM f) Source #

(SupportedPrim a, SupportedPrim b) => Function (a --> b) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Associated Types

type Arg (a --> b) Source #

type Ret (a --> b) Source #

Methods

(#) :: (a --> b) -> Arg (a --> b) -> Ret (a --> b) Source #

(SupportedPrim a, SupportedPrim b) => Function (a -~> b) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Associated Types

type Arg (a -~> b) Source #

type Ret (a -~> b) Source #

Methods

(#) :: (a -~> b) -> Arg (a -~> b) -> Ret (a -~> b) Source #

(SupportedPrim a, SupportedPrim b) => Function (a =~> b) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Associated Types

type Arg (a =~> b) Source #

type Ret (a =~> b) Source #

Methods

(#) :: (a =~> b) -> Arg (a =~> b) -> Ret (a =~> b) Source #

Eq a => Function (a =-> b) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.TabularFun

Associated Types

type Arg (a =-> b) Source #

type Ret (a =-> b) Source #

Methods

(#) :: (a =-> b) -> Arg (a =-> b) -> Ret (a =-> b) Source #

Function (a -> b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Function

Associated Types

type Arg (a -> b) Source #

type Ret (a -> b) Source #

Methods

(#) :: (a -> b) -> Arg (a -> b) -> Ret (a -> b) Source #

Unsolvable types

There are types that cannot be directly represented as SMT formulas and therefore not supported by the SMT solvers. These types are referred to as unsolvable types. To symbolically evaluate such types, we represent them with symbolic unions. A symbolic union is a set of multiple values from different execution paths, each guarded with a corresponding path condition. The value of a union can be determined by an SMT solver based on the truth value of the path conditions.

In Grisette, the symbolic union type is UnionM. Two constructs are useful in constructing symbolic union values: mrgIf and mrgSingle. mrgSingle unconditionally wraps a value in a symbolic union container, while mrgIf models branching control flow semantics with symbolic conditions. Here are some examples of using mrgSingle and mrgIf:

>>> mrgSingle ["a"] :: UnionM [SymInteger]
{[a]}
>>> mrgIf "a" (mrgSingle ["b"]) (mrgSingle ["c", "d"]) :: UnionM [SymInteger]
{If a [b] [c,d]}

UnionM is a monad, and its bind operation is similar to tree substitution. This means you can then use monadic constructs to model sequential programs. For example, the following pseudo code can be modeled in Grisette with the combinators provided by Grisette, and the do-notation:

x = if a then [b] else [b,c] -- pseudo code, not Grisette code
y = if d then [e] else [e,f]
return (x ++ y :: [SymInteger])
>>> :{
  ret :: UnionM [SymInteger]
  ret = do x <- mrgIf "a" (single ["b"]) (single ["b","c"])
           y <- mrgIf "d" (single ["e"]) (single ["e","f"])
           mrgReturn $ x ++ y -- we will explain mrgReturn later
:}

When this code is evaluated, the result would be as follows:

>>> ret
{If (&& a d) [b,e] (If (|| a d) [b,(ite a e c),(ite a f e)] [b,c,e,f])}

In the result, we can see that the results are reorganized and the two lists with the same length are merged together. This is important for scaling symbolic evaluation to real-world problems.

The mrgReturn function is crucial for ensuring that the results are merged. It resolves the Mergeable constraint, and retrieves a merging strategy for the contained type from the constraint. The merging strategy is then cached in the UnionMBase container to help merge the result of the entire do-block. This is necessary due to the constrained-monad problem, as the return function from the Monad type class cannot resolve extra constraints. Our solution to this problem with merging strategy caching is inspired by the knowledge propagation technique introduced in the blog post by Oleg Kiselyov.

In addition to mrgReturn, Grisette provides many combinators with the mrg prefix. You should use these combinators and always have the result cache the merging strategy. Consider the following code:

>>> return 1 :: UnionM Integer
<1>
>>> mrgReturn 1 :: UnionM Integer
{1}
>>> mrgIf "a" (return 1) (return 2) :: UnionM Integer
{If a 1 2}

In the first example, using return instead of mrgReturn results in a UAny container (printed as <...>), which means that no merging strategy is cached. In the second and third example, using mrgReturn or mrgIf results in a UMrg container (printed as {...}), which means that the merging strategy is cached.

When working with UnionM, it is important to always use the mrg prefixed combinators to ensure that the merging strategy is properly cached. This will enable Grisette to properly merge the results of the entire do-block and scale symbolic evaluation to real-world problems. Those functions that merges the results can also further propagate the cached merging strategy, note that the result is merged:

>>> f x y = mrgIf "f" (return x) (return y)
>>> do; a <- mrgIf "a" (return 1) (return 2); f a (a + 1) :: UnionM Integer
{If (&& a f) 1 (If (|| a f) 2 3)}

For more details of this, see the documentation for UnionMBase and MergingStrategy.

To make a type compatible with the symbolic evaluation and merging in Grisette, you need to implement the Mergeable type class. If you are only working with algebraic data types, you can derive the Mergeable instance automatically For example:

>>> :set -XDerivingStrategies
>>> :set -XDerivingVia
>>> :set -XDeriveGeneric
>>> import GHC.Generics
>>> :{
  data X = X SymInteger Integer
    deriving (Generic, Show)
    deriving (Mergeable) via (Default X)
:}

This allows you to use the UnionM type to represent values of type X, and have them merged with the mrgIf combinator:

>>> mrgIf "c1" (mrgSingle $ X "b" 1) (mrgIf "c2" (mrgSingle $ X "c" 2) (mrgSingle $ X "d" 1)) :: UnionM X
{If (|| c1 (! c2)) (X (ite c1 b d) 1) (X c 2)}

It is also possible to apply monad transformers onto UnionM to extend it with various mechanisms. For example, by applying ExceptT, you can symbolically evaluate a program with error handling. To do this, you will need to define an error type and derive the Mergeable instance for it. Then, you can use the combinators provided by MonadError (and the mrg* variants of them) for error handling, and the mrgIf combinator will also work with transformed UnionM containers.

Here's an example using the ExceptT transformer to model error handling in Grisette:

>>> import Control.Monad.Except
>>> :{
  data Error = Fail
    deriving (Show, Generic)
    deriving (Mergeable) via (Default Error)
:}
>>> mrgIf "a" (throwError Fail) (return "x") :: ExceptT Error UnionM SymInteger
ExceptT {If a (Left Fail) (Right x)}

This will return a symbolic union value representing a program that throws an error in the then branch and returns a value in the else branch.

The following is the details of the merging algorithm. If you are not going to manually configure the system by writing a MergingStrategy and will only use the derived strategies, you can safely ignore the following contents in this section.

In Grisette, the symbolic union has the Ordered Guards (ORG) representation, which can be viewed as a nested if-then-else with some representation invariant.

For example, the following symbolic union represents a symbolic list of symbolic integers with length 1, 2 or 3. The values are kept sorted in the container: the list with length 1 is placed at the first place, the list with length 2 is placed at the second place, and so on.

\[ \left\{\begin{aligned} &\texttt{[a]}&&\mathrm{if}&&\texttt{c1}\\ &\texttt{[b,b]}&&\mathrm{else~if}&&\texttt{c2}\\& \texttt{[a,b,c]}&&\mathrm{otherwise} \end{aligned}\right. \]

In Haskell syntax, the container is represented as the following nested if-then-else tree

If c1 [a] (If c2 [b,b] [a,b,c])

The representations means that when c1 is true, then the value is a list [a], or when c1 is false and c2 is true, the value is a list [b,b], or otherwise the value is [a,b,c].

This representation allows you to use the constructs that are not supported by the underlying solvers freely. For example, when applying head on this structure, we can just distribute the head function through the three branches, and get

\[ \left\{\begin{aligned} &\texttt{head [a]}&&\mathrm{if}&&\texttt{c1}\\ &\texttt{head [b,b]}&&\mathrm{else~if}&&\texttt{c2}\\ &\texttt{head [a,b,c]}&&\mathrm{otherwise} \end{aligned}\right. \]

or, equivalently

\[ \left\{\begin{aligned} &\texttt{a}&&\mathrm{if}&&\texttt{c1}\\ &\texttt{b}&&\mathrm{else~if}&&\texttt{c2}\\ &\texttt{a}&&\mathrm{otherwise} \end{aligned}\right. \]

Further symbolic evaluation will also distribute computations over the branches in this result, and the identical branches will cause redundant computation. To mitigate this, Grisette would try to merge the branches, and the previous result would become

\[ \left\{\begin{aligned} &\texttt{a}&&\mathrm{if}&&\texttt{c1}\vee\neg\texttt{c2}\\ &\texttt{b}&&\mathrm{otherwise}\\ \end{aligned}\right. \]

Note that if the contained type is symbolic Boolean, we may further merge the values into a single formula.

\[ \left\{\begin{aligned}&\texttt{(ite c1 a (ite c2 b a))}&&\mathrm{unconditional}\end{aligned}\right. \]

In Grisette, such merging happens in the mrgIf or unionIf functions, which model the symbolic conditional branching semantics. To keep the merging efficient and generate small constraints, we enforce that the symbolic union maintains the values in a sorted way, and merge the unions with a mergesort-style merging algorithm. In the following example, the two ORG containers passed to the mrgIf are sorted with the natural ordering on the integers. In the result, the values are also organized in a sorted way, and the path conditions are correctly maintained.

\[ \texttt{mrgIf}\left[ \texttt{c}, \left\{\begin{aligned} &\texttt{1}&&\mathrm{if}&&\texttt{c1}\\ &\texttt{3}&&\mathrm{else~if}&&\texttt{c2}\\ &\texttt{4}&&\mathrm{otherwise} \end{aligned}\right., \left\{\begin{aligned} &\texttt{1}&&\mathrm{if}&&\texttt{c3}\\ &\texttt{2}&&\mathrm{else~if}&&\texttt{c4}\\ &\texttt{4}&&\mathrm{otherwise} \end{aligned}\right. \right] =\left\{\begin{aligned} &\texttt{1}&&\mathrm{if}&&\texttt{(ite c c1 c3)}\\ &\texttt{2}&&\mathrm{else~if}&&\texttt{(&& (! c) c3)}\\ &\texttt{3}&&\mathrm{else~if}&&\texttt{(&& c c2)}\\ &\texttt{4}&&\mathrm{otherwise} \end{aligned}\right. \]

So far, we have described ORG as a flat list of values. When the list is long, it is beneficial to partition the values and merge (some or all) partitions into nested ORG values. This hierarchical ORG representation is particularly useful for complex data types, such as tuples, which tend to yield long lists.

In the following example, v* are values, while t* are ORG containers. The values in the containers are first partitioned into three groups: {v11, v12, v13}, {v2}, and {v13}. In each group, the values share some common features, (e.g., they are constructed with the same data constructor). The values in each group are organized in a subtree, e.g., the first group is organized in the subtree t1. The hierarchical representation also keeps a representation invariant: at each level in the hierarchy, the values (or the subtrees) are also sorted by some criteria. Here, in the first level, the values are sorted by the constructor declaration order, and in the second level, the values are sorted by the concrete field in the constructor A. This criteria is given by the MergingStrategy in the Mergeable class, called the root merging strategy of the type.

data X = A Integer SymInteger | B | C

\[ \left\{\begin{aligned} &\texttt{t1}&&\mathrm{if}&&\texttt{c1}\\ &\texttt{B}&&\mathrm{else if}&&\texttt{c2}\\ &\texttt{C}&&\mathrm{otherwise}&& \end{aligned}\right. \hspace{2em}\mathrm{where}\hspace{2em} \texttt{t1} = \left\{\begin{aligned} &\texttt{A 1 a}&&\mathrm{if}&&\texttt{c11}\\ &\texttt{A 3 b}&&\mathrm{else if}&&\texttt{c12}\\ &\texttt{A 4 (&& x y)}&&\mathrm{otherwise}&& \end{aligned}\right. \]

In Haskell syntax, it can be represented as follows:

If      c1    (If c11 (A 1 a) (If c12 (A 3 b) (A 4 (&& x y))))
  (If   c2    B
              C)

All the symbolic unions in Grisette should maintain the hierarchical sorted invariant, and are sorted in the same way, with respect to the same merging strategy (the root merging strategy for the type). We can then merge the containers with a hierarchical merging algorithm: at each level, we align the values and subtrees, and merge the aligned ones. In the following example, mrgIf resolves the root merging strategy s, and calls the function mrgIf', which accepts the merging strategy as an argument. The symbolic union operands to the mrgIf' function must be sorted with the merging strategy passed to the function.

Here we use the name of the subtrees and values to indicate the order of them:

  • t1 should be placed before v3 in the then branch,
  • t1 and v4 can be aligned with t1' and v4', respectively.

The aligned subtrees will be merged recursively with mrgIf', with a sub-strategy given by the merging strategy s for the subtrees. For example, t1 and t1' will be merged with the sub-strategy s'. The aligned values will be merged with a merging function, also given by the merging strategy s. For example, v4 and v4' will be merged with the merging function f'.

The ordering and the sub-strategies are abstracted with SortedStrategy, and the merging functions will be wrapped in SimpleStrategy. The merging algorithm can then be configured by implementing the merging strategies for the types contained in a symbolic union. See the documentation for MergingStrategy for details.

\[ \begin{aligned} & \texttt{mrgIf}\left[ \texttt{c}, \left\{\begin{aligned} &\texttt{t1}&&\mathrm{if}&&\texttt{c1}\\ &\texttt{v3}&&\mathrm{else~if}&&\texttt{c2}\\ &\texttt{v4}&&\mathrm{otherwise} \end{aligned}\right., \left\{\begin{aligned} &\texttt{t1'}&&\mathrm{if}&&\texttt{c3}\\ &\texttt{t2'}&&\mathrm{else~if}&&\texttt{c4}\\ &\texttt{v4'}&&\mathrm{otherwise} \end{aligned}\right. \right]\\ =~ & \texttt{mrgIf'}\left[ \texttt{s}, \texttt{c}, \left\{\begin{aligned} &\texttt{t1}&&\mathrm{if}&&\texttt{c1}\\ &\texttt{v3}&&\mathrm{else~if}&&\texttt{c2}\\ &\texttt{v4}&&\mathrm{otherwise} \end{aligned}\right., \left\{\begin{aligned} &\texttt{t1'}&&\mathrm{if}&&\texttt{c3}\\ &\texttt{t2'}&&\mathrm{else~if}&&\texttt{c4}\\ &\texttt{v4'}&&\mathrm{otherwise} \end{aligned}\right. \right]\\ =~ & \left\{\begin{aligned} &\texttt{mrgIf' s' c t1 t1'}&&\mathrm{if}&&\texttt{(ite c c1 c3)}\\ &\texttt{t2'}&&\mathrm{else~if}&&\texttt{(&& (! c) c4)}\\ &\texttt{v3}&&\mathrm{else~if}&&\texttt{(&& c c2)}\\ &\texttt{f' c v4 v4'}&&\mathrm{otherwise} \end{aligned}\right. \end{aligned} \]

For more details of the algorithm, please refer to Grisette's paper.

UnionM Monad

data UnionM a Source #

UnionM is the Union container (hidden) enhanced with MergingStrategy knowledge propagation.

The Union models the underlying semantics evaluation semantics for unsolvable types with the nested if-then-else tree semantics, and can be viewed as the following structure:

data Union a
  = Single a
  | If bool (Union a) (Union a)

The Single constructor is for a single value with the path condition true, and the If constructor is the if operator in an if-then-else tree. For clarity, when printing a UnionM value, we will omit the Single constructor. The following two representations has the same semantics.

If      c1    (If c11 v11 (If c12 v12 v13))
  (If   c2    v2
              v3)

\[ \left\{\begin{aligned}&t_1&&\mathrm{if}&&c_1\\&v_2&&\mathrm{else if}&&c_2\\&v_3&&\mathrm{otherwise}&&\end{aligned}\right.\hspace{2em}\mathrm{where}\hspace{2em}t_1 = \left\{\begin{aligned}&v_{11}&&\mathrm{if}&&c_{11}\\&v_{12}&&\mathrm{else if}&&c_{12}\\&v_{13}&&\mathrm{otherwise}&&\end{aligned}\right. \]

To reduce the size of the if-then-else tree to reduce the number of paths to execute, Grisette would merge the branches in a Union container and maintain a representation invariant for them. To perform this merging procedure, Grisette relies on a type class called Mergeable and the merging strategy defined by it.

Union is a monad, so we can easily write code with the do-notation and monadic combinators. However, the standard monadic operators cannot resolve any extra constraints, including the Mergeable constraint (see The constrained-monad problem by Sculthorpe et al.). This prevents the standard do-notations to merge the results automatically, and would result in bad performance or very verbose code.

To reduce this boilerplate, Grisette provide another monad, UnionM that would try to cache the merging strategy. The UnionM has two data constructors (hidden intentionally), UAny and UMrg. The UAny data constructor (printed as <...>) wraps an arbitrary (probably unmerged) Union. It is constructed when no Mergeable knowledge is available (for example, when constructed with Haskell's return). The UMrg data constructor (printed as {...}) wraps a merged UnionM along with the Mergeable constraint. This constraint can be propagated to the contexts without Mergeable knowledge, and helps the system to merge the resulting Union.

Examples:

return cannot resolve the Mergeable constraint.

>>> return 1 :: UnionM Integer
<1>

mrgReturn can resolve the Mergeable constraint.

>>> import Grisette.Lib.Base
>>> mrgReturn 1 :: UnionM Integer
{1}

unionIf cannot resolve the Mergeable constraint.

>>> unionIf "a" (return 1) (unionIf "b" (return 1) (return 2)) :: UnionM Integer
<If a 1 (If b 1 2)>

But unionIf is able to merge the result if some of the branches are merged:

>>> unionIf "a" (return 1) (unionIf "b" (mrgReturn 1) (return 2)) :: UnionM Integer
{If (|| a b) 1 2}

The >>= operator uses unionIf internally. When the final statement in a do-block merges the values, the system can then merge the final result.

>>> :{
  do
    x <- unionIf (ssym "a") (return 1) (unionIf (ssym "b") (return 1) (return 2))
    mrgSingle $ x + 1 :: UnionM Integer
:}
{If (|| a b) 2 3}

Calling a function that merges a result at the last line of a do-notation will also merge the whole block. If you stick to these mrg* combinators and all the functions will merge the results, the whole program can be symbolically evaluated efficiently.

>>> f x y = mrgIf "c" x y
>>> :{
  do
    x <- unionIf (ssym "a") (return 1) (unionIf (ssym "b") (return 1) (return 2))
    f x (x + 1) :: UnionM Integer
:}
{If (&& c (|| a b)) 1 (If (|| a (|| b c)) 2 3)}

In Grisette.Lib.Base, Grisette.Lib.Mtl, we also provided more mrg* variants of other combinators. You should stick to these combinators to ensure efficient merging by Grisette.

Instances

Instances details
Eq1 UnionM Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

liftEq :: (a -> b -> Bool) -> UnionM a -> UnionM b -> Bool #

Show1 UnionM Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> UnionM a -> ShowS #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [UnionM a] -> ShowS #

Applicative UnionM Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

pure :: a -> UnionM a #

(<*>) :: UnionM (a -> b) -> UnionM a -> UnionM b #

liftA2 :: (a -> b -> c) -> UnionM a -> UnionM b -> UnionM c #

(*>) :: UnionM a -> UnionM b -> UnionM b #

(<*) :: UnionM a -> UnionM b -> UnionM a #

Functor UnionM Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

fmap :: (a -> b) -> UnionM a -> UnionM b #

(<$) :: a -> UnionM b -> UnionM a #

Monad UnionM Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

(>>=) :: UnionM a -> (a -> UnionM b) -> UnionM b #

(>>) :: UnionM a -> UnionM b -> UnionM b #

return :: a -> UnionM a #

NFData1 UnionM Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

liftRnf :: (a -> ()) -> UnionM a -> () #

Mergeable1 UnionM Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

SimpleMergeable1 UnionM Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

liftMrgIte :: (SymBool -> a -> a -> a) -> SymBool -> UnionM a -> UnionM a -> UnionM a Source #

UnionLike UnionM Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

UnionPrjOp UnionM Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

(GenSym spec a, Mergeable a) => GenSym spec (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

fresh :: MonadFresh m => spec -> m (UnionM (UnionM a)) Source #

GenSym spec a => GenSymSimple spec (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

simpleFresh :: MonadFresh m => spec -> m (UnionM a) Source #

(Solvable c t, Mergeable t) => Solvable c (UnionM t) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

con :: c -> UnionM t Source #

conView :: UnionM t -> Maybe c Source #

ssym :: String -> UnionM t Source #

isym :: String -> Int -> UnionM t Source #

sinfosym :: (Typeable a, Ord a, Lift a, NFData a, Show a, Hashable a) => String -> a -> UnionM t Source #

iinfosym :: (Typeable a, Ord a, Lift a, NFData a, Show a, Hashable a) => String -> Int -> a -> UnionM t Source #

(ToSym a b, Mergeable b) => ToSym a (UnionM b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

toSym :: a -> UnionM b Source #

Lift a => Lift (UnionM a :: Type) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

lift :: Quote m => UnionM a -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => UnionM a -> Code m (UnionM a) #

(IsString a, Mergeable a) => IsString (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

fromString :: String -> UnionM a #

(Num a, Mergeable a) => Num (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

(+) :: UnionM a -> UnionM a -> UnionM a #

(-) :: UnionM a -> UnionM a -> UnionM a #

(*) :: UnionM a -> UnionM a -> UnionM a #

negate :: UnionM a -> UnionM a #

abs :: UnionM a -> UnionM a #

signum :: UnionM a -> UnionM a #

fromInteger :: Integer -> UnionM a #

Show a => Show (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

showsPrec :: Int -> UnionM a -> ShowS #

show :: UnionM a -> String #

showList :: [UnionM a] -> ShowS #

NFData a => NFData (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

rnf :: UnionM a -> () #

Eq a => Eq (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

(==) :: UnionM a -> UnionM a -> Bool #

(/=) :: UnionM a -> UnionM a -> Bool #

(ITEOp a, Mergeable a) => ITEOp (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

ites :: SymBool -> UnionM a -> UnionM a -> UnionM a Source #

(LogicalOp a, Mergeable a) => LogicalOp (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

(||~) :: UnionM a -> UnionM a -> UnionM a Source #

(&&~) :: UnionM a -> UnionM a -> UnionM a Source #

nots :: UnionM a -> UnionM a Source #

xors :: UnionM a -> UnionM a -> UnionM a Source #

implies :: UnionM a -> UnionM a -> UnionM a Source #

SEq a => SEq (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

(==~) :: UnionM a -> UnionM a -> SymBool Source #

(/=~) :: UnionM a -> UnionM a -> SymBool Source #

(Mergeable a, EvaluateSym a) => EvaluateSym (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

evaluateSym :: Bool -> Model -> UnionM a -> UnionM a Source #

ExtractSymbolics a => ExtractSymbolics (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

(Function f, Mergeable f, Mergeable a, Ret f ~ a) => Function (UnionM f) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Associated Types

type Arg (UnionM f) Source #

type Ret (UnionM f) Source #

Methods

(#) :: UnionM f -> Arg (UnionM f) -> Ret (UnionM f) Source #

Mergeable a => Mergeable (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

SOrd a => SOrd (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Mergeable a => SimpleMergeable (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

mrgIte :: SymBool -> UnionM a -> UnionM a -> UnionM a Source #

(Mergeable a, SubstituteSym a) => SubstituteSym (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

substituteSym :: TypedSymbol b -> Sym b -> UnionM a -> UnionM a Source #

Hashable a => Hashable (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

hashWithSalt :: Int -> UnionM a -> Int #

hash :: UnionM a -> Int #

(GenSym a a, Mergeable a) => GenSym (UnionM a) a Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

fresh :: MonadFresh m => UnionM a -> m (UnionM a) Source #

ToCon a b => ToCon (UnionM a) b Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

toCon :: UnionM a -> Maybe b Source #

UnionWithExcept (UnionM (Either e v)) UnionM e v Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

UnionWithExcept (UnionM (CBMCEither e v)) UnionM e v Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

(ToCon a b, Mergeable b) => ToCon (UnionM a) (UnionM b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

toCon :: UnionM a -> Maybe (UnionM b) Source #

(ToSym a b, Mergeable b) => ToSym (UnionM a) (UnionM b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

toSym :: UnionM a -> UnionM b Source #

(IsConcrete k, Mergeable t) => Mergeable (HashMap k (UnionM (Maybe t))) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

(IsConcrete k, Mergeable t) => SimpleMergeable (HashMap k (UnionM (Maybe t))) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

mrgIte :: SymBool -> HashMap k (UnionM (Maybe t)) -> HashMap k (UnionM (Maybe t)) -> HashMap k (UnionM (Maybe t)) Source #

type Arg (UnionM f) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

type Arg (UnionM f) = Arg f
type Ret (UnionM f) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

type Ret (UnionM f) = UnionM (Ret f)

class (Eq t, Ord t, Hashable t) => IsConcrete t Source #

Tag for concrete types. Useful for specifying the merge strategy for some parametrized types where we should have different merge strategy for symbolic and concrete ones.

Instances

Instances details
IsConcrete Integer Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

IsConcrete Bool Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

makeUnionWrapper Source #

Arguments

:: String

Prefix for generated wrappers

-> Name

The type to generate the wrappers for

-> Q [Dec] 

Generate constructor wrappers that wraps the result in a union-like monad.

$(makeUnionWrapper "mrg" ''Maybe)

generates

mrgNothing :: (SymBoolOp bool, Monad u, Mergeable bool t, MonadUnion bool u) => u (Maybe t)
mrgNothing = mrgSingle Nothing
mrgJust :: (SymBoolOp bool, Monad u, Mergeable bool t, MonadUnion bool u) => t -> u (Maybe t)
mrgJust = \x -> mrgSingle (Just x)

makeUnionWrapper' Source #

Arguments

:: [String]

Names for generated wrappers

-> Name

The type to generate the wrappers for

-> Q [Dec] 

Generate constructor wrappers that wraps the result in a union-like monad with provided names.

$(makeUnionWrapper' ["mrgTuple2"] ''(,))

generates

mrgTuple2 :: (SymBoolOp bool, Monad u, Mergeable bool t1, Mergeable bool t2, MonadUnion bool u) => t1 -> t2 -> u (t1, t2)
mrgTuple2 = \v1 v2 -> mrgSingle (v1, v2)

liftToMonadUnion :: (Mergeable a, MonadUnion u) => UnionM a -> u a Source #

Lift the UnionM to any MonadUnion.

Merging

Mergeable

class Mergeable a where Source #

Each type is associated with a root merge strategy given by rootStrategy. The root merge strategy should be able to merge every value of the type. Grisette will use the root merge strategy to merge the values of the type in a union.

Note 1: This type class can be derived for algebraic data types. You may need the DerivingVia and DerivingStrategies extensions.

data X = ... deriving Generic deriving Mergeable via (Default X)

Methods

rootStrategy :: MergingStrategy a Source #

The root merging strategy for the type.

Instances

Instances details
Mergeable Int16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable Int32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable Int64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable Int8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable Word16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable Word32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable Word64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable ByteString Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable Ordering Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable AssertionError Source # 
Instance details

Defined in Grisette.Core.Control.Exception

Mergeable VerificationConditions Source # 
Instance details

Defined in Grisette.Core.Control.Exception

Mergeable CEGISCondition Source # 
Instance details

Defined in Grisette.Core.Data.Class.CEGISSolver

Mergeable FreshIndex Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Mergeable Word8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable Integer Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable () Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable Bool Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable Char Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable Int Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable Word Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable a => Mergeable (Identity a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable a => Mergeable (Sum a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Generic a, Mergeable' (Rep a)) => Mergeable (Default a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable a => Mergeable (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Mergeable a => Mergeable (Union a) Source # 
Instance details

Defined in Grisette.Core.Data.Union

SupportedPrim a => Mergeable (Sym a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable a => Mergeable (Maybe a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable a => Mergeable [a] Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable e, Mergeable a) => Mergeable (Either e a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable (U1 x) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable (V1 x) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable e, Mergeable a) => Mergeable (CBMCEither e a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

(Mergeable a, Mergeable1 m) => Mergeable (FreshT m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

(Mergeable1 m, Mergeable a) => Mergeable (MaybeT m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(IsConcrete k, Mergeable t) => Mergeable (HashMap k (UnionM (Maybe t))) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Mergeable b => Mergeable (a -> b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable a, Mergeable b) => Mergeable (a, b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable1 m, Mergeable e, Mergeable a) => Mergeable (CBMCExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

(Mergeable1 m, Mergeable e, Mergeable a) => Mergeable (ExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable1 m, Mergeable a) => Mergeable (IdentityT m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable a, Mergeable1 m) => Mergeable (ReaderT s m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable s, Mergeable a, Mergeable1 m) => Mergeable (StateT s m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable s, Mergeable a, Mergeable1 m) => Mergeable (StateT s m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable s, Mergeable a, Mergeable1 m) => Mergeable (WriterT s m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable s, Mergeable a, Mergeable1 m) => Mergeable (WriterT s m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable a, Mergeable b, Mergeable c) => Mergeable (a, b, c) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Methods

rootStrategy :: MergingStrategy (a, b, c) Source #

(Mergeable1 l, Mergeable1 r, Mergeable x) => Mergeable (Sum l r x) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable (a x), Mergeable (b x)) => Mergeable ((a :*: b) x) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable (a x), Mergeable (b x)) => Mergeable ((a :+: b) x) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable c => Mergeable (K1 i c x) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable1 m, Mergeable r) => Mergeable (ContT r m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable a, Mergeable b, Mergeable c, Mergeable d) => Mergeable (a, b, c, d) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Methods

rootStrategy :: MergingStrategy (a, b, c, d) Source #

Mergeable (a x) => Mergeable (M1 i c a x) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Methods

rootStrategy :: MergingStrategy (M1 i c a x) Source #

(Mergeable s, Mergeable w, Mergeable a, Mergeable1 m) => Mergeable (RWST r w s m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Methods

rootStrategy :: MergingStrategy (RWST r w s m a) Source #

(Mergeable s, Mergeable w, Mergeable a, Mergeable1 m) => Mergeable (RWST r w s m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Methods

rootStrategy :: MergingStrategy (RWST r w s m a) Source #

(Mergeable a, Mergeable b, Mergeable c, Mergeable d, Mergeable e) => Mergeable (a, b, c, d, e) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Methods

rootStrategy :: MergingStrategy (a, b, c, d, e) Source #

(Mergeable a, Mergeable b, Mergeable c, Mergeable d, Mergeable e, Mergeable f) => Mergeable (a, b, c, d, e, f) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Methods

rootStrategy :: MergingStrategy (a, b, c, d, e, f) Source #

(Mergeable a, Mergeable b, Mergeable c, Mergeable d, Mergeable e, Mergeable f, Mergeable g) => Mergeable (a, b, c, d, e, f, g) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Methods

rootStrategy :: MergingStrategy (a, b, c, d, e, f, g) Source #

(Mergeable a, Mergeable b, Mergeable c, Mergeable d, Mergeable e, Mergeable f, Mergeable g, Mergeable h) => Mergeable (a, b, c, d, e, f, g, h) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Methods

rootStrategy :: MergingStrategy (a, b, c, d, e, f, g, h) Source #

class Mergeable1 (u :: Type -> Type) where Source #

Lifting of the Mergeable class to unary type constructors.

Methods

liftRootStrategy :: MergingStrategy a -> MergingStrategy (u a) Source #

Lift merge strategy through the type constructor.

Instances

Instances details
Mergeable1 Identity Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable1 Sum Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable1 UnionM Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Mergeable1 Union Source # 
Instance details

Defined in Grisette.Core.Data.Union

Mergeable1 Maybe Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable1 [] Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable e => Mergeable1 (Either e) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Generic1 u, Mergeable1' (Rep1 u)) => Mergeable1 (Default1 u) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable e => Mergeable1 (CBMCEither e) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Mergeable1 m => Mergeable1 (FreshT m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Mergeable1 m => Mergeable1 (MaybeT m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable a => Mergeable1 ((,) a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable1 m, Mergeable e) => Mergeable1 (CBMCExceptT e m) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

(Mergeable1 m, Mergeable e) => Mergeable1 (ExceptT e m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable1 m => Mergeable1 (IdentityT m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable1 m => Mergeable1 (ReaderT s m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable s, Mergeable1 m) => Mergeable1 (StateT s m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable s, Mergeable1 m) => Mergeable1 (StateT s m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable s, Mergeable1 m) => Mergeable1 (WriterT s m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable s, Mergeable1 m) => Mergeable1 (WriterT s m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable a, Mergeable b) => Mergeable1 ((,,) a b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable1 l, Mergeable1 r) => Mergeable1 (Sum l r) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable1 m, Mergeable r) => Mergeable1 (ContT r m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable a, Mergeable b, Mergeable c) => Mergeable1 ((,,,) a b c) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable1 ((->) a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable s, Mergeable w, Mergeable1 m) => Mergeable1 (RWST r w s m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable s, Mergeable w, Mergeable1 m) => Mergeable1 (RWST r w s m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(Mergeable a, Mergeable b, Mergeable c, Mergeable d) => Mergeable1 ((,,,,) a b c d) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Methods

liftRootStrategy :: MergingStrategy a0 -> MergingStrategy (a, b, c, d, a0) Source #

(Mergeable a, Mergeable b, Mergeable c, Mergeable d, Mergeable e) => Mergeable1 ((,,,,,) a b c d e) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Methods

liftRootStrategy :: MergingStrategy a0 -> MergingStrategy (a, b, c, d, e, a0) Source #

(Mergeable a, Mergeable b, Mergeable c, Mergeable d, Mergeable e, Mergeable f) => Mergeable1 ((,,,,,,) a b c d e f) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Methods

liftRootStrategy :: MergingStrategy a0 -> MergingStrategy (a, b, c, d, e, f, a0) Source #

(Mergeable a, Mergeable b, Mergeable c, Mergeable d, Mergeable e, Mergeable f, Mergeable g) => Mergeable1 ((,,,,,,,) a b c d e f g) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Methods

liftRootStrategy :: MergingStrategy a0 -> MergingStrategy (a, b, c, d, e, f, g, a0) Source #

rootStrategy1 :: (Mergeable a, Mergeable1 u) => MergingStrategy (u a) Source #

Lift the root merge strategy through the unary type constructor.

class Mergeable2 (u :: Type -> Type -> Type) where Source #

Lifting of the Mergeable class to binary type constructors.

Methods

liftRootStrategy2 :: MergingStrategy a -> MergingStrategy b -> MergingStrategy (u a b) Source #

Lift merge strategy through the type constructor.

rootStrategy2 :: (Mergeable a, Mergeable b, Mergeable2 u) => MergingStrategy (u a b) Source #

Lift the root merge strategy through the binary type constructor.

class Mergeable3 (u :: Type -> Type -> Type -> Type) where Source #

Lifting of the Mergeable class to ternary type constructors.

Methods

liftRootStrategy3 :: MergingStrategy a -> MergingStrategy b -> MergingStrategy c -> MergingStrategy (u a b c) Source #

Lift merge strategy through the type constructor.

Instances

Instances details
Mergeable3 (,,) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

rootStrategy3 :: (Mergeable a, Mergeable b, Mergeable c, Mergeable3 u) => MergingStrategy (u a b c) Source #

Lift the root merge strategy through the binary type constructor.

Merging strategy

data MergingStrategy a where Source #

Merging strategies.

You probably do not need to know the details of this type if you are only going to use algebraic data types. You can get merging strategies for them with type derivation.

In Grisette, a merged union (if-then-else tree) follows the hierarchical sorted representation invariant with regards to some merging strategy.

A merging strategy encodes how to merge a subset of the values of a given type. We have three types of merging strategies:

  • Simple strategy
  • Sorted strategy
  • No strategy

The SimpleStrategy merges values with a simple merge function. For example,

  • the symbolic boolean values can be directly merged with ites.
  • the set {1}, which is a subset of the values of the type Integer, can be simply merged as the set contains only a single value.
  • all the Just values of the type Maybe SymBool can be simply merged by merging the wrapped symbolic boolean with ites.

The SortedStrategy merges values by first grouping the values with an indexing function, and the values with the same index will be organized as a sub-tree in the if-then-else structure of UnionBase. Each group (sub-tree) will be further merged with a sub-strategy for the index. The index type should be a totally ordered type (with the Ord type class). Grisette will use the indexing function to partition the values into sub-trees, and organize them in a sorted way. The sub-trees will further be merged with the sub-strategies. For example,

  • all the integers can be merged with SortedStrategy by indexing with the identity function and use the SimpleStrategy shown before as the sub-strategies.
  • all the Maybe SymBool values can be merged with SortedStrategy by indexing with isJust, the Nothing and Just values can then then be merged with different simple strategies as sub-strategies.

The NoStrategy does not perform any merging. For example, we cannot merge values with function types that returns concrete lists.

For ADTs, we can automatically derive the Mergeable type class, which provides a merging strategy.

If the derived version does not work for you, you should determine if your type can be directly merged with a merging function. If so, you can implement the merging strategy as a SimpleStrategy. If the type cannot be directly merged with a merging function, but could be partitioned into subsets of values that can be simply merged with a function, you should implement the merging strategy as a SortedStrategy. For easier building of the merging strategies, check out the combinators like wrapStrategy.

For more details, please see the documents of the constructors, or refer to Grisette's paper.

Constructors

SimpleStrategy

Simple mergeable strategy.

For symbolic booleans, we can implement its merge strategy as follows:

SimpleStrategy ites :: MergingStrategy SymBool

Fields

SortedStrategy

Sorted mergeable strategy.

For Integers, we can implement its merge strategy as follows:

SortedStrategy id (\_ -> SimpleStrategy $ \_ t _ -> t)

For Maybe SymBool, we can implement its merge strategy as follows:

SortedStrategy
  (\case; Nothing -> False; Just _ -> True)
  (\idx ->
     if idx
       then SimpleStrategy $ \_ t _ -> t
       else SimpleStrategy $ \cond (Just l) (Just r) -> Just $ ites cond l r)

Fields

NoStrategy :: MergingStrategy a

For preventing the merging intentionally. This could be useful for keeping some value concrete and may help generate more efficient formulas.

See Grisette's paper for details.

derivedRootStrategy :: (Generic a, Mergeable' (Rep a)) => MergingStrategy a Source #

Generic derivation for the Mergeable class.

Usually you can derive the merging strategy with the DerivingVia and DerivingStrategies extension.

data X = ... deriving (Generic) deriving Mergeable via (Default X)

Manual merging strategy construction

wrapStrategy Source #

Arguments

:: MergingStrategy a

The merge strategy to be wrapped

-> (a -> b)

The wrap function

-> (b -> a)

The unwrap function, which does not have to be defined for every value

-> MergingStrategy b 

Useful utility function for building merge strategies manually.

For example, to build the merge strategy for the just branch of Maybe a, one could write

wrapStrategy Just fromMaybe rootStrategy :: MergingStrategy (Maybe a)

product2Strategy Source #

Arguments

:: (a -> b -> r)

The wrap function

-> (r -> (a, b))

The unwrap function, which does not have to be defined for every value

-> MergingStrategy a

The first merge strategy to be wrapped

-> MergingStrategy b

The second merge strategy to be wrapped

-> MergingStrategy r 

Useful utility function for building merge strategies for product types manually.

For example, to build the merge strategy for the following product type, one could write

data X = X { x1 :: Int, x2 :: Bool }
product2Strategy X (\(X a b) -> (a, b)) rootStrategy rootStrategy
  :: MergingStrategy X

data DynamicSortedIdx where Source #

Helper type for combining arbitrary number of indices into one. Useful when trying to write efficient merge strategy for lists/vectors.

Constructors

DynamicSortedIdx :: forall idx. (Show idx, Ord idx, Typeable idx) => idx -> DynamicSortedIdx 

data StrategyList container where Source #

Helper type for building efficient merge strategy for list-like containers.

Constructors

StrategyList :: forall bool a container. container [DynamicSortedIdx] -> container (MergingStrategy a) -> StrategyList container 

Instances

Instances details
Show1 container => Show (StrategyList container) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Methods

showsPrec :: Int -> StrategyList container -> ShowS #

show :: StrategyList container -> String #

showList :: [StrategyList container] -> ShowS #

Eq1 container => Eq (StrategyList container) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Methods

(==) :: StrategyList container -> StrategyList container -> Bool #

(/=) :: StrategyList container -> StrategyList container -> Bool #

Ord1 container => Ord (StrategyList container) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Methods

compare :: StrategyList container -> StrategyList container -> Ordering #

(<) :: StrategyList container -> StrategyList container -> Bool #

(<=) :: StrategyList container -> StrategyList container -> Bool #

(>) :: StrategyList container -> StrategyList container -> Bool #

(>=) :: StrategyList container -> StrategyList container -> Bool #

max :: StrategyList container -> StrategyList container -> StrategyList container #

min :: StrategyList container -> StrategyList container -> StrategyList container #

buildStrategyList :: forall bool a container. Functor container => MergingStrategy a -> container a -> StrategyList container Source #

Helper function for building efficient merge strategy for list-like containers.

resolveStrategy :: forall x. MergingStrategy x -> x -> ([DynamicSortedIdx], MergingStrategy x) Source #

Resolves the indices and the terminal merge strategy for a value of some Mergeable type.

resolveStrategy' :: forall x. x -> MergingStrategy x -> ([DynamicSortedIdx], MergingStrategy x) Source #

Resolves the indices and the terminal merge strategy for a value given a merge strategy for its type.

Simple mergeable types

class Mergeable a => SimpleMergeable a where Source #

This class indicates that a type has a simple root merge strategy.

Note: This type class can be derived for algebraic data types. You may need the DerivingVia and DerivingStrategies extensions.

data X = ...
  deriving Generic
  deriving (Mergeable, SimpleMergeable) via (Default X)

Methods

mrgIte :: SymBool -> a -> a -> a Source #

Performs if-then-else with the simple root merge strategy.

>>> mrgIte "a" "b" "c" :: SymInteger
(ite a b c)

Instances

Instances details
SimpleMergeable AssertionError Source # 
Instance details

Defined in Grisette.Core.Control.Exception

SimpleMergeable CEGISCondition Source # 
Instance details

Defined in Grisette.Core.Data.Class.CEGISSolver

SimpleMergeable FreshIndex Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

SimpleMergeable () Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> () -> () -> () Source #

SimpleMergeable a => SimpleMergeable (Identity a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> Identity a -> Identity a -> Identity a Source #

(Generic a, Mergeable' (Rep a), SimpleMergeable' (Rep a)) => SimpleMergeable (Default a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> Default a -> Default a -> Default a Source #

Mergeable a => SimpleMergeable (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

mrgIte :: SymBool -> UnionM a -> UnionM a -> UnionM a Source #

Mergeable a => SimpleMergeable (Union a) Source # 
Instance details

Defined in Grisette.Core.Data.Union

Methods

mrgIte :: SymBool -> Union a -> Union a -> Union a Source #

SupportedPrim a => SimpleMergeable (Sym a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> Sym a -> Sym a -> Sym a Source #

(UnionLike m, Mergeable a) => SimpleMergeable (FreshT m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

mrgIte :: SymBool -> FreshT m a -> FreshT m a -> FreshT m a Source #

(UnionLike m, Mergeable a) => SimpleMergeable (MaybeT m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> MaybeT m a -> MaybeT m a -> MaybeT m a Source #

(IsConcrete k, Mergeable t) => SimpleMergeable (HashMap k (UnionM (Maybe t))) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

mrgIte :: SymBool -> HashMap k (UnionM (Maybe t)) -> HashMap k (UnionM (Maybe t)) -> HashMap k (UnionM (Maybe t)) Source #

SimpleMergeable b => SimpleMergeable (a -> b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> (a -> b) -> (a -> b) -> a -> b Source #

(SimpleMergeable a, SimpleMergeable b) => SimpleMergeable (a, b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> (a, b) -> (a, b) -> (a, b) Source #

(UnionLike m, Mergeable e, Mergeable a) => SimpleMergeable (CBMCExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

mrgIte :: SymBool -> CBMCExceptT e m a -> CBMCExceptT e m a -> CBMCExceptT e m a Source #

(UnionLike m, Mergeable e, Mergeable a) => SimpleMergeable (ExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> ExceptT e m a -> ExceptT e m a -> ExceptT e m a Source #

(UnionLike m, Mergeable a) => SimpleMergeable (IdentityT m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> IdentityT m a -> IdentityT m a -> IdentityT m a Source #

(Mergeable a, UnionLike m) => SimpleMergeable (ReaderT s m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> ReaderT s m a -> ReaderT s m a -> ReaderT s m a Source #

(Mergeable s, Mergeable a, UnionLike m) => SimpleMergeable (StateT s m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> StateT s m a -> StateT s m a -> StateT s m a Source #

(Mergeable s, Mergeable a, UnionLike m) => SimpleMergeable (StateT s m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> StateT s m a -> StateT s m a -> StateT s m a Source #

(Mergeable s, Mergeable a, UnionLike m, Monoid s) => SimpleMergeable (WriterT s m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> WriterT s m a -> WriterT s m a -> WriterT s m a Source #

(Mergeable s, Mergeable a, UnionLike m, Monoid s) => SimpleMergeable (WriterT s m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> WriterT s m a -> WriterT s m a -> WriterT s m a Source #

(SimpleMergeable a, SimpleMergeable b, SimpleMergeable c) => SimpleMergeable (a, b, c) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> (a, b, c) -> (a, b, c) -> (a, b, c) Source #

(UnionLike m, Mergeable r) => SimpleMergeable (ContT r m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> ContT r m a -> ContT r m a -> ContT r m a Source #

(SimpleMergeable a, SimpleMergeable b, SimpleMergeable c, SimpleMergeable d) => SimpleMergeable (a, b, c, d) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d) Source #

(Mergeable s, Mergeable w, Monoid w, Mergeable a, UnionLike m) => SimpleMergeable (RWST r w s m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> RWST r w s m a -> RWST r w s m a -> RWST r w s m a Source #

(Mergeable s, Mergeable w, Monoid w, Mergeable a, UnionLike m) => SimpleMergeable (RWST r w s m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> RWST r w s m a -> RWST r w s m a -> RWST r w s m a Source #

(SimpleMergeable a, SimpleMergeable b, SimpleMergeable c, SimpleMergeable d, SimpleMergeable e) => SimpleMergeable (a, b, c, d, e) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e) Source #

(SimpleMergeable a, SimpleMergeable b, SimpleMergeable c, SimpleMergeable d, SimpleMergeable e, SimpleMergeable f) => SimpleMergeable (a, b, c, d, e, f) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> (a, b, c, d, e, f) Source #

(SimpleMergeable a, SimpleMergeable b, SimpleMergeable c, SimpleMergeable d, SimpleMergeable e, SimpleMergeable f, SimpleMergeable g) => SimpleMergeable (a, b, c, d, e, f, g) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) Source #

(SimpleMergeable a, SimpleMergeable b, SimpleMergeable c, SimpleMergeable d, SimpleMergeable e, SimpleMergeable f, SimpleMergeable g, SimpleMergeable h) => SimpleMergeable (a, b, c, d, e, f, g, h) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) Source #

class SimpleMergeable1 u where Source #

Lifting of the SimpleMergeable class to unary type constructors.

Methods

liftMrgIte :: (SymBool -> a -> a -> a) -> SymBool -> u a -> u a -> u a Source #

Lift mrgIte through the type constructor.

>>> liftMrgIte mrgIte "a" (Identity "b") (Identity "c") :: Identity SymInteger
Identity (ite a b c)

Instances

Instances details
SimpleMergeable1 Identity Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

liftMrgIte :: (SymBool -> a -> a -> a) -> SymBool -> Identity a -> Identity a -> Identity a Source #

SimpleMergeable1 UnionM Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

liftMrgIte :: (SymBool -> a -> a -> a) -> SymBool -> UnionM a -> UnionM a -> UnionM a Source #

SimpleMergeable1 Union Source # 
Instance details

Defined in Grisette.Core.Data.Union

Methods

liftMrgIte :: (SymBool -> a -> a -> a) -> SymBool -> Union a -> Union a -> Union a Source #

UnionLike m => SimpleMergeable1 (FreshT m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

liftMrgIte :: (SymBool -> a -> a -> a) -> SymBool -> FreshT m a -> FreshT m a -> FreshT m a Source #

UnionLike m => SimpleMergeable1 (MaybeT m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

liftMrgIte :: (SymBool -> a -> a -> a) -> SymBool -> MaybeT m a -> MaybeT m a -> MaybeT m a Source #

SimpleMergeable a => SimpleMergeable1 ((,) a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

liftMrgIte :: (SymBool -> a0 -> a0 -> a0) -> SymBool -> (a, a0) -> (a, a0) -> (a, a0) Source #

(UnionLike m, Mergeable e) => SimpleMergeable1 (CBMCExceptT e m) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

liftMrgIte :: (SymBool -> a -> a -> a) -> SymBool -> CBMCExceptT e m a -> CBMCExceptT e m a -> CBMCExceptT e m a Source #

(UnionLike m, Mergeable e) => SimpleMergeable1 (ExceptT e m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

liftMrgIte :: (SymBool -> a -> a -> a) -> SymBool -> ExceptT e m a -> ExceptT e m a -> ExceptT e m a Source #

UnionLike m => SimpleMergeable1 (IdentityT m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

liftMrgIte :: (SymBool -> a -> a -> a) -> SymBool -> IdentityT m a -> IdentityT m a -> IdentityT m a Source #

UnionLike m => SimpleMergeable1 (ReaderT s m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

liftMrgIte :: (SymBool -> a -> a -> a) -> SymBool -> ReaderT s m a -> ReaderT s m a -> ReaderT s m a Source #

(Mergeable s, UnionLike m) => SimpleMergeable1 (StateT s m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

liftMrgIte :: (SymBool -> a -> a -> a) -> SymBool -> StateT s m a -> StateT s m a -> StateT s m a Source #

(Mergeable s, UnionLike m) => SimpleMergeable1 (StateT s m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

liftMrgIte :: (SymBool -> a -> a -> a) -> SymBool -> StateT s m a -> StateT s m a -> StateT s m a Source #

(Mergeable s, UnionLike m, Monoid s) => SimpleMergeable1 (WriterT s m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

liftMrgIte :: (SymBool -> a -> a -> a) -> SymBool -> WriterT s m a -> WriterT s m a -> WriterT s m a Source #

(Mergeable s, UnionLike m, Monoid s) => SimpleMergeable1 (WriterT s m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

liftMrgIte :: (SymBool -> a -> a -> a) -> SymBool -> WriterT s m a -> WriterT s m a -> WriterT s m a Source #

(UnionLike m, Mergeable r) => SimpleMergeable1 (ContT r m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

liftMrgIte :: (SymBool -> a -> a -> a) -> SymBool -> ContT r m a -> ContT r m a -> ContT r m a Source #

SimpleMergeable1 ((->) a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

liftMrgIte :: (SymBool -> a0 -> a0 -> a0) -> SymBool -> (a -> a0) -> (a -> a0) -> a -> a0 Source #

(Mergeable s, Mergeable w, Monoid w, UnionLike m) => SimpleMergeable1 (RWST r w s m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

liftMrgIte :: (SymBool -> a -> a -> a) -> SymBool -> RWST r w s m a -> RWST r w s m a -> RWST r w s m a Source #

(Mergeable s, Mergeable w, Monoid w, UnionLike m) => SimpleMergeable1 (RWST r w s m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

liftMrgIte :: (SymBool -> a -> a -> a) -> SymBool -> RWST r w s m a -> RWST r w s m a -> RWST r w s m a Source #

mrgIte1 :: (SimpleMergeable1 u, SimpleMergeable a) => SymBool -> u a -> u a -> u a Source #

Lift the standard mrgIte function through the type constructor.

>>> mrgIte1 "a" (Identity "b") (Identity "c") :: Identity SymInteger
Identity (ite a b c)

class Mergeable2 u => SimpleMergeable2 u where Source #

Lifting of the SimpleMergeable class to binary type constructors.

Methods

liftMrgIte2 :: (SymBool -> a -> a -> a) -> (SymBool -> b -> b -> b) -> SymBool -> u a b -> u a b -> u a b Source #

Lift mrgIte through the type constructor.

>>> liftMrgIte2 mrgIte mrgIte "a" ("b", "c") ("d", "e") :: (SymInteger, SymBool)
((ite a b d),(ite a c e))

Instances

Instances details
SimpleMergeable2 (,) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

liftMrgIte2 :: (SymBool -> a -> a -> a) -> (SymBool -> b -> b -> b) -> SymBool -> (a, b) -> (a, b) -> (a, b) Source #

mrgIte2 :: (SimpleMergeable2 u, SimpleMergeable a, SimpleMergeable b) => SymBool -> u a b -> u a b -> u a b Source #

Lift the standard mrgIte function through the type constructor.

>>> mrgIte2 "a" ("b", "c") ("d", "e") :: (SymInteger, SymBool)
((ite a b d),(ite a c e))

UnionLike operations

class (SimpleMergeable1 u, Mergeable1 u) => UnionLike u where Source #

Special case of the Mergeable1 and SimpleMergeable1 class for type constructors that are SimpleMergeable when applied to any Mergeable types.

This type class is used to generalize the mrgIf function to other containers, for example, monad transformer transformed Unions.

Minimal complete definition

single, unionIf, mergeWithStrategy

Methods

single :: a -> u a Source #

Wrap a single value in the union.

Note that this function cannot propagate the Mergeable knowledge.

>>> single "a" :: UnionM SymInteger
<a>
>>> mrgSingle "a" :: UnionM SymInteger
{a}

unionIf :: SymBool -> u a -> u a -> u a Source #

If-then-else on two union values.

Note that this function cannot capture the Mergeable knowledge. However, it may use the merging strategy from the branches to merge the results.

>>> unionIf "a" (single "b") (single "c") :: UnionM SymInteger
<If a b c>
>>> unionIf "a" (mrgSingle "b") (single "c") :: UnionM SymInteger
{(ite a b c)}

mergeWithStrategy :: MergingStrategy a -> u a -> u a Source #

Merge the contents with some merge strategy.

>>> mergeWithStrategy rootStrategy $ unionIf "a" (single "b") (single "c") :: UnionM SymInteger
{(ite a b c)}

Note: Be careful to call this directly in your code. The supplied merge strategy should be consistent with the type's root merge strategy, or some internal invariants would be broken and the program can crash.

This function is to be called when the Mergeable constraint can not be resolved, e.g., the merge strategy for the contained type is given with Mergeable1. In other cases, merge is usually a better alternative.

mrgIfWithStrategy :: MergingStrategy a -> SymBool -> u a -> u a -> u a Source #

Symbolic if control flow with the result merged with some merge strategy.

>>> mrgIfWithStrategy rootStrategy "a" (mrgSingle "b") (single "c") :: UnionM SymInteger
{(ite a b c)}

Note: Be careful to call this directly in your code. The supplied merge strategy should be consistent with the type's root merge strategy, or some internal invariants would be broken and the program can crash.

This function is to be called when the Mergeable constraint can not be resolved, e.g., the merge strategy for the contained type is given with Mergeable1. In other cases, mrgIf is usually a better alternative.

mrgSingleWithStrategy :: MergingStrategy a -> a -> u a Source #

Wrap a single value in the union and capture the Mergeable knowledge.

>>> mrgSingleWithStrategy rootStrategy "a" :: UnionM SymInteger
{a}

Note: Be careful to call this directly in your code. The supplied merge strategy should be consistent with the type's root merge strategy, or some internal invariants would be broken and the program can crash.

This function is to be called when the Mergeable constraint can not be resolved, e.g., the merge strategy for the contained type is given with Mergeable1. In other cases, mrgSingle is usually a better alternative.

Instances

Instances details
UnionLike UnionM Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

UnionLike Union Source # 
Instance details

Defined in Grisette.Core.Data.Union

UnionLike m => UnionLike (FreshT m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

UnionLike m => UnionLike (MaybeT m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

(UnionLike m, Mergeable e) => UnionLike (CBMCExceptT e m) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

(UnionLike m, Mergeable e) => UnionLike (ExceptT e m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

UnionLike m => UnionLike (IdentityT m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

UnionLike m => UnionLike (ReaderT s m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

(Mergeable s, UnionLike m) => UnionLike (StateT s m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

single :: a -> StateT s m a Source #

unionIf :: SymBool -> StateT s m a -> StateT s m a -> StateT s m a Source #

mergeWithStrategy :: MergingStrategy a -> StateT s m a -> StateT s m a Source #

mrgIfWithStrategy :: MergingStrategy a -> SymBool -> StateT s m a -> StateT s m a -> StateT s m a Source #

mrgSingleWithStrategy :: MergingStrategy a -> a -> StateT s m a Source #

(Mergeable s, UnionLike m) => UnionLike (StateT s m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

single :: a -> StateT s m a Source #

unionIf :: SymBool -> StateT s m a -> StateT s m a -> StateT s m a Source #

mergeWithStrategy :: MergingStrategy a -> StateT s m a -> StateT s m a Source #

mrgIfWithStrategy :: MergingStrategy a -> SymBool -> StateT s m a -> StateT s m a -> StateT s m a Source #

mrgSingleWithStrategy :: MergingStrategy a -> a -> StateT s m a Source #

(Mergeable s, UnionLike m, Monoid s) => UnionLike (WriterT s m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

(Mergeable s, UnionLike m, Monoid s) => UnionLike (WriterT s m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

(UnionLike m, Mergeable r) => UnionLike (ContT r m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

single :: a -> ContT r m a Source #

unionIf :: SymBool -> ContT r m a -> ContT r m a -> ContT r m a Source #

mergeWithStrategy :: MergingStrategy a -> ContT r m a -> ContT r m a Source #

mrgIfWithStrategy :: MergingStrategy a -> SymBool -> ContT r m a -> ContT r m a -> ContT r m a Source #

mrgSingleWithStrategy :: MergingStrategy a -> a -> ContT r m a Source #

(Mergeable s, Mergeable w, Monoid w, UnionLike m) => UnionLike (RWST r w s m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

single :: a -> RWST r w s m a Source #

unionIf :: SymBool -> RWST r w s m a -> RWST r w s m a -> RWST r w s m a Source #

mergeWithStrategy :: MergingStrategy a -> RWST r w s m a -> RWST r w s m a Source #

mrgIfWithStrategy :: MergingStrategy a -> SymBool -> RWST r w s m a -> RWST r w s m a -> RWST r w s m a Source #

mrgSingleWithStrategy :: MergingStrategy a -> a -> RWST r w s m a Source #

(Mergeable s, Mergeable w, Monoid w, UnionLike m) => UnionLike (RWST r w s m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

single :: a -> RWST r w s m a Source #

unionIf :: SymBool -> RWST r w s m a -> RWST r w s m a -> RWST r w s m a Source #

mergeWithStrategy :: MergingStrategy a -> RWST r w s m a -> RWST r w s m a Source #

mrgIfWithStrategy :: MergingStrategy a -> SymBool -> RWST r w s m a -> RWST r w s m a -> RWST r w s m a Source #

mrgSingleWithStrategy :: MergingStrategy a -> a -> RWST r w s m a Source #

mrgIf :: (UnionLike u, Mergeable a) => SymBool -> u a -> u a -> u a Source #

Symbolic if control flow with the result merged with the type's root merge strategy.

Equivalent to mrgIfWithStrategy rootStrategy.

>>> mrgIf "a" (single "b") (single "c") :: UnionM SymInteger
{(ite a b c)}

merge :: (UnionLike u, Mergeable a) => u a -> u a Source #

Merge the contents with the type's root merge strategy.

Equivalent to mergeWithStrategy rootStrategy.

>>> merge $ unionIf "a" (single "b") (single "c") :: UnionM SymInteger
{(ite a b c)}

mrgSingle :: (UnionLike u, Mergeable a) => a -> u a Source #

Wrap a single value in the type and propagate the type's root merge strategy.

Equivalent to mrgSingleWithStrategy rootStrategy.

>>> mrgSingle "a" :: UnionM SymInteger
{a}

class UnionLike u => UnionPrjOp (u :: Type -> Type) where Source #

Union containers that can be projected back into single value or if-guarded values.

Methods

singleView :: u a -> Maybe a Source #

Pattern match to extract single values.

>>> singleView (single 1 :: UnionM Integer)
Just 1
>>> singleView (unionIf "a" (single 1) (single 2) :: UnionM Integer)
Nothing

ifView :: u a -> Maybe (SymBool, u a, u a) Source #

Pattern match to extract if values.

>>> ifView (single 1 :: UnionM Integer)
Nothing
>>> ifView (unionIf "a" (single 1) (single 2) :: UnionM Integer)
Just (a,<1>,<2>)
>>> ifView (mrgIf "a" (single 1) (single 2) :: UnionM Integer)
Just (a,{1},{2})

leftMost :: u a -> a Source #

The leftmost value in the union.

>>> leftMost (unionIf "a" (single 1) (single 2) :: UnionM Integer)
1

Instances

Instances details
UnionPrjOp UnionM Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

UnionPrjOp Union Source # 
Instance details

Defined in Grisette.Core.Data.Union

pattern SingleU :: UnionPrjOp u => a -> u a Source #

Pattern match to extract single values with singleView.

>>> case (single 1 :: UnionM Integer) of SingleU v -> v
1

pattern IfU :: UnionPrjOp u => SymBool -> u a -> u a -> u a Source #

Pattern match to extract guard values with ifView >>> case (unionIf "a" (single 1) (single 2) :: UnionM Integer) of IfU c t f -> (c,t,f) (a,1,2)

type MonadUnion u = (UnionLike u, Monad u) Source #

Class for monads that support union-like operations and Mergeable knowledge propagation.

simpleMerge :: forall bool u a. (SimpleMergeable a, UnionLike u, UnionPrjOp u) => u a -> a Source #

Merge the simply mergeable values in a union, and extract the merged value.

In the following example, unionIf will not merge the results, and simpleMerge will merge it and extract the single merged value.

>>> unionIf (ssym "a") (return $ ssym "b") (return $ ssym "c") :: UnionM SymBool
<If a b c>
>>> simpleMerge $ (unionIf (ssym "a") (return $ ssym "b") (return $ ssym "c") :: UnionM SymBool)
(ite a b c)

onUnion :: forall bool u a r. (SimpleMergeable r, UnionLike u, UnionPrjOp u, Monad u) => (a -> r) -> u a -> r Source #

Lift a function to work on union values.

>>> sumU = onUnion sum
>>> sumU (unionIf "cond" (return ["a"]) (return ["b","c"]) :: UnionM [SymInteger])
(ite cond a (+ b c))

onUnion2 :: forall bool u a b r. (SimpleMergeable r, UnionLike u, UnionPrjOp u, Monad u) => (a -> b -> r) -> u a -> u b -> r Source #

Lift a function to work on union values.

onUnion3 :: forall bool u a b c r. (SimpleMergeable r, UnionLike u, UnionPrjOp u, Monad u) => (a -> b -> c -> r) -> u a -> u b -> u c -> r Source #

Lift a function to work on union values.

onUnion4 :: forall bool u a b c d r. (SimpleMergeable r, UnionLike u, UnionPrjOp u, Monad u) => (a -> b -> c -> d -> r) -> u a -> u b -> u c -> u d -> r Source #

Lift a function to work on union values.

(#~) :: (Function f, SimpleMergeable (Ret f), UnionPrjOp u, Functor u) => f -> u (Arg f) -> Ret f infixl 9 Source #

Helper for applying functions on UnionPrjOp and SimpleMergeable.

>>> let f :: Integer -> UnionM Integer = \x -> mrgIf (ssym "a") (mrgSingle $ x + 1) (mrgSingle $ x + 2)
>>> f #~ (mrgIf (ssym "b" :: SymBool) (mrgSingle 0) (mrgSingle 2) :: UnionM Integer)
{If (&& b a) 1 (If b 2 (If a 3 4))}

Conversion between Concrete and Symbolic values

class ToCon a b where Source #

Convert a symbolic value to concrete value if possible.

Methods

toCon :: a -> Maybe b Source #

Convert a symbolic value to concrete value if possible. If the symbolic value cannot be converted to concrete, the result will be Nothing.

>>> toCon (ssym "a" :: SymInteger) :: Maybe Integer
Nothing
>>> toCon (con 1 :: SymInteger) :: Maybe Integer
Just 1

toCon works on complex types too.

>>> toCon ([con 1, con 2] :: [SymInteger]) :: Maybe [Integer]
Just [1,2]
>>> toCon ([con 1, ssym "a"] :: [SymInteger]) :: Maybe [Integer]
Nothing

Instances

Instances details
ToCon Int16 Int16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: Int16 -> Maybe Int16 Source #

ToCon Int32 Int32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: Int32 -> Maybe Int32 Source #

ToCon Int64 Int64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: Int64 -> Maybe Int64 Source #

ToCon Int8 Int8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: Int8 -> Maybe Int8 Source #

ToCon Word16 Word16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

ToCon Word32 Word32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

ToCon Word64 Word64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

ToCon ByteString ByteString Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

ToCon AssertionError AssertionError Source # 
Instance details

Defined in Grisette.Core.Control.Exception

ToCon VerificationConditions VerificationConditions Source # 
Instance details

Defined in Grisette.Core.Control.Exception

ToCon Word8 Word8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: Word8 -> Maybe Word8 Source #

ToCon Integer Integer Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

ToCon () () Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: () -> Maybe () Source #

ToCon Bool Bool Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: Bool -> Maybe Bool Source #

ToCon Char Char Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: Char -> Maybe Char Source #

ToCon Int Int Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: Int -> Maybe Int Source #

ToCon Word Word Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: Word -> Maybe Word Source #

(Generic a, Generic b, ToCon' (Rep a) (Rep b)) => ToCon a (Default b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: a -> Maybe (Default b) Source #

ToCon v (Identity v) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: v -> Maybe (Identity v) Source #

ToCon (Identity v) v Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: Identity v -> Maybe v Source #

ToCon a b => ToCon (UnionM a) b Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

toCon :: UnionM a -> Maybe b Source #

ToCon (Sym (IntN 8)) Int8 Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: Sym (IntN 8) -> Maybe Int8 Source #

ToCon (Sym (IntN 16)) Int16 Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: Sym (IntN 16) -> Maybe Int16 Source #

ToCon (Sym (IntN 32)) Int32 Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: Sym (IntN 32) -> Maybe Int32 Source #

ToCon (Sym (IntN 64)) Int64 Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: Sym (IntN 64) -> Maybe Int64 Source #

ToCon (Sym (IntN 64)) Int Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: Sym (IntN 64) -> Maybe Int Source #

ToCon (Sym (WordN 8)) Word8 Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: Sym (WordN 8) -> Maybe Word8 Source #

ToCon (Sym (WordN 16)) Word16 Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: Sym (WordN 16) -> Maybe Word16 Source #

ToCon (Sym (WordN 32)) Word32 Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: Sym (WordN 32) -> Maybe Word32 Source #

ToCon (Sym (WordN 64)) Word64 Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: Sym (WordN 64) -> Maybe Word64 Source #

ToCon (Sym (WordN 64)) Word Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: Sym (WordN 64) -> Maybe Word Source #

SupportedPrim a => ToCon (Sym a) a Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: Sym a -> Maybe a Source #

ToCon a b => ToCon (Identity a) (Identity b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: Identity a -> Maybe (Identity b) Source #

(ToCon a b, Mergeable b) => ToCon (UnionM a) (UnionM b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

toCon :: UnionM a -> Maybe (UnionM b) Source #

SupportedPrim a => ToCon (Sym a) (Sym a) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: Sym a -> Maybe (Sym a) Source #

ToCon a1 a2 => ToCon (Maybe a1) (Maybe a2) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: Maybe a1 -> Maybe (Maybe a2) Source #

ToCon a b => ToCon [a] [b] Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: [a] -> Maybe [b] Source #

(ToCon e1 e2, ToCon a1 a2) => ToCon (Either e1 a1) (Either e2 a2) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: Either e1 a1 -> Maybe (Either e2 a2) Source #

(ToCon e1 e2, ToCon a1 a2) => ToCon (Either e1 a1) (CBMCEither e2 a2) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

toCon :: Either e1 a1 -> Maybe (CBMCEither e2 a2) Source #

(ToCon e1 e2, ToCon a1 a2) => ToCon (CBMCEither e1 a1) (Either e2 a2) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

toCon :: CBMCEither e1 a1 -> Maybe (Either e2 a2) Source #

(ToCon e1 e2, ToCon a1 a2) => ToCon (CBMCEither e1 a1) (CBMCEither e2 a2) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

toCon :: CBMCEither e1 a1 -> Maybe (CBMCEither e2 a2) Source #

ToCon (m1 (Maybe a)) (m2 (Maybe b)) => ToCon (MaybeT m1 a) (MaybeT m2 b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: MaybeT m1 a -> Maybe (MaybeT m2 b) Source #

(ToCon a1 a2, ToCon b1 b2) => ToCon (a1, b1) (a2, b2) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: (a1, b1) -> Maybe (a2, b2) Source #

ToCon (m1 (CBMCEither e1 a)) (Either e2 b) => ToCon (CBMCExceptT e1 m1 a) (Either e2 b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

toCon :: CBMCExceptT e1 m1 a -> Maybe (Either e2 b) Source #

ToCon (m1 (Either e1 a)) (Either e2 b) => ToCon (ExceptT e1 m1 a) (Either e2 b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: ExceptT e1 m1 a -> Maybe (Either e2 b) Source #

ToCon (m1 (CBMCEither e1 a)) (m2 (CBMCEither e2 b)) => ToCon (CBMCExceptT e1 m1 a) (CBMCExceptT e2 m2 b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

toCon :: CBMCExceptT e1 m1 a -> Maybe (CBMCExceptT e2 m2 b) Source #

ToCon (m1 (Either e1 a)) (m2 (Either e2 b)) => ToCon (ExceptT e1 m1 a) (ExceptT e2 m2 b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: ExceptT e1 m1 a -> Maybe (ExceptT e2 m2 b) Source #

ToCon (m a) (m1 b) => ToCon (IdentityT m a) (IdentityT m1 b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: IdentityT m a -> Maybe (IdentityT m1 b) Source #

ToCon (m1 (a, s1)) (m2 (b, s2)) => ToCon (WriterT s1 m1 a) (WriterT s2 m2 b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: WriterT s1 m1 a -> Maybe (WriterT s2 m2 b) Source #

ToCon (m1 (a, s1)) (m2 (b, s2)) => ToCon (WriterT s1 m1 a) (WriterT s2 m2 b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: WriterT s1 m1 a -> Maybe (WriterT s2 m2 b) Source #

(ToCon a1 a2, ToCon b1 b2, ToCon c1 c2) => ToCon (a1, b1, c1) (a2, b2, c2) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: (a1, b1, c1) -> Maybe (a2, b2, c2) Source #

(ToCon (f a) (f1 a1), ToCon (g a) (g1 a1)) => ToCon (Sum f g a) (Sum f1 g1 a1) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: Sum f g a -> Maybe (Sum f1 g1 a1) Source #

(ToCon a1 a2, ToCon b1 b2, ToCon c1 c2, ToCon d1 d2) => ToCon (a1, b1, c1, d1) (a2, b2, c2, d2) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: (a1, b1, c1, d1) -> Maybe (a2, b2, c2, d2) Source #

(ToCon a1 a2, ToCon b1 b2, ToCon c1 c2, ToCon d1 d2, ToCon e1 e2) => ToCon (a1, b1, c1, d1, e1) (a2, b2, c2, d2, e2) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: (a1, b1, c1, d1, e1) -> Maybe (a2, b2, c2, d2, e2) Source #

(ToCon a1 a2, ToCon b1 b2, ToCon c1 c2, ToCon d1 d2, ToCon e1 e2, ToCon f1 f2) => ToCon (a1, b1, c1, d1, e1, f1) (a2, b2, c2, d2, e2, f2) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: (a1, b1, c1, d1, e1, f1) -> Maybe (a2, b2, c2, d2, e2, f2) Source #

(ToCon a1 a2, ToCon b1 b2, ToCon c1 c2, ToCon d1 d2, ToCon e1 e2, ToCon f1 f2, ToCon g1 g2) => ToCon (a1, b1, c1, d1, e1, f1, g1) (a2, b2, c2, d2, e2, f2, g2) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: (a1, b1, c1, d1, e1, f1, g1) -> Maybe (a2, b2, c2, d2, e2, f2, g2) Source #

(ToCon a1 a2, ToCon b1 b2, ToCon c1 c2, ToCon d1 d2, ToCon e1 e2, ToCon f1 f2, ToCon g1 g2, ToCon h1 h2) => ToCon (a1, b1, c1, d1, e1, f1, g1, h1) (a2, b2, c2, d2, e2, f2, g2, h2) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: (a1, b1, c1, d1, e1, f1, g1, h1) -> Maybe (a2, b2, c2, d2, e2, f2, g2, h2) Source #

class ToSym a b where Source #

Convert a concrete value to symbolic value.

Methods

toSym :: a -> b Source #

Convert a concrete value to symbolic value.

>>> toSym False :: SymBool
false
>>> toSym [False, True] :: [SymBool]
[false,true]

Instances

Instances details
ToSym Int16 Int16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: Int16 -> Int16 Source #

ToSym Int32 Int32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: Int32 -> Int32 Source #

ToSym Int64 Int64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: Int64 -> Int64 Source #

ToSym Int8 Int8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: Int8 -> Int8 Source #

ToSym Word16 Word16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: Word16 -> Word16 Source #

ToSym Word32 Word32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: Word32 -> Word32 Source #

ToSym Word64 Word64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: Word64 -> Word64 Source #

ToSym ByteString ByteString Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

ToSym AssertionError AssertionError Source # 
Instance details

Defined in Grisette.Core.Control.Exception

ToSym VerificationConditions VerificationConditions Source # 
Instance details

Defined in Grisette.Core.Control.Exception

ToSym Word8 Word8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: Word8 -> Word8 Source #

ToSym Integer Integer Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

ToSym () () Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: () -> () Source #

ToSym Bool Bool Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: Bool -> Bool Source #

ToSym Char Char Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: Char -> Char Source #

ToSym Int Int Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: Int -> Int Source #

ToSym Word Word Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: Word -> Word Source #

ToSym Int16 (Sym (IntN 16)) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: Int16 -> Sym (IntN 16) Source #

ToSym Int32 (Sym (IntN 32)) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: Int32 -> Sym (IntN 32) Source #

ToSym Int64 (Sym (IntN 64)) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: Int64 -> Sym (IntN 64) Source #

ToSym Int8 (Sym (IntN 8)) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: Int8 -> Sym (IntN 8) Source #

ToSym Word16 (Sym (WordN 16)) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: Word16 -> Sym (WordN 16) Source #

ToSym Word32 (Sym (WordN 32)) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: Word32 -> Sym (WordN 32) Source #

ToSym Word64 (Sym (WordN 64)) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: Word64 -> Sym (WordN 64) Source #

ToSym Word8 (Sym (WordN 8)) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: Word8 -> Sym (WordN 8) Source #

ToSym Int (Sym (IntN 64)) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: Int -> Sym (IntN 64) Source #

ToSym Word (Sym (WordN 64)) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: Word -> Sym (WordN 64) Source #

(Generic a, Generic b, ToSym' (Rep a) (Rep b)) => ToSym a (Default b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: a -> Default b Source #

(ToSym a b, Mergeable b) => ToSym a (UnionM b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

toSym :: a -> UnionM b Source #

SupportedPrim a => ToSym a (Sym a) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: a -> Sym a Source #

ToSym a b => ToSym (Identity a) (Identity b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: Identity a -> Identity b Source #

(ToSym a b, Mergeable b) => ToSym (UnionM a) (UnionM b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

toSym :: UnionM a -> UnionM b Source #

SupportedPrim a => ToSym (Sym a) (Sym a) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: Sym a -> Sym a Source #

ToSym a b => ToSym (Maybe a) (Maybe b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: Maybe a -> Maybe b Source #

ToSym a b => ToSym [a] [b] Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: [a] -> [b] Source #

(ToSym e1 e2, ToSym a1 a2) => ToSym (Either e1 a1) (Either e2 a2) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: Either e1 a1 -> Either e2 a2 Source #

(ToSym e1 e2, ToSym a1 a2) => ToSym (Either e1 a1) (CBMCEither e2 a2) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

toSym :: Either e1 a1 -> CBMCEither e2 a2 Source #

(ToSym e1 e2, ToSym a1 a2) => ToSym (CBMCEither e1 a1) (Either e2 a2) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

toSym :: CBMCEither e1 a1 -> Either e2 a2 Source #

(ToSym e1 e2, ToSym a1 a2) => ToSym (CBMCEither e1 a1) (CBMCEither e2 a2) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

toSym :: CBMCEither e1 a1 -> CBMCEither e2 a2 Source #

ToSym (m1 (Maybe a)) (m2 (Maybe b)) => ToSym (MaybeT m1 a) (MaybeT m2 b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: MaybeT m1 a -> MaybeT m2 b Source #

ToSym a b => ToSym (v -> a) (v -> b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: (v -> a) -> v -> b Source #

(ToSym a1 b1, ToSym a2 b2) => ToSym (a1, a2) (b1, b2) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: (a1, a2) -> (b1, b2) Source #

ToSym (m1 (CBMCEither e1 a)) (m2 (CBMCEither e2 b)) => ToSym (CBMCExceptT e1 m1 a) (CBMCExceptT e2 m2 b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

toSym :: CBMCExceptT e1 m1 a -> CBMCExceptT e2 m2 b Source #

ToSym (m1 (Either e1 a)) (m2 (Either e2 b)) => ToSym (ExceptT e1 m1 a) (ExceptT e2 m2 b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: ExceptT e1 m1 a -> ExceptT e2 m2 b Source #

ToSym (m a) (m1 b) => ToSym (IdentityT m a) (IdentityT m1 b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: IdentityT m a -> IdentityT m1 b Source #

ToSym (s1 -> m1 a1) (s2 -> m2 a2) => ToSym (ReaderT s1 m1 a1) (ReaderT s2 m2 a2) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: ReaderT s1 m1 a1 -> ReaderT s2 m2 a2 Source #

ToSym (s1 -> m1 (a1, s1)) (s2 -> m2 (a2, s2)) => ToSym (StateT s1 m1 a1) (StateT s2 m2 a2) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: StateT s1 m1 a1 -> StateT s2 m2 a2 Source #

ToSym (s1 -> m1 (a1, s1)) (s2 -> m2 (a2, s2)) => ToSym (StateT s1 m1 a1) (StateT s2 m2 a2) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: StateT s1 m1 a1 -> StateT s2 m2 a2 Source #

ToSym (m1 (a1, s1)) (m2 (a2, s2)) => ToSym (WriterT s1 m1 a1) (WriterT s2 m2 a2) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: WriterT s1 m1 a1 -> WriterT s2 m2 a2 Source #

ToSym (m1 (a1, s1)) (m2 (a2, s2)) => ToSym (WriterT s1 m1 a1) (WriterT s2 m2 a2) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: WriterT s1 m1 a1 -> WriterT s2 m2 a2 Source #

(ToSym a1 b1, ToSym a2 b2, ToSym a3 b3) => ToSym (a1, a2, a3) (b1, b2, b3) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: (a1, a2, a3) -> (b1, b2, b3) Source #

(ToSym (f a) (f1 a1), ToSym (g a) (g1 a1)) => ToSym (Sum f g a) (Sum f1 g1 a1) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: Sum f g a -> Sum f1 g1 a1 Source #

(ToSym a1 a2, ToSym b1 b2, ToSym c1 c2, ToSym d1 d2) => ToSym (a1, b1, c1, d1) (a2, b2, c2, d2) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: (a1, b1, c1, d1) -> (a2, b2, c2, d2) Source #

(ToSym a1 a2, ToSym b1 b2, ToSym c1 c2, ToSym d1 d2, ToSym e1 e2) => ToSym (a1, b1, c1, d1, e1) (a2, b2, c2, d2, e2) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: (a1, b1, c1, d1, e1) -> (a2, b2, c2, d2, e2) Source #

(ToSym a1 a2, ToSym b1 b2, ToSym c1 c2, ToSym d1 d2, ToSym e1 e2, ToSym f1 f2) => ToSym (a1, b1, c1, d1, e1, f1) (a2, b2, c2, d2, e2, f2) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: (a1, b1, c1, d1, e1, f1) -> (a2, b2, c2, d2, e2, f2) Source #

(ToSym a1 a2, ToSym b1 b2, ToSym c1 c2, ToSym d1 d2, ToSym e1 e2, ToSym f1 f2, ToSym g1 g2) => ToSym (a1, b1, c1, d1, e1, f1, g1) (a2, b2, c2, d2, e2, f2, g2) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: (a1, b1, c1, d1, e1, f1, g1) -> (a2, b2, c2, d2, e2, f2, g2) Source #

(ToSym a1 a2, ToSym b1 b2, ToSym c1 c2, ToSym d1 d2, ToSym e1 e2, ToSym f1 f2, ToSym g1 g2, ToSym h1 h2) => ToSym (a1, b1, c1, d1, e1, f1, g1, h1) (a2, b2, c2, d2, e2, f2, g2, h2) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: (a1, b1, c1, d1, e1, f1, g1, h1) -> (a2, b2, c2, d2, e2, f2, g2, h2) Source #

Symbolic Generation

It is usually useful to generate complex symbolic values. For example, in program synthesis task, we may want to generate symbolic programs to represent the search space given some specification.

To help with this, we provide a set of classes and functions. The core of the symbolic generation is the Fresh monad, the GenSymSimple class, and the GenSym class.

The Fresh monad is a combination of specialized state and reader monads. It keeps an identifier, and an index. The generated symbolic constants would be constructed with both the identifier and the index. Each time a new symbolic constant is generated, the index would be incremented. This keeps that the generated symbolic constants are unique.

The GenSymSimple class helps generate symbolic values that do not require a symbolic union, for example, symbolic Booleans. It provides the simpleFresh function, which accepts a specification for the symbolic values to generate.

We do not need any specification to generate a symbolic Boolean, so we provide a unit value as the specification:

>>> runFresh (simpleFresh ()) "x" :: SymBool
x@0

We can generate a list of symbolic Booleans by specifying the length of the list, and the specification for the elements. The two elements in the generated list are unique as they have different indices.

>>> runFresh (simpleFresh (SimpleListSpec 2 ())) "x" :: [SymBool]
[x@0,x@1]
>>> runFresh (simpleFresh (SimpleListSpec 2 (SimpleListSpec 1 ()))) "x" :: [[SymBool]]
[[x@0],[x@1]]

The GenSym class helps generate symbolic values that require a symbolic union, for example, lists with different lengths. It provides the fresh function, which accepts a specification for the symbolic values to generate.

We can generate a list of length 0, 1, or 2 by specifying the minimum and maximum lengths, and the specification for the elements:

>>> runFresh (fresh (ListSpec 0 2 ())) "x" :: UnionM [SymBool]
{If x@2 [] (If x@3 [x@1] [x@0,x@1])}

We can generate many symbolic values at once with the Fresh monad. The symbolic constants are ensured to be unique:

>>> :set -XScopedTypeVariables
>>> :{
  flip runFresh "x" $ do
    a :: SymBool <- simpleFresh ()
    b :: UnionM [SymBool] <- fresh (ListSpec 0 2 ())
    return (a, b)
:}
(x@0,{If x@3 [] (If x@4 [x@2] [x@1,x@2])})

When you are just generating a symbolic value, and do not need to compose multiple simpleFresh or fresh calls, you can use the genSym and genSymSimple functions instead.

>>> genSymSimple (SimpleListSpec 2 ()) "x" :: [SymBool]
[x@0,x@1]
>>> genSym (ListSpec 0 2 ()) "x" :: UnionM [SymBool]
{If x@2 [] (If x@3 [x@1] [x@0,x@1])}

Symbolic choices from a list of symbolic values is very useful. With the chooseFresh function, we can generate a symbolic value by choosing from a list of alternative values. Grisette would generate symbolic Boolean guards to perform the symbolic choice.

>>> :{
  (flip runFresh "x" $ do
    a <- simpleFresh ()
    b <- simpleFresh ()
    chooseFresh [[a],[a,b],[a,a,b]]) :: UnionM [SymBool]
:}
{If x@2 [x@0] (If x@3 [x@0,x@1] [x@0,x@0,x@1])}

Symbolic Generation Context

newtype FreshIndex Source #

Index type used for GenSym.

To generate fresh variables, a monadic stateful context will be maintained. The index should be increased every time a new symbolic constant is generated.

Constructors

FreshIndex Int 

data FreshIdent where Source #

Identifier type used for GenSym

The constructor is hidden intentionally. You can construct an identifier by:

  • a raw name

The following two expressions will refer to the same identifier (the solver won't distinguish them and would assign the same value to them). The user may need to use unique names to avoid unintentional identifier collision.

>>> name "a"
a
>>> "a" :: FreshIdent -- available when OverloadedStrings is enabled
a
  • bundle the calling file location with the name to ensure global uniqueness

Identifiers created at different locations will not be the same. The identifiers created at the same location will be the same.

>>> $$(nameWithLoc "a") -- a sample result could be "a:<interactive>:18:4-18"
a:<interactive>:...
  • bundle the calling file location with some user provided information

Identifiers created with different name or different additional information will not be the same.

>>> nameWithInfo "a" (1 :: Int)
a:1

Constructors

FreshIdent :: String -> FreshIdent 
FreshIdentWithInfo :: (Typeable a, Ord a, Lift a, NFData a, Show a, Hashable a) => String -> a -> FreshIdent 

name :: String -> FreshIdent Source #

Simple name identifier. The same identifier refers to the same symbolic variable in the whole program.

The user may need to use unique names to avoid unintentional identifier collision.

nameWithInfo :: forall a. (Typeable a, Ord a, Lift a, NFData a, Show a, Hashable a) => String -> a -> FreshIdent Source #

Identifier with extra information. The same name with the same information refers to the same symbolic variable in the whole program.

The user may need to use unique names or additional information to avoid unintentional identifier collision.

data FileLocation Source #

Constructors

FileLocation 

Fields

Instances

Instances details
Generic FileLocation Source # 
Instance details

Defined in Grisette.Core.Data.FileLocation

Associated Types

type Rep FileLocation :: Type -> Type #

Show FileLocation Source # 
Instance details

Defined in Grisette.Core.Data.FileLocation

NFData FileLocation Source # 
Instance details

Defined in Grisette.Core.Data.FileLocation

Methods

rnf :: FileLocation -> () #

Eq FileLocation Source # 
Instance details

Defined in Grisette.Core.Data.FileLocation

Ord FileLocation Source # 
Instance details

Defined in Grisette.Core.Data.FileLocation

Hashable FileLocation Source # 
Instance details

Defined in Grisette.Core.Data.FileLocation

Lift FileLocation Source # 
Instance details

Defined in Grisette.Core.Data.FileLocation

Methods

lift :: Quote m => FileLocation -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => FileLocation -> Code m FileLocation #

type Rep FileLocation Source # 
Instance details

Defined in Grisette.Core.Data.FileLocation

type Rep FileLocation = D1 ('MetaData "FileLocation" "Grisette.Core.Data.FileLocation" "grisette-0.1.0.0-7JmpZvRpjzaDDLSSjCfe9O" 'False) (C1 ('MetaCons "FileLocation" 'PrefixI 'True) (S1 ('MetaSel ('Just "locPath") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String) :*: (S1 ('MetaSel ('Just "locLineno") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int) :*: S1 ('MetaSel ('Just "locSpan") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Int, Int)))))

nameWithLoc :: String -> SpliceQ FreshIdent Source #

Identifier with the current location as extra information.

>>> $$(nameWithLoc "a") -- a sample result could be "a:<interactive>:18:4-18"
a:<interactive>:...

The uniqueness is ensured for the call to nameWithLoc at different location.

Symbolic Generation Monad

class Monad m => MonadFresh m where Source #

Monad class for fresh symbolic value generation.

The monad should be a reader monad for the FreshIdent and a state monad for the FreshIndex.

Methods

nextFreshIndex :: m FreshIndex Source #

Increase the index by one and return the new index.

getFreshIdent :: m FreshIdent Source #

Get the identifier.

Instances

Instances details
Monad m => MonadFresh (FreshT m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

type Fresh = FreshT Identity Source #

FreshT specialized with Identity.

data FreshT m a Source #

A symbolic generation monad transformer. It is a reader monad transformer for identifiers and a state monad transformer for indices.

Each time a fresh symbolic variable is generated, the index should be increased.

Instances

Instances details
MonadTrans FreshT Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

lift :: Monad m => m a -> FreshT m a #

MonadError e m => MonadError e (FreshT m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

throwError :: e -> FreshT m a #

catchError :: FreshT m a -> (e -> FreshT m a) -> FreshT m a #

(Applicative m, Monad m) => Applicative (FreshT m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

pure :: a -> FreshT m a #

(<*>) :: FreshT m (a -> b) -> FreshT m a -> FreshT m b #

liftA2 :: (a -> b -> c) -> FreshT m a -> FreshT m b -> FreshT m c #

(*>) :: FreshT m a -> FreshT m b -> FreshT m b #

(<*) :: FreshT m a -> FreshT m b -> FreshT m a #

Functor f => Functor (FreshT f) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fmap :: (a -> b) -> FreshT f a -> FreshT f b #

(<$) :: a -> FreshT f b -> FreshT f a #

Monad m => Monad (FreshT m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

(>>=) :: FreshT m a -> (a -> FreshT m b) -> FreshT m b #

(>>) :: FreshT m a -> FreshT m b -> FreshT m b #

return :: a -> FreshT m a #

Monad m => MonadFresh (FreshT m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Mergeable1 m => Mergeable1 (FreshT m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

UnionLike m => SimpleMergeable1 (FreshT m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

liftMrgIte :: (SymBool -> a -> a -> a) -> SymBool -> FreshT m a -> FreshT m a -> FreshT m a Source #

UnionLike m => UnionLike (FreshT m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

(Mergeable a, Mergeable1 m) => Mergeable (FreshT m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

(UnionLike m, Mergeable a) => SimpleMergeable (FreshT m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

mrgIte :: SymBool -> FreshT m a -> FreshT m a -> FreshT m a Source #

runFresh :: Fresh a -> FreshIdent -> a Source #

Run the symbolic generation with the given identifier and 0 as the initial index.

runFreshT :: Monad m => FreshT m a -> FreshIdent -> m a Source #

Run the symbolic generation with the given identifier and 0 as the initial index.

Symbolic Generation Class

class Mergeable a => GenSym spec a where Source #

Class of types in which symbolic values can be generated with respect to some specification.

The result will be wrapped in a union-like monad. This ensures that we can generate those types with complex merging rules.

The uniqueness of symbolic constants is managed with the a monadic context. Fresh and FreshT can be useful.

Minimal complete definition

Nothing

Methods

fresh :: MonadFresh m => spec -> m (UnionM a) Source #

Generate a symbolic value given some specification. Within a single MonadFresh context, calls to fresh would generate unique symbolic constants.

The following example generates a symbolic boolean. No specification is needed.

>>> runFresh (fresh ()) "a" :: UnionM SymBool
{a@0}

The following example generates booleans, which cannot be merged into a single value with type Bool. No specification is needed.

>>> runFresh (fresh ()) "a" :: UnionM Bool
{If a@0 False True}

The following example generates Maybe Bools. There are more than one symbolic constants introduced, and their uniqueness is ensured. No specification is needed.

>>> runFresh (fresh ()) "a" :: UnionM (Maybe Bool)
{If a@0 Nothing (If a@1 (Just False) (Just True))}

The following example generates lists of symbolic booleans with length 1 to 2.

>>> runFresh (fresh (ListSpec 1 2 ())) "a" :: UnionM [SymBool]
{If a@2 [a@1] [a@0,a@1]}

When multiple symbolic values are generated, there will not be any identifier collision

>>> runFresh (do; a <- fresh (); b <- fresh (); return (a, b)) "a" :: (UnionM SymBool, UnionM SymBool)
({a@0},{a@1})

default fresh :: GenSymSimple spec a => MonadFresh m => spec -> m (UnionM a) Source #

Instances

Instances details
GenSym Int16 Int16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => Int16 -> m (UnionM Int16) Source #

GenSym Int32 Int32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => Int32 -> m (UnionM Int32) Source #

GenSym Int64 Int64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => Int64 -> m (UnionM Int64) Source #

GenSym Int8 Int8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => Int8 -> m (UnionM Int8) Source #

GenSym Word16 Word16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => Word16 -> m (UnionM Word16) Source #

GenSym Word32 Word32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => Word32 -> m (UnionM Word32) Source #

GenSym Word64 Word64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => Word64 -> m (UnionM Word64) Source #

GenSym ByteString ByteString Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

GenSym Word8 Word8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => Word8 -> m (UnionM Word8) Source #

GenSym Integer Integer Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => Integer -> m (UnionM Integer) Source #

GenSym () () Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => () -> m (UnionM ()) Source #

GenSym () Bool Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => () -> m (UnionM Bool) Source #

GenSym Bool Bool Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => Bool -> m (UnionM Bool) Source #

GenSym Char Char Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => Char -> m (UnionM Char) Source #

GenSym Int Int Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => Int -> m (UnionM Int) Source #

GenSym Word Word Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => Word -> m (UnionM Word) Source #

(GenSymSimple () a, Mergeable a) => GenSym Integer [a] Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => Integer -> m (UnionM [a]) Source #

SupportedPrim a => GenSym () (Sym a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => () -> m (UnionM (Sym a)) Source #

(GenSym () a, Mergeable a) => GenSym () (Maybe a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => () -> m (UnionM (Maybe a)) Source #

(GenSym spec a, Mergeable a) => GenSym spec (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

fresh :: MonadFresh m => spec -> m (UnionM (UnionM a)) Source #

(GenSym () a, Mergeable a, GenSym () b, Mergeable b) => GenSym () (Either a b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => () -> m (UnionM (Either a b)) Source #

(GenSym () a, Mergeable a, GenSym () b, Mergeable b) => GenSym () (CBMCEither a b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

fresh :: MonadFresh m => () -> m (UnionM (CBMCEither a b)) Source #

(GenSym () a, Mergeable a, GenSym () b, Mergeable b) => GenSym () (a, b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => () -> m (UnionM (a, b)) Source #

(GenSym spec (m (Maybe a)), Mergeable1 m, Mergeable a) => GenSym spec (MaybeT m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m0 => spec -> m0 (UnionM (MaybeT m a)) Source #

(GenSym () a, Mergeable a, GenSym () b, Mergeable b, GenSym () c, Mergeable c) => GenSym () (a, b, c) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => () -> m (UnionM (a, b, c)) Source #

(GenSym spec (m (CBMCEither a b)), Mergeable1 m, Mergeable a, Mergeable b) => GenSym spec (CBMCExceptT a m b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

fresh :: MonadFresh m0 => spec -> m0 (UnionM (CBMCExceptT a m b)) Source #

(GenSym spec (m (Either a b)), Mergeable1 m, Mergeable a, Mergeable b) => GenSym spec (ExceptT a m b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m0 => spec -> m0 (UnionM (ExceptT a m b)) Source #

(GenSym () a, Mergeable a, GenSym () b, Mergeable b, GenSym () c, Mergeable c, GenSym () d, Mergeable d) => GenSym () (a, b, c, d) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => () -> m (UnionM (a, b, c, d)) Source #

(GenSym () a, Mergeable a, GenSym () b, Mergeable b, GenSym () c, Mergeable c, GenSym () d, Mergeable d, GenSym () e, Mergeable e) => GenSym () (a, b, c, d, e) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => () -> m (UnionM (a, b, c, d, e)) Source #

(GenSym () a, Mergeable a, GenSym () b, Mergeable b, GenSym () c, Mergeable c, GenSym () d, Mergeable d, GenSym () e, Mergeable e, GenSym () f, Mergeable f) => GenSym () (a, b, c, d, e, f) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => () -> m (UnionM (a, b, c, d, e, f)) Source #

(GenSym () a, Mergeable a, GenSym () b, Mergeable b, GenSym () c, Mergeable c, GenSym () d, Mergeable d, GenSym () e, Mergeable e, GenSym () f, Mergeable f, GenSym () g, Mergeable g) => GenSym () (a, b, c, d, e, f, g) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => () -> m (UnionM (a, b, c, d, e, f, g)) Source #

(GenSym () a, Mergeable a, GenSym () b, Mergeable b, GenSym () c, Mergeable c, GenSym () d, Mergeable d, GenSym () e, Mergeable e, GenSym () f, Mergeable f, GenSym () g, Mergeable g, GenSym () h, Mergeable h) => GenSym () (a, b, c, d, e, f, g, h) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => () -> m (UnionM (a, b, c, d, e, f, g, h)) Source #

(GenSym a a, Mergeable a) => GenSym (UnionM a) a Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

fresh :: MonadFresh m => UnionM a -> m (UnionM a) Source #

(Enum v, Mergeable v) => GenSym (EnumGenBound v) v Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => EnumGenBound v -> m (UnionM v) Source #

(Enum v, Mergeable v) => GenSym (EnumGenUpperBound v) v Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => EnumGenUpperBound v -> m (UnionM v) Source #

(GenSymSimple spec a, Mergeable a) => GenSym (ListSpec spec) [a] Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => ListSpec spec -> m (UnionM [a]) Source #

(GenSymSimple spec a, Mergeable a) => GenSym (SimpleListSpec spec) [a] Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => SimpleListSpec spec -> m (UnionM [a]) Source #

SupportedPrim a => GenSym (Sym a) (Sym a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => Sym a -> m (UnionM (Sym a)) Source #

(GenSymSimple a a, Mergeable a) => GenSym (Maybe a) (Maybe a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => Maybe a -> m (UnionM (Maybe a)) Source #

(GenSymSimple a a, Mergeable a) => GenSym [a] [a] Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => [a] -> m (UnionM [a]) Source #

(GenSymSimple a a, Mergeable a, GenSymSimple b b, Mergeable b) => GenSym (Either a b) (Either a b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => Either a b -> m (UnionM (Either a b)) Source #

(GenSymSimple a a, Mergeable a, GenSymSimple b b, Mergeable b) => GenSym (CBMCEither a b) (CBMCEither a b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

fresh :: MonadFresh m => CBMCEither a b -> m (UnionM (CBMCEither a b)) Source #

(GenSymSimple (m (Maybe a)) (m (Maybe a)), Mergeable1 m, Mergeable a) => GenSym (MaybeT m a) (MaybeT m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m0 => MaybeT m a -> m0 (UnionM (MaybeT m a)) Source #

(GenSym aspec a, Mergeable a, GenSym bspec b, Mergeable b) => GenSym (aspec, bspec) (a, b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => (aspec, bspec) -> m (UnionM (a, b)) Source #

(GenSymSimple (m (CBMCEither e a)) (m (CBMCEither e a)), Mergeable1 m, Mergeable e, Mergeable a) => GenSym (CBMCExceptT e m a) (CBMCExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

fresh :: MonadFresh m0 => CBMCExceptT e m a -> m0 (UnionM (CBMCExceptT e m a)) Source #

(GenSymSimple (m (Either e a)) (m (Either e a)), Mergeable1 m, Mergeable e, Mergeable a) => GenSym (ExceptT e m a) (ExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m0 => ExceptT e m a -> m0 (UnionM (ExceptT e m a)) Source #

(GenSym aspec a, Mergeable a, GenSym bspec b, Mergeable b, GenSym cspec c, Mergeable c) => GenSym (aspec, bspec, cspec) (a, b, c) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => (aspec, bspec, cspec) -> m (UnionM (a, b, c)) Source #

(GenSym aspec a, Mergeable a, GenSym bspec b, Mergeable b, GenSym cspec c, Mergeable c, GenSym dspec d, Mergeable d) => GenSym (aspec, bspec, cspec, dspec) (a, b, c, d) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => (aspec, bspec, cspec, dspec) -> m (UnionM (a, b, c, d)) Source #

(GenSym aspec a, Mergeable a, GenSym bspec b, Mergeable b, GenSym cspec c, Mergeable c, GenSym dspec d, Mergeable d, GenSym espec e, Mergeable e) => GenSym (aspec, bspec, cspec, dspec, espec) (a, b, c, d, e) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => (aspec, bspec, cspec, dspec, espec) -> m (UnionM (a, b, c, d, e)) Source #

(GenSym aspec a, Mergeable a, GenSym bspec b, Mergeable b, GenSym cspec c, Mergeable c, GenSym dspec d, Mergeable d, GenSym espec e, Mergeable e, GenSym fspec f, Mergeable f) => GenSym (aspec, bspec, cspec, dspec, espec, fspec) (a, b, c, d, e, f) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => (aspec, bspec, cspec, dspec, espec, fspec) -> m (UnionM (a, b, c, d, e, f)) Source #

(GenSym aspec a, Mergeable a, GenSym bspec b, Mergeable b, GenSym cspec c, Mergeable c, GenSym dspec d, Mergeable d, GenSym espec e, Mergeable e, GenSym fspec f, Mergeable f, GenSym gspec g, Mergeable g) => GenSym (aspec, bspec, cspec, dspec, espec, fspec, gspec) (a, b, c, d, e, f, g) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => (aspec, bspec, cspec, dspec, espec, fspec, gspec) -> m (UnionM (a, b, c, d, e, f, g)) Source #

(GenSym aspec a, Mergeable a, GenSym bspec b, Mergeable b, GenSym cspec c, Mergeable c, GenSym dspec d, Mergeable d, GenSym espec e, Mergeable e, GenSym fspec f, Mergeable f, GenSym gspec g, Mergeable g, GenSym hspec h, Mergeable h) => GenSym (aspec, bspec, cspec, dspec, espec, fspec, gspec, hspec) (a, b, c, d, e, f, g, h) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => (aspec, bspec, cspec, dspec, espec, fspec, gspec, hspec) -> m (UnionM (a, b, c, d, e, f, g, h)) Source #

class GenSymSimple spec a where Source #

Class of types in which symbolic values can be generated with respect to some specification.

The result will not be wrapped in a union-like monad.

The uniqueness of symbolic constants is managed with the a monadic context. Fresh and FreshT can be useful.

Methods

simpleFresh :: MonadFresh m => spec -> m a Source #

Generate a symbolic value given some specification. The uniqueness is ensured.

The following example generates a symbolic boolean. No specification is needed.

>>> runFresh (simpleFresh ()) "a" :: SymBool
a@0

The following code generates list of symbolic boolean with length 2. As the length is fixed, we don't have to wrap the result in unions.

>>> runFresh (simpleFresh (SimpleListSpec 2 ())) "a" :: [SymBool]
[a@0,a@1]

Instances

Instances details
GenSymSimple Int16 Int16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

GenSymSimple Int32 Int32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

GenSymSimple Int64 Int64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

GenSymSimple Int8 Int8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => Int8 -> m Int8 Source #

GenSymSimple Word16 Word16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

GenSymSimple Word32 Word32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

GenSymSimple Word64 Word64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

GenSymSimple ByteString ByteString Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

GenSymSimple Word8 Word8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

GenSymSimple Integer Integer Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

GenSymSimple () () Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => () -> m () Source #

GenSymSimple Bool Bool Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => Bool -> m Bool Source #

GenSymSimple Char Char Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => Char -> m Char Source #

GenSymSimple Int Int Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => Int -> m Int Source #

GenSymSimple Word Word Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => Word -> m Word Source #

SupportedPrim a => GenSymSimple () (Sym a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => () -> m (Sym a) Source #

GenSym spec a => GenSymSimple spec (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

simpleFresh :: MonadFresh m => spec -> m (UnionM a) Source #

(GenSymSimple () a, GenSymSimple () b) => GenSymSimple () (a, b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => () -> m (a, b) Source #

GenSymSimple spec (m (Maybe a)) => GenSymSimple spec (MaybeT m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m0 => spec -> m0 (MaybeT m a) Source #

(GenSymSimple () a, GenSymSimple () b, GenSymSimple () c) => GenSymSimple () (a, b, c) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => () -> m (a, b, c) Source #

GenSymSimple spec (m (CBMCEither a b)) => GenSymSimple spec (CBMCExceptT a m b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

simpleFresh :: MonadFresh m0 => spec -> m0 (CBMCExceptT a m b) Source #

GenSymSimple spec (m (Either a b)) => GenSymSimple spec (ExceptT a m b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m0 => spec -> m0 (ExceptT a m b) Source #

(GenSymSimple () a, GenSymSimple () b, GenSymSimple () c, GenSymSimple () d) => GenSymSimple () (a, b, c, d) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => () -> m (a, b, c, d) Source #

(GenSymSimple () a, GenSymSimple () b, GenSymSimple () c, GenSymSimple () d, GenSymSimple () e) => GenSymSimple () (a, b, c, d, e) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => () -> m (a, b, c, d, e) Source #

(GenSymSimple () a, GenSymSimple () b, GenSymSimple () c, GenSymSimple () d, GenSymSimple () e, GenSymSimple () f) => GenSymSimple () (a, b, c, d, e, f) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => () -> m (a, b, c, d, e, f) Source #

(GenSymSimple () a, GenSymSimple () b, GenSymSimple () c, GenSymSimple () d, GenSymSimple () e, GenSymSimple () f, GenSymSimple () g) => GenSymSimple () (a, b, c, d, e, f, g) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => () -> m (a, b, c, d, e, f, g) Source #

(GenSymSimple () a, GenSymSimple () b, GenSymSimple () c, GenSymSimple () d, GenSymSimple () e, GenSymSimple () f, GenSymSimple () g, GenSymSimple () h) => GenSymSimple () (a, b, c, d, e, f, g, h) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => () -> m (a, b, c, d, e, f, g, h) Source #

GenSymSimple spec a => GenSymSimple (SimpleListSpec spec) [a] Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => SimpleListSpec spec -> m [a] Source #

SupportedPrim a => GenSymSimple (Sym a) (Sym a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => Sym a -> m (Sym a) Source #

GenSymSimple a a => GenSymSimple (Maybe a) (Maybe a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => Maybe a -> m (Maybe a) Source #

GenSymSimple a a => GenSymSimple [a] [a] Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => [a] -> m [a] Source #

(GenSymSimple a a, GenSymSimple b b) => GenSymSimple (Either a b) (Either a b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => Either a b -> m (Either a b) Source #

(GenSymSimple a a, GenSymSimple b b) => GenSymSimple (CBMCEither a b) (CBMCEither a b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

simpleFresh :: MonadFresh m => CBMCEither a b -> m (CBMCEither a b) Source #

GenSymSimple (m (Maybe a)) (m (Maybe a)) => GenSymSimple (MaybeT m a) (MaybeT m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m0 => MaybeT m a -> m0 (MaybeT m a) Source #

(GenSymSimple aspec a, GenSymSimple bspec b) => GenSymSimple (aspec, bspec) (a, b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => (aspec, bspec) -> m (a, b) Source #

GenSymSimple (m (CBMCEither e a)) (m (CBMCEither e a)) => GenSymSimple (CBMCExceptT e m a) (CBMCExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

simpleFresh :: MonadFresh m0 => CBMCExceptT e m a -> m0 (CBMCExceptT e m a) Source #

GenSymSimple (m (Either e a)) (m (Either e a)) => GenSymSimple (ExceptT e m a) (ExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m0 => ExceptT e m a -> m0 (ExceptT e m a) Source #

(GenSymSimple aspec a, GenSymSimple bspec b, GenSymSimple cspec c) => GenSymSimple (aspec, bspec, cspec) (a, b, c) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => (aspec, bspec, cspec) -> m (a, b, c) Source #

(GenSymSimple aspec a, GenSymSimple bspec b, GenSymSimple cspec c, GenSymSimple dspec d) => GenSymSimple (aspec, bspec, cspec, dspec) (a, b, c, d) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => (aspec, bspec, cspec, dspec) -> m (a, b, c, d) Source #

(GenSymSimple aspec a, GenSymSimple bspec b, GenSymSimple cspec c, GenSymSimple dspec d, GenSymSimple espec e) => GenSymSimple (aspec, bspec, cspec, dspec, espec) (a, b, c, d, e) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => (aspec, bspec, cspec, dspec, espec) -> m (a, b, c, d, e) Source #

(GenSymSimple aspec a, GenSymSimple bspec b, GenSymSimple cspec c, GenSymSimple dspec d, GenSymSimple espec e, GenSymSimple fspec f) => GenSymSimple (aspec, bspec, cspec, dspec, espec, fspec) (a, b, c, d, e, f) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => (aspec, bspec, cspec, dspec, espec, fspec) -> m (a, b, c, d, e, f) Source #

(GenSymSimple aspec a, GenSymSimple bspec b, GenSymSimple cspec c, GenSymSimple dspec d, GenSymSimple espec e, GenSymSimple fspec f, GenSymSimple gspec g) => GenSymSimple (aspec, bspec, cspec, dspec, espec, fspec, gspec) (a, b, c, d, e, f, g) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => (aspec, bspec, cspec, dspec, espec, fspec, gspec) -> m (a, b, c, d, e, f, g) Source #

(GenSymSimple aspec a, GenSymSimple bspec b, GenSymSimple cspec c, GenSymSimple dspec d, GenSymSimple espec e, GenSymSimple fspec f, GenSymSimple gspec g, GenSymSimple hspec h) => GenSymSimple (aspec, bspec, cspec, dspec, espec, fspec, gspec, hspec) (a, b, c, d, e, f, g, h) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => (aspec, bspec, cspec, dspec, espec, fspec, gspec, hspec) -> m (a, b, c, d, e, f, g, h) Source #

genSym :: GenSym spec a => spec -> FreshIdent -> UnionM a Source #

Generate a symbolic variable wrapped in a Union without the monadic context. A globally unique identifier should be supplied to ensure the uniqueness of symbolic constants in the generated symbolic values.

>>> genSym (ListSpec 1 2 ()) "a" :: UnionM [SymBool]
{If a@2 [a@1] [a@0,a@1]}

genSymSimple :: forall spec a. GenSymSimple spec a => spec -> FreshIdent -> a Source #

Generate a simple symbolic variable wrapped in a Union without the monadic context. A globally unique identifier should be supplied to ensure the uniqueness of symbolic constants in the generated symbolic values.

>>> genSymSimple (SimpleListSpec 2 ()) "a" :: [SymBool]
[a@0,a@1]

Symbolic Generation Class Derivation

derivedNoSpecFresh :: forall bool a m u. (Generic a, GenSymNoSpec (Rep a), Mergeable a, MonadFresh m) => () -> m (UnionM a) Source #

We cannot provide DerivingVia style derivation for GenSym, while you can use this fresh implementation to implement GenSym for your own types.

This fresh implementation is for the types that does not need any specification. It will generate product types by generating each fields with () as specification, and generate all possible values for a sum type.

Note: Never use on recursive types.

derivedNoSpecSimpleFresh :: forall a m. (Generic a, GenSymSimpleNoSpec (Rep a), MonadFresh m) => () -> m a Source #

We cannot provide DerivingVia style derivation for GenSymSimple, while you can use this simpleFresh implementation to implement GenSymSimple fo your own types.

This simpleFresh implementation is for the types that does not need any specification. It will generate product types by generating each fields with () as specification. It will not work on sum types.

Note: Never use on recursive types.

derivedSameShapeSimpleFresh :: forall a m. (Generic a, GenSymSameShape (Rep a), MonadFresh m) => a -> m a Source #

We cannot provide DerivingVia style derivation for GenSymSimple, while you can use this simpleFresh implementation to implement GenSymSimple fo your own types.

This simpleFresh implementation is for the types that can be generated with a reference value of the same type.

For sum types, it will generate the result with the same data constructor. For product types, it will generate the result by generating each field with the corresponding reference value.

Note: Can be used on recursive types.

Symbolic choice

chooseFresh :: forall bool a m u. (Mergeable a, MonadFresh m) => [a] -> m (UnionM a) Source #

Symbolically chooses one of the provided values. The procedure creates n - 1 fresh symbolic boolean variables every time it is evaluated, and use these variables to conditionally select one of the n provided expressions.

The result will be wrapped in a union-like monad, and also a monad maintaining the MonadFresh context.

>>> runFresh (chooseFresh [1,2,3]) "a" :: UnionM Integer
{If a@0 1 (If a@1 2 3)}

chooseSimpleFresh :: forall a m. (SimpleMergeable a, MonadFresh m) => [a] -> m a Source #

Symbolically chooses one of the provided values. The procedure creates n - 1 fresh symbolic boolean variables every time it is evaluated, and use these variables to conditionally select one of the n provided expressions.

The result will not be wrapped in a union-like monad, but will be wrapped in a monad maintaining the Fresh context.

>>> import Data.Proxy
>>> runFresh (chooseSimpleFresh [ssym "b", ssym "c", ssym "d"]) "a" :: SymInteger
(ite a@0 b (ite a@1 c d))

chooseUnionFresh :: forall bool a m u. (Mergeable a, MonadFresh m) => [UnionM a] -> m (UnionM a) Source #

Symbolically chooses one of the provided values wrapped in union-like monads. The procedure creates n - 1 fresh symbolic boolean variables every time it is evaluated, and use these variables to conditionally select one of the n provided expressions.

The result will be wrapped in a union-like monad, and also a monad maintaining the Fresh context.

>>> let a = runFresh (chooseFresh [1, 2]) "a" :: UnionM Integer
>>> let b = runFresh (chooseFresh [2, 3]) "b" :: UnionM Integer
>>> runFresh (chooseUnionFresh [a, b]) "c" :: UnionM Integer
{If (&& c@0 a@0) 1 (If (|| c@0 b@0) 2 3)}

choose :: forall bool a u. Mergeable a => [a] -> FreshIdent -> UnionM a Source #

A wrapper for chooseFresh that executes the MonadFresh context. A globally unique identifier should be supplied to ensure the uniqueness of symbolic constants in the generated symbolic values.

chooseSimple :: forall a. SimpleMergeable a => [a] -> FreshIdent -> a Source #

A wrapper for chooseSimpleFresh that executes the MonadFresh context. A globally unique identifier should be supplied to ensure the uniqueness of symbolic constants in the generated symbolic values.

chooseUnion :: forall a u. Mergeable a => [UnionM a] -> FreshIdent -> UnionM a Source #

A wrapper for chooseUnionFresh that executes the MonadFresh context. A globally unique identifier should be supplied to ensure the uniqueness of symbolic constants in the generated symbolic values.

Useful specifications

data EnumGenBound a Source #

Specification for numbers with lower bound (inclusive) and upper bound (exclusive)

>>> runFresh (fresh (EnumGenBound @Integer 0 4)) "c" :: UnionM Integer
{If c@0 0 (If c@1 1 (If c@2 2 3))}

Constructors

EnumGenBound a a 

Instances

Instances details
(Enum v, Mergeable v) => GenSym (EnumGenBound v) v Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => EnumGenBound v -> m (UnionM v) Source #

newtype EnumGenUpperBound a Source #

Specification for enum values with upper bound (exclusive). The result would chosen from [0 .. upperbound].

>>> runFresh (fresh (EnumGenUpperBound @Integer 4)) "c" :: UnionM Integer
{If c@0 0 (If c@1 1 (If c@2 2 3))}

Constructors

EnumGenUpperBound a 

Instances

Instances details
(Enum v, Mergeable v) => GenSym (EnumGenUpperBound v) v Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => EnumGenUpperBound v -> m (UnionM v) Source #

data ListSpec spec Source #

Specification for list generation.

>>> runFresh (fresh (ListSpec 0 2 ())) "c" :: UnionM [SymBool]
{If c@2 [] (If c@3 [c@1] [c@0,c@1])}
>>> runFresh (fresh (ListSpec 0 2 (SimpleListSpec 1 ()))) "c" :: UnionM [[SymBool]]
{If c@2 [] (If c@3 [[c@1]] [[c@0],[c@1]])}

Constructors

ListSpec 

Fields

Instances

Instances details
Show spec => Show (ListSpec spec) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

showsPrec :: Int -> ListSpec spec -> ShowS #

show :: ListSpec spec -> String #

showList :: [ListSpec spec] -> ShowS #

(GenSymSimple spec a, Mergeable a) => GenSym (ListSpec spec) [a] Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => ListSpec spec -> m (UnionM [a]) Source #

data SimpleListSpec spec Source #

Specification for list generation of a specific length.

>>> runFresh (simpleFresh (SimpleListSpec 2 ())) "c" :: [SymBool]
[c@0,c@1]

Constructors

SimpleListSpec 

Fields

Instances

Instances details
Show spec => Show (SimpleListSpec spec) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

(GenSymSimple spec a, Mergeable a) => GenSym (SimpleListSpec spec) [a] Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => SimpleListSpec spec -> m (UnionM [a]) Source #

GenSymSimple spec a => GenSymSimple (SimpleListSpec spec) [a] Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => SimpleListSpec spec -> m [a] Source #

Error Handling

Grisette supports using ExceptT to handle errors, and provides the mrg* variants for the combinators in Grisette.Lib.Mtl, for example, mrgThrowError.

>>> import Control.Monad.Except
>>> import Grisette.Lib.Mtl
>>> mrgThrowError AssertionError :: ExceptT AssertionError UnionM ()
ExceptT {Left AssertionError}

You can define your own error types, and reason about them with the solver APIs.

>>> :set -XDerivingVia -XDeriveGeneric -XDerivingStrategies -XLambdaCase
>>> import GHC.Generics
>>> import Grisette.Backend.SBV
>>> :{
  data Error = Error1 | Error2 | Error3
    deriving (Show, Generic)
    deriving (Mergeable) via Default Error
:}
>>> let [a,b,c] = ["a","b","c"] :: [SymBool]
>>> res = mrgIf a (throwError Error1) (mrgIf b (return c) (throwError Error2)) :: ExceptT Error UnionM SymBool
>>> res
ExceptT {If (|| a (! b)) (If a (Left Error1) (Left Error2)) (Right c)}
>>> solveExcept (UnboundedReasoning z3) (\case Left _ -> con False; Right x -> x) res
Right (Model {a -> False :: Bool, b -> True :: Bool, c -> True :: Bool})

The solver call in the above example means that we want the solver to find the conditions under which no error is thrown, and the result is true. For more details, please refer to the documentation of the solver APIs.

For those who prefer to encode errors as assertions and assumptions, we provide the symAssert and symAssume functions. These functions relies on the TransformError type class to transform the assertions and assumptions to the user-defined error type. See their documentation for details.

Predefined errors

data AssertionError Source #

Assertion error.

Constructors

AssertionError 

Instances

Instances details
Generic AssertionError Source # 
Instance details

Defined in Grisette.Core.Control.Exception

Associated Types

type Rep AssertionError :: Type -> Type #

Show AssertionError Source # 
Instance details

Defined in Grisette.Core.Control.Exception

NFData AssertionError Source # 
Instance details

Defined in Grisette.Core.Control.Exception

Methods

rnf :: AssertionError -> () #

Eq AssertionError Source # 
Instance details

Defined in Grisette.Core.Control.Exception

Ord AssertionError Source # 
Instance details

Defined in Grisette.Core.Control.Exception

SEq AssertionError Source # 
Instance details

Defined in Grisette.Core.Control.Exception

EvaluateSym AssertionError Source # 
Instance details

Defined in Grisette.Core.Control.Exception

ExtractSymbolics AssertionError Source # 
Instance details

Defined in Grisette.Core.Control.Exception

Mergeable AssertionError Source # 
Instance details

Defined in Grisette.Core.Control.Exception

SOrd AssertionError Source # 
Instance details

Defined in Grisette.Core.Control.Exception

SimpleMergeable AssertionError Source # 
Instance details

Defined in Grisette.Core.Control.Exception

TransformError ArithException AssertionError Source # 
Instance details

Defined in Grisette.Core.Control.Exception

TransformError ArrayException AssertionError Source # 
Instance details

Defined in Grisette.Core.Control.Exception

TransformError AssertionError AssertionError Source # 
Instance details

Defined in Grisette.Core.Control.Exception

TransformError AssertionError VerificationConditions Source # 
Instance details

Defined in Grisette.Core.Control.Exception

ToCon AssertionError AssertionError Source # 
Instance details

Defined in Grisette.Core.Control.Exception

ToSym AssertionError AssertionError Source # 
Instance details

Defined in Grisette.Core.Control.Exception

type Rep AssertionError Source # 
Instance details

Defined in Grisette.Core.Control.Exception

type Rep AssertionError = D1 ('MetaData "AssertionError" "Grisette.Core.Control.Exception" "grisette-0.1.0.0-7JmpZvRpjzaDDLSSjCfe9O" 'False) (C1 ('MetaCons "AssertionError" 'PrefixI 'False) (U1 :: Type -> Type))

data VerificationConditions Source #

Verification conditions. A crashed program path can terminate with either assertion violation errors or assumption violation errors.

Instances

Instances details
Generic VerificationConditions Source # 
Instance details

Defined in Grisette.Core.Control.Exception

Associated Types

type Rep VerificationConditions :: Type -> Type #

Show VerificationConditions Source # 
Instance details

Defined in Grisette.Core.Control.Exception

NFData VerificationConditions Source # 
Instance details

Defined in Grisette.Core.Control.Exception

Methods

rnf :: VerificationConditions -> () #

Eq VerificationConditions Source # 
Instance details

Defined in Grisette.Core.Control.Exception

Ord VerificationConditions Source # 
Instance details

Defined in Grisette.Core.Control.Exception

SEq VerificationConditions Source # 
Instance details

Defined in Grisette.Core.Control.Exception

EvaluateSym VerificationConditions Source # 
Instance details

Defined in Grisette.Core.Control.Exception

ExtractSymbolics VerificationConditions Source # 
Instance details

Defined in Grisette.Core.Control.Exception

Mergeable VerificationConditions Source # 
Instance details

Defined in Grisette.Core.Control.Exception

SOrd VerificationConditions Source # 
Instance details

Defined in Grisette.Core.Control.Exception

TransformError AssertionError VerificationConditions Source # 
Instance details

Defined in Grisette.Core.Control.Exception

TransformError VerificationConditions VerificationConditions Source # 
Instance details

Defined in Grisette.Core.Control.Exception

ToCon VerificationConditions VerificationConditions Source # 
Instance details

Defined in Grisette.Core.Control.Exception

ToSym VerificationConditions VerificationConditions Source # 
Instance details

Defined in Grisette.Core.Control.Exception

type Rep VerificationConditions Source # 
Instance details

Defined in Grisette.Core.Control.Exception

type Rep VerificationConditions = D1 ('MetaData "VerificationConditions" "Grisette.Core.Control.Exception" "grisette-0.1.0.0-7JmpZvRpjzaDDLSSjCfe9O" 'False) (C1 ('MetaCons "AssertionViolation" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "AssumptionViolation" 'PrefixI 'False) (U1 :: Type -> Type))

Error transformation

class TransformError from to where Source #

This class indicates that the error type to can always represent the error type from.

This is useful in implementing generic procedures that may throw errors. For example, we support symbolic division and modulo operations. These operations should throw an error when the divisor is zero, and we use the standard error type ArithException for this purpose. However, the user may use other type to represent errors, so we need this type class to transform the ArithException to the user-defined types.

Another example of these generic procedures is the symAssert and symAssume functions. They can be used with any error types that are compatible with the AssertionError and VerificationConditions types, respectively.

Methods

transformError :: from -> to Source #

Transforms an error with type from to an error with type to.

symAssert :: (TransformError AssertionError to, Mergeable to, MonadError to erm, MonadUnion erm) => SymBool -> erm () Source #

Used within a monadic multi path computation to begin exception processing.

Checks the condition passed to the function. The current execution path will be terminated with assertion error if the condition is false.

If the condition is symbolic, Grisette will split the execution into two paths based on the condition. The symbolic execution will continue on the then-branch, where the condition is true. For the else branch, where the condition is false, the execution will be terminated.

The resulting monadic environment should be compatible with the AssertionError error type. See TransformError type class for details.

Examples:

Terminates the execution if the condition is false. Note that we may lose the Mergeable knowledge here if no possible execution path is viable. This may affect the efficiency in theory, but in practice this should not be a problem as all paths are terminated and no further evaluation would be performed.

>>> symAssert (con False) :: ExceptT AssertionError UnionM ()
ExceptT {Left AssertionError}
>>> do; symAssert (con False); mrgReturn 1 :: ExceptT AssertionError UnionM Integer
ExceptT <Left AssertionError>

No effect if the condition is true:

>>> symAssert (con True) :: ExceptT AssertionError UnionM ()
ExceptT {Right ()}
>>> do; symAssert (con True); mrgReturn 1 :: ExceptT AssertionError UnionM Integer
ExceptT {Right 1}

Splitting the path and terminate one of them when the condition is symbolic.

>>> symAssert (ssym "a") :: ExceptT AssertionError UnionM ()
ExceptT {If (! a) (Left AssertionError) (Right ())}
>>> do; symAssert (ssym "a"); mrgReturn 1 :: ExceptT AssertionError UnionM Integer
ExceptT {If (! a) (Left AssertionError) (Right 1)}

AssertionError is compatible with VerificationConditions:

>>> symAssert (ssym "a") :: ExceptT VerificationConditions UnionM ()
ExceptT {If (! a) (Left AssertionViolation) (Right ())}

symAssume :: (TransformError VerificationConditions to, Mergeable to, MonadError to erm, MonadUnion erm) => SymBool -> erm () Source #

Used within a monadic multi path computation to begin exception processing.

Similar to symAssert, but terminates the execution path with AssumptionViolation error.

Examples:

>>> symAssume (ssym "a") :: ExceptT VerificationConditions UnionM ()
ExceptT {If (! a) (Left AssumptionViolation) (Right ())}

symAssertTransformableError :: (Mergeable to, TransformError from to, MonadError to erm, MonadUnion erm) => from -> SymBool -> erm () Source #

Used within a monadic multi path computation for exception processing.

Terminate the current execution path with the specified error if the condition does not hold. Compatible error can be transformed.

>>> let assert = symAssertTransformableError AssertionError
>>> assert "a" :: ExceptT AssertionError UnionM ()
ExceptT {If (! a) (Left AssertionError) (Right ())}

symThrowTransformableError :: (Mergeable to, Mergeable a, TransformError from to, MonadError to erm, MonadUnion erm) => from -> erm a Source #

Used within a monadic multi path computation to begin exception processing.

Terminate the current execution path with the specified error. Compatible errors can be transformed.

>>> symThrowTransformableError Overflow :: ExceptT AssertionError UnionM ()
ExceptT {Left AssertionError}

Simulate CBMC error handling

newtype CBMCEither a b Source #

A wrapper type for Either. Uses different merging strategies.

Constructors

CBMCEither 

Fields

Instances

Instances details
(GenSym () a, Mergeable a, GenSym () b, Mergeable b) => GenSym () (CBMCEither a b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

fresh :: MonadFresh m => () -> m (UnionM (CBMCEither a b)) Source #

(Lift a, Lift b) => Lift (CBMCEither a b :: Type) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

lift :: Quote m => CBMCEither a b -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => CBMCEither a b -> Code m (CBMCEither a b) #

Eq a => Eq1 (CBMCEither a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

liftEq :: (a0 -> b -> Bool) -> CBMCEither a a0 -> CBMCEither a b -> Bool #

Ord a => Ord1 (CBMCEither a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

liftCompare :: (a0 -> b -> Ordering) -> CBMCEither a a0 -> CBMCEither a b -> Ordering #

Read a => Read1 (CBMCEither a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

liftReadsPrec :: (Int -> ReadS a0) -> ReadS [a0] -> Int -> ReadS (CBMCEither a a0) #

liftReadList :: (Int -> ReadS a0) -> ReadS [a0] -> ReadS [CBMCEither a a0] #

liftReadPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec (CBMCEither a a0) #

liftReadListPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec [CBMCEither a a0] #

Show a => Show1 (CBMCEither a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

liftShowsPrec :: (Int -> a0 -> ShowS) -> ([a0] -> ShowS) -> Int -> CBMCEither a a0 -> ShowS #

liftShowList :: (Int -> a0 -> ShowS) -> ([a0] -> ShowS) -> [CBMCEither a a0] -> ShowS #

Applicative (CBMCEither a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

pure :: a0 -> CBMCEither a a0 #

(<*>) :: CBMCEither a (a0 -> b) -> CBMCEither a a0 -> CBMCEither a b #

liftA2 :: (a0 -> b -> c) -> CBMCEither a a0 -> CBMCEither a b -> CBMCEither a c #

(*>) :: CBMCEither a a0 -> CBMCEither a b -> CBMCEither a b #

(<*) :: CBMCEither a a0 -> CBMCEither a b -> CBMCEither a a0 #

Functor (CBMCEither a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

fmap :: (a0 -> b) -> CBMCEither a a0 -> CBMCEither a b #

(<$) :: a0 -> CBMCEither a b -> CBMCEither a a0 #

Monad (CBMCEither a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

(>>=) :: CBMCEither a a0 -> (a0 -> CBMCEither a b) -> CBMCEither a b #

(>>) :: CBMCEither a a0 -> CBMCEither a b -> CBMCEither a b #

return :: a0 -> CBMCEither a a0 #

Mergeable e => Mergeable1 (CBMCEither e) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

UnionWithExcept (UnionM (CBMCEither e v)) UnionM e v Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Generic (CBMCEither a b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Associated Types

type Rep (CBMCEither a b) :: Type -> Type #

Methods

from :: CBMCEither a b -> Rep (CBMCEither a b) x #

to :: Rep (CBMCEither a b) x -> CBMCEither a b #

(Read a, Read b) => Read (CBMCEither a b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

(Show a, Show b) => Show (CBMCEither a b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

showsPrec :: Int -> CBMCEither a b -> ShowS #

show :: CBMCEither a b -> String #

showList :: [CBMCEither a b] -> ShowS #

(NFData a, NFData b) => NFData (CBMCEither a b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

rnf :: CBMCEither a b -> () #

(Eq a, Eq b) => Eq (CBMCEither a b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

(==) :: CBMCEither a b -> CBMCEither a b -> Bool #

(/=) :: CBMCEither a b -> CBMCEither a b -> Bool #

(Ord a, Ord b) => Ord (CBMCEither a b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

compare :: CBMCEither a b -> CBMCEither a b -> Ordering #

(<) :: CBMCEither a b -> CBMCEither a b -> Bool #

(<=) :: CBMCEither a b -> CBMCEither a b -> Bool #

(>) :: CBMCEither a b -> CBMCEither a b -> Bool #

(>=) :: CBMCEither a b -> CBMCEither a b -> Bool #

max :: CBMCEither a b -> CBMCEither a b -> CBMCEither a b #

min :: CBMCEither a b -> CBMCEither a b -> CBMCEither a b #

(SEq e, SEq a) => SEq (CBMCEither e a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

(EvaluateSym a, EvaluateSym b) => EvaluateSym (CBMCEither a b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

evaluateSym :: Bool -> Model -> CBMCEither a b -> CBMCEither a b Source #

(ExtractSymbolics a, ExtractSymbolics b) => ExtractSymbolics (CBMCEither a b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

(Mergeable e, Mergeable a) => Mergeable (CBMCEither e a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

(SOrd a, SOrd b) => SOrd (CBMCEither a b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

(Hashable a, Hashable b) => Hashable (CBMCEither a b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

hashWithSalt :: Int -> CBMCEither a b -> Int #

hash :: CBMCEither a b -> Int #

(GenSymSimple a a, Mergeable a, GenSymSimple b b, Mergeable b) => GenSym (CBMCEither a b) (CBMCEither a b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

fresh :: MonadFresh m => CBMCEither a b -> m (UnionM (CBMCEither a b)) Source #

(GenSymSimple a a, GenSymSimple b b) => GenSymSimple (CBMCEither a b) (CBMCEither a b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

simpleFresh :: MonadFresh m => CBMCEither a b -> m (CBMCEither a b) Source #

(ToCon e1 e2, ToCon a1 a2) => ToCon (Either e1 a1) (CBMCEither e2 a2) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

toCon :: Either e1 a1 -> Maybe (CBMCEither e2 a2) Source #

(ToCon e1 e2, ToCon a1 a2) => ToCon (CBMCEither e1 a1) (Either e2 a2) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

toCon :: CBMCEither e1 a1 -> Maybe (Either e2 a2) Source #

(ToCon e1 e2, ToCon a1 a2) => ToCon (CBMCEither e1 a1) (CBMCEither e2 a2) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

toCon :: CBMCEither e1 a1 -> Maybe (CBMCEither e2 a2) Source #

(ToSym e1 e2, ToSym a1 a2) => ToSym (Either e1 a1) (CBMCEither e2 a2) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

toSym :: Either e1 a1 -> CBMCEither e2 a2 Source #

(ToSym e1 e2, ToSym a1 a2) => ToSym (CBMCEither e1 a1) (Either e2 a2) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

toSym :: CBMCEither e1 a1 -> Either e2 a2 Source #

(ToSym e1 e2, ToSym a1 a2) => ToSym (CBMCEither e1 a1) (CBMCEither e2 a2) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

toSym :: CBMCEither e1 a1 -> CBMCEither e2 a2 Source #

type Rep (CBMCEither a b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

type Rep (CBMCEither a b) = D1 ('MetaData "CBMCEither" "Grisette.Core.Control.Monad.CBMCExcept" "grisette-0.1.0.0-7JmpZvRpjzaDDLSSjCfe9O" 'True) (C1 ('MetaCons "CBMCEither" 'PrefixI 'True) (S1 ('MetaSel ('Just "runCBMCEither") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Either a b))))

newtype CBMCExceptT e m a Source #

Similar to ExceptT, but with different error handling mechanism.

Constructors

CBMCExceptT 

Fields

Instances

Instances details
Monad m => MonadError e (CBMCExceptT e m) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

throwError :: e -> CBMCExceptT e m a #

catchError :: CBMCExceptT e m a -> (e -> CBMCExceptT e m a) -> CBMCExceptT e m a #

(GenSym spec (m (CBMCEither a b)), Mergeable1 m, Mergeable a, Mergeable b) => GenSym spec (CBMCExceptT a m b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

fresh :: MonadFresh m0 => spec -> m0 (UnionM (CBMCExceptT a m b)) Source #

GenSymSimple spec (m (CBMCEither a b)) => GenSymSimple spec (CBMCExceptT a m b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

simpleFresh :: MonadFresh m0 => spec -> m0 (CBMCExceptT a m b) Source #

MonadTrans (CBMCExceptT e) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

lift :: Monad m => m a -> CBMCExceptT e m a #

Functor m => Generic1 (CBMCExceptT e m :: Type -> Type) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Associated Types

type Rep1 (CBMCExceptT e m) :: k -> Type #

Methods

from1 :: forall (a :: k). CBMCExceptT e m a -> Rep1 (CBMCExceptT e m) a #

to1 :: forall (a :: k). Rep1 (CBMCExceptT e m) a -> CBMCExceptT e m a #

MonadFail m => MonadFail (CBMCExceptT e m) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

fail :: String -> CBMCExceptT e m a #

MonadFix m => MonadFix (CBMCExceptT e m) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

mfix :: (a -> CBMCExceptT e m a) -> CBMCExceptT e m a #

MonadIO m => MonadIO (CBMCExceptT e m) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

liftIO :: IO a -> CBMCExceptT e m a #

MonadZip m => MonadZip (CBMCExceptT e m) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

mzip :: CBMCExceptT e m a -> CBMCExceptT e m b -> CBMCExceptT e m (a, b) #

mzipWith :: (a -> b -> c) -> CBMCExceptT e m a -> CBMCExceptT e m b -> CBMCExceptT e m c #

munzip :: CBMCExceptT e m (a, b) -> (CBMCExceptT e m a, CBMCExceptT e m b) #

Foldable f => Foldable (CBMCExceptT e f) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

fold :: Monoid m => CBMCExceptT e f m -> m #

foldMap :: Monoid m => (a -> m) -> CBMCExceptT e f a -> m #

foldMap' :: Monoid m => (a -> m) -> CBMCExceptT e f a -> m #

foldr :: (a -> b -> b) -> b -> CBMCExceptT e f a -> b #

foldr' :: (a -> b -> b) -> b -> CBMCExceptT e f a -> b #

foldl :: (b -> a -> b) -> b -> CBMCExceptT e f a -> b #

foldl' :: (b -> a -> b) -> b -> CBMCExceptT e f a -> b #

foldr1 :: (a -> a -> a) -> CBMCExceptT e f a -> a #

foldl1 :: (a -> a -> a) -> CBMCExceptT e f a -> a #

toList :: CBMCExceptT e f a -> [a] #

null :: CBMCExceptT e f a -> Bool #

length :: CBMCExceptT e f a -> Int #

elem :: Eq a => a -> CBMCExceptT e f a -> Bool #

maximum :: Ord a => CBMCExceptT e f a -> a #

minimum :: Ord a => CBMCExceptT e f a -> a #

sum :: Num a => CBMCExceptT e f a -> a #

product :: Num a => CBMCExceptT e f a -> a #

(Eq e, Eq1 m) => Eq1 (CBMCExceptT e m) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

liftEq :: (a -> b -> Bool) -> CBMCExceptT e m a -> CBMCExceptT e m b -> Bool #

(Ord e, Ord1 m) => Ord1 (CBMCExceptT e m) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

liftCompare :: (a -> b -> Ordering) -> CBMCExceptT e m a -> CBMCExceptT e m b -> Ordering #

(Read e, Read1 m) => Read1 (CBMCExceptT e m) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (CBMCExceptT e m a) #

liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [CBMCExceptT e m a] #

liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (CBMCExceptT e m a) #

liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [CBMCExceptT e m a] #

(Show e, Show1 m) => Show1 (CBMCExceptT e m) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> CBMCExceptT e m a -> ShowS #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [CBMCExceptT e m a] -> ShowS #

Contravariant m => Contravariant (CBMCExceptT e m) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

contramap :: (a' -> a) -> CBMCExceptT e m a -> CBMCExceptT e m a' #

(>$) :: b -> CBMCExceptT e m b -> CBMCExceptT e m a #

Traversable f => Traversable (CBMCExceptT e f) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

traverse :: Applicative f0 => (a -> f0 b) -> CBMCExceptT e f a -> f0 (CBMCExceptT e f b) #

sequenceA :: Applicative f0 => CBMCExceptT e f (f0 a) -> f0 (CBMCExceptT e f a) #

mapM :: Monad m => (a -> m b) -> CBMCExceptT e f a -> m (CBMCExceptT e f b) #

sequence :: Monad m => CBMCExceptT e f (m a) -> m (CBMCExceptT e f a) #

(Functor m, Monad m, Monoid e) => Alternative (CBMCExceptT e m) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

empty :: CBMCExceptT e m a #

(<|>) :: CBMCExceptT e m a -> CBMCExceptT e m a -> CBMCExceptT e m a #

some :: CBMCExceptT e m a -> CBMCExceptT e m [a] #

many :: CBMCExceptT e m a -> CBMCExceptT e m [a] #

(Functor m, Monad m) => Applicative (CBMCExceptT e m) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

pure :: a -> CBMCExceptT e m a #

(<*>) :: CBMCExceptT e m (a -> b) -> CBMCExceptT e m a -> CBMCExceptT e m b #

liftA2 :: (a -> b -> c) -> CBMCExceptT e m a -> CBMCExceptT e m b -> CBMCExceptT e m c #

(*>) :: CBMCExceptT e m a -> CBMCExceptT e m b -> CBMCExceptT e m b #

(<*) :: CBMCExceptT e m a -> CBMCExceptT e m b -> CBMCExceptT e m a #

Functor m => Functor (CBMCExceptT e m) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

fmap :: (a -> b) -> CBMCExceptT e m a -> CBMCExceptT e m b #

(<$) :: a -> CBMCExceptT e m b -> CBMCExceptT e m a #

Monad m => Monad (CBMCExceptT e m) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

(>>=) :: CBMCExceptT e m a -> (a -> CBMCExceptT e m b) -> CBMCExceptT e m b #

(>>) :: CBMCExceptT e m a -> CBMCExceptT e m b -> CBMCExceptT e m b #

return :: a -> CBMCExceptT e m a #

(Monad m, Monoid e) => MonadPlus (CBMCExceptT e m) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

mzero :: CBMCExceptT e m a #

mplus :: CBMCExceptT e m a -> CBMCExceptT e m a -> CBMCExceptT e m a #

(Mergeable1 m, Mergeable e) => Mergeable1 (CBMCExceptT e m) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

(UnionLike m, Mergeable e) => SimpleMergeable1 (CBMCExceptT e m) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

liftMrgIte :: (SymBool -> a -> a -> a) -> SymBool -> CBMCExceptT e m a -> CBMCExceptT e m a -> CBMCExceptT e m a Source #

(UnionLike m, Mergeable e) => UnionLike (CBMCExceptT e m) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Generic (CBMCExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Associated Types

type Rep (CBMCExceptT e m a) :: Type -> Type #

Methods

from :: CBMCExceptT e m a -> Rep (CBMCExceptT e m a) x #

to :: Rep (CBMCExceptT e m a) x -> CBMCExceptT e m a #

(Read e, Read1 m, Read a) => Read (CBMCExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

(Show e, Show1 m, Show a) => Show (CBMCExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

showsPrec :: Int -> CBMCExceptT e m a -> ShowS #

show :: CBMCExceptT e m a -> String #

showList :: [CBMCExceptT e m a] -> ShowS #

(Eq e, Eq1 m, Eq a) => Eq (CBMCExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

(==) :: CBMCExceptT e m a -> CBMCExceptT e m a -> Bool #

(/=) :: CBMCExceptT e m a -> CBMCExceptT e m a -> Bool #

(Ord e, Ord1 m, Ord a) => Ord (CBMCExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

compare :: CBMCExceptT e m a -> CBMCExceptT e m a -> Ordering #

(<) :: CBMCExceptT e m a -> CBMCExceptT e m a -> Bool #

(<=) :: CBMCExceptT e m a -> CBMCExceptT e m a -> Bool #

(>) :: CBMCExceptT e m a -> CBMCExceptT e m a -> Bool #

(>=) :: CBMCExceptT e m a -> CBMCExceptT e m a -> Bool #

max :: CBMCExceptT e m a -> CBMCExceptT e m a -> CBMCExceptT e m a #

min :: CBMCExceptT e m a -> CBMCExceptT e m a -> CBMCExceptT e m a #

SEq (m (CBMCEither e a)) => SEq (CBMCExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

(==~) :: CBMCExceptT e m a -> CBMCExceptT e m a -> SymBool Source #

(/=~) :: CBMCExceptT e m a -> CBMCExceptT e m a -> SymBool Source #

EvaluateSym (m (CBMCEither e a)) => EvaluateSym (CBMCExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

evaluateSym :: Bool -> Model -> CBMCExceptT e m a -> CBMCExceptT e m a Source #

ExtractSymbolics (m (CBMCEither e a)) => ExtractSymbolics (CBMCExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

(Mergeable1 m, Mergeable e, Mergeable a) => Mergeable (CBMCExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

SOrd (m (CBMCEither e a)) => SOrd (CBMCExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

(UnionLike m, Mergeable e, Mergeable a) => SimpleMergeable (CBMCExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

mrgIte :: SymBool -> CBMCExceptT e m a -> CBMCExceptT e m a -> CBMCExceptT e m a Source #

(Monad u, UnionLike u, Mergeable e, Mergeable v) => UnionWithExcept (CBMCExceptT e u v) u e v Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

extractUnionExcept :: CBMCExceptT e u v -> u (Either e v) Source #

ToCon (m1 (CBMCEither e1 a)) (Either e2 b) => ToCon (CBMCExceptT e1 m1 a) (Either e2 b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

toCon :: CBMCExceptT e1 m1 a -> Maybe (Either e2 b) Source #

(GenSymSimple (m (CBMCEither e a)) (m (CBMCEither e a)), Mergeable1 m, Mergeable e, Mergeable a) => GenSym (CBMCExceptT e m a) (CBMCExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

fresh :: MonadFresh m0 => CBMCExceptT e m a -> m0 (UnionM (CBMCExceptT e m a)) Source #

GenSymSimple (m (CBMCEither e a)) (m (CBMCEither e a)) => GenSymSimple (CBMCExceptT e m a) (CBMCExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

simpleFresh :: MonadFresh m0 => CBMCExceptT e m a -> m0 (CBMCExceptT e m a) Source #

ToCon (m1 (CBMCEither e1 a)) (m2 (CBMCEither e2 b)) => ToCon (CBMCExceptT e1 m1 a) (CBMCExceptT e2 m2 b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

toCon :: CBMCExceptT e1 m1 a -> Maybe (CBMCExceptT e2 m2 b) Source #

ToSym (m1 (CBMCEither e1 a)) (m2 (CBMCEither e2 b)) => ToSym (CBMCExceptT e1 m1 a) (CBMCExceptT e2 m2 b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

toSym :: CBMCExceptT e1 m1 a -> CBMCExceptT e2 m2 b Source #

type Rep1 (CBMCExceptT e m :: Type -> Type) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

type Rep1 (CBMCExceptT e m :: Type -> Type) = D1 ('MetaData "CBMCExceptT" "Grisette.Core.Control.Monad.CBMCExcept" "grisette-0.1.0.0-7JmpZvRpjzaDDLSSjCfe9O" 'True) (C1 ('MetaCons "CBMCExceptT" 'PrefixI 'True) (S1 ('MetaSel ('Just "runCBMCExceptT") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (m :.: Rec1 (CBMCEither e))))
type Rep (CBMCExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

type Rep (CBMCExceptT e m a) = D1 ('MetaData "CBMCExceptT" "Grisette.Core.Control.Monad.CBMCExcept" "grisette-0.1.0.0-7JmpZvRpjzaDDLSSjCfe9O" 'True) (C1 ('MetaCons "CBMCExceptT" 'PrefixI 'True) (S1 ('MetaSel ('Just "runCBMCExceptT") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (m (CBMCEither e a)))))

cbmcExcept :: Monad m => Either e a -> CBMCExceptT e m a Source #

Wrap an Either value in CBMCExceptT

mapCBMCExceptT :: (m (Either e a) -> n (Either e' b)) -> CBMCExceptT e m a -> CBMCExceptT e' n b Source #

Map the error and values in a CBMCExceptT

withCBMCExceptT :: Functor m => (e -> e') -> CBMCExceptT e m a -> CBMCExceptT e' m a Source #

Map the error in a CBMCExceptT

Solver backend

Grisette abstracts the solver backend with the Solver type class, and the most basic solver call is the solve function.

In the following code, we will search for the integer solutions to two equation systems. The first equation system, as shown below, has the solution (x, y) = (13, -7).

\[ \left\{ \begin{aligned} x + y &= 6 \\ x - y &= 20 \end{aligned} \right. \]

The second equation system, as shown below, has no integer solutions.

\[ \left\{ \begin{aligned} x + y &= 6 \\ x - y &= 19 \end{aligned} \right. \]

>>> import Grisette.IR.SymPrim
>>> import Grisette.Backend.SBV
>>> let x = "x" :: SymInteger
>>> let y = "y" :: SymInteger
>>> solve (UnboundedReasoning z3) (x + y ==~ 6 &&~ x - y ==~ 20)
Right (Model {x -> 13 :: Integer, y -> -7 :: Integer})
>>> solve (UnboundedReasoning z3) (x + y ==~ 6 &&~ x - y ==~ 19)
Left Unsat

The first parameter of solve is the solver configuration. Here it means that we should not perform any approximation, and should use the Z3 solver.

The second parameter is the formula to be solved. It have the type SymBool.

The solve function would return a model if the formula is satisfiable. The model is a mapping from symbolic variables to concrete values, as shown in the following example.

Right (Model {x -> 13 :: Integer, y -> -7 :: Integer})

This model maps x to 13, and y to -7. With this model, we can then evaluate symbolic values. The following code evaluates the product of x and y under the solution of the equation system.

>>> Right m <- solve (UnboundedReasoning z3) (x + y ==~ 6 &&~ x - y ==~ 20)
>>> evaluateSym False m (x * y)
-91

You may notice that the first argument to the evaluateSym function is a Boolean value False. This argument controls whether the evaluation should assign a default value to the symbolic constants that does not appear in the model. When the argument is False, the evaluation would preserve any symbolic constants that does not appear in the model, and partially evaluate the expression. When the argument is True, the evaluation would assign a default value to the symbolic constants that does not appear in the model, e.g., 0 for integers, and the evaluation result would become a concrete value -91.

>>> let z = "z" :: SymInteger
>>> evaluateSym False m (x * y + z)
(+ -91 z)
>>> evaluateSym True m (x * y + z)
-91

Grisette also provides convenient functions to solve problems with error handling. The lambda case function used in the following code means that we would like the solver to find path that would not lead to an error. This is done by mapping left values (failed paths) to false, and right values (successful paths) to true.

The following example finds bugs in a program in the hard way. It is an overkill for such a simple program, but it is a good example to show how to use Grisette to solve problems with error handling.

We can first define the error type used in the program.

>>> :set -XLambdaCase -XDeriveGeneric -XDerivingStrategies -XDerivingVia
>>> import Control.Monad.Except
>>> import Control.Exception
>>> import GHC.Generics
>>> :{
data Error = Arith | Assert
  deriving (Show, Generic)
  deriving (Mergeable, SEq) via (Default Error)
:}

Then we define how to transform the generic errors to the error type.

>>> :{
  instance TransformError ArithException Error where
    transformError _ = Arith
  instance TransformError AssertionError Error where
    transformError _ = Assert
:}

Then we can perform the symbolic evaluation. The divs function throws ArithException when the divisor is 0, which would be transformed to Arith, and the symAssert function would throw AssertionError when the condition is false, which would be transformed to Assert.

>>> let x = "x" :: SymInteger
>>> let y = "y" :: SymInteger
>>> :{
  -- equivalent concrete program:
  -- let x = x `div` y
  -- if z > 0 then assert (x >= y) else return ()
  res :: ExceptT Error UnionM ()
  res = do
    z <- x `divs` y
    mrgIf (z >~ 0) (symAssert (x >=~ y)) (return ())
:}

Then we can ask the solver to find a counter-example that would lead to an assertion violation error, but do not trigger the division by zero error. This can be done by asking the solver to find a path that produce Left Assert.

>>> res
ExceptT {If (|| (= y 0) (&& (< 0 (div x y)) (! (<= y x)))) (If (= y 0) (Left Arith) (Left Assert)) (Right ())}
>>> solveExcept (UnboundedReasoning z3) (==~ Left Assert) res
Right (Model {x -> -6 :: Integer, y -> -3 :: Integer}) -- possible output

Grisette also provide implementation for counter-example guided inductive synthesis (CEGIS) algorithm. See the documentation for CEGISSolver for more details.

Solver interface

class Solver config failure | config -> failure where Source #

A solver interface.

Methods

solve Source #

Arguments

:: config

solver configuration

-> SymBool

formula to solve, the solver will try to make it true

-> IO (Either failure Model) 

Solve a single formula. Find an assignment to it to make it true.

>>> solve (UnboundedReasoning z3) ("a" &&~ ("b" :: SymInteger) ==~ 1)
Right (Model {a -> True :: Bool, b -> 1 :: Integer})
>>> solve (UnboundedReasoning z3) ("a" &&~ nots "a")
Left Unsat

solveMulti Source #

Arguments

:: config

solver configuration

-> Int

maximum number of models to return

-> SymBool

formula to solve, the solver will try to make it true

-> IO [Model] 

Solve a single formula while returning multiple models to make it true. The maximum number of desired models are given.

>>> solveMulti (UnboundedReasoning z3) 4 ("a" ||~ "b")
[Model {a -> True :: Bool, b -> False :: Bool},Model {a -> False :: Bool, b -> True :: Bool},Model {a -> True :: Bool, b -> True :: Bool}]

solveAll Source #

Arguments

:: config

solver configuration

-> SymBool

formula to solve, the solver will try to make it true

-> IO [Model] 

Solve a single formula while returning multiple models to make it true. All models are returned.

>>> solveAll (UnboundedReasoning z3) ("a" ||~ "b")
[Model {a -> True :: Bool, b -> False :: Bool},Model {a -> False :: Bool, b -> True :: Bool},Model {a -> True :: Bool, b -> True :: Bool}]

class UnionWithExcept t u e v | t -> u e v where Source #

A class that abstracts the union-like structures that contains exceptions.

Methods

extractUnionExcept :: t -> u (Either e v) Source #

Extract a union of exceptions and values from the structure.

Instances

Instances details
UnionWithExcept (UnionM (Either e v)) UnionM e v Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

UnionWithExcept (UnionM (CBMCEither e v)) UnionM e v Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

(Monad u, UnionLike u, Mergeable e, Mergeable v) => UnionWithExcept (CBMCExceptT e u v) u e v Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

extractUnionExcept :: CBMCExceptT e u v -> u (Either e v) Source #

UnionWithExcept (ExceptT e u v) u e v Source # 
Instance details

Defined in Grisette.Core.Data.Class.Solver

Methods

extractUnionExcept :: ExceptT e u v -> u (Either e v) Source #

solveExcept Source #

Arguments

:: (UnionWithExcept t u e v, UnionPrjOp u, Functor u, Solver config failure) 
=> config

solver configuration

-> (Either e v -> SymBool)

mapping the results to symbolic boolean formulas, the solver would try to find a model to make the formula true

-> t

the program to be solved, should be a union of exception and values

-> IO (Either failure Model) 

Solver procedure for programs with error handling.

>>> :set -XLambdaCase
>>> import Control.Monad.Except
>>> let x = "x" :: SymInteger
>>> :{
  res :: ExceptT AssertionError UnionM ()
  res = do
    symAssert $ x >~ 0       -- constrain that x is positive
    symAssert $ x <~ 2       -- constrain that x is less than 2
:}
>>> :{
  translate (Left _) = con False -- errors are not desirable
  translate _ = con True         -- non-errors are desirable
:}
>>> solveExcept (UnboundedReasoning z3) translate res
Right (Model {x -> 1 :: Integer})

solveMultiExcept Source #

Arguments

:: (UnionWithExcept t u e v, UnionPrjOp u, Functor u, Solver config failure) 
=> config

solver configuration

-> Int

maximum number of models to return

-> (Either e v -> SymBool)

mapping the results to symbolic boolean formulas, the solver would try to find a model to make the formula true

-> t

the program to be solved, should be a union of exception and values

-> IO [Model] 

Solver procedure for programs with error handling. Would return multiple models if possible.

Counter-example Guided Inductive Synthesis (CEGIS)

class CEGISSolver config failure | config -> failure where Source #

Counter-example guided inductive synthesis (CEGIS) solver interface.

Methods

cegisMultiInputs Source #

Arguments

:: (EvaluateSym inputs, ExtractSymbolics inputs) 
=> config

The configuration of the solver

-> [inputs]

Some initial counter-examples. Providing some concrete inputs may help the solver to find a model faster. Providing symbolic inputs would cause the solver to find the program that works on all the inputs representable by it (see CEGISCondition).

-> (inputs -> CEGISCondition)

The function mapping the inputs to the conditions for the solver to solve.

-> IO (Either failure ([inputs], Model))

The counter-examples generated during the CEGIS loop, and the model found by the solver.

CEGIS with multiple (possibly symbolic) inputs. Solves the following formula (see CEGISCondition for details).

\[ \forall P. (\exists I\in\mathrm{inputs}. \mathrm{pre}(P, I)) \wedge (\forall I\in\mathrm{inputs}. \mathrm{pre}(P, I)\implies \mathrm{post}(P, I)) \]

For simpler queries, where the inputs are representable by a single symbolic value, you may want to use cegis or cegisExcept instead. We have an example for the cegis call.

Instances

Instances details
CEGISSolver (GrisetteSMTConfig n) CheckSatResult Source # 
Instance details

Defined in Grisette.Backend.SBV.Data.SMT.Solving

Methods

cegisMultiInputs :: (EvaluateSym inputs, ExtractSymbolics inputs) => GrisetteSMTConfig n -> [inputs] -> (inputs -> CEGISCondition) -> IO (Either CheckSatResult ([inputs], Model)) Source #

data CEGISCondition Source #

The condition for CEGIS to solve.

The first argument is the pre-condition, and the second argument is the post-condition.

The CEGIS procedures would try to find a model for the formula

\[ \forall P. (\exists I. \mathrm{pre}(P, I)) \wedge (\forall I. \mathrm{pre}(P, I)\implies \mathrm{post}(P, I)) \]

In program synthesis tasks, \(P\) is the symbolic constants in the symbolic program, and \(I\) is the input. The pre-condition is used to restrict the search space of the program. The procedure would only return programs that meets the pre-conditions on every possible inputs, and there are at least one possible input. The post-condition is used to specify the desired program behaviors.

cegisPostCond :: SymBool -> CEGISCondition Source #

Construct a CEGIS condition with only a post-condition. The pre-condition would be set to true, meaning that all programs in the program space are allowed.

cegisPrePost :: SymBool -> SymBool -> CEGISCondition Source #

Construct a CEGIS condition with both pre- and post-conditions.

cegis Source #

Arguments

:: (CEGISSolver config failure, EvaluateSym inputs, ExtractSymbolics inputs) 
=> config

The configuration of the solver

-> inputs

Initial symbolic inputs. The solver will try to find a program that works on all the inputs representable by it (see CEGISCondition).

-> CEGISCondition

The condition for the solver to solve. All the symbolic constants that are not in the inputs will be considered as part of the symbolic program.

-> IO (Either failure ([inputs], Model))

The counter-examples generated during the CEGIS loop, and the model found by the solver.

CEGIS with a single symbolic input to represent a set of inputs.

The following example tries to find the value of c such that for all positive x, x * c && c -2. The c >~ -2 clause is used to make the solution unique.

>>> :set -XOverloadedStrings
>>> let [x,c] = ["x","c"] :: [SymInteger]
>>> cegis (UnboundedReasoning z3) x (cegisPrePost (x >~ 0) (x * c <~ 0 &&~ c >~ -2))
Right ([],Model {c -> -1 :: Integer})

cegisExcept :: (UnionWithExcept t u e v, UnionPrjOp u, Functor u, EvaluateSym inputs, ExtractSymbolics inputs, CEGISSolver config failure) => config -> inputs -> (Either e v -> CEGISCondition) -> t -> IO (Either failure ([inputs], Model)) Source #

CEGIS for symbolic programs with error handling, using a single symbolic input to represent a set of inputs.

cegisExcept is particularly useful when custom error types are used. With cegisExcept, you define how the errors are interpreted to the CEGIS conditions after the symbolic evaluation. This could increase the readability and modularity of the code.

The following example tries to find the value of c such that for all positive x, x * c && c -2. The c >~ -2 assertion is used to make the solution unique.

>>> :set -XOverloadedStrings
>>> let [x,c] = ["x","c"] :: [SymInteger]
>>> import Control.Monad.Except
>>> :{
  res :: ExceptT VerificationConditions UnionM ()
  res = do
    symAssume $ x >~ 0
    symAssert $ x * c <~ 0
    symAssert $ c >~ -2
:}
>>> :{
  translation (Left AssumptionViolation) = cegisPrePost (con False) (con True)
  translation (Left AssertionViolation) = cegisPostCond (con False)
  translation _ = cegisPostCond (con True)
:}
>>> cegisExcept (UnboundedReasoning z3) x translation res
Right ([],Model {c -> -1 :: Integer})

cegisExceptStdVC :: (UnionWithExcept t u VerificationConditions (), UnionPrjOp u, Monad u, EvaluateSym inputs, ExtractSymbolics inputs, CEGISSolver config failure) => config -> inputs -> t -> IO (Either failure ([inputs], Model)) Source #

CEGIS for symbolic programs with error handling, using a single symbolic input to represent a set of inputs. This function saves the efforts to implement the translation function for the standard error type VerificationConditions, and the standard result type ().

This function translates assumption violations to failed pre-conditions, and translates assertion violations to failed post-conditions. The () result will not fail any conditions.

The following example tries to find the value of c such that for all positive x, x * c && c -2. The c >~ -2 assertion is used to make the solution unique.

>>> :set -XOverloadedStrings
>>> let [x,c] = ["x","c"] :: [SymInteger]
>>> import Control.Monad.Except
>>> :{
  res :: ExceptT VerificationConditions UnionM ()
  res = do
    symAssume $ x >~ 0
    symAssert $ x * c <~ 0
    symAssert $ c >~ -2
:}
>>> cegisExceptStdVC (UnboundedReasoning z3) x res
Right ([],Model {c -> -1 :: Integer})

cegisExceptVC :: (UnionWithExcept t u e v, UnionPrjOp u, Monad u, EvaluateSym inputs, ExtractSymbolics inputs, CEGISSolver config failure) => config -> inputs -> (Either e v -> u (Either VerificationConditions ())) -> t -> IO (Either failure ([inputs], Model)) Source #

CEGIS for symbolic programs with error handling, using a single symbolic input to represent a set of inputs.

The errors should be translated to assertion or assumption violations.

cegisExceptMultiInputs :: (CEGISSolver config failure, EvaluateSym inputs, ExtractSymbolics inputs, UnionWithExcept t u e v, UnionPrjOp u, Monad u) => config -> [inputs] -> (Either e v -> CEGISCondition) -> (inputs -> t) -> IO (Either failure ([inputs], Model)) Source #

CEGIS for symbolic programs with error handling, using multiple (possibly symbolic) inputs to represent a set of inputs.

cegisExceptStdVCMultiInputs :: (CEGISSolver config failure, EvaluateSym inputs, ExtractSymbolics inputs, UnionWithExcept t u VerificationConditions (), UnionPrjOp u, Monad u) => config -> [inputs] -> (inputs -> t) -> IO (Either failure ([inputs], Model)) Source #

CEGIS for symbolic programs with error handling, using multiple (possibly symbolic) inputs to represent a set of inputs. This function saves the efforts to implement the translation function for the standard error type VerificationConditions, and the standard result type ().

This function translates assumption violations to failed pre-conditions, and translates assertion violations to failed post-conditions. The () result will not fail any conditions.

cegisExceptVCMultiInputs :: (CEGISSolver config failure, EvaluateSym inputs, ExtractSymbolics inputs, UnionWithExcept t u e v, UnionPrjOp u, Monad u) => config -> [inputs] -> (Either e v -> u (Either VerificationConditions ())) -> (inputs -> t) -> IO (Either failure ([inputs], Model)) Source #

CEGIS for symbolic programs with error handling, using multiple (possibly symbolic) inputs to represent a set of inputs.

The errors should be translated to assertion or assumption violations.

Symbolic constant extraction

class Monoid symbolSet => SymbolSetOps symbolSet (typedSymbol :: Type -> Type) | symbolSet -> typedSymbol where Source #

The operations on symbolic constant sets

Note that symbolic constants with different types are considered different.

>>> let aBool = "a" :: TypedSymbol Bool
>>> let bBool = "b" :: TypedSymbol Bool
>>> let cBool = "c" :: TypedSymbol Bool
>>> let aInteger = "a" :: TypedSymbol Integer
>>> emptySet :: SymbolSet
SymbolSet {}
>>> containsSymbol aBool (buildSymbolSet aBool :: SymbolSet)
True
>>> containsSymbol bBool (buildSymbolSet aBool :: SymbolSet)
False
>>> insertSymbol aBool (buildSymbolSet aBool :: SymbolSet)
SymbolSet {a :: Bool}
>>> insertSymbol aInteger (buildSymbolSet aBool :: SymbolSet)
SymbolSet {a :: Bool, a :: Integer}
>>> let abSet = buildSymbolSet (aBool, bBool) :: SymbolSet
>>> let acSet = buildSymbolSet (aBool, cBool) :: SymbolSet
>>> intersectionSet abSet acSet
SymbolSet {a :: Bool}
>>> unionSet abSet acSet
SymbolSet {a :: Bool, b :: Bool, c :: Bool}
>>> differenceSet abSet acSet
SymbolSet {b :: Bool}

Methods

emptySet :: symbolSet Source #

Construct an empty set

isEmptySet :: symbolSet -> Bool Source #

Check if the set is empty

containsSymbol :: forall a. typedSymbol a -> symbolSet -> Bool Source #

Check if the set contains the given symbol

insertSymbol :: forall a. typedSymbol a -> symbolSet -> symbolSet Source #

Insert a symbol into the set

intersectionSet :: symbolSet -> symbolSet -> symbolSet Source #

Set intersection

unionSet :: symbolSet -> symbolSet -> symbolSet Source #

Set union

differenceSet :: symbolSet -> symbolSet -> symbolSet Source #

Set difference

class SymbolSetOps symbolSet typedSymbol => SymbolSetRep rep symbolSet (typedSymbol :: * -> *) where Source #

A type class for building a symbolic constant set manually from a symbolic constant set representation

>>> buildSymbolSet ("a" :: TypedSymbol Bool, "b" :: TypedSymbol Bool) :: SymbolSet
SymbolSet {a :: Bool, b :: Bool}

Methods

buildSymbolSet :: rep -> symbolSet Source #

Build a symbolic constant set

Instances

Instances details
SymbolSetRep (TypedSymbol t) SymbolSet TypedSymbol Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.Prim.Model

SymbolSetRep (TypedSymbol a, TypedSymbol b) SymbolSet TypedSymbol Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.Prim.Model

SymbolSetRep (TypedSymbol a, TypedSymbol b, TypedSymbol c) SymbolSet TypedSymbol Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.Prim.Model

SymbolSetRep (TypedSymbol a, TypedSymbol b, TypedSymbol c, TypedSymbol d) SymbolSet TypedSymbol Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.Prim.Model

SymbolSetRep (TypedSymbol a, TypedSymbol b, TypedSymbol c, TypedSymbol d, TypedSymbol e) SymbolSet TypedSymbol Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.Prim.Model

SymbolSetRep (TypedSymbol a, TypedSymbol b, TypedSymbol c, TypedSymbol d, TypedSymbol e, TypedSymbol f) SymbolSet TypedSymbol Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.Prim.Model

SymbolSetRep (TypedSymbol a, TypedSymbol b, TypedSymbol c, TypedSymbol d, TypedSymbol e, TypedSymbol f, TypedSymbol g) SymbolSet TypedSymbol Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.Prim.Model

SymbolSetRep (TypedSymbol a, TypedSymbol b, TypedSymbol c, TypedSymbol d, TypedSymbol e, TypedSymbol f, TypedSymbol g, TypedSymbol h) SymbolSet TypedSymbol Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.Prim.Model

class ExtractSymbolics a where Source #

Extracts all the symbolic variables that are transitively contained in the given value.

>>> extractSymbolics ("a" :: SymBool) :: SymbolSet
SymbolSet {a :: Bool}
>>> extractSymbolics (mrgIf "a" (mrgReturn ["b"]) (mrgReturn ["c", "d"]) :: UnionM [SymBool]) :: SymbolSet
SymbolSet {a :: Bool, b :: Bool, c :: Bool, d :: Bool}

Note 1: This type class can be derived for algebraic data types. You may need the DerivingVia and DerivingStrategies extensions.

data X = ... deriving Generic deriving ExtractSymbolics via (Default X)

Instances

Instances details
ExtractSymbolics Int16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

ExtractSymbolics Int32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

ExtractSymbolics Int64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

ExtractSymbolics Int8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

ExtractSymbolics Word16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

ExtractSymbolics Word32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

ExtractSymbolics Word64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

ExtractSymbolics ByteString Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

ExtractSymbolics AssertionError Source # 
Instance details

Defined in Grisette.Core.Control.Exception

ExtractSymbolics VerificationConditions Source # 
Instance details

Defined in Grisette.Core.Control.Exception

ExtractSymbolics SymbolSet Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.Prim.Model

ExtractSymbolics Word8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

ExtractSymbolics Integer Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

ExtractSymbolics () Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

ExtractSymbolics Bool Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

ExtractSymbolics Char Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

ExtractSymbolics Int Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

ExtractSymbolics Word Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

ExtractSymbolics a => ExtractSymbolics (Identity a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

(Generic a, ExtractSymbolics' (Rep a)) => ExtractSymbolics (Default a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

ExtractSymbolics a => ExtractSymbolics (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

SupportedPrim a => ExtractSymbolics (Sym a) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ExtractSymbolics a => ExtractSymbolics (Maybe a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

ExtractSymbolics a => ExtractSymbolics [a] Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

(ExtractSymbolics a, ExtractSymbolics b) => ExtractSymbolics (Either a b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

(ExtractSymbolics a, ExtractSymbolics b) => ExtractSymbolics (CBMCEither a b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

ExtractSymbolics (m (Maybe a)) => ExtractSymbolics (MaybeT m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

(ExtractSymbolics a, ExtractSymbolics b) => ExtractSymbolics (a, b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

Methods

extractSymbolics :: (a, b) -> SymbolSet Source #

ExtractSymbolics (m (CBMCEither e a)) => ExtractSymbolics (CBMCExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

ExtractSymbolics (m (Either e a)) => ExtractSymbolics (ExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

ExtractSymbolics (m a) => ExtractSymbolics (IdentityT m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

ExtractSymbolics (m (a, s)) => ExtractSymbolics (WriterT s m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

ExtractSymbolics (m (a, s)) => ExtractSymbolics (WriterT s m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

(ExtractSymbolics a, ExtractSymbolics b, ExtractSymbolics c) => ExtractSymbolics (a, b, c) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

Methods

extractSymbolics :: (a, b, c) -> SymbolSet Source #

(ExtractSymbolics (f a), ExtractSymbolics (g a)) => ExtractSymbolics (Sum f g a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

Evaluation with a model

When given a satisfiable formula, a solver can return a model that specifies the concrete assignments of the variables in the formula to make the formula true. We can use this model to evaluate some symbolic values by substituting the symbolic constants with the concrete assignments.

class SymbolSetOps symbolSet typedSymbol => ModelOps model symbolSet typedSymbol | model -> symbolSet typedSymbol where Source #

The operations on Models.

Note that symbolic constants with different types are considered different.

>>> let aBool = "a" :: TypedSymbol Bool
>>> let bBool = "b" :: TypedSymbol Bool
>>> let cBool = "c" :: TypedSymbol Bool
>>> let aInteger = "a" :: TypedSymbol Integer
>>> emptyModel :: Model
Model {}
>>> valueOf aBool (buildModel (aBool ::= True) :: Model)
Just True
>>> valueOf bBool (buildModel (aBool ::= True) :: Model)
Nothing
>>> insertValue bBool False (buildModel (aBool ::= True) :: Model)
Model {a -> True :: Bool, b -> False :: Bool}
>>> let abModel = buildModel (aBool ::= True, bBool ::= False) :: Model
>>> let acSet = buildSymbolSet (aBool, cBool) :: SymbolSet
>>> exceptFor acSet abModel
Model {b -> False :: Bool}
>>> restrictTo acSet abModel
Model {a -> True :: Bool}
>>> extendTo acSet abModel
Model {a -> True :: Bool, b -> False :: Bool, c -> False :: Bool}
>>> exact acSet abModel
Model {a -> True :: Bool, c -> False :: Bool}

Methods

emptyModel :: model Source #

Construct an empty model

isEmptyModel :: model -> Bool Source #

Check if the model is empty

valueOf :: typedSymbol t -> model -> Maybe t Source #

Extract the assigned value for a given symbolic constant

insertValue :: typedSymbol t -> t -> model -> model Source #

Insert an assignment into the model

exceptFor :: symbolSet -> model -> model Source #

Returns a model that removed all the assignments for the symbolic constants in the set

restrictTo :: symbolSet -> model -> model Source #

Returns a model that only keeps the assignments for the symbolic constants in the set

extendTo :: symbolSet -> model -> model Source #

Returns a model that extends the assignments for the symbolic constants in the set by assigning default values to them

exact :: symbolSet -> model -> model Source #

Returns a model that contains the assignments for exactly the symbolic constants in the set by removing assignments for the symbolic constants that are not in the set and add assignments for the missing symbolic constants by assigning default values to them.

class ModelOps model symbolSet typedSymbol => ModelRep rep model symbolSet (typedSymbol :: * -> *) where Source #

A type class for building a model manually from a model representation

Methods

buildModel :: rep -> model Source #

Build a model

>>> let aBool = "a" :: TypedSymbol Bool
>>> let bBool = "b" :: TypedSymbol Bool
>>> buildModel (aBool ::= True, bBool ::= False) :: Model
Model {a -> True :: Bool, b -> False :: Bool}

Instances

Instances details
ModelRep (ModelValuePair t) Model SymbolSet TypedSymbol Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.Prim.Model

ModelRep (ModelSymPair t) Model SymbolSet TypedSymbol Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ModelRep (ModelValuePair a, ModelValuePair b) Model SymbolSet TypedSymbol Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.Prim.Model

ModelRep (ModelSymPair a, ModelSymPair b) Model SymbolSet TypedSymbol Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ModelRep (ModelValuePair a, ModelValuePair b, ModelValuePair c) Model SymbolSet TypedSymbol Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.Prim.Model

ModelRep (ModelSymPair a, ModelSymPair b, ModelSymPair c) Model SymbolSet TypedSymbol Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ModelRep (ModelValuePair a, ModelValuePair b, ModelValuePair c, ModelValuePair d) Model SymbolSet TypedSymbol Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.Prim.Model

ModelRep (ModelSymPair a, ModelSymPair b, ModelSymPair c, ModelSymPair d) Model SymbolSet TypedSymbol Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ModelRep (ModelValuePair a, ModelValuePair b, ModelValuePair c, ModelValuePair d, ModelValuePair e) Model SymbolSet TypedSymbol Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.Prim.Model

ModelRep (ModelSymPair a, ModelSymPair b, ModelSymPair c, ModelSymPair d, ModelSymPair e) Model SymbolSet TypedSymbol Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ModelRep (ModelValuePair a, ModelValuePair b, ModelValuePair c, ModelValuePair d, ModelValuePair e, ModelValuePair f) Model SymbolSet TypedSymbol Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.Prim.Model

ModelRep (ModelSymPair a, ModelSymPair b, ModelSymPair c, ModelSymPair d, ModelSymPair e, ModelSymPair f) Model SymbolSet TypedSymbol Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ModelRep (ModelValuePair a, ModelValuePair b, ModelValuePair c, ModelValuePair d, ModelValuePair e, ModelValuePair f, ModelValuePair g) Model SymbolSet TypedSymbol Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.Prim.Model

ModelRep (ModelSymPair a, ModelSymPair b, ModelSymPair c, ModelSymPair d, ModelSymPair e, ModelSymPair f, ModelSymPair g) Model SymbolSet TypedSymbol Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ModelRep (ModelValuePair a, ModelValuePair b, ModelValuePair c, ModelValuePair d, ModelValuePair e, ModelValuePair f, ModelValuePair g, ModelValuePair h) Model SymbolSet TypedSymbol Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.Prim.Model

ModelRep (ModelSymPair a, ModelSymPair b, ModelSymPair c, ModelSymPair d, ModelSymPair e, ModelSymPair f, ModelSymPair g, ModelSymPair h) Model SymbolSet TypedSymbol Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

class EvaluateSym a where Source #

Evaluating symbolic values with some model.

>>> let model = insertValue (SimpleSymbol "a") (1 :: Integer) emptyModel :: Model
>>> evaluateSym False model ([ssym "a", ssym "b"] :: [SymInteger])
[1,b]

If we set the first argument true, the missing variables will be filled in with some default values:

>>> evaluateSym True model ([ssym "a", ssym "b"] :: [SymInteger])
[1,0]

Note 1: This type class can be derived for algebraic data types. You may need the DerivingVia and DerivingStrategies extensions.

data X = ... deriving Generic deriving EvaluateSym via (Default X)

Methods

evaluateSym :: Bool -> Model -> a -> a Source #

Evaluate a symbolic variable with some model, possibly fill in values for the missing variables.

Instances

Instances details
EvaluateSym Int16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> Int16 -> Int16 Source #

EvaluateSym Int32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> Int32 -> Int32 Source #

EvaluateSym Int64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> Int64 -> Int64 Source #

EvaluateSym Int8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> Int8 -> Int8 Source #

EvaluateSym Word16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

EvaluateSym Word32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

EvaluateSym Word64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

EvaluateSym ByteString Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

EvaluateSym AssertionError Source # 
Instance details

Defined in Grisette.Core.Control.Exception

EvaluateSym VerificationConditions Source # 
Instance details

Defined in Grisette.Core.Control.Exception

EvaluateSym Word8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> Word8 -> Word8 Source #

EvaluateSym Integer Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

EvaluateSym () Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> () -> () Source #

EvaluateSym Bool Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> Bool -> Bool Source #

EvaluateSym Char Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> Char -> Char Source #

EvaluateSym Int Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> Int -> Int Source #

EvaluateSym Word Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> Word -> Word Source #

EvaluateSym a => EvaluateSym (Identity a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> Identity a -> Identity a Source #

(Generic a, EvaluateSym' (Rep a)) => EvaluateSym (Default a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> Default a -> Default a Source #

(Mergeable a, EvaluateSym a) => EvaluateSym (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

evaluateSym :: Bool -> Model -> UnionM a -> UnionM a Source #

SupportedPrim a => EvaluateSym (Sym a) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

evaluateSym :: Bool -> Model -> Sym a -> Sym a Source #

EvaluateSym a => EvaluateSym (Maybe a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> Maybe a -> Maybe a Source #

EvaluateSym a => EvaluateSym [a] Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> [a] -> [a] Source #

(EvaluateSym a, EvaluateSym b) => EvaluateSym (Either a b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> Either a b -> Either a b Source #

(EvaluateSym a, EvaluateSym b) => EvaluateSym (CBMCEither a b) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

evaluateSym :: Bool -> Model -> CBMCEither a b -> CBMCEither a b Source #

EvaluateSym (m (Maybe a)) => EvaluateSym (MaybeT m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> MaybeT m a -> MaybeT m a Source #

(EvaluateSym a, EvaluateSym b) => EvaluateSym (a, b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> (a, b) -> (a, b) Source #

EvaluateSym (m (CBMCEither e a)) => EvaluateSym (CBMCExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.CBMCExcept

Methods

evaluateSym :: Bool -> Model -> CBMCExceptT e m a -> CBMCExceptT e m a Source #

EvaluateSym (m (Either e a)) => EvaluateSym (ExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> ExceptT e m a -> ExceptT e m a Source #

EvaluateSym (m a) => EvaluateSym (IdentityT m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> IdentityT m a -> IdentityT m a Source #

EvaluateSym (m (a, s)) => EvaluateSym (WriterT s m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> WriterT s m a -> WriterT s m a Source #

EvaluateSym (m (a, s)) => EvaluateSym (WriterT s m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> WriterT s m a -> WriterT s m a Source #

(EvaluateSym a, EvaluateSym b, EvaluateSym c) => EvaluateSym (a, b, c) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> (a, b, c) -> (a, b, c) Source #

(EvaluateSym (f a), EvaluateSym (g a)) => EvaluateSym (Sum f g a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> Sum f g a -> Sum f g a Source #

(EvaluateSym a, EvaluateSym b, EvaluateSym c, EvaluateSym d) => EvaluateSym (a, b, c, d) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> (a, b, c, d) -> (a, b, c, d) Source #

(EvaluateSym a, EvaluateSym b, EvaluateSym c, EvaluateSym d, EvaluateSym e) => EvaluateSym (a, b, c, d, e) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> (a, b, c, d, e) -> (a, b, c, d, e) Source #

(EvaluateSym a, EvaluateSym b, EvaluateSym c, EvaluateSym d, EvaluateSym e, EvaluateSym f) => EvaluateSym (a, b, c, d, e, f) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> (a, b, c, d, e, f) -> (a, b, c, d, e, f) Source #

(EvaluateSym a, EvaluateSym b, EvaluateSym c, EvaluateSym d, EvaluateSym e, EvaluateSym f, EvaluateSym g) => EvaluateSym (a, b, c, d, e, f, g) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) Source #

(EvaluateSym a, EvaluateSym b, EvaluateSym c, EvaluateSym d, EvaluateSym e, EvaluateSym f, EvaluateSym g, EvaluateSym h) => EvaluateSym (a, b, c, d, e, f, g, h) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) Source #

evaluateSymToCon :: (ToCon a b, EvaluateSym a) => Model -> a -> b Source #

Evaluate a symbolic variable with some model, fill in values for the missing variables, and transform to concrete ones

>>> let model = insertValue (SimpleSymbol "a") (1 :: Integer) emptyModel :: Model
>>> evaluateSymToCon model ([ssym "a", ssym "b"] :: [SymInteger]) :: [Integer]
[1,0]

Substitution of a symbol

class SubstituteSym a where Source #

Substitution of symbolic constants.

>>> a = "a" :: TypedSymbol Bool
>>> v = "x" &&~ "y" :: SymBool
>>> substituteSym a v (["a" &&~ "b", "a"] :: [SymBool])
[(&& (&& x y) b),(&& x y)]

Note 1: This type class can be derived for algebraic data types. You may need the DerivingVia and DerivingStrategies extensions.

data X = ... deriving Generic deriving SubstituteSym via (Default X)

Methods

substituteSym :: TypedSymbol b -> Sym b -> a -> a Source #

Instances

Instances details
SubstituteSym Int16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

SubstituteSym Int32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

SubstituteSym Int64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

SubstituteSym Int8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: TypedSymbol b -> Sym b -> Int8 -> Int8 Source #

SubstituteSym Word16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

SubstituteSym Word32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

SubstituteSym Word64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

SubstituteSym ByteString Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

SubstituteSym Word8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

SubstituteSym Integer Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

SubstituteSym () Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: TypedSymbol b -> Sym b -> () -> () Source #

SubstituteSym Bool Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: TypedSymbol b -> Sym b -> Bool -> Bool Source #

SubstituteSym Char Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: TypedSymbol b -> Sym b -> Char -> Char Source #

SubstituteSym Int Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: TypedSymbol b -> Sym b -> Int -> Int Source #

SubstituteSym Word Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: TypedSymbol b -> Sym b -> Word -> Word Source #

SubstituteSym a => SubstituteSym (Identity a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

(Generic a, SubstituteSym' (Rep a)) => SubstituteSym (Default a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: TypedSymbol b -> Sym b -> Default a -> Default a Source #

(Mergeable a, SubstituteSym a) => SubstituteSym (UnionM a) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

substituteSym :: TypedSymbol b -> Sym b -> UnionM a -> UnionM a Source #

SubstituteSym (Sym a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: TypedSymbol b -> Sym b -> Sym a -> Sym a Source #

SubstituteSym a => SubstituteSym (Maybe a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: TypedSymbol b -> Sym b -> Maybe a -> Maybe a Source #

SubstituteSym a => SubstituteSym [a] Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: TypedSymbol b -> Sym b -> [a] -> [a] Source #

(SubstituteSym a, SubstituteSym b) => SubstituteSym (Either a b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: TypedSymbol b0 -> Sym b0 -> Either a b -> Either a b Source #

SubstituteSym (m (Maybe a)) => SubstituteSym (MaybeT m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: TypedSymbol b -> Sym b -> MaybeT m a -> MaybeT m a Source #

(SubstituteSym a, SubstituteSym b) => SubstituteSym (a, b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: TypedSymbol b0 -> Sym b0 -> (a, b) -> (a, b) Source #

SubstituteSym (m (Either e a)) => SubstituteSym (ExceptT e m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: TypedSymbol b -> Sym b -> ExceptT e m a -> ExceptT e m a Source #

SubstituteSym (m a) => SubstituteSym (IdentityT m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: TypedSymbol b -> Sym b -> IdentityT m a -> IdentityT m a Source #

SubstituteSym (m (a, s)) => SubstituteSym (WriterT s m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: TypedSymbol b -> Sym b -> WriterT s m a -> WriterT s m a Source #

SubstituteSym (m (a, s)) => SubstituteSym (WriterT s m a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: TypedSymbol b -> Sym b -> WriterT s m a -> WriterT s m a Source #

(SubstituteSym a, SubstituteSym b, SubstituteSym c) => SubstituteSym (a, b, c) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: TypedSymbol b0 -> Sym b0 -> (a, b, c) -> (a, b, c) Source #

(SubstituteSym (f a), SubstituteSym (g a)) => SubstituteSym (Sum f g a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: TypedSymbol b -> Sym b -> Sum f g a -> Sum f g a Source #

(SubstituteSym a, SubstituteSym b, SubstituteSym c, SubstituteSym d) => SubstituteSym (a, b, c, d) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: TypedSymbol b0 -> Sym b0 -> (a, b, c, d) -> (a, b, c, d) Source #

(SubstituteSym a, SubstituteSym b, SubstituteSym c, SubstituteSym d, SubstituteSym e) => SubstituteSym (a, b, c, d, e) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: TypedSymbol b0 -> Sym b0 -> (a, b, c, d, e) -> (a, b, c, d, e) Source #

(SubstituteSym a, SubstituteSym b, SubstituteSym c, SubstituteSym d, SubstituteSym e, SubstituteSym f) => SubstituteSym (a, b, c, d, e, f) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: TypedSymbol b0 -> Sym b0 -> (a, b, c, d, e, f) -> (a, b, c, d, e, f) Source #

(SubstituteSym a, SubstituteSym b, SubstituteSym c, SubstituteSym d, SubstituteSym e, SubstituteSym f, SubstituteSym g) => SubstituteSym (a, b, c, d, e, f, g) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: TypedSymbol b0 -> Sym b0 -> (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) Source #

(SubstituteSym a, SubstituteSym b, SubstituteSym c, SubstituteSym d, SubstituteSym e, SubstituteSym f, SubstituteSym g, SubstituteSym h) => SubstituteSym (a, b, c, d, e, f, g, h) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: TypedSymbol b0 -> Sym b0 -> (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) Source #

class SubstituteSym' a where Source #

Auxiliary class for SubstituteSym instance derivation

Methods

substituteSym' :: TypedSymbol b -> Sym b -> a c -> a c Source #

Auxiliary function for substituteSym derivation

Instances

Instances details
SubstituteSym' (U1 :: Type -> Type) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym' :: TypedSymbol b -> Sym b -> U1 c -> U1 c Source #

(SubstituteSym' a, SubstituteSym' b) => SubstituteSym' (a :*: b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym' :: TypedSymbol b0 -> Sym b0 -> (a :*: b) c -> (a :*: b) c Source #

(SubstituteSym' a, SubstituteSym' b) => SubstituteSym' (a :+: b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym' :: TypedSymbol b0 -> Sym b0 -> (a :+: b) c -> (a :+: b) c Source #

SubstituteSym c => SubstituteSym' (K1 i c :: Type -> Type) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym' :: TypedSymbol b -> Sym b -> K1 i c c0 -> K1 i c c0 Source #

SubstituteSym' a => SubstituteSym' (M1 i c a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym' :: TypedSymbol b -> Sym b -> M1 i c a c0 -> M1 i c a c0 Source #

Type Class Derivation

newtype Default a #

This newtype wrapper can be used to derive default instances for classes taking an argument of kind Type.

Constructors

Default 

Fields

Instances

Instances details
(Generic a, Generic b, ToCon' (Rep a) (Rep b)) => ToCon a (Default b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: a -> Maybe (Default b) Source #

(Generic a, Generic b, ToSym' (Rep a) (Rep b)) => ToSym a (Default b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: a -> Default b Source #

(Generic a, GEq a, Enum' (Rep a)) => GEnum (Default a)

The Enum class in base is slightly different; it comprises toEnum and fromEnum. Generics.Deriving.Enum provides functions toEnumDefault and fromEnumDefault.

Instance details

Defined in Generics.Deriving.Default

Methods

genum :: [Default a] #

(Generic a, GEq' (Rep a)) => GEq (Default a) 
Instance details

Defined in Generics.Deriving.Default

Methods

geq :: Default a -> Default a -> Bool #

(Generic a, GMonoid' (Rep a)) => GMonoid (Default a) 
Instance details

Defined in Generics.Deriving.Default

Methods

gmempty :: Default a #

gmappend :: Default a -> Default a -> Default a #

gmconcat :: [Default a] -> Default a #

(Generic a, GSemigroup' (Rep a)) => GSemigroup (Default a)

Semigroups often have many sensible implementations of <> / gsappend, and therefore no sensible default. Indeed, there is no GSemigroup' instance for representations of sum types.

In other cases, one may wish to use the existing wrapper newtypes in base, such as the following (using First):

newtype FirstSemigroup = FirstSemigroup Bool
  deriving stock (Eq, Show)
  deriving (GSemigroup) via (First Bool)
Instance details

Defined in Generics.Deriving.Default

Methods

gsappend :: Default a -> Default a -> Default a #

gstimes :: Integral b => b -> Default a -> Default a #

gsconcat :: NonEmpty (Default a) -> Default a #

(Generic a, GShow' (Rep a)) => GShow (Default a)

For example, with this type:

newtype TestShow = TestShow Bool
  deriving (GShow) via (Default Bool)

gshow for TestShow would produce the same string as gshow for Bool.

In this example, TestShow requires no Generic instance, as the constraint on gshowsPrec from Default Bool is Generic Bool.

In general, when using a newtype wrapper, the instance can be derived via the wrapped type, as here (via Default Bool rather than Default TestShow).

Instance details

Defined in Generics.Deriving.Default

(Generic a, Uniplate' (Rep a) a, Context' (Rep a) a) => Uniplate (Default a) 
Instance details

Defined in Generics.Deriving.Default

Methods

children :: Default a -> [Default a] #

context :: Default a -> [Default a] -> Default a #

descend :: (Default a -> Default a) -> Default a -> Default a #

descendM :: Monad m => (Default a -> m (Default a)) -> Default a -> m (Default a) #

transform :: (Default a -> Default a) -> Default a -> Default a #

transformM :: Monad m => (Default a -> m (Default a)) -> Default a -> m (Default a) #

(Generic a, SEq' (Rep a)) => SEq (Default a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

(Generic a, EvaluateSym' (Rep a)) => EvaluateSym (Default a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> Default a -> Default a Source #

(Generic a, ExtractSymbolics' (Rep a)) => ExtractSymbolics (Default a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

(Generic a, Mergeable' (Rep a)) => Mergeable (Default a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(SEq a, Generic a, SOrd' (Rep a)) => SOrd (Default a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

(Generic a, Mergeable' (Rep a), SimpleMergeable' (Rep a)) => SimpleMergeable (Default a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> Default a -> Default a -> Default a Source #

(Generic a, SubstituteSym' (Rep a)) => SubstituteSym (Default a) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: TypedSymbol b -> Sym b -> Default a -> Default a Source #

newtype Default1 (f :: Type -> Type) a #

This newtype wrapper can be used to derive default instances for classes taking an argument of kind Type -> Type.

Constructors

Default1 

Fields

Instances

Instances details
(Generic1 f, GCopoint' (Rep1 f)) => GCopoint (Default1 f) 
Instance details

Defined in Generics.Deriving.Default

Methods

gcopoint :: Default1 f a -> a #

(Generic1 t, GFoldable' (Rep1 t)) => GFoldable (Default1 t) 
Instance details

Defined in Generics.Deriving.Default

Methods

gfoldMap :: Monoid m => (a -> m) -> Default1 t a -> m #

gfold :: Monoid m => Default1 t m -> m #

gfoldr :: (a -> b -> b) -> b -> Default1 t a -> b #

gfoldr' :: (a -> b -> b) -> b -> Default1 t a -> b #

gfoldl :: (a -> b -> a) -> a -> Default1 t b -> a #

gfoldl' :: (a -> b -> a) -> a -> Default1 t b -> a #

gfoldr1 :: (a -> a -> a) -> Default1 t a -> a #

gfoldl1 :: (a -> a -> a) -> Default1 t a -> a #

(Generic1 f, GFunctor' (Rep1 f)) => GFunctor (Default1 f) 
Instance details

Defined in Generics.Deriving.Default

Methods

gmap :: (a -> b) -> Default1 f a -> Default1 f b #

(Generic1 t, GFunctor' (Rep1 t), GFoldable' (Rep1 t), GTraversable' (Rep1 t)) => GTraversable (Default1 t) 
Instance details

Defined in Generics.Deriving.Default

Methods

gtraverse :: Applicative f => (a -> f b) -> Default1 t a -> f (Default1 t b) #

gsequenceA :: Applicative f => Default1 t (f a) -> f (Default1 t a) #

gmapM :: Monad m => (a -> m b) -> Default1 t a -> m (Default1 t b) #

gsequence :: Monad m => Default1 t (m a) -> m (Default1 t a) #

(Generic1 u, Mergeable1' (Rep1 u)) => Mergeable1 (Default1 u) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Utilities

Memoization

htmemo :: (Eq k, Hashable k) => (k -> a) -> k -> a Source #

Function memoizer with mutable hash table.

htmemo2 :: (Eq k1, Hashable k1, Eq k2, Hashable k2) => (k1 -> k2 -> a) -> k1 -> k2 -> a Source #

Function memoizer with mutable hash table. Works on binary functions.

htmemo3 :: (Eq k1, Hashable k1, Eq k2, Hashable k2, Eq k3, Hashable k3) => (k1 -> k2 -> k3 -> a) -> k1 -> k2 -> k3 -> a Source #

Function memoizer with mutable hash table. Works on ternary functions.

htmup :: (Eq k, Hashable k) => (b -> c) -> (k -> b) -> k -> c Source #

Lift a memoizer to work with one more argument.

htmemoFix :: (Eq k, Hashable k) => ((k -> a) -> k -> a) -> k -> a Source #

Memoizing recursion. Use like fix.

Bundled Constructor Wrappers

mrgTuple2 :: forall (a :: Type) (b :: Type). Mergeable (a, b) => a -> b -> UnionM (a, b) Source #

mrgTuple3 :: forall (a :: Type) (b :: Type) (c :: Type). Mergeable (a, b, c) => a -> b -> c -> UnionM (a, b, c) Source #

mrgJust :: forall (a :: Type). Mergeable (Maybe a) => a -> UnionM (Maybe a) Source #

mrgNothing :: forall (a :: Type). Mergeable (Maybe a) => UnionM (Maybe a) Source #

mrgLeft :: forall (a :: Type) (b :: Type). Mergeable (Either a b) => a -> UnionM (Either a b) Source #

mrgRight :: forall (a :: Type) (b :: Type). Mergeable (Either a b) => b -> UnionM (Either a b) Source #

mrgInL :: forall {k :: Type} (f :: k -> Type) (g :: k -> Type) (a :: k). Mergeable (Sum f g a) => f a -> UnionM (Sum f g a) Source #

mrgInR :: forall {k :: Type} (f :: k -> Type) (g :: k -> Type) (a :: k). Mergeable (Sum f g a) => g a -> UnionM (Sum f g a) Source #