Can someone explain this formula for calculating Manhattan distance?
Lemma. $|a|+|b|=\max(|a+b|, |a-b|)$ for any real number $a$ and $b$.
Proof 1.
$|x|=\max(x, -x)$ for all real number $x$. So
$$\begin{aligned}
|a|+|b|
&amp;=\max(a, -a) + \max(b, -b)\\
&amp;=\max(a+b, a-b, -a+b, -a-b)\\
&amp;=\max(\max(a+b, -a-b), \max(a-b, -(a-b))\\
&amp;=\max(|a+b|, |a-b|)
\end{aligned}$$
Proof 2.
There are $2 \times 2 = 4$ cases.

$a\ge 0$

$b\gt 0$. LHS is $a+b$, RHS is $a+b$.
$b\le 0$. LHS is $a-b$, RHS is $a-b$.


$a\lt 0$

$b\gt 0$. LHS is $-a+b$, RHS is $-(a-b)$.
$b\le 0$. LHS is $-a-b$, RHS is $-(a+b)$.



One dimensionality of Manhattan-distance.
The Manhattan-distance of two points $(x_1, y_1)$ and $(x_2, y_2)$ is either $|(x_1+y_1)-(x_2+y_2)|$ or $|(x_1-y_1)-(x_2-y_2)|$, whichever is larger. That is, $ d((x_1, y_1),(x_2, y_2))= \max(|(x_1+y_1)-(x_2+y_2)|, |(x_1-y_1)-(x_2-y_2)|)$$
Proof: By definition,
$$d((x_1, y_1),(x_2, y_2))=|x_1-x_2| + |y_1-y_2|.$$
Now apply the lemma above. QED.
This answer also serves as a complement to another answer of mine.