Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Exclusive or

From Wikipedia, the free encyclopedia
(Redirected fromExclusive disjunction)
True when either but not both inputs are true
"XOR" redirects here. For the logic gate, seeXOR gate. For other uses, seeXOR (disambiguation).
This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed.
Find sources: "Exclusive or" – news ·newspapers ·books ·scholar ·JSTOR
(May 2013) (Learn how and when to remove this message)
Exclusive disjunction
XOR
Venn diagram of Exclusive disjunction
Truth table(0110){\displaystyle (0110)}
Logic gate
Normal forms
Disjunctivex¯y+xy¯{\displaystyle {\overline {x}}\cdot y+x\cdot {\overline {y}}}
Conjunctive(x¯+y¯)(x+y){\displaystyle ({\overline {x}}+{\overline {y}})\cdot (x+y)}
Zhegalkin polynomialxy{\displaystyle x\oplus y}
Post's lattices
0-preservingyes
1-preservingno
Monotoneno
Affineyes
Self-dualno
Logical connectives
NOT¬A,A,A¯,A{\displaystyle \neg A,-A,{\overline {A}},\sim A}
ANDAB,AB,AB,A & B,A && B{\displaystyle A\land B,A\cdot B,AB,A\ \&\ B,A\ \&\&\ B}
NANDA¯B,AB,AB,AB¯{\displaystyle A{\overline {\land }}B,A\uparrow B,A\mid B,{\overline {A\cdot B}}}
ORAB,A+B,AB,AB{\displaystyle A\lor B,A+B,A\mid B,A\parallel B}
NORA¯B,AB,A+B¯{\displaystyle A{\overline {\lor }}B,A\downarrow B,{\overline {A+B}}}
XNORAB,A¯B¯{\displaystyle A\odot B,{\overline {A{\overline {\lor }}B}}}
equivalentAB,AB,AB{\displaystyle A\equiv B,A\Leftrightarrow B,A\leftrightharpoons B}
XORA_B,AB{\displaystyle A{\underline {\lor }}B,A\oplus B}
└nonequivalentAB,AB,AB{\displaystyle A\not \equiv B,A\not \Leftrightarrow B,A\nleftrightarrow B}
impliesAB,AB,AB{\displaystyle A\Rightarrow B,A\supset B,A\rightarrow B}
nonimplication (NIMPLY)AB,AB,AB{\displaystyle A\not \Rightarrow B,A\not \supset B,A\nrightarrow B}
converseAB,AB,AB{\displaystyle A\Leftarrow B,A\subset B,A\leftarrow B}
converse nonimplicationAB,AB,AB{\displaystyle A\not \Leftarrow B,A\not \subset B,A\nleftarrow B}
Related concepts
Applications
Category
Venn diagram ofABC{\displaystyle A\oplus B\oplus C}

Exclusive or,exclusive disjunction,exclusive alternation,logical non-equivalence, orlogical inequality is alogical operator whose negation is thelogical 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 isodd.[1]

It gains the name "exclusive or" because the meaning of "or" is ambiguous when bothoperands are true. XORexcludes 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 issymbolized by the prefix operatorJ{\displaystyle J}[2]: 16  and by theinfix operatorsXOR (/ˌɛksˈɔːr/,/ˌɛksˈɔː/,/ˈksɔːr/ or/ˈksɔː/),EOR,EXOR,˙{\displaystyle {\dot {\vee }}},¯{\displaystyle {\overline {\vee }}},_{\displaystyle {\underline {\vee }}},,{\displaystyle \oplus },{\displaystyle \nleftrightarrow }, and{\displaystyle \not \equiv }.

Definition

[edit]
Each row of this binaryWalsh matrix is the truth table of thevariadic 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.)

Thetruth table ofAB{\displaystyle A\nleftrightarrow B} shows that it outputs true whenever the inputs differ:

A{\displaystyle A}B{\displaystyle B}AB{\displaystyle A\nleftrightarrow B}
FFF
FTT
TFT
TTF

Equivalences, elimination, and introduction

[edit]

Exclusive disjunction essentially means 'either one, but not both nor none'. In other words, the statement is trueif 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 disjunctionpq{\displaystyle p\nleftrightarrow q}, also denoted byp?q{\displaystyle p\operatorname {?} q} orJpq{\displaystyle Jpq}, can be expressed in terms of thelogical conjunction ("logical and",{\displaystyle \land }), thedisjunction ("logical or",{\displaystyle \vee }), and thenegation (¬{\displaystyle \neg }) as follows:

pq=(pq)¬(pq){\displaystyle {\begin{matrix}p\nleftrightarrow q&=&(p\vee q)\land \neg (p\land q)\end{matrix}}}

The exclusive disjunctionpq{\displaystyle p\nleftrightarrow q} can also be expressed in the following way:

pq=(p¬q)(¬pq){\displaystyle {\begin{matrix}p\nleftrightarrow q&=&(p\land \lnot q)\lor (\lnot p\land q)\end{matrix}}}

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

pq=(p¬q)(¬pq)=((p¬q)¬p)((p¬q)q)=((p¬p)(¬q¬p))((pq)(¬qq))=(¬p¬q)(pq)=¬(pq)(pq){\displaystyle {\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}}}

It is sometimes useful to writepq{\displaystyle p\nleftrightarrow q} in the following way:

pq=¬((pq)(¬p¬q)){\displaystyle {\begin{matrix}p\nleftrightarrow q&=&\lnot ((p\land q)\lor (\lnot p\land \lnot q))\end{matrix}}}

or:

pq=(pq)(¬p¬q){\displaystyle {\begin{matrix}p\nleftrightarrow q&=&(p\lor q)\land (\lnot p\lor \lnot q)\end{matrix}}}

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

The exclusive or is also equivalent to the negation of alogical biconditional, by the rules of material implication (amaterial conditional is equivalent to the disjunction of the negation of itsantecedent and its consequence) andmaterial equivalence.

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

pq=(p¬q)(¬pq)=pq¯+p¯q=(pq)(¬p¬q)=(p+q)(p¯+q¯)=(pq)¬(pq)=(p+q)(pq¯){\displaystyle {\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}}}

Negation of the operator

[edit]

By applying the spirit ofDe Morgan's laws, we get:¬(pq)¬pqp¬q.{\displaystyle \neg (p\nleftrightarrow q)\equiv \neg p\nleftrightarrow q\equiv p\nleftrightarrow \neg q.}

Relation to modern algebra

[edit]

Although theoperators{\displaystyle \wedge } (conjunction) and{\displaystyle \lor } (disjunction) are very useful in logic systems, they fail a more generalizable structure in the following way:

The systems({T,F},){\displaystyle (\{T,F\},\wedge )} and({T,F},){\displaystyle (\{T,F\},\lor )} aremonoids, but neither is agroup. This unfortunately prevents the combination of these two systems into larger structures, such as amathematical ring.

However, the system using exclusive or({T,F},){\displaystyle (\{T,F\},\oplus )}is anabelian group. The combination of operators{\displaystyle \wedge } and{\displaystyle \oplus } over elements{T,F}{\displaystyle \{T,F\}} produce the well-knowntwo-element fieldF2{\displaystyle \mathbb {F} _{2}}. This field can represent any logic obtainable with the system(,){\displaystyle (\land ,\lor )} and has the added benefit of the arsenal of algebraic analysis tools for fields.

More specifically, if one associatesF{\displaystyle F} with 0 andT{\displaystyle T} with 1, one can interpret the logical "AND" operation as multiplication onF2{\displaystyle \mathbb {F} _{2}} and the "XOR" operation as addition onF2{\displaystyle \mathbb {F} _{2}}:

r=pqr=pq(mod2)r=pqr=p+q(mod2){\displaystyle {\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}}}

The description of aBoolean function as apolynomial inF2{\displaystyle \mathbb {F} _{2}}, using this basis, is called the function'salgebraic normal form.[3]

Exclusive or in natural language

[edit]

Disjunction is often understood exclusively innatural 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 befelicitously used in combination with an outright statement that both disjuncts are true. The second example shows that the exclusive inference vanishes away underdownward 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 aspragmaticconversational implicatures calculated on the basis of an inclusivesemantics. Implicatures are typicallycancellable and do not arise in downward entailing contexts if their calculation depends on theMaxim of Quantity. However, some researchers have treated exclusivity as a bona fide semanticentailment 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 Frenchsoit... soit.[4]

Alternative symbols

[edit]

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

[edit]
Commutativity: yes
AB{\displaystyle A\oplus B}     {\displaystyle \Leftrightarrow }    BA{\displaystyle B\oplus A}
    {\displaystyle \Leftrightarrow }    
Associativity: yes
 A{\displaystyle ~A}      {\displaystyle ~~~\oplus ~~~}(BC){\displaystyle (B\oplus C)}     {\displaystyle \Leftrightarrow }    (AB){\displaystyle (A\oplus B)}      {\displaystyle ~~~\oplus ~~~} C{\displaystyle ~C}
      {\displaystyle ~~~\oplus ~~~}     {\displaystyle \Leftrightarrow }         {\displaystyle \Leftrightarrow }          {\displaystyle ~~~\oplus ~~~}
Distributivity:
The exclusive or does not distribute over any binary function (not even itself), butlogical conjunction distributes over exclusive or.C(AB)=(CA)(CB){\displaystyle C\land (A\oplus B)=(C\land A)\oplus (C\land B)} (Conjunction and exclusive or form the multiplication and addition operations of afieldGF(2), and as in any field they obey the distributive law.)
Idempotency: no
 A {\displaystyle ~A~}  {\displaystyle ~\oplus ~} A {\displaystyle ~A~}     {\displaystyle \Leftrightarrow }     0 {\displaystyle ~0~}     {\displaystyle \nLeftrightarrow }     A {\displaystyle ~A~}
  {\displaystyle ~\oplus ~}     {\displaystyle \Leftrightarrow }         {\displaystyle \nLeftrightarrow }    
Monotonicity: no
AB{\displaystyle A\rightarrow B}     {\displaystyle \nRightarrow }    (AC){\displaystyle (A\oplus C)}{\displaystyle \rightarrow }(BC){\displaystyle (B\oplus C)}
    {\displaystyle \nRightarrow }         {\displaystyle \Leftrightarrow }    {\displaystyle \rightarrow }
Truth-preserving: no
When all inputs are true, the output is not true.
AB{\displaystyle A\land B}     {\displaystyle \nRightarrow }    AB{\displaystyle A\oplus B}
    {\displaystyle \nRightarrow }    
Falsehood-preserving: yes
When all inputs are false, the output is false.
AB{\displaystyle A\oplus B}     {\displaystyle \Rightarrow }    AB{\displaystyle A\lor B}
    {\displaystyle \Rightarrow }    
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 aninvolution or self-inverse function; applying it twice leaves the variable input unchanged.
 AB {\displaystyle ~A\oplus B~}  {\displaystyle ~\oplus ~} B {\displaystyle ~B~}     {\displaystyle \Leftrightarrow }     A {\displaystyle ~A~}
  {\displaystyle ~\oplus ~}     {\displaystyle \Leftrightarrow }    

If usingbinary values for true (1) and false (0), thenexclusive or works exactly likeadditionmodulo 2.

Computer science

[edit]
Traditional symbolic representation of an XORlogic gate

Bitwise operation

[edit]
Main article:Bitwise operation
Nimber addition is theexclusive or ofnonnegative integers inbinary representation. This is also the vector addition in(Z/2Z)4{\displaystyle (\mathbb {Z} /2\mathbb {Z} )^{4}}.

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
  • 11102 XOR10012 =01112 (this is equivalent to addition withoutcarry)

As noted above, since exclusive disjunction is identical to addition modulo 2, the bitwise exclusive disjunction of twon-bit strings is identical to the standard vector of addition in thevector space(Z/2Z)n{\displaystyle (\mathbb {Z} /2\mathbb {Z} )^{n}}.

In computer science, exclusive disjunction has several uses:

In logical circuits, a simpleadder can be made with anXOR 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.

Incryptography, XOR is sometimes used as a simple, self-inverse mixing function, such as inone-time pad orFeistel 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-activatedartificial neural networks, modeling the XOR function requires a second layer because XOR is not alinearly separable function.

Similarly, XOR can be used in generatingentropy pools forhardware 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 inRAID 3–6 for creating parity information. For example, RAID can "back up" bytes100111002 and011011002 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 containing011011002 is lost,100111002 and111100002 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 theXOR 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 representdoubly linked list data structures.

Incomputer graphics, XOR-based drawing methods are often used to manage such items asbounding boxes andcursors on systems withoutalpha channels or overlay planes.

Encodings

[edit]

It is also called "not left-right arrow" (\nleftrightarrow) inLaTeX-based markdown ({\displaystyle \nleftrightarrow }). Apart from the ASCII codes, the operator is encoded atU+22BB XOR (⊻) andU+2295 CIRCLED PLUS (⊕, ⊕), both in blockmathematical operators.

See also

[edit]

Notes

[edit]
  1. ^Germundsson, Roger; Weisstein, Eric."XOR".MathWorld.Wolfram Research. Retrieved17 June 2015.
  2. ^abBocheński, J. M. (1949).Précis de logique mathématique(PDF) (in French). The Netherlands: F. G. Kroonder, Bussum, Pays-Bas. Translated asBocheń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.{{cite book}}:ISBN / Date incompatibility (help)
  3. ^Joux, Antoine (2009)."9.2: Algebraic normal forms of Boolean functions".Algorithmic Cryptanalysis. CRC Press. pp. 285–286.ISBN 9781420070033.
  4. ^abcdAloni, Maria (2016)."Disjunction". In Zalta, Edward N. (ed.).The Stanford Encyclopedia of Philosophy (Winter 2016 ed.). Metaphysics Research Lab, Stanford University. Retrieved2020-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. ^abBoole, 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 inPeano, G. (1958).Opere Scelte, Volume II. Roma: Edizioni Cremonese. pp. 123–176.
  12. ^ГРАДШТЕЙН, И. С. (1959) [1936].ПРЯМАЯ И ОБРАТНАЯ ТЕОРЕМЫ: ЭЛЕМЕНТЫ АЛГЕБРЫ ЛОГИКИ (in Russian) (3 ed.). МОСКВА: ГОСУДАРСТВЕННОЕ ИЗДАТЕЛЬСТВО ФИЗИКа-МАТЕМАТИЧЕСКОЙ ЛИТЕРАТУРЫ. Translated asGradshtein, 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. Retrieved7 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). Retrieved28 August 2013.
  23. ^Nobel, Rickard (26 July 2011)."How RAID 5 actually works". Retrieved23 March 2017.

External links

[edit]
Wikimedia Commons has media related toExclusive disjunction.
Look upexclusive or orXOR in Wiktionary, the free dictionary.
Retrieved from "https://en.wikipedia.org/w/index.php?title=Exclusive_or&oldid=1285566162"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp