DA.Logic
DA.Logic
Logic - Propositional calculus.
Data Types
data Formula t
A
Formula tis a formula in propositional calculus with propositions of type t.
Proposition pis the formula pFor a formula f,
Negation fis ¬fConjunction [Formula t]
For formulas f1, ..., fn,
Conjunction [f1, ..., fn]is f1 ∧ ... ∧ fnDisjunction [Formula t]
For formulas f1, ..., fn,
Disjunction [f1, ..., fn]is f1 ∨ ... ∨ fninstance Applicative Formula
instance Eq t => Eq (Formula t)
Functions
(&&&): Formula t -> Formula t -> Formula t
&&& is the ∧ operation of the boolean algebra of formulas, to
be read as "and"
: Formula t -> Formula t -> Formula t
||| is the ∨ operation of the boolean algebra of formulas, to
be read as "or"
: Formula t
true is the 1 element of the boolean algebra of formulas,
represented as an empty conjunction.
: Formula t
false is the 0 element of the boolean algebra of formulas,
represented as an empty disjunction.
neg is the ¬ (negation) operation of the boolean algebra of
formulas.
conj is a list version of &&&, enabled by the associativity
of ∧.
disj is a list version of |||, enabled by the associativity
of ∨.
fromBool converts True to true and False to false.
toNNF transforms a formula to negation normal form
(see https://en.wikipedia.org/wiki/Negation_normal_form).
toDNF turns a formula into disjunctive normal form.
(see https://en.wikipedia.org/wiki/Disjunctive_normal_form).
: Applicative f => (t -> f s) -> Formula t -> f (Formula s)
An implementation of traverse in the usual sense.
: Formula t -> Formula s -> Formula (t, s)
zipFormulas takes to formulas of same shape, meaning only
propositions are different and zips them up.
: (t -> Optional Bool) -> Formula t -> Formula t
substitute takes a truth assignment and substitutes True or
False into the respective places in a formula.
reduce reduces a formula as far as possible by:
Removing any occurrences of
trueandfalse;Removing directly nested Conjunctions and Disjunctions;
Going to negation normal form.
isBool attempts to convert a formula to a bool. It satisfies
isBool true == Some True and isBool false == Some False.
Otherwise, it returns None.
: (t -> Optional Bool) -> Formula t -> Either (Formula t) Bool
interpret is a version of toBool that first substitutes using
a truth function and then reduces as far as possible.
: Applicative f => (t -> f (Optional Bool)) -> Formula t -> f (Formula t)
substituteA is a version of substitute that allows for truth
values to be obtained from an action.
: Applicative f => (t -> f (Optional Bool)) -> Formula t -> f (Either (Formula t) Bool)
interpretA is a version of interpret that allows for truth
values to be obtained form an action.