Functions: Metric spaces and continuity The following question is from Fred H. Croom's book "Principles of Topology"


Let $X$ be a metric space with metric $d$ and $A$ a non-empty subset of $X$. Define $f:X\rightarrow \mathbb{R}$ by 
    \begin{equation}
f(x) = d(x,A) , x\in X
\end{equation}
    Show that $f$ is continuous.  


Now, we seek to show that $f$ is continuous. In order for it to be continuous, for every point $a$ in $X$, then for every $\epsilon>0$ there exists a $\delta>0$ such that if $x\in X$ and $d(x,a)<\delta$, then $d^{'}(f(x),f(a))<\epsilon$. 
Now in this problem, $f(x)$ is defined to be the greatest lower bound of all distances between some point $x$ and the set $A$ (if I am not mistaken).
I am still a little confused on how to approach it from here. Would I just need to apply the definition of continuity? Any suggestion? How would I properly approach this problem?

I want to thank you for taking the time to read this question. I greatly appreciate any assistance you provide. 
 A: First prove that $f_p(x) = d(x,p)$ for a fixed point $p$ is a continuous function, then prove that $g_A(x) = d(x,A)$ is continuous for a given set $A \subset X$.

*

*Let $x,y \in X$ such that $d(x,y) < \delta$ for some $\delta > 0$. Using a triangle inequality we have $f_p(x) \le f_p(y) + \delta$, as well as $f_p(y) \le f_p(x) + \delta$, from where $|f_p(x) - f_p(y)| \le \delta$. Choosing $\delta = \epsilon$ we prove that $f_p$ is continuous.


*Furthermore, for every $\delta' > 0$ (by definition of infimum) there is $a \in A$ such that $d(x,a) < d(x,A) + \delta'$. Then
$$d(y,a) \le d(y,x) + d(x,a) < \delta + d(x,A) + \delta'$$
Since $d(y,A) \le d(y,a)$, it follows that $g_A(y) < g_A(x) + \delta + \delta'$, that is
$$g_A(y) - g_A(x) < \delta + \delta'$$
Analogously we have that
$$g_A(x) - g_A(y) < \delta + \delta'$$
These two inequalities together give us
$$|g_A(x) - g_A(y)| < \delta + \delta'$$
Choosing $\delta = \delta' = \epsilon/2$ we prove the claim. I hope this helps...
EDIT: As noted by Invisible, beginning of the second part of the proof should be written more carefully. By definition of infimum and triangle inequality we know that for any $a \in A$
$$g_A(y) \le d(y,a) \le d(y,x) + d(x,a) = \delta + d(x,a)$$
Furthermore, for any $\delta' > 0$ there is $a_x \in A$ such that $d(x,a_x) < g_A(x) + \delta'$, thus taking $a = a_x$ we have $g_A(y) < g_A(x) + \delta + \delta'$. Rest of the proof may remain as it is.
