Copyright | (c) Galois Inc 2019-2020 |
---|---|
License | BSD3 |
Maintainer | rdockins@galois.com |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
What4.Expr.BoolMap
Contents
Description
Declares a datatype for representing n-way conjunctions or disjunctions in a way that efficiently captures important algebraic laws like commutativity, associativity and resolution.
Synopsis
- data BoolMap (f :: BaseType -> Type)
- var :: (HashableF f, OrdF f) => f BaseBoolType -> Polarity -> BoolMap f
- addVar :: (HashableF f, OrdF f) => f BaseBoolType -> Polarity -> BoolMap f -> BoolMap f
- fromVars :: (HashableF f, OrdF f) => [(f BaseBoolType, Polarity)] -> BoolMap f
- combine :: OrdF f => BoolMap f -> BoolMap f -> BoolMap f
- data Polarity
- negatePolarity :: Polarity -> Polarity
- contains :: OrdF f => BoolMap f -> f BaseBoolType -> Maybe Polarity
- isInconsistent :: BoolMap f -> Bool
- isNull :: BoolMap f -> Bool
- data BoolMapView f
- viewBoolMap :: BoolMap f -> BoolMapView f
- foldMapVars :: Monoid m => (f BaseBoolType -> m) -> BoolMap f -> m
- traverseVars :: (Applicative m, HashableF g, OrdF g) => (f BaseBoolType -> m (g BaseBoolType)) -> BoolMap f -> m (BoolMap g)
- reversePolarities :: OrdF f => BoolMap f -> BoolMap f
- removeVar :: OrdF f => BoolMap f -> f BaseBoolType -> BoolMap f
- newtype Wrap (f :: k -> Type) (x :: k) = Wrap {
- unWrap :: f x
- newtype ConjMap f = ConjMap {
- getConjMap :: BoolMap f
- data ConjMapView f
- pattern ConjTrue :: ConjMapView f
- pattern ConjFalse :: ConjMapView f
- pattern Conjuncts :: NonEmpty (f BaseBoolType, Polarity) -> ConjMapView f
- viewConjMap :: forall f. ConjMap f -> ConjMapView f
- addConjunct :: forall f. (HashableF f, OrdF f) => f BaseBoolType -> Polarity -> ConjMap f -> ConjMap f
- evalConj :: Applicative m => (f BaseBoolType -> m Bool) -> ConjMap f -> m Bool
Documentation
data BoolMap (f :: BaseType -> Type) Source #
A representation of a conjunction or a disjunction.
This data structure keeps track of a collection of expressions together with their polarities. The implementation uses a map from expression values to their polarities, and thus automatically implements the associative, commutative and idempotency laws common to both conjunctions and disjunctions. Moreover, if the same expression occurs in the collection with opposite polarities, the entire collection collapses via a resolution step to an "inconsistent" map. For conjunctions this corresponds to a contradiction and represents false; for disjunction, this corresponds to the law of the excluded middle and represents true.
The annotation on the AnnotatedMap
is an incremental hash (IncrHash
)
of the map, used to support a fast Hashable
instance.
Instances
FoldableF BoolMap Source # | Specialized version of |
Defined in What4.Expr.BoolMap Methods foldMapF :: Monoid m => (forall (s :: k). e s -> m) -> BoolMap e -> m # foldrF :: (forall (s :: k). e s -> b -> b) -> b -> BoolMap e -> b # foldlF :: (forall (s :: k). b -> e s -> b) -> b -> BoolMap e -> b # foldrF' :: (forall (s :: k). e s -> b -> b) -> b -> BoolMap e -> b # foldlF' :: (forall (s :: k). b -> e s -> b) -> b -> BoolMap e -> b # toListF :: (forall (tp :: k). f tp -> a) -> BoolMap f -> [a] # | |
OrdF f => Semigroup (BoolMap f) Source # | |
OrdF f => Eq (BoolMap f) Source # | |
(OrdF f, HashableF f) => Hashable (BoolMap f) Source # | |
Defined in What4.Expr.BoolMap |
var :: (HashableF f, OrdF f) => f BaseBoolType -> Polarity -> BoolMap f Source #
Produce a singleton bool map, consisting of just the given term
addVar :: (HashableF f, OrdF f) => f BaseBoolType -> Polarity -> BoolMap f -> BoolMap f Source #
Add a variable to a bool map, performing a resolution step if possible
fromVars :: (HashableF f, OrdF f) => [(f BaseBoolType, Polarity)] -> BoolMap f Source #
Generate a bool map from a list of terms and polarities by repeatedly
calling addVar
.
combine :: OrdF f => BoolMap f -> BoolMap f -> BoolMap f Source #
Merge two bool maps, performing resolution as necessary.
Describes the occurrence of a variable or expression, whether it is negated or not.
negatePolarity :: Polarity -> Polarity Source #
Swap a polarity value
contains :: OrdF f => BoolMap f -> f BaseBoolType -> Maybe Polarity Source #
Test if the bool map contains the given term, and return the polarity of that term if so.
isInconsistent :: BoolMap f -> Bool Source #
Returns true for an inconsistent bool map
data BoolMapView f Source #
Represents the state of a BoolMap
(either a conjunction or disjunction).
If you know you are dealing with a BoolMap
that represents a conjunction,
consider using ConjMap
and viewConjMap
for the sake of clarity.
Constructors
BoolMapUnit | A bool map with no expressions, represents the unit of the corresponding operation |
BoolMapDualUnit | An inconsistent bool map, represents the dual of the operation unit |
BoolMapTerms (NonEmpty (f BaseBoolType, Polarity)) | The terms appearing in the bool map, of which there is at least one |
viewBoolMap :: BoolMap f -> BoolMapView f Source #
Deconstruct the given bool map for later processing
foldMapVars :: Monoid m => (f BaseBoolType -> m) -> BoolMap f -> m Source #
traverseVars :: (Applicative m, HashableF g, OrdF g) => (f BaseBoolType -> m (g BaseBoolType)) -> BoolMap f -> m (BoolMap g) Source #
Traverse the expressions in a bool map, and rebuild the map.
reversePolarities :: OrdF f => BoolMap f -> BoolMap f Source #
Swap the polarities of the terms in the given bool map.
removeVar :: OrdF f => BoolMap f -> f BaseBoolType -> BoolMap f Source #
Remove the given term from the bool map. The map is unchanged if inconsistent or if the term does not occur.
newtype Wrap (f :: k -> Type) (x :: k) Source #
Instances
TestEquality f => Eq (Wrap f x) Source # | |
OrdF f => Ord (Wrap f x) Source # | |
Defined in What4.Expr.BoolMap | |
(HashableF f, TestEquality f) => Hashable (Wrap f x) Source # | |
Defined in What4.Expr.BoolMap |
ConjMap
A BoolMap
representing a conjunction.
Constructors
ConjMap | |
Fields
|
Instances
FoldableF ConjMap Source # | |
Defined in What4.Expr.BoolMap Methods foldMapF :: Monoid m => (forall (s :: k). e s -> m) -> ConjMap e -> m # foldrF :: (forall (s :: k). e s -> b -> b) -> b -> ConjMap e -> b # foldlF :: (forall (s :: k). b -> e s -> b) -> b -> ConjMap e -> b # foldrF' :: (forall (s :: k). e s -> b -> b) -> b -> ConjMap e -> b # foldlF' :: (forall (s :: k). b -> e s -> b) -> b -> ConjMap e -> b # toListF :: (forall (tp :: k). f tp -> a) -> ConjMap f -> [a] # | |
OrdF f => Semigroup (ConjMap f) Source # | |
OrdF f => Eq (ConjMap f) Source # | |
(OrdF f, HashableF f) => Hashable (ConjMap f) Source # | |
Defined in What4.Expr.BoolMap |
data ConjMapView f Source #
Represents the state of a ConjMap
. See viewConjMap
.
Like BoolMapView
, but with more specific patterns for readability.
pattern ConjTrue :: ConjMapView f Source #
pattern ConjFalse :: ConjMapView f Source #
pattern Conjuncts :: NonEmpty (f BaseBoolType, Polarity) -> ConjMapView f Source #
viewConjMap :: forall f. ConjMap f -> ConjMapView f Source #
Deconstruct the given ConjMap
for later processing
addConjunct :: forall f. (HashableF f, OrdF f) => f BaseBoolType -> Polarity -> ConjMap f -> ConjMap f Source #