Is $M(x, y) = 0$ when $x=y$; 1 otherwise a metric? My graph theory textbook gives the definition of a 'metric' as:


*

*$M(x,y) \ge 0$ for all $x$, $y$, and $M(x,y) =0$ if and only if $x=y$;

*$M(x,y) = M(y,x)$ for all $x,y$;

*$M(x,y) \le M(x,z) + M(z,y)$ for all $x,y,z$.


When I see properties like this I try to construct basic functions that break only one of the rules at a time, while leaving the others intact. That gives me a good feel for how they play off one another.
So I tried the function
\begin{equation}
M(x, y) = \left\{\begin{matrix}
0 & \text{when} \quad x = y \\ 
1 & \text{when} \quad x \neq y \\
\end{matrix}\right.
\end{equation}
This seems to satisfy all the properties, though, except for maybe the third one! But it feels like it goes against the "spirit" of a metric somewhat.
Is there a counterexample I'm not seeing here? Many thanks in advance.
 A: The function you provide is indeed a metric, and it satisfies the third condition as well: if $x=y$, $M(x, y)=0$ and the inequality is satisfied; if instead $x\ne y$, surely one of $z\ne x$ or $z\ne y$ must be true, so you have $M(x,z)+M(z,y)\ge1$.
The metric you have found is called discrete metric, and is a particular example of metric that induces a discrete topology on the set equipped with it. If a set $X$ is endowed with this topology, all of its subsets are open in the topology, and as a consequence all functions from $X$ to another topological space is a continuous map.
A: It is not too hard to verify that
$$ M(x,y) = \begin{cases}
1 & \text{if $x\ne y$,} \\
0 & \text{otherwise}
\end{cases} $$
defines a metric.  Properties (1) and (2) are explicit in the definition, so only the triangle inequality (3) requires any though to verify.  The following argument maybe be overkill, but gets the job done:

Note that if $x\ne y$, then for any arbitrary point $z$, we have either $z \ne x$ or $z \ne y$ (or both!).  But then either
  $$ M(x,z) + M(z,y) = 1 + M(z,y) \ge 1
\qquad\text{or}\qquad
M(x,z) + M(z,y) = M(x,z) + 1 \ge 1. $$
  In either case, since $M(x,y) = 1$, we have
  $$ M(x,y) = 1 \le M(x,z) + M(z,y). $$
  On the other hand, if $x = y$, then $M(x,y) = 0$, and so
  $$ M(x,y) = 0 \le M(x,z) + M(z,y) $$
  for all $z$.

Therefore $M$ verifies property (3) and is a metric.  This metric is often called the trivial metric or the discrete metric, and is a fairly standard example.  You might think of this as "Baby's First Metric!"; it is a very simple function to understand, and it is not too hard to verify that it satisfies the axioms of a metric.  It also gives an abstract example of a metric that does't obviously relate to our usual intuition regarding the measurement of distances in Euclidean space.
