TITLE: If a function $d(x,y)$ fulfills triangle inequality, is the same true for $|d(x,y)|$?
QUESTION [5 upvotes]: Suppose we have a function $d\colon X\times X\to\mathbb R$ such that
$$d(x,z)\le d(x,y)+d(y,z).$$
But we do not require other properties of metric (non-negativity, symmetry). If it helps, in the situation which motivated this question we have $d(x,x)=0$.
Do we get that then also
$$|d(x,z)|\le |d(x,y)|+|d(y,z)|,$$
(triangle inequality for the absolute value of $d$) holds?

Of course, we immediately have 
$$d(x,z)\le d(x,y)+d(y,z) \le |d(x,y)|+|d(y,z)|,$$
so it would suffice to show the same upper bound for $-d(x,z)$. If we had symmetry we could say that
$$-d(x,z) \le d(y,x) - d(y,z) = d(x,y) - d(y,z) \le |d(x,y)|+|d(y,z)|,$$
but it is not clear whether we can do something similar without symmetry, too.

This was motivated by my previous question: Does a metric-like space generate a topology if open balls are defined as $B_\sigma(X,\varepsilon)=\{y\in X; |\sigma(x,y)-\sigma(x,x)|<\varepsilon\}$? (You can find there further links including a paper from which the definition mentioned in the question was taken.)
The question dealt with function similar to metric but with the condition $p(x,x)=0$ omitted.

$p(x,y)\ge0$
$p(x,y)=0$ $\Rightarrow$ $x=y$
$p(x,y)=p(y,x)$
$p(x,z) \le p(x,y) + p(y,z)$

It was pointed out that the suggested way of generating topology, by taking the sets of the form $B(x,r)=\{y\in X; |p(x,y)-p(x,x)|<r\}$, does not give a base of topology. An answer suggested to use this version of triangle inequality:
$$p(x,z) \le p(x,y)+p(y,z)-p(y,y).$$
This is the version of the triangle inequality which is used in the definition of partial metric space. Still some conditions from the definition of partial metric space are missing (for example, we do not have $p(x,x)\le p(x,y)$ or that "indistancy implies equality".)1
If we want to define topology using the base consisting of sets $B(x,r)$ defined above, it is natural to look at the function $d(x,y)=p(x,y)-p(x,x)$ and its absolute value.
We have
\begin{align*}
p(x,z) &\le p(x,y)+p(y,z)-p(y,y)\\
p(x,z)-p(x,x) &\le (p(x,y)-p(x,x))+(p(y,z)-p(y,y))\\
d(x,z)&\le d(x,y)+d(y,z)
\end{align*}
So, the function $d$ fulfills triangle inequality. If the same is true for $|d|$, we would at least have some information about the system $B(x,r)$.
Notice that if $p(x,x)\ne p(y,y)$ for some $x$, $y$ than we do not have symmetry.

1You can find more information on partial metric spaces on website created by Steve Matthews or in the papper
Michael Bukatin, Ralph Kopperman, Steve Matthews and Homeira Pajoohesh: Partial Metric spaces, The American Mathematical Monthly, Vol. 116, No. 8 (Oct., 2009), pp. 708-718 (author's website, jstor).

REPLY [3 votes]: I will offer here another presentation of the counterexample given by Milo Brandt.
The minor difference is that triangle inequality is proved here, not verified by computer. However, the proof is still by cases, so perhaps it is not such a big improvement. Still, it is more difficult to find a counterexample than to offer a different presentation.
Let us define $$d(x,y)= \left\lceil \frac{x-y}2 \right\rceil$$ for $x,y\in\mathbb Z$.
To show that this function fulfills triangle inequality, i.e., that
\begin{align*}
d(x,z) &\le d(x,y)+d(y,z)\\
\left\lceil \frac{x-z}2 \right\rceil &\le \left\lceil \frac{x-y}2 \right\rceil + \left\lceil \frac{y-z}2 \right\rceil
\end{align*}
it suffices to check that
$$\left\lceil\frac{a+b}2\right\rceil \le \left\lceil\frac{a}2\right\rceil + \left\lceil\frac{b}2\right\rceil$$
for any $a,b\in\mathbb Z$. Which follows immediately from the facts that $\frac{a+b}2=\frac{a}2+\frac{b}2\le\left\lceil\frac{a}2\right\rceil + \left\lceil\frac{b}2\right\rceil$ and that $\left\lceil\frac{a}2\right\rceil + \left\lceil\frac{b}2\right\rceil$ is an integer. (Originally I have a more complicated argument here, I have replaced it by an easier proof taken from this answer.)
And, as mentioned in the other post, we have $d(1,0)=d(0,-1)=0$ while $d(1,-1)=-1$ and $|d(1,-1)|=1$, which means that $|d|$ does not fulfill triangle inequality. 

The same argument can be generalized in this way: If we take a subadditive function $f\colon\mathbb R\to\mathbb R$, then $d(x,y)=f(x-y)$ satisfies triangle inequality. From $f(a+b)\le f(a)+f(b)$ we immediately get $d(x,z)=f(z-x)\le f(y-x)+f(z-y)=f(z-x)$.
However, if $|f|$ is not subadditive, then $|d|$ does not satisfy triangle inequality. (Namely if $f(a+b)>f(a)+f(b)$ then the triangle inequality fails for $x=0$, $y=a$ and $z=a+b$.)