Distance between compact sets in a metric space. 
Let $K_1$ and $K_2$ be two disjoint compact sets in a metric space $(X,d).$ Show that $$a = \inf_{x_1 \in K_1, x_2 \in K_2} d(x_1, x_2) > 0.$$
  Moreover, show that there are $x \in K_1$ and $y \in K_2$ such that $a = d(x,y)$.

For the first part, suppose to the contrary that $\inf d(x_1, x_2) = 0$. Then $\epsilon$ is not a lower bound, so $d(x_1, x_2) < \epsilon$ for all $\epsilon > 0$. Since $K_1$ and $K_2$ are compact subsets of a metric space, they are closed and bounded. So, then $B(x_1, \epsilon) \cap K_2 \neq \emptyset$. Thus, $x_1$ is an adherent point to $K_2$. Since $K_2$ is closed, this means $x_1 \in K_2$, a contradiction.
I'm stuck on the moreover part. I tried supposing to the contrary that $d(x,y) > a$, but I did not get far. 
 A: As hint, I will leave you with a result and its corollary. See if you can use the corollary to prove the "moreover" part of the question.

Theorem: Let $f$ be a continuous function mapping from a compact set $X$ to a topological space $Y$. The image $f(Y)$ is compact.
Corollary: Let $f$ be a continuous function mapping from a compact set $X$ to $\mathbb{R}$. $f(X)$ is a compact subset of $\mathbb{R}$,
  and hence there exists $x\in X$ such that $f(x) = \inf f(X)$.

It's also a good exercise to prove the theorem above. To do so, use the characterization that $f$ is continuous if and only if its inverse image $f^{-1}$ maps open sets to open sets.
A: By the definition of an infimum, you can find a sequence of pairs $((x_1^n,x_2^n))_{n \ge 1}$ in $K_1 \times K_2$ such that $d(x_1^n,x_2^n) \le a+\frac{1}{n}$ for each $n \ge 1$. Since we are in a metric space, you can use sequential compactness to take subsequences of each sequence and find respective limits $x_1 \in K_1$ and $x_2 \in K_2$. Using the triangle inequality, we have for any $\delta>0$,
$$d(x_1,x_2) \le d(x_1,x_1^n) + d(x_1^n,x_2^n) + d(x_2^n,x_2) \le \delta + a + \frac{1}{n} + \delta,$$
for all sufficiently large $n$. Thus $d(x_1,x_2)=a$.

Proving the "moreover" part allows you to prove the first part of the question immediately, since if $a=0$, then $x_1=x_2 \in K_1 \cap K_2$, a contradiction. By the way, I don't think your proof of the first part is correct.
A: We can prove this without using continuous mappings in compact sets. Let any $x \epsilon K_1$, and define $ D_x = \{\rho(x,y):y \epsilon K_2\} \subset \mathbb{R}$. Then $D_x$ is nonempty since $K_2$ is nonempty and disjoint from $K_1$, and it is bounded below by $0$. Hence its infimum exists, denote it by $d_x = \inf D_x$. Now for all $\varepsilon>0$, there exists some $y \epsilon K_2$ such that $\rho(x,y) < d_x + \varepsilon$, otherwise $d_x$ would not be the infimum of $D_x$. Then we can construct a sequence $\{y_n\}$ in $K_2$ such that $\rho(x,y_n) < d + 1/2^n$, for all $n \epsilon \mathbb{N}$. Since a metric space is Hausdorff and $\{y_n\}$ is an infinite subset of the compact $K_2$, it has a limit point in $K_2$. In other words, $b= \lim \limits_{n \to \infty}{y_n}$ exists and $b \epsilon K_2$. Hence $\rho(x,b)= \lim \limits_{n \to \infty}{\rho(x,y_n)} = d_x$, and $\rho(x,b) \le \rho(x,y)$, for all $y \epsilon K_2$. Denote this $\rho(x,b)$ by $\rho(x,K_2)$, the distance from $x$ to $K_2$.
In a similar was we can construct a sequence $\{x_n\}$ in $K_1$ such that $\rho(x_n,K_2) < d + 1/2^n$, for all $n \epsilon \mathbb{N}$. This sequence will converge to some $a \epsilon K_1$, and for that $a$ we will have $\rho(a,K_2) \le \rho(x,K_2)$, for all $x \epsilon K_1$. Denote this $\rho(a,K_2)$ by $\rho(K_1,K_2)$, the distance from $K_1$ to $K_2$.
