# If $A$ is compact and $B$ is closed, show $d(A,B)$ is achieved [duplicate]

Let $A, B$ be subsets of a metric space $X$. If $A$ is compact and $B$ is closed, show that the distance between $A$ and $B$ is achieved.

Attempt at a proof:

Let $A$ be compact and $B$ be closed. Let $m=d(A,B)=\inf_{b\in B} d(A,B)$. Then, there are two possibilities:
(a) $\exists b\in B$, $d(a,b)=m$. If this is the case, we're done.
(b) $\forall b\in B$, $d(a,b)>m$. In this case,

there exists a sequence $\{b_n\}\subseteq B:$ $d(a,b_n)\rightarrow m$ as $n\rightarrow\infty$ by definition of infinum. Then there exists a subsequence $\{b_{n_k}\}$: $d(b_{n_1},a)>d(b_{n_2},a)>...$ which is monotonic decreasing. Then note that $d(b_{n_k},a)<d(b_{n_1},a)<\infty$. So it's a bounded sequence. Now I want to show that it has a convergent subsequence that converges to $b\in B$ and then I want to do the same for $A$. And then finally to show that $d(a,b)=m$ in fact. Any clues to how to get there?

• @JonasMeyer. The argument given in your link uses the fact that closed balls are compact Feb 14, 2012 at 4:15
• @azarel: Thanks, I had only supeficially looked at it. Emir: Sorry about the hasty close vote. Feb 14, 2012 at 4:18
• This is not true as stated. Let $X = \{0\} \cup (1,2)$ with the Euclidean metric, $A = \{0\}$, $B=(1,2)$. $A$ is compact and $B$ is closed (in $X$!) but $d(A,B) = 1$ is not equal to $d(a,b)$ for any $a \in A$, $b \in B$. Are there more assumptions you've missed? Feb 14, 2012 at 4:18
• Here is a counterexample in a complete connected space. If $(e_n)$ is an orthonormal sequence in an infinite dimensional Hilbert space, $A=\{0\}$, and $B=\{(1+1/n)e_n\}$, then $B$ is closed, $A$ is compact, $d(A,B)=1$, but $d(a,b)>1$ for all $a\in A$ and $b\in B$. Feb 14, 2012 at 4:24
• does the proof apply if B is not compact but closed only?
– user54200
Dec 25, 2012 at 14:19

## 2 Answers

If one of the sets is just closed you're plenty of counterexamples to your statement. See the comments. If both sets are compact, we can use something similar to your arguments to prove the result. Just with a bit of careful.

So, consider $X$ a metric space and $A$, $B$ compact subsets of $X$. There exist sequences $\{a_n\}$ in $A$ and $\{b_n\}$ in $B$, such that $$\lim_{n\to\infty}d(a_n,b_n)=d(A,B).$$ In metric spaces the notion of compactness is equivalent to sequential compactness. Then, since $A$ is compact, there is a subsequence $\{a_{n_k}\}$ such that $$\lim_{k\to\infty} a_{n_k}=a\quad\text{ with }\quad a\in A.$$ Note that $$\lim_{k\to\infty} d(a_{n_k},b_{n_k})=d(A,B).$$ Since $B$ is compact, there is a subsequence $\{b_{n_{k_j}}\}$, such that $$\lim_{j\to\infty} b_{n_{k_j}}=b\quad\text{ with }\quad b\in B.$$ Note that $$\lim_{j\to\infty} d(a_{n_{k_j}},b_{n_{k_j}})=d(A,B),$$ but, since $d$ is a continuous function$^*$, the above equality says $$d(a,b)=d(A,B)\quad\text{ with }\quad a\in A,\, b\in B.$$

$^*$ Indeed, consider $d:A\times B\to \mathbb{R}$. By considering the metric $D((a_1,b_1),(a_2,b_2))=d(a_1,a_2)+d(b_1,b_2)$ (just as we needed) in $A\times B$ and the usual metric in $\mathbb{R}$, you can see that $d$ is continuous.

As was pointed out in the comments, you can see that $A\times B$ is compact in $X\times X$ with the metric given above. Since $d$ is continuous in the compact $A\times B$, $d$ attains its extremums. That gives you the desired result.

• Or you could compactify all of this (pun intended) by noting that $A\times B$ is compact (for obvious reasons) and then note that you're secretly just invoking the Extreme value theorem. Feb 14, 2012 at 8:06
• I was trying to argue like the OP in his post. However I haven't noted that. Thanks for point that out @AlexYoucis.
– leo
Feb 14, 2012 at 16:17

I assume that $A$ and $B$ are compact subspaces. As it was was proved here the function $d(\cdot,B):A\to \mathbb{R}_+:a\mapsto\inf\{d(a,b):b\in B\}$ is continuous. But it is defined on the compact space $A$, hence there exist $a_0\in A$ such that $$d(a_0,B)=\inf\{d(a,B):a\in B\}=d(A,B)$$ Similarly the function $d(\{a_0\},\cdot):B\to\mathbb{R}_+:b\mapsto\inf\{d(a_0,b):b\in B\}$ is continuous function on the compact metric space $B$, hence there exist $b_0\in B$ such that $$d(\{a_0\},b_0)=\inf\{d(\{a_0\},b):b\in B\}$$ What is equivalent to $$d(a_0,b_0)=d(a_0,B)=d(A,B)$$ for some $a_0\in A$ and $b_0\in B$.

• I think what Alex had in mind is that $d : A \times B \to \mathbb{R}_+$ is a continuous function on a compact set. Feb 14, 2012 at 15:14
• So I can say that this is my idea :) Feb 14, 2012 at 15:17
• Isnt the second function you define just a constant function Nov 22, 2016 at 8:16