# Given that $f(E)$ is compact if and only if $E$ is, can we deduce the continuity of $f$?

Let $(X_1,d_1)$ and $(X_2,d_2)$ be metric spaces. A criterion for the global continuity of some $f:X_1\to X_2$ is that for all closed $E\subseteq X_2$, $f^{-1}(E)$ is closed. This is a corollary of the analogous theorem for counterimages of open subsets of the codomain.

Another necessary condition is that the image of any compact subset of $X_1$ be compact. But it is not sufficient: e.g. in $\mathbb{R}$, $$f(x)= \begin{cases} x & x\ge 0\\ \sin\frac1x & x <0 \end{cases}$$ satisfies it, but it is discontinuous in $x_0=0$. I noticed that, on the other hand, $f((-1,1))=[-1,1]$ so I tried strengthening the condition, i.e. requiring the preimage of any compact subset of $X_2$ to be compact.

Vacuously, it works if $X_1$ and $X_2$ are discrete and finite because then all of their subsets are compact and $f$ is continuous in every point of $X_1$ because each one is isolated. By contrapositive, I think I have proved it also for $X_1\subseteq\mathbb{R}=X_2$, considering a point of discontinuity of the different kinds (except removable discontinuites not included in the domain, since thus the function is still continuous on it). I haven't really tried to generalise, so here's the question:

Let $(X_1,d_1)$ and $(X_2,d_2)$ be metric spaces. Let $f:X_1\to X_2$ be such that for all $E\subseteq X_1$, $f(E)$ is compact if and only if $E$ is. Must $f$ be continuous?

Yes, $f$ must be continuous. For metric spaces, continuity is equivalent to sequential continuity (this requires some choice, but topology without choice is very strange, so we assume choice anyway).

So suppose that $X_1, X_2$ are metric spaces, and $f \colon X_1 \to X_2$ is not continuous at $p$. Then there is a sequence $(x_n)_{n\in\mathbb{N}}$ in $X_1 \setminus \{p\}$ and an $\varepsilon > 0$ such that $x_n \to p$ and $d_2(f(x_n),f(p)) \geqslant \varepsilon$ for all $n$. The set $A := \{ x_n : n \in \mathbb{N}\}$ is not compact, while $A \cup \{p\}$ is compact. But since $f(p)$ has positive distance from $f(A)$, the set $f(A)$ is compact if and only if $f(A) \cup \{f(p)\} = f(A\cup \{p\})$ is compact. So either we have found a compact set whose image isn't compact, or we have found a non-compact set whose image is compact.

• well you beet me up, in frustration I posted a half answer with messed up math formatting, just to show I got it too :) Will try to complete it without reading the details in your answer (which seems somewhat shorter than what mine would be). – Mirko May 29 '17 at 22:29
• So, with $E=A \cup \{p\}$, $E$ is compact, hence (by OP assumption) $f(E)= f(A\cup \{p\})=f(A) \cup \{f(p)\}$ is compact, hence (as you have crucially observed, which took me some time to digest) $f(A)$ is compact, contradicting that $A$ is not. ($f(A)$ is compact as a relatively closed subspace of $f(E)$.) Just a rephrasing of what you say, to make it easier for me to follow. My answer says essentially the same, only in a longer roundabout way. – Mirko May 29 '17 at 23:07
• Essentially yes. But I made a proof via the contrapositive, not by contradiction, so I don't use the hypothesis $E\text{ compact} \iff f(E) \text{ compact}$. I show that if $f$ isn't continuous, that property doesn't hold. It's open whether $f(A)$ is compact or $f(A\cup \{p\})$ is non-compact. Now let me read your answer. – Daniel Fischer May 29 '17 at 23:16
• >= \epsilon for all n needs to be changed to infinitely many n ; p must be removed from A, from the x sequence. – William Elliot May 30 '17 at 4:07
• @Mirko: Thank you both! Nice that the proof is still by contrapositive. – Vincenzo Oliva May 30 '17 at 5:22

The answer is yes. Suppose to the contrary that $f$ were discontinuous, then there is a sequence $x_n\to x$ in $X_1$ such that $f(x_n)\not\to f(x)$ in $X_2$. Then there is some $\varepsilon>0$ such that there are infinitely many $n$ with $d_2(f(x_n),f(x))\ge\varepsilon$. Taking a subsequence of the $x_n$ we may assume that $d_2(f(x_n),f(x))\ge\varepsilon$ for all $n$. Consider two cases.

Case 1. The set $\{f(x_n):n\in\mathbb N\}$ is finite. Then let $E=\{x_n:n\in\mathbb N\}$. It is easy to see that $E$ is not compact (as it is missing its limit point $x$), but $f(E)$ is compact since it is finite.

Case 2. The set $\{f(x_n):n\in\mathbb N\}$ is infinite. Then (reverting to a subsequence) we may assume that $f(x_n)\not=f(x_m)$ if $n\not=m$. Let $E=\{x\}\cup\{x_n:n\in\mathbb N\}$. Then $E$ is compact, hence by assumption $f(E)$ is compact. Since $\{f(x_n):n\in\mathbb N\}\subseteq f(E)$, the sequence $\langle f(x_n):n\in\mathbb N\rangle$ must have a convergent subsequence with limit some $y\in f(E)$, say $f(x_{n_k})\to y$ as $k\to\infty$. Clearly $d_2(y,f(x))\ge\varepsilon$ so $y\not=x$. Since all $f(x_n)$ are different we may assume that $y\not\in\{f(x_{n_k}):\in\mathbb N\}$ (if $y=f(x_{n_m})$ for some $m$, then $m$ is unique and we may throw out $x_{n_m}$.) Now take $C=\{x\}\cup\{x_{n_k}:k\in\mathbb N\}$. Clearly $x_{n_k}\to x$ as $k\to\infty$, hence $C$ is compact. Then $f(C)$ is not compact as it does not contain the limit point $y$.

(Now let me read the shorter answer by Daniel Fisher who beat me up with 22 min :) (Thank you also for pointing out inaccuracies in my answer!)

• Two things: first you have a typo, sunsequence. Second, you should state that you choose a subsequence $(x_{n_k})$ such that all $f(x_{n_k})$ are distinct, so that it cannot happen that $y = f(x_{n_k})$ for infinitely many $k$. – Daniel Fischer May 29 '17 at 23:22
• @DanielFischer Thank you, I corrected it in a slightly different way, stating that we may assume all $f(x_n)$ different. – Mirko May 29 '17 at 23:47