Module contents
Lesson 5 of 20Core 110 min

Metric spaces, compactness and the Banach fixed-point theorem

Generalize convergence and continuity to metric spaces to reason simultaneously about ℝⁿ, function spaces and policy spaces. Covers topology of ℝⁿ, compactness and its consequences (extreme values and uniform continuity), completeness and Banach's fixed-point theorem, which later proves the inverse function and Picard–Lindelöf theorems and explains value iteration convergence.

After this lesson you can

  • Verify metric and norm axioms and compare metrics induced by ℓ1, ℓ2 and ℓ∞.
  • Characterize open, closed and compact sets in ℝⁿ (Heine–Borel) and explain why the characterization fails in infinite dimensions.
  • Prove the extreme value and Heine–Cantor theorems.
  • Prove Banach's fixed-point theorem with a priori and a posteriori error bounds.
  • Implement fixed-point iterations with an error certificate and detect when a map is not contractive in the chosen norm.

Before you start

Motivation: iterate until it stops changing

Four problems that look nothing alike:

  • Kepler. A planet’s position in its elliptical orbit at time tt requires solving E−esin⁡E=ME - e\sin E = M, where MM is proportional to tt and e∈[0,1)e \in [0, 1) is eccentricity. There is no closed formula for EE. The simplest approach iterates E←M+esin⁡EE \leftarrow M + e\sin E.
  • Square roots. The Babylonian method calculates 2\sqrt 2 by iterating x←x/2+1/xx \leftarrow x/2 + 1/x. After four steps from x0=1x_0 = 1 it has eleven correct decimal places.
  • Value iteration. In a Markov decision process, optimal value function V∗V^* satisfies Bellman equation V=TVV = TV, where (TV)(s)=max⁡a[R(s,a)+γ∑s′P(s′∣s,a) V(s′)](TV)(s) = \max_a \big[R(s, a) + \gamma\sum_{s'} P(s' \given s, a)\,V(s')\big]. The solving algorithm, foundational to dynamic programming and much of reinforcement learning, iterates V←TVV \leftarrow TV.
  • Differential equations. The solution of y′=f(t,y)y' = f(t, y), y(0)=y0y(0) = y_0, is the function satisfying y(t)=y0+∫0tf(s,y(s)) ⁣dsy(t) = y_0 + \int_0^t f(s, y(s)) \dd s. Picard proposed iterating that equality: the unknown is no longer a number or vector, but an entire function.

All four are the same problem: find a fixed point, an xx with x=g(x)x = g(x), in a set that is R\R, Rn\R^n, the space of functions on states or a space of continuous functions. All four use the same algorithm, iterating xk+1=g(xk)x_{k+1} = g(x_k). The questions are also the same: does a fixed point exist, is it unique, does iteration converge from any starting point, how fast, and when can I stop knowing my error?

Banach’s fixed-point theorem answers all five with one assumption: gg brings points closer by a fixed factor q<1q < 1, in a space without holes. To state it once for all cases requires talking about distances without specifying the objects. That is a metric space. Along the way appears the other great existence argument in analysis, compactness, guaranteeing a continuous function attains its maximum and underlying existence of minimizers in optimization. We will see why both ideas, nearly free in Rn\R^n, fail instructively in infinite dimensions, where functions live.

Metrics and norms

Three axioms, and almost everything you know about limits in R\R survives. A sequence (xk)(x_k) converges to xx in (X,d)(X, d) if d(xk,x)→0d(x_k, x) \to 0, the sequence limit notion with ∣xk−x∣\abs{x_k - x} replaced by d(xk,x)d(x_k, x). The limit is unique because if xk→xx_k \to x and xk→yx_k \to y, the triangle inequality gives d(x,y)≤d(x,xk)+d(xk,y)→0d(x, y) \le d(x, x_k) + d(x_k, y) \to 0. Examples we will use:

  • Rn\R^n with dp(x,y)=∥x−y∥pd_p(\vb{x}, \vb{y}) = \norm{\vb{x} - \vb{y}}_p for 1≤p≤∞1 \le p \le \infty.
  • Any subset A⊆XA \subseteq X with restricted distance: (0,1](0, 1], Q\Q or the unit sphere are metric spaces in their own right.
  • The discrete metric, d(x,y)=1d(x, y) = 1 if x≠yx \neq y: every set is a metric space with it.
  • Hamming distance between bit strings of length nn: the number of positions where they differ. It is the metric of error-correcting codes.
  • C[a,b]C[a, b], continuous functions on [a,b][a, b], with d∞(f,h)=sup⁡t∈[a,b]∣f(t)−h(t)∣d_\infty(f, h) = \sup_{t \in [a, b]} \abs{f(t) - h(t)}: the largest vertical separation between graphs. This is the space of Picard iteration.
  • Bounded functions on a state set SS, with d∞(V,W)=sup⁡s∣V(s)−W(s)∣d_\infty(V, W) = \sup_s \abs{V(s) - W(s)}: the value-iteration space.

Nearly all these metrics come from a norm: a function ∥⋅∥\norm{\cdot} on a vector space with ∥x∥=0\norm{\vb{x}} = 0 only if x=0\vb{x} = \vb{0}, ∥αx∥=∣α∣∥x∥\norm{\alpha\vb{x}} = \abs{\alpha}\norm{\vb{x}} and ∥x+y∥≤∥x∥+∥y∥\norm{\vb{x} + \vb{y}} \le \norm{\vb{x}} + \norm{\vb{y}}. Every norm induces metric d(x,y)=∥x−y∥d(\vb{x}, \vb{y}) = \norm{\vb{x} - \vb{y}}, also invariant under translations and scaling with homotheties. The discrete metric does not come from a norm: for x≠0\vb{x} \neq \vb{0}, d(2x,0)=1≠2 d(x,0)d(2\vb{x}, \vb{0}) = 1 \neq 2\,d(\vb{x}, \vb{0}).

The ℓp\ell_p norms and why p≥1p \ge 1

In Rn\R^n, ∥x∥p=(∑i∣xi∣p)1/p\norm{\vb{x}}_p = \big(\sum_i \abs{x_i}^p\big)^{1/p} and ∥x∥∞=max⁡i∣xi∣\norm{\vb{x}}_\infty = \max_i \abs{x_i}, the limit of ∥x∥p\norm{\vb{x}}_p as p→∞p \to \infty. For p≥1p \ge 1 the triangle inequality is Minkowski’s. For p<1p < 1 the expression still makes sense, but fails: with e1=(1,0)\vb{e}_1 = (1, 0) and e2=(0,1)\vb{e}_2 = (0, 1),

∥e1+e2∥p=21/p>2=∥e1∥p+∥e2∥p(p<1).\norm{\vb{e}_1 + \vb{e}_2}_p = 2^{1/p} > 2 = \norm{\vb{e}_1}_p + \norm{\vb{e}_2}_p \qquad (p < 1).

There is a geometric way to see which condition fails.

Proof

If NN is a norm and x,y∈B\vb{x}, \vb{y} \in B, for t∈[0,1]t \in [0, 1] we have N(tx+(1−t)y)≤tN(x)+(1−t)N(y)≤1N(t\vb{x} + (1 - t)\vb{y}) \le tN(\vb{x}) + (1 - t)N(\vb{y}) \le 1. Conversely, suppose BB convex and take nonzero x,y\vb{x}, \vb{y} (if one is zero there is nothing to prove). Points x/N(x)\vb{x}/N(\vb{x}) and y/N(y)\vb{y}/N(\vb{y}) lie in BB, and with t=N(x)/(N(x)+N(y))t = N(\vb{x})/(N(\vb{x}) + N(\vb{y})) their convex combination is

txN(x)+(1−t)yN(y)=x+yN(x)+N(y)∈B.t\frac{\vb{x}}{N(\vb{x})} + (1 - t)\frac{\vb{y}}{N(\vb{y})} = \frac{\vb{x} + \vb{y}}{N(\vb{x}) + N(\vb{y})} \in B.

By homogeneity, N(x+y)≤N(x)+N(y)N(\vb{x} + \vb{y}) \le N(\vb{x}) + N(\vb{y}).

∎
Interactiveℓp unit balls
fuera de la bola
  • ℓ0.60\ell_{0.60} unit ball
  • ℓ2\ell_2 balls of radii 1/C1/C and 1/c1/c
  • ℓ1\ell_1
  • ℓ∞\ell_\infty
0.60
d0.60(u,v)=∥u−v∥0.60d_{0.60}(\vb{u}, \vb{v}) = \|\vb{u} - \vb{v}\|_{0.60}3.175
d1(u,v)d_1(\vb{u}, \vb{v})2.000
d2(u,v)d_2(\vb{u}, \vb{v})1.414
d∞(u,v)d_\infty(\vb{u}, \vb{v})1.000
d0.60(u,0)+d0.60(0,v)d_{0.60}(\vb{u}, \vb{0}) + d_{0.60}(\vb{0}, \vb{v})2.000
∥u∥0.60/∥u∥2\|\vb{u}\|_{0.60} / \|\vb{u}\|_21.000
always in [c,C][c, C][1.000, 2.245]
The triangle inequality fails: 3.175 > 1.000 + 1.000. For p<1p < 1, dpd_p is not a metric.
The blue region is unit ball {x:∥x∥p≤1}\{\vb{x} : \norm{\vb{x}}_p \le 1\}. You start at p=0.6p = 0.6, with u=(1,0)\vb{u} = (1, 0) and v=(0,1)\vb{v} = (0, 1): their chord leaves the ball and the triangle inequality fails. Raise pp to 1, where the ball becomes the diamond ℓ1\ell_1, and continue to ∞\infty, where it is a square. Dashed circles are the largest ℓ2\ell_2 ball inside and smallest outside: their radii give equivalence constants. Drag u\vb{u} and v\vb{v} and compare distances in each metric: which is always largest and which smallest?

The figure shows more than convexity. The three metrics d1d_1, d2d_2 and d∞d_\infty always order the distance between two points the same way and never differ by more than a fixed factor:

∥x∥∞≤∥x∥2≤∥x∥1≤n ∥x∥2≤n ∥x∥∞.\norm{\vb{x}}_\infty \le \norm{\vb{x}}_2 \le \norm{\vb{x}}_1 \le \sqrt{n}\,\norm{\vb{x}}_2 \le n\,\norm{\vb{x}}_\infty.

The first inequality follows from max⁡ixi2≤∑ixi2\max_i x_i^2 \le \sum_i x_i^2; the second from expanding (∑i∣xi∣)2(\sum_i \abs{x_i})^2, containing all xi2x_i^2 and nonnegative cross terms; the third is Cauchy–Schwarz applied to (∣x1∣,…,∣xn∣)(\abs{x_1}, \dots, \abs{x_n}) and (1,…,1)(1, \dots, 1); the fourth follows because each xi2≤∥x∥∞2x_i^2 \le \norm{\vb{x}}_\infty^2. All are optimal: e1\vb{e}_1 gives equality in the first two and (1,…,1)(1, \dots, 1) in the last two.

Two norms ∥⋅∥a\norm{\cdot}_a and ∥⋅∥b\norm{\cdot}_b are equivalent if there exist constants 0<c≤C0 < c \le C with c∥x∥a≤∥x∥b≤C∥x∥ac\norm{\vb{x}}_a \le \norm{\vb{x}}_b \le C\norm{\vb{x}}_a for every x\vb{x}. Equivalent norms have the same convergent sequences, Cauchy sequences and, as we will see, open sets: qualitatively they are interchangeable. In Rn\R^n this is not a coincidence of the ℓp\ell_p norms. Once we have compactness, we will prove all norms on Rn\R^n are equivalent. But the constants depend on nn: in R106\R^{10^6}, ∥x∥1\norm{\vb{x}}_1 can be a thousand times ∥x∥2\norm{\vb{x}}_2. For quantitative matters such as a contraction constant, the norm matters greatly, and in infinite dimensions equivalence disappears entirely.

Topology of Rn\R^n: open and closed sets, continuity

In a metric space, the open ball with center xx and radius r>0r > 0 is B(x,r)={y:d(x,y)<r}B(x, r) = \{y : d(x, y) < r\}, and the closed ball is Bˉ(x,r)={y:d(x,y)≤r}\bar B(x, r) = \{y : d(x, y) \le r\}.

Open balls are open: if y∈B(x,r)y \in B(x, r), with s=r−d(x,y)>0s = r - d(x, y) > 0 the triangle inequality gives B(y,s)⊆B(x,r)B(y, s) \subseteq B(x, r). A similar argument shows closed balls are closed. Open and closed are not opposites: [0,1)[0, 1) is neither, and Rn\R^n and ∅\emptyset are both. In R\R, Q\Q has empty interior (every interval contains irrationals) and closure R\R (every interval contains rationals), so its boundary is all R\R. Arbitrary unions of open sets are open, and finite intersections too, but not infinite ones: ⋂k(−1/k,1/k)={0}\bigcap_k (-1/k, 1/k) = \{0\}.

The most used characterization of closed sets is sequential: a closed set cannot be left by taking limits.

Proof

Suppose FF closed, xk∈Fx_k \in F and xk→xx_k \to x. If x∉Fx \notin F, since X∖FX \setminus F is open there is a ball B(x,r)B(x, r) disjoint from FF; but d(xk,x)<rd(x_k, x) < r for large kk, contradiction. Conversely, suppose FF contains limits of its sequences and X∖FX \setminus F is not open. Then there is x∉Fx \notin F such that every ball B(x,1/k)B(x, 1/k) contains a point xk∈Fx_k \in F. That sequence converges to x∉Fx \notin F, contradiction. The assertion about Aˉ\bar A uses the same argument: x∈Aˉx \in \bar A if and only if each B(x,1/k)B(x, 1/k) contains some xk∈Ax_k \in A.

∎

Continuity without epsilons

A function f:X→Yf: X \to Y between metric spaces is continuous at xx if for each ε>0\eps > 0 there is δ>0\delta > 0 with dY(f(x),f(y))<εd_Y(f(x), f(y)) < \eps whenever dX(x,y)<δd_X(x, y) < \delta; as in R\R, this is equivalent to preserving sequence limits (continuity in lesson 1). Every Lipschitz function, dY(f(x),f(y))≤L dX(x,y)d_Y(f(x), f(y)) \le L\,d_X(x, y), is continuous with δ=ε/L\delta = \eps/L. The global reformulation without ε\eps or δ\delta uses the preimage.

Proof

Suppose ff continuous, UU open and x∈f−1(U)x \in f^{-1}(U). Since f(x)∈Uf(x) \in U, there is ε\eps with B(f(x),ε)⊆UB(f(x), \eps) \subseteq U, and continuity gives δ\delta with f(B(x,δ))⊆B(f(x),ε)⊆Uf(B(x, \delta)) \subseteq B(f(x), \eps) \subseteq U, that is, B(x,δ)⊆f−1(U)B(x, \delta) \subseteq f^{-1}(U). Conversely, given xx and ε\eps, set f−1(B(f(x),ε))f^{-1}(B(f(x), \eps)) is open and contains xx, so contains a ball B(x,δ)B(x, \delta): this is δ\delta. The closed-set version follows from f−1(Y∖U)=X∖f−1(U)f^{-1}(Y \setminus U) = X \setminus f^{-1}(U).

∎

This theorem makes trivial what would be tedious with sequences. If g:Rn→Rg: \R^n \to \R is continuous, {g<c}\{g < c\} is open and {g≤c}\{g \le c\} and {g=c}\{g = c\} are closed. Thus the feasible set of a problem with continuous constraints gi(x)≤0g_i(\vb{x}) \le 0, hj(x)=0h_j(\vb{x}) = 0 is closed; probability simplex {p≥0, ∑ipi=1}\{\vb{p} \ge \vb{0},\ \sum_i p_i = 1\} is closed; sphere {∥x∥=1}\{\norm{\vb{x}} = 1\} is closed.

Compactness

In R\R, Bolzano–Weierstrass says every bounded sequence has a convergent subsequence. To prevent the limit escaping the set, the set must be closed. Sets with no possible escape are compact.

In any metric space, compact implies closed and bounded. Closed, because if xk∈Kx_k \in K converges to xx, the compactness subsequence converges to a point of KK, and uniqueness makes that point xx. Bounded, because otherwise there would be xk∈Kx_k \in K with d(xk,x0)>kd(x_k, x_0) > k and no subsequence could converge (a convergent sequence is bounded). In Rn\R^n the converse holds.

Proof

We have seen the forward implication. If KK is closed and bounded and (xk)(\vb{x}_k) is a sequence in KK, Bolzano–Weierstrass in Rn\R^n (applied coordinate by coordinate, extracting successive subsequences) gives a subsequence converging to some x∈Rn\vb{x} \in \R^n, and since KK is closed, x∈K\vb{x} \in K.

∎

Thus the closed ball, sphere, simplex and every bounded set {x:g(x)≤c}\{\vb{x} : g(\vb{x}) \le c\} with continuous gg are compact. The next figure shows what breaks when each assumption is removed. Its animation follows the Bolzano–Weierstrass proof: bisect the interval, retain the half containing infinitely many terms (in the figure, the one containing more of the first 600) and choose a term inside, repeatedly. Nested intervals close onto a point; the question is whether that point lies in the set.

InteractiveWhen compactness fails
Set (0,1](0, 1], first terms of xn=1/nx_n = 1/n and bisection intervals
01
A continuous function on the set: f(x)=1−xf(x) = 1 - x
sup f = 1
  • set
  • terms xnx_n
  • subsequence and current interval
  • missing limit or maximum
bisection: step 9
Sequencexn=1/nx_n = 1/n
Interval at step 9[0.0020, 0.0039]
Terms inside (of the first 600)255
Subsequence n1<n2<⋯n_1 < n_2 < \cdots…, 128, 256, 257
Subsequence limit0
Is it in (0,1](0, 1]?no
sup⁡f\sup f on (0,1](0, 1]1, not attained
Bounded but not closed: every subsequence of 1/n1/n converges to 0, which is outside the set, and ff approaches 1 without reaching it.
The line shows the set (blue), initial sequence terms (gray marks) and, below, bisection intervals; magenta points are its selected subsequence. Start in (0,1](0, 1] with xn=1/nx_n = 1/n: the limit is 0, the missing endpoint. Switch to [0,1][0, 1] with sequence {nφ}\{n\varphi\} (fractional part of nn times the golden ratio), which does not converge and fills the interval uniformly: bisection always ends inside. Try Q∩[0,1]\mathbb{Q} \cap [0, 1] and R\mathbb{R}, and finally the unit ball of ℓ2\ell^2, where no bisection is possible. Below, a continuous function on the set that, except on [0,1][0, 1], does not attain its supremum: the same ff with a maximum on [0,1][0, 1] loses it on the rationals.

Why it fails in infinite dimensions

Space ℓ2\ell^2 consists of real sequences x=(x1,x2,… )\vb{x} = (x_1, x_2, \dots) with ∑kxk2<∞\sum_k x_k^2 < \infty, and its norm is ∥x∥2=(∑kxk2)1/2\norm{\vb{x}}_2 = (\sum_k x_k^2)^{1/2}. It is the analogue of Rn\R^n with infinitely many coordinates and a model of function spaces: Fourier coefficients of a square-integrable function form an element of ℓ2\ell^2. Its closed unit ball {∥x∥2≤1}\{\norm{\vb{x}}_2 \le 1\} is closed (it is the preimage of [0,1][0, 1] under the continuous norm) and bounded. But it is not compact. Canonical basis vectors en=(0,…,0,1,0,… )\vb{e}_n = (0, \dots, 0, 1, 0, \dots) lie in it and satisfy

∥ei−ej∥2=2(i≠j).\norm{\vb{e}_i - \vb{e}_j}_2 = \sqrt 2 \qquad (i \neq j).

No subsequence can converge, because any two terms are distance 2\sqrt 2 apart: it is not even Cauchy. In infinite dimensions there is room for infinitely many mutually distant directions inside a bounded ball. This is general (Riesz’s theorem): the closed unit ball of a normed space is compact if and only if its dimension is finite.

The practical consequence is that existence in function spaces cannot be proved by “closed and bounded.” The set of continuous functions on [0,1][0, 1] with ∥f∥∞≤1\norm{f}_\infty \le 1 is closed and bounded in C[0,1]C[0, 1], but fn(t)=tnf_n(t) = t^n has no uniformly convergent subsequence (the pointwise limit is 0 on [0,1)[0, 1) and 1 at t=1t = 1, and is not continuous). Compactness in function spaces requires more, the equicontinuity of Arzelà–Ascoli, appearing with uniform convergence.

Consequences of compactness

Compactness is useful because continuous functions preserve it.

The proof has three lines and you will do it in a guided exercise at the end. Its corollary is analysis’s most-used existence result.

This is the extreme value theorem. By the preceding theorem, f(K)f(K) is a compact subset of R\R, hence closed and bounded; its supremum exists by real completeness and is a limit of points of f(K)f(K), so belongs to f(K)f(K) because it is closed. The guided exercise reconstructs this step too. Notice what the preceding figure says: every assumption is necessary. On (0,1](0, 1], R\R and Q∩[0,1]\Q \cap [0, 1] there are continuous, even bounded, functions without maxima, and so on the ball of ℓ2\ell^2: f(x)=∑k(1−1/k) xk2f(\vb{x}) = \sum_k (1 - 1/k)\,x_k^2 is continuous (indeed ∣f(x)−f(y)∣≤∥x−y∥2∥x+y∥2\abs{f(\vb{x}) - f(\vb{y})} \le \norm{\vb{x} - \vb{y}}_2\norm{\vb{x} + \vb{y}}_2 by Cauchy–Schwarz), equals 1−1/n1 - 1/n at en\vb{e}_n and never reaches 1, because f(x)=∥x∥22−∑kxk2/k<1f(\vb{x}) = \norm{\vb{x}}_2^2 - \sum_k x_k^2/k < 1 if ∥x∥2≤1\norm{\vb{x}}_2 \le 1 and x≠0\vb{x} \neq \vb{0}.

All norms on Rn\R^n are equivalent

Proof

Upper bound. Write x=∑ixiei\vb{x} = \sum_i x_i\vb{e}_i. By the triangle inequality and Cauchy–Schwarz, ∥x∥≤∑i∣xi∣ ∥ei∥≤M∥x∥2\norm{\vb{x}} \le \sum_i \abs{x_i}\,\norm{\vb{e}_i} \le M\norm{\vb{x}}_2 with M=(∑i∥ei∥2)1/2M = (\sum_i \norm{\vb{e}_i}^2)^{1/2}. In particular, ∣∥x∥−∥y∥∣≤∥x−y∥≤M∥x−y∥2\abs{\norm{\vb{x}} - \norm{\vb{y}}} \le \norm{\vb{x} - \vb{y}} \le M\norm{\vb{x} - \vb{y}}_2, so ∥⋅∥\norm{\cdot} is a continuous (Lipschitz) function on (Rn,∥⋅∥2)(\R^n, \norm{\cdot}_2).

Lower bound. Sphere S={x:∥x∥2=1}S = \{\vb{x} : \norm{\vb{x}}_2 = 1\} is closed and bounded, hence compact by Heine–Borel. By the extreme value theorem, ∥⋅∥\norm{\cdot} attains a minimum m=∥x0∥m = \norm{\vb{x}_0} on SS, and m>0m > 0 because x0≠0\vb{x}_0 \neq \vb{0}. For x≠0\vb{x} \neq \vb{0}, x/∥x∥2∈S\vb{x}/\norm{\vb{x}}_2 \in S, and by homogeneity ∥x∥≥m∥x∥2\norm{\vb{x}} \ge m\norm{\vb{x}}_2.

If ∥⋅∥a\norm{\cdot}_a and ∥⋅∥b\norm{\cdot}_b are two norms, compare both with ∥⋅∥2\norm{\cdot}_2.

∎

Compactness was only used for the lower bound, precisely what fails in infinite dimensions. In the space of finitely supported sequences, xn=(1,…,1,0,… )\vb{x}_n = (1, \dots, 1, 0, \dots) with nn ones has ∥xn∥1=n\norm{\vb{x}_n}_1 = n and ∥xn∥2=n\norm{\vb{x}_n}_2 = \sqrt n: no CC satisfies ∥⋅∥1≤C∥⋅∥2\norm{\cdot}_1 \le C\norm{\cdot}_2.

The same scheme proves existence of minimizers in optimization. If f:Rn→Rf: \R^n \to \R is continuous and coercive (f(x)→∞f(\vb{x}) \to \infty as ∥x∥→∞\norm{\vb{x}} \to \infty), sublevel set {f≤f(x0)}\{f \le f(\vb{x}_0)\} is closed (preimage of a closed set) and bounded (by coercivity), hence compact, and ff attains its minimum there, the global minimum. Least-squares loss with λ∥w∥2\lambda\norm{\vb{w}}^2 regularization is coercive; logistic loss on linearly separable data is not, and indeed has no minimizer: weights grow without bound.

Uniform continuity

In the definition of continuity, δ\delta may depend on the point. For f(x)=1/xf(x) = 1/x on (0,1](0, 1], the closer to 0, the smaller δ\delta must be for the same ε\eps, and no δ\delta works for every point at once.

Every Lipschitz function is uniformly continuous, with δ=ε/L\delta = \eps/L. The converse is false: x\sqrt x on [0,1][0, 1] is uniformly continuous because ∣x−y∣≤∣x−y∣\abs{\sqrt x - \sqrt y} \le \sqrt{\abs{x - y}}, but is not Lipschitz because its slope is infinite at 0. And x2x^2 on R\R is continuous but not uniformly: (n+1/n)2−n2=2+1/n2(n + 1/n)^2 - n^2 = 2 + 1/n^2, so points distance 1/n1/n apart have images more than 2 apart. In both examples of continuous functions not uniformly continuous, 1/x1/x on (0,1](0, 1] and x2x^2 on R\R, the domain is not compact, and the next theorem says this is no coincidence.

Proof

Otherwise there would be ε>0\eps > 0 such that for each kk there are points xk,yk∈Kx_k, y_k \in K with d(xk,yk)<1/kd(x_k, y_k) < 1/k and d(f(xk),f(yk))≥εd(f(x_k), f(y_k)) \ge \eps. By compactness, a subsequence xkjx_{k_j} converges to some x∈Kx \in K, and since d(ykj,x)≤d(ykj,xkj)+d(xkj,x)→0d(y_{k_j}, x) \le d(y_{k_j}, x_{k_j}) + d(x_{k_j}, x) \to 0, so does ykj→xy_{k_j} \to x. By continuity at xx, f(xkj)→f(x)f(x_{k_j}) \to f(x) and f(ykj)→f(x)f(y_{k_j}) \to f(x), so d(f(xkj),f(ykj))→0d(f(x_{k_j}), f(y_{k_j})) \to 0, contradicting d≥εd \ge \eps.

∎

Uniform continuity enables discretization. If ff is continuous on [a,b][a, b], for every tolerance ε\eps there is a mesh of step δ\delta whose piecewise-linear interpolation of ff is within ε\eps of ff at every point: this is the argument for integrability of continuous functions in the Riemann integral and the simplest idea behind universal approximation theorems.

Completeness

You already know Cauchy sequences: in a metric space, (xk)(x_k) is Cauchy if for each ε>0\eps > 0 there is NN with d(xk,xm)<εd(x_k, x_m) < \eps for all k,m≥Nk, m \ge N. Every convergent sequence is Cauchy because d(xk,xm)≤d(xk,x)+d(x,xm)d(x_k, x_m) \le d(x_k, x) + d(x, x_m). The converse depends on the space.

Completeness lets us prove something exists without knowing where in advance: prove a sequence stabilizes, and the space supplies its limit. Examples:

  • R\R is complete: another form of its supremum axiom. Q\Q is not: Babylonian iterations xk+1=xk/2+1/xkx_{k+1} = x_k/2 + 1/x_k from x0=2x_0 = 2 are all rational, Cauchy and converge to 2∉Q\sqrt 2 \notin \Q.
  • Rn\R^n is complete under any norm. With ∥⋅∥∞\norm{\cdot}_\infty, if (xk)(\vb{x}_k) is Cauchy, each coordinate is because ∣xk,i−xm,i∣≤∥xk−xm∥∞\abs{x_{k,i} - x_{m,i}} \le \norm{\vb{x}_k - \vb{x}_m}_\infty; each coordinate converges in R\R and the vector of limits is the limit. For another norm use equivalence.
  • A subset of a complete space is complete if and only if closed. Thus [1,∞)[1, \infty) and any compact subset of Rn\R^n are complete, and (0,1](0, 1] is not.
  • C[a,b]C[a, b] with d∞d_\infty is complete: the uniform limit of continuous functions is continuous. This is supremum-norm completeness, proved in lesson 14 and making Picard iteration work. With distance ∫ab∣f−h∣\int_a^b \abs{f - h}, however, C[a,b]C[a, b] is not complete: increasingly steep ramps are Cauchy and approach a step function, which is not continuous.
  • Every compact space is complete: if a Cauchy sequence has a convergent subsequence, the whole sequence converges to the same limit.

Banach’s fixed-point theorem

This is the Banach fixed-point theorem, also called the contraction mapping principle. Besides the four opening problems, it is the tool you will use to prove the inverse function theorem (lesson 10) and Picard–Lindelöf for differential equations. You will prove existence and uniqueness step by step in the guided exercise; the idea is that steps d(xk+1,xk)≤qkd(x1,x0)d(x_{k+1}, x_k) \le q^k d(x_1, x_0) decrease geometrically, so the sequence is Cauchy, completeness supplies its limit, and continuity of gg makes it a fixed point. Here we prove the bounds, what you will use in code.

Proof

(5) Since x∗=g(x∗)x^* = g(x^*), d(xk+1,x∗)=d(g(xk),g(x∗))≤q d(xk,x∗)d(x_{k+1}, x^*) = d(g(x_k), g(x^*)) \le q\,d(x_k, x^*).

(4) By the triangle inequality and (5), d(xk−1,x∗)≤d(xk−1,xk)+d(xk,x∗)≤d(xk−1,xk)+q d(xk−1,x∗)d(x_{k-1}, x^*) \le d(x_{k-1}, x_k) + d(x_k, x^*) \le d(x_{k-1}, x_k) + q\,d(x_{k-1}, x^*), giving d(xk−1,x∗)≤d(xk,xk−1)/(1−q)d(x_{k-1}, x^*) \le d(x_k, x_{k-1})/(1 - q). Applying (5) once more, d(xk,x∗)≤q d(xk−1,x∗)≤q1−q d(xk,xk−1)d(x_k, x^*) \le q\,d(x_{k-1}, x^*) \le \frac{q}{1 - q}\,d(x_k, x_{k-1}).

(3) By induction, d(xk,xk−1)=d(g(xk−1),g(xk−2))≤q d(xk−1,xk−2)≤⋯≤qk−1d(x1,x0)d(x_k, x_{k-1}) = d(g(x_{k-1}), g(x_{k-2})) \le q\,d(x_{k-1}, x_{k-2}) \le \cdots \le q^{k-1}d(x_1, x_0). Substituting in (4), d(xk,x∗)≤q1−q qk−1d(x1,x0)=qk1−q d(x1,x0)d(x_k, x^*) \le \frac{q}{1 - q}\,q^{k-1}d(x_1, x_0) = \frac{q^k}{1 - q}\,d(x_1, x_0).

∎

The two bounds play different roles. The a priori bound says before starting how many iterations suffice: qk d(x1,x0)/(1−q)<εq^k\,d(x_1, x_0)/(1 - q) < \eps gives

k≥log⁡(ε(1−q)/d(x1,x0))log⁡q.k \ge \frac{\log\big(\eps(1 - q)/d(x_1, x_0)\big)}{\log q}.

The a posteriori bound is a certificate calculated during iteration using what you already have, and is usually much tighter. Both depend on knowing a valid qq, and linear convergence guarantees the number of correct digits grows at least like klog⁡10(1/q)k\log_{10}(1/q): with q=0.9q = 0.9 you gain at least one digit per 22 iterations; with q=0.5q = 0.5, one per 3.3. This is linear convergence from lesson 3.

Every assumption is necessary

  • Completeness. g(x)=x/2+1/xg(x) = x/2 + 1/x maps X=Q∩[1,2]X = \Q \cap [1, 2] into itself (its image is in [2,1.5][\sqrt 2, 1.5]) and is contractive with q=1/2q = 1/2, because ∣g′(x)∣=∣1/2−1/x2∣≤1/2\abs{g'(x)} = \abs{1/2 - 1/x^2} \le 1/2 on [1,2][1, 2]. But it has no fixed point in XX: the only candidate is 2\sqrt 2.
  • The uniform constant q<1q < 1. g(x)=x2+1g(x) = \sqrt{x^2 + 1} on R\R, which is complete, satisfies ∣g(x)−g(y)∣<∣x−y∣\abs{g(x) - g(y)} < \abs{x - y} for x≠yx \neq y, because ∣g′(t)∣=∣t∣/t2+1<1\abs{g'(t)} = \abs{t}/\sqrt{t^2 + 1} < 1. But g(x)>∣x∣≥xg(x) > \abs{x} \ge x always: no fixed point exists. Ratio ∣g(x)−g(y)∣/∣x−y∣\abs{g(x) - g(y)}/\abs{x - y} approaches 1 as x,y→∞x, y \to \infty, and no q<1q < 1 works for every pair.
  • gg must map XX into XX. To apply the theorem on a closed FF of Rn\R^n check g(F)⊆Fg(F) \subseteq F. Forgetting this is the most common mistake when using it on an interval.

The local version and speed

In practice a global contraction is unnecessary. If gg is class C1C^1 near a fixed point x∗x^* with ∣g′(x∗)∣<1\abs{g'(x^*)} < 1, continuity gives a closed interval I=[x∗−r,x∗+r]I = [x^* - r, x^* + r] on which ∣g′∣≤q<1\abs{g'} \le q < 1. By the mean value theorem, ∣g(x)−g(y)∣≤q∣x−y∣\abs{g(x) - g(y)} \le q\abs{x - y} on II, and in particular ∣g(x)−x∗∣=∣g(x)−g(x∗)∣≤q∣x−x∗∣≤r\abs{g(x) - x^*} = \abs{g(x) - g(x^*)} \le q\abs{x - x^*} \le r, so g(I)⊆Ig(I) \subseteq I. II is complete and Banach applies: iteration converges from any x0x_0 close enough. The mean value theorem also says ek+1=∣g′(ξk)∣ eke_{k+1} = \abs{g'(\xi_k)}\,e_k with ξk\xi_k between xkx_k and x∗x^*, so

ek+1ek→∣g′(x∗)∣,ek=∣xk−x∗∣.\frac{e_{k+1}}{e_k} \to \abs{g'(x^*)}, \qquad e_k = \abs{x_k - x^*}.

The actual rate is ∣g′(x∗)∣\abs{g'(x^*)}, possibly much smaller than global constant qq. If ∣g′(x∗)∣>1\abs{g'(x^*)} > 1, the fixed point repels: nearby errors grow. And if g′(x∗)=0g'(x^*) = 0 and gg is class C2C^2, Taylor expansion gives ek+1≈12∣g′′(x∗)∣ ek2e_{k+1} \approx \tfrac12\abs{g''(x^*)}\,e_k^2: quadratic convergence, doubling correct digits each step. Newton’s method, g(x)=x−h(x)/h′(x)g(x) = x - h(x)/h'(x), does this: g′(x∗)=h(x∗)h′′(x∗)/h′(x∗)2=0g'(x^*) = h(x^*)h''(x^*)/h'(x^*)^2 = 0 at a simple root of hh. Babylonian iteration is Newton for h(x)=x2−2h(x) = x^2 - 2 (studied as Newton–Raphson).

InteractiveFixed-point cobweb
x*y = g(x)
  • y=cos⁡xy = \cos x
  • y=xy = x
  • cobweb: xk→g(xk)x_k \to g(x_k)
k = 40
xkx_k0.7391
ek=∣xk−x∗∣e_k = |x_k - x^*|5.2·10⁻⁸
ek/ek−1e_k / e_{k-1}0.6736
x∗x^* and ∣g′(x∗)∣|g'(x^*)|0.7391, 0.6736
∣g′(x∗)∣=sin⁡x∗=0.6736|g'(x^*)| = \sin x^* = 0.6736: each step multiplies error by this factor, and the cobweb spirals because g′<0g' < 0.
The cobweb rises from xkx_k to the graph of gg and goes horizontally to the diagonal: there is xk+1x_{k+1}. Start with g(x)=cos⁡xg(x) = \cos x: the cobweb spirals toward x∗≈0.739x^* \approx 0.739 and, on the right, error falls in a straight line alongside prediction e0∣g′(x∗)∣ke_0\abs{g'(x^*)}^k. Switch to the logistic map with r=2.8r = 2.8 (slow zigzag, rate 0.8), r=3.5r = 3.5 (fixed point repels and a period-4 cycle appears) and r=3.9r = 3.9 (chaos: move x0x_0 slightly and compare). Finally, x/2+1/xx/2 + 1/x: the graph is horizontal at 2\sqrt 2 and error plummets quadratically. Drag x0x_0 in each case.

Logistic map g(x)=rx(1−x)g(x) = rx(1 - x) is the classic example of what happens without contraction. Its nonzero fixed point is x∗=1−1/rx^* = 1 - 1/r, with g′(x∗)=2−rg'(x^*) = 2 - r. For r=2.8r = 2.8, ∣g′(x∗)∣=0.8\abs{g'(x^*)} = 0.8 and iteration converges in a zigzag because the derivative is negative. For r=3.5r = 3.5, ∣g′(x∗)∣=1.5\abs{g'(x^*)} = 1.5: the fixed point exists but repels, and the orbit falls into an attracting period-4 cycle (0.383→0.827→0.501→0.8750.383 \to 0.827 \to 0.501 \to 0.875). For r=3.9r = 3.9 there is not even an attracting cycle: this is the chaotic regime, where two very close starting points separate exponentially. No fixed-point theorem says anything useful there, and that is a lesson: when iteration fails to converge, first check contractivity.

In Kepler’s equation, g(E)=M+esin⁡Eg(E) = M + e\sin E satisfies ∣g′(E)∣=e∣cos⁡E∣≤e\abs{g'(E)} = e\abs{\cos E} \le e throughout R\R, so is a global contraction with constant q=e<1q = e < 1 and iteration converges for every elliptical eccentricity from any E0E_0. For ee near 1 convergence is slow and Newton is used, but Banach’s fixed-point theorem guarantees the solution exists and is unique.

Contractivity depends on the norm

In Rn\R^n all norms give the same limits but not the same contractions. The clearest example is the affine case, g(x)=Ax+bg(\vb{x}) = \mat{A}\vb{x} + \vb{b}, the model for every linear iterative method. For any norm,

∥g(x)−g(y)∥=∥A(x−y)∥≤∥A∥ ∥x−y∥,\norm{g(\vb{x}) - g(\vb{y})} = \norm{\mat{A}(\vb{x} - \vb{y})} \le \norm{\mat{A}}\,\norm{\vb{x} - \vb{y}},

where ∥A∥\norm{\mat{A}} is the induced norm, max⁡x≠0∥Ax∥/∥x∥\max_{\vb{x} \neq \vb{0}} \norm{\mat{A}\vb{x}}/\norm{\vb{x}}. The bound is exact (some x\vb{x} attains it), so gg is a contraction in that norm if and only if ∥A∥<1\norm{\mat{A}} < 1, and the best constant is q=∥A∥q = \norm{\mat{A}}. Three easy ones are ∥A∥1\norm{\mat{A}}_1, largest absolute column sum; ∥A∥∞\norm{\mat{A}}_\infty, largest absolute row sum; and ∥A∥2=σmax⁡(A)\norm{\mat{A}}_2 = \sigma_{\max}(\mat{A}), largest singular value. Geometrically, ∥A∥<1\norm{\mat{A}} < 1 means A\mat{A} maps the norm’s unit ball inside itself.

They can disagree. A=[0.51.500.5]\mat{A} = \begin{bmatrix} 0.5 & 1.5 \\ 0 & 0.5 \end{bmatrix} has ∥A∥1=∥A∥∞=2\norm{\mat{A}}_1 = \norm{\mat{A}}_\infty = 2 and ∥A∥2≈1.651\norm{\mat{A}}_2 \approx 1.651: none of the three certifies anything. Yet its only eigenvalue is 0.50.5, and Ak→0\mat{A}^k \to \mat{0}. What decides convergence is not any particular norm but the spectral radius.

Proof

(2) ⇒ (3) is Banach, because Rn\R^n is complete under any norm.

(3) ⇒ (1). With b=0\vb{b} = \vb{0}, the assumption says Akx0\mat{A}^k\vb{x}_0 converges for every x0\vb{x}_0, and limit y\vb{y} satisfies Ay=y\mat{A}\vb{y} = \vb{y}. If λ\lambda is an eigenvalue with eigenvector v=u+iw\vb{v} = \vb{u} + i\vb{w}, both limits Aku\mat{A}^k\vb{u} and Akw\mat{A}^k\vb{w} exist, so Akv=λkv\mat{A}^k\vb{v} = \lambda^k\vb{v} converges. This requires ∣λ∣<1\abs{\lambda} < 1 or λ=1\lambda = 1. To exclude λ=1\lambda = 1 use b≠0\vb{b} \neq \vb{0}: if Av=v\mat{A}\vb{v} = \vb{v} with nonzero real v\vb{v} and you take b=v\vb{b} = \vb{v} and x0=0\vb{x}_0 = \vb{0}, iterates are xk=∑j<kAjv=kv\vb{x}_k = \sum_{j < k}\mat{A}^j\vb{v} = k\vb{v}, which do not converge.

(1) ⇒ (2). Choose ss with ρ(A)<s<1\rho(\mat{A}) < s < 1. By Gelfand’s formula, ∥Ak∥21/k→ρ(A)\norm{\mat{A}^k}_2^{1/k} \to \rho(\mat{A}), so ∥Ak∥2≤Cs′k\norm{\mat{A}^k}_2 \le C s'^k for some s′<ss' < s and the following series converges:

∥x∥∗=∑k=0∞∥Akx∥2sk.\norm{\vb{x}}_* = \sum_{k=0}^{\infty} \frac{\norm{\mat{A}^k\vb{x}}_2}{s^k}.

It is a norm: a sum of seminorms with first term ∥x∥2\norm{\vb{x}}_2. And ∥Ax∥∗=∑k≥0∥Ak+1x∥2/sk=s∑k≥1∥Akx∥2/sk≤s∥x∥∗\norm{\mat{A}\vb{x}}_* = \sum_{k \ge 0} \norm{\mat{A}^{k+1}\vb{x}}_2/s^k = s\sum_{k \ge 1}\norm{\mat{A}^k\vb{x}}_2/s^k \le s\norm{\vb{x}}_*. Thus ∥A∥∗≤s<1\norm{\mat{A}}_* \le s < 1.

∎

Norm ∥⋅∥∗\norm{\cdot}_* is tailored to A\mat{A}: it weights directions A\mat{A} initially stretches more heavily. In practice something simpler sometimes suffices. With D=diag⁡(1,w)\mat{D} = \diag(1, w) and ∥x∥w=∥Dx∥∞=max⁡(∣x1∣,w∣x2∣)\norm{\vb{x}}_w = \norm{\mat{D}\vb{x}}_\infty = \max(\abs{x_1}, w\abs{x_2}), the induced norm is ∥DAD−1∥∞\norm{\mat{D}\mat{A}\mat{D}^{-1}}_\infty. For the earlier matrix, DAD−1=[0.51.5/w00.5]\mat{D}\mat{A}\mat{D}^{-1} = \begin{bmatrix} 0.5 & 1.5/w \\ 0 & 0.5 \end{bmatrix}, which contracts in ℓ∞\ell_\infty once w>3w > 3: with w=4w = 4, q=0.875q = 0.875.

InteractiveContractive in which norm?
  • ℓ2\ell_2 ball and its image under A\mat{A}
  • ∥⋅∥w\|\cdot\|_w ball and its image
  • errors ek=Ake0\vb{e}_k = \mat{A}^k\vb{e}_0 (origin =x∗= \vb{x}^*)
  • ∥ek∥w/∥e0∥w\|\vb{e}_k\|_w / \|\vb{e}_0\|_w
  • ∥ek∥2/∥e0∥2\|\vb{e}_k\|_2 / \|\vb{e}_0\|_2
  • ρ(A)k\rho(\mat{A})^k
Entries of A
1.000
ρ(A)\rho(\mat{A})0.5000
∥A∥2\|\mat{A}\|_21.651
∥A∥w=∥DAD−1∥∞\|\mat{A}\|_w = \|\mat{D}\mat{A}\mat{D}^{-1}\|_\infty2.000
∥A∥1\|\mat{A}\|_1 and ∥A∥∞\|\mat{A}\|_\infty2.000, 2.000
Maximum ∥ek∥2/∥e0∥2\|\vb{e}_k\|_2 / \|\vb{e}_0\|_21.649 at k = 1
ρ(A)=0.5000<1\rho(\mat{A}) = 0.5000 < 1: it converges, but neither ℓ2\ell_2 nor this ∥⋅∥w\|\cdot\|_w certifies it in one step. Move weight ww: a norm in which it contracts exists.
The origin is fixed point x∗=(I−A)−1b\vb{x}^* = (\mat{I} - \mat{A})^{-1}\vb{b}, so what you see are errors ek=Ake0\vb{e}_k = \mat{A}^k\vb{e}_0, the same picture for any b\vb{b}. In blue, the ℓ2\ell_2 unit circle and its image under A\mat{A} (dashed); in green, the ∥⋅∥w\norm{\cdot}_w ball and its image. Iteration is a contraction in a norm exactly when the image fits inside the ball. Start with the nonnormal matrix: the ellipse leaves the circle, ∥e1∥2\norm{\vb{e}_1}_2 is 1.65 times ∥e0∥2\norm{\vb{e}_0}_2, yet errors eventually fall like ρ(A)k=0.5k\rho(\mat{A})^k = 0.5^k. Raise weight ww above 3 and watch the green parallelogram enter its rectangle. Then choose the Bellman operator: it contracts in ℓ∞\ell_\infty but not ℓ2\ell_2.

The Bellman operator contracts in the supremum norm

For a fixed policy π\pi, the Bellman evaluation equation is affine: TπV=rπ+γPπVT_\pi V = \vb{r}_\pi + \gamma\mat{P}_\pi V, where (Pπ)ss′(\mat{P}_\pi)_{ss'} is transition probability from ss to s′s'. Rows of Pπ\mat{P}_\pi are nonnegative and sum to 1, so ∥Pπ∥∞=1\norm{\mat{P}_\pi}_\infty = 1 and ∥γPπ∥∞=γ\norm{\gamma\mat{P}_\pi}_\infty = \gamma: TπT_\pi is a contraction with constant γ\gamma in ∥⋅∥∞\norm{\cdot}_\infty for any transition matrix. In ℓ2\ell_2 there is no guarantee. With γ=0.9\gamma = 0.9 and two states both leading to the second with probability 0.90.9, γP=0.9[0.10.90.10.9]\gamma\mat{P} = 0.9\begin{bmatrix} 0.1 & 0.9 \\ 0.1 & 0.9 \end{bmatrix} has ∥γP∥2≈1.153\norm{\gamma\mat{P}}_2 \approx 1.153: two value functions can move farther apart in ℓ2\ell_2 after one evaluation step.

The optimality operator, with its max⁡\max, is no longer affine but remains a contraction in the same norm. The key is an elementary inequality: for functions f,hf, h on a finite action set, ∣max⁡af(a)−max⁡ah(a)∣≤max⁡a∣f(a)−h(a)∣\abs{\max_a f(a) - \max_a h(a)} \le \max_a \abs{f(a) - h(a)}. (If the first maximum is attained at a1a_1 and is the larger of the two, max⁡f−max⁡h≤f(a1)−h(a1)\max f - \max h \le f(a_1) - h(a_1); the other case is symmetric.) With f(a)=R(s,a)+γ∑s′P(s′∣s,a)V(s′)f(a) = R(s, a) + \gamma\sum_{s'}P(s' \given s, a)V(s') and hh similarly with WW,

∣(TV)(s)−(TW)(s)∣≤max⁡aγ∑s′P(s′∣s,a) ∣V(s′)−W(s′)∣≤γ ∥V−W∥∞.\abs{(TV)(s) - (TW)(s)} \le \max_a \gamma\sum_{s'} P(s' \given s, a)\,\abs{V(s') - W(s')} \le \gamma\,\norm{V - W}_\infty.

Taking the supremum over ss, ∥TV−TW∥∞≤γ∥V−W∥∞\norm{TV - TW}_\infty \le \gamma\norm{V - W}_\infty. Bounded functions on SS with supremum norm form a complete space (even if SS is infinite), and Banach gives existence and uniqueness of V∗V^*, convergence of value iteration from any V0V_0 and its stopping criterion at once. This is Bellman operator contraction, the foundation of value iteration.

The same analysis certifies iterative linear-system methods. Jacobi’s method for Mx=c\mat{M}\vb{x} = \vb{c} iterates x←D−1(c−(M−D)x)\vb{x} \leftarrow \mat{D}^{-1}(\vb{c} - (\mat{M} - \mat{D})\vb{x}), with D\mat{D} the diagonal of M\mat{M}. If M\mat{M} is strictly row diagonally dominant, each row of D−1(M−D)\mat{D}^{-1}(\mat{M} - \mat{D}) has absolute sum below 1, iteration is a contraction in ℓ∞\ell_\infty and converges (see stationary iterative methods).

Implementation from scratch

The following function iterates and stops when the a posteriori bound drops below tolerance. It returns point, iteration count and bound, an error certificate if gg really is a contraction with constant qq in the chosen metric. Apply it to Kepler’s equation with e=0.5e = 0.5 and M=1M = 1.

[ ]Fixed point with a certificate: KeplerBrowser
import math
import numpy as np
import matplotlib.pyplot as plt

def fixed_point(g, x0, q, tol=1e-10, max_iter=10_000, dist=None):
    """Itera x_{k+1} = g(x_k) hasta que la cota a posteriori q/(1-q) d(x_k, x_{k-1}) baje de tol.

    Devuelve (x, k, cota, historial). La cota solo es un certificado si g es una contracción
    de constante q en la métrica dist sobre un conjunto cerrado que g deja invariante."""
    if not 0 <= q < 1:
        raise ValueError("q debe estar en [0, 1)")
    if dist is None:      # por defecto, la distancia del supremo (|x - y| para escalares)
        dist = lambda a, b: float(np.max(np.abs(np.asarray(a) - np.asarray(b))))
    x, historial = x0, [x0]
    for k in range(1, max_iter + 1):
        x_nuevo = g(x)
        paso = dist(x_nuevo, x)
        historial.append(x_nuevo)
        x = x_nuevo
        cota = q / (1 - q) * paso
        if cota < tol:
            return x, k, cota, historial
    raise RuntimeError(f"sin certificado tras {max_iter} iteraciones (cota {cota:.2e})")

def iteraciones_a_priori(q, d01, tol):
    """Menor k con q^k/(1-q) d(x1, x0) < tol."""
    return max(0, math.ceil(math.log(tol * (1 - q) / d01) / math.log(q)))

# Ecuación de Kepler: E = M + e sen E, contracción en R con q = e
e, M, tol = 0.5, 1.0, 1e-10
g = lambda E: M + e * math.sin(E)
E, k, cota, hist = fixed_point(g, M, q=e, tol=tol)
k_prev = iteraciones_a_priori(e, abs(g(M) - M), tol)
E_ref = hist[-1]
for _ in range(50):
    E_ref = g(E_ref)                       # referencia: iterar hasta el punto fijo en coma flotante
k_real = next(i for i, x in enumerate(hist) if abs(x - E_ref) < tol)
print(f"E* = {E:.12f}   residuo |g(E) - E| = {abs(g(E) - E):.1e}")
print(f"a priori: {k_prev} iteraciones   a posteriori: se detiene en k = {k}   error real < tol desde k = {k_real}")
print(f"cota certificada {cota:.1e}   error real {abs(E - E_ref):.1e}")
errs = [abs(x - E_ref) for x in hist[:8]]
print("cocientes e_k/e_(k-1):", [round(errs[i + 1] / errs[i], 4) for i in range(1, 6)], "  e cos E* =", round(e * math.cos(E_ref), 4))

ks = np.arange(len(hist))
d01 = abs(hist[1] - hist[0])
plt.semilogy(ks, [max(abs(x - E_ref), 1e-17) for x in hist], "o-", label="error real")
plt.semilogy(ks, e**ks / (1 - e) * d01, "--", label="cota a priori")
plt.semilogy(ks[1:], [e / (1 - e) * abs(hist[i] - hist[i - 1]) for i in ks[1:]], "s-", label="cota a posteriori")
plt.axhline(tol, color="gray", lw=0.8)
plt.xlabel("iteración k"); plt.ylabel("|E_k − E*|"); plt.legend(); plt.show()

The a priori bound requires 33 iterations; the a posteriori bound certifies error at the ninth, and actual error was already below 10−1010^{-10} at the eighth. The difference has a precise cause: the bound uses global constant q=e=0.5q = e = 0.5, worst-case ∣g′(E)∣=e∣cos⁡E∣\abs{g'(E)} = e\abs{\cos E} over all R\R, while near the solution the actual rate is ecos⁡E∗≈0.036e\cos E^* \approx 0.036, as error ratios show. The a posteriori bound benefits from small actual steps despite still using pessimistic qq. That is its value: it adapts to reality and remains a guarantee.

Now a Bellman operator in a three-state, two-action MDP with γ=0.9\gamma = 0.9. Iteration lives in R3\R^3 with the supremum norm, the default distance of fixed_point.

[ ]Value iteration with a certificateBrowser
# MDP de 3 estados y 2 acciones. P[a][s, s'] = probabilidad de pasar de s a s' con la acción a.
P = np.array([
    [[0.9, 0.1, 0.0],          # a = 0, «esperar»: casi siempre se queda donde está
     [0.0, 0.9, 0.1],
     [0.0, 0.0, 1.0]],
    [[0.1, 0.9, 0.0],          # a = 1, «avanzar»: empuja hacia el estado 2... salvo desde el 2,
     [0.0, 0.1, 0.9],          #        que vuelve al 0
     [0.9, 0.0, 0.1]],
])
R = np.array([[0.0, -1.0],     # R[s, a]: avanzar cuesta, estar en el estado 2 paga
              [0.0, -1.0],
              [2.0,  0.0]])
gamma, tol = 0.9, 1e-6

def bellman(V):
    Q = R + gamma * np.einsum("ast,t->sa", P, V)   # Q[s, a] = R[s, a] + γ Σ_s' P[a][s, s'] V[s']
    return Q.max(axis=1)

V0 = np.zeros(3)
V, k, cota, hist = fixed_point(bellman, V0, q=gamma, tol=tol)
k_prev = iteraciones_a_priori(gamma, np.max(np.abs(bellman(V0) - V0)), tol)

# referencia exacta: con la política voraz, V* resuelve el sistema lineal (I - γ P_π) V = R_π
pi = (R + gamma * np.einsum("ast,t->sa", P, V)).argmax(axis=1)
P_pi = P[pi, np.arange(3)]
R_pi = R[np.arange(3), pi]
V_star = np.linalg.solve(np.eye(3) - gamma * P_pi, R_pi)
k_real = next(i for i, W in enumerate(hist) if np.max(np.abs(W - V_star)) < tol)
print("política óptima:", ["esperar" if a == 0 else "avanzar" for a in pi])
print("V* =", np.round(V_star, 6))
print(f"a priori: {k_prev}   a posteriori: k = {k}   error real < tol desde k = {k_real}")
print(f"cota certificada {cota:.2e}   error real {np.max(np.abs(V - V_star)):.2e}")
paso = [np.max(np.abs(hist[i + 1] - hist[i])) for i in range(len(hist) - 1)]
print("cociente de pasos al final:", round(paso[-1] / paso[-2], 4))
print(f"‖γ P_π‖_∞ = {np.abs(gamma * P_pi).sum(axis=1).max():.3f}   ‖γ P_π‖_2 = {np.linalg.norm(gamma * P_pi, 2):.3f}")

Here all three numbers agree: 160 iterations a priori, 160 a posteriori and 160 actual, and the certified bound equals actual error. This is no coincidence. The optimal policy stays forever in state 2, paying 2 per step, so Vk(2)=2(1+γ+⋯+γk−1)V_k(2) = 2(1 + \gamma + \cdots + \gamma^{k-1}) and error in that state is exactly 20γk20\gamma^k, what both bounds say. This MDP is the theorem’s worst case: actual rate is γ\gamma and the bounds cannot be improved. The last line confirms that policy evaluation is a contraction in ℓ∞\ell_\infty with constant 0.90.9 but not in ℓ2\ell_2, where the induced norm is 1.2141.214.

With libraries: scipy.optimize.fixed_point

SciPy provides scipy.optimize.fixed_point(func, x0, xtol=1e-08, maxiter=500, method='del2'). By default it does not merely iterate gg: it applies Steffensen acceleration. At each step it calculates p1=g(p0)p_1 = g(p_0) and p2=g(p1)p_2 = g(p_1) and jumps to

p=p0−(p1−p0)2p2−2p1+p0,p = p_0 - \frac{(p_1 - p_0)^2}{p_2 - 2p_1 + p_0},

Aitken’s Δ2\Delta^2 extrapolation, exact if errors decreased in an exact geometric progression. If gg is class C2C^2 near x∗x^* and g′(x∗)≠1g'(x^*) \neq 1, convergence order is 2, at the price of two evaluations of gg per step. It stops when relative step ∣p−p0∣/∣p0∣\abs{p - p_0}/\abs{p_0} falls below xtol. Measure observed order log⁡(ek+1/ek)/log⁡(ek/ek−1)\log(e_{k+1}/e_k)/\log(e_k/e_{k-1}) by recording where gg is evaluated.

[ ]SciPy: Steffensen versus simple iterationBrowser
from scipy.optimize import fixed_point as fixed_point_scipy

def registrar(g):
    """Envuelve g para guardar cada punto en el que se evalúa."""
    llamadas = []
    def h(x):
        llamadas.append(float(x))
        return g(x)
    return h, llamadas

def orden_observado(errores):
    """p_k = log(e_{k+1}/e_k) / log(e_k/e_{k-1}): tiende al orden de convergencia."""
    e = [x for x in errores if x > 0]
    return [round(math.log(e[i + 1] / e[i]) / math.log(e[i] / e[i - 1]), 2) for i in range(1, len(e) - 1)]

kepler = lambda E: 1.0 + 0.5 * math.sin(E)      # E_ref viene de la primera celda

for metodo in ["iteration", "del2"]:
    h, llamadas = registrar(kepler)
    E = fixed_point_scipy(h, 1.0, xtol=1e-14, method=metodo)
    paso = 1 if metodo == "iteration" else 2          # Steffensen evalúa g dos veces por paso
    errores = [abs(x - E_ref) for x in llamadas[::paso]]
    print(f"{metodo:9s} evaluaciones de g: {len(llamadas):2d}   error final {abs(E - E_ref):.1e}")
    print("          errores:", [f"{x:.1e}" for x in errores[:6]])
    print("          orden observado:", orden_observado(errores[:6]))

# Steffensen no necesita una contracción: converge al punto fijo repulsor de la logística
logistica = lambda x: 3.5 * x * (1 - x)
x = fixed_point_scipy(logistica, 0.3, xtol=1e-12)
print(f"\nlogística r = 3.5, del2: x = {x:.12f}   (1 - 1/r = {1 - 1/3.5:.12f}, |g'(x*)| = 1.5)")

# ... y puede «converger» donde no hay ningún punto fijo
g_sin = lambda x: x + 1 / x
x_falso = fixed_point_scipy(g_sin, 1.0)
print(f"x + 1/x, del2: devuelve x = {x_falso:.2f}   con g(x) - x = {g_sin(x_falso) - x_falso:.1e}")

Three results, each with a lesson:

  • Order. For Kepler, simple iteration has observed order 1 (errors divide by about 27 each step, the reciprocal of 0.0360.036) and Steffensen order 2: it goes from 10−210^{-2} to 10−610^{-6} to 10−1410^{-14}. With 8 evaluations of gg it reaches machine precision; simple iteration needs 11 for the same tolerance. When gg is expensive (a simulation step, policy evaluation), the difference matters.
  • The logistic map with r=3.5r = 3.5. Simple iteration never reaches x∗=0.714285…x^* = 0.714285\ldots because it repels, and falls into the period-4 cycle from the cobweb. Steffensen converges to it. Acceleration is not fixed-point iteration of gg but a secant-type method applied to g(x)−x=0g(x) - x = 0, and does not require gg to contract. In exchange it loses Banach’s global guarantee.
  • x+1/xx + 1/x, which has no fixed point. SciPy returns 18296.7718296.77 without warning. Steffensen iterates roughly double each step until denominator p2−2p1+p0≈−1/p03p_2 - 2p_1 + p_0 \approx -1/p_0^3 rounds to 0 in floating point; SciPy then takes p=p2p = p_2, the relative step is 2/p02≈6×10−9<10−82/p_0^2 \approx 6\times 10^{-9} < 10^{-8} and the criterion is satisfied. A small step is not a certificate. q/(1−q)q/(1 - q) times the step is one, and only if q<1q < 1 is a proven contraction constant.

For systems, fixed_point accepts arrays and accelerates each component separately. For large problems (Picard on a grid, fixed points of implicit networks), Anderson acceleration combines several earlier iterates and is available in scipy.optimize.anderson. Their analysis is in fixed-point iterations in numerical methods.

Common mistakes

Exercises

ProofExistence and uniqueness in Banach's theorem
Prove: Let (X,d)(X, d) be a nonempty complete metric space and g:X→Xg: X \to X with d(g(x),g(y))≤q d(x,y)d(g(x), g(y)) \le q\,d(x, y) for a constant q∈[0,1)q \in [0, 1). Then gg has a unique fixed point, and iterates xk+1=g(xk)x_{k+1} = g(x_k) converge to it from any x0x_0.
0
Fix x0∈Xx_0 \in X and define xk+1=g(xk)x_{k+1} = g(x_k).

Step 1 of 4. How do you control distance between consecutive iterates?

NumericGuaranteed iterations for Kepler
Kepler's equation with e=0.5e = 0.5 and M=1M = 1: iterate Ek+1=M+esin⁡EkE_{k+1} = M + e\sin E_k from E0=ME_0 = M, a contraction of constant q=eq = e. Using a priori bound qk ∣E1−E0∣/(1−q)q^k\,\abs{E_1 - E_0}/(1 - q), what is the smallest iteration count kk guaranteeing error below 10−1010^{-10}?
QuizAlmost a contraction
Function g(x)=x+1/xg(x) = x + 1/x on X=[1,∞)X = [1, \infty) satisfies ∣g(x)−g(y)∣<∣x−y∣\abs{g(x) - g(y)} < \abs{x - y} for every x≠yx \neq y. Does it have a fixed point, and what does Banach's theorem say?
QuizWhich sets are compact?
Which sets are compact under the indicated metric?

More than one answer may be correct.

QuizUniform continuity
Which functions are uniformly continuous on the indicated domains?

More than one answer may be correct.

NumericWhat a small step is worth
Value iteration with γ=0.99\gamma = 0.99: two consecutive iterates differ by ∥Vk−Vk−1∥∞=10−4\norm{V_k - V_{k-1}}_\infty = 10^{-4}. What bound does Banach's theorem guarantee for ∥Vk−V∗∥∞\norm{V_k - V^*}_\infty?
NumericA tailored norm
Let A=[0.51.500.5]\mat{A} = \begin{bmatrix} 0.5 & 1.5 \\ 0 & 0.5 \end{bmatrix} and ∥x∥w=max⁡(∣x1∣,w∣x2∣)\norm{\vb{x}}_w = \max(\abs{x_1}, w\abs{x_2}) with w>0w > 0. Iteration x↦Ax+b\vb{x} \mapsto \mat{A}\vb{x} + \vb{b} is a contraction in ∥⋅∥w\norm{\cdot}_w exactly for w>w0w > w_0. What is w0w_0?
ProofContinuous image of a compact set and extreme values
Prove: If f:X→Yf: X \to Y is continuous and K⊆XK \subseteq X compact, then f(K)f(K) is compact. In particular, if K≠∅K \neq \emptyset and Y=RY = \mathbb{R}, ff attains its maximum on KK.
0
Use the sequential definition: show every sequence in f(K)f(K) has a subsequence converging to a point of f(K)f(K).

Step 1 of 3. Take a sequence (yk)(y_k) in f(K)f(K). What is the first step?

CodeContractive in which norm?
Implement is_contraction_affine(A, norm), deciding whether x↦Ax+b\vb{x} \mapsto \mat{A}\vb{x} + \vb{b} is a contraction in norm ℓ1\ell_1, ℓ2\ell_2 or ℓ∞\ell_\infty of Rn\mathbb{R}^n (norm is 1, 2 or np.inf). Return a tuple (es_contraccion, q) with induced norm q of A\mat{A} and q < 1. Compute each induced norm using its formula (column sums, singular values, row sums) rather than calling np.linalg.norm(A, ord). If A is not square or norm is not one of the three, raise ValueError.
import numpy as np

def is_contraction_affine(A, norm):
  """Devuelve (es_contraccion, q), con q la norma inducida de A en l1, l2 o linf."""
  A = np.asarray(A, dtype=float)
  # tu código: comprueba la forma, calcula q según norm y compáralo con 1
  q = max(abs(np.linalg.eigvals(A)))      # ¡el radio espectral no es una norma inducida!
  return bool(q < 1), float(q)
Shift+Enter to run

Summary

Key idea
A contraction on a complete metric space has a unique fixed point, iteration reaches it from anywhere and each step brings its own error certificate, q/(1−q)q/(1 - q) times the step; compactness, by contrast, guarantees a continuous function attains its maximum. Both ideas apply to numbers, vectors and functions, but in infinite dimensions “closed and bounded” stops being compact, and in any dimension contraction depends on the norm.
  • A metric space is a set with a distance satisfying separation, symmetry and triangle inequality. ℓp\ell_p norms with p≥1p \ge 1 induce metrics; for p<1p < 1 the ball ceases to be convex and the triangle inequality fails. In Rn\R^n all norms are equivalent, with constants depending on nn.
  • Closed sets contain limits of their sequences, and ff is continuous if and only if preimages of open sets are open.
  • Compact means every sequence has a subsequence converging inside. In Rn\R^n it is equivalent to closed and bounded (Heine–Borel); in ℓ2\ell^2 the unit ball is closed and bounded but not compact.
  • On a compact set every continuous function attains a maximum and minimum (Weierstrass) and is uniformly continuous (Heine–Cantor). With coercivity this gives existence of minimizers.
  • Complete means Cauchy sequences converge: Rn\R^n and C[a,b]C[a, b] with supremum norm are complete; Q\Q and (0,1](0, 1] are not.
  • Banach: a contraction on a complete space implies a unique fixed point, linear convergence with rate qq and bounds qkd(x1,x0)/(1−q)q^k d(x_1, x_0)/(1 - q) and q d(xk,xk−1)/(1−q)q\,d(x_k, x_{k-1})/(1 - q). The local rate is ∣g′(x∗)∣\abs{g'(x^*)}; if 0, convergence is quadratic, as in Newton.
  • x↦Ax+b\vb{x} \mapsto \mat{A}\vb{x} + \vb{b} contracts in a norm if and only if the induced norm is below 1, and such a norm exists if and only if ρ(A)<1\rho(\mat{A}) < 1. The Bellman operator contracts by factor γ\gamma in the supremum norm, so value iteration converges.