sbv-13.1: SMT Based Verification: Symbolic Haskell theorem prover using SMT solving.
Copyright(c) Joel Burget
Levent Erkok
LicenseBSD3
Maintainererkokl@gmail.com
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Data.SBV.Maybe

Description

Symbolic option type, symbolic version of Haskell's Maybe type.

Synopsis

Constructing optional values

sJust :: SymVal a => SBV a -> SBV (Maybe a) Source #

Symbolic version of the constructor Just.

sNothing :: SymVal a => SBV (Maybe a) Source #

Symbolic version of the constructor Nothing.

liftMaybe :: SymVal a => Maybe (SBV a) -> SMaybe a Source #

Construct an SMaybe a from a Maybe (SBV a).

>>> liftMaybe (Just (3 :: SInteger))
Just 3 :: Maybe Integer
>>> liftMaybe (Nothing :: Maybe SInteger)
Nothing :: Maybe Integer

type SMaybe a = SBV (Maybe a) Source #

Symbolic version of the type Maybe.

sMaybe :: SymVal a => String -> Symbolic (SMaybe a) Source #

Declare a symbolic maybe.

sMaybe_ :: SymVal a => Symbolic (SMaybe a) Source #

Declare a symbolic maybe, unnamed.

sMaybes :: SymVal a => [String] -> Symbolic [SMaybe a] Source #

Declare a list of symbolic maybes.

Destructing optionals

maybe :: (SymVal a, SymVal b) => SBV b -> (SBV a -> SBV b) -> SMaybe a -> SBV b Source #

Case analysis for symbolic Maybes. If the value isNothing, return the default value; if it isJust, apply the function.

>>> sat $ \x -> x .== maybe 0 (`sMod` 2) (sJust (3 :: SInteger))
Satisfiable. Model:
  s0 = 1 :: Integer
>>> sat $ \x -> x .== maybe 0 (`sMod` 2) (sNothing :: SMaybe Integer)
Satisfiable. Model:
  s0 = 0 :: Integer
>>> let f = uninterpret "f" :: SInteger -> SBool
>>> prove $ \x d -> maybe d f (sJust x) .== f x
Q.E.D.
>>> prove $ \d -> maybe d f sNothing .== d
Q.E.D.

Mapping functions

map :: (SymVal a, SymVal b) => (SBV a -> SBV b) -> SMaybe a -> SMaybe b Source #

Map over the Just side of a Maybe.

>>> prove $ \x -> fromJust (map (+1) (sJust x)) .== x+(1::SInteger)
Q.E.D.
>>> let f = uninterpret "f" :: SInteger -> SBool
>>> prove $ \x -> map f (sJust x) .== sJust (f x)
Q.E.D.
>>> map f sNothing .== sNothing
True

map2 :: (SymVal a, SymVal b, SymVal c) => (SBV a -> SBV b -> SBV c) -> SMaybe a -> SMaybe b -> SMaybe c Source #

Map over two maybe values.

Scrutinizing the branches of an option

isNothing :: SymVal a => SBV (Maybe a) -> SBool Source #

Field recognizer predicate.

isJust :: SymVal a => SBV (Maybe a) -> SBool Source #

Field recognizer predicate.

fromMaybe :: SymVal a => SBV a -> SMaybe a -> SBV a Source #

Return the value of an optional value. The default is returned if Nothing. Compare to fromJust.

>>> fromMaybe 2 (sNothing :: SMaybe Integer)
2 :: SInteger
>>> sat $ \x -> fromMaybe 2 (sJust 5 :: SMaybe Integer) .== x
Satisfiable. Model:
  s0 = 5 :: Integer
>>> prove $ \x -> fromMaybe x (sNothing :: SMaybe Integer) .== x
Q.E.D.
>>> prove $ \x -> fromMaybe (x+1) (sJust x :: SMaybe Integer) .== x
Q.E.D.

fromJust :: SymVal a => SMaybe a -> SBV a Source #

Return the value of an optional value. The behavior is undefined if passed Nothing, i.e., it can return any value. Compare to fromMaybe.

>>> sat $ \x -> fromJust (sJust (literal 'a')) .== x
Satisfiable. Model:
  s0 = 'a' :: Char
>>> prove $ \x -> fromJust (sJust x) .== (x :: SChar)
Q.E.D.
>>> sat $ \x -> x .== (fromJust sNothing :: SChar)
Satisfiable. Model:
  s0 = 'A' :: Char

Note how we get a satisfying assignment in the last case: The behavior is unspecified, thus the SMT solver picks whatever satisfies the constraints, if there is one.

Orphan instances

(Ord a, SymVal a, Num a, Num (SBV a)) => Num (SBV (Maybe a)) Source #

Custom Num instance over SMaybe

Instance details

Methods

(+) :: SBV (Maybe a) -> SBV (Maybe a) -> SBV (Maybe a) #

(-) :: SBV (Maybe a) -> SBV (Maybe a) -> SBV (Maybe a) #

(*) :: SBV (Maybe a) -> SBV (Maybe a) -> SBV (Maybe a) #

negate :: SBV (Maybe a) -> SBV (Maybe a) #

abs :: SBV (Maybe a) -> SBV (Maybe a) #

signum :: SBV (Maybe a) -> SBV (Maybe a) #

fromInteger :: Integer -> SBV (Maybe a) #

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

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

(OrdSymbolic (SBV a), SymVal a) => OrdSymbolic (SBV (Maybe a)) Source #

Custom OrdSymbolic instance over SMaybe.

Instance details

Methods

(.<) :: SBV (Maybe a) -> SBV (Maybe a) -> SBool Source #

(.<=) :: SBV (Maybe a) -> SBV (Maybe a) -> SBool Source #

(.>) :: SBV (Maybe a) -> SBV (Maybe a) -> SBool Source #

(.>=) :: SBV (Maybe a) -> SBV (Maybe a) -> SBool Source #

smin :: SBV (Maybe a) -> SBV (Maybe a) -> SBV (Maybe a) Source #

smax :: SBV (Maybe a) -> SBV (Maybe a) -> SBV (Maybe a) Source #

inRange :: SBV (Maybe a) -> (SBV (Maybe a), SBV (Maybe a)) -> SBool Source #

SymVal a => HasInductionSchema (Forall ta (Maybe a) -> SBool) Source # 
Instance details

Methods

inductionSchema :: (Forall ta (Maybe a) -> SBool) -> ProofObj Source #

(SymVal a, SymVal extraT) => HasInductionSchema (Forall ta (Maybe a) -> Forall extraS extraT -> SBool) Source # 
Instance details

Methods

inductionSchema :: (Forall ta (Maybe a) -> Forall extraS extraT -> SBool) -> ProofObj Source #

(SymVal a, SymVal extraT1, SymVal extraT2) => HasInductionSchema (Forall ta (Maybe a) -> Forall extraS1 extraT1 -> Forall extraS2 extraT2 -> SBool) Source # 
Instance details

Methods

inductionSchema :: (Forall ta (Maybe a) -> Forall extraS1 extraT1 -> Forall extraS2 extraT2 -> SBool) -> ProofObj Source #

(SymVal a, SymVal extraT1, SymVal extraT2, SymVal extraT3) => HasInductionSchema (Forall ta (Maybe a) -> Forall extraS1 extraT1 -> Forall extraS2 extraT2 -> Forall extraS3 extraT3 -> SBool) Source # 
Instance details

Methods

inductionSchema :: (Forall ta (Maybe a) -> Forall extraS1 extraT1 -> Forall extraS2 extraT2 -> Forall extraS3 extraT3 -> SBool) -> ProofObj Source #

(SymVal a, SymVal extraT1, SymVal extraT2, SymVal extraT3, SymVal extraT4) => HasInductionSchema (Forall ta (Maybe a) -> Forall extraS1 extraT1 -> Forall extraS2 extraT2 -> Forall extraS3 extraT3 -> Forall extraS4 extraT4 -> SBool) Source # 
Instance details

Methods

inductionSchema :: (Forall ta (Maybe a) -> Forall extraS1 extraT1 -> Forall extraS2 extraT2 -> Forall extraS3 extraT3 -> Forall extraS4 extraT4 -> SBool) -> ProofObj Source #

(SymVal a, SymVal extraT1, SymVal extraT2, SymVal extraT3, SymVal extraT4, SymVal extraT5) => HasInductionSchema (Forall ta (Maybe a) -> Forall extraS1 extraT1 -> Forall extraS2 extraT2 -> Forall extraS3 extraT3 -> Forall extraS4 extraT4 -> Forall extraS5 extraT5 -> SBool) Source # 
Instance details

Methods

inductionSchema :: (Forall ta (Maybe a) -> Forall extraS1 extraT1 -> Forall extraS2 extraT2 -> Forall extraS3 extraT3 -> Forall extraS4 extraT4 -> Forall extraS5 extraT5 -> SBool) -> ProofObj Source #