A small library to evaluate ternary logic expressions under various systems.
Common boolean logic is dictated by two values, True and False. Ternary logic allows for an intermediate value, usually I or U. Different systems designate this extra value to lean towards True or False, or be more neutral.
No specific GHC version required. Run the following to load the library.
ghci SimpleTernaryLogic.hs
The front-end syntax is similar to connectives in formal logic.
Logic Symbol | STL Syntax | Meaning |
---|---|---|
¬ | ! | Not |
∧ | & | And |
∨ | ‖ | Or |
→ | >> | Material Implication |
↔ | <-> | Biconditional Equivalence |
Construct Operations (Ops
) with lambdas. Ops take in two arbitrary Expressions and returns the specified composition:
type Op = Expression -> Expression -> Expression
myOp :: Op
myOp = (\e1 e2 -> ((e2 || e1) >> ((!) e2) <-> (e1 & e2)))
myOp T F
-- (((F ∨ T) → ¬F) ↔ (T ∧ F))
Remember that logic connectives are Ops
themselves:
(&), (||), (>>), (<->) :: Op
Currently, there are three supported Systems:
data Syst
= Kleene
| Lukasiewicz
| Bochvar
The main interface is through truthTable
. This evaluates the truth table of the given Op under a specified System.
truthTable :: Syst -> Op -> Table Expression
truthTable Lukasiewicz myOp
-- F. U. T.
-- F: F F T
-- U: F U U
-- T: F T F
- Wikipedia - Three-valued Logic
- Wikipedia - Many-value Logic
- Inspired by Janko-dev’s plogic