sbv-8.0: SMT Based Verification: Symbolic Haskell theorem prover using SMT solving.

Documentation.SBV.Examples.Misc.Enumerate

Description

Author : Levent Erkok License : BSD3 Maintainer: erkokl@gmail.com Stability : experimental

Demonstrates how enumerations can be translated to their SMT-Lib counterparts, without losing any information content. Also see Documentation.SBV.Examples.Puzzles.U2Bridge for a more detailed example involving enumerations.

Synopsis

Documentation

data E Source #

A simple enumerated type, that we'd like to translate to SMT-Lib intact; i.e., this type will not be uninterpreted but rather preserved and will be just like any other symbolic type SBV provides.

Also note that we need to have the following LANGUAGE options defined: TemplateHaskell, StandaloneDeriving, DeriveDataTypeable, DeriveAnyClass for this to work.

Constructors

 A B C
Instances
 Source # Instance details Methods(==) :: E -> E -> Bool #(/=) :: E -> E -> Bool # Source # Instance details Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> E -> c E #gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c E #toConstr :: E -> Constr #dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c E) #dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c E) #gmapT :: (forall b. Data b => b -> b) -> E -> E #gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> E -> r #gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> E -> r #gmapQ :: (forall d. Data d => d -> u) -> E -> [u] #gmapQi :: Int -> (forall d. Data d => d -> u) -> E -> u #gmapM :: Monad m => (forall d. Data d => d -> m d) -> E -> m E #gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> E -> m E #gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> E -> m E # Source # Instance details Methodscompare :: E -> E -> Ordering #(<) :: E -> E -> Bool #(<=) :: E -> E -> Bool #(>) :: E -> E -> Bool #(>=) :: E -> E -> Bool #max :: E -> E -> E #min :: E -> E -> E # Source # Instance details MethodsreadList :: ReadS [E] # Source # Instance details MethodsshowsPrec :: Int -> E -> ShowS #show :: E -> String #showList :: [E] -> ShowS # Source # Instance details Methods Source # Instance details MethodsmkSymVal :: MonadSymbolic m => Maybe Quantifier -> Maybe String -> m (SBV E) Source #fromCV :: CV -> E Source #isConcretely :: SBV E -> (E -> Bool) -> Bool Source #forall :: MonadSymbolic m => String -> m (SBV E) Source #forall_ :: MonadSymbolic m => m (SBV E) Source #mkForallVars :: MonadSymbolic m => Int -> m [SBV E] Source #exists :: MonadSymbolic m => String -> m (SBV E) Source #exists_ :: MonadSymbolic m => m (SBV E) Source #mkExistVars :: MonadSymbolic m => Int -> m [SBV E] Source #free :: MonadSymbolic m => String -> m (SBV E) Source #free_ :: MonadSymbolic m => m (SBV E) Source #mkFreeVars :: MonadSymbolic m => Int -> m [SBV E] Source #symbolic :: MonadSymbolic m => String -> m (SBV E) Source #symbolics :: MonadSymbolic m => [String] -> m [SBV E] Source # Source # Make E a symbolic value. Instance details MethodsparseCVs :: [CV] -> Maybe (E, [CV]) Source #cvtModel :: (E -> Maybe b) -> Maybe (E, [CV]) -> Maybe (b, [CV]) Source # Source # Instance details MethodssexprToVal :: SExpr -> Maybe E Source #

type SE = SBV E Source #

Give a name to the symbolic variants of E, for convenience

Have the SMT solver enumerate the elements of the domain. We have:

>>> elts
Solution #1:
s0 = B :: E
Solution #2:
s0 = A :: E
Solution #3:
s0 = C :: E
Found 3 different solutions.


Shows that if we require 4 distinct elements of the type E, we shall fail; as the domain only has three elements. We have:

>>> four
Unsatisfiable


Enumerations are automatically ordered, so we can ask for the maximum element. Note the use of quantification. We have:

>>> maxE
Satisfiable. Model:
maxE = C :: E


Similarly, we get the minumum element. We have:

>>> minE
Satisfiable. Model:
minE = A :: E