XOR Undoes Itself

Zobrist hashing assigns a random 64-bit value to each (piece, square) pair and XORs them together into a position key. Why XOR rather than a sum or a polynomial?

A

XOR is faster than addition on modern CPUs, so making and unmaking a move is a cycle cheaper: XOR out the old square, XOR in the new one. No history is stored and the update is O(1)O(1) either way.

B

XOR is its own inverse, so making and unmaking a move is the same operation: XOR out the old square, XOR in the new one. No history is stored and the update is O(1)O(1) either way.

C

XOR distributes over addition, so making and unmaking a move is the same operation: XOR out the old square, XOR in the new one. No history is stored and the update is O(1)O(1) either way.

D

The XOR of uniform values is uniform while a sum is not, so a position key avoids collisions entirely: XOR out the old square, XOR in the new one. No history is stored and the key is unique.