| Copyright | (c) Brian Schroeder | 
|---|---|
| License | BSD3 | 
| Maintainer | erkokl@gmail.com | 
| Stability | experimental | 
| Safe Haskell | Safe-Inferred | 
| Language | Haskell2010 | 
Documentation.SBV.Examples.Transformers.SymbolicEval
Description
A demonstration of the use of the SymbolicT and QueryT transformers in
 the setting of symbolic program evaluation.
In this example, we perform symbolic evaluation across three steps:
- allocate free variables, so we can extract a model after evaluation
 - perform symbolic evaluation of a program and an associated property
 - querying the solver for whether it's possible to find a set of program inputs that falsify the property. if there is, we extract a model.
 
To simplify the example, our programs always have exactly two integer inputs
 named x and y.
Synopsis
- newtype Alloc a = Alloc {}
 - data Env = Env {}
 - alloc :: String -> Alloc (SBV Integer)
 - allocEnv :: Alloc Env
 - data Term :: Type -> Type where
- Var :: String -> Term r
 - Lit :: Integer -> Term Integer
 - Plus :: Term Integer -> Term Integer -> Term Integer
 - LessThan :: Term Integer -> Term Integer -> Term Bool
 - GreaterThan :: Term Integer -> Term Integer -> Term Bool
 - Equals :: Term Integer -> Term Integer -> Term Bool
 - Not :: Term Bool -> Term Bool
 - Or :: Term Bool -> Term Bool -> Term Bool
 - And :: Term Bool -> Term Bool -> Term Bool
 - Implies :: Term Bool -> Term Bool -> Term Bool
 
 - newtype Eval a = Eval {}
 - unsafeCastSBV :: SBV a -> SBV b
 - eval :: Term r -> Eval (SBV r)
 - runEval :: Env -> Term a -> Except String (SBV a)
 - newtype Program a = Program (Term a)
 - newtype Result = Result SVal
 - mkResult :: SBV a -> Result
 - runProgramEval :: Env -> Program a -> Except String Result
 - newtype Property = Property (Term Bool)
 - runPropertyEval :: Result -> Env -> Property -> Except String (SBV Bool)
 - data CheckResult
 - generalize :: Monad m => Identity a -> m a
 - newtype Q a = Q {}
 - mkQuery :: Env -> Q CheckResult
 - check :: Program a -> Property -> IO (Either String CheckResult)
 - ex1 :: IO (Either String CheckResult)
 - ex2 :: IO (Either String CheckResult)
 - ex3 :: IO (Either String CheckResult)
 
Allocation of symbolic variables, so we can extract a model later.
Monad for allocating free variables.
Instances
Environment holding allocated variables.
Symbolic term evaluation
data Term :: Type -> Type where Source #
The term language we use to express programs and properties.
Constructors
| Var :: String -> Term r | |
| Lit :: Integer -> Term Integer | |
| Plus :: Term Integer -> Term Integer -> Term Integer | |
| LessThan :: Term Integer -> Term Integer -> Term Bool | |
| GreaterThan :: Term Integer -> Term Integer -> Term Bool | |
| Equals :: Term Integer -> Term Integer -> Term Bool | |
| Not :: Term Bool -> Term Bool | |
| Or :: Term Bool -> Term Bool -> Term Bool | |
| And :: Term Bool -> Term Bool -> Term Bool | |
| Implies :: Term Bool -> Term Bool -> Term Bool | 
Monad for performing symbolic evaluation.
unsafeCastSBV :: SBV a -> SBV b Source #
Unsafe cast for symbolic values. In production code, we would check types instead.
runEval :: Env -> Term a -> Except String (SBV a) Source #
Runs symbolic evaluation, sending a Term to a symbolic value (or
 failing). Used for symbolic evaluation of programs and properties.
A program that can reference two input variables, x and y.
A symbolic value representing the result of running a program -- its output.
runProgramEval :: Env -> Program a -> Except String Result Source #
Performs symbolic evaluation of a Program.
Property evaluation
runPropertyEval :: Result -> Env -> Property -> Except String (SBV Bool) Source #
Performs symbolic evaluation of a 'Property.
Checking whether a program satisfies a property
data CheckResult Source #
Constructors
| Proved | |
| Counterexample Integer Integer | 
Instances
| Show CheckResult Source # | |
Defined in Documentation.SBV.Examples.Transformers.SymbolicEval Methods showsPrec :: Int -> CheckResult -> ShowS # show :: CheckResult -> String # showList :: [CheckResult] -> ShowS #  | |
| Eq CheckResult Source # | |
generalize :: Monad m => Identity a -> m a Source #
Sends an Identity computation to an arbitrary monadic computation.
Monad for querying a solver.
Instances
| MonadIO Q Source # | |
| Applicative Q Source # | |
| Functor Q Source # | |
| Monad Q Source # | |
| MonadQuery Q Source # | |
Defined in Documentation.SBV.Examples.Transformers.SymbolicEval Methods queryState :: Q State Source #  | |
| MonadError String Q Source # | |
mkQuery :: Env -> Q CheckResult Source #
Creates a computation that queries a solver and yields a CheckResult.
Some examples
ex1 :: IO (Either String CheckResult) Source #
Check that x+1+y generates a counter-example for the property that the
 result is less than 10 when x+y is at least 9. We have:
>>>ex1Right (Counterexample 0 9)