Show that in a metric space $(X, d)$, $A \cap B$ is non-empty iff $\inf\{d(x,y)\mid x \in A, y\in B\}=0$, where $A$ is closed and $B$ is compact.. Let $(X,d)$ be a non-empty metric space equipped with metric topology. Let $A,B \subseteq X$ be non-empty subsets with $A$ closed in $X$ and $B$ compact.
Show $A \cap B$ is non-empty if and only if $\inf\{d(x,y)\mid x \in A, y\in B\}=0$.
I'm having some trouble with this. I have before in an exercise showed this for $A$ compact and $B$ closed:
Let $A$ be compact and $B$ be closed in $X$. We want to show that $A\cap B \neq \varnothing$ if and only if $d(A,B):=\inf\{d(x,y)|x \in A, y\in B\}=0$.
Let us choose $a_n\in A$ and $b_n\in B$ such that we have:
$$d(a_n,b_n) \rightarrow d(A,B)=0$$
Since A is compact $(a_n)$ must have a convergent subsequence we may suppose wlog that $a_n \rightarrow a \in A$. As $d(a_n,b_n)\rightarrow 0$ we must have:
$$d(b_n,a)\leq d(a_n,b_n)+d(a_n,a) \rightarrow 0$$
That is $b_n \rightarrow a$. As $B$ is closed, $a \in B$, that is $a \in A \cap B$. I was wondering if I could use this to solve my problem?
I was also thinking something like considering what happens when I cover B by small open balls.
But I am a little lost…
 A: Since $\inf\{d(x, y) : x \in A, y \in B\} = 0,$ $A$ is closed and $B$ is compact, there is a sequence $(b_{n})$ of elements from $B$ converging to an $a \in A.$ Since $B$ is compact, this means $a \in B,$ so $A \cap B \ne \emptyset.$
Suppose on the other hand that $\inf\{d(x, y) : x \in A, y \in B\} = \epsilon > 0.$ Then no open ball of radius $\epsilon$ can contain points from both $A$ and $B$. Since $B$ is compact, we may cover $B$ by a finite collection of open balls of radius $\epsilon.$ The union of these balls contain no points from $A$, so $A \cap B = \emptyset.$
A: A useful general fact: In  any metric space $(X,d),$ if $\emptyset\ne B\subset X$ then the function $d(x,B)=^{def}\inf \{d(x,b):b\in B\}$ is continuous from $X$ to $\Bbb R.$
So if $A$ is compact and $A\ne\emptyset$ then the set $C=^{def} \{d(x,B):x\in A\}$ is a non-empty compact subset of $\Bbb R,$ so $\min C$ exists.
Obviously if $\min C>0$ then $A\cap B=\emptyset.$
If $a\in A$ and $d(x,B)= \min C=0$ then there exists a sequence $(b_n)_{n\in\Bbb N}$ in $B$ with $\lim_{n\to\infty}d(a,b_n)=0,$ so $a\in \overline B,$ so if $B$ is closed then $a\in B,$ so $a\in A\cap B.$
