开发者

What does Exclusive in XOR really mean?

开发者 https://www.devze.com 2023-02-15 14:12 出处:网络
Maybe this is just obvious to everyone but can someone explain where XOR (or Exclusive-OR) got its name from? What does the word Exclusive really mean? Not that it matters, but its just stuck in my he

Maybe this is just obvious to everyone but can someone explain where XOR (or Exclusive-OR) got its name from? What does the word Exclusive really mean? Not that it matters, but its just stuck in my head since morning.

OR:
0 0 0
0 1 1
1 0 1
1 1 1

XOR:
0 0 0
0 1 1
1 0 1
1 1 0

开发者_开发问答Is it "exclusively 0 for inputs 1,1", "special version of OR" or something else?


It's what children understand as OR

You can have chocolate OR you can have ice cream

But a programmer would regard this as having both!

Q: "Would you like tea or coffee"
Annoying programmer answer = yes


XOR is an "exclusive OR" because it only returns a "true" value of 1 if the two values are exclusive, i.e. they are both different.


According to Knuth in Vol. 4A of TAOCP, George Boole "...wrote x+y to stand for disjunction, but he took pains to never use this notation unless x and y were mutually exclusive (not both 1). If necessary, he wrote x+(1-x)y to ensure that the result of a disjunction would never be 2."

XOR is addition with carries being lost.


It's exclusive in the sense that the two operands must be mutually exclusive (in other words, different).


This comes from set theory. Consider that you have two sets A and B, and an element which may or may not be in those sets. The first boolean input is true if the element is in set A. The second boolean input is true if the element is in set B.

If the element is "exclusive" to one set (as in "not shared" with the other) then the XOR operator will return true. Illustration from wikipedia:

What does Exclusive in XOR really mean?


Exclusive in XOR means exactly what it says - one of the two has to be excluded. That is, either one or the other. Neither both, nor none - only one. At least that's how I've understood it :)


It's exclusive as in "only one." In other words, it's "one of the two, but not both."


I read a nice 'plain English' example today:

Consider, for example, the English sentence, "You pay me by Tuesday or I'll sue." If that "or" were the logical connective, then the sentence is true when either you do pay me by Tuesday or I sue you; so you could pay me on Monday and I still might sue you. But this particular use of "or" would normally be taken to mean that either you pay me by Tuesday and I don't sue you, or you do not pay me by Tuesday and I do sue you - the so-called "exclusive or".

Hugh Darwen, "An Introduction to Relational Database Theory", p76.

0

精彩评论

暂无评论...
验证码 换一张
取 消