Ternary logic
From Wikipedia, the free encyclopedia
A ternary, three-valued or trivalent logic is a term to describe any of several multi-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 boolean logic) which provide only for true and false.
Contents |
[edit] Definitions
[edit] 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:
- 1 for true, 2 for false, and 0 for unknown, irrelevant, or both.[1]
- 0 for false, 1 for true, with the third value being non-integer symbol such as # or ½.[2]
- Balanced ternary uses -1 for false, 1 for true and 0 for the third value; these values may also be simplified to -, +, and 0, respectively.[3]
This article mainly illustrates a system of ternary propositional logic using the truth values {false, unknown, and true}, and extends conventional boolean connectives to a trivalent context. Ternary predicate logics exist as well[citation needed]; these may have readings of the quantifier different from classical (binary) predicate logic, and may include alternative quantifiers as well.
[edit] Basic truth table
Below is a truth table showing the results of some logic operations for a true/false/unknown state system.
A | B | A OR B | A AND B | NOT A |
---|---|---|---|---|
True | True | True | True | False |
False | True | True | False | True |
True | False | True | False | |
False | False | False | False | |
Unknown | True | True | Unknown | Unknown |
True | Unknown | True | Unknown | |
Unknown | False | Unknown | False | |
False | Unknown | Unknown | False | |
Unknown | Unknown | Unknown | Unknown |
In this truth table, the UNKNOWN state can be metaphorically thought of as a sealed box containing either an unambiguously TRUE or unambiguously FALSE value. 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 at least one UNKNOWN operand. For example, since TRUE OR TRUE equals TRUE, and TRUE OR FALSE also equals TRUE, one can infer that TRUE OR UNKNOWN equals TRUE, as well. In this example, since either bivalent state could be underlying the UNKNOWN state, but either state also yields the same result, a definitive TRUE results in all three cases.
[edit] Ternary logic in database applications
The database query language SQL implements ternary logic as a means of handling NULL field content. SQL uses NULL to represent missing data in a database. If a field contains no defined value, SQL assumes this means that an actual value exists, but that that value is not recorded in the database. Note that a missing value is not the same as either a numeric value of zero, or a string value of zero length. Comparing anything to NULL—even another NULL—results in an unknown truth state. For example, the SQL expression "City='Paris'" resolves to FALSE for a record with "Chicago" in the City field, but UNKNOWN for a record with a NULL City field. In other words, to SQL, an undefined field represents potentially any possible value: a missing city might or might not represent Paris.
Using ternary logic, SQL can then account for the UNKNOWN truth state in evaluating boolean expressions. Consider the expression "City='Paris' OR Balance<0.0". This expression resolves to TRUE for any record whose Balance field contains a negative number. Likewise, this expression is TRUE for any record with 'Paris' in its City field. The expression resolves to FALSE only for a record whose City field explicitly contains a string other than 'Paris', and whose Balance field explicitly contains a non-negative number. In any other case, the expression resolves to UNKNOWN. This is because a missing City value might be missing the string 'Paris', and a missing Balance might be missing a negative number. However, regardless of missing data, a boolean OR operation is FALSE only when both of its operands are also FALSE, so not all missing data leads to an UNKNOWN resolution.
In SQL, a truth state of TRUE for an expression (e.g. in a WHERE clause) triggers an action (e.g. return the row), while a truth state of UNKNOWN or FALSE does not.[4] In this way, ternary logic is implemented in SQL, while behaving as binary logic to the SQL user.
[edit] Electronics
Many hardware description language (HDL) simulation tools, such as verilog and VHDL, support an unknown value like that shown above during simulation of digital electronics. The unknown value may be the result of a design error, which the designer can correct before synthesis into an actual circuit. HDL synthesis tools usually produce circuits that operate only on binary logic.
The most widely implemented form of three-state logic is found in digital electronics. It is very important to note that this is not true ternary logic. It is mentioned here for completeness, being the only widespread three-state system in use. Outputs can have one of three states, yet inputs can only recognise two. Hence the kind of relations shown in the table above do not occur.
Commonly referred to as tristate [5] logic (a trademark of National Semiconductor), it comprises the usual true and false states, with a third transparent high impedance state (or 'off-state') which effectively disconnects the logic output. This provides an effective way to connect several logic outputs to a single input, where all but one are put into the high impedance state, allowing the remaining output to operate in the normal binary sense. This is commonly used to connect banks of computer memory and other similar devices to a common data bus; a large number of devices can communicate over the same channel simply by ensuring only one is enabled at a time.
Although it could be argued that the high-impedance state is effectively an "unknown", there is absolutely no provision in the vast majority of normal electronics to interpret a high-impedance state as a state in itself. Inputs can only detect true and false; high-impedance is best described as invisible. Typically, most electronic logic configurations default to a true state when they sense no input - thus they also interpret a high impedance on an input as a true state, although this is by no means universal.
True ternary logic can be implemented in electronics, although the complexity of design has thus far made it uneconomical to pursue commercially and interest has been primarily confined to research, since 'normal' binary logic is very much cheaper to implement and in most cases can easily be configured to emulate ternary systems. However, there are useful applications in fuzzy logic and error correction, and several true ternary logic devices have been manufactured (see external links).
[edit] References
- ^ Hayes, Brian (November-December, 2001). "Third Base". American Scientist 89 (6): 490-494. Retrieved on 2006-12-25.
- ^ (1998) The Penguin Dictionary of Mathematics. 2nd Edition. London, England: Penguin Books, 417.
- ^ Knuth, Donald E. (1981). The Art of Computer Programming Vol. 2. Reading, Mass.: Addison-Wesley Publishing Company, 190.
- ^ Lex de Haan and Gennick, Jonathan (July-August, 2005). "Nulls: Nothing to Worry About". Oracle Magazine.
- ^ National Semiconductor, LS TTL Data Book, National Semiconductor Corporation, 1993.
[edit] See also
- Digital circuit
- Ternary
- Ternary computer
- Boolean algebra
- Boolean function
- Binary logic
- Setun - an experimental Russian computer which was based on ternary logic
[edit] External links
- Trinary Computer Systems
- TriINTERCAL - the intentionally-obfuscated INTERCAL programming language supports an implementation of ternary logic
- Boost.Tribool – an implementation of ternary logic in C++
- Team-R2D2 - a French institute that fabricated the first full-ternary logic chip (a 64-tert SRAM and 4-tert adder) in 2004