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

Types

t()

A trinary logical value: true, false, or maybe

Link to this section Types

Link to this type t()
t() :: boolean() | :maybe

A trinary logical value: true, false, or maybe

Link to this section Functions

Logical conjunction ()

Truth table

FMT
FFFF
MFMM
TFMT

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
Link to this function cyc_neg(arg1)
cyc_neg(Trilean.t()) :: Trilean.t()

Logical cyclic negation

Truth table

Acyclic not(A)
FT
MF
TM

Examples

iex> Trilean.cyc_neg(true)
Trilean.maybe()
iex> Trilean.cyc_neg(false)
true
iex> Trilean.cyc_neg(Trilean.maybe())
false
Link to this function equivalence(arg1, arg2)
equivalence(Trilean.t(), Trilean.t()) :: Trilean.t()

Logical equivalence ( or )

Truth table

FMT
FTMF
MMMM
TFMT

Examples

iex> Trilean.equivalence(true, true)
true
iex> Trilean.equivalence(false, false)
true
iex> Trilean.equivalence(Trilean.maybe(), false)
Trilean.maybe()
Link to this function false()
false() :: Trilean.t()

Return the false value.

This provided for symmetry with maybe/0.

Link to this function implies(arg1, arg2)
implies(Trilean.t(), Trilean.t()) :: Trilean.t()

Material implication ( or )

Truth table

FMT
FTTT
MMMT
TFMT

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
Link to this function maybe()
maybe() :: Trilean.t()

Returns the maybe value

Link to this function maybe?(arg1)
maybe?(Trilean.t()) :: boolean()

Implementation of I unary logic operator. “it is unknown that…” or “it is contingent that…”.

AI(A)
FF
MT
TF

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
FT
MM
TF

Examples

iex> Trilean.not(true)
false
iex> Trilean.not(false)
true
iex> Trilean.not(Trilean.maybe())
Trilean.maybe()

Logical disjunction ()

Truth table

FMT
FFMT
MMMt
TTTT

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()
Link to this function possible?(arg1)
possible?(Trilean.t()) :: boolean()

Logical possibility (or M or )

A◇A
FF
MT
TT

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.

Link to this function true?(arg1)
true?(Trilean.t()) :: boolean()

Logical necessity (or L or )

Truth table

A□A
FT
MF
TT

Examples

iex> Trilean.true?(false)
false
iex> Trilean.true?(Trilean.maybe())
false
iex> Trilean.true?(true)
true