Continuity of distance function and its generalization The starting is an easy undergraduate problem. The distance function $d: X \times X \rightarrow \mathbb{R}$ in a metric space $(X,d)$ is continuous. Please check if my proof is correct. If it is wrong please give some hint for the accurate proof.
From the triangular inequality we can say $d(x,y) \le d(x,z) + d(y,z)$ i.e. $d(x,y) - d(z,y) \le d(x,z)$
Interchanging the role of $x$ and $y$ we shall get $|d(x,y) - d(z,y)| \le d(x,z)$. 
Now for any $\epsilon > 0$ $|d(x,y) - d(z,y)| < \epsilon$ when $d(x,z) < \delta$ where $\epsilon = \delta$. 
Thus $d$ is uniformly continuous and hence continuous.
The main problem is here.


*

*I am thinking to prove it by using the open set definition of continuous function in a general topological space. Basis open sets of $\mathbb{R}$ with usual metric is open intervals $(a,b)$. Its inverse in the metric space will be an open set. How to prove it? 

*Can we generalize the concept of distance function to an arbitrary order topology? I want to say if we can replace the range $\mathbb{R}$ of the distance function $d$ by a linear continuum or an arbitrary order topology.   
Thank you very much for your help.
 A: In general,if $X,Y$ are any spaces, a function $f:X\times X\to Y$ may have the property that the functions  $f^{(1)}_a:X\to Y$ and $f^{(2)}_a:X\to Y$ are continuous for every $a\in X,$ where $f^{(1)}_a(x)=f(a,x)$ and $f^{(2)}_a(x)=f(x,a),$ and yet $f$ may still not be continuous. 
What you need to show is that when $u,v\in \mathbb R$ with $u<v$ then $d^{-1}(u,v)=\{(a,b)\in X:u <d(a,b)<v\}$ is open in the space $X\times X.$ 
An open set in $X\times X$ is a union of a family of sets of the form  $C\times D$ where $C,D$ are open balls in $X.$ So it suffices to show that if $(a,b)\in d^{-1}(u,v)$ then $C\times D\subset d^{-1}(u,v)$ for some open balls $C,D$ of $X$ with $(a,b)\in C\times D.$ That is, with $a\in C$ and $b\in D.$
For $d(a,b)\in (u,v),$ let $w=\min (d(a,b)-u,\; v-d(a,b)).$ We have $w>0$ so $a\in B_d(a,w/2)$ and $b\in B_d(b,w/2)$.
For $a'\in B_d(a,w/2)$ and $b'\in B_d(b,w/2)$ we have $$\text {(i)} \quad d(a',b')\leq d(a',a)+d(a,b)+d(b,b')<w/2+d(a,b)+w/2\leq v$$  and  we have $$\text {(ii) }\quad  d(a,a')+d(a',b')+d(b',b)\geq d(a,b)$$  which implies $$\text {(ii') }\quad  d(a',b')\geq d(a,b)-d(a,a')-d(b',b)>d(a,b)-w/2-w/2\geq  u.$$ Therefore $$(a,b)\in d^{-1}(u,v)\implies (a,b)\in B_d(a,w/2)\times B_d(b,w/2)\subset d^{-1}(u,v).$$
Remark: For an example of an $f$ of my first paragraph, let $X=Y=\mathbb R,$ let $f(0,0)=0$ and let $f(x,y)=xy/(x^2+y^2)$ when $x^2+y^2\ne 0.$ If $x\ne 0$ then $f(x,x)=1/2$ so $\lim_{x\to 0^+}f(x,x)=1/2\ne f(0,0)$. So $f$ is not continuous at $(0,0).$
A: Let $\{(a_n,b_n)\}_n\subseteq X\times X, (a,b)\in X\times X, (a_n,b_n)\to(a,b)$. We claim that $d(a_n,b_n)\to d(a,b)$.
First observe that $\forall n:d(a_n,b_n)\leq d(a_n,a)+d(a,b)+d(b,b_n)$ 
$\implies \limsup d(a_n,b_n)\leq \limsup (d(a_n,a)+d(a,b)+d(b,b_n)) $
$=\limsup d(a_n,a)+\limsup d(a,b)+\limsup d(b,b_n)= d(a,b)$ (equality holds when distributing limit superior over two sequences when one of them is convergent and the other one is bounded $(*)$). Hence $\limsup d(a_n,b_n)\leq d(a,b)$.
Conversely, $\forall n: d(a,b)\leq d(a,a_n)+d(a_n,b_n)+d(b_n,b)$
$ \implies d(a,b)\leq \liminf (d(a,a_n)+d(a_n,b_n)+d(b_n,b))=\liminf d(a_n,b_n)$ 
by an analogue of $(*)$. Thus $\limsup d(a_n,b_n)\leq d(a,b)\leq \liminf d(a_n,b_n)$, so that $d$ is continuous.
A: Take any open ball $B=(d(x,y)-\epsilon,d(x,y)+\epsilon)$ in $\Bbb{R}$. Then the inverse image $d^{-1}(B)\supseteq B_d(x,\epsilon/2)\times B_d(y,\epsilon/2)=U$, since for any $(z,t)\in U$, $d(z,t)\leq d(z,x)+d(x,t)<\epsilon/2+d(x,y)+d(y,t)<\epsilon+d(x,y)$. Similarly $d(x,y)<\epsilon+d(z,t)$.   So, $|d(x,y)-d(z,t)|<\epsilon$ as desired!
