linguistic:translation, stylistic:tone
Generalization to metric and topological spaces

When moving from the real line R {\displaystyle \mathbb {R} } to metric spaces and general topological spaces, the appropriate generalization of a closed bounded interval is a compact set. A set K {\displaystyle K} is said to be compact if it has the following property: from every collection of open sets U α {\displaystyle U_{\alpha }} such that ⋃ U α ⊃ K {\textstyle \bigcup U_{\alpha }\supset K}, a finite subcollection U α 1, …, U α n {\displaystyle U_{\alpha _{1}},\ldots,U_{\alpha _{n}}} can be chosen such that ⋃ i = 1 n U α i ⊃ K {\textstyle \bigcup _{i=1}^{n}U_{\alpha _{i}}\supset K}. This is usually stated in short as "every open cover of K {\displaystyle K} has a finite subcover". The Heine–Borel theorem asserts that a subset of the real line is compact if and only if it is both closed and bounded. Correspondingly, a metric space has the Heine–Borel property if every closed and bounded set is also compact.

The concept of a continuous function can likewise be generalized. Given topological spaces V, W {\displaystyle V,\ W}, a function f: V → W {\displaystyle f:V\to W} is said to be continuous if for every open set U ⊂ W {\displaystyle U\subset W}, f − 1 (U) ⊂ V {\displaystyle f^{-1}(U)\subset V} is also open. Given these definitions, continuous functions can be shown to preserve compactness:

Theorem — If V, W {\displaystyle V,\ W} are topological spaces, f: V → W {\displaystyle f:V\to W} is a continuous function, and K ⊂ V {\displaystyle K\subset V} is compact, then f (K) ⊂ W {\displaystyle f(K)\subset W} is also compact.

In particular, if W = R {\displaystyle W=\mathbb {R} }, then this theorem implies that f (K) {\displaystyle f(K)} is closed and bounded for any compact set K {\displaystyle K}, which in turn implies that f {\displaystyle f} attains its supremum and infimum on any (nonempty) compact set K {\displaystyle K}. Thus, we have the following generalization of the extreme value theorem:

Theorem — If K {\displaystyle K} is a nonempty compact set and f: K → R {\displaystyle f:K\to \mathbb {R} } is a continuous function, then f {\displaystyle f} is bounded and there exist p, q ∈ K {\displaystyle p,q\in K} such that f (p) = sup x ∈ K f (x) {\displaystyle f(p)=\sup _{x\in K}f(x)} and f (q) = inf x ∈ K f (x) {\displaystyle f(q)=\inf _{x\in K}f(x)}.

Slightly more generally, this is also true for an upper semicontinuous function. (see compact space#Functions and compact spaces).