Search

Search papers and lessons

Compact Set

Level 2 · 9 min read

A compact set is one where every covering by open sets can be trimmed to finitely many of them, which guarantees that continuous functions on it reach a largest and smallest value.

On this page

  • Colour = topic mix
  • Discrete math
  • ReadReady to readNot yet

TL;DR

A set KK in a metric space is compact when every collection of open sets that covers KK has a finite part that still covers KK. The definition says nothing about size, but it forces a set to have no escape routes: it cannot be spread out endlessly or have a missing endpoint that a cover can slip past. Compactness is what guarantees that a continuous function on KK reaches a largest and a smallest value.

Builds on: Open Set, Bounded Set · Leads to: Universal Approximation Theorem, and the extreme value theorem for continuous functions

Where it's used

Choosing the best design. An engineer who tunes a process over a closed range of settings, say a mixing fraction between 0 and 1, wants a best setting to exist before searching for it. If the quality measure is continuous and the range is compact, the extreme value theorem guarantees a maximum and a minimum. The search can then be about finding them, not about whether they exist.

Neural networks. The universal approximation theorem for neural networks is usually stated for functions on a compact input set, such as a closed and bounded box of inputs. Compactness there gives the uniform control needed to approximate the function well everywhere on the box.

Checking compactness in Rn\mathbb{R}^n. The Heine–Borel theorem says that in ordinary space Rn\mathbb{R}^n, a set is compact exactly when it is closed and bounded. Most practical checks therefore reduce to two easy tests, instead of testing every possible cover.

How it works

Take the closed interval K=[0,1]K = [0, 1] on the real line. A cover of KK is a family of sets whose union contains KK. Here is one cover by open intervals:

  • U1=(−0.1,0.4)U_1 = (-0.1, 0.4)
  • U2=(0.3,0.7)U_2 = (0.3, 0.7)
  • U3=(0.6,1.1)U_3 = (0.6, 1.1)
  1. Check that it covers. Points from 0 up to 0.4 lie in U1U_1, points from 0.3 to 0.7 lie in U2U_2, and points from 0.6 to 1 lie in U3U_3. Every point of [0,1][0, 1] is in at least one set. Check: 0.35 lies in U1U_1 and U2U_2, so overlaps are allowed.

  2. Start from one end. The point 0 lies in U1U_1. The rightmost reach of U1U_1 is 0.4, which is not in U1U_1 itself, so the next set must cover 0.4. The point 0.4 lies in U2U_2, since 0.3<0.4<0.70.3 \lt 0.4 \lt 0.7.

  3. Keep going. U2U_2 reaches up to 0.7, which is not in U2U_2. The point 0.7 lies in U3U_3, since 0.6<0.7<1.10.6 \lt 0.7 \lt 1.1. Now U3U_3 reaches 1.1, which is past the end of KK.

  4. Read off the finite subcover. The three sets U1U_1, U2U_2, U3U_3 together cover KK. Check: dropping U2U_2 would leave 0.5 uncovered, since U1U_1 stops at 0.4 and U3U_3 starts at 0.6. The subcover is finite, which is all the definition asks for.

flowchart LR
    A["Any open cover of K"] --> B["Start at one end of K"]
    B --> C["Pick a set that covers the current point"]
    C --> D{"Does the chosen reach cover the end of K?"}
    D -- no --> C
    D -- yes --> E["A finite subcover: compact"]

This walkthrough checked one cover. Compactness needs every cover to pass, and the proof for [0,1][0, 1] does this for all covers at once.

The math

Definition: Compact set

Let (X,d)(X, d) be a metric space and K⊆XK \subseteq X. A family {Uα}\{U_\alpha\} of open sets is an open cover of KK when K⊆⋃αUαK \subseteq \bigcup_\alpha U_\alpha. The set KK is compact when every open cover of KK has a finite subfamily Uα1,…,UαnU_{\alpha_1}, \ldots, U_{\alpha_n} with K⊆Uα1∪⋯∪UαnK \subseteq U_{\alpha_1} \cup \cdots \cup U_{\alpha_n}.

Here ⋃αUα\bigcup_\alpha U_\alpha means the set of all points that lie in at least one UαU_\alpha. A finite subfamily is a choice of finitely many of the sets, though the cover itself may be infinite.

Step 1 in symbols: the cover

For the example, K=[0,1]K = [0, 1] and the cover is {U1,U2,U3}\{U_1, U_2, U_3\}. Each UiU_i is an open interval, hence an open set, and K⊆U1∪U2∪U3=(−0.1,1.1)K \subseteq U_1 \cup U_2 \cup U_3 = (-0.1, 1.1).

Step 2 in symbols: the finite subcover

The subfamily {U1,U2,U3}\{U_1, U_2, U_3\} is finite and covers KK. Here no set can be removed, since removing U2U_2 leaves 0.5∉U1∪U30.5 \notin U_1 \cup U_3.

Step 3 in symbols: the Heine–Borel test

In Rn\mathbb{R}^n, KK is compact exactly when KK is closed (it contains all its limit points) and bounded (it lies inside some ball B(x0,R)B(x_0, R) of finite radius). The interval [0,1][0, 1] is closed and bounded, so it is compact.

Step 4 in symbols: the extreme value theorem

If KK is compact and f:K→Rf : K \to \mathbb{R} is continuous, then ff attains a maximum and a minimum on KK. That is, there are points a,b∈Ka, b \in K with f(a)≤f(x)≤f(b)f(a) \le f(x) \le f(b) for every x∈Kx \in K. This is the reason compactness matters in optimisation.

Worked examples

Example
Example 1: a finite set

Let K={1,2,3}K = \{1, 2, 3\} in the real line, and take any open cover of KK.

  1. Some set UaU_a in the cover contains 1. Pick one.
  2. Some set UbU_b contains 2. Pick one.
  3. Some set UcU_c contains 3. Pick one.
  4. The three chosen sets, UaU_a, UbU_b, UcU_c, cover KK, and there are three of them.

Check: three is a finite number, so the cover has a finite subcover. Every finite set is compact by this argument.

Example
Example 2: the standard case, the closed interval

Use the cover U1=(−0.1,0.4)U_1 = (-0.1, 0.4), U2=(0.3,0.7)U_2 = (0.3, 0.7), U3=(0.6,1.1)U_3 = (0.6, 1.1) of [0,1][0, 1] from "How it works".

  1. Verify the cover: the three intervals together contain (−0.1,1.1)⊇[0,1](-0.1, 1.1) \supseteq [0, 1].
  2. Find the subcover by the walkthrough: start at 0, then 0.4, then 0.7. Three sets are used.
  3. Confirm it is finite: 3 sets, so it is finite.
  4. Confirm the Heine–Borel test agrees: [0,1][0, 1] is closed and bounded, so it is compact.

Check: the finite subcover exists, and the closed and bounded test gives the same answer.

Example
Example 3: a realistic maximum

A process has quality g(x)=2x−x2g(x) = 2x - x^2, where xx is the mixing fraction, and xx is only allowed to range over [0,1][0, 1]. Find the best setting.

  1. The set K=[0,1]K = [0, 1] is closed and bounded, so it is compact.
  2. The function gg is a Polynomial, so it is continuous.
  3. Compactness and continuity guarantee a largest value of gg on KK. Find it.
  4. Differentiate: g′(x)=2−2xg'(x) = 2 - 2x. On [0,1)[0, 1) this is positive, so gg is still rising.
  5. Compare the endpoints: g(0)=0g(0) = 0 and g(1)=2−1=1g(1) = 2 - 1 = 1.
  6. The largest value is 1, reached at x=1x = 1. The best setting is therefore the full mixing fraction, x=1x = 1, and no interior setting does better.

Try it: the function h(x)=x(1−x)h(x) = x(1 - x) on [0,1][0, 1] has a maximum. Where is it, and what is its value?

Answer: h′(x)=1−2xh'(x) = 1 - 2x is zero at x=12x = \tfrac{1}{2}, and h(12)=12⋅12=14h(\tfrac{1}{2}) = \tfrac{1}{2} \cdot \tfrac{1}{2} = \tfrac{1}{4}. The endpoints give h(0)=h(1)=0h(0) = h(1) = 0, so the maximum is 14\tfrac{1}{4}, at x=12x = \tfrac{1}{2}.

Common mistakes and tradeoffs

It is tempting to think compact means small. In fact a compact set can be very large: [0,1000000][0, 1000000] is compact. Compactness is about covers, not size.

It is tempting to think bounded is enough. In fact the open interval (0,1)(0, 1) is bounded but not compact. Take the open cover {(1/n,1):n≥2}\{(1/n, 1) : n \ge 2\}. Every finite part of it has the form (1/N,1)(1/N, 1) for some NN, which misses the points between 0 and 1/N1/N. So no finite subcover exists. The cover fails because the set has an endpoint, 0, that is not in it.

It is tempting to think one cover with a finite subcover proves compactness. In fact the definition asks for every open cover. The walkthrough above is an example, not a proof.

It is tempting to think closed and bounded is the definition. In fact that is only the Heine–Borel theorem in Rn\mathbb{R}^n. In infinite-dimensional spaces a closed and bounded set need not be compact, so the general definition must be used there.

When to use it: when you need a maximum or minimum to exist, or a property to hold uniformly over a set. When not to use it: for small finite problems, where a direct check is simpler, and for spaces where the closed and bounded test fails and the cover definition is hard to verify. Alternative: in a metric space, compactness is equivalent to sequential compactness, where every sequence in KK has a subsequence converging inside KK. Proofs that work with sequences are often easier, and the Sequence lesson covers the tools.

History

Eduard Heine proved in 1872 that a continuous function on a closed interval is uniformly continuous. Émile Borel gave the covering statement for intervals in 1895, and the result is now named after Heine and Borel. Henri Lebesgue extended the covering idea in the early 1900s. In the 1920s Pavel Alexandroff and Paul Urysohn defined compact spaces in general topology, which made compactness a standard tool in analysis and geometry.

Recap

  • A compact set is one where every open cover has a finite subcover, which is a property about covers, not size.
  • Open intervals with endpoints missing, and unbounded sets, fail to be compact.
  • In Rn\mathbb{R}^n, compact means closed and bounded (Heine–Borel).
  • A continuous function on a compact set attains a maximum and a minimum (extreme value theorem).
  • Read next: Continuity for the functions this result applies to, and Universal Approximation Theorem for an application to neural networks.

Check yourself

QuestionIs the set {2,4,6,8}\{2, 4, 6, 8\} compact? Explain in one sentence.Show answer

Yes. Any open cover has an open set containing each of its four points, so picking one set per point gives a finite subcover. A finite set is always compact.

QuestionCompute the largest value of f(x)=x2f(x) = x^2 on the closed interval [−2,3][-2, 3], and say which theorem guarantees it exists.Show answer

The largest value is f(3)=9f(3) = 9, since x2x^2 grows as ∣x∣|x| grows and ∣−2∣<3|-2| \lt 3. The extreme value theorem guarantees it, because [−2,3][-2, 3] is closed and bounded, hence compact, and x2x^2 is continuous.

QuestionWhy does compactness fail for (0,1)(0, 1), even though the set is bounded?Show answer

Compactness needs every open cover to have a finite subcover. The cover {(1/n,1):n≥2}\{(1/n, 1) : n \ge 2\} has no finite subcover, because any finite part is (1/N,1)(1/N, 1) for some NN. The point 1/(2N)1/(2N) lies in (0,1)(0, 1) but not in (1/N,1)(1/N, 1), so it is missed. The set has an endpoint, 0, that is not in it, so the cover can get arbitrarily close to 0 without ever containing it.

QuestionA researcher says the closed unit ball in R3\mathbb{R}^3 must be compact because it is closed and bounded. Is the reasoning valid, and why?Show answer

Yes. In Rn\mathbb{R}^n, the Heine–Borel theorem says a set is compact exactly when it is closed and bounded, so the closed unit ball in R3\mathbb{R}^3 is compact. The same reasoning does not carry over to infinite-dimensional spaces, where closed and bounded sets need not be compact.

Sources