Prove that $d(A,B)=d(x,y).$ Problem: Define the distance between two subsets $A$ and $B$ of a metric space $X$ by
\begin{equation*}
d(A,B)=\inf\{d(a,b):a\in A,b\in B\}.
\end{equation*}
Prove that if $A$ and $B$ are compact, then there exist $x\in A$ and $y\in B$ such that
\begin{equation*}
d(x,y)=d(A,B).
\end{equation*}
** I know there's something missing in this proof because I can't guarentee that my $x\in A, y\in B$ will cover all the possible point in the set. We're currently using Baby Rudin as our textbook and haven't finished the chapter on series and sequences yet. I would appreciate any feedback.
My work:
Given $A$ and $B$ are compact, choose a sequence $\{a_n\}_n \in A, \{b_n\}_n\in B.$ Then by thrm 3.6(a), there exists a subsequence $a_{n_\ell}\to x\in A, b_{n_\ell}\to y\in B.$ This means for all $\varepsilon >0,$ there exists a $N\in \mathbb{N}$ s.t. $d(a_{n_\ell}, x) <\varepsilon$ for $\ell\geq N$. Similarly for all $\varepsilon >0,$ there exists $M\in \mathbb{N}$ s.t.  $d(b_{n_\ell}, y)<y$ for $\ell \geq M.$ Then choosing $\ell\geq \max\{N,M\},$ $$d(a_{n_\ell}, b_{n_\ell})\leq d(a_{n_\ell}, x)+d(b_{n_\ell},y)+d(x,y)$$
$$d(x,y)\leq d(a_{n_\ell}, x)+d(b_{n_\ell},y)+d(a_{n_\ell}, b_{n_\ell})$$
So together we have $|d(a_{n_\ell}, b_{n_\ell})-d(x,y)|\leq d(a_{n_\ell}, x)+d(b_{n_\ell},y)<2\varepsilon$ thus $\lim_{\ell\to \infty} d(a_{n_\ell}, b_{n_\ell})=d(x,y).$
Let $D:=\{d(a, b) \mid a\in A, b\in B\}$; need to show $\inf\{D\}=d(x,y).$ We have $d(x,y)\in D.$
By thrm 3.7 we have that all the limits of subsequences in a metric space form a closed set. i.e.  \begin{align*}
    \lim_{\ell \to \infty}d(a_{n_\ell},b_{n_\ell})&=d(x_1,y_1)\\
    \lim_{k \to \infty}d(a_{n_k},b_{n_k})&=d(x_2,y_2)\\
    &\vdots
\end{align*}
Then all the $d(x_i, y_i)$ form a closed set where $x_i\in A, y_i\in B$. All of theses $\{d(x_i,y_i)\mid i\in\mathbb{N} \} \subset \mathbb{R}$ and in particular, they form a closed subset of $\mathbb{R}$ so there is a minimum  element we call $d(x,y)$.
\begin{align*}
    d(A,B)&=\inf\{d(a, b) \mid a\in A, b\in B\}\\
    &=\inf\left\{\lim_{\ell \to \infty} d(a_{n_\ell},b_{n_\ell})=d(x,y) \mid  a_{n_\ell} \in A, y, b_{n_\ell} \in B\right\}.
\end{align*}
The infimum of a closes sets is an element that is in the set because every set contains all its limit points so $\inf\{D\}\in D.$
Reference:
Thrm 3.6(a) If $\{p_n\}$ is a sequence in a compact metric space $X$, then some subsequence of $\{p_n\}$ converges to a point of $X$.
Thrm 3.7 The subsequential limits of a sequence $\{p_n\}$ in a metric space $X$ from a closed subset of $X$.
 A: I'll be honest, I didn't read all of what you wrote, but you're overcomplicating it for yourself.
For every $n > 0$, there are $x_n \in A, y_n \in B$ such that $d(x_n, y_n) < d(A, B) + 1/n$.
Let $\{x_n\}$ and $\{y_n\}$ be the associated sequences in $A, B$. So by compactness both have convergent subsequences, and suppose that those convergent subsequences converge to some $x, y$ respectively. For convenience let $\{x_n\}$ and $\{y_n\}$ now refer to the subsequences that converge to $x,y$
.
Note that for any $\epsilon > 0$, there is some $N$ such that for $n \geq N$ for $d(x, x_n), d(y,y_n) < \epsilon /2$, which means thanks to the triangle inequality that $d(x, y) \leq d(x, x_n) + d(x_n, y_n) + d(y, y_n) \leq \epsilon + d(x_n, y_n)$.
Therefore for every $\epsilon > 0$ there is $N$ such that for all $n \geq N$, $d(x,y) \leq d(x_n, y_n) + \epsilon/2$. We also know by construction of the sequences that there is some $M$ such that for all $n \geq M$, $d(x_n, y_n) < d(A, B) + \epsilon/2$. So for $n \geq max (M, N)$, $d(x, y) \leq d(x_n, y_n) + \epsilon/2 \leq d(A, B) + \epsilon$.
So then $d(x, y) \leq d(A, B) + \epsilon$, and $\epsilon > 0$ was arbitrary. So $d(x, y) \leq d(A, B) \implies d(x,y) = d(A, B)$.
