# If the image of a particular compact set under the function f is compact, is f continuous?

I know that the continuous images of compact sets are compact, but if we know a mapping f that maps a particular compact set into a compact set, is the mapping continuous? What if f is a real function?

-
Let $f(x)=2x$ for $0\le x\le 1/2$, $f(x)=0$ for $1/2<x\le 1$. Then $f$ maps $[0,1]$ to $[0,1]$. – André Nicolas Jan 21 '12 at 2:41
This is too strong to be true. Certainly there are "wild" functions mapping $[0,1]$ onto $[0,1]$. – Srivatsan Jan 21 '12 at 2:41
Thank you! I was actually thinking about a problem in Baby Rudin: chapter 4, problem 6: Suppose E is compact, prove that f is continuous on E if and only if {(x,f(x)), $x \in E$} is compact. I am not sure if the conclusion is correct. Suppose this conclusion is true, now if E compact, f(E) compact, then {(x,f(x)), $x \in E$} should be compact, then f is continuous? What went wrong in my argument? – Yang Jan 21 '12 at 2:56
@Yang: $E$ and $f(E)$ can be compact without the graph of $f$ being compact. E.g., restrict Neal's example to the closed unit interval $[0,1]$. Then the graph is $\{(x,1):x\in\mathbb Q\}\cup\{(x,0):x\in(\mathbb R\setminus Q)\}$. This is not even a closed subset of $\mathbb R$, because for example $(1/(n\pi),0)$ is in the graph but converges to $(0,0)$ as $n\to \infty$, and $(0,0)$ is not in the graph. It is true that the graph is contained in the compact set $E\times f(E)$, but to be compact it must be closed (I'm assuming $T_2$, but we're probably talking metric spaces in Baby Rudin). – Jonas Meyer Jan 21 '12 at 3:41
See the question Characterising Continuous functions for interesting generalizations. – Jonas Meyer Jan 21 '12 at 3:46

Absolutely not. Consider the real function $f:\mathbb{R}\to\mathbb{R}$ defined by $f(x)=1$, $x\in\mathbb{Q}$, otherwise $f(x)=0$. Every compact set (in fact, every subset of $\mathbb{R}$) is mapped onto one of the compact sets $\emptyset$, $\{0\}$, $\{1\}$, or $\{0,1\}$, but the function $f$ is nowhere continuous.

(Edit: corrected small error, and remove "non-empty" -- thank you, Pierre)

-
Dear Neal: The empty set is compact. – Pierre-Yves Gaillard Jan 21 '12 at 5:02
Argh! Fixing for even greater generality. – Neal Jan 21 '12 at 13:17

The exercise in Rudin is correct. Suppose $\lim x_n=x$. Consider the sequence $(x_n,f(x_n))$ since the set $\{(x,f(x)): x\in E\}$ is compact there exists a convergent subsequence $(x_{n_k},f(x_{n_k}))$ which converges to $(x,y)$. Since the point $(x,y)$ is in the set $\{(x,f(x)): x\in E\}$, then $y=f(x)$. The problem in your argument is that $E$ and $f(E)$ compact does not imply that the graph $\{(x,f(x)):x\in E\}$ is compact.

-
I think you have only shown that $f(x_{n_k})$ converges to $f(x)$. How do you know then that $f(x_n)$ must converge to $x$? – user38268 Apr 15 '12 at 11:31
@BenjaminLim The argument above shows that $limsup f(x_n)=liminf f(x_n)$. – azarel Apr 15 '12 at 14:50