Module 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”
- true
: Formula t
trueis the 1 element of the boolean algebra of formulas, represented as an empty conjunction.
- false
: Formula t
falseis the 0 element of the boolean algebra of formulas, represented as an empty disjunction.
- toNNF
-
toNNFtransforms a formula to negation normal form (see https://en.wikipedia.org/wiki/Negation_normal_form).
- toDNF
-
toDNFturns a formula into disjunctive normal form. (see https://en.wikipedia.org/wiki/Disjunctive_normal_form).
- traverse
: Applicative f => (t -> f s) -> Formula t -> f (Formula s)
An implementation of
traversein the usual sense.
- zipFormulas
: Formula t -> Formula s -> Formula (t, s)
zipFormulastakes to formulas of same shape, meaning only propositions are different and zips them up.
- substitute
: (t -> Optional Bool) -> Formula t -> Formula t
substitutetakes a truth assignment and substitutesTrueorFalseinto the respective places in a formula.
- reduce
-
reducereduces a formula as far as possible by:- Removing any occurrences of
trueandfalse; - Removing directly nested Conjunctions and Disjunctions;
- Going to negation normal form.
- Removing any occurrences of
- isBool
-
isBoolattempts to convert a formula to a bool. It satisfiesisBool true == Right TrueandtoBool false == Right False. Otherwise, it returnsLeft x, wherexis the input.
- interpret
: (t -> Optional Bool) -> Formula t -> Either (Formula t) Bool
interpretis a version oftoBoolthat first substitutes using a truth function and then reduces as far as possible.
- substituteA
: Applicative f => (t -> f (Optional Bool)) -> Formula t -> f (Formula t)
substituteAis a version ofsubstitutethat allows for truth values to be obtained from an action.
- interpretA
: Applicative f => (t -> f (Optional Bool)) -> Formula t -> f (Either (Formula t) Bool)
interpretAis a version ofinterpretthat allows for truth values to be obtained form an action.