Copyright | (c) Galois Inc 2019-2020 |
---|---|
License | BSD3 |
Maintainer | rdockins@galois.com |
Safe Haskell | None |
Language | Haskell2010 |
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
- 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
Documentation
data BoolMap (f :: BaseType -> Type) Source #
This data structure keeps track of a collection of expressions together with their polarities. Such a collection might represent either a conjunction or a disjunction of expressions. 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.
Instances
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 bool map
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
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.