nrk said:
Yes, as x xor y is the same as x' xor y'. However, while this is pretty
neat, I think it makes the code harder to comprehend than using a straight
xor operation on the logical conditions (maybe its me that gets confused
when seeing negation all over the place).
And for those who believe that the xor shouldn't be used in combining
logical conditions, there is one situation where I have found this to be
eminently useful: when processing command line arguments where two
different options are mutually incompatible, but atleast one of them must
have been specified.
If you think that's bad, try the following with
A,B:{0,1}. First column is the intended operation.
Middle column is the arithmetic equivalent. Last
column is an alternative logical expression. The
variables A,B have values from the set {0,1}.
NOT(A): 1-A
A AND B: A*B : NOT(NOT(A) OR NOT(B))
A NAND B: 1-A*B : NOT(A) OR NOT(B)
A OR B: A+B-A*B : NOT(NOT(A) AND NOT(B))
A NOR B: 1-A-B+A*B : NOT(A) AND NOT(B)
A == B: 1+2*A*B-A-B : A XNOR B
A <> B: A+B-2*A*B : A XOR B
A < B: B-B*A : NOT(A) AND B
A > B: A-A*B : A AND NOT(B)
A <= B: 1-A+A*B : NOT(A) OR B
A >= B: 1-B+A*B : A OR NOT(B)