MATH-341 · Lesson 7 of 12 · 23 min

Metric spaces: examples and open and closed sets

Lessons 2 to 6 measured the distance between functions by \(\sup |f - g|\). Real Analysis I measured the distance between numbers by \(|x - y|\), and in several variables we measure the distance between points of \(\mathbb{R}^n\) by the length of the segment joining them. The definitions of convergence, Cauchy sequence and continuity look the same in all three settings, and so do many proofs. A metric space is the common framework: a set with a distance function satisfying three axioms, and nothing else. Theorems proved once for metric spaces hold in every example at once.

The definition

Definition. A metric on a set \(X\) is a function \(d: X \times X \to \mathbb{R}\) such that for all \(x, y, z \in X\):

  • (M1) \(d(x, y) \ge 0\), and \(d(x, y) = 0\) if and only if \(x = y\);
  • (M2) \(d(x, y) = d(y, x)\) (symmetry);
  • (M3) \(d(x, z) \le d(x, y) + d(y, z)\) (the triangle inequality).

A metric space is a pair \((X, d)\). Its elements are called points, whatever they actually are: numbers, vectors, functions or something else entirely.

Maurice Fréchet introduced the idea in his doctoral thesis of 1906, Sur quelques points du calcul fonctionnel, under the name 'classes (E)', motivated precisely by spaces of functions. Felix Hausdorff's book Grundzüge der Mengenlehre of 1914 gave the axioms their modern form and the name metric space, and went further to define topological spaces, which are the subject of MATH-447.

A useful consequence of the axioms is the reverse triangle inequality \(|d(x, z) - d(y, z)| \le d(x, y)\). It follows from (M3) applied twice: \(d(x, z) \le d(x, y) + d(y, z)\) and \(d(y, z) \le d(y, x) + d(x, z)\).

Examples

  • The real line with \(d(x, y) = |x - y|\).
  • \(\mathbb{R}^n\) with any of three standard metrics. For \(x = (x_1, \dots, x_n)\) and \(y = (y_1, \dots, y_n)\): the Euclidean metric \(d_2(x, y) = \sqrt{\sum_i (x_i - y_i)^2}\); the taxicab metric \(d_1(x, y) = \sum_i |x_i - y_i|\), the distance traveled along a grid of streets; and the sup metric \(d_\infty(x, y) = \max_i |x_i - y_i|\).
  • The discrete metric on any set: \(d(x, y) = 1\) if \(x \ne y\) and 0 if \(x = y\).
  • The space \(C[a, b]\) of continuous functions on \([a, b]\) with the sup metric \(d_\infty(f, g) = \max_{x \in [a, b]} |f(x) - g(x)|\), the maximum existing by the extreme value theorem. Convergence in this metric is uniform convergence.
  • \(C[a, b]\) with the integral metric \(d_1(f, g) = \int_a^b |f(x) - g(x)|\,dx\), the area between the graphs.
  • Any subset \(Y\) of a metric space \(X\), with the restriction of \(d\). For example, \([0, 1]\), \(\mathbb{Q}\) and the unit circle are metric spaces with the distances they inherit from \(\mathbb{R}\) or \(\mathbb{R}^2\).

For most of these the axioms (M1) and (M2) are immediate, and only the triangle inequality needs thought. For \(d_1\) and \(d_\infty\) on \(\mathbb{R}^n\) it follows coordinate by coordinate from the triangle inequality for real numbers. For the sup metric on \(C[a, b]\), \(|f(x) - h(x)| \le |f(x) - g(x)| + |g(x) - h(x)| \le d_\infty(f, g) + d_\infty(g, h)\) for every \(x\), and taking the maximum over \(x\) gives (M3). In (M1) for the integral metric, \(d_1(f, g) = 0\) forces \(f = g\) because the functions are continuous: a continuous nonnegative function with integral 0 vanishes, as shown in lesson 6. On the larger set of Riemann integrable functions the same formula fails (M1), since changing a function at one point does not change its integral.

The Euclidean triangle inequality is the one that needs a real argument, and it rests on the Cauchy–Schwarz inequality.

Theorem 7.1 (Cauchy–Schwarz). For \(a, b \in \mathbb{R}^n\), \(\big|\sum_i a_ib_i\big| \le \sqrt{\sum_i a_i^2}\,\sqrt{\sum_i b_i^2}\).

Proof. If \(b = 0\) both sides are 0. Otherwise, for every real \(t\), \[0 \le \sum_i (a_i - tb_i)^2 = \sum_i a_i^2 - 2t\sum_i a_ib_i + t^2\sum_i b_i^2.\] A quadratic in \(t\) with positive leading coefficient that is never negative has discriminant at most 0, so \(4(\sum a_ib_i)^2 - 4\sum a_i^2\sum b_i^2 \le 0\). \(\square\)

Corollary 7.2. \(d_2\) satisfies the triangle inequality. Proof. Write \(\|v\| = \sqrt{\sum v_i^2}\). For \(u, v \in \mathbb{R}^n\), \(\|u + v\|^2 = \|u\|^2 + 2\sum u_iv_i + \|v\|^2 \le \|u\|^2 + 2\|u\|\|v\| + \|v\|^2 = (\|u\| + \|v\|)^2\) by Cauchy–Schwarz, so \(\|u + v\| \le \|u\| + \|v\|\). With \(u = x - y\) and \(v = y - z\) this is \(d_2(x, z) \le d_2(x, y) + d_2(y, z)\). \(\square\)

Open balls

Definition. In a metric space \((X, d)\), the open ball with center \(a\) and radius \(r > 0\) is \(B(a, r) = \{x \in X : d(x, a) < r\}\), and the closed ball is \(\overline{B}(a, r) = \{x \in X : d(x, a) \le r\}\).

Balls can look very different in different metrics. In \(\mathbb{R}\) they are open intervals. In \(\mathbb{R}^2\) the Euclidean unit ball is a disc, the taxicab unit ball is a square standing on a corner, a diamond with vertices \((\pm 1, 0)\) and \((0, \pm 1)\), and the sup-metric unit ball is the square \((-1, 1) \times (-1, 1)\). In the discrete metric, \(B(a, r) = \{a\}\) if \(r \le 1\) and the whole space if \(r > 1\). In \(C[0, 1]\) with the sup metric, \(B(f, r)\) is the set of continuous functions whose graphs lie strictly inside the band of half-width \(r\) around the graph of \(f\), the band of lesson 2.

Three unit balls centered at the origin of the plane drawn on the same axes: a diamond for the taxicab metric, inside a disc for the Euclidean metric, inside a square for the sup metric. The diamond touches the disc at the four axis points, and the disc touches the square at the same four points.
Unit balls in the plane for the taxicab, Euclidean and sup metrics: each ball contains the one before

The pictures are nested because for every \(x, y \in \mathbb{R}^n\), \[d_\infty(x, y) \le d_2(x, y) \le d_1(x, y) \le n\,d_\infty(x, y).\] The first inequality holds because the largest \(|x_i - y_i|\) is one of the terms under the square root; the second because \((\sum |v_i|)^2 = \sum v_i^2 + \sum_{i \ne j} |v_i||v_j| \ge \sum v_i^2\); the third because each of the \(n\) terms of \(d_1\) is at most \(d_\infty\). Small distance in one metric therefore means small distance in the others, and as we will see, the three metrics have the same open sets.

Areas and inclusions of unit balls in three metrics
import math

d1 = lambda p: abs(p[0]) + abs(p[1])
d2 = lambda p: math.hypot(p[0], p[1])
dinf = lambda p: max(abs(p[0]), abs(p[1]))

# area of each unit ball in the plane by counting points of a fine grid in [-1, 1]^2
m = 1000
h = 2 / m
counts = [0, 0, 0]
ok = True
for i in range(m):
    for j in range(m):
        p = (-1 + (i + 0.5) * h, -1 + (j + 0.5) * h)
        a, b, c = d1(p) < 1, d2(p) < 1, dinf(p) < 1
        counts[0] += a; counts[1] += b; counts[2] += c
        if a and not b or b and not c:   # inclusion B1 inside B2 inside Binf
            ok = False
for name, cnt, exact in zip(["taxicab", "Euclidean", "sup"], counts, [2, math.pi, 4]):
    print(f"{name:<10} unit ball area about {cnt * h * h:.4f}   exact {exact:.4f}")
print("B1 inside B2 inside Binf at every grid point:", ok)

# the inequalities d_inf <= d_2 <= d_1 <= n d_inf on random-looking points of R^5
pts = [[math.sin(7 * k + i) * (1 + k % 3) for i in range(5)] for k in range(1000)]
worst = 0.0
for p in pts:
    a, b, c = max(abs(t) for t in p), math.sqrt(sum(t * t for t in p)), sum(abs(t) for t in p)
    assert a <= b <= c <= 5 * a + 1e-12
    worst = max(worst, c / a)
print("largest d_1/d_inf seen in R^5:", round(worst, 3), "(never above 5)")
Output
taxicab    unit ball area about 1.9970   exact 2.0000
Euclidean  unit ball area about 3.1418   exact 3.1416
sup        unit ball area about 4.0000   exact 4.0000
B1 inside B2 inside Binf at every grid point: True
largest d_1/d_inf seen in R^5: 3.851 (never above 5)

The areas come out close to 2, \(\pi\) and 4, and every grid point in the taxicab ball is in the Euclidean ball, and every point in that is in the sup ball. The ratio \(\frac{d_1}{d_\infty}\) reaches its largest possible value \(n\) only when all coordinates of \(x - y\) have the same absolute value, which none of the sample points does, so the largest ratio seen is below 5.

Open sets

Definition. A set \(U \subseteq X\) is open if for every \(x \in U\) there is an \(r > 0\) with \(B(x, r) \subseteq U\). In words, every point of \(U\) has a ball around it that stays inside \(U\).

Theorem 7.3. Every open ball is an open set.

Proof. Let \(x \in B(a, r)\) and put \(s = r - d(x, a) > 0\). If \(y \in B(x, s)\), then by the triangle inequality \(d(y, a) \le d(y, x) + d(x, a) < s + d(x, a) = r\), so \(y \in B(a, r)\). Thus \(B(x, s) \subseteq B(a, r)\). \(\square\)

Theorem 7.4. (a) \(\varnothing\) and \(X\) are open. (b) Any union of open sets is open. (c) The intersection of finitely many open sets is open.

Proof. (a) is immediate: \(\varnothing\) has no points to check, and every ball lies in \(X\). (b) If \(x\) lies in the union of the sets \(U_\alpha\), it lies in some \(U_\alpha\), which contains a ball around \(x\), and that ball lies in the union. (c) If \(x \in U_1 \cap \dots \cap U_k\), choose \(r_i > 0\) with \(B(x, r_i) \subseteq U_i\) and let \(r = \min(r_1, \dots, r_k) > 0\). Then \(B(x, r)\) lies in every \(U_i\). \(\square\)

Infinite intersections of open sets need not be open: in \(\mathbb{R}\), \(\bigcap_{n \ge 1} (-\frac{1}{n}, \frac{1}{n}) = \{0\}\). The proof of (c) breaks because the minimum of infinitely many positive radii may be 0.

Whether a set is open depends on the metric and on the ambient space. In the discrete metric every set is open, since \(B(x, \frac{1}{2}) = \{x\}\). The interval \([0, 1)\) is not open in \(\mathbb{R}\), but it is open as a subset of the metric space \([0, 1]\): the ball \(B(0, \frac{1}{2})\) in \([0, 1]\) is \([0, \frac{1}{2})\).

Theorem 7.5. Two metrics \(d\) and \(d^\prime\) on \(X\) with \(c\,d \le d^\prime \le C\,d\) for constants \(0 < c \le C\) have the same open sets.

Proof. The inequalities give \(B_{d^\prime}(x, cr) \subseteq B_d(x, r)\) and \(B_d(x, \frac{r}{C}) \subseteq B_{d^\prime}(x, r)\). So every \(d\)-ball around \(x\) contains a \(d^\prime\)-ball around \(x\), and conversely, and the definition of open set gives the same sets for both metrics. \(\square\)

By the chain of inequalities above, \(d_1\), \(d_2\) and \(d_\infty\) on \(\mathbb{R}^n\) have the same open sets, the same convergent sequences and the same continuous functions. In contrast, the sup and integral metrics on \(C[0, 1]\) do not: the functions \(f_n(x) = x^n\) satisfy \(d_1(f_n, 0) = \frac{1}{n + 1} \to 0\) while \(d_\infty(f_n, 0) = 1\). Infinite-dimensional spaces are where the choice of metric really matters.

Closed sets, closure and limit points

Definition. A sequence \((x_n)\) in \(X\) converges to \(x\) if \(d(x_n, x) \to 0\). A set \(F \subseteq X\) is closed if its complement \(X \setminus F\) is open.

Limits are unique, by the same argument as in \(\mathbb{R}\): if \(x_n \to x\) and \(x_n \to y\) then \(d(x, y) \le d(x, x_n) + d(x_n, y) \to 0\).

Theorem 7.6. \(F\) is closed if and only if it contains the limit of every convergent sequence of points of \(F\).

Proof. Suppose \(F\) is closed, \(x_n \in F\) and \(x_n \to x\). If \(x \notin F\), the open set \(X \setminus F\) contains a ball \(B(x, r)\), and for large \(n\), \(d(x_n, x) < r\), so \(x_n \notin F\), a contradiction. Conversely, suppose \(F\) contains the limits of its convergent sequences, and let \(x \notin F\). If no ball around \(x\) lay in \(X \setminus F\), then for each \(n\) there would be \(x_n \in F \cap B(x, \frac{1}{n})\), giving a sequence in \(F\) converging to \(x \notin F\). So some ball around \(x\) misses \(F\), and \(X \setminus F\) is open. \(\square\)

By taking complements in theorem 7.4, \(\varnothing\) and \(X\) are closed, finite unions of closed sets are closed, and arbitrary intersections of closed sets are closed. Closed balls are closed, and finite sets are closed. 'Closed' is not the opposite of 'open': in \(\mathbb{R}\), \([0, 1)\) is neither, and \(\mathbb{R}\) itself is both.

Definition. A point \(x\) is a limit point of \(A\) if every ball around \(x\) contains a point of \(A\) other than \(x\). The closure \(\overline{A}\) is \(A\) together with its limit points; equivalently, the set of limits of convergent sequences in \(A\). The interior of \(A\) is the set of points of \(A\) that have a ball around them inside \(A\).

The closure is the smallest closed set containing \(A\), and the interior the largest open set inside \(A\). In \(\mathbb{R}\), \(\overline{\mathbb{Q}} = \mathbb{R}\) and the interior of \(\mathbb{Q}\) is empty. In \(C[a, b]\) with the sup metric, the Weierstrass theorem of lesson 6 says exactly that the closure of the set of polynomials is the whole space.

Worked problem

An open set in C[0, 1]

In \(C[0, 1]\) with the sup metric, show that \(U = \{f : f(x) > 0 \text{ for all } x\}\) is open, and that \(V = \{f : f(0) = 0\}\) is closed.

Show solution
  1. Let \(f \in U\). By the extreme value theorem \(f\) attains a minimum \(m = f(c) > 0\). If \(d_\infty(g, f) < m\), then \(g(x) > f(x) - m \ge 0\) for every \(x\), so \(g \in U\). Thus \(B(f, m) \subseteq U\), and \(U\) is open.
  2. For \(V\), use theorem 7.6. If \(f_n \in V\) and \(f_n \to f\) in the sup metric, then \(|f(0)| = |f(0) - f_n(0)| \le d_\infty(f, f_n) \to 0\), so \(f(0) = 0\) and \(f \in V\).
  3. In the integral metric \(d_1\), \(V\) is not closed. The functions \(g_n(x) = \min(1, nx)\) lie in \(V\), and \(d_1(g_n, 1) = \int_0^{1/n} (1 - nx)\,dx = \frac{1}{2n} \to 0\), so \(g_n\) converges to the constant function 1, which is not in \(V\).

Answer: \(U\) is open and \(V\) is closed in the sup metric. In the integral metric \(V\) is not closed, another sign that the two metrics differ.

Common mistakes

  • MistakeThinking a set that is not open must be closed.

    Instead\([0, 1)\) is neither open nor closed in \(\mathbb{R}\); \(\mathbb{R}\) and \(\varnothing\) are both.

  • MistakeBelieving infinite intersections of open sets are open.

    Instead\(\bigcap (-\frac{1}{n}, \frac{1}{n}) = \{0\}\).

  • MistakeForgetting that openness depends on the ambient space.

    Instead\([0, \frac{1}{2})\) is open in \([0, 1]\) but not in \(\mathbb{R}\).

  • MistakeAssuming all metrics on a space give the same open sets.

    InsteadTrue for \(d_1, d_2, d_\infty\) on \(\mathbb{R}^n\), false for the sup and integral metrics on \(C[0, 1]\).

Summary and key terms

  • A metric satisfies positivity, symmetry and the triangle inequality; Fréchet introduced metric spaces in 1906.
  • Examples: \(\mathbb{R}^n\) with \(d_1, d_2, d_\infty\), the discrete metric, \(C[a, b]\) with the sup and integral metrics.
  • The Euclidean triangle inequality follows from Cauchy–Schwarz.
  • Open balls are open; unions and finite intersections of open sets are open.
  • A set is closed if and only if it contains the limits of its convergent sequences.
  • Metrics with \(c\,d \le d^\prime \le C\,d\) have the same open sets, so \(d_1, d_2, d_\infty\) agree on which sets are open.
Metric space
A set with a distance satisfying positivity, symmetry and the triangle inequality.
Open ball
\(B(a, r) = \{x : d(x, a) < r\}\).
Open set
Every point has a ball around it inside the set.
Closed set
A set whose complement is open.
Closure
The set together with its limit points.
Equivalent metrics
Metrics bounded by constant multiples of each other.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Show that \(d(x, y) = \frac{|x - y|}{1 + |x - y|}\) is a metric on \(\mathbb{R}\).

    Show answer

    (M1) and (M2) are clear. The function \(\phi(t) = \frac{t}{1 + t}\) is increasing and satisfies \(\phi(s + t) \le \phi(s) + \phi(t)\) for \(s, t \ge 0\), so \(d(x, z) \le \phi(|x - y| + |y - z|) \le d(x, y) + d(y, z)\).

  2. Describe the unit ball \(B(0, 1)\) in \(C[0, 1]\) with the sup metric, and decide whether \(\sin(2\pi x)\) belongs to it.

    Show answer

    It is the set of continuous \(f\) with \(|f(x)| < 1\) for all \(x\), the maximum of \(|f|\) being less than 1. \(\sin(2\pi x)\) reaches 1 at \(x = \frac{1}{4}\), so it is not in the open ball.

  3. Is \(\{(x, y) : x > 0, y > 0\}\) open in \(\mathbb{R}^2\)?

    Show answer

    Yes. Around \((x, y)\) the ball of radius \(\min(x, y)\) in \(d_\infty\) lies in the set, and \(d_\infty\) has the same open sets as \(d_2\).

  4. Find the closure and interior of \(\{\frac{1}{n} : n \ge 1\}\) in \(\mathbb{R}\).

    Show answer

    The closure adds the limit point 0. The interior is empty, since every interval around \(\frac{1}{n}\) contains points not of the form \(\frac{1}{m}\).

  5. In the discrete metric, which sequences converge?

    Show answer

    Exactly the eventually constant ones: \(d(x_n, x) < \frac{1}{2}\) forces \(x_n = x\).

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz