Proving that a sphere is a closed set I have to prove that a sphere centered at $x_0$ with radius $r$
$S(x_0,r) = \{x \in X | d(x,x_0) = r\}$
is a closed set.
I know I should prove that the complement is open. If I take a point $y$ inside the complement and consider the open ball with radius $\epsilon = \frac{d-r}{2}$ where $d$ is the distance from $x_0$ to $y$ I have to show that the distance $d(x_0,y) > r$. This is where I am stuck. I thought about using the triangle inequality, but I am sure how to proceed. Any help would be greatly appreicated.
 A: Easiest way to prove this is to first prove that the function $d_{x_0}: X \to \mathbb{R}$, defined as $d_{x_0} = d(x, x_0)$, is continuous (this follows essentially from the triangle inequality for the metric $d$), and then to note that the preimage of a closed set under a continuous function is closed, a singleton set $\{r\}$ is closed in $\mathbb{R}$, and $S(x_0, r) = d_{x_0}^{-1}(\{r\})$.
A: Take $y$ in the complement of your sphere, $S(x_0, r)^c$.
If $y$ is inside the sphere, meaning $d(x_0, y) < r$, then consider $\varepsilon = r - d(x_0, y) > 0$ and the open ball $B(y, \varepsilon)$.
For $z \in B(y, \varepsilon)$ we have
$$d(x_0, z) \le d(x_0, y) + d(y,z) < d(x_0, y) + r - d(x_0, r) = r $$
Hence $B(y, \varepsilon) \subseteq S(x_0, r)^c$.
If $y$ is on the outside of the sphere, meaning $d(x_0, y) > r$, then consider $\varepsilon = d(x_0, y) -r > 0$ and the open ball $B(y, \varepsilon)$.
For $z \in B(y, \varepsilon)$ we have
$$d(x_0, y) \le d(x_0, z) + d(y,z) \implies d(x_0, z) \ge d(x_0, y) - d(y,z) > d(x_0, y)- d(x_0, r) +r= r $$
Hence $B(y, \varepsilon) \subseteq S(x_0, r)^c$.
$\therefore$ in any case we have, for all $y\in S(x_0,r)^c$, there exists $\varepsilon>0$ such that $B(x_0,\varepsilon)\subseteq S(x_0,r)^c$.
So, $S(x_0, r)^c$ is open which implies that $S(x_0, r)$ is closed.
