Continuity of $d(x,A)$

I am doing a head-check here. I keep seeing this theorem quoted as requiring $A$ to be closed (as in Is the distance function in a metric space (uniformly) continuous?), but I don't think that it is needed.

Theorem. Let $(X,d)$ be a metric space and $\emptyset \neq A\subseteq X$. Then $x \longmapsto d(x,A)$ is Lipschitz continuous.

Proof. Fix $x,y \in X$. We note that for any $a \in A$ we have $d(x,a) \leq d(x,y) + d(y,a)$. Taking the infimum over $a \in A$ then gives $d(x,A) \leq d(x,y) + d(y,A)$. It follows quickly that $$ |d(x,A)-d(y,A)| \leq d(x,y) $$ and the claim is proved.

Have I accidentally used closedness of $A$ somewhere in my proof? I don't think it is necessary. Maybe the reason that it is usually quoted with $A$ closed is so that there is an $a \in A$ with $d(x,A) = d(x,a)$? (As @Martin points out, this also requires some compactness assumption on the unit ball, e.g. it holds if $X=\mathbb{R}^n$ with Euclidean metric)


Summarizing the comments and expanding slightly:

Yes, your argument is perfectly okay as it stands and you didn't make any hidden use of closedness of $A$ anywhere, only non-emptiness of $A$ is used to ensure that $d(\cdot,A)$ is a real-valued function.

A good additional exercise would be to show that $1$ is the best Lipschitz constant (unless $A$ is dense in $X$ where $d(\cdot,A) = 0$).


Why people often state this result for closed $A$ only is unclear to me, but I agree that it is quite common to make this unnecessary assumption. See for example this question or this question for further examples. The answers point out more or less explicitly that this is not needed.

It could be that the reason is related to the fact you mention---that the infimum is a minimum for closed subsets of $\mathbb{R}^n$, or, more generally, in metric spaces for which closed balls are compact. Another possible "reason" could be that $\overline{A} = \{x \in X \mid d(x,A) = 0\}$, which shows that a closed set $A$ can be recovered from the zero-set of $d(\cdot,A)$.