TITLE: Prove that if $A$ is compact and $B$ is closed and $A\cap B = \emptyset$ then $\text{dist}(A,B) > 0$
QUESTION [5 upvotes]: Let $X$ be a metric space. For nonempty subsets $A,B\subseteq X$. Define $\text{dist}(A,B) := \inf\{d(x,y) : x\in A, y\in B\}$
a) Prove that if $A$ is compact and $B$ is closed and $A\cap B = \emptyset$ then $\text{dist}(A,B) > 0$
b) Suppose that $X = \mathbb{R}^n$, with the standard metric. Under the same assumptions of (a), prove that $\exists x_0\in A$ and $\exists y_0\in B$ such that dist$(A,B) = ||x_0 - y_0||$.
For a), it seems to me that the crucial point is that $A\cap B = \emptyset$. I can immediately see how this would imply that $\text{dist}(A,B) > 0$. However, I do not understand why it's necessary for $A$ to be compact, and $B$ to be closed. Could you explain why those conditions are necessary?

REPLY [3 votes]: This does not answer your questions but it's another proof of a).
If $\text{dist}(A,B)=0$, then by definition of this distance there are two sequences $(a_n)$ and $(b_n)$ (with terms in $A$ and $B$ respectively), such that $\lim d(a_n,b_n)=0$.
Since $A$ is compact, you know that there exists a convergent subsequence $(a_{n_k})$ of $(a_n)$ in $A$. 
Let $a\in A$ be its limit. $(d(a_{n_k},b_{n_k}))_{k\geqslant 0}$ is a subsequence of the convergent sequence $(d(a_n,b_n))$, so it has the same limit.
Since : $d(a,b_{n_k})\leqslant d(a,a_{n_k})+d(a_{n_k},b_{n_k})$ for all $k$, you find that $\lim b_{n_k}=a$
But $(b_{n_k})$ is a sequence with terms in the closed set $B$, so its limit $a$ is an element of $B$. 
Remember that we also have $a\in A$. This proves that $A\cap B\neq\emptyset$.
Consequently, if $A\cap B=\emptyset$ with $A$ compact and $B$ closed, then $d(A,B)>0$.