Hamming metric
Let
$x$  $=({x}_{1},{x}_{2},{x}_{3},\mathrm{\dots},{x}_{n}),$  
$y$  $=({y}_{1},{y}_{2},{y}_{3},\mathrm{\dots},{y}_{n})$ 
be bit patterns, that is, vectors consisting of zeros and ones.
The Hamming distance^{} ${d}_{H}(u,v)$ defined as
$$\sum _{j=1}^{n}{x}_{i}{y}_{i}$$ 
is equal to the number of positions where the bit patterns are differents.
For instance, if $u=(0,1,1,0,1,0,1)$ and $v=(1,0,1,0,1,0,1)$ then
$${d}_{H}(u,v)=01+10+11+00+11+00+11=3$$ 
because $u$ and $v$ have different bits at three positions.
The Hamming distance holds the properties of a metric (otherwise it would not be truly a distance):

•
${d}_{H}(x,y)\ge 0$ for any $x,y$.

•
${d}_{H}(x,y)=0$ if and only if $x=y$.

•
${d}_{H}(x,y)={d}_{H}(y,x)$ for any $x,y$.

•
${d}_{H}(x,y)\le {d}_{H}(x,z)+{d}_{H}(z,y)$ for any $x,y,z$.
If we realize that ${d}_{H}$ is counting something (positions where bits differ), then it’s clear that ${d}_{H}$ can never be negative. Also, ${d}_{H}(x,x)=0$ because a bit pattern has no different bits respect to itself, and if two bit patterns coincide on each position, they are indeed the same pattern, which proves the second property. The third condition also follows from the trivial fact that if $x$ differs at some position from $y$, then $y$ differs at the sae position from $x$.
We are left to prove the last condition (trangle inequality). If
$x$  $=({x}_{1},{x}_{2},{x}_{3},\mathrm{\dots},{x}_{n})$  
$y$  $=({y}_{1},{y}_{2},{y}_{3},\mathrm{\dots},{y}_{n})$  
$z$  $=({z}_{1},{z}_{2},{z}_{3},\mathrm{\dots},{z}_{n})$ 
then ${d}_{H}(x,y)$ counts at how many places does $x$ differ from $y$. For instance, suppose that ${x}_{3}\ne {y}_{3}$. This means that the third bits are different, which adds $1$ to the whole sum ${d}_{H}(x,y)$.
Now, if ${x}_{3}\ne {y}_{3}$ it cannot happen that ${x}_{3}={z}_{3}$ and ${z}_{3}={y}_{3}$ at the same , so we have that ${x}_{3}\ne {z}_{3}$ or ${z}_{3}\ne {y}_{3}$. In either case, the sum ${d}_{H}(x,z)+{d}_{H}(z,y)$ also increases by one.
So, for each mismatch that increases ${d}_{H}(x,y)$ by one, ${d}_{H}(x,z)+{d}_{H}(z,y)$ also increases by one. We conclude that
$${d}_{H}(x,y)\le {d}_{H}(x,z)+{d}_{H}(z,y).$$ 
Title  Hamming metric 

Canonical name  HammingMetric 
Date of creation  20130322 14:59:37 
Last modified on  20130322 14:59:37 
Owner  drini (3) 
Last modified by  drini (3) 
Numerical id  7 
Author  drini (3) 
Entry type  Definition 
Classification  msc 05C12 
Classification  msc 94C99 
Synonym  Hamming distance 
Synonym  Hamming metric 
Related topic  HammingDistance 