The Hamming distance between two strings of equal length is the number of positions at which their symbols differ (Black 2006). For binary strings, this is the number of coordinates at which the corresponding vertices of a hypercube graph differ. For example, abc and bca have Hamming distance 3.
For binary strings and
of length
,
|
(1)
|
where
is the Hamming weight and
denotes bitwise XOR. Indeed, a
coordinate of
is 1 iff the corresponding coordinates of
and
differ. For any binary string
of length
, applying the same XOR mask
to both arguments gives
|
(2)
|
Thus common XOR masking is an isometry of the binary string space.
For a subset with
and
, Fang and Huang (2026)
proved
|
(3)
|
where
and
are independent uniform elements of
, so equal pairs are included.
Equality holds precisely when
is a codimension-three subcube, obtained by fixing three coordinates.
Fang and Huang (2026) report that discussions with ChatGPT led to the trigonometric
polynomials in Lemma 2.3.