Copyright | (c) Artem Mavrin 2021 |
---|---|
License | BSD3 |
Maintainer | artemvmavrin@gmail.com |
Stability | experimental |
Portability | POSIX |
Safe Haskell | Safe |
Language | Haskell2010 |
Defines the Formula
type and related functions.
Synopsis
- data Formula a where
- prettyFormula :: PrettyPrintable a => Formula a -> String
- subformulas :: Ord a => Formula a -> Set (Formula a)
- substitute :: Eq a => Formula a -> a -> Formula a -> Formula a
- getAnyVariable :: Formula a -> Maybe a
Formula type
Formulas of propositional logic are built inductively from atomic propositions
- truth \(\top\),
- falsity \(\bot\), and
- propositional variables \(a, b, c, \ldots\)
using the unary connective
- negation \(\lnot\)
and the binary connectives
- implication \(\rightarrow\),
- disjunction \(\lor\),
- conjunction \(\land\), and
- equivalence \(\leftrightarrow\).
pattern Lit :: Bool -> Formula a | Propositional literal/constant. |
pattern Var :: a -> Formula a | Propositional variable. |
pattern Not :: Formula a -> Formula a | Negation. |
pattern Imp :: Formula a -> Formula a -> Formula a | Implication. |
pattern Or :: Formula a -> Formula a -> Formula a | Disjunction. |
pattern And :: Formula a -> Formula a -> Formula a | Conjunction. |
pattern Iff :: Formula a -> Formula a -> Formula a | Equivalence. |
Instances
Eq a => Eq (Formula a) Source # | Syntactic equality. |
Ord a => Ord (Formula a) Source # | First compare heights, then compare sizes, then resolve using the
convention |
Defined in AutoProof.Internal.Formula.Types | |
Read a => Read (Formula a) Source # | |
Show a => Show (Formula a) Source # | |
AST (Formula a) Source # | |
PrettyPrintable a => PrettyPrintable (Formula a) Source # | |
type Root (Formula a) Source # | |
Defined in AutoProof.Internal.Formula.Types |
Pretty-printing
prettyFormula :: PrettyPrintable a => Formula a -> String Source #
Get a pretty-printed representation of a propositional formula.
Examples
>>>
prettyFormula $ Imp (Var "a") (Or (Var "b") (Lit False))
"a → (b ∨ ⊥)"
Operations on formulas
subformulas :: Ord a => Formula a -> Set (Formula a) Source #
Get the set of subformulas of a propositional formula.
Examples
>>>
subformulas $ Or (Var 'x') (And (Var 'y') (Var 'z'))
fromList [Var 'x',Var 'y',Var 'z',And (Var 'y') (Var 'z'),Or (Var 'x') (And (Var 'y') (Var 'z'))]
substitute :: Eq a => Formula a -> a -> Formula a -> Formula a Source #
(
represents \(a[p/x]\), the substitution of each
occurence of the variable \(x\) in the formula \(a\) by the formula \(p\).substitute
a x p)
Examples
>>>
substitute (Imp (Var 'e') (Var 'e')) 'e' (And (Var 'a') (Var 'a'))
Imp (And (Var 'a') (Var 'a')) (And (Var 'a') (Var 'a'))
getAnyVariable :: Formula a -> Maybe a Source #
Obtain a propositional variable from a formula, if there is one.
Examples
>>>
getAnyVariable (Or (Var "a") (Var "b"))
Just "a"
>>>
getAnyVariable (Lit False :: Formula String)
Nothing