Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Exclusive or
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{short description|True when either but not both inputs are true}} {{Redirect|XOR|the logic gate|XOR gate|other uses|XOR (disambiguation)}} {{refimprove|date=May 2013}} {{Infobox logical connective | title = Exclusive disjunction | other titles = XOR | Venn diagram = Venn0110.svg | wikifunction = Z10237 | definition = | truth table = <math>(0110)</math> | logic gate = XOR_ANSI.svg | DNF = <math>\overline{x} \cdot y + x \cdot \overline{y}</math> | CNF = <math>( \overline{x} + \overline{y} ) \cdot ( x + y )</math> | Zhegalkin = <math>x \oplus y </math> | 0-preserving = yes | 1-preserving = no | monotone = no | affine = yes | self-dual = no }} {{Logical connectives sidebar}} [[File:Venn 0110 1001.svg|220px|[[Venn diagram]] of <math>A \oplus B \oplus C</math>|thumb|right]] '''Exclusive or''', '''exclusive disjunction''', '''exclusive alternation''', '''logical non-equivalence''', or [[Logical_equality#Inequality|logical inequality]] is a [[Logical connective|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 [[Parity (mathematics)|odd]].<ref name=wolfram>{{cite web|last1=Germundsson|first1=Roger|last2=Weisstein|first2=Eric|title=XOR|url=http://mathworld.wolfram.com/XOR.html|website=[[MathWorld]]|publisher=[[Wolfram Research]]|access-date=17 June 2015}}</ref> It gains the name "exclusive or" because the meaning of "or" is ambiguous when both [[operand]]s 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 [[Table of logic symbols|symbolized]] by the prefix operator <math>J</math><ref name="Bochenski1949">{{cite book |last1=Bocheński |first1=J. M. |title=Précis de logique mathématique |url=https://burjcdigital.urjc.es/bitstream/handle/10115/1425/PRECIS_DE_LOGIQUE_MATHEMATIQUE.pdf?sequence=1&isAllowed=y |date=1949 |location=The Netherlands |publisher=F. G. Kroonder, Bussum, Pays-Bas |language=French}} Translated as {{cite book |last1=Bocheński |first1=J. M. |translator-last=Bird |translator-first=O. |title=A Precis of Mathematical Logic |date=1959 |publisher=D. Reidel Publishing Company |url=https://archive.org/details/precisofmathemat0000boch/ |url-access=limited |doi=10.1007/978-94-017-0592-9 |location=Dordrecht, Holland|isbn=978-90-481-8329-6 }}</ref>{{rp|page=16}} and by the [[infix operator]]s '''XOR''' ({{IPAc-en|ˌ|ɛ|k|s|_|ˈ|ɔ:|r}}, {{IPAc-en|ˌ|ɛ|k|s|_|ˈ|ɔ:}}, {{IPAc-en|'|k|s|ɔ:|r}} or {{IPAc-en|'|k|s|ɔ:}}), '''EOR''', '''EXOR''', <math>\dot{\vee}</math>, <math>\overline{\vee}</math>, <math>\underline{\vee}</math>, '''<span style="font-size:120%;">⩛</span>''', <math>\oplus</math>, <math>\nleftrightarrow</math>, and <math>\not\equiv</math>. ==Definition== [[File:Variadic logical XOR.svg|thumb|220px|Each row of this binary [[Walsh matrix]] is the truth table of the [[variadic function|variadic]] XOR of the arguments shown on the left. <small>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.)</small>]] The [[truth table]] of <math>A\nleftrightarrow B</math> shows that it outputs true whenever the inputs differ: {{2-ary truth table|0|1|1|0|<math>A\nleftrightarrow B</math>}} ==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 <math>p\nleftrightarrow q</math>, also denoted by <math>p\operatorname{?}q</math> or <math>Jpq</math>, can be expressed in terms of the [[logical conjunction]] ("logical and", <math>\and</math>), the [[disjunction]] ("logical or", <math>\vee</math>), and the [[negation]] (<math>\neg</math>) as follows: : <math>\begin{matrix} p\nleftrightarrow q & = & (p\vee q)\and\neg(p\and q) \end{matrix}</math> The exclusive disjunction <math>p \nleftrightarrow q</math> can also be expressed in the following way: : <math>\begin{matrix} p \nleftrightarrow q & = & (p \land \lnot q) \lor (\lnot p \land q) \end{matrix}</math> This representation of XOR may be found useful when constructing a circuit or network, because it has only one <math>\lnot</math> operation and small number of <math>\land</math> and <math>\lor</math> operations. A proof of this identity is given below: : <math>\begin{matrix} p \nleftrightarrow q & = & (p \land \lnot q) & \lor & (\lnot p \land q) \\[3pt] & = & ((p \land \lnot q) \lor \lnot p) & \land & ((p \land \lnot q) \lor q) \\[3pt] & = & ((p \lor \lnot p) \land (\lnot q \lor \lnot p)) & \land & ((p \lor q) \land (\lnot q \lor q)) \\[3pt] & = & (\lnot p \lor \lnot q) & \land & (p \lor q) \\[3pt] & = & \lnot (p \land q) & \land & (p \lor q) \end{matrix}</math> It is sometimes useful to write <math>p \nleftrightarrow q</math> in the following way: : <math>\begin{matrix} p \nleftrightarrow q & = & \lnot ((p \land q) \lor (\lnot p \land \lnot q)) \end{matrix}</math> or: : <math>\begin{matrix} p \nleftrightarrow q & = & (p \lor q) \land (\lnot p \lor \lnot q) \end{matrix}</math> 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 (logic)|antecedent]] and its consequence) and [[If and only if|material equivalence]]. In summary, we have, in mathematical and in engineering notation: : <math>\begin{matrix} p \nleftrightarrow q & = & (p \land \lnot q) & \lor & (\lnot p \land q) & = & p\overline{q} + \overline{p}q \\[3pt] & = & (p \lor q) & \land & (\lnot p \lor \lnot q) & = & (p + q)(\overline{p} + \overline{q}) \\[3pt] & = & (p \lor q) & \land & \lnot (p \land q) & = & (p + q)(\overline{pq}) \end{matrix}</math> ==Negation of the operator== By applying the spirit of [[De Morgan's laws]], we get: <math display="block">\neg(p \nleftrightarrow q)\equiv\neg p\nleftrightarrow q\equiv p\nleftrightarrow\neg q.</math> ==Relation to modern algebra== Although the [[Operation (mathematics)|operators]] <math>\wedge</math> ([[Logical conjunction|conjunction]]) and <math>\lor</math> ([[Logical disjunction|disjunction]]) are very useful in logic systems, they fail a more generalizable structure in the following way: The systems <math>(\{T, F\}, \wedge)</math> and <math>(\{T, F\}, \lor)</math> are [[monoid]]s, but neither is a [[group (mathematics)|group]]. This unfortunately prevents the combination of these two systems into larger structures, such as a [[Ring (mathematics)|mathematical ring]]. However, the system using exclusive or <math>(\{T, F\}, \oplus)</math> ''is'' an [[abelian group]]. The combination of operators <math>\wedge</math> and <math>\oplus</math> over elements <math>\{T, F\}</math> produce the well-known [[GF(2)|two-element field <math>\mathbb{F}_2</math>]]. This field can represent any logic obtainable with the system <math>(\land, \lor)</math> and has the added benefit of the arsenal of algebraic analysis tools for fields. More specifically, if one associates <math>F</math> with 0 and <math>T</math> with 1, one can interpret the logical "AND" operation as multiplication on <math>\mathbb{F}_2</math> and the "XOR" operation as addition on <math>\mathbb{F}_2</math>: : <math>\begin{matrix} r = p \land q & \Leftrightarrow & r = p \cdot q \pmod 2 \\[3pt] r = p \oplus q & \Leftrightarrow & r = p + q \pmod 2 \\ \end{matrix}</math> The description of a [[Boolean function]] as a [[polynomial]] in <math>\mathbb{F}_2</math>, using this basis, is called the function's [[algebraic normal form]].<ref>{{cite book|title=Algorithmic Cryptanalysis|first=Antoine|last=Joux|publisher=CRC Press|year=2009|isbn=9781420070033|contribution=9.2: Algebraic normal forms of Boolean functions|pages=285–286|contribution-url=https://books.google.com/books?id=buQajqt-_iUC&pg=PA285}}</ref> ==Exclusive or in natural language== Disjunction is often understood exclusively in [[natural language]]s. 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.<ref name= "alonisep">{{cite encyclopedia|last=Aloni|first=Maria|author-link=Maria Aloni|title=Disjunction|date=2016|url=https://plato.stanford.edu/archives/win2016/entries/disjunction/|encyclopedia=The Stanford Encyclopedia of Philosophy|editor-last=Zalta|editor-first=Edward N.|edition=Winter 2016|publisher=Metaphysics Research Lab, Stanford University|access-date=2020-09-03}}</ref><ref>Jennings quotes numerous authors saying that the word "or" has an exclusive sense. See Chapter 3, "The First Myth of 'Or'":<br />{{cite book |last=Jennings |first=R. E. |date=1994 |title=The Genealogy of Disjunction |location=New York |publisher=Oxford University Press }}</ref> :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 [[felicity (pragmatics)|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.<ref name= "alonisep"/> :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 [[pragmatics|pragmatic]] [[conversational implicature]]s calculated on the basis of an inclusive [[formal semantics (linguistics)|semantics]]. Implicatures are typically [[cancellable (linguistics)|cancellable]] and do not arise in downward entailing contexts if their calculation depends on the [[Cooperative_principle#Maxim of quantity (content length and depth)|Maxim of Quantity]]. However, some researchers have treated exclusivity as a bona fide semantic [[entailment]] and proposed nonclassical logics which would validate it.<ref name= "alonisep" /> 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''.<ref name= "alonisep" /> ==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: * <math>+</math> was used by [[George Boole]] in 1847.<ref name="boole1847">{{cite book |last1=Boole |first1=G. |title=The Mathematical Analysis of Logic, Being an Essay Towards a Calculus of Deductive Reasoning |date=1847 |publisher=Macmillan, Barclay, & Macmillan/George Bell |location=Cambridge/London |page=17 |url=https://archive.org/details/mathematicalanal00booluoft}}</ref> Although Boole used <math>+</math> mainly on classes, he also considered the case that <math>x,y</math> are propositions in <math>x+y</math>, and at the time <math>+</math> is a connective. Furthermore, Boole used it exclusively. Although such use does not show the relationship between inclusive disjunction (for which <math>\vee</math> is almost fixedly used nowadays) and exclusive disjunction, and may also bring about confusions with its other uses, some classical and modern textbooks still keep such use.<ref name="enderton2001">{{cite book |last1=Enderton |first1=H. |title=A Mathematical Introduction to Logic |orig-date=1972 |date=2001 |publisher=A Harcourt Science and Technology Company |location=San Diego, New York, Boston, London, Toronto, Sydney and Tokyo |page=51 |edition=2}}</ref><ref name="rautenberg2010">{{cite book |last1=Rautenberg |first1=W. |title=A Concise Introduction to Mathematical Logic |orig-date=2006 |date=2010 |publisher=Springer |location=New York, Dordrecht, Heidelberg and London |page=3 |edition=3}}</ref> * <math>\overline{\vee}</math> was used by [[Christine Ladd-Franklin]] in 1883.<ref name="ladd1883">{{cite encyclopedia |last1=Ladd |first1=Christine |title=On the Algebra of Logic |url=https://archive.org/details/studiesinlogic00peiruoft/page/16|encyclopedia=Studies in Logic by Members of the Johns Hopkins University |editor1-last=Peirce |editor1-first=C. S. |publisher=Little, Brown & Company |location=Boston |date=1883 |pages=17–71}}</ref> Strictly speaking, Ladd used <math>A\operatorname{\overline{\vee}}B</math> to express "<math>A</math> is-not <math>B</math>" or "No <math>A</math> is <math>B</math>", i.e., used <math>\overline{\vee}</math> as exclusions, while implicitly <math>\overline{\vee}</math> has the meaning of exclusive disjunction since the article is titled as "On the Algebra of Logic". * <math>\not=</math>, denoting the negation of [[Logical biconditional|equivalence]], was used by [[Ernst Schröder (mathematician)|Ernst Schröder]] in 1890,<ref name="schroder1890">{{cite book |last1=Schröder |first1=E. |title=Vorlesungen über die Algebra der Logik (Exakte Logik), Erster Band |date=1890 |publisher=Druck und Verlag B. G. Teubner |location=Leipzig |language=German}} Reprinted by Thoemmes Press in 2000.</ref>{{rp|page=307}} Although the usage of <math>=</math> as equivalence could be dated back to [[George Boole]] in 1847,<ref name="boole1847"/> during the 40 years after Boole, his followers, such as [[Charles Sanders Peirce]], [[Hugh MacColl]], [[Giuseppe Peano]] and so on, did not use <math>\not=</math> as non-equivalence literally which is possibly because it could be defined from negation and equivalence easily. * <math>\circ</math> was used by [[Giuseppe Peano]] in 1894: "<math>a\circ b=a-b\,\cup\,b-a</math>. The sign <math>\circ</math> corresponds to Latin ''aut''; the sign <math>\cup</math> to ''vel''."<ref name="peano1894"> {{cite book |last1=Peano |first1=G. |title=Notations de logique mathématique. Introduction au formulaire de mathématique |date=1894 |publisher=Fratelli Boccna. |location=Turin}} Reprinted in {{cite book |last1=Peano |first1=G. |title=Opere Scelte, Volume II |url=https://archive.org/details/operescelte0002gius/page/n5/mode/2up |date=1958 |publisher=Edizioni Cremonese |location=Roma |pages=123–176}}</ref>{{rp|page=10}} Note that the Latin word "aut" means "exclusive or" and "vel" means "inclusive or", and that Peano use <math>\cup</math> as inclusive disjunction. * <math>\vee\vee</math> was used by Izrail Solomonovich Gradshtein (Израиль Соломонович Градштейн) in 1936.<ref name="gradshtein1959">{{cite book |last1=ГРАДШТЕЙН |first1=И. С. |title=ПРЯМАЯ И ОБРАТНАЯ ТЕОРЕМЫ: ЭЛЕМЕНТЫ АЛГЕБРЫ ЛОГИКИ |url=https://www.mathedu.ru/text/gradshteyn_pryamaya_i_obratnaya_teoremy_1959/p0/ |orig-date=1936 |date=1959 |publisher=ГОСУДАРСТВЕННОЕ ИЗДАТЕЛЬСТВО ФИЗИКа-МАТЕМАТИЧЕСКОЙ ЛИТЕРАТУРЫ |location=МОСКВА |edition=3 |language=Russian}} Translated as {{cite book |last1=Gradshtein |first1=I. S. |translator-last1=Boddington |translator-first1=T. |title=Direct and Converse Theorems: The Elements of Symbolic Logic |date=1963 |publisher=Pergamon Press |location=Oxford, London, New York and Paris}}</ref>{{rp|page=76}} * <math>\oplus</math> was used by [[Claude Shannon]] in 1938.<ref>{{ cite journal |last = Shannon |first = C. E. |author-link = Claude Elwood Shannon |title = A Symbolic Analysis of Relay and Switching Circuits |journal = Transactions of the American Institute of Electrical Engineers |year = 1938 |volume = 57 |issue=12 |pages = 713–723 |doi= 10.1109/T-AIEE.1938.5057767 |hdl = 1721.1/11173 |s2cid = 51638483 |url = https://www.cs.virginia.edu/~evans/greatworks/shannon38.pdf |hdl-access = free }}</ref> Shannon borrowed the symbol as exclusive disjunction from [[Edward Vermilye Huntington]] in 1904.<ref name="huntington1904">{{cite journal |last1=Huntington |first1=E. V. |title=Sets of Independent Postulates for the Algebra of Logic |journal=Transactions of the American Mathematical Society |date=1904 |volume=5 |issue=3 |pages=288–309|doi=10.1090/S0002-9947-1904-1500675-4 }}</ref> Huntington borrowed the symbol from [[Gottfried Wilhelm Leibniz]] in 1890 (the original date is not definitely known, but almost certainly it is written after 1685; and 1890 is the publishing time).<ref>{{cite book |last1=Leibniz |first1=G. W. |editor1-last=Gerhardt |editor1-first=C. I. |title=Die philosophischen Schriften, Siebter Band |url=https://archive.org/details/diephilosophisc01leibgoog/page/n11/mode/2up |access-date= 7 July 2023 |orig-date=16??/17??|date=1890 |language= German |publisher=Weidmann |location=Berlin |page=237}}</ref> While both Huntington in 1904 and Leibniz in 1890 used the symbol as an algebraic operation. Furthermore, Huntington in 1904 used the symbol as inclusive disjunction (logical sum) too, and in 1933 used <math>+</math> as inclusive disjunction.<ref name="huntington1933">{{cite journal |last1=Huntington |first1=E. V. |title=New Sets of Independent Postulates for the Algebra of Logic, With Special Reference to Whitehead and Russell's Principia Mathematica |journal=Transactions of the American Mathematical Society |date=1933 |volume=35 |issue=1 |pages=274–304}}</ref> * <math>\not\equiv</math>, also denoting the negation of [[Logical biconditional|equivalence]], was used by [[Alonzo Church]] in 1944.<ref name="church1944">{{cite book |last1=Church |first1=A. |title=Introduction to Mathematical Logic |orig-date=1944|date=1996 |publisher=Princeton University Press |location=New Jersey |page=37}}</ref> * <math>J</math> (as a [[Polish notation|prefix operator]], <math>J\phi\psi</math>) was used by [[Józef Maria Bocheński]] in 1949.<ref name="Bochenski1949"/>{{rp|page=16}} Somebody<ref name="Craig_1998">{{cite book |title=Routledge Encyclopedia of Philosophy, Volume 8 |author-first=Edward |author-last=Craig |publisher=[[Taylor & Francis]] |date=1998 |isbn=978-0-41507310-3 |page=496 |url=https://books.google.com/books?id=mxpFwcAplaAC&pg=PA496}}</ref> may mistake that it is [[Jan Łukasiewicz]] who is the first to use <math>J</math> for exclusive disjunction (it seems that the mistake spreads widely), while neither in 1929<ref name="lukasiewicz1929">{{cite book |title=Elementy logiki matematycznej |language=pl |trans-title=Elements of Mathematical Logic |author-last=Łukasiewicz |author-first=Jan |author-link=Jan Łukasiewicz |location=Warsaw, Poland |edition=1 |publisher=[[Państwowe Wydawnictwo Naukowe]] |date=1929}}</ref> nor in other works did Łukasiewicz make such use. In fact, in 1949 Bocheński introduced a system of [[Polish notation]] that names all 16 binary [[logical connective|connectives]] of classical logic which is a compatible extension of the notation of Łukasiewicz in 1929, and in which <math>J</math> for exclusive disjunction appeared at the first time. Bocheński's usage of <math>J</math> as exclusive disjunction has no relationship with the Polish "alternatywa rozłączna" of "exclusive or" and is an accident for which see the table on page 16 of the book in 1949. * <samp>^</samp>, the [[caret]], has been used in several [[programming language]]s to denote the [[bitwise operation|bitwise]] exclusive or operator, beginning with [[C (programming language)|C]]<ref>{{cite book|title=The C Programming Language|title-link=The C Programming Language|year=1978|publisher=Prentice-Hall|first1=Brian W.|last1=Kernighan|author1-link=Brian Kernighan|first2=Dennis M.|last2=Ritchie|author2-link=Dennis Ritchie|contribution=2.9: Bitwise logical operators|pages=44–46|contribution-url=https://archive.org/details/TheCProgrammingLanguageFirstEdition/page/n51}}</ref> and also including [[C++]], [[C Sharp (programming language)|C#]], [[D (programming language)|D]], [[Java (programming language)|Java]], [[Perl]], [[Ruby (programming language)|Ruby]], [[PHP]] and [[Python (programming language)|Python]]. * The [[symmetric difference]] of two sets <math>S</math> and <math>T</math>, which may be interpreted as their elementwise exclusive or, has variously been denoted as <math>S\ominus T</math>, <math>S\mathop{\triangledown} T</math>, or <math>S\mathop{\vartriangle} T</math>.<ref>{{mathworld|title=Symmetric Difference|urlname=SymmetricDifference}}</ref> ==Properties== {{glossary}} {{term|[[Commutative property|Commutativity]]: yes}}{{defn| {{aligned table | style=text-align:center; border:1px solid darkgrey; | rowstyle=; | cols=3 | <math>A \oplus B</math> | <math>\Leftrightarrow</math> | <math>B \oplus A</math> | [[File:Venn0110.svg|50px]] | <math>\Leftrightarrow</math> | [[File:Venn0110.svg|50px]] }} }} {{term|[[Associative property|Associativity]]: yes}}{{defn| {{aligned table | style=text-align:center; border:1px solid darkgrey; | rowstyle=; | cols=9 | <math>~A</math> | <math>~~~\oplus~~~</math> | <math>(B \oplus C)</math> | <math>\Leftrightarrow</math> | | | <math>(A \oplus B)</math> | <math>~~~\oplus~~~</math> | <math>~C</math> | [[File:Venn 0101 0101.svg|50px]] | <math>~~~\oplus~~~</math> | [[File:Venn 0011 1100.svg|50px]] | <math>\Leftrightarrow</math> | [[File:Venn 0110 1001.svg|50px]] | <math>\Leftrightarrow</math> | [[File:Venn 0110 0110.svg|50px]] | <math>~~~\oplus~~~</math> | [[File:Venn 0000 1111.svg|50px]] }} }} {{term|[[Distributive property|Distributivity]]:}}{{defn|The exclusive or does not distribute over any binary function (not even itself), but [[Logical conjunction#Properties|logical conjunction distributes over exclusive or]]. <math>C\land(A \oplus B )= (C\land A) \oplus (C\land B)</math> (Conjunction and exclusive or form the multiplication and addition operations of a [[Field (mathematics)|field]] [[GF(2)]], and as in any field they obey the distributive law.)}} {{term|[[Idempotence|Idempotency]]: no}}{{defn| {{aligned table | style=text-align:center; border:1px solid darkgrey; | rowstyle=; | cols=7 | <math>~A~</math> | <math>~\oplus~</math> | <math>~A~</math> | <math>\Leftrightarrow</math> | <math>~0~</math> | <math>\nLeftrightarrow</math> | <math>~A~</math> | [[File:Venn01.svg|36px]] | <math>~\oplus~</math> | [[File:Venn01.svg|36px]] | <math>\Leftrightarrow</math> | [[File:Venn00.svg|36px]] | <math>\nLeftrightarrow</math> | [[File:Venn01.svg|36px]] }} }} {{term|[[Monotone Boolean function|Monotonicity]]: no}}{{defn| {{aligned table | style=text-align:center; border:1px solid darkgrey; | rowstyle=; | cols=7 | <math>A \rightarrow B</math> | <math>\nRightarrow</math> | | | <math>(A \oplus C)</math> | <math>\rightarrow</math> | <math>(B \oplus C)</math> | [[File:Venn 1011 1011.svg|50px]] | <math>\nRightarrow</math> | [[File:Venn 1011 1101.svg|50px]] | <math>\Leftrightarrow</math> | [[File:Venn 0101 1010.svg|50px]] | <math>\rightarrow</math> | [[File:Venn 0011 1100.svg|50px]] }} }} {{term|Truth-preserving: no}}{{defn|When all inputs are true, the output is not true. {{aligned table | style=text-align:center; border:1px solid darkgrey; | rowstyle=; | cols=3 | <math>A \land B</math> | <math>\nRightarrow</math> | <math>A \oplus B</math> | [[File:Venn0001.svg|50px]] | <math>\nRightarrow</math> | [[File:Venn0110.svg|60px]] }} }} {{term|Falsehood-preserving: yes}}{{defn|When all inputs are false, the output is false. {{aligned table | style=text-align:center; border:1px solid darkgrey; | rowstyle=; | cols=3 | <math>A \oplus B</math> | <math>\Rightarrow</math> | <math>A \lor B</math> | [[File:Venn0110.svg|60px]] | <math>\Rightarrow</math> | [[File:Venn0111.svg|50px]] }} }} {{term|[[Hadamard transform|Walsh spectrum]]: (2,0,0,−2)}} {{term|Non-[[Linear#Boolean functions|linearity]]: 0}}{{defn|The function is linear.}} {{term|Involution:}}{{defn|Exclusive or with one specified input, as a function of the other input, is an [[Involution (mathematics)|involution]] or self-inverse function; applying it twice leaves the variable input unchanged. {{aligned table | style=text-align:center; border:1px solid darkgrey; | rowstyle=; | cols=5 | <math>~A\oplus B~</math> | <math>~\oplus~</math> | <math>~B~</math> | <math>\Leftrightarrow</math> | <math>~A~</math> | [[File:Venn0110.svg|50px]] | <math>~\oplus~</math> | [[File:Venn0011.svg|50px]] | <math>\Leftrightarrow</math> | [[File:Venn0101.svg|50px]] }} }} {{glossary end}} If using [[binary numeral system|binary]] values for true (1) and false (0), then ''exclusive or'' works exactly like [[addition]] [[Modular arithmetic|modulo]] 2. ==Computer science== [[File:XOR ANSI Labelled.svg|thumb|right|114px|Traditional symbolic representation of an XOR [[logic gate]]]] ===Bitwise operation=== {{Main article|Bitwise operation}} [[File:Z2^4; Cayley table; binary.svg|thumb|[[Nimber]] addition is the ''exclusive or'' of [[nonnegative integer]]s in [[w:binary numeral system|binary]] representation. This is also the vector addition in <math>(\Z/2\Z)^4</math>.]] Exclusive disjunction is often used for bitwise operations. Examples: * 1 XOR 1 = 0 * 1 XOR 0 = 1 * 0 XOR 1 = 1 * 0 XOR 0 = 0 * {{n-ary|1110|2}} XOR {{n-ary|1001|2}} = {{n-ary|0111|2}} (this is equivalent to addition without [[carry (arithmetic)|carry]]) 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]] <math>(\Z/2\Z)^n</math>. In computer science, exclusive disjunction has several uses: * It tells whether two bits are unequal. * It is a controllable bit-flipper (the control input chooses whether or not to invert the data input). * It tells whether there is an [[Parity (mathematics)|odd]] number of 1 bits (<math>A \oplus B \oplus C \oplus D \oplus E</math> is true [[if and only if]] an odd number of the variables are true), which is equal to the [[parity bit]] returned by a [[parity function]]. In logical circuits, a simple [[adder (electronics)|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 cipher|Feistel network]] systems.{{citation needed|date=June 2015}} 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 network]]s, modeling the XOR function requires a second layer because XOR is not a [[Linear separability|linearly separable]] function. Similarly, XOR can be used in generating [[entropy pool]]s for [[hardware random number generator]]s. 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.<ref>{{cite web|last=Davies|first=Robert B|title=Exclusive OR (XOR) and hardware random number generators|url=http://www.robertnz.net/pdf/xor2.pdf|access-date=28 August 2013|date=28 February 2002}}</ref> XOR is used in [[RAID]] 3–6 for creating parity information. For example, RAID can "back up" bytes {{n-ary|10011100|2}} and {{n-ary|01101100|2}} from two (or more) hard drives by XORing the just mentioned bytes, resulting in ({{n-ary|11110000|2}}) 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 {{n-ary|01101100|2}} is lost, {{n-ary|10011100|2}} and {{n-ary|11110000|2}} can be XORed to recover the lost byte.<ref>{{cite web|last=Nobel|first=Rickard|title=How RAID 5 actually works|access-date=23 March 2017|date=26 July 2011|url=http://rickardnobel.se/how-raid5-works}}</ref> 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 list]]s 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 volume|bounding boxes]] and [[cursor (computers)|cursors]] on systems without [[alpha compositing|alpha channels]] or overlay planes. ==Encodings== It is also called "not left-right arrow" (<code>\nleftrightarrow</code>) in [[LaTeX]]-based markdown (<math>\nleftrightarrow</math>). Apart from the ASCII codes, the operator is encoded at {{unichar|22BB|XOR|html=}} and {{unichar|2295|CIRCLED PLUS|html=}}, both in block [[Mathematical operators and symbols in Unicode#Mathematical Operators|mathematical operators]]. ==See also== {{columns-list|colwidth=22em| * [[Material conditional]] • [[Paradoxes of material implication|(Paradox)]] * [[Affirming a disjunct]] * [[Ampheck]] * [[Controlled NOT gate]] * [[Disjunctive syllogism]] * [[Inclusive or]] * [[involution (mathematics)|Involution]] * [[List of Boolean algebra topics]] * [[Logical graph]] * [[Logical value]] * [[Propositional calculus]] * [[Rule 90]] * [[XOR cipher]] * [[XOR gate]] * [[XOR linked list]] }} ==Notes== <references /> ==External links== {{Commons category}} {{Wiktionary|exclusive or|XOR}} * [https://accu.org/index.php/journals/1915 All About XOR] * [https://web.stanford.edu/class/archive/cs/cs103/cs103.1142/lectures/01/Small01.pdf Proofs of XOR properties and applications of XOR, CS103: Mathematical Foundations of Computing, Stanford University] {{Logical connectives}} [[Category:Dichotomies]] [[Category:Logical connectives]] [[Category:Semantics]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:2-ary truth table
(
edit
)
Template:Citation needed
(
edit
)
Template:Cite book
(
edit
)
Template:Cite encyclopedia
(
edit
)
Template:Cite journal
(
edit
)
Template:Cite web
(
edit
)
Template:Columns-list
(
edit
)
Template:Commons category
(
edit
)
Template:Defn
(
edit
)
Template:Glossary
(
edit
)
Template:Glossary end
(
edit
)
Template:IPAc-en
(
edit
)
Template:Infobox logical connective
(
edit
)
Template:Logical connectives
(
edit
)
Template:Logical connectives sidebar
(
edit
)
Template:Main article
(
edit
)
Template:Mathworld
(
edit
)
Template:N-ary
(
edit
)
Template:Redirect
(
edit
)
Template:Refimprove
(
edit
)
Template:Rp
(
edit
)
Template:Short description
(
edit
)
Template:Term
(
edit
)
Template:Unichar
(
edit
)
Template:Wiktionary
(
edit
)