1. Continuity

Metric spaces allow us to generalize all of the key constructions and concepts we've encountered so far in the study of limits and continuity. The key idea is to replace quantities of the form \(|x-y|\) for real numbers \(x\) and \(y\) with the distance \(d(x,y)\) of points \(x,y\) in some metric space \((X,d)\). An example of this principle can be seen in the definition of limits and continuity of maps between metric spaces:
Definition
Given two metric spaces \((X,d_X)\) and \((Y,d_Y)\) and a map \(f \ : \ X \rightarrow Y\), we say that
\[ \lim_{x \rightarrow p} f(x) = y \]
for some given \(p \in X\) and \(y \in Y\) when for every \(\epsilon > 0\), there is some \(\delta > 0\) such that all \(x \in X\) with \(0 < d_X(x,p) < \delta\) satisfy \(d_Y(y,f(x)) < \epsilon\). We say that \(f\) is continuous at \(p\) when
\[ \lim_{x \rightarrow p} f(x) = f(p), \]
i.e., when the limit exists and equals \(f(p)\). As was the case on the real line, continuity is also equivalent to the statement that for all \(\epsilon > 0\), there is some \(\delta > 0\) such that \(d_X(x,p) < \delta\) implies \(d_Y(f(x),f(p)) < \epsilon\).
Example
Let \(X := {\mathbb{N}} \cup \{\infty\}\) with metric
\[ d_X(x,y) := \begin{cases} \left| \frac{1}{x} - \frac{1}{y} \right| & \text{ if } x,y \neq \infty, \\ \left| \frac{1}{x} \right| & x \neq \infty, y = \infty, \\ \left| \frac{1}{y} \right| & x = \infty, y \neq \infty, \\ 0 & x,y = \infty. \end{cases}\]
By putting \(X\) in bijection with the set \(\{0 \} \cup \{\frac{1}{n} \ : \ n \in \mathbb{N}\} \subset {\mathbb R}\) via the map \(n \mapsto n^{-1}, \infty \mapsto 0\), it's easy to check that \(d_X\) is indeed a metric. With this metric structure, the definition of the limit of a sequence, i.e.,
\[ \lim_{n \rightarrow \infty} a_n = L \]
coincides exactly with the metric space definition when \(a\) is regarded as a function on \(X\). Moreover, if we define \(f(n) := a_n\) for each natural number \(n\) and \(f(\infty) = L\), then \(f\) is continuous at \(\infty\) if and only if \(\lim_{n \rightarrow \infty} a_n = L\) in the usual sense.

To hint at the most general formulation of continuity (the purely topological one), we note that the relationship between continuity and openness persists in the metric space setting, just as was the case in the real numbers.
Proposition (Topological Characterization of Continuity)
If \(X\) and \(Y\) are metric spaces, then \(f \ : \ X \rightarrow Y\) is continuous at every point if and only if \(f^{-1}(O)\) is open for every open set \(O \subset Y\).
Proof
\([\Rightarrow]\) Let \(O \subset Y\) be open and let \(U := f^{-1}(O)\). Pick any point \(p \in U\). Since \(O\) is open, there is some \(\epsilon\) such that the \(\epsilon\)-ball centered at \(f(p)\) is contained in \(O\). Since \(f\) is continuous, there is some \(\delta > 0\), such that every point \(x' \in N_\delta(p)\) has \(f(x') \in N_\epsilon(f(p))\). Consequently \(f(x') \in O\), meaning that \(x' \in f^{-1}(O) = U\). It follows that \(N_\delta(p) \subset U\), and therefore \(U\) must be open.

\([\Leftarrow]\) Fix any \(p \in X\) and any \(\epsilon > 0\). Let \(O := N_\epsilon(f(p))\), i.e., the \(\epsilon\)-neighborhood of \(f(p)\). By assumption, \(f^{-1}(O)\) is open. Since \(p \in f^{-1}(O)\), there is some \(\delta\) such that \(N_\delta(p) \subset f^{-1}(O)\). Thus, if \(x \in X\) satisfies \(d_X(x,p) < \delta\), it follows that \(x \in f^{-1}(O)\), i.e., that \(f(x) \in O = N_\epsilon(f(p))\). In formulas, this means that \(d_Y(f(x),f(p)) < \epsilon\).
Corollary
If \(X\) is a discrete space (meaning that all sets are open), then every map \(f \ : \ X \rightarrow Y\) is continuous.
Corollary
If \(X\) is a discrete space, then \(f \ : \ \mathbb{R} \rightarrow X\) is continuous if and only if \(f\) is constant.
Proof
If \(f\) is constant, then \(f^{-1}(O)\) is either the empty set or \({\mathbb R}\) for every set \(O\), both of which are open. Conversely, if \(X\) is discrete and not constant, then there would be some point \(p \in X\) such that \(f^{-1}(\{p\})\) and \(f^{-1}(X \setminus \{p\})\) are both nonempty. Since all sets in \(X\) are open, both \(f^{-1}(\{p\})\) and \(f^{-1}(X \setminus \{p\})\) are open. However, they're also clearly disjoint and have union equal to all of \({\mathbb R}\), so this contradicts the fact that \({\mathbb R}\) is connected.

2. Compactness

Definition
We say that a metric space \((X,d)\) is compact when every open cover of \(X\) admits a finite subcover.

General compact metric spaces share many properties in common with compact subsets of the real line, but one must be a little bit careful not to overgeneralize.
Proposition
Suppose that \((X,d)\) is a compact metric space. Then
  1. The metric space is bounded. I.e., there exists a real number \(M\) such that \(d(x,y) < M\) for all \(x,y \in X\).
  2. Every compact subset \(E \subset X\) is closed in \(E\) (here compact subsets are ones which are compact with respect to the metric that \(E\) inherits from \(X\)).
  3. There exist metric spaces which are closed and bounded but not compact.
Proof
[1.] Fix any \(x \in X\) and consider the collection \(\{N_m(x)\}_{m=1}^\infty\) of neighborhoods of \(x\) for each \(m \in \mathbb{N}\). Each neighborhood is open, and every \(y \in X\) belongs to at least one such neighborhood, so \(\{N_m(x)\}_{m=1}^\infty\) is an open cover of \(X\). Since \(X\) has a finite subcover, \(X \subset N_{m_1}(x) \cup \cdots \cup N_{m_N}(x)\) for some natural numbers \(m_1,\ldots,m_N\). Because neighborhoods are nested, fixing \(m := \max\{m_1,\ldots,m_N\}\) gives that \(X \subset N_m(x)\). In other words, all points \(y\) have \(d(x,y) < m\). By the triangle inequality, \(d(y_1,y_2) \leq d(y_1,x) + d(x,y_2) < 2m\), so the first part of the proposition holds when \(M := 2m\).

[2.] Suppose \(E\) is not closed. There must be some point \(x \in E^c\) such that no neighborhood \(N_\delta(x)\) is entirely contained in \(E^c\). Let \(\mathcal U\) be the collection of all open sets (in \(X\)) of the form \(U_r := \{y \in X \ : \ d(x,y) > r\}\) for some \(r > 0\). Because the union of all \(U_r\) over all \(r > 0\) contains all points \(y\) for which \(d(x,y) \neq 0\), the collection \(\mathcal{U}\) is an open cover of \(X \setminus \{x\}\) and consequently an open cover of \(E\). Restricting each each \(U_r\) to \(E\) by intersecting \(E\) gives sets \(U_r \cap E\) which are open in \(E\) and cover \(E\). If there were a finite subcover, then one would have \(E = (U_{r_1} \cup \cdots \cup U_{r_N}) \cap E\); fixing \(r\) to be the minimum of \(r_1,\ldots,r_N\), it follows that \(E \subset U_r\). However, this would mean that the neighborhood \(N_r(x)\) does not intersect \(E\), contradicting the choice of \(E\).

[3.] Let \(X\) be any infinite set and consider the discrete metric: \(d(x,y) = 1\) if and only if \(x \neq y\). Every subset of \(X\) is vacuously closed and \(X\) is bounded, but \(X\) is not compact because we can cover \(X\) by singelton sets \(\{x\}\) as \(x\) ranges over all points of \(X\). This open cover cannot have a finite subcover because it would mean that \(X\) itself would have to be finite.
Proposition
Every closed subset of a compact metric space \((X,d)\) is itself compact.
Proof
We can follow the proof that we used on the real line: Let \(\mathcal U\) be an open cover of \(E \subset X\) with respect to the metric that \(E\) inherits from \(X\). We can write each \(U \in \mathcal U\) as an intersection \(E \cap U'\), where \(U'\) is an open set in the larger space \(X\): simply take \(U'\) to be the union of all neighborhoods \(N_\delta(x)\) in \(X\) such that a \(\delta\)-neighborhood of \(x\) in the set \(E\) is contained in \(U\), i.e., \(N_\delta(x) \cap E \subset U\). These new sets \(U'\) are open and cover \(E\). Now let \(\mathcal U'\) be the collection of all such \(U'\) and adjoin the open set \(X \setminus E\) to make \(\mathcal{U}'\) an open cover of \(X\). Since \(X\) is compact, it has a finite subcover. The subcover may or may not contain \(X \setminus E\), but when we select just the elements of the subcover which intersect \(E\), the set \(X \setminus E\) will not be among them, and consequently we have that \(E \subset U'_1 \cup \cdots \cup U'_n\) for appropriate \(U'_1,\ldots,U'_n\). Fixing \(U_i := U'_i \cap E\) gives that \(U_1,\ldots,U_n\) form a finite subcover of \(E\).
Exercise
  1. Adapt the proof of the Extreme Value Theorem to prove that every real-valued continuous function on a compact metric space is bounded and attains maximum and minimum values.

3. Completeness

Because the analogue of the Heine-Borel Theorem does not hold for general compact metric spaces, it is useful to parse concepts a little more finely than we did on the real line. To that end, we also introduce the notion of a complete metric space.
Definition
A sequence \(\{x_n\}_{n=1}^\infty\) in a metric space \((X,d)\) is called a Cauchy sequence when for all \(\epsilon > 0\), there is some \(N \in \mathbb{N}\) such that every \(n,m > N\) satisfy \(d(x_n,x_m) < \epsilon\). The space \((X,d)\) is called complete when every Cauchy sequence converges.

In the next sections, we will examine more closely the connection between compactness and completeness.
Exercises
  1. Prove that every convergent sequence in a metric space \((X,d)\) is necessarily a Cauchy sequence.
  2. Give an example of a metric space which is not complete (think about adding a hole to a simpler example).