Let $(X,d)$ be a metric space and let $A$ be a subset of $X$. Define function $f_A:X\to \mathbb R$ by $f(x)=d(\{x\},A)$. Show that the function is continuous.
Here is my attempt in which I do not know if there are any mistakes. I am especially concerned about my construction of $\epsilon$ in the second part. Also, if I am correct, is there a simpler way for me to do so?
Let $(a,b)$ be a basis element in the standard topology on $\mathbb R$. Let $x\in f^{-1}((a,b))$.
If $d(\{x\},A)=0$, then $a<0$ and $b>0$. Consider $x'\in B_d(x,b)$, I claim that $f(x')\in (a,b)$: For any $\epsilon>0$, there exists $p\in A$ such that $d(x,p)<\epsilon$. Since $x'\in B_d(x,b)$, $d(x,x')<b$. Let $\epsilon={b-d(x,x')}$, then $d(x',p)\le d(x,x')+d(x,p)<b$. Therefore, $f(x')=d(\{x'\},A)<b$. Since $a<0$ and $f(x')\ge 0$, $f(x')\in (a,b)$ must be true.
If $d(\{x\},A)=r>0$, then $x\notin A$. Now consider some arbitrary $x'\in B_d(x,\epsilon)$ where $\epsilon=\min\{{r-a\over 2},b-r,r\}$. Since $d(x,x')<b-r$, let $\epsilon=b-r-d(x,x')$. For any $\epsilon>0$, there exists a point $p\in A$ such that $d(x,p)<r+\epsilon=b-d(x,x')$. Hence $d(x', p)\le d(x',x)+d(x,p)<b$. It follows that $f(x')=d(\{x'\},A)<b$. Also we have $d(x',p)\ge d(x,p)-d(x,x')> 0$(guaranteed by our assumption that $d(x,x')<r$ ). Since $d(x,p)\ge r$ and $d(x,x')<{r-a\over 2}$, $d(x',p)> {a+r\over 2}$ for any $p\in A$. As a result, $d(\{x'\},A)\ge {a+r\over 2}>a$. Therefore, $f(x')\in (a,b)$.
In conclusion there is a neighborhood of $x$ that is contained entirely inside $f^{-1}((a,b))$. Hence $f^{-1}((a,b)) $ is open.