TITLE: Distance to a closed set
QUESTION [17 upvotes]: The distance between a point $a \in \mathbb{R}$ and a set $X \subset \mathbb{R}$ is defined as $$d(a,X) := \inf\{|x-a|: x \in X\}.$$ How to prove if $X$ is closed, then there is a $b \in X$ such that $d(a,X) = |b-a|$?
I've constructed a decreasing sequence converging to $d$ as follows: Given $r > d(a,X)$, there is a $x \in X$ such that $|x-a| < r$. Repeating the process with $r_{n+1} := \frac{d+r_n}{2}$ we get the inequality:
$$d \le |x_n-a| < r_n$$
It's easy to prove that $r_n \to d$, and therefore $|x_n-a| \to d$. If i could show the set $A := \{|x-a|: x\in X\}$ is closed, the result would be immediate. This is somehow my second question, is true that for every closed set $X$, the set $|X| := \{|x|: x\in X\}$ is closed?
Be free to contribute alternative proofs, i would appreciate.

REPLY [9 votes]: Another way to look at this: Letting $r$ be sufficiently large, $d(a,X) = d(a, X \cap B(0,r))$, where $B(0,r)$ is the closed ball of radius $r$ centered at the origin. Use the triangle inequality to show that $|a - x|$ is a continuous function of $x$ for $x  \in X \cap B(0,r)$. Since $ X \cap B(0,r)$ is compact, it achieves its minimum value at some $b \in X \cap B(0,r)$, and this $b$ will minimize $|a - b|$ over all $b \in X$ as well since $d(a,X) = d(a, X \cap B(0,r))$.
Yet another way: Let $E_n = \{x \in X: |x - a| \leq d(a,X) + {1 \over n}\}$. The $E_n$'s are nested compact sets and thus have nonempty intersection i.e. you can choose $b \in \cap_n E_n$. Then since $d(a,X) \leq |a - b| \leq d(a,X) + {1 \over n}$ for all $n$, you must have $|a - b| = d(a,X)$.