Exclusive or

Last updated
Exclusive or
XOR
Venn0110.svg
Truth table
Logic gate XOR ANSI.svg
Normal forms
Disjunctive
Conjunctive
Zhegalkin polynomial
Post's lattices
0-preservingyes
1-preservingno
Monotone no
Affine yes
Self-dualno
Venn diagram of
A
[?]
B
[?]
C
{\displaystyle A\oplus B\oplus C} Venn 0110 1001.svg
Venn diagram of

Exclusive or, exclusive disjunction, exclusive alternation, logical non-equivalence, or logical inequality is a logical operator whose negation is the logical biconditional. With two inputs, XOR is true if and only if the inputs differ (one is true, one is false). With multiple inputs, XOR is true if and only if the number of true inputs is odd. [1]

Contents

It gains the name "exclusive or" because the meaning of "or" is ambiguous when both operands are true. XOR excludes that case. Some informal ways of describing XOR are "one or the other but not both", "either one or the other", and "A or B, but not A and B".

It is symbolized by the prefix operator [2] :16 and by the infix operators XOR ( /ˌɛksˈɔːr/ , /ˌɛksˈɔː/ , /ˈksɔːr/ or /ˈksɔː/ ), EOR, EXOR, , , , , , , and .

Definition

Each row of this binary Walsh matrix is the truth table of the variadic XOR of the arguments shown on the left. E.g. row AB corresponds to the 2-circle, and row ABC to the 3-circle Venn diagram shown above. (As in the Venn diagrams, white is false, and red is true.) Variadic logical XOR.svg
Each row of this binary Walsh matrix is the truth table of the variadic XOR of the arguments shown on the left. E.g. row AB corresponds to the 2-circle, and row ABC to the 3-circle Venn diagram shown above. (As in the Venn diagrams, white is false, and red is true.)

The truth table of shows that it outputs true whenever the inputs differ:

FFF
FTT
TFT
TTF

Equivalences, elimination, and introduction

Exclusive disjunction essentially means 'either one, but not both nor none'. In other words, the statement is true if and only if one is true and the other is false. For example, if two horses are racing, then one of the two will win the race, but not both of them. The exclusive disjunction , also denoted by or , can be expressed in terms of the logical conjunction ("logical and", ), the disjunction ("logical or", ), and the negation () as follows:

The exclusive disjunction can also be expressed in the following way:

This representation of XOR may be found useful when constructing a circuit or network, because it has only one operation and small number of and operations. A proof of this identity is given below:

It is sometimes useful to write in the following way:

or:

This equivalence can be established by applying De Morgan's laws twice to the fourth line of the above proof.

The exclusive or is also equivalent to the negation of a logical biconditional, by the rules of material implication (a material conditional is equivalent to the disjunction of the negation of its antecedent and its consequence) and material equivalence.

In summary, we have, in mathematical and in engineering notation:

Negation of the operator

By applying the spirit of De Morgan's laws, we get:

Relation to modern algebra

Although the operators (conjunction) and (disjunction) are very useful in logic systems, they fail a more generalizable structure in the following way:

The systems and are monoids, but neither is a group. This unfortunately prevents the combination of these two systems into larger structures, such as a mathematical ring.

However, the system using exclusive or is an abelian group. The combination of operators and over elements produce the well-known two-element field . This field can represent any logic obtainable with the system and has the added benefit of the arsenal of algebraic analysis tools for fields.

More specifically, if one associates with 0 and with 1, one can interpret the logical "AND" operation as multiplication on and the "XOR" operation as addition on :

The description of a Boolean function as a polynomial in , using this basis, is called the function's algebraic normal form. [3]

Exclusive or in natural language

Disjunction is often understood exclusively in natural languages. In English, the disjunctive word "or" is often understood exclusively, particularly when used with the particle "either". The English example below would normally be understood in conversation as implying that Mary is not both a singer and a poet. [4] [5]

1. Mary is a singer or a poet.

However, disjunction can also be understood inclusively, even in combination with "either". For instance, the first example below shows that "either" can be felicitously used in combination with an outright statement that both disjuncts are true. The second example shows that the exclusive inference vanishes away under downward entailing contexts. If disjunction were understood as exclusive in this example, it would leave open the possibility that some people ate both rice and beans. [4]

2. Mary is either a singer or a poet or both.
3. Nobody ate either rice or beans.

Examples such as the above have motivated analyses of the exclusivity inference as pragmatic conversational implicatures calculated on the basis of an inclusive semantics. Implicatures are typically cancellable and do not arise in downward entailing contexts if their calculation depends on the Maxim of Quantity. However, some researchers have treated exclusivity as a bona fide semantic entailment and proposed nonclassical logics which would validate it. [4]

This behavior of English "or" is also found in other languages. However, many languages have disjunctive constructions which are robustly exclusive such as French soit... soit. [4]

Alternative symbols

The symbol used for exclusive disjunction varies from one field of application to the next, and even depends on the properties being emphasized in a given context of discussion. In addition to the abbreviation "XOR", any of the following symbols may also be seen:

Properties

Commutativity: yes
        
Venn0110.svg          Venn0110.svg
Associativity: yes
        
Venn 0101 0101.svg Venn 0011 1100.svg          Venn 0110 1001.svg          Venn 0110 0110.svg Venn 0000 1111.svg
Distributivity:
The exclusive or does not distribute over any binary function (not even itself), but logical conjunction distributes over exclusive or. (Conjunction and exclusive or form the multiplication and addition operations of a field GF(2), and as in any field they obey the distributive law.)
Idempotency: no
                
Venn01.svg Venn01.svg          Venn00.svg          Venn01.svg
Monotonicity: no
        
Venn 1011 1011.svg          Venn 1011 1101.svg          Venn 0101 1010.svg Venn 0011 1100.svg
Truth-preserving: no
When all inputs are true, the output is not true.
        
Venn0001.svg          Venn0110.svg
Falsehood-preserving: yes
When all inputs are false, the output is false.
        
Venn0110.svg          Venn0111.svg
Walsh spectrum: (2,0,0,−2)
Non-linearity: 0
The function is linear.
Involution:
Exclusive or with one specified input, as a function of the other input, is an involution or self-inverse function; applying it twice leaves the variable input unchanged.
        
Venn0110.svg Venn0011.svg          Venn0101.svg

If using binary values for true (1) and false (0), then exclusive or works exactly like addition modulo 2.

Computer science

Traditional symbolic representation of an XOR logic gate XOR ANSI Labelled.svg
Traditional symbolic representation of an XOR logic gate

Bitwise operation

Nimber addition is the exclusive or of nonnegative integers in binary representation. This is also the vector addition in
(
Z
/
2
Z
)
4
{\displaystyle (\mathbb {Z} /2\mathbb {Z} )^{4}}
. Z2^4; Cayley table; binary.svg
Nimber addition is the exclusive or of nonnegative integers in binary representation. This is also the vector addition in .

Exclusive disjunction is often used for bitwise operations. Examples:

As noted above, since exclusive disjunction is identical to addition modulo 2, the bitwise exclusive disjunction of two n-bit strings is identical to the standard vector of addition in the vector space .

In computer science, exclusive disjunction has several uses:

In logical circuits, a simple adder can be made with an XOR gate to add the numbers, and a series of AND, OR and NOT gates to create the carry output.

On some computer architectures, it is more efficient to store a zero in a register by XOR-ing the register with itself (bits XOR-ed with themselves are always zero) than to load and store the value zero.

In cryptography, XOR is sometimes used as a simple, self-inverse mixing function, such as in one-time pad or Feistel network systems.[ citation needed ] XOR is also heavily used in block ciphers such as AES (Rijndael) or Serpent and in block cipher implementation (CBC, CFB, OFB or CTR).

In simple threshold-activated artificial neural networks, modeling the XOR function requires a second layer because XOR is not a linearly separable function.

Similarly, XOR can be used in generating entropy pools for hardware random number generators. The XOR operation preserves randomness, meaning that a random bit XORed with a non-random bit will result in a random bit. Multiple sources of potentially random data can be combined using XOR, and the unpredictability of the output is guaranteed to be at least as good as the best individual source. [22]

XOR is used in RAID 3–6 for creating parity information. For example, RAID can "back up" bytes 100111002 and 011011002 from two (or more) hard drives by XORing the just mentioned bytes, resulting in (111100002) and writing it to another drive. Under this method, if any one of the three hard drives are lost, the lost byte can be re-created by XORing bytes from the remaining drives. For instance, if the drive containing 011011002 is lost, 100111002 and 111100002 can be XORed to recover the lost byte. [23]

XOR is also used to detect an overflow in the result of a signed binary arithmetic operation. If the leftmost retained bit of the result is not the same as the infinite number of digits to the left, then that means overflow occurred. XORing those two bits will give a "1" if there is an overflow.

XOR can be used to swap two numeric variables in computers, using the XOR swap algorithm; however this is regarded as more of a curiosity and not encouraged in practice.

XOR linked lists leverage XOR properties in order to save space to represent doubly linked list data structures.

In computer graphics, XOR-based drawing methods are often used to manage such items as bounding boxes and cursors on systems without alpha channels or overlay planes.

Encodings

It is also called "not left-right arrow" (\nleftrightarrow) in LaTeX-based markdown (). Apart from the ASCII codes, the operator is encoded at U+22BBXOR (⊻) and U+2295CIRCLED PLUS (⊕, ⊕), both in block mathematical operators.

See also

Notes

  1. Germundsson, Roger; Weisstein, Eric. "XOR". MathWorld . Wolfram Research . Retrieved 17 June 2015.
  2. 1 2 Bocheński, J. M. (1949). Précis de logique mathématique (PDF) (in French). The Netherlands: F. G. Kroonder, Bussum, Pays-Bas. Translated as Bocheński, J. M. (1959). A Precis of Mathematical Logic . Translated by Bird, O. Dordrecht, Holland: D. Reidel Publishing Company. doi:10.1007/978-94-017-0592-9. ISBN   978-90-481-8329-6.
  3. Joux, Antoine (2009). "9.2: Algebraic normal forms of Boolean functions". Algorithmic Cryptanalysis. CRC Press. pp. 285–286. ISBN   9781420070033.
  4. 1 2 3 4 Aloni, Maria (2016). "Disjunction". In Zalta, Edward N. (ed.). The Stanford Encyclopedia of Philosophy (Winter 2016 ed.). Metaphysics Research Lab, Stanford University. Retrieved 2020-09-03.
  5. Jennings quotes numerous authors saying that the word "or" has an exclusive sense. See Chapter 3, "The First Myth of 'Or'":
    Jennings, R. E. (1994). The Genealogy of Disjunction. New York: Oxford University Press.
  6. 1 2 Boole, G. (1847). The Mathematical Analysis of Logic, Being an Essay Towards a Calculus of Deductive Reasoning. Cambridge/London: Macmillan, Barclay, & Macmillan/George Bell. p. 17.
  7. Enderton, H. (2001) [1972]. A Mathematical Introduction to Logic (2 ed.). San Diego, New York, Boston, London, Toronto, Sydney and Tokyo: A Harcourt Science and Technology Company. p. 51.
  8. Rautenberg, W. (2010) [2006]. A Concise Introduction to Mathematical Logic (3 ed.). New York, Dordrecht, Heidelberg and London: Springer. p. 3.
  9. Ladd, Christine (1883). "On the Algebra of Logic". In Peirce, C. S. (ed.). Studies in Logic by Members of the Johns Hopkins University. Boston: Little, Brown & Company. pp. 17–71.
  10. Schröder, E. (1890). Vorlesungen über die Algebra der Logik (Exakte Logik), Erster Band (in German). Leipzig: Druck und Verlag B. G. Teubner. Reprinted by Thoemmes Press in 2000.
  11. Peano, G. (1894). Notations de logique mathématique. Introduction au formulaire de mathématique. Turin: Fratelli Boccna. Reprinted in Peano, G. (1958). Opere Scelte, Volume II. Roma: Edizioni Cremonese. pp. 123–176.
  12. ГРАДШТЕЙН, И. С. (1959) [1936]. ПРЯМАЯ И ОБРАТНАЯ ТЕОРЕМЫ: ЭЛЕМЕНТЫ АЛГЕБРЫ ЛОГИКИ (in Russian) (3 ed.). МОСКВА: ГОСУДАРСТВЕННОЕ ИЗДАТЕЛЬСТВО ФИЗИКа-МАТЕМАТИЧЕСКОЙ ЛИТЕРАТУРЫ. Translated as Gradshtein, I. S. (1963). Direct and Converse Theorems: The Elements of Symbolic Logic. Translated by Boddington, T. Oxford, London, New York and Paris: Pergamon Press.
  13. Shannon, C. E. (1938). "A Symbolic Analysis of Relay and Switching Circuits" (PDF). Transactions of the American Institute of Electrical Engineers. 57 (12): 713–723. doi:10.1109/T-AIEE.1938.5057767. hdl: 1721.1/11173 . S2CID   51638483.
  14. Huntington, E. V. (1904). "Sets of Independent Postulates for the Algebra of Logic". Transactions of the American Mathematical Society. 5 (3): 288–309. doi:10.1090/S0002-9947-1904-1500675-4.
  15. Leibniz, G. W. (1890) [16??/17??]. Gerhardt, C. I. (ed.). Die philosophischen Schriften, Siebter Band (in German). Berlin: Weidmann. p. 237. Retrieved 7 July 2023.
  16. Huntington, E. V. (1933). "New Sets of Independent Postulates for the Algebra of Logic, With Special Reference to Whitehead and Russell's Principia Mathematica". Transactions of the American Mathematical Society. 35 (1): 274–304.
  17. Church, A. (1996) [1944]. Introduction to Mathematical Logic. New Jersey: Princeton University Press. p. 37.
  18. Craig, Edward (1998). Routledge Encyclopedia of Philosophy, Volume 8. Taylor & Francis. p. 496. ISBN   978-0-41507310-3.
  19. Łukasiewicz, Jan (1929). Elementy logiki matematycznej[Elements of Mathematical Logic] (in Polish) (1 ed.). Warsaw, Poland: Państwowe Wydawnictwo Naukowe.
  20. Kernighan, Brian W.; Ritchie, Dennis M. (1978). "2.9: Bitwise logical operators". The C Programming Language. Prentice-Hall. pp. 44–46.
  21. Weisstein, Eric W. "Symmetric Difference". MathWorld .
  22. Davies, Robert B (28 February 2002). "Exclusive OR (XOR) and hardware random number generators" (PDF). Retrieved 28 August 2013.
  23. Nobel, Rickard (26 July 2011). "How RAID 5 actually works" . Retrieved 23 March 2017.

Related Research Articles

<span class="mw-page-title-main">Logical disjunction</span> Logical connective OR

In logic, disjunction, also known as logical disjunction or logical or or logical addition or inclusive disjunction, is a logical connective typically notated as and read aloud as "or". For instance, the English language sentence "it is sunny or it is warm" can be represented in logic using the disjunctive formula , assuming that abbreviates "it is sunny" and abbreviates "it is warm".

<span class="mw-page-title-main">Logical connective</span> Symbol connecting sentential formulas in logic

In logic, a logical connective is a logical constant. Connectives can be used to connect logical formulas. For instance in the syntax of propositional logic, the binary connective can be used to join the two atomic formulas and , rendering the complex formula .

<span class="mw-page-title-main">Sheffer stroke</span> Logical operation

In Boolean functions and propositional calculus, the Sheffer stroke denotes a logical operation that is equivalent to the negation of the conjunction operation, expressed in ordinary language as "not both". It is also called non-conjunction, or alternative denial, or NAND. In digital electronics, it corresponds to the NAND gate. It is named after Henry Maurice Sheffer and written as or as or as or as in Polish notation by Łukasiewicz.

<span class="mw-page-title-main">De Morgan's laws</span> Pair of logical equivalences

In propositional logic and Boolean algebra, De Morgan's laws, also known as De Morgan's theorem, are a pair of transformation rules that are both valid rules of inference. They are named after Augustus De Morgan, a 19th-century British mathematician. The rules allow the expression of conjunctions and disjunctions purely in terms of each other via negation.

In boolean logic, a disjunctive normal form (DNF) is a canonical normal form of a logical formula consisting of a disjunction of conjunctions; it can also be described as an OR of ANDs, a sum of products, or — in philosophical logic — a cluster concept. As a normal form, it is useful in automated theorem proving.

In Boolean logic, a formula is in conjunctive normal form (CNF) or clausal normal form if it is a conjunction of one or more clauses, where a clause is a disjunction of literals; otherwise put, it is a product of sums or an AND of ORs. As a canonical normal form, it is useful in automated theorem proving and circuit theory.

<span class="mw-page-title-main">Negation</span> Logical operation

In logic, negation, also called the logical not or logical complement, is an operation that takes a proposition to another proposition "not ", standing for " is not true", written , or . It is interpreted intuitively as being true when is false, and false when is true. Negation is thus a unary logical connective. It may be applied as an operation on notions, propositions, truth values, or semantic values more generally. In classical logic, negation is normally identified with the truth function that takes truth to falsity. In intuitionistic logic, according to the Brouwer–Heyting–Kolmogorov interpretation, the negation of a proposition is the proposition whose proofs are the refutations of .

<span class="mw-page-title-main">Logical NOR</span> Binary operation that is true if and only if both operands are false

In Boolean logic, logical NOR, non-disjunction, or joint denial is a truth-functional operator which produces a result that is the negation of logical or. That is, a sentence of the form (p NOR q) is true precisely when neither p nor q is true—i.e. when both p and q are false. It is logically equivalent to and , where the symbol signifies logical negation, signifies OR, and signifies AND.

In mathematics, a Heyting algebra (also known as pseudo-Boolean algebra) is a bounded lattice (with join and meet operations written ∨ and ∧ and with least element 0 and greatest element 1) equipped with a binary operation ab of implication such that (ca) ≤ b is equivalent to c ≤ (ab). From a logical standpoint, AB is by this definition the weakest proposition for which modus ponens, the inference rule AB, AB, is sound. Like Boolean algebras, Heyting algebras form a variety axiomatizable with finitely many equations. Heyting algebras were introduced by Arend Heyting (1930) to formalize intuitionistic logic.

In mathematical logic, a formula is in negation normal form (NNF) if the negation operator (, not) is only applied to variables and the only other allowed Boolean operators are conjunction (, and) and disjunction (, or).

In logic, a truth function is a function that accepts truth values as input and produces a unique truth value as output. In other words: the input and output of a truth function are all truth values; a truth function will always output exactly one truth value, and inputting the same truth value(s) will always output the same truth value. The typical example is in propositional logic, wherein a compound statement is constructed using individual statements connected by logical connectives; if the truth value of the compound statement is entirely determined by the truth value(s) of the constituent statement(s), the compound statement is called a truth function, and any logical connectives used are said to be truth functional.

In Boolean algebra, the algebraic normal form (ANF), ring sum normal form, Zhegalkin normal form, or Reed–Muller expansion is a way of writing propositional logic formulas in one of three subforms:

In mathematical logic and automated theorem proving, resolution is a rule of inference leading to a refutation-complete theorem-proving technique for sentences in propositional logic and first-order logic. For propositional logic, systematically applying the resolution rule acts as a decision procedure for formula unsatisfiability, solving the Boolean satisfiability problem. For first-order logic, resolution can be used as the basis for a semi-algorithm for the unsatisfiability problem of first-order logic, providing a more practical method than one following from Gödel's completeness theorem.

<span class="mw-page-title-main">Logical equality</span>

Logical equality is a logical operator that compares two truth values, or more generally, two formulas, such that it gives the value True if both arguments have the same truth value, and False if they are different. In the case where formulas have free variables, we say two formulas are equal when their truth values are equal for all possible resolutions of free variables. It corresponds to equality in Boolean algebra and to the logical biconditional in propositional calculus.

XOR gate is a digital logic gate that gives a true output when the number of true inputs is odd. An XOR gate implements an exclusive or from mathematical logic; that is, a true output results if one, and only one, of the inputs to the gate is true. If both inputs are false (0/LOW) or both are true, a false output results. XOR represents the inequality function, i.e., the output is true if the inputs are not alike otherwise the output is false. A way to remember XOR is "must have one or the other but not both".

The XNOR gate is a digital logic gate whose function is the logical complement of the Exclusive OR (XOR) gate. It is equivalent to the logical connective from mathematical logic, also known as the material biconditional. The two-input version implements logical equality, behaving according to the truth table to the right, and hence the gate is sometimes called an "equivalence gate". A high output (1) results if both of the inputs to the gate are the same. If one but not both inputs are high (1), a low output (0) results.

In logic, a functionally complete set of logical connectives or Boolean operators is one that can be used to express all possible truth tables by combining members of the set into a Boolean expression. A well-known complete set of connectives is { AND, NOT }. Each of the singleton sets { NAND } and { NOR } is functionally complete. However, the set { AND, OR } is incomplete, due to its inability to express NOT.

A truth table is a mathematical table used in logic—specifically in connection with Boolean algebra, Boolean functions, and propositional calculus—which sets out the functional values of logical expressions on each of their functional arguments, that is, for each combination of values taken by their logical variables. In particular, truth tables can be used to show whether a propositional expression is true for all legitimate input values, that is, logically valid.

The Tseytin transformation, alternatively written Tseitin transformation, takes as input an arbitrary combinatorial logic circuit and produces an equisatisfiable boolean formula in conjunctive normal form (CNF). The length of the formula is linear in the size of the circuit. Input vectors that make the circuit output "true" are in 1-to-1 correspondence with assignments that satisfy the formula. This reduces the problem of circuit satisfiability on any circuit to the satisfiability problem on 3-CNF formulas. It was discovered by the Russian scientist Grigori Tseitin.