trilean v1.0.1 Trilean
Trilean implements a functionally complete three-valued logic, K3+. This is an extension of Kleene’s strong logic of indeterminacy.
Three value logics allow reasoning in face of uncertainty. For example
iex> will_there_be_a_sea_battle_tomorrow = Trilean.maybe()
...> nice_day_tomorrow = true
...>
...> _should_i_pack_a_picnic = (
...> will_there_be_a_sea_battle_tomorrow
...> |> Trilean.and(nice_day_tomorrow)
...> |> Trilean.possible?()
...> )
true
I should pack a picnic because it will be a nice day and there could be a spectacle to watch. (The sea battle problem is Aristotle’s formulation of the contingent futures problem on which three value logics can shed some light.)
iex> will_there_be_a_sea_battle_tomorrow = Trilean.maybe()
...> nice_day_tomorrow = false
...>
...> _should_i_pack_a_picnic = (
...> will_there_be_a_sea_battle_tomorrow
...> |> Trilean.and(nice_day_tomorrow)
...> |> Trilean.possible?()
...> )
false
I should not pack a picnic even though there could be a spectacle because it will be a crummy day.
All expressions evaluate the same as they would in normal boolean logic if their inputs are true or false. If, however, one or more of the inputs is :maybe
then the output may become indeterminate. For example:
iex> Trilean.and(true, true)
true
iex> Trilean.and(true, false)
false
iex> Trilean.and(true, Trilean.maybe())
Trilean.maybe()
Link to this section Summary
Functions
Return the false value
Returns the maybe value
Implementation of I
unary logic operator. “it is unknown that…” or “it is contingent that…”
Returns the true value
Link to this section Types
A trinary logical value: true, false, or maybe
Link to this section Functions
Truth table
F | M | T | |
---|---|---|---|
F | F | F | F |
M | F | M | M |
T | F | M | T |
Examples
iex> Trilean.and(true, true)
true
iex> Trilean.and(true, Trilean.maybe())
Trilean.maybe()
iex> Trilean.and(true, false)
false
iex> Trilean.and(false, Trilean.maybe())
false
Truth table
A | cyclic not(A) |
---|---|
F | T |
M | F |
T | M |
Examples
iex> Trilean.cyc_neg(true)
Trilean.maybe()
iex> Trilean.cyc_neg(false)
true
iex> Trilean.cyc_neg(Trilean.maybe())
false
Truth table
F | M | T | |
---|---|---|---|
F | T | M | F |
M | M | M | M |
T | F | M | T |
Examples
iex> Trilean.equivalence(true, true)
true
iex> Trilean.equivalence(false, false)
true
iex> Trilean.equivalence(Trilean.maybe(), false)
Trilean.maybe()
Return the false value.
This provided for symmetry with maybe/0
.
Truth table
F | M | T | |
---|---|---|---|
F | T | T | T |
M | M | M | T |
T | F | M | T |
Examples
iex> Trilean.implies(true, true)
true
iex> Trilean.implies(true, false)
false
iex> Trilean.implies(Trilean.maybe(), false)
Trilean.maybe()
iex> Trilean.implies(Trilean.maybe(), Trilean.maybe())
Trilean.maybe()
iex> Trilean.implies(false, false)
true
iex> Trilean.implies(false, true)
true
Returns the maybe value
Implementation of I
unary logic operator. “it is unknown that…” or “it is contingent that…”.
A | I(A) |
---|---|
F | F |
M | T |
T | F |
Examples
iex> Trilean.maybe?(false)
false
iex> Trilean.maybe?(Trilean.maybe())
true
iex> Trilean.maybe?(true)
false
Logical negation or complement (¬
)
Truth table
A | ¬A |
---|---|
F | T |
M | M |
T | F |
Examples
iex> Trilean.not(true)
false
iex> Trilean.not(false)
true
iex> Trilean.not(Trilean.maybe())
Trilean.maybe()
Truth table
F | M | T | |
---|---|---|---|
F | F | M | T |
M | M | M | t |
T | T | T | T |
Examples
iex> Trilean.or(true, true)
true
iex> Trilean.or(true, false)
true
iex> Trilean.or(true, Trilean.maybe())
true
iex> Trilean.or(false, false)
false
iex> Trilean.or(false, Trilean.maybe())
Trilean.maybe()
Logical possibility (or M
or ◇
)
A | ◇A |
---|---|
F | F |
M | T |
T | T |
Examples
iex> Trilean.possible?(false)
false
iex> Trilean.possible?(Trilean.maybe())
true
iex> Trilean.possible?(true)
true
Returns the true value.
This provided for symmetry with maybe/0
.
Truth table
A | □A |
---|---|
F | T |
M | F |
T | T |
Examples
iex> Trilean.true?(false)
false
iex> Trilean.true?(Trilean.maybe())
false
iex> Trilean.true?(true)
true