Copyright | (C) 2017-18 Jakub Daniel |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | Jakub Daniel <jakub.daniel@protonmail.com> |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Usage:
You can build expressions in predefined languages (QFLogic
, QFLia
,
QFALia
, Lia
, ALia
) using the smart constructors such as var
, and
,
or
, not
, forall
, exists
(or operators .&.
, .|.
, .->.
, .<-.
,
.<->.
) or you can define your own sorted language as a fixpoint (IFix
)
of a sum (:+:
) of indexed functors (IFunctor
).
Synopsis
- module Data.Expression.Arithmetic
- module Data.Expression.Array
- module Data.Expression.Equality
- module Data.Expression.IfThenElse
- module Data.Expression.Parser
- data family Sing (a :: k) :: *
- data Sort
- data DynamicallySorted (f :: (Sort -> *) -> Sort -> *) where
- DynamicallySorted :: forall (s :: Sort) f. Sing s -> IFix f s -> DynamicallySorted f
- data DynamicSort where
- DynamicSort :: forall (s :: Sort). Sing s -> DynamicSort
- toStaticSort :: forall (s :: Sort). SingI s => DynamicSort -> Maybe (Sing s)
- toDynamicallySorted :: forall f (s :: Sort). SingI s => IFix f s -> DynamicallySorted f
- toStaticallySorted :: forall f (s :: Sort). SingI s => DynamicallySorted f -> Maybe (IFix f s)
- parseSort :: Parser DynamicSort
- module Data.Expression.Utils.Indexed.Eq
- module Data.Expression.Utils.Indexed.Foldable
- module Data.Expression.Utils.Indexed.Functor
- module Data.Expression.Utils.Indexed.Show
- module Data.Expression.Utils.Indexed.Sum
- module Data.Expression.Utils.Indexed.Traversable
- type QFLogicF = EqualityF :+: (ConjunctionF :+: (DisjunctionF :+: (NegationF :+: VarF)))
- type QFLiaF = ArithmeticF :+: (IfThenElseF :+: QFLogicF)
- type LiaF = ExistentialF BooleanSort :+: (ExistentialF IntegralSort :+: (UniversalF BooleanSort :+: (UniversalF IntegralSort :+: QFLiaF)))
- type QFALiaF = ArrayF :+: QFLiaF
- type ALiaF = ExistentialF BooleanSort :+: (ExistentialF IntegralSort :+: (UniversalF BooleanSort :+: (UniversalF IntegralSort :+: QFALiaF)))
- type Var = IFix VarF
- type QFLogic = IFix QFLogicF
- type QFLia = IFix QFLiaF
- type Lia = IFix LiaF
- type QFALia = IFix QFALiaF
- type ALia = IFix ALiaF
- class BoundedLattice a => ComplementedLattice a where
- type VariableName = String
- data VarF a (s :: Sort) where
- Var :: VariableName -> Sing s -> VarF a s
- data ConjunctionF a (s :: Sort) where
- And :: [a BooleanSort] -> ConjunctionF a BooleanSort
- data DisjunctionF a (s :: Sort) where
- Or :: [a BooleanSort] -> DisjunctionF a BooleanSort
- data NegationF a (s :: Sort) where
- Not :: a BooleanSort -> NegationF a BooleanSort
- data UniversalF (v :: Sort) a (s :: Sort) where
- Forall :: [Var v] -> a BooleanSort -> UniversalF v a BooleanSort
- data ExistentialF (v :: Sort) a (s :: Sort) where
- Exists :: [Var v] -> a BooleanSort -> ExistentialF v a BooleanSort
- newtype Substitution f = Substitution {
- runSubstitution :: forall (s :: Sort). IFix f s -> Maybe (IFix f s)
- substitute :: (IFunctor f, IEq1 f) => IFix f s -> Substitution f -> IFix f s
- for :: forall f (s :: Sort). (IFunctor f, IEq1 f) => IFix f s -> IFix f s -> Substitution f
- var :: forall f s. (VarF :<: f, SingI s) => VariableName -> IFix f s
- true :: ConjunctionF :<: f => IFix f BooleanSort
- false :: DisjunctionF :<: f => IFix f BooleanSort
- and :: ConjunctionF :<: f => [IFix f BooleanSort] -> IFix f BooleanSort
- or :: DisjunctionF :<: f => [IFix f BooleanSort] -> IFix f BooleanSort
- not :: NegationF :<: f => IFix f BooleanSort -> IFix f BooleanSort
- forall :: UniversalF v :<: f => [Var v] -> IFix f BooleanSort -> IFix f BooleanSort
- exists :: ExistentialF v :<: f => [Var v] -> IFix f BooleanSort -> IFix f BooleanSort
- (.&.) :: ConjunctionF :<: f => IFix f BooleanSort -> IFix f BooleanSort -> IFix f BooleanSort
- (.|.) :: DisjunctionF :<: f => IFix f BooleanSort -> IFix f BooleanSort -> IFix f BooleanSort
- (.->.) :: (DisjunctionF :<: f, NegationF :<: f) => IFix f BooleanSort -> IFix f BooleanSort -> IFix f BooleanSort
- (.<-.) :: (DisjunctionF :<: f, NegationF :<: f) => IFix f BooleanSort -> IFix f BooleanSort -> IFix f BooleanSort
- (.<->.) :: (ConjunctionF :<: f, DisjunctionF :<: f, NegationF :<: f) => IFix f BooleanSort -> IFix f BooleanSort -> IFix f BooleanSort
- (./=.) :: forall f s. (NegationF :<: f, EqualityF :<: f, SingI s) => IFix f s -> IFix f s -> IFix f BooleanSort
- literals :: (ConjunctionF :<: f, DisjunctionF :<: f) => IFix f BooleanSort -> [IFix f BooleanSort]
- conjuncts :: ConjunctionF :<: f => IFix f BooleanSort -> [IFix f BooleanSort]
- disjuncts :: DisjunctionF :<: f => IFix f BooleanSort -> [IFix f BooleanSort]
- vars :: (VarF :<: f, IFoldable f, IFunctor f) => IFix f s -> [DynamicallySorted VarF]
- freevars :: (IFunctor f, MaybeQuantified f) => IFix f s -> [DynamicallySorted VarF]
- class MaybeQuantified f
- isQuantified :: MaybeQuantified f => IFix f s -> Bool
- isQuantifierFree :: MaybeQuantified f => IFix f s -> Bool
- class (NegationF :<: f, HasDual f f) => NNF f
- nnf :: forall f. NNF f => IFix f BooleanSort -> IFix f BooleanSort
- class (VarF :<: f, NegationF :<: f, IFunctor f, IFoldable f, ITraversable f, HasDual f f, MaybeQuantified' f f) => Prenex f
- prenex :: forall f. Prenex f => IFix f BooleanSort -> IFix f BooleanSort
- class (VarF :<: f, Bind f f, Bind' f f, MaybeQuantified'' f f, IFoldable f, ITraversable f) => Flatten f
- flatten :: forall f. Flatten f => IFix f BooleanSort -> IFix f BooleanSort
- class (VarF :<: f, EqualityF :<: f, Bind f f, Bind' f f, MaybeQuantified'' f f, Forall f f, Axiomatized f f, IFoldable f, ITraversable f) => Unstore f
- unstore :: forall f. Unstore f => IFix f BooleanSort -> IFix f BooleanSort
Documentation
module Data.Expression.Arithmetic
module Data.Expression.Array
module Data.Expression.Equality
module Data.Expression.IfThenElse
module Data.Expression.Parser
data family Sing (a :: k) :: * #
The singleton kind-indexed data family.
Instances
A universe of recognized sorts
BooleanSort | booleans (true, false) |
IntegralSort | integers (..., -1, 0, 1, ...) |
ArraySort Sort Sort | arrays indexed by |
Instances
data DynamicallySorted (f :: (Sort -> *) -> Sort -> *) where Source #
An expression of some sort (obtained for example during parsing)
DynamicallySorted :: forall (s :: Sort) f. Sing s -> IFix f s -> DynamicallySorted f |
Instances
IEq1 f => Eq (DynamicallySorted f) Source # | |
Defined in Data.Expression.Sort (==) :: DynamicallySorted f -> DynamicallySorted f -> Bool # (/=) :: DynamicallySorted f -> DynamicallySorted f -> Bool # | |
(IFunctor f, IShow f) => Show (DynamicallySorted f) Source # | |
Defined in Data.Expression.Sort showsPrec :: Int -> DynamicallySorted f -> ShowS # show :: DynamicallySorted f -> String # showList :: [DynamicallySorted f] -> ShowS # |
data DynamicSort where Source #
Some sort (obtained for example during parsing)
DynamicSort :: forall (s :: Sort). Sing s -> DynamicSort |
Instances
Eq DynamicSort Source # | |
Defined in Data.Expression.Sort (==) :: DynamicSort -> DynamicSort -> Bool # (/=) :: DynamicSort -> DynamicSort -> Bool # |
toStaticSort :: forall (s :: Sort). SingI s => DynamicSort -> Maybe (Sing s) Source #
Tries to convert some sort (DynamicSort
) to a requested sort.
toDynamicallySorted :: forall f (s :: Sort). SingI s => IFix f s -> DynamicallySorted f Source #
Converts a statically sorted expression to a dynamically sorted one.
toStaticallySorted :: forall f (s :: Sort). SingI s => DynamicallySorted f -> Maybe (IFix f s) Source #
Tries to convert an expression (DynamicallySorted
) of some sort to an expression of requested sort.
Performs no conversions.
parseSort :: Parser DynamicSort Source #
Parser that accepts sort definitions such as bool
, int
, array int int
, array int (array ...)
.
type QFLiaF = ArithmeticF :+: (IfThenElseF :+: QFLogicF) Source #
A functor representing the language of quantifier-free linear integer arithmetic theory in first order logic (integer constants, integer variables, addition, multiplication, divisibility, ordering)
type LiaF = ExistentialF BooleanSort :+: (ExistentialF IntegralSort :+: (UniversalF BooleanSort :+: (UniversalF IntegralSort :+: QFLiaF))) Source #
A functor much like QFLiaF
with quantifiers over booleans and integers
type ALiaF = ExistentialF BooleanSort :+: (ExistentialF IntegralSort :+: (UniversalF BooleanSort :+: (UniversalF IntegralSort :+: QFALiaF))) Source #
A functor much like QFALiaF
with quantifiers over booleans and integers
A language consisting solely of variables (useful for listing variables outside of any particular context, such as bound variables of quantified formula)
class BoundedLattice a => ComplementedLattice a where Source #
Bounded lattices that support complementing elements
complement . complement = id
complement :: a -> a Source #
Instances
ComplementedLattice (ALia BooleanSort) Source # | |
Defined in Data.Expression complement :: ALia BooleanSort -> ALia BooleanSort Source # | |
ComplementedLattice (QFALia BooleanSort) Source # | |
Defined in Data.Expression | |
ComplementedLattice (Lia BooleanSort) Source # | |
Defined in Data.Expression complement :: Lia BooleanSort -> Lia BooleanSort Source # | |
ComplementedLattice (QFLia BooleanSort) Source # | |
Defined in Data.Expression | |
ComplementedLattice (QFLogic BooleanSort) Source # | |
Defined in Data.Expression |
type VariableName = String Source #
Type of names assigned to variables
data VarF a (s :: Sort) where Source #
A functor representing a sorted variable, each variable is identified by its name and sort
Var :: VariableName -> Sing s -> VarF a s |
Instances
data ConjunctionF a (s :: Sort) where Source #
A functor representing a logical connective for conjunction
And :: [a BooleanSort] -> ConjunctionF a BooleanSort |
Instances
data DisjunctionF a (s :: Sort) where Source #
A functor representing a logical connective for disjunction
Or :: [a BooleanSort] -> DisjunctionF a BooleanSort |
Instances
data NegationF a (s :: Sort) where Source #
A functor representing a logical connective for negation
Not :: a BooleanSort -> NegationF a BooleanSort |
Instances
data UniversalF (v :: Sort) a (s :: Sort) where Source #
A functor representing a mono-sorted universal quantifier binding a number of variables within a formula
Forall :: [Var v] -> a BooleanSort -> UniversalF v a BooleanSort |
Instances
data ExistentialF (v :: Sort) a (s :: Sort) where Source #
A functor representing a mono-sorted existential quantifier binding a number of variables within a formula
Exists :: [Var v] -> a BooleanSort -> ExistentialF v a BooleanSort |
Instances
newtype Substitution f Source #
Substitution that given an expression produces replacement if the expression is to be replaced or nothing otherwise.
Substitution | |
|
Instances
Semigroup (Substitution f) Source # | |
Defined in Data.Expression (<>) :: Substitution f -> Substitution f -> Substitution f # sconcat :: NonEmpty (Substitution f) -> Substitution f # stimes :: Integral b => b -> Substitution f -> Substitution f # | |
Monoid (Substitution f) Source # | |
Defined in Data.Expression mempty :: Substitution f # mappend :: Substitution f -> Substitution f -> Substitution f # mconcat :: [Substitution f] -> Substitution f # |
substitute :: (IFunctor f, IEq1 f) => IFix f s -> Substitution f -> IFix f s Source #
Executes a substitution.
for :: forall f (s :: Sort). (IFunctor f, IEq1 f) => IFix f s -> IFix f s -> Substitution f Source #
A simple constructor of substitutions that replaces the latter expression with the former.
var :: forall f s. (VarF :<: f, SingI s) => VariableName -> IFix f s Source #
A smart constructor for variables of any sort in any language Takes the variable name and infers the target language and sort from context.
var "a" :: Lia 'IntegralSort
true :: ConjunctionF :<: f => IFix f BooleanSort Source #
Logical tautology
false :: DisjunctionF :<: f => IFix f BooleanSort Source #
Logical contradiction
and :: ConjunctionF :<: f => [IFix f BooleanSort] -> IFix f BooleanSort Source #
A smart constructor for variadic conjunction
or :: DisjunctionF :<: f => [IFix f BooleanSort] -> IFix f BooleanSort Source #
A smart constructor for variadic disjunction
not :: NegationF :<: f => IFix f BooleanSort -> IFix f BooleanSort Source #
A smart constructor for negation
forall :: UniversalF v :<: f => [Var v] -> IFix f BooleanSort -> IFix f BooleanSort Source #
A smart constructor for universally quantified formulae
exists :: ExistentialF v :<: f => [Var v] -> IFix f BooleanSort -> IFix f BooleanSort Source #
A smart constructor for existentially quantified formulae
(.&.) :: ConjunctionF :<: f => IFix f BooleanSort -> IFix f BooleanSort -> IFix f BooleanSort infixr 6 Source #
A smart constructor for binary conjunction
(.|.) :: DisjunctionF :<: f => IFix f BooleanSort -> IFix f BooleanSort -> IFix f BooleanSort infixr 5 Source #
A smart constructor for binary disjunction
(.->.) :: (DisjunctionF :<: f, NegationF :<: f) => IFix f BooleanSort -> IFix f BooleanSort -> IFix f BooleanSort infixr 4 Source #
A smart constructor for implication (an abbreviation for not a .|. b
)
(.<-.) :: (DisjunctionF :<: f, NegationF :<: f) => IFix f BooleanSort -> IFix f BooleanSort -> IFix f BooleanSort infixl 4 Source #
A smart constructor for reversed implication (an abbreviation for a .|. not b
)
(.<->.) :: (ConjunctionF :<: f, DisjunctionF :<: f, NegationF :<: f) => IFix f BooleanSort -> IFix f BooleanSort -> IFix f BooleanSort infix 3 Source #
A smart constructor for if-and-only-if connective
(./=.) :: forall f s. (NegationF :<: f, EqualityF :<: f, SingI s) => IFix f s -> IFix f s -> IFix f BooleanSort infix 7 Source #
A smart constructor for disequality
literals :: (ConjunctionF :<: f, DisjunctionF :<: f) => IFix f BooleanSort -> [IFix f BooleanSort] Source #
literals
decomposes a boolean combination (formed with conjunctions and disjunctions, preferably in negation normal form) into its constituents.
conjuncts :: ConjunctionF :<: f => IFix f BooleanSort -> [IFix f BooleanSort] Source #
conjuncts
decomposes a conjunction into conjuncts.
disjuncts :: DisjunctionF :<: f => IFix f BooleanSort -> [IFix f BooleanSort] Source #
disjuncts
decomposes a disjunction into disjuncts.
vars :: (VarF :<: f, IFoldable f, IFunctor f) => IFix f s -> [DynamicallySorted VarF] Source #
Collects a list of all variables occurring in an expression (bound or free).
freevars :: (IFunctor f, MaybeQuantified f) => IFix f s -> [DynamicallySorted VarF] Source #
Collects a list of all free variables occurring in an expression.
class MaybeQuantified f Source #
isQuantified', freevars'
Instances
isQuantified :: MaybeQuantified f => IFix f s -> Bool Source #
Test whether an expression contains a quantifier.
isQuantifierFree :: MaybeQuantified f => IFix f s -> Bool Source #
Tests whether an expression is free of any quantifier.
nnf :: forall f. NNF f => IFix f BooleanSort -> IFix f BooleanSort Source #
Propagates negation toward boolean atoms (across conjunction, disjunction, quantifiers).
class (VarF :<: f, NegationF :<: f, IFunctor f, IFoldable f, ITraversable f, HasDual f f, MaybeQuantified' f f) => Prenex f Source #
prenex :: forall f. Prenex f => IFix f BooleanSort -> IFix f BooleanSort Source #
Puts an expression into prenex form (quantifier prefix and a quantifier-free formula).
class (VarF :<: f, Bind f f, Bind' f f, MaybeQuantified'' f f, IFoldable f, ITraversable f) => Flatten f Source #
flatten :: forall f. Flatten f => IFix f BooleanSort -> IFix f BooleanSort Source #
class (VarF :<: f, EqualityF :<: f, Bind f f, Bind' f f, MaybeQuantified'' f f, Forall f f, Axiomatized f f, IFoldable f, ITraversable f) => Unstore f Source #
unstore :: forall f. Unstore f => IFix f BooleanSort -> IFix f BooleanSort Source #
Replaces store
with an instance of its axiomatization.