MathLabs

Topology

Metric spaces

A metric space equips a set with a distance function satisfying three axioms; contraction mappings on complete metric spaces always have a unique fixed point (Banach's theorem), the engine behind PageRank, iterative solvers, and fractal image compression.

IntuitionMeasuring distance without a ruler

GPS uses straight-line distance, a taxi driver uses street-grid distance, and a spell-checker uses "edit distance" between words. All three are legitimate notions of distance because they share the same three common-sense rules: distance is never negative and is zero only when two points coincide, distance from AA to BB equals distance from BB to AA, and going via a detour CC never shortens the direct trip from AA to BB. A metric space is exactly a set equipped with any distance function obeying these three rules.

Plot of the line T(x) = 0.5x + 1 crossing the diagonal y = x at the fixed point x = 2, illustrating contraction mapping iteration.
The map T(x)=0.5x+1T(x) = 0.5x + 1 on R\mathbb{R} (with d(x,y)=∣x−y∣d(x,y)=|x-y|) is a contraction with ratio q=0.5q=0.5: it always halves the distance between any two points. Adjust the sliders and watch that every starting point iterates toward the same fixed point x∗=2x^* = 2.

UndergraduateThe three axioms

Definition: Metric space

A metric on a set XX is a function d:X×X→Rd: X \times X \to \mathbb{R} satisfying, for all x,y,z∈Xx,y,z \in X: (M1) positivity d(x,y)≥0, d(x,y)=0  ⟺  x=yd(x,y) \ge 0,\ d(x,y)=0 \iff x=y; (M2) symmetry d(x,y)=d(y,x)d(x,y) = d(y,x); (M3) the triangle inequality d(x,z)≤d(x,y)+d(y,z)d(x,z) \le d(x,y) + d(y,z). The pair (X,d)(X,d) is a metric space.

d(x,y)≥0,d(x,y)=0  ⟺  x=yd(x,y)=d(y,x)d(x,z)≤d(x,y)+d(y,z)d(x,y) \ge 0,\quad d(x,y)=0 \iff x=y \qquad d(x,y)=d(y,x) \qquad d(x,z) \le d(x,y)+d(y,z)

Two families of examples matter most. On Rn\mathbb{R}^n, the **ℓp\ell_p metrics** are dp(x,y)=(∑i=1n∣xi−yi∣p)1/pd_p(x,y) = \left(\sum_{i=1}^n |x_i - y_i|^p\right)^{1/p} for p≥1p \ge 1 (so p=2p=2 gives ordinary Euclidean distance, p=1p=1 gives "taxicab" distance, and p→∞p\to\infty gives the maximum coordinate difference). On the space C([a,b])C([a,b]) of continuous functions, the sup-metric is d∞(f,g)=sup⁡t∈[a,b]∣f(t)−g(t)∣d_\infty(f,g) = \sup_{t \in [a,b]} |f(t) - g(t)|: two functions are close if their graphs never separate by more than a small margin anywhere on [a,b][a,b].

dp(x,y)=(∑i=1n∣xi−yi∣p)1/pd∞(f,g)=sup⁡t∈[a,b]∣f(t)−g(t)∣d_p(x,y) = \left(\sum_{i=1}^n |x_i - y_i|^p\right)^{1/p} \qquad d_\infty(f,g) = \sup_{t \in [a,b]} |f(t) - g(t)|
Metrics on Rn\mathbb{R}^n compared
MetricFormulaUnit ball shapeTypical use
ℓ1\ell_1 (taxicab)∑∣xi−yi∣\sum |x_i-y_i|diamondsparse recovery, city blocks
ℓ2\ell_2 (Euclidean)∑(xi−yi)2\sqrt{\sum (x_i-y_i)^2}diskphysical distance, PCA
ℓ∞\ell_\infty (Chebyshev)max⁡i∣xi−yi∣\max_i |x_i-y_i|squareworst-case error bound

UndergraduateBalls, completeness, and contractions

The open ball B(x0,r)={x∈X:d(x,x0)<r}B(x_0, r) = \{x \in X : d(x, x_0) < r\} is the set of points within distance rr of the center. A sequence (xn)(x_n) is Cauchy if ∀ε>0 ∃N ∀m,n>N: d(xm,xn)<ε\forall \varepsilon > 0\ \exists N\ \forall m,n > N:\ d(x_m,x_n) < \varepsilon: its terms eventually get arbitrarily close to each other (not necessarily to any fixed limit point yet). A metric space is complete if every Cauchy sequence converges to a point of XX. Rn\mathbb{R}^n with any ℓp\ell_p metric is complete; Q\mathbb{Q} with d(x,y)=∣x−y∣d(x,y)=|x-y| is not, since 2\sqrt{2} is missing.

UndergraduateTheorems

For all x,y,zx,y,z in a metric space, ∣d(x,z)−d(y,z)∣≤d(x,y)|d(x,z) - d(y,z)| \le d(x,y).

Why is it true?

It shows the distance function itself is Lipschitz-continuous (with constant 1) in each argument, which is what lets you take limits of distances safely.

Proof

Step 1 — Two applications of the triangle inequality. By (M3), d(x,z)≤d(x,y)+d(y,z)d(x,z) \le d(x,y) + d(y,z), which rearranges to d(x,z)−d(y,z)≤d(x,y)d(x,z) - d(y,z) \le d(x,y). Swapping the roles of xx and yy in the same axiom gives d(y,z)≤d(y,x)+d(x,z)=d(x,y)+d(x,z)d(y,z) \le d(y,x) + d(x,z) = d(x,y) + d(x,z) (using symmetry d(y,x)=d(x,y)d(y,x)=d(x,y)), which rearranges to d(y,z)−d(x,z)≤d(x,y)d(y,z) - d(x,z) \le d(x,y), i.e. −(d(x,z)−d(y,z))≤d(x,y)-(d(x,z)-d(y,z)) \le d(x,y).

Step 2 — Combine both bounds. The two inequalities say d(x,z)−d(y,z)≤d(x,y)d(x,z)-d(y,z) \le d(x,y) and −(d(x,z)−d(y,z))≤d(x,y)-(d(x,z)-d(y,z)) \le d(x,y) simultaneously, which is exactly the statement ∣d(x,z)−d(y,z)∣≤d(x,y)|d(x,z)-d(y,z)| \le d(x,y) by the definition of absolute value: a real number uu satisfies ∣u∣≤c|u| \le c precisely when both u≤cu \le c and −u≤c-u \le c hold.

Let (X,d)(X,d) be a complete metric space and T:X→XT: X \to X a contraction: d(T(x),T(y))≤q d(x,y)d(T(x), T(y)) \le q\, d(x,y) for some fixed 0≤q<10 \le q < 1 and all x,y∈Xx,y \in X. Then TT has exactly one fixed point x∗∈Xx^* \in X (i.e. T(x∗)=x∗T(x^*)=x^*), and starting from any x0∈Xx_0 \in X the iterates xn+1=T(xn)x_{n+1}=T(x_n) converge to x∗x^* with the explicit error bound d(xn,x∗)≤qn1−q d(x1,x0)d(x_n, x^*) \le \dfrac{q^n}{1-q}\, d(x_1, x_0).

Why is it true?

It converts existence-and-uniqueness questions (does this equation have exactly one solution?) into a mechanical, guaranteed-to-converge computation, with a precomputable bound on how many iterations are needed for any target accuracy.

Proof

Step 1 — The iterates form a Cauchy sequence. Fix x0∈Xx_0 \in X and set xn=Tn(x0)x_n = T^n(x_0). By the contraction property applied repeatedly, d(xn+1,xn)=d(T(xn),T(xn−1))≤q d(xn,xn−1)≤⋯≤qn d(x1,x0)d(x_{n+1},x_n) = d(T(x_n),T(x_{n-1})) \le q\,d(x_n,x_{n-1}) \le \dots \le q^n\,d(x_1,x_0). For m>nm > n, the triangle inequality chains this along the path xn,xn+1,…,xmx_n, x_{n+1}, \dots, x_m: d(xm,xn)≤∑k=nm−1d(xk+1,xk)≤∑k=nm−1qk d(x1,x0)≤d(x1,x0)∑k=n∞qk=d(x1,x0) qn1−qd(x_m,x_n) \le \sum_{k=n}^{m-1} d(x_{k+1},x_k) \le \sum_{k=n}^{m-1} q^k\,d(x_1,x_0) \le d(x_1,x_0)\sum_{k=n}^{\infty} q^k = d(x_1,x_0)\,\dfrac{q^n}{1-q}, using the geometric series formula since 0≤q<10 \le q < 1. As n→∞n \to \infty, qn→0q^n \to 0, so this tail bound goes to 0: (xn)(x_n) is Cauchy.

Step 2 — Completeness gives a limit, and continuity makes it a fixed point. Since XX is complete, the Cauchy sequence (xn)(x_n) converges to some x∗∈Xx^* \in X. The contraction inequality d(T(x),T(y))≤q d(x,y)d(T(x),T(y)) \le q\,d(x,y) shows TT is (Lipschitz) continuous, so T(x∗)=T(lim⁡nxn)=lim⁡nT(xn)=lim⁡nxn+1=x∗T(x^*) = T(\lim_n x_n) = \lim_n T(x_n) = \lim_n x_{n+1} = x^*. Thus x∗x^* is a fixed point.

Step 3 — Uniqueness. Suppose x∗x^* and y∗y^* are both fixed points. Then d(x∗,y∗)=d(T(x∗),T(y∗))≤q d(x∗,y∗)d(x^*,y^*) = d(T(x^*),T(y^*)) \le q\,d(x^*,y^*), so (1−q) d(x∗,y∗)≤0(1-q)\,d(x^*,y^*) \le 0. Since 1−q>01-q>0, this forces d(x∗,y∗)=0d(x^*,y^*)=0, i.e. x∗=y∗x^*=y^*.

Step 4 — The error bound. Letting m→∞m \to \infty in the Step 1 estimate d(xm,xn)≤qn1−q d(x1,x0)d(x_m,x_n) \le \dfrac{q^n}{1-q}\,d(x_1,x_0) and using continuity of dd gives exactly d(xn,x∗)≤qn1−q d(x1,x0)d(x_n,x^*) \le \dfrac{q^n}{1-q}\,d(x_1,x_0): the distance to the true fixed point after nn steps shrinks geometrically, and the bound can be computed before running a single iteration.

UndergraduateReal-World Applications and Worked Examples

Google's PageRank computes the dominant eigenvector of a web-link matrix by repeatedly applying it to a probability vector — this power iteration is a contraction in the ℓ1\ell_1 metric on probability distributions. Iterative linear solvers (Jacobi, Gauss–Seidel) rewrite Ax=bAx=b as a fixed-point map x↦Cx+dx \mapsto Cx+d that is a contraction in the sup-metric whenever AA is diagonally dominant. Fractal (IFS) image compression represents an image as the unique fixed point of a contraction on the space of images equipped with the sup/Hausdorff metric, so decompression is just iterating the map.

Example: PageRank as a contraction on probability vectors

A tiny 2-page web has link matrix M=(0.10.90.90.1)M = \begin{pmatrix} 0.1 & 0.9 \\ 0.9 & 0.1 \end{pmatrix} (each column redistributes rank with a damping factor). Starting from r0=(1,0)r_0 = (1,0), compute r1=Mr0r_1 = Mr_0 and r2=Mr1r_2 = Mr_1 using the ℓ1\ell_1 metric d(x,y)=∣x1−y1∣+∣x2−y2∣d(x,y)=|x_1-y_1|+|x_2-y_2|, and check d(r1,r2)≤q d(r0,r1)d(r_1,r_2) \le q\,d(r_0,r_1) for q=0.8q=0.8.

Solution

Step 1 — Compute r1r_1. r1=Mr0=(0.1⋅1+0.9⋅0, 0.9⋅1+0.1⋅0)=(0.1,0.9)r_1 = M r_0 = (0.1 \cdot 1 + 0.9 \cdot 0,\ 0.9 \cdot 1 + 0.1 \cdot 0) = (0.1, 0.9).

Step 2 — Compute r2r_2. r2=Mr1=(0.1(0.1)+0.9(0.9), 0.9(0.1)+0.1(0.9))=(0.01+0.81, 0.09+0.09)=(0.82,0.18)r_2 = M r_1 = (0.1(0.1)+0.9(0.9),\ 0.9(0.1)+0.1(0.9)) = (0.01+0.81,\ 0.09+0.09) = (0.82, 0.18).

Step 3 — Compute distances and check the contraction ratio. d(r0,r1)=∣1−0.1∣+∣0−0.9∣=0.9+0.9=1.8d(r_0,r_1) = |1-0.1|+|0-0.9| = 0.9+0.9=1.8. d(r1,r2)=∣0.1−0.82∣+∣0.9−0.18∣=0.72+0.72=1.44d(r_1,r_2)=|0.1-0.82|+|0.9-0.18|=0.72+0.72=1.44. Indeed 1.44=0.8×1.81.44 = 0.8 \times 1.8, matching q=0.8q=0.8 exactly (the row/column sums of MM shifted by 0.5 from the damping factor give this ratio), confirming the iteration contracts and will converge to the stationary rank vector (0.5,0.5)(0.5,0.5).

Example: How many iterations for a target compression accuracy?

A fractal image-compression decoder applies a contraction TT with ratio q=0.6q=0.6 on the sup-metric over images, and the first two iterates satisfy d(x1,x0)=100d(x_1,x_0)=100 (pixel-intensity units). Using the error bound d(xn,x∗)≤qn1−q d(x1,x0)d(x_n, x^*) \le \dfrac{q^n}{1-q}\, d(x_1, x_0), find the smallest nn guaranteeing d(xn,x∗)<1d(x_n,x^*) < 1.

Solution

Step 1 — Write the inequality to solve. We need qn1−q d(x1,x0)<1\dfrac{q^n}{1-q}\,d(x_1,x_0) < 1, i.e. 0.6n0.4×100<1\dfrac{0.6^n}{0.4} \times 100 < 1, i.e. 0.6n<0.0040.6^n < 0.004.

Step 2 — Take logarithms. nln⁡(0.6)<ln⁡(0.004)n \ln(0.6) < \ln(0.004). Since ln⁡(0.6)≈−0.5108\ln(0.6) \approx -0.5108 is negative, dividing flips the inequality: n>ln⁡(0.004)ln⁡(0.6)=−5.521−0.5108≈10.81n > \dfrac{\ln(0.004)}{\ln(0.6)} = \dfrac{-5.521}{-0.5108} \approx 10.81.

Step 3 — Round up to the smallest integer. n=11n = 11 iterations guarantee d(xn,x∗)<1d(x_n,x^*) < 1 pixel-intensity unit, and this number was known before running any iteration — exactly the practical value of the a priori error bound in compression codecs.

Which property FAILS for d(x,y)=(x−y)2d(x,y) = (x-y)^2 on R\mathbb{R}?

Using the ℓ2\ell_2 metric, what is d((1,2,2),(4,6,2))d((1,2,2),(4,6,2)) in R3\mathbb{R}^3?

An iterative solver has contraction ratio q=0.9q=0.9 instead of q=0.1q=0.1 for the same problem. What happens?

Which pair of conditions guarantees the Banach fixed-point theorem applies?

References

  1. Walter Rudin (1976). Principles of Mathematical Analysis
  2. James Munkres (2000). Topology
  3. Shaojie Bai, J. Zico Kolter, Vladlen Koltun (2019). Deep Equilibrium Models · arXiv:1909.01377