# Three-valued logic

In logic, a three-valued logic (also trinary logic, trivalent, ternary, or trilean, sometimes abbreviated 3VL) is any of several many-valued logic systems in which there are three truth values indicating true, false, and some third value. This is contrasted with the more commonly known bivalent logics (such as classical sentential or Boolean logic) which provide only for true and false.
Emil Leon Post is credited with first introducing additional logical truth degrees in his 1921 theory of elementary propositions. The conceptual form and basic ideas of three-valued logic were initially published by Jan Łukasiewicz and Clarence Irving Lewis. These were then re-formulated by Grigore Constantin Moisil in an axiomatic algebraic form, and also extended to n-valued logics in 1945.

## Pre-discovery

Around 1910, Charles Sanders Peirce defined a many-valued logic system. He never published it. In fact, he did not even number the three pages of notes where he defined his three-valued operators. Peirce soundly rejected the idea all propositions must be either true or false; boundary-propositions, he writes, are "at the limit between P and not P." However, as confident as he was that "Triadic Logic is universally true," he also jotted down that "All this is mighty close to nonsense." Only in 1966, when Max Fisch and Atwell Turquette began publishing what they rediscovered in his unpublished manuscripts, did Peirce's triadic ideas become widely known.

## Motivation

Broadly speaking, the primary motivation for research of three valued logic is to represent the truth value of a statement that cannot be represented as true or false. Łukasiewicz initially developed three-valued logic for the problem of future contingents to represent the truth value of statements about the undetermined future. Bruno de Finetti used a third value to represent when "a given individual does not know the [correct] response, at least at a given moment." Hilary Putnam used it to represent values that cannot physically be decided:
   For example, if we have verified (by using a speedometer) that the velocity of a motor car is such and such, it might be impossible in such a world to verify or falsify certain statements concerning its position at that moment. If we know by reference to a physical law together with certain observational data that a statement as to the position of a motor car can never be falsified or verified, then there may be some point to not regarding the statement as true or false, but regarding it as "middle". It is only because, in macrocosmic experience, everything that we regard as an empirically meaningful statement seems to be at least potentially verifiable or falsifiable that we prefer the convention according to which we say that every such statement is either true or false, but in many cases we don't know which.
Similarly, Stephen Cole Kleene used a third value to represent predicates that are "undecidable by [any] algorithms whether true or false"

## Representation of values

As with bivalent logic, truth values in ternary logic may be represented numerically using various representations of the ternary numeral system. A few of the more common examples are:
* in balanced ternary, each digit has one of 3 values: −1, 0, or +1; these values may also be simplified to −, 0, +, respectively;
* in the redundant binary representation, each digit can have a value of −1, 0, 0/1 (the value 0/1 has two different representations);
* in the ternary numeral system, each digit is a trit (trinary digit) having a value of: 0, 1, or 2;
* in the skew binary number system, only the least-significant non-zero digit can have a value of 2, and the remaining digits have a value of 0 or 1;
* 1 for true, 2 for false, and 0 for unknown, unknowable/undecidable, irrelevant, or both;
* 0 for false, 1 for true, and a third non-integer "maybe" symbol such as ?, #, ⁠1/2⁠, or xy.
Inside a ternary computer, ternary values are represented by ternary signals.
This article mainly illustrates a system of ternary propositional logic using the truth values {false, unknown, true}, and extends conventional Boolean connectives to a trivalent context.

## Logics

Boolean logic allows 2$^2$ = 4 unary operators; the addition of a third value in ternary logic leads to a total of 3$^3$ = 27 distinct operators on a single input value. (This may be made clear by considering all possible truth tables for an arbitrary unary operator. Given 2 possible values TF of the single Boolean input, there are four different patterns of output TT, TF, FT, FF resulting from the following unary operators acting on each value: always T, Identity, NOT, always F. Given three possible values of a ternary variable, each times three possible results of a unary operation, there are 27 different output patterns: TTT, TTU, TTF, TUT, TUU, TUF, TFT, TFU, TFF, UTT, UTU, UTF, UUT, UUU, UUF, UFT, UFU, UFF, FTT, FTU, FTF, FUT, FUU, FUF, FFT, FFU, and FFF.) Similarly, where Boolean logic has 2$^{2×2}$ = 16 distinct binary operators (operators with 2 inputs) possible, ternary logic has 3$^{3×3}$ = 19,683 such operators. Where the nontrival Boolean operators can be named (AND, NAND, OR, NOR, XOR, XNOR (equivalence), and 4 variants of implication or inequality), with six trivial operators considering 0 or 1 inputs only, it is unreasonable to attempt to name all but a small fraction of the possible ternary operators. Just as in bivalent logic, where not all operators are given names and subsets of functionally complete operators are used, there may be functionally complete sets of ternary-valued operators.

### Kleene and Priest logics

Below is a set of truth tables showing the logic operations for Stephen Cole Kleene's "strong logic of indeterminacy" and Graham Priest's "logic of paradox".
(F, false; U, unknown; T, true) :
NOT(A) :
| A | ¬A |
| F | T |
| U | U |
| T | F |
AND(A, B) :
| A ∧ B | A ∧ B | B | B | B |
| A ∧ B | A ∧ B | F | U | T |
| A | F | F | F | F |
| A | U | F | U | U |
| A | T | F | U | T |
OR(A, B) :
| A ∨ B | A ∨ B | B | B | B |
| A ∨ B | A ∨ B | F | U | T |
| A | F | F | U | T |
| A | U | U | U | T |
| A | T | T | T | T |
XOR(A, B) :
| A ⊕ B | A ⊕ B | B | B | B |
| A ⊕ B | A ⊕ B | F | U | T |
| A | F | F | U | T |
| A | U | U | U | U |
| A | T | T | U | F |
(−1, false; 0, unknown; +1, true) :
NEG(A) :
| A | ¬A |
| −1 | +1 |
| 0 | 0 |
| +1 | −1 |
MIN(A, B) :
| A ∧ B | A ∧ B | B | B | B |
| A ∧ B | A ∧ B | −1 | 0 | +1 |
| A | −1 | −1 | −1 | −1 |
| A | 0 | −1 | 0 | 0 |
| A | +1 | −1 | 0 | +1 |
MAX(A, B) :
| A ∨ B | A ∨ B | B | B | B |
| A ∨ B | A ∨ B | −1 | 0 | +1 |
| A | −1 | −1 | 0 | +1 |
| A | 0 | 0 | 0 | +1 |
| A | +1 | +1 | +1 | +1 |
MIN(MAX(A, B), NEG(MIN(A, B))) :
| A ⊕ B | A ⊕ B | B | B | B |
| A ⊕ B | A ⊕ B | −1 | 0 | +1 |
| A | −1 | −1 | 0 | +1 |
| A | 0 | 0 | 0 | 0 |
| A | +1 | +1 | 0 | −1 |
If the truth values 1, 0, and -1 are interpreted as integers, these operations may be expressed with the ordinary operations of arithmetic (where x + y uses addition, xy uses multiplication, and x$^2$ uses exponentiation), or by the minimum/maximum functions:
    ${\begin{aligned}x\wedge y&={\frac {1}{2}}(x+y-x^{2}-y^{2}+xy+x^{2}y^{2})=\min(x,y)\\x\vee y&={\frac {1}{2}}(x+y+x^{2}+y^{2}-xy-x^{2}y^{2})=\max(x,y)\\\neg x&=-x\end{aligned}}$
In these truth tables, the unknown state can be thought of as neither true nor false in Kleene logic, or thought of as both true and false in Priest logic. The difference lies in the definition of tautologies. Where Kleene logic's only designated truth value is T, Priest logic's designated truth values are both T and U. In Kleene logic, the knowledge of whether any particular unknown state secretly represents true or false at any moment in time is not available. However, certain logical operations can yield an unambiguous result, even if they involve an unknown operand. For example, because true OR true equals true, and true OR false also equals true, then true OR unknown equals true as well. In this example, because either bivalent state could be underlying the unknown state, and either state also yields the same result, true results in all three cases.
If numeric values, e.g. balanced ternary values, are assigned to false, unknown and true such that false is less than unknown and unknown is less than true, then A AND B AND C... = MIN(A, B, C ...) and A OR B OR C ... = MAX(A, B, C...).
Material implication for Kleene logic can be defined as:
$A\rightarrow B\ {\overset {\underset {\mathrm {def} }}{=}}\ {\mbox{OR}}(\ {\mbox{NOT}}(A),\ B)$, and its truth table is
IMP$_K$(A, B), OR(¬A, B) :
| A → B | A → B | B | B | B |
| A → B | A → B | F | U | T |
| A | F | T | T | T |
| A | U | U | U | T |
| A | T | F | U | T |
IMP$_K$(A, B), MAX(−A, B) :
| A → B | A → B | B | B | B |
| A → B | A → B | −1 | 0 | +1 |
| A | −1 | +1 | +1 | +1 |
| A | 0 | 0 | 0 | +1 |
| A | +1 | −1 | 0 | +1 |
which differs from that for Łukasiewicz logic (described below).
Kleene logic has no tautologies (valid formulas) because whenever all of the atomic components of a well-formed formula are assigned the value Unknown, the formula itself must also have the value Unknown. (And the only designated truth value for Kleene logic is True.) However, the lack of valid formulas does not mean that it lacks valid arguments and/or inference rules. An argument is semantically valid in Kleene logic if, whenever (for any interpretation/model) all of its premises are True, the conclusion must also be True. (The Logic of Paradox (LP) has the same truth tables as Kleene logic, but it has two designated truth values instead of one; these are: True and Both (the analogue of Unknown), so that LP does have tautologies but it has fewer valid inference rules).

### Łukasiewicz logic

The Łukasiewicz Ł3 has the same tables for AND, OR, and NOT as the Kleene logic given above, but differs in its definition of implication in that "unknown implies unknown" is true. This section follows the presentation from Malinowski's chapter of the Handbook of the History of Logic, vol 8.
Material implication for Łukasiewicz logic truth table is
IMP$_Ł$(A, B) :
| A → B | A → B | B | B | B |
| A → B | A → B | F | U | T |
| A | F | T | T | T |
| A | U | U | T | T |
| A | T | F | U | T |
IMP$_Ł$(A, B), MIN(1, 1−A+B) :
| A → B | A → B | B | B | B |
| A → B | A → B | −1 | 0 | +1 |
| A | −1 | +1 | +1 | +1 |
| A | 0 | 0 | +1 | +1 |
| A | +1 | −1 | 0 | +1 |
In fact, using Łukasiewicz's implication and negation, the other usual connectives may be derived as:
* A ∨ B = (A → B) → B
* A ∧ B = ¬(¬A ∨ ¬ B)
* A ⇔ B = (A → B) ∧ (B → A)
It is also possible to derive a few other useful unary operators (first derived by Tarski in 1921):
* MA = ¬A → A
* LA = ¬M¬A
* IA = MA ∧ ¬LA
They have the following truth tables:
| A | MA |
| F | F |
| U | T |
| T | T |
| A | LA |
| F | F |
| U | F |
| T | T |
| A | IA |
| F | F |
| U | T |
| T | F |
M is read as "it is not false that..." or in the (unsuccessful) Tarski–Łukasiewicz attempt to axiomatize modal logic using a three-valued logic, "it is possible that..." L is read "it is true that..." or "it is necessary that..." Finally I is read "it is unknown that..." or "it is contingent that..."
In Łukasiewicz's Ł3 the designated value is True, meaning that only a proposition having this value everywhere is considered a tautology. For example, A → A and A ↔ A are tautologies in Ł3 and also in classical logic. Not all tautologies of classical logic lift to Ł3 "as is". For example, the law of excluded middle, A ∨ ¬A, and the law of non-contradiction, ¬(A ∧ ¬A) are not tautologies in Ł3. However, using the operator I defined above, it is possible to state tautologies that are their analogues:
* A ∨ IA ∨ ¬A (law of excluded fourth)
* ¬(A ∧ ¬IA ∧ ¬A) (extended contradiction principle).

### RM3 logic

The truth table for the material implication of R-mingle 3 (RM3) is
IMP$_{RM3}$(A, B) :
| A → B | A → B | B | B | B |
| A → B | A → B | F | U | T |
| A | F | T | T | T |
| A | U | F | U | T |
| A | T | F | F | T |
A defining characteristic of RM3 is the lack of the axiom of Weakening:
* (A → (B → A))
which, by adjointness, is equivalent to the projection from the product:
* (A ⊗ B) → A
RM3 is a non-cartesian symmetric monoidal closed category; the product, which is left-adjoint to the implication, lacks valid projections, and has U as the monoid identity. This logic is equivalent to an "ideal" paraconsistent logic which also obeys the contrapositive.

### HT logic

The logic of here and there (HT, also referred as Smetanov logic SmT or as Gödel G3 logic), introduced by Heyting in 1930 as a model for studying intuitionistic logic, is a three-valued intermediate logic where the third truth value NF (not false) has the semantics of a proposition that can be intuitionistically proven to not be false, but does not have an intuitionistic proof of correctness.
(F, false; NF, not false; T, true) :
NOT$_{HT}$(A) :
| A | ¬A |
| F | T |
| NF | F |
| T | F |
IMP$_{HT}$(A, B) :
| A → B | A → B | B | B | B |
| A → B | A → B | F | NF | T |
| A | F | T | T | T |
| A | NF | F | T | T |
| A | T | F | NF | T |
It may be defined either by appending one of the two equivalent axioms (¬q → p) → (((p → q) → p) → p) or equivalently p∨(¬q)∨(p → q) to the axioms of intuitionistic logic, or by explicit truth tables for its operations. In particular, conjunction and disjunction are the same as for Kleene's and Łukasiewicz's logic, while the negation is different.
HT logic is the unique coatom in the lattice of intermediate logics. In this sense it may be viewed as the "second strongest" intermediate logic after classical logic.

### Bochvar logic

This logic is also known as a weak form of Kleene's three-valued logic.

### Ternary Post logic

    not(a) = (a + 1) mod 3, or
    not(a) = (a + 1) mod (n), where (n) is the value of a logic

### Modular algebras

Some 3VL modulars arithmetics have been introduced more recently, motivated by circuit problems rather than philosophical issues:
* Cohn algebra
* Pradhan algebra
* Dubrova and Muzio algebra

## Applications
### SQL

The database query language SQL implements ternary logic as a means of handling comparisons with NULL field content. SQL uses a common fragment of the Kleene K3 logic, restricted to AND, OR, and NOT tables.