boolexpr-0.2: Boolean expressions with various representations and search queries.
Copyright(c) Nicolas Pouillard 20082009
LicenseBSD3
MaintainerNicolas Pouillard <nicolas.pouillard@gmail.com>
Stabilityprovisional
Portability
Safe HaskellSafe-Inferred
LanguageHaskell98

Data.BoolExpr

Description

Boolean expressions and various representations.

Synopsis

A boolean class

class Boolean f where Source #

A boolean type class.

Methods

(/\) :: f a -> f a -> f a infix 9 Source #

(\/) :: f a -> f a -> f a infix 9 Source #

bNot :: f a -> f a Source #

bTrue :: f a Source #

bFalse :: f a Source #

bConst :: Signed a -> f a Source #

Instances

Instances details
Boolean BoolExpr Source # 
Instance details

Defined in Data.BoolExpr

Boolean CNF Source # 
Instance details

Defined in Data.BoolExpr

Methods

(/\) :: CNF a -> CNF a -> CNF a Source #

(\/) :: CNF a -> CNF a -> CNF a Source #

bNot :: CNF a -> CNF a Source #

bTrue :: CNF a Source #

bFalse :: CNF a Source #

bConst :: Signed a -> CNF a Source #

Boolean DNF Source # 
Instance details

Defined in Data.BoolExpr

Methods

(/\) :: DNF a -> DNF a -> DNF a Source #

(\/) :: DNF a -> DNF a -> DNF a Source #

bNot :: DNF a -> DNF a Source #

bTrue :: DNF a Source #

bFalse :: DNF a Source #

bConst :: Signed a -> DNF a Source #

b ~ Bool => Boolean (Eval b) Source # 
Instance details

Defined in Data.BoolExpr

Methods

(/\) :: Eval b a -> Eval b a -> Eval b a Source #

(\/) :: Eval b a -> Eval b a -> Eval b a Source #

bNot :: Eval b a -> Eval b a Source #

bTrue :: Eval b a Source #

bFalse :: Eval b a Source #

bConst :: Signed a -> Eval b a Source #

Generic functions derived from Boolean

bAnd :: (Foldable t, Boolean f) => t (f b) -> f b Source #

Generalized and.

bAll :: (Foldable t, Boolean f) => (a -> f b) -> t a -> f b Source #

Generalized all.

bOr :: (Foldable t, Boolean f) => t (f b) -> f b Source #

Generalized or.

bAny :: (Foldable t, Boolean f) => (a -> f b) -> t a -> f b Source #

Generalized any.

Boolean trees

data BoolExpr a Source #

Syntax of boolean expressions parameterized over a set of leaves, named constants.

Constructors

BAnd (BoolExpr a) (BoolExpr a) 
BOr (BoolExpr a) (BoolExpr a) 
BNot (BoolExpr a) 
BTrue 
BFalse 
BConst (Signed a) 

Instances

Instances details
Foldable BoolExpr Source # 
Instance details

Defined in Data.BoolExpr

Methods

fold :: Monoid m => BoolExpr m -> m #

foldMap :: Monoid m => (a -> m) -> BoolExpr a -> m #

foldMap' :: Monoid m => (a -> m) -> BoolExpr a -> m #

foldr :: (a -> b -> b) -> b -> BoolExpr a -> b #

foldr' :: (a -> b -> b) -> b -> BoolExpr a -> b #

foldl :: (b -> a -> b) -> b -> BoolExpr a -> b #

foldl' :: (b -> a -> b) -> b -> BoolExpr a -> b #

foldr1 :: (a -> a -> a) -> BoolExpr a -> a #

foldl1 :: (a -> a -> a) -> BoolExpr a -> a #

toList :: BoolExpr a -> [a] #

null :: BoolExpr a -> Bool #

length :: BoolExpr a -> Int #

elem :: Eq a => a -> BoolExpr a -> Bool #

maximum :: Ord a => BoolExpr a -> a #

minimum :: Ord a => BoolExpr a -> a #

sum :: Num a => BoolExpr a -> a #

product :: Num a => BoolExpr a -> a #

Traversable BoolExpr Source # 
Instance details

Defined in Data.BoolExpr

Methods

traverse :: Applicative f => (a -> f b) -> BoolExpr a -> f (BoolExpr b) #

sequenceA :: Applicative f => BoolExpr (f a) -> f (BoolExpr a) #

mapM :: Monad m => (a -> m b) -> BoolExpr a -> m (BoolExpr b) #

sequence :: Monad m => BoolExpr (m a) -> m (BoolExpr a) #

Functor BoolExpr Source # 
Instance details

Defined in Data.BoolExpr

Methods

fmap :: (a -> b) -> BoolExpr a -> BoolExpr b #

(<$) :: a -> BoolExpr b -> BoolExpr a #

Boolean BoolExpr Source # 
Instance details

Defined in Data.BoolExpr

Show a => Show (BoolExpr a) Source # 
Instance details

Defined in Data.BoolExpr

Methods

showsPrec :: Int -> BoolExpr a -> ShowS #

show :: BoolExpr a -> String #

showList :: [BoolExpr a] -> ShowS #

Eq a => Eq (BoolExpr a) Source # 
Instance details

Defined in Data.BoolExpr

Methods

(==) :: BoolExpr a -> BoolExpr a -> Bool #

(/=) :: BoolExpr a -> BoolExpr a -> Bool #

Ord a => Ord (BoolExpr a) Source # 
Instance details

Defined in Data.BoolExpr

Methods

compare :: BoolExpr a -> BoolExpr a -> Ordering #

(<) :: BoolExpr a -> BoolExpr a -> Bool #

(<=) :: BoolExpr a -> BoolExpr a -> Bool #

(>) :: BoolExpr a -> BoolExpr a -> Bool #

(>=) :: BoolExpr a -> BoolExpr a -> Bool #

max :: BoolExpr a -> BoolExpr a -> BoolExpr a #

min :: BoolExpr a -> BoolExpr a -> BoolExpr a #

reduceBoolExpr :: BoolExpr Bool -> Bool Source #

Reduce a boolean tree annotated by booleans to a single boolean.

Boolean evaluation semantic

newtype Eval b a Source #

Constructors

Eval 

Fields

Instances

Instances details
b ~ Bool => Boolean (Eval b) Source # 
Instance details

Defined in Data.BoolExpr

Methods

(/\) :: Eval b a -> Eval b a -> Eval b a Source #

(\/) :: Eval b a -> Eval b a -> Eval b a Source #

bNot :: Eval b a -> Eval b a Source #

bTrue :: Eval b a Source #

bFalse :: Eval b a Source #

bConst :: Signed a -> Eval b a Source #

runEvalId :: Eval a a -> a Source #

Signed constants

data Signed a Source #

Signed values are either positive or negative.

Constructors

Positive a 
Negative a 

Instances

Instances details
Foldable Signed Source # 
Instance details

Defined in Data.BoolExpr

Methods

fold :: Monoid m => Signed m -> m #

foldMap :: Monoid m => (a -> m) -> Signed a -> m #

foldMap' :: Monoid m => (a -> m) -> Signed a -> m #

foldr :: (a -> b -> b) -> b -> Signed a -> b #

foldr' :: (a -> b -> b) -> b -> Signed a -> b #

foldl :: (b -> a -> b) -> b -> Signed a -> b #

foldl' :: (b -> a -> b) -> b -> Signed a -> b #

foldr1 :: (a -> a -> a) -> Signed a -> a #

foldl1 :: (a -> a -> a) -> Signed a -> a #

toList :: Signed a -> [a] #

null :: Signed a -> Bool #

length :: Signed a -> Int #

elem :: Eq a => a -> Signed a -> Bool #

maximum :: Ord a => Signed a -> a #

minimum :: Ord a => Signed a -> a #

sum :: Num a => Signed a -> a #

product :: Num a => Signed a -> a #

Traversable Signed Source # 
Instance details

Defined in Data.BoolExpr

Methods

traverse :: Applicative f => (a -> f b) -> Signed a -> f (Signed b) #

sequenceA :: Applicative f => Signed (f a) -> f (Signed a) #

mapM :: Monad m => (a -> m b) -> Signed a -> m (Signed b) #

sequence :: Monad m => Signed (m a) -> m (Signed a) #

Applicative Signed Source # 
Instance details

Defined in Data.BoolExpr

Methods

pure :: a -> Signed a #

(<*>) :: Signed (a -> b) -> Signed a -> Signed b #

liftA2 :: (a -> b -> c) -> Signed a -> Signed b -> Signed c #

(*>) :: Signed a -> Signed b -> Signed b #

(<*) :: Signed a -> Signed b -> Signed a #

Functor Signed Source # 
Instance details

Defined in Data.BoolExpr

Methods

fmap :: (a -> b) -> Signed a -> Signed b #

(<$) :: a -> Signed b -> Signed a #

Monad Signed Source # 
Instance details

Defined in Data.BoolExpr

Methods

(>>=) :: Signed a -> (a -> Signed b) -> Signed b #

(>>) :: Signed a -> Signed b -> Signed b #

return :: a -> Signed a #

Read a => Read (Signed a) Source # 
Instance details

Defined in Data.BoolExpr

Show a => Show (Signed a) Source # 
Instance details

Defined in Data.BoolExpr

Methods

showsPrec :: Int -> Signed a -> ShowS #

show :: Signed a -> String #

showList :: [Signed a] -> ShowS #

Eq a => Eq (Signed a) Source # 
Instance details

Defined in Data.BoolExpr

Methods

(==) :: Signed a -> Signed a -> Bool #

(/=) :: Signed a -> Signed a -> Bool #

Ord a => Ord (Signed a) Source # 
Instance details

Defined in Data.BoolExpr

Methods

compare :: Signed a -> Signed a -> Ordering #

(<) :: Signed a -> Signed a -> Bool #

(<=) :: Signed a -> Signed a -> Bool #

(>) :: Signed a -> Signed a -> Bool #

(>=) :: Signed a -> Signed a -> Bool #

max :: Signed a -> Signed a -> Signed a #

min :: Signed a -> Signed a -> Signed a #

evalSigned :: (a -> Bool) -> Signed a -> Bool Source #

constants :: BoolExpr a -> [Signed a] Source #

Returns constants used in a given boolean tree, these constants are returned signed depending one how many negations stands over a given constant.

Conjunctive Normal Form

newtype CNF a Source #

Constructors

CNF 

Fields

Instances

Instances details
Functor CNF Source # 
Instance details

Defined in Data.BoolExpr

Methods

fmap :: (a -> b) -> CNF a -> CNF b #

(<$) :: a -> CNF b -> CNF a #

Boolean CNF Source # 
Instance details

Defined in Data.BoolExpr

Methods

(/\) :: CNF a -> CNF a -> CNF a Source #

(\/) :: CNF a -> CNF a -> CNF a Source #

bNot :: CNF a -> CNF a Source #

bTrue :: CNF a Source #

bFalse :: CNF a Source #

bConst :: Signed a -> CNF a Source #

Monoid (CNF a) Source # 
Instance details

Defined in Data.BoolExpr

Methods

mempty :: CNF a #

mappend :: CNF a -> CNF a -> CNF a #

mconcat :: [CNF a] -> CNF a #

Semigroup (CNF a) Source # 
Instance details

Defined in Data.BoolExpr

Methods

(<>) :: CNF a -> CNF a -> CNF a #

sconcat :: NonEmpty (CNF a) -> CNF a #

stimes :: Integral b => b -> CNF a -> CNF a #

Show a => Show (CNF a) Source # 
Instance details

Defined in Data.BoolExpr

Methods

showsPrec :: Int -> CNF a -> ShowS #

show :: CNF a -> String #

showList :: [CNF a] -> ShowS #

newtype Conj a Source #

Constructors

Conj 

Fields

Instances

Instances details
Functor Conj Source # 
Instance details

Defined in Data.BoolExpr

Methods

fmap :: (a -> b) -> Conj a -> Conj b #

(<$) :: a -> Conj b -> Conj a #

Monoid (Conj a) Source # 
Instance details

Defined in Data.BoolExpr

Methods

mempty :: Conj a #

mappend :: Conj a -> Conj a -> Conj a #

mconcat :: [Conj a] -> Conj a #

Semigroup (Conj a) Source # 
Instance details

Defined in Data.BoolExpr

Methods

(<>) :: Conj a -> Conj a -> Conj a #

sconcat :: NonEmpty (Conj a) -> Conj a #

stimes :: Integral b => b -> Conj a -> Conj a #

Show a => Show (Conj a) Source # 
Instance details

Defined in Data.BoolExpr

Methods

showsPrec :: Int -> Conj a -> ShowS #

show :: Conj a -> String #

showList :: [Conj a] -> ShowS #

fromCNF :: Boolean f => CNF a -> f a Source #

Convert a CNF (a boolean expression in conjunctive normal form) to any other form supported by Boolean.

boolTreeToCNF :: BoolExpr a -> CNF a Source #

Convert a boolean tree to a conjunctive normal form.

reduceCNF :: CNF Bool -> Bool Source #

Reduce a boolean expression in conjunctive normal form to a single boolean.

Disjunctive Normal Form

newtype Disj a Source #

Constructors

Disj 

Fields

Instances

Instances details
Functor Disj Source # 
Instance details

Defined in Data.BoolExpr

Methods

fmap :: (a -> b) -> Disj a -> Disj b #

(<$) :: a -> Disj b -> Disj a #

Monoid (Disj a) Source # 
Instance details

Defined in Data.BoolExpr

Methods

mempty :: Disj a #

mappend :: Disj a -> Disj a -> Disj a #

mconcat :: [Disj a] -> Disj a #

Semigroup (Disj a) Source # 
Instance details

Defined in Data.BoolExpr

Methods

(<>) :: Disj a -> Disj a -> Disj a #

sconcat :: NonEmpty (Disj a) -> Disj a #

stimes :: Integral b => b -> Disj a -> Disj a #

Show a => Show (Disj a) Source # 
Instance details

Defined in Data.BoolExpr

Methods

showsPrec :: Int -> Disj a -> ShowS #

show :: Disj a -> String #

showList :: [Disj a] -> ShowS #

newtype DNF a Source #

Constructors

DNF 

Fields

Instances

Instances details
Functor DNF Source # 
Instance details

Defined in Data.BoolExpr

Methods

fmap :: (a -> b) -> DNF a -> DNF b #

(<$) :: a -> DNF b -> DNF a #

Boolean DNF Source # 
Instance details

Defined in Data.BoolExpr

Methods

(/\) :: DNF a -> DNF a -> DNF a Source #

(\/) :: DNF a -> DNF a -> DNF a Source #

bNot :: DNF a -> DNF a Source #

bTrue :: DNF a Source #

bFalse :: DNF a Source #

bConst :: Signed a -> DNF a Source #

Monoid (DNF a) Source # 
Instance details

Defined in Data.BoolExpr

Methods

mempty :: DNF a #

mappend :: DNF a -> DNF a -> DNF a #

mconcat :: [DNF a] -> DNF a #

Semigroup (DNF a) Source # 
Instance details

Defined in Data.BoolExpr

Methods

(<>) :: DNF a -> DNF a -> DNF a #

sconcat :: NonEmpty (DNF a) -> DNF a #

stimes :: Integral b => b -> DNF a -> DNF a #

Show a => Show (DNF a) Source # 
Instance details

Defined in Data.BoolExpr

Methods

showsPrec :: Int -> DNF a -> ShowS #

show :: DNF a -> String #

showList :: [DNF a] -> ShowS #

fromDNF :: Boolean f => DNF a -> f a Source #

Convert a DNF (a boolean expression in disjunctive normal form) to any other form supported by Boolean.

boolTreeToDNF :: BoolExpr a -> DNF a Source #

Convert a boolean tree to a disjunctive normal form.

reduceDNF :: DNF Bool -> Bool Source #

Reduce a boolean expression in disjunctive normal form to a single boolean.

Other transformations

dualize :: Boolean f => BoolExpr a -> f a Source #

fromBoolExpr :: Boolean f => BoolExpr a -> f a Source #

Turns a boolean tree into any boolean type.

pushNotInwards :: Boolean f => BoolExpr a -> f a Source #

Push the negations inwards as much as possible. The resulting boolean tree no longer use negations.