grisette-0.2.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 (symbolic Booleans)
  • SymInteger (symbolic unbounded integers)
  • SymIntN n (symbolic signed bit vectors of length n)
  • SymWordN n (symbolic unsigned bit vectors of length n)

The two bit vector types has their lengths checked at compile time. Grisette also provides runtime-checked versions of these types: SomeSymIntN and SomeSymWordN.

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
Solvable Integer SymInteger Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Solvable Bool SymBool Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

(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 #

(KnownNat n, 1 <= n) => Solvable (IntN n) (SymIntN n) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

con :: IntN n -> SymIntN n Source #

conView :: SymIntN n -> Maybe (IntN n) Source #

ssym :: String -> SymIntN n Source #

isym :: String -> Int -> SymIntN n Source #

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

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

(KnownNat n, 1 <= n) => Solvable (WordN n) (SymWordN n) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

con :: WordN n -> SymWordN n Source #

conView :: SymWordN n -> Maybe (WordN n) Source #

ssym :: String -> SymWordN n Source #

isym :: String -> Int -> SymWordN n Source #

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

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

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => Solvable (ca --> cb) (sa -~> sb) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

con :: (ca --> cb) -> sa -~> sb Source #

conView :: (sa -~> sb) -> Maybe (ca --> cb) Source #

ssym :: String -> sa -~> sb Source #

isym :: String -> Int -> sa -~> sb Source #

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

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

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => Solvable (ca =-> cb) (sa =~> sb) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

con :: (ca =-> cb) -> sa =~> sb Source #

conView :: (sa =~> sb) -> Maybe (ca =-> cb) Source #

ssym :: String -> sa =~> sb Source #

isym :: String -> Int -> sa =~> sb Source #

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

iinfosym :: (Typeable a, Ord a, Lift a, NFData a, Show a, Hashable a) => String -> Int -> a -> sa =~> sb 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

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 SomeSymIntN Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

ITEOp SomeSymWordN Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

ITEOp SymBool Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

ITEOp SymInteger Source # 
Instance details

Defined in Grisette.Core.Data.Class.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 #

(KnownNat n, 1 <= n) => ITEOp (SymIntN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

Methods

ites :: SymBool -> SymIntN n -> SymIntN n -> SymIntN n Source #

(KnownNat n, 1 <= n) => ITEOp (SymWordN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

Methods

ites :: SymBool -> SymWordN n -> SymWordN n -> SymWordN n Source #

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => ITEOp (sa -~> sb) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

Methods

ites :: SymBool -> (sa -~> sb) -> (sa -~> sb) -> sa -~> sb Source #

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => ITEOp (sa =~> sb) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

Methods

ites :: SymBool -> (sa =~> sb) -> (sa =~> sb) -> sa =~> sb 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 Word8 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 SomeIntN Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

SEq SomeWordN Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

SEq SomeSymIntN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

SEq SomeSymWordN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

SEq SymBool Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

SEq SymInteger Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

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 #

(KnownNat n, 1 <= n) => SEq (IntN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Bool

Methods

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

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

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

Defined in Grisette.Core.Data.Class.Bool

Methods

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

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

(KnownNat n, 1 <= n) => SEq (SymIntN n) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

(KnownNat n, 1 <= n) => SEq (SymWordN n) 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

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 Word8 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 SomeIntN Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

SOrd SomeWordN Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

SOrd SomeSymIntN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

SOrd SomeSymWordN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

SOrd SymBool Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

SOrd SymInteger Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

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

(KnownNat n, 1 <= n) => SOrd (IntN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SOrd

Methods

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

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

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

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

symCompare :: IntN n -> IntN n -> UnionM Ordering Source #

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

Defined in Grisette.Core.Data.Class.SOrd

(KnownNat n, 1 <= n) => SOrd (SymIntN n) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

(KnownNat n, 1 <= n) => SOrd (SymWordN n) 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 SomeBV bv where Source #

Bit vector operations. Including concatenation (someBVConcat), extension (someBVZext, someBVSext, someBVExt), and selection (someBVSelect).

Methods

someBVConcat :: bv -> bv -> bv Source #

Concatenation of two bit vectors.

>>> someBVConcat (SomeSymWordN (0b101 :: SymWordN 3)) (SomeSymWordN (0b010 :: SymWordN 3))
0b101010

someBVZext Source #

Arguments

:: forall p l. KnownNat l 
=> p l

Desired output length

-> bv

Bit vector to extend

-> bv 

Zero extension of a bit vector.

>>> someBVZext (Proxy @6) (SomeSymWordN (0b101 :: SymWordN 3))
0b000101

someBVSext Source #

Arguments

:: forall p l. KnownNat l 
=> p l

Desired output length

-> bv

Bit vector to extend

-> bv 

Sign extension of a bit vector.

>>> someBVSext (Proxy @6) (SomeSymWordN (0b101 :: SymWordN 3))
0b111101

someBVExt Source #

Arguments

:: forall p l. KnownNat l 
=> p l

Desired output length

-> bv

Bit vector to extend

-> bv 

Extension of a bit vector. Signedness is determined by the input bit vector type.

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

someBVSelect Source #

Arguments

:: forall p ix q w. (KnownNat ix, KnownNat w) 
=> p ix

Index of the least significant bit of the slice

-> q w

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

-> bv

Bit vector to select from

-> bv 

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

The least significant bit is indexed as 0.

>>> someBVSelect (Proxy @1) (Proxy @3) (SomeSymIntN (0b001010 :: SymIntN 6))
0b101

Instances

Instances details
SomeBV SomeIntN Source # 
Instance details

Defined in Grisette.Core.Data.BV

Methods

someBVConcat :: SomeIntN -> SomeIntN -> SomeIntN Source #

someBVZext :: forall p (l :: Nat). KnownNat l => p l -> SomeIntN -> SomeIntN Source #

someBVSext :: forall p (l :: Nat). KnownNat l => p l -> SomeIntN -> SomeIntN Source #

someBVExt :: forall p (l :: Nat). KnownNat l => p l -> SomeIntN -> SomeIntN Source #

someBVSelect :: forall p (ix :: Nat) q (w :: Nat). (KnownNat ix, KnownNat w) => p ix -> q w -> SomeIntN -> SomeIntN Source #

SomeBV SomeWordN Source # 
Instance details

Defined in Grisette.Core.Data.BV

Methods

someBVConcat :: SomeWordN -> SomeWordN -> SomeWordN Source #

someBVZext :: forall p (l :: Nat). KnownNat l => p l -> SomeWordN -> SomeWordN Source #

someBVSext :: forall p (l :: Nat). KnownNat l => p l -> SomeWordN -> SomeWordN Source #

someBVExt :: forall p (l :: Nat). KnownNat l => p l -> SomeWordN -> SomeWordN Source #

someBVSelect :: forall p (ix :: Nat) q (w :: Nat). (KnownNat ix, KnownNat w) => p ix -> q w -> SomeWordN -> SomeWordN Source #

SomeBV SomeSymIntN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

someBVConcat :: SomeSymIntN -> SomeSymIntN -> SomeSymIntN Source #

someBVZext :: forall p (l :: Nat). KnownNat l => p l -> SomeSymIntN -> SomeSymIntN Source #

someBVSext :: forall p (l :: Nat). KnownNat l => p l -> SomeSymIntN -> SomeSymIntN Source #

someBVExt :: forall p (l :: Nat). KnownNat l => p l -> SomeSymIntN -> SomeSymIntN Source #

someBVSelect :: forall p (ix :: Nat) q (w :: Nat). (KnownNat ix, KnownNat w) => p ix -> q w -> SomeSymIntN -> SomeSymIntN Source #

SomeBV SomeSymWordN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

someBVConcat :: SomeSymWordN -> SomeSymWordN -> SomeSymWordN Source #

someBVZext :: forall p (l :: Nat). KnownNat l => p l -> SomeSymWordN -> SomeSymWordN Source #

someBVSext :: forall p (l :: Nat). KnownNat l => p l -> SomeSymWordN -> SomeSymWordN Source #

someBVExt :: forall p (l :: Nat). KnownNat l => p l -> SomeSymWordN -> SomeSymWordN Source #

someBVSelect :: forall p (ix :: Nat) q (w :: Nat). (KnownNat ix, KnownNat w) => p ix -> q w -> SomeSymWordN -> SomeSymWordN Source #

someBVZext' Source #

Arguments

:: forall l bv. SomeBV bv 
=> NatRepr l

Desired output length

-> bv

Bit vector to extend

-> bv 

Zero extension of a bit vector.

>>> someBVZext' (natRepr @6) (SomeSymWordN (0b101 :: SymWordN 3))
0b000101

someBVSext' Source #

Arguments

:: forall l bv. SomeBV bv 
=> NatRepr l 
-> bv

Desired output length

-> bv

Bit vector to extend

Sign extension of a bit vector.

>>> someBVSext' (natRepr @6) (SomeSymWordN (0b101 :: SymWordN 3))
0b111101

someBVExt' Source #

Arguments

:: forall l bv. SomeBV bv 
=> NatRepr l

Desired output length

-> bv

Bit vector to extend

-> bv 

Extension of a bit vector. Signedness is determined by the input bit vector type.

>>> someBVExt' (natRepr @6) (SomeSymIntN (0b101 :: SymIntN 3))
0b111101
>>> someBVExt' (natRepr @6) (SomeSymIntN (0b001 :: SymIntN 3))
0b000001
>>> someBVExt' (natRepr @6) (SomeSymWordN (0b101 :: SymWordN 3))
0b000101
>>> someBVExt' (natRepr @6) (SomeSymWordN (0b001 :: SymWordN 3))
0b000001

someBVSelect' Source #

Arguments

:: forall ix w bv. SomeBV bv 
=> NatRepr ix

Index of the least significant bit of the slice

-> NatRepr w

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

-> bv

Bit vector to select from

-> bv 

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

The least significant bit is indexed as 0.

>>> someBVSelect' (natRepr @1) (natRepr @3) (SomeSymIntN (0b001010 :: SymIntN 6))
0b101

someBVExtract Source #

Arguments

:: forall p (i :: Nat) q (j :: Nat) bv. (SomeBV bv, KnownNat i, KnownNat j) 
=> p i

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

-> q j

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

-> bv

Bit vector to extract from

-> bv 

Slicing out a smaller bit vector from a larger one, extract a slice from bit i down to j.

The least significant bit is indexed as 0.

>>> someBVExtract (Proxy @4) (Proxy @2) (SomeSymIntN (0b010100 :: SymIntN 6))
0b101

someBVExtract' Source #

Arguments

:: forall (i :: Nat) (j :: Nat) bv. SomeBV bv 
=> NatRepr i

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

-> NatRepr j

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

-> bv

Bit vector to extract from

-> bv 

Slicing out a smaller bit vector from a larger one, extract a slice from bit i down to j.

The least significant bit is indexed as 0.

>>> someBVExtract' (natRepr @4) (natRepr @2) (SomeSymIntN (0b010100 :: SymIntN 6))
0b101

class SizedBV bv where Source #

Sized bit vector operations. Including concatenation (sizedBVConcat), extension (sizedBVZext, sizedBVSext, sizedBVExt), and selection (sizedBVSelect).

Methods

sizedBVConcat :: (KnownNat l, KnownNat r, 1 <= l, 1 <= r) => bv l -> bv r -> bv (l + r) Source #

Concatenation of two bit vectors.

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

sizedBVZext Source #

Arguments

:: (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) 
=> proxy r

Desired output width

-> bv l

Bit vector to extend

-> bv r 

Zero extension of a bit vector.

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

sizedBVSext Source #

Arguments

:: (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) 
=> proxy r

Desired output width

-> bv l

Bit vector to extend

-> bv r 

Signed extension of a bit vector.

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

sizedBVExt Source #

Arguments

:: (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) 
=> proxy r

Desired output width

-> bv l

Bit vector to extend

-> bv r 

Extension of a bit vector. Signedness is determined by the input bit vector type.

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

sizedBVSelect Source #

Arguments

:: (KnownNat n, KnownNat ix, KnownNat w, 1 <= n, 1 <= w, (ix + w) <= n) 
=> proxy ix

Index of the least significant bit of the slice

-> proxy w

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

-> bv n

Bit vector to select from

-> bv w 

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

The least significant bit is indexed as 0.

>>> sizedBVSelect (Proxy @2) (Proxy @3) (con 0b010100 :: SymIntN 6)
0b101

Instances

Instances details
SizedBV IntN Source # 
Instance details

Defined in Grisette.Core.Data.BV

Methods

sizedBVConcat :: forall (l :: Nat) (r :: Nat). (KnownNat l, KnownNat r, 1 <= l, 1 <= r) => IntN l -> IntN r -> IntN (l + r) Source #

sizedBVZext :: forall (l :: Nat) (r :: Nat) proxy. (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> IntN l -> IntN r Source #

sizedBVSext :: forall (l :: Nat) (r :: Nat) proxy. (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> IntN l -> IntN r Source #

sizedBVExt :: forall (l :: Nat) (r :: Nat) proxy. (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> IntN l -> IntN r Source #

sizedBVSelect :: forall (n :: Nat) (ix :: Nat) (w :: Nat) proxy. (KnownNat n, KnownNat ix, KnownNat w, 1 <= n, 1 <= w, (ix + w) <= n) => proxy ix -> proxy w -> IntN n -> IntN w Source #

SizedBV WordN Source # 
Instance details

Defined in Grisette.Core.Data.BV

Methods

sizedBVConcat :: forall (l :: Nat) (r :: Nat). (KnownNat l, KnownNat r, 1 <= l, 1 <= r) => WordN l -> WordN r -> WordN (l + r) Source #

sizedBVZext :: forall (l :: Nat) (r :: Nat) proxy. (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> WordN l -> WordN r Source #

sizedBVSext :: forall (l :: Nat) (r :: Nat) proxy. (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> WordN l -> WordN r Source #

sizedBVExt :: forall (l :: Nat) (r :: Nat) proxy. (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> WordN l -> WordN r Source #

sizedBVSelect :: forall (n :: Nat) (ix :: Nat) (w :: Nat) proxy. (KnownNat n, KnownNat ix, KnownNat w, 1 <= n, 1 <= w, (ix + w) <= n) => proxy ix -> proxy w -> WordN n -> WordN w Source #

SizedBV SymIntN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

sizedBVConcat :: forall (l :: Nat) (r :: Nat). (KnownNat l, KnownNat r, 1 <= l, 1 <= r) => SymIntN l -> SymIntN r -> SymIntN (l + r) Source #

sizedBVZext :: forall (l :: Nat) (r :: Nat) proxy. (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> SymIntN l -> SymIntN r Source #

sizedBVSext :: forall (l :: Nat) (r :: Nat) proxy. (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> SymIntN l -> SymIntN r Source #

sizedBVExt :: forall (l :: Nat) (r :: Nat) proxy. (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> SymIntN l -> SymIntN r Source #

sizedBVSelect :: forall (n :: Nat) (ix :: Nat) (w :: Nat) proxy. (KnownNat n, KnownNat ix, KnownNat w, 1 <= n, 1 <= w, (ix + w) <= n) => proxy ix -> proxy w -> SymIntN n -> SymIntN w Source #

SizedBV SymWordN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

sizedBVConcat :: forall (l :: Nat) (r :: Nat). (KnownNat l, KnownNat r, 1 <= l, 1 <= r) => SymWordN l -> SymWordN r -> SymWordN (l + r) Source #

sizedBVZext :: forall (l :: Nat) (r :: Nat) proxy. (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> SymWordN l -> SymWordN r Source #

sizedBVSext :: forall (l :: Nat) (r :: Nat) proxy. (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> SymWordN l -> SymWordN r Source #

sizedBVExt :: forall (l :: Nat) (r :: Nat) proxy. (KnownNat l, KnownNat r, 1 <= l, KnownNat r, l <= r) => proxy r -> SymWordN l -> SymWordN r Source #

sizedBVSelect :: forall (n :: Nat) (ix :: Nat) (w :: Nat) proxy. (KnownNat n, KnownNat ix, KnownNat w, 1 <= n, 1 <= w, (ix + w) <= n) => proxy ix -> proxy w -> SymWordN n -> SymWordN w Source #

sizedBVExtract Source #

Arguments

:: forall proxy i j n bv. (SizedBV bv, KnownNat n, KnownNat i, KnownNat j, 1 <= n, (i + 1) <= n, j <= i) 
=> proxy i

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

-> proxy j

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

-> bv n

Bit vector to extract from

-> bv ((i - j) + 1) 

Slicing out a smaller bit vector from a larger one, extract a slice from bit i down to j.

The least significant bit is indexed as 0.

>>> sizedBVExtract (Proxy @4) (Proxy @2) (con 0b010100 :: SymIntN 6)
0b101

class (SOrd a, Num a, Mergeable a, Mergeable e) => SafeDivision e a | a -> e where Source #

Safe division with monadic error handling in multi-path execution. These procedures throw an exception when the divisor is zero. The result should be able to handle errors with MonadError.

Minimal complete definition

(safeDivMod | safeDiv, safeMod), (safeDivMod' | safeDiv', safeMod')

Methods

safeDiv :: (MonadError e uf, MonadUnion uf) => a -> a -> uf a Source #

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

>>> safeDiv (ssym "a") (ssym "b") :: ExceptT ArithException UnionM SymInteger
ExceptT {If (= b 0) (Left divide by zero) (Right (div a b))}

safeMod :: (MonadError e uf, MonadUnion uf) => a -> a -> uf a Source #

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

>>> safeMod (ssym "a") (ssym "b") :: ExceptT ArithException UnionM SymInteger
ExceptT {If (= b 0) (Left divide by zero) (Right (mod a b))}

safeDivMod :: (MonadError e uf, MonadUnion uf) => a -> a -> uf (a, a) Source #

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

>>> safeDivMod (ssym "a") (ssym "b") :: ExceptT ArithException UnionM (SymInteger, SymInteger)
ExceptT {If (= b 0) (Left divide by zero) (Right ((div a b),(mod a b)))}

safeQuot :: (MonadError e uf, MonadUnion uf) => a -> a -> uf a Source #

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

safeRem :: (MonadError e uf, MonadUnion uf) => a -> a -> uf a Source #

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

safeQuotRem :: (MonadError e uf, MonadUnion uf) => a -> a -> uf (a, a) Source #

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

safeDiv' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (e -> e') -> a -> a -> uf a Source #

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

>>> safeDiv' (const ()) (ssym "a") (ssym "b") :: ExceptT () UnionM SymInteger
ExceptT {If (= b 0) (Left ()) (Right (div a b))}

safeMod' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (e -> e') -> a -> a -> uf a Source #

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

>>> safeMod' (const ()) (ssym "a") (ssym "b") :: ExceptT () UnionM SymInteger
ExceptT {If (= b 0) (Left ()) (Right (mod a b))}

safeDivMod' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (e -> e') -> a -> a -> uf (a, a) Source #

Safe signed divMod with monadic error handling in multi-path execution. The error is transformed.

>>> safeDivMod' (const ()) (ssym "a") (ssym "b") :: ExceptT () UnionM (SymInteger, SymInteger)
ExceptT {If (= b 0) (Left ()) (Right ((div a b),(mod a b)))}

safeQuot' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (e -> e') -> a -> a -> uf a Source #

Safe signed quot with monadic error handling in multi-path execution. The error is transformed.

safeRem' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (e -> e') -> a -> a -> uf a Source #

Safe signed rem with monadic error handling in multi-path execution. The error is transformed.

safeQuotRem' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (e -> e') -> a -> a -> uf (a, a) Source #

Safe signed quotRem with monadic error handling in multi-path execution. The error is transformed.

Instances

Instances details
SafeDivision ArithException Int16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

SafeDivision ArithException Int32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

SafeDivision ArithException Int64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

SafeDivision ArithException Int8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

SafeDivision ArithException Word16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

SafeDivision ArithException Word32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

SafeDivision ArithException Word64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

SafeDivision ArithException Word8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

SafeDivision ArithException SymInteger Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

safeDiv :: (MonadError ArithException uf, MonadUnion uf) => SymInteger -> SymInteger -> uf SymInteger Source #

safeMod :: (MonadError ArithException uf, MonadUnion uf) => SymInteger -> SymInteger -> uf SymInteger Source #

safeDivMod :: (MonadError ArithException uf, MonadUnion uf) => SymInteger -> SymInteger -> uf (SymInteger, SymInteger) Source #

safeQuot :: (MonadError ArithException uf, MonadUnion uf) => SymInteger -> SymInteger -> uf SymInteger Source #

safeRem :: (MonadError ArithException uf, MonadUnion uf) => SymInteger -> SymInteger -> uf SymInteger Source #

safeQuotRem :: (MonadError ArithException uf, MonadUnion uf) => SymInteger -> SymInteger -> uf (SymInteger, SymInteger) Source #

safeDiv' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> SymInteger -> SymInteger -> uf SymInteger Source #

safeMod' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> SymInteger -> SymInteger -> uf SymInteger Source #

safeDivMod' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> SymInteger -> SymInteger -> uf (SymInteger, SymInteger) Source #

safeQuot' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> SymInteger -> SymInteger -> uf SymInteger Source #

safeRem' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> SymInteger -> SymInteger -> uf SymInteger Source #

safeQuotRem' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> SymInteger -> SymInteger -> uf (SymInteger, SymInteger) Source #

SafeDivision ArithException Integer Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

SafeDivision ArithException Int Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

Methods

safeDiv :: (MonadError ArithException uf, MonadUnion uf) => Int -> Int -> uf Int Source #

safeMod :: (MonadError ArithException uf, MonadUnion uf) => Int -> Int -> uf Int Source #

safeDivMod :: (MonadError ArithException uf, MonadUnion uf) => Int -> Int -> uf (Int, Int) Source #

safeQuot :: (MonadError ArithException uf, MonadUnion uf) => Int -> Int -> uf Int Source #

safeRem :: (MonadError ArithException uf, MonadUnion uf) => Int -> Int -> uf Int Source #

safeQuotRem :: (MonadError ArithException uf, MonadUnion uf) => Int -> Int -> uf (Int, Int) Source #

safeDiv' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> Int -> Int -> uf Int Source #

safeMod' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> Int -> Int -> uf Int Source #

safeDivMod' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> Int -> Int -> uf (Int, Int) Source #

safeQuot' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> Int -> Int -> uf Int Source #

safeRem' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> Int -> Int -> uf Int Source #

safeQuotRem' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> Int -> Int -> uf (Int, Int) Source #

SafeDivision ArithException Word Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

(KnownNat n, 1 <= n) => SafeDivision ArithException (IntN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

Methods

safeDiv :: (MonadError ArithException uf, MonadUnion uf) => IntN n -> IntN n -> uf (IntN n) Source #

safeMod :: (MonadError ArithException uf, MonadUnion uf) => IntN n -> IntN n -> uf (IntN n) Source #

safeDivMod :: (MonadError ArithException uf, MonadUnion uf) => IntN n -> IntN n -> uf (IntN n, IntN n) Source #

safeQuot :: (MonadError ArithException uf, MonadUnion uf) => IntN n -> IntN n -> uf (IntN n) Source #

safeRem :: (MonadError ArithException uf, MonadUnion uf) => IntN n -> IntN n -> uf (IntN n) Source #

safeQuotRem :: (MonadError ArithException uf, MonadUnion uf) => IntN n -> IntN n -> uf (IntN n, IntN n) Source #

safeDiv' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> IntN n -> IntN n -> uf (IntN n) Source #

safeMod' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> IntN n -> IntN n -> uf (IntN n) Source #

safeDivMod' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> IntN n -> IntN n -> uf (IntN n, IntN n) Source #

safeQuot' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> IntN n -> IntN n -> uf (IntN n) Source #

safeRem' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> IntN n -> IntN n -> uf (IntN n) Source #

safeQuotRem' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> IntN n -> IntN n -> uf (IntN n, IntN n) Source #

(KnownNat n, 1 <= n) => SafeDivision ArithException (WordN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

Methods

safeDiv :: (MonadError ArithException uf, MonadUnion uf) => WordN n -> WordN n -> uf (WordN n) Source #

safeMod :: (MonadError ArithException uf, MonadUnion uf) => WordN n -> WordN n -> uf (WordN n) Source #

safeDivMod :: (MonadError ArithException uf, MonadUnion uf) => WordN n -> WordN n -> uf (WordN n, WordN n) Source #

safeQuot :: (MonadError ArithException uf, MonadUnion uf) => WordN n -> WordN n -> uf (WordN n) Source #

safeRem :: (MonadError ArithException uf, MonadUnion uf) => WordN n -> WordN n -> uf (WordN n) Source #

safeQuotRem :: (MonadError ArithException uf, MonadUnion uf) => WordN n -> WordN n -> uf (WordN n, WordN n) Source #

safeDiv' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> WordN n -> WordN n -> uf (WordN n) Source #

safeMod' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> WordN n -> WordN n -> uf (WordN n) Source #

safeDivMod' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> WordN n -> WordN n -> uf (WordN n, WordN n) Source #

safeQuot' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> WordN n -> WordN n -> uf (WordN n) Source #

safeRem' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> WordN n -> WordN n -> uf (WordN n) Source #

safeQuotRem' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> WordN n -> WordN n -> uf (WordN n, WordN n) Source #

(KnownNat n, 1 <= n) => SafeDivision ArithException (SymIntN n) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

safeDiv :: (MonadError ArithException uf, MonadUnion uf) => SymIntN n -> SymIntN n -> uf (SymIntN n) Source #

safeMod :: (MonadError ArithException uf, MonadUnion uf) => SymIntN n -> SymIntN n -> uf (SymIntN n) Source #

safeDivMod :: (MonadError ArithException uf, MonadUnion uf) => SymIntN n -> SymIntN n -> uf (SymIntN n, SymIntN n) Source #

safeQuot :: (MonadError ArithException uf, MonadUnion uf) => SymIntN n -> SymIntN n -> uf (SymIntN n) Source #

safeRem :: (MonadError ArithException uf, MonadUnion uf) => SymIntN n -> SymIntN n -> uf (SymIntN n) Source #

safeQuotRem :: (MonadError ArithException uf, MonadUnion uf) => SymIntN n -> SymIntN n -> uf (SymIntN n, SymIntN n) Source #

safeDiv' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> SymIntN n -> SymIntN n -> uf (SymIntN n) Source #

safeMod' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> SymIntN n -> SymIntN n -> uf (SymIntN n) Source #

safeDivMod' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> SymIntN n -> SymIntN n -> uf (SymIntN n, SymIntN n) Source #

safeQuot' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> SymIntN n -> SymIntN n -> uf (SymIntN n) Source #

safeRem' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> SymIntN n -> SymIntN n -> uf (SymIntN n) Source #

safeQuotRem' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> SymIntN n -> SymIntN n -> uf (SymIntN n, SymIntN n) Source #

(KnownNat n, 1 <= n) => SafeDivision ArithException (SymWordN n) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

safeDiv :: (MonadError ArithException uf, MonadUnion uf) => SymWordN n -> SymWordN n -> uf (SymWordN n) Source #

safeMod :: (MonadError ArithException uf, MonadUnion uf) => SymWordN n -> SymWordN n -> uf (SymWordN n) Source #

safeDivMod :: (MonadError ArithException uf, MonadUnion uf) => SymWordN n -> SymWordN n -> uf (SymWordN n, SymWordN n) Source #

safeQuot :: (MonadError ArithException uf, MonadUnion uf) => SymWordN n -> SymWordN n -> uf (SymWordN n) Source #

safeRem :: (MonadError ArithException uf, MonadUnion uf) => SymWordN n -> SymWordN n -> uf (SymWordN n) Source #

safeQuotRem :: (MonadError ArithException uf, MonadUnion uf) => SymWordN n -> SymWordN n -> uf (SymWordN n, SymWordN n) Source #

safeDiv' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> SymWordN n -> SymWordN n -> uf (SymWordN n) Source #

safeMod' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> SymWordN n -> SymWordN n -> uf (SymWordN n) Source #

safeDivMod' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> SymWordN n -> SymWordN n -> uf (SymWordN n, SymWordN n) Source #

safeQuot' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> SymWordN n -> SymWordN n -> uf (SymWordN n) Source #

safeRem' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> SymWordN n -> SymWordN n -> uf (SymWordN n) Source #

safeQuotRem' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> SymWordN n -> SymWordN n -> uf (SymWordN n, SymWordN n) Source #

SafeDivision (Either BitwidthMismatch ArithException) SomeIntN Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

Methods

safeDiv :: (MonadError (Either BitwidthMismatch ArithException) uf, MonadUnion uf) => SomeIntN -> SomeIntN -> uf SomeIntN Source #

safeMod :: (MonadError (Either BitwidthMismatch ArithException) uf, MonadUnion uf) => SomeIntN -> SomeIntN -> uf SomeIntN Source #

safeDivMod :: (MonadError (Either BitwidthMismatch ArithException) uf, MonadUnion uf) => SomeIntN -> SomeIntN -> uf (SomeIntN, SomeIntN) Source #

safeQuot :: (MonadError (Either BitwidthMismatch ArithException) uf, MonadUnion uf) => SomeIntN -> SomeIntN -> uf SomeIntN Source #

safeRem :: (MonadError (Either BitwidthMismatch ArithException) uf, MonadUnion uf) => SomeIntN -> SomeIntN -> uf SomeIntN Source #

safeQuotRem :: (MonadError (Either BitwidthMismatch ArithException) uf, MonadUnion uf) => SomeIntN -> SomeIntN -> uf (SomeIntN, SomeIntN) Source #

safeDiv' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (Either BitwidthMismatch ArithException -> e') -> SomeIntN -> SomeIntN -> uf SomeIntN Source #

safeMod' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (Either BitwidthMismatch ArithException -> e') -> SomeIntN -> SomeIntN -> uf SomeIntN Source #

safeDivMod' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (Either BitwidthMismatch ArithException -> e') -> SomeIntN -> SomeIntN -> uf (SomeIntN, SomeIntN) Source #

safeQuot' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (Either BitwidthMismatch ArithException -> e') -> SomeIntN -> SomeIntN -> uf SomeIntN Source #

safeRem' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (Either BitwidthMismatch ArithException -> e') -> SomeIntN -> SomeIntN -> uf SomeIntN Source #

safeQuotRem' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (Either BitwidthMismatch ArithException -> e') -> SomeIntN -> SomeIntN -> uf (SomeIntN, SomeIntN) Source #

SafeDivision (Either BitwidthMismatch ArithException) SomeWordN Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

Methods

safeDiv :: (MonadError (Either BitwidthMismatch ArithException) uf, MonadUnion uf) => SomeWordN -> SomeWordN -> uf SomeWordN Source #

safeMod :: (MonadError (Either BitwidthMismatch ArithException) uf, MonadUnion uf) => SomeWordN -> SomeWordN -> uf SomeWordN Source #

safeDivMod :: (MonadError (Either BitwidthMismatch ArithException) uf, MonadUnion uf) => SomeWordN -> SomeWordN -> uf (SomeWordN, SomeWordN) Source #

safeQuot :: (MonadError (Either BitwidthMismatch ArithException) uf, MonadUnion uf) => SomeWordN -> SomeWordN -> uf SomeWordN Source #

safeRem :: (MonadError (Either BitwidthMismatch ArithException) uf, MonadUnion uf) => SomeWordN -> SomeWordN -> uf SomeWordN Source #

safeQuotRem :: (MonadError (Either BitwidthMismatch ArithException) uf, MonadUnion uf) => SomeWordN -> SomeWordN -> uf (SomeWordN, SomeWordN) Source #

safeDiv' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (Either BitwidthMismatch ArithException -> e') -> SomeWordN -> SomeWordN -> uf SomeWordN Source #

safeMod' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (Either BitwidthMismatch ArithException -> e') -> SomeWordN -> SomeWordN -> uf SomeWordN Source #

safeDivMod' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (Either BitwidthMismatch ArithException -> e') -> SomeWordN -> SomeWordN -> uf (SomeWordN, SomeWordN) Source #

safeQuot' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (Either BitwidthMismatch ArithException -> e') -> SomeWordN -> SomeWordN -> uf SomeWordN Source #

safeRem' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (Either BitwidthMismatch ArithException -> e') -> SomeWordN -> SomeWordN -> uf SomeWordN Source #

safeQuotRem' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (Either BitwidthMismatch ArithException -> e') -> SomeWordN -> SomeWordN -> uf (SomeWordN, SomeWordN) Source #

class (SOrd a, Num a, Mergeable a, Mergeable e) => SafeLinearArith e a | a -> e where Source #

Safe division with monadic error handling in multi-path execution. These procedures throw an exception when overflow or underflow happens. The result should be able to handle errors with MonadError.

Methods

safeAdd :: (MonadError e uf, MonadUnion uf) => a -> a -> uf a Source #

Safe + with monadic error handling in multi-path execution. Overflows or underflows are treated as errors.

>>> safeAdd (ssym "a") (ssym "b") :: ExceptT ArithException UnionM SymInteger
ExceptT {Right (+ a b)}
>>> safeAdd (ssym "a") (ssym "b") :: ExceptT ArithException UnionM (SymIntN 4)
ExceptT {If (ite (< 0x0 a) (&& (< 0x0 b) (< (+ a b) 0x0)) (&& (< a 0x0) (&& (< b 0x0) (<= 0x0 (+ a b))))) (If (< 0x0 a) (Left arithmetic overflow) (Left arithmetic underflow)) (Right (+ a b))}

safeNeg :: (MonadError e uf, MonadUnion uf) => a -> uf a Source #

Safe negate with monadic error handling in multi-path execution. Overflows or underflows are treated as errors.

>>> safeNeg (ssym "a") :: ExceptT ArithException UnionM SymInteger
ExceptT {Right (- a)}
>>> safeNeg (ssym "a") :: ExceptT ArithException UnionM (SymIntN 4)
ExceptT {If (= a 0x8) (Left arithmetic overflow) (Right (- a))}

safeMinus :: (MonadError e uf, MonadUnion uf) => a -> a -> uf a Source #

Safe - with monadic error handling in multi-path execution. Overflows or underflows are treated as errors.

>>> safeMinus (ssym "a") (ssym "b") :: ExceptT ArithException UnionM SymInteger
ExceptT {Right (+ a (- b))}
>>> safeMinus (ssym "a") (ssym "b") :: ExceptT ArithException UnionM (SymIntN 4)
ExceptT {If (ite (<= 0x0 a) (&& (< b 0x0) (< (+ a (- b)) 0x0)) (&& (< a 0x0) (&& (< 0x0 b) (< 0x0 (+ a (- b)))))) (If (<= 0x0 a) (Left arithmetic overflow) (Left arithmetic underflow)) (Right (+ a (- b)))}

safeAdd' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (e -> e') -> a -> a -> uf a Source #

Safe + with monadic error handling in multi-path execution. Overflows or underflows are treated as errors. The error is transformed.

safeNeg' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (e -> e') -> a -> uf a Source #

Safe negate with monadic error handling in multi-path execution. Overflows or underflows are treated as errors. The error is transformed.

safeMinus' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (e -> e') -> a -> a -> uf a Source #

Safe - with monadic error handling in multi-path execution. Overflows or underflows are treated as errors. The error is transformed.

Instances

Instances details
SafeLinearArith ArithException Int16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

SafeLinearArith ArithException Int32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

SafeLinearArith ArithException Int64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

SafeLinearArith ArithException Int8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

SafeLinearArith ArithException Word16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

SafeLinearArith ArithException Word32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

SafeLinearArith ArithException Word64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

SafeLinearArith ArithException Word8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

SafeLinearArith ArithException SymInteger Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

SafeLinearArith ArithException Integer Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

SafeLinearArith ArithException Int Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

Methods

safeAdd :: (MonadError ArithException uf, MonadUnion uf) => Int -> Int -> uf Int Source #

safeNeg :: (MonadError ArithException uf, MonadUnion uf) => Int -> uf Int Source #

safeMinus :: (MonadError ArithException uf, MonadUnion uf) => Int -> Int -> uf Int Source #

safeAdd' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> Int -> Int -> uf Int Source #

safeNeg' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> Int -> uf Int Source #

safeMinus' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> Int -> Int -> uf Int Source #

SafeLinearArith ArithException Word Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

(KnownNat n, 1 <= n) => SafeLinearArith ArithException (IntN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

Methods

safeAdd :: (MonadError ArithException uf, MonadUnion uf) => IntN n -> IntN n -> uf (IntN n) Source #

safeNeg :: (MonadError ArithException uf, MonadUnion uf) => IntN n -> uf (IntN n) Source #

safeMinus :: (MonadError ArithException uf, MonadUnion uf) => IntN n -> IntN n -> uf (IntN n) Source #

safeAdd' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> IntN n -> IntN n -> uf (IntN n) Source #

safeNeg' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> IntN n -> uf (IntN n) Source #

safeMinus' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> IntN n -> IntN n -> uf (IntN n) Source #

(KnownNat n, 1 <= n) => SafeLinearArith ArithException (WordN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

Methods

safeAdd :: (MonadError ArithException uf, MonadUnion uf) => WordN n -> WordN n -> uf (WordN n) Source #

safeNeg :: (MonadError ArithException uf, MonadUnion uf) => WordN n -> uf (WordN n) Source #

safeMinus :: (MonadError ArithException uf, MonadUnion uf) => WordN n -> WordN n -> uf (WordN n) Source #

safeAdd' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> WordN n -> WordN n -> uf (WordN n) Source #

safeNeg' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> WordN n -> uf (WordN n) Source #

safeMinus' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> WordN n -> WordN n -> uf (WordN n) Source #

(KnownNat n, 1 <= n) => SafeLinearArith ArithException (SymIntN n) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

safeAdd :: (MonadError ArithException uf, MonadUnion uf) => SymIntN n -> SymIntN n -> uf (SymIntN n) Source #

safeNeg :: (MonadError ArithException uf, MonadUnion uf) => SymIntN n -> uf (SymIntN n) Source #

safeMinus :: (MonadError ArithException uf, MonadUnion uf) => SymIntN n -> SymIntN n -> uf (SymIntN n) Source #

safeAdd' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> SymIntN n -> SymIntN n -> uf (SymIntN n) Source #

safeNeg' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> SymIntN n -> uf (SymIntN n) Source #

safeMinus' :: (MonadError e' uf, MonadUnion uf, Mergeable e') => (ArithException -> e') -> SymIntN n -> SymIntN n -> uf (SymIntN n) Source #

(KnownNat n, 1 <= n) => SafeLinearArith ArithException (SymWordN n) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

SafeLinearArith (Either BitwidthMismatch ArithException) SomeIntN Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

SafeLinearArith (Either BitwidthMismatch ArithException) SomeWordN Source # 
Instance details

Defined in Grisette.Core.Data.Class.SafeArith

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 SymInteger 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 #

(LinkedRep a sa, LinkedRep b sb) => Function (a --> b) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.Prim.InternedTerm.Term

Associated Types

type Arg (a --> b) Source #

type Ret (a --> b) Source #

Methods

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

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => Function (sa -~> sb) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Associated Types

type Arg (sa -~> sb) Source #

type Ret (sa -~> sb) Source #

Methods

(#) :: (sa -~> sb) -> Arg (sa -~> sb) -> Ret (sa -~> sb) Source #

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => Function (sa =~> sb) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Associated Types

type Arg (sa =~> sb) Source #

type Ret (sa =~> sb) Source #

Methods

(#) :: (sa =~> sb) -> Arg (sa =~> sb) -> Ret (sa =~> sb) 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 -> () #

MonadParallelUnion UnionM Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

parBindUnion :: (Mergeable b, NFData b) => UnionM a -> (a -> UnionM b) -> UnionM b Source #

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 #

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

Defined in Grisette.Core.Control.Monad.UnionM

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 #

ToSym (UnionM SomeIntN) SomeSymIntN Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

ToSym (UnionM SomeWordN) SomeSymWordN Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

ToSym (UnionM Integer) SymInteger Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

ToSym (UnionM Bool) SymBool Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

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 #

(KnownNat n, 1 <= n) => ToSym (UnionM (IntN n)) (SymIntN n) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

toSym :: UnionM (IntN n) -> SymIntN n Source #

(KnownNat n, 1 <= n) => ToSym (UnionM (WordN n)) (SymWordN n) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

toSym :: UnionM (WordN n) -> SymWordN n 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 ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => ToSym (UnionM (ca --> cb)) (sa -~> sb) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

toSym :: UnionM (ca --> cb) -> sa -~> sb Source #

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => ToSym (UnionM (ca =-> cb)) (sa =~> sb) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

toSym :: UnionM (ca =-> cb) -> sa =~> sb 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.

unionSize :: UnionM a -> Int Source #

The size of a union is defined as the number of branches. For example,

>>> unionSize (single True)
1
>>> unionSize (mrgIf "a" (single 1) (single 2) :: UnionM Integer)
2
>>> unionSize (choose [1..7] "a" :: UnionM Integer)
7

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 ArithException Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

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 Word8 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 BitwidthMismatch Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable SomeIntN Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable SomeWordN Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

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 SomeSymIntN Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable SomeSymWordN Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable SymBool Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

Mergeable SymInteger 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

(KnownNat n, 1 <= n) => Mergeable (IntN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

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

Defined in Grisette.Core.Data.Class.Mergeable

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

Defined in Grisette.Core.Data.Union

(KnownNat n, 1 <= n) => Mergeable (SymIntN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(KnownNat n, 1 <= n) => Mergeable (SymWordN n) 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

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => Mergeable (sa -~> sb) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => Mergeable (sa =~> sb) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Mergeable

(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 SomeSymIntN Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

SimpleMergeable SomeSymWordN Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

SimpleMergeable SymBool Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

SimpleMergeable SymInteger Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

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 #

(KnownNat n, 1 <= n) => SimpleMergeable (SymIntN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> SymIntN n -> SymIntN n -> SymIntN n Source #

(KnownNat n, 1 <= n) => SimpleMergeable (SymWordN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> SymWordN n -> SymWordN n -> SymWordN n 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 #

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => SimpleMergeable (sa -~> sb) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> (sa -~> sb) -> (sa -~> sb) -> sa -~> sb Source #

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => SimpleMergeable (sa =~> sb) Source # 
Instance details

Defined in Grisette.Core.Data.Class.SimpleMergeable

Methods

mrgIte :: SymBool -> (sa =~> sb) -> (sa =~> sb) -> sa =~> sb 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.

class (UnionLike m, Monad m) => MonadParallelUnion m where Source #

Parallel union monad.

With the QualifiedDo extension and the Grisette.Qualified.ParallelUnionDo module, one can execute the paths in parallel and merge the results with:

:set -XQualifiedDo -XOverloadedStrings
import Grisette
import qualified Grisette.Qualified.ParallelUnionDo as P
P.do
  x <- mrgIf "a" (return 1) (return 2) :: UnionM Int
  return $ x + 1

-- {If a 2 3}

Methods

parBindUnion :: (Mergeable b, NFData b) => m a -> (a -> m b) -> m b Source #

Instances

Instances details
MonadParallelUnion UnionM Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

parBindUnion :: (Mergeable b, NFData b) => UnionM a -> (a -> UnionM b) -> UnionM b Source #

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

Defined in Grisette.Core.Control.Monad.Class.MonadParallelUnion

Methods

parBindUnion :: (Mergeable b, NFData b) => MaybeT m a -> (a -> MaybeT m b) -> MaybeT m b Source #

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

Defined in Grisette.Core.Control.Monad.Class.MonadParallelUnion

Methods

parBindUnion :: (Mergeable b, NFData b) => ExceptT e m a -> (a -> ExceptT e m b) -> ExceptT e m b Source #

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

Defined in Grisette.Core.Control.Monad.Class.MonadParallelUnion

Methods

parBindUnion :: (Mergeable b, NFData b) => IdentityT m a -> (a -> IdentityT m b) -> IdentityT m b Source #

(MonadParallelUnion m, Mergeable a, NFData a) => MonadParallelUnion (ReaderT a m) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.Class.MonadParallelUnion

Methods

parBindUnion :: (Mergeable b, NFData b) => ReaderT a m a0 -> (a0 -> ReaderT a m b) -> ReaderT a m b Source #

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

Defined in Grisette.Core.Control.Monad.Class.MonadParallelUnion

Methods

parBindUnion :: (Mergeable b, NFData b) => StateT s m a -> (a -> StateT s m b) -> StateT s m b Source #

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

Defined in Grisette.Core.Control.Monad.Class.MonadParallelUnion

Methods

parBindUnion :: (Mergeable b, NFData b) => StateT s m a -> (a -> StateT s m b) -> StateT s m b Source #

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

Defined in Grisette.Core.Control.Monad.Class.MonadParallelUnion

Methods

parBindUnion :: (Mergeable b, NFData b) => WriterT s m a -> (a -> WriterT s m b) -> WriterT s m b Source #

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

Defined in Grisette.Core.Control.Monad.Class.MonadParallelUnion

Methods

parBindUnion :: (Mergeable b, NFData b) => WriterT s m a -> (a -> WriterT s m b) -> WriterT s m b Source #

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

Defined in Grisette.Core.Control.Monad.Class.MonadParallelUnion

Methods

parBindUnion :: (Mergeable b, NFData b) => RWST r w s m a -> (a -> RWST r w s m b) -> RWST r w s m b Source #

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

Defined in Grisette.Core.Control.Monad.Class.MonadParallelUnion

Methods

parBindUnion :: (Mergeable b, NFData b) => RWST r w s m a -> (a -> RWST r w s m b) -> RWST r w s m b Source #

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 Word8 Word8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: Word8 -> Maybe Word8 Source #

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 SomeIntN SomeIntN Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

ToCon SomeWordN SomeWordN Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

ToCon SomeSymIntN SomeIntN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ToCon SomeSymIntN SomeSymIntN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ToCon SomeSymWordN SomeWordN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ToCon SomeSymWordN SomeSymWordN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ToCon SymBool SymBool Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ToCon SymBool Bool Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ToCon SymInteger SymInteger Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ToCon SymInteger Integer Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

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 (SymIntN 8) Int8 Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: SymIntN 8 -> Maybe Int8 Source #

ToCon (SymIntN 16) Int16 Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: SymIntN 16 -> Maybe Int16 Source #

ToCon (SymIntN 32) Int32 Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: SymIntN 32 -> Maybe Int32 Source #

ToCon (SymIntN 64) Int64 Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: SymIntN 64 -> Maybe Int64 Source #

ToCon (SymIntN 64) Int Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: SymIntN 64 -> Maybe Int Source #

ToCon (SymWordN 8) Word8 Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: SymWordN 8 -> Maybe Word8 Source #

ToCon (SymWordN 16) Word16 Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: SymWordN 16 -> Maybe Word16 Source #

ToCon (SymWordN 32) Word32 Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: SymWordN 32 -> Maybe Word32 Source #

ToCon (SymWordN 64) Word64 Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: SymWordN 64 -> Maybe Word64 Source #

ToCon (SymWordN 64) Word Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: SymWordN 64 -> Maybe Word 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 #

(KnownNat n, 1 <= n) => ToCon (IntN n) (IntN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: IntN n -> Maybe (IntN n) Source #

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

Defined in Grisette.Core.Data.Class.ToCon

Methods

toCon :: WordN n -> Maybe (WordN n) Source #

(KnownNat n, 1 <= n) => ToCon (SymIntN n) (IntN n) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: SymIntN n -> Maybe (IntN n) Source #

(KnownNat n, 1 <= n) => ToCon (SymIntN n) (SymIntN n) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: SymIntN n -> Maybe (SymIntN n) Source #

(KnownNat n, 1 <= n) => ToCon (SymWordN n) (WordN n) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: SymWordN n -> Maybe (WordN n) Source #

(KnownNat n, 1 <= n) => ToCon (SymWordN n) (SymWordN n) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: SymWordN n -> Maybe (SymWordN n) 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 #

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

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

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

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => ToCon (sa -~> sb) (ca --> cb) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: (sa -~> sb) -> Maybe (ca --> cb) Source #

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

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: (a =~> b) -> Maybe (a =~> b) Source #

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => ToCon (sa =~> sb) (ca =-> cb) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toCon :: (sa =~> sb) -> Maybe (ca =-> cb) 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 Int16 SomeSymIntN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ToSym Int32 Int32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: Int32 -> Int32 Source #

ToSym Int32 SomeSymIntN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ToSym Int64 Int64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: Int64 -> Int64 Source #

ToSym Int64 SomeSymIntN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ToSym Int8 Int8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: Int8 -> Int8 Source #

ToSym Int8 SomeSymIntN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ToSym Word16 Word16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: Word16 -> Word16 Source #

ToSym Word16 SomeSymWordN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ToSym Word32 Word32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: Word32 -> Word32 Source #

ToSym Word32 SomeSymWordN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ToSym Word64 Word64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: Word64 -> Word64 Source #

ToSym Word64 SomeSymWordN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ToSym Word8 Word8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: Word8 -> Word8 Source #

ToSym Word8 SomeSymWordN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

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 SomeIntN SomeIntN Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

ToSym SomeIntN SomeSymIntN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ToSym SomeWordN SomeWordN Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

ToSym SomeWordN SomeSymWordN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ToSym SomeSymIntN SomeSymIntN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ToSym SomeSymWordN SomeSymWordN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ToSym SymBool SymBool Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ToSym SymInteger SymInteger Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ToSym Integer SymInteger Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

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 SymBool Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: Bool -> SymBool 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 SomeSymIntN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ToSym Int Int Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: Int -> Int Source #

ToSym Word SomeSymWordN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ToSym Word Word Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: Word -> Word Source #

ToSym Int16 (SymIntN 16) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: Int16 -> SymIntN 16 Source #

ToSym Int32 (SymIntN 32) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: Int32 -> SymIntN 32 Source #

ToSym Int64 (SymIntN 64) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: Int64 -> SymIntN 64 Source #

ToSym Int8 (SymIntN 8) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: Int8 -> SymIntN 8 Source #

ToSym Word16 (SymWordN 16) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: Word16 -> SymWordN 16 Source #

ToSym Word32 (SymWordN 32) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: Word32 -> SymWordN 32 Source #

ToSym Word64 (SymWordN 64) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: Word64 -> SymWordN 64 Source #

ToSym Word8 (SymWordN 8) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: Word8 -> SymWordN 8 Source #

ToSym Int (SymIntN 64) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: Int -> SymIntN 64 Source #

ToSym Word (SymWordN 64) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: Word -> SymWordN 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 #

ToSym (UnionM SomeIntN) SomeSymIntN Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

ToSym (UnionM SomeWordN) SomeSymWordN Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

ToSym (UnionM Integer) SymInteger Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

ToSym (UnionM Bool) SymBool Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

(KnownNat n, 1 <= n) => ToSym (IntN n) SomeSymIntN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: IntN n -> SomeSymIntN Source #

(KnownNat n, 1 <= n) => ToSym (WordN n) SomeSymWordN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

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 #

(KnownNat n, 1 <= n) => ToSym (UnionM (IntN n)) (SymIntN n) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

toSym :: UnionM (IntN n) -> SymIntN n Source #

(KnownNat n, 1 <= n) => ToSym (UnionM (WordN n)) (SymWordN n) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

toSym :: UnionM (WordN n) -> SymWordN n 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 #

(KnownNat n, 1 <= n) => ToSym (IntN n) (IntN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: IntN n -> IntN n Source #

(KnownNat n, 1 <= n) => ToSym (IntN n) (SymIntN n) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: IntN n -> SymIntN n Source #

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

Defined in Grisette.Core.Data.Class.ToSym

Methods

toSym :: WordN n -> WordN n Source #

(KnownNat n, 1 <= n) => ToSym (WordN n) (SymWordN n) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: WordN n -> SymWordN n Source #

(KnownNat n, 1 <= n) => ToSym (SymIntN n) (SymIntN n) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: SymIntN n -> SymIntN n Source #

(KnownNat n, 1 <= n) => ToSym (SymWordN n) (SymWordN n) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: SymWordN n -> SymWordN n 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 #

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => ToSym (UnionM (ca --> cb)) (sa -~> sb) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

toSym :: UnionM (ca --> cb) -> sa -~> sb Source #

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => ToSym (UnionM (ca =-> cb)) (sa =~> sb) Source # 
Instance details

Defined in Grisette.Core.Control.Monad.UnionM

Methods

toSym :: UnionM (ca =-> cb) -> sa =~> sb 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 #

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => ToSym (ca --> cb) (sa -~> sb) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: (ca --> cb) -> sa -~> sb Source #

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

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: (a -~> b) -> a -~> b Source #

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

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: (a =~> b) -> a =~> b Source #

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => ToSym (ca =-> cb) (sa =~> sb) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

toSym :: (ca =-> cb) -> sa =~> sb 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.2.0.0-CYZZ7WjRTnw1wxrPITB8ce" '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

MonadFresh m => MonadFresh (ExceptT e m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

MonadFresh m => MonadFresh (ReaderT r m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

MonadFresh m => MonadFresh (StateT s m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

MonadFresh m => MonadFresh (StateT s m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

(MonadFresh m, Monoid w) => MonadFresh (WriterT w m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

(MonadFresh m, Monoid w) => MonadFresh (WriterT w m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

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

Defined in Grisette.Core.Data.Class.GenSym

(MonadFresh m, Monoid w) => MonadFresh (RWST r w s 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 #

MonadRWS r w s m => MonadRWS r w s (FreshT m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

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 #

MonadReader r m => MonadReader r (FreshT m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

ask :: FreshT m r #

local :: (r -> r) -> FreshT m a -> FreshT m a #

reader :: (r -> a) -> FreshT m a #

MonadState s m => MonadState s (FreshT m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

get :: FreshT m s #

put :: s -> FreshT m () #

state :: (s -> (a, s)) -> FreshT m a #

MonadWriter w m => MonadWriter w (FreshT m) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

writer :: (a, w) -> FreshT m a #

tell :: w -> FreshT m () #

listen :: FreshT m a -> FreshT m (a, w) #

pass :: FreshT m (a, w -> w) -> 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 Word8 Word8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

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

GenSym ByteString ByteString Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

GenSym SomeIntN SomeIntN Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

GenSym SomeWordN SomeWordN Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

GenSym SomeSymIntN SomeSymIntN Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

GenSym SomeSymWordN SomeSymWordN Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

GenSym SymBool SymBool Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

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

GenSym SymInteger SymInteger Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

GenSym Integer Integer Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

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

GenSym () SymBool Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

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

GenSym () SymInteger Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => () -> m (UnionM SymInteger) 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 #

(KnownNat n, 1 <= n) => GenSym () (SymIntN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

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

(KnownNat n, 1 <= n) => GenSym () (SymWordN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => () -> m (UnionM (SymWordN n)) 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 #

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => GenSym () (sa -~> sb) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => () -> m (UnionM (sa -~> sb)) Source #

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => GenSym () (sa =~> sb) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => () -> m (UnionM (sa =~> sb)) 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 #

(KnownNat n, 1 <= n) => GenSym (p n) SomeSymIntN Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => p n -> m (UnionM SomeSymIntN) Source #

(KnownNat n, 1 <= n) => GenSym (p n) SomeSymWordN Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => p n -> m (UnionM SomeSymWordN) Source #

(KnownNat n, 1 <= n) => GenSym (IntN n) (IntN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

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

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

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => WordN n -> m (UnionM (WordN n)) 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 #

(KnownNat n, 1 <= n) => GenSym (SymIntN n) (SymIntN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

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

(KnownNat n, 1 <= n) => GenSym (SymWordN n) (SymWordN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => SymWordN n -> m (UnionM (SymWordN n)) 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 #

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => GenSym (sa -~> sb) (sa -~> sb) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => (sa -~> sb) -> m (UnionM (sa -~> sb)) Source #

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => GenSym (sa =~> sb) (sa =~> sb) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

fresh :: MonadFresh m => (sa =~> sb) -> m (UnionM (sa =~> sb)) 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 Word8 Word8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

GenSymSimple ByteString ByteString Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

GenSymSimple SomeIntN SomeIntN Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

GenSymSimple SomeWordN SomeWordN Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

GenSymSimple SomeSymIntN SomeSymIntN Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

GenSymSimple SomeSymWordN SomeSymWordN Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

GenSymSimple SymBool SymBool Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

GenSymSimple SymInteger SymInteger Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

GenSymSimple Integer Integer Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

GenSymSimple () SymBool Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => () -> m SymBool Source #

GenSymSimple () SymInteger Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => () -> m SymInteger Source #

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 #

(KnownNat n, 1 <= n) => GenSymSimple () (SymIntN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => () -> m (SymIntN n) Source #

(KnownNat n, 1 <= n) => GenSymSimple () (SymWordN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => () -> m (SymWordN n) 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 #

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => GenSymSimple () (sa -~> sb) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => () -> m (sa -~> sb) Source #

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => GenSymSimple () (sa =~> sb) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => () -> m (sa =~> sb) 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 #

(KnownNat n, 1 <= n) => GenSymSimple (p n) SomeSymIntN Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => p n -> m SomeSymIntN Source #

(KnownNat n, 1 <= n) => GenSymSimple (p n) SomeSymWordN Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => p n -> m SomeSymWordN Source #

(KnownNat n, 1 <= n) => GenSymSimple (IntN n) (IntN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => IntN n -> m (IntN n) Source #

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

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => WordN n -> m (WordN n) 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 #

(KnownNat n, 1 <= n) => GenSymSimple (SymIntN n) (SymIntN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => SymIntN n -> m (SymIntN n) Source #

(KnownNat n, 1 <= n) => GenSymSimple (SymWordN n) (SymWordN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => SymWordN n -> m (SymWordN n) 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 #

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => GenSymSimple (sa -~> sb) (sa -~> sb) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => (sa -~> sb) -> m (sa -~> sb) Source #

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => GenSymSimple (sa =~> sb) (sa =~> sb) Source # 
Instance details

Defined in Grisette.Core.Data.Class.GenSym

Methods

simpleFresh :: MonadFresh m => (sa =~> sb) -> m (sa =~> sb) 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 (precise 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

AllSyms AssertionError Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

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.2.0.0-CYZZ7WjRTnw1wxrPITB8ce" '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

AllSyms VerificationConditions Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

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.2.0.0-CYZZ7WjRTnw1wxrPITB8ce" '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 ())}

symAssertWith :: (Mergeable e, MonadError e erm, MonadUnion erm) => e -> SymBool -> erm () Source #

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 #

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

(Lift a, Lift b) => Lift (CBMCEither a b :: TYPE LiftedRep) 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) #

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.2.0.0-CYZZ7WjRTnw1wxrPITB8ce" '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
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 #

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 #

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.2.0.0-CYZZ7WjRTnw1wxrPITB8ce" '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.2.0.0-CYZZ7WjRTnw1wxrPITB8ce" '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 (precise z3) (x + y ==~ 6 &&~ x - y ==~ 20)
Right (Model {x -> 13 :: Integer, y -> -7 :: Integer})
>>> solve (precise 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 (precise 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 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
>>> assert = symAssertWith Assert
>>> sdiv = safeDiv' (const Arith)
>>> :{
  -- 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 `sdiv` y
    mrgIf (z >~ 0) (assert (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 (precise z3) ("a" &&~ ("b" :: SymInteger) ==~ 1)
Right (Model {a -> True :: Bool, b -> 1 :: Integer})
>>> solve (precise 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], failure) 

Solve a single formula while returning multiple models to make it true. The maximum number of desired models are given.

>>> solveMulti (precise 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 (precise 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 (precise 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], failure) 

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 ([inputs], Either failure 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) SolvingFailure Source # 
Instance details

Defined in Grisette.Backend.SBV.Data.SMT.Solving

Methods

cegisMultiInputs :: (EvaluateSym inputs, ExtractSymbolics inputs) => GrisetteSMTConfig n -> [inputs] -> (inputs -> CEGISCondition) -> IO ([inputs], Either SolvingFailure 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 ([inputs], Either failure 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 (precise 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 ([inputs], Either failure 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 (precise 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 ([inputs], Either failure 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 (precise 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 ([inputs], Either failure 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 ([inputs], Either failure 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 ([inputs], Either failure 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 ([inputs], Either failure 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 Word8 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 SomeIntN Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

ExtractSymbolics SomeWordN Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

ExtractSymbolics SymbolSet Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.Prim.Model

ExtractSymbolics SomeSymIntN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ExtractSymbolics SomeSymWordN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ExtractSymbolics SymBool Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

ExtractSymbolics SymInteger Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

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

(KnownNat n, 1 <= n) => ExtractSymbolics (IntN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.ExtractSymbolics

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

Defined in Grisette.Core.Data.Class.ExtractSymbolics

(KnownNat n, 1 <= n) => ExtractSymbolics (SymIntN n) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

(KnownNat n, 1 <= n) => ExtractSymbolics (SymWordN n) 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

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => ExtractSymbolics (sa -~> sb) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

extractSymbolics :: (sa -~> sb) -> SymbolSet Source #

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => ExtractSymbolics (sa =~> sb) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

extractSymbolics :: (sa =~> sb) -> SymbolSet Source #

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

modelContains :: typedSymbol a -> model -> Bool Source #

Check if the model contains the given symbol

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

exceptFor' :: typedSymbol t -> model -> model Source #

Returns a model that removed the assignments for the symbolic constants

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 ModelRep rep model | rep -> model 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 Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.Prim.Model

ModelRep (ModelSymPair ct st) Model Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

buildModel :: ModelSymPair ct st -> Model Source #

(ModelRep a Model, ModelRep b Model) => ModelRep (a, b) Model Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.Prim.Model

Methods

buildModel :: (a, b) -> Model Source #

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

Defined in Grisette.IR.SymPrim.Data.Prim.Model

Methods

buildModel :: (a, b, c) -> Model Source #

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

Defined in Grisette.IR.SymPrim.Data.Prim.Model

Methods

buildModel :: (a, b, c, d) -> Model Source #

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

Defined in Grisette.IR.SymPrim.Data.Prim.Model

Methods

buildModel :: (a, b, c, d, e) -> Model Source #

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

Defined in Grisette.IR.SymPrim.Data.Prim.Model

Methods

buildModel :: (a, b, c, d, e, f) -> Model Source #

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

Defined in Grisette.IR.SymPrim.Data.Prim.Model

Methods

buildModel :: (a, b, c, d, e, f, g) -> Model Source #

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

Defined in Grisette.IR.SymPrim.Data.Prim.Model

Methods

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

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 Word8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> Word8 -> Word8 Source #

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 SomeIntN Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

EvaluateSym SomeWordN Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

EvaluateSym SomeSymIntN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

EvaluateSym SomeSymWordN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

EvaluateSym SymBool Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

EvaluateSym SymInteger Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

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 #

(KnownNat n, 1 <= n) => EvaluateSym (IntN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> IntN n -> IntN n Source #

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

Defined in Grisette.Core.Data.Class.Evaluate

Methods

evaluateSym :: Bool -> Model -> WordN n -> WordN n Source #

(KnownNat n, 1 <= n) => EvaluateSym (SymIntN n) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

evaluateSym :: Bool -> Model -> SymIntN n -> SymIntN n Source #

(KnownNat n, 1 <= n) => EvaluateSym (SymWordN n) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

evaluateSym :: Bool -> Model -> SymWordN n -> SymWordN n 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 #

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => EvaluateSym (sa -~> sb) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

evaluateSym :: Bool -> Model -> (sa -~> sb) -> sa -~> sb Source #

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => EvaluateSym (sa =~> sb) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

evaluateSym :: Bool -> Model -> (sa =~> sb) -> sa =~> sb 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 :: LinkedRep cb sb => TypedSymbol cb -> sb -> a -> a Source #

Instances

Instances details
SubstituteSym Int16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> Int16 -> Int16 Source #

SubstituteSym Int32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> Int32 -> Int32 Source #

SubstituteSym Int64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> Int64 -> Int64 Source #

SubstituteSym Int8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> Int8 -> Int8 Source #

SubstituteSym Word16 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> Word16 -> Word16 Source #

SubstituteSym Word32 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> Word32 -> Word32 Source #

SubstituteSym Word64 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> Word64 -> Word64 Source #

SubstituteSym Word8 Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> Word8 -> Word8 Source #

SubstituteSym ByteString Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> ByteString -> ByteString Source #

SubstituteSym SomeIntN Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> SomeIntN -> SomeIntN Source #

SubstituteSym SomeWordN Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> SomeWordN -> SomeWordN Source #

SubstituteSym SomeSymIntN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

SubstituteSym SomeSymWordN Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

SubstituteSym SymBool Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> SymBool -> SymBool Source #

SubstituteSym SymInteger Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> SymInteger -> SymInteger Source #

SubstituteSym Integer Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> Integer -> Integer Source #

SubstituteSym () Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> () -> () Source #

SubstituteSym Bool Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> Bool -> Bool Source #

SubstituteSym Char Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> Char -> Char Source #

SubstituteSym Int Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> Int -> Int Source #

SubstituteSym Word Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> Word -> Word Source #

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

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> Identity a -> Identity a Source #

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

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> Default a -> Default a Source #

(KnownNat n, 1 <= n) => SubstituteSym (IntN n) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> IntN n -> IntN n Source #

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

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> WordN n -> WordN n Source #

(KnownNat n, 1 <= n) => SubstituteSym (SymIntN n) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> SymIntN n -> SymIntN n Source #

(KnownNat n, 1 <= n) => SubstituteSym (SymWordN n) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> SymWordN n -> SymWordN n Source #

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

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> Maybe a -> Maybe a Source #

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

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> [a] -> [a] Source #

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

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> Either a b -> Either a b Source #

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => SubstituteSym (sa -~> sb) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

substituteSym :: LinkedRep cb sb0 => TypedSymbol cb -> sb0 -> (sa -~> sb) -> sa -~> sb Source #

(SupportedPrim ca, SupportedPrim cb, LinkedRep ca sa, LinkedRep cb sb) => SubstituteSym (sa =~> sb) Source # 
Instance details

Defined in Grisette.IR.SymPrim.Data.SymPrim

Methods

substituteSym :: LinkedRep cb sb0 => TypedSymbol cb -> sb0 -> (sa =~> sb) -> sa =~> sb Source #

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

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym :: LinkedRep cb sb => TypedSymbol cb -> sb -> 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 :: LinkedRep cb sb => TypedSymbol cb -> sb -> (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 :: LinkedRep cb sb => TypedSymbol cb -> sb -> 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 :: LinkedRep cb sb => TypedSymbol cb -> sb -> 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 :: LinkedRep cb sb => TypedSymbol cb -> sb -> 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 :: LinkedRep cb sb => TypedSymbol cb -> sb -> 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 :: LinkedRep cb sb => TypedSymbol cb -> sb -> (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 :: LinkedRep cb sb => TypedSymbol cb -> sb -> 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 :: LinkedRep cb sb => TypedSymbol cb -> sb -> (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 :: LinkedRep cb sb => TypedSymbol cb -> sb -> (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 :: LinkedRep cb sb => TypedSymbol cb -> sb -> (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 :: LinkedRep cb sb => TypedSymbol cb -> sb -> (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 :: LinkedRep cb sb => TypedSymbol cb -> sb -> (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' :: LinkedRep cb sb => TypedSymbol cb -> sb -> 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' :: LinkedRep cb sb => TypedSymbol cb -> sb -> U1 c -> U1 c Source #

(SubstituteSym' a, SubstituteSym' b) => SubstituteSym' (a :*: b) Source # 
Instance details

Defined in Grisette.Core.Data.Class.Substitute

Methods

substituteSym' :: LinkedRep cb sb => TypedSymbol cb -> sb -> (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' :: LinkedRep cb sb => TypedSymbol cb -> sb -> (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' :: LinkedRep cb sb => TypedSymbol cb -> sb -> 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' :: LinkedRep cb sb => TypedSymbol cb -> sb -> 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 :: LinkedRep cb sb => TypedSymbol cb -> sb -> Default a -> Default a Source #

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

Defined in Grisette.IR.SymPrim.Data.SymPrim

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 #