Question about a metric on $\mathbb{R}^2$ Can anyone please tell me whether the following function $d:\mathbb{R}^2 \times \mathbb{R}^2 \to  \mathbb{R}$ is really a metric or not on $\mathbb{R}^2$.
$$
d((x_1,x_2),(y_1,y_2))=
\begin{cases}
|x_1-y_1|, &\text{ if } x_2=y_2\\
|x_1|+|y_1|+|x_2-y_2|, &\text{ if } x_2 \neq y_2.
\end{cases}
$$
If it really is indeed a metric, please give the proof of triangle inequality.(I'm OK with the other two conditions).
 A: It is. Your indexing is confusing me, so I'm going to rename the points $p = (x_1, y_1)$ and $q = (x_2, y_2)$. Then your metric is
$$d(p, q) = \begin{cases}
|x_1 - x_2|, &\text{ if } y_1=y_2\\
|x_1|+|x_2|+|y_1-y_2|, &\text{ if } y_1 \neq y_2.
\end{cases}.$$
This metric describes the length of the shortest path between $p$ and $q$ which cannot move vertically except on the $y$-axis. (Imagine that $\mathbb{R}^2$ has been separated into horizontal rows, and the only way to move vertically is to go to a central column given by the $y$-axis.) 
That this is indeed a metric is a special case of the following general result, which is probably implicitly known to many people, but I have never seen it written down.
Proposition: Any function of the form "length of the shortest path between two points which satisfies condition $P$" on a metric space $M$ with an intrinsic metric is another metric provided that


*

*the shortest path between two points satisfying condition $P$ exists,

*the trivial path satisfies condition $P$,

*the reverse of a path satisfying condition $P$ also satisfies condition $P$, and

*the composition of two paths satisfying condition $P$ also satisfies condition $P$.


(In other words, the collection of all paths satisfying condition $P$ is a connected groupoid.) 
Proof. The first condition implies that the function $d$ is well-defined. The second condition implies that $d(p, p) = 0$. The third condition implies that $d(p, q) = d(q, p)$. Since $M$ has an intrinsic metric, $d$ is automatically positive-definite, so it remains to prove the triangle inequality.
Let $p, q, r$ be three points. The composition of the shortest path from $p$ to $q$ satisfying $P$ and the shortest path from $q$ to $r$ satisfying $P$ is, by the fourth condition, a path from $p$ to $r$ satisfying $P$, hence has length at least the length of the shortest path from $p$ to $r$ satisfying $P$. Thus
$$d(p, r) \le d(p, q) + d(q, r)$$
as desired. 
This optimization argument is in some sense a fundamental reason to consider the triangle inequality a reasonable axiom. In fact it is arguably the most important axiom; there are good reasons to drop any of the other axioms of a metric space (some of which correspond to dropping conditions above) to get various generalizations of metric spaces, which are described on the nLab among other places. 
