Three-bit lossy Hamming code (source code)

= Three-bit lossy Hamming code
{title2=$R=1/3,\quad D=1/4$}

Let $X_1,X_2,X_3$ be <independent> fair <bits>. The <encoder> sends their majority <bit>: zero when at least two inputs are zero, and one otherwise. The <decoder> reconstructs $000$ or $111$ by repeating that received <bit> three times. This is <lossy compression>: different original strings deliberately share a reconstruction.

There are eight equally likely inputs. The strings $000$ and $111$ have zero <Hamming distance> from their reconstructions; each of the other six has <Hamming distance> one. One transmitted <bit> represents three source symbols, so
$$
\boxed{R=\frac13,\qquad D=\frac{2\cdot0+6\cdot1}{8\cdot3}=\frac14.}
$$
Every input has average <Hamming distortion> at most $1/3$, whereas the population average is $1/4$. The actual <block code> therefore obeys $R\geq R(D)\approx0.18872$, but does not reach the optimal long-block rate.

\Image[/three-bit-lossy-hamming-code.png]
{title=Eight equally likely source strings become two reconstructions using one transmitted bit}
{description=The <encoder> sends the majority <bit>. Orange highlights a reconstructed <bit> that differs from its input. Six source strings have one mismatch and two have none, giving average <Hamming distortion> $1/4$ per source symbol. No errors occur in the transmission model; the loss is introduced deliberately by the <encoder>.}

This construction uses the same reconstruction strings as the threefold <binary repetition code>, but the tasks differ. An error-correcting <encoder> expands one source <bit> into three transmitted <bits>; this <lossy compression> example compresses three source <bits> into one transmitted <bit>. The source distribution and the direction of the mapping matter.