In particular, I was musing on this trick for swapping two values in a program without allocating any new variables. Wikipedia proves its correctness, and the proof picqued my curiosity.
It relies on the following four properties of XOR:
- Commutativity: $A \oplus B = B \oplus A$
- Associativity: $(A \oplus B) \oplus C = A \oplus (B \oplus C)$
- Identity exists: there is a bit string, 0, (of length N) such that $A \oplus 0 = A$ for any $A$
- Each element is its own inverse: for each $A$, $A \oplus A = 0$.
I suspect that it'd be trivial to construct another group for which those four properties of XOR hold, so I'm not interested in the assertion that other such groups exist. Instead, I ask:
Are there any other functions over bit strings that satisfy these same properties? If so, what are some examples? If not, can we prove that?
(For example, my first thought was $|x - y|$ while interpreting the binary strings as integers, which satisfies commutativity, identity existence, and each element being its own inverse, but not associativity.)