# Continuity over a compact subset of a metric space implies continuity everywhere

Let $f: (X, d_X) \rightarrow (Y, d_Y)$ be a function from metric spaces. If $f$ restricted to any compact subset of $X$ is continuous, then $f$ must be continuous everywhere.

Should I proceed with the characterization of continuity that the preimage of a closed set is closed? Except we are working with compact subsets of the domain, not the range, and it is not true that closed sets are mapped to closed sets, so how can I get continuity of $f$ everywhere?

I am also thinking about the fact that compactness is equivalent to sequential compactness in a metric space. Would this help?

• Did you mean to write dense subset of a metric space? – Dalton Apr 11 '15 at 20:02
• No, I believe it's supposed to be compact. Wikipedia has the same statement here: en.wikipedia.org/wiki/Metric_space#Continuous_maps - "f is continuous if and only if it is continuous on every compact subset of M1" – cappuccino Apr 11 '15 at 20:04
• Single points are compact. Are you saying that any function continuous at a single point is automatically continuous everywhere? – Adam Hughes Apr 11 '15 at 20:05
• The question should say "$f$ restricted to any compact set". – user21467 Apr 11 '15 at 20:06
• You are missing a crucial part of the hypothesis, namely that $f$ is continuous when restricted to every compact sunspace of $X$, not just a single compact subspace. – Dalton Apr 11 '15 at 20:06

Let $C$ be a closed subset of $Y$ and let $x\in\overline{f^{-1}(C)}$.

There exists a sequence $(x_n)$ in $f^{-1}(C)$ that converges to $x$. The set $S=\{x_n:n\ge0\}\cup\{x\}$ is compact, so $f$ is continuous on $S$. Therefore $\lim_{n\to\infty}f(x_n)=f(x)$ and, since $C$ is closed, we have that $f(x)\in C$. Hence $x\in f^{-1}(C)$.

This is false, but as I've commented I believe it is due only to a typo in the original post. The true statement would be to say

If $f$ restricted to every compact subset of $X$ is continuous, then $f$ must be continuous everywhere.

The trivial counter example to your original statement would be something along the lines of: let $f : \mathbb{R} \rightarrow \mathbb{R}$ be identically the zero map on $[0, 1]$, and elsewhere $f(r) = 0$ for every rational number $r$ and $f(x) = 1$ for every irrational number $x$.

Hint: a convergent sequence together with its limit point is a compact set.

Further hint: Also, continuity at a point is equivalent to continuity along (all) sequences converging to that point.

• I've thought about this as well, but am not really sure it is useful. I know that compact sets map to compact sets under continuous functions, but how does that help me characterize continuity over the entire space? – cappuccino Apr 11 '15 at 20:13
• This does not suffice to prove the original statement. In fact, the original statement is false. If you meant to answer the corrected statement, then yes it does work as a strategy for proof. – Dalton Apr 11 '15 at 20:14