Safe Haskell | None |
---|---|
Language | Haskell2010 |
Handling primitive Fortran values symbolically.
There are a few challenges that this module attempts to solve:
Fortran uses fixed-width machine integers and floating point reals. Sometimes we might want to reason about these directly (which is supported by SBV and therefore feasible). However, sometimes they get in the way of the logic and we just want to pretend that they're the pure mathematical values that they approximate. For example floating point addition obeys very few algebraic laws, so most theorems about real numbers don't hold at all for floating point numbers.
In addition, Fortran's boolean values are actually arbitrary signed integers. If we treat all boolean values symbolically as bit-vectors, logic can become very slow; so it might be best to pretend that all booleans are single bits. However, sometimes we might want to verify properties that rely on the actual bit-vector representation of booleans.
This module deals with these problems by abstracting over the choices: the user should be able to choose which representation they want to use for each primitive data type.
The user provides a PrimReprSpec
which specifies how each data type should be
treated. Some examples are provided: prsPrecise
treats all values precisely as
they are represented in the Fortran program. This makes logic slow and makes it
very difficult to prove many things, but it is most accurate. On the other hand,
prsIdealized
treats all values as their idealized mathematical equivalents.
This makes logic fast and lots intuitive properties can be proved easily.
However, these properties often will not hold in actual running Fortran
programs: sometimes in weird edge cases and sometimes in sensible-seeming
executions. It would be interesting future work to provide an analysis that
helps to determine which of the two applies to a particular program!
Synopsis
- data IntRepr a
- data RealRepr a
- data BoolRepr a
- data PrimReprHandler a = PrimReprHandler {
- _prhKind :: !Kind
- _prhLiteral :: !(a -> SVal)
- _prhSymbolic :: !(String -> Symbolic SVal)
- data PrimReprSpec = PrimReprSpec {
- _prsInt8Repr :: !(IntRepr Int8)
- _prsInt16Repr :: !(IntRepr Int16)
- _prsInt32Repr :: !(IntRepr Int32)
- _prsInt64Repr :: !(IntRepr Int64)
- _prsFloatRepr :: !(RealRepr Float)
- _prsDoubleRepr :: !(RealRepr Double)
- _prsBool8Repr :: !(BoolRepr Bool8)
- _prsBool16Repr :: !(BoolRepr Bool16)
- _prsBool32Repr :: !(BoolRepr Bool32)
- _prsBool64Repr :: !(BoolRepr Bool64)
- prhSymbolic :: forall a. Lens' (PrimReprHandler a) (String -> Symbolic SVal)
- prhLiteral :: forall a a. Lens (PrimReprHandler a) (PrimReprHandler a) (a -> SVal) (a -> SVal)
- prhKind :: forall a. Lens' (PrimReprHandler a) Kind
- prsInt8Repr :: Lens' PrimReprSpec (IntRepr Int8)
- prsInt64Repr :: Lens' PrimReprSpec (IntRepr Int64)
- prsInt32Repr :: Lens' PrimReprSpec (IntRepr Int32)
- prsInt16Repr :: Lens' PrimReprSpec (IntRepr Int16)
- prsFloatRepr :: Lens' PrimReprSpec (RealRepr Float)
- prsDoubleRepr :: Lens' PrimReprSpec (RealRepr Double)
- prsBool8Repr :: Lens' PrimReprSpec (BoolRepr Bool8)
- prsBool64Repr :: Lens' PrimReprSpec (BoolRepr Bool64)
- prsBool32Repr :: Lens' PrimReprSpec (BoolRepr Bool32)
- prsBool16Repr :: Lens' PrimReprSpec (BoolRepr Bool16)
- prsPrecise :: PrimReprSpec
- prsIdealized :: PrimReprSpec
- prsWithArbitraryInts :: Bool -> PrimReprSpec -> PrimReprSpec
- prsWithArbitraryReals :: Bool -> PrimReprSpec -> PrimReprSpec
- makeSymRepr :: PrimReprSpec -> Prim p k a -> PrimReprHandler a
- class HasPrimReprHandlers r where
- primReprHandlers :: r -> PrimReprHandlers
- primReprHandler :: r -> Prim p k a -> PrimReprHandler a
- newtype PrimReprHandlers = PrimReprHandlers {
- unPrimReprHandlers :: forall p k a. Prim p k a -> PrimReprHandler a
- primSBVKind :: (MonadReader r m, HasPrimReprHandlers r) => Prim p k a -> m Kind
- primLit :: (MonadReader r m, HasPrimReprHandlers r) => Prim p k a -> a -> m SVal
- primSymbolic :: (MonadReader r m, HasPrimReprHandlers r) => Prim p k a -> String -> m (Symbolic SVal)
Types
Instances
Eq (RealRepr a) Source # | |
Ord (RealRepr a) Source # | |
Defined in Language.Fortran.Model.Repr.Prim | |
Show (RealRepr a) Source # | |
Instances
Eq (BoolRepr a) Source # | |
Ord (BoolRepr a) Source # | |
Defined in Language.Fortran.Model.Repr.Prim | |
Show (BoolRepr a) Source # | |
data PrimReprHandler a Source #
PrimReprHandler | |
|
data PrimReprSpec Source #
PrimReprSpec | |
|
Lenses
prhSymbolic :: forall a. Lens' (PrimReprHandler a) (String -> Symbolic SVal) Source #
prhLiteral :: forall a a. Lens (PrimReprHandler a) (PrimReprHandler a) (a -> SVal) (a -> SVal) Source #
prhKind :: forall a. Lens' (PrimReprHandler a) Kind Source #
prsInt8Repr :: Lens' PrimReprSpec (IntRepr Int8) Source #
prsInt64Repr :: Lens' PrimReprSpec (IntRepr Int64) Source #
prsInt32Repr :: Lens' PrimReprSpec (IntRepr Int32) Source #
prsInt16Repr :: Lens' PrimReprSpec (IntRepr Int16) Source #
prsFloatRepr :: Lens' PrimReprSpec (RealRepr Float) Source #
prsDoubleRepr :: Lens' PrimReprSpec (RealRepr Double) Source #
prsBool8Repr :: Lens' PrimReprSpec (BoolRepr Bool8) Source #
prsBool64Repr :: Lens' PrimReprSpec (BoolRepr Bool64) Source #
prsBool32Repr :: Lens' PrimReprSpec (BoolRepr Bool32) Source #
prsBool16Repr :: Lens' PrimReprSpec (BoolRepr Bool16) Source #
Standard specs
prsWithArbitraryInts :: Bool -> PrimReprSpec -> PrimReprSpec Source #
prsWithArbitraryReals :: Bool -> PrimReprSpec -> PrimReprSpec Source #
Using specs
makeSymRepr :: PrimReprSpec -> Prim p k a -> PrimReprHandler a Source #
Monadic Accessors
class HasPrimReprHandlers r where Source #
Nothing
primReprHandlers :: r -> PrimReprHandlers Source #
primReprHandler :: r -> Prim p k a -> PrimReprHandler a Source #
Instances
HasPrimReprHandlers PrimReprHandlers Source # | |
Defined in Language.Fortran.Model.Repr.Prim primReprHandlers :: PrimReprHandlers -> PrimReprHandlers Source # primReprHandler :: forall (p :: Precision) (k :: BasicType) a. PrimReprHandlers -> Prim p k a -> PrimReprHandler a Source # |
newtype PrimReprHandlers Source #
PrimReprHandlers | |
|
Instances
HasPrimReprHandlers PrimReprHandlers Source # | |
Defined in Language.Fortran.Model.Repr.Prim primReprHandlers :: PrimReprHandlers -> PrimReprHandlers Source # primReprHandler :: forall (p :: Precision) (k :: BasicType) a. PrimReprHandlers -> Prim p k a -> PrimReprHandler a Source # |
primSBVKind :: (MonadReader r m, HasPrimReprHandlers r) => Prim p k a -> m Kind Source #
primLit :: (MonadReader r m, HasPrimReprHandlers r) => Prim p k a -> a -> m SVal Source #
primSymbolic :: (MonadReader r m, HasPrimReprHandlers r) => Prim p k a -> String -> m (Symbolic SVal) Source #