Prove that this function defined over $ \mathbb{R^2} $ is continuous. Recently, I've encountered with the following problem in an elementary analysis course:
Let $ f: \mathbb{R^2} \rightarrow \mathbb{R^2} $ be a function that maps every connected set to connected set and also, every compact set to compact set. Prove that $ f $ is continuous.
My attempt was to consider a convergent sequence $ (x_n, y_n) $ with its limit point, say $ (x, y) $, which together form a compact set, and I wanted to show that
$ \lim_{n \rightarrow \infty} f((x_n, y_n)) = f((x, y)) $. But I couldn't continue. I wonder if there is anything special with $ \mathbb{R^2} $ here?
Any help would be appreciated.
 A: I decided to present some more general details around this concept. The proof of a more general result can be found in
McMillan, Evelyn R., On continuity conditions for functions, Pac. J. Math. 32, 479-494 (1970). ZBL0198.28004.
which I found in the MathOverflow link posted in the comments, I'll link it here for completeness. Your course is "elementary" analysis : this problem isn't very elementary, and is anything else but easy : it's a research problem after all.  Nevertheless, the paper is terse, I will try to make it easier to read. It will still remain a difficult read for someone just starting out in analysis and topology, but I plan to make sure I can emphasise the two key lemmas that are really the cornerstone of this particular piece of research. It should be comfortable for someone with one course of topology behind them , who can ideally work with connectedness and compactness.
The following result is true in general :

Let $X,Y$ be Hausdorff spaces with $X$ locally connected and having the following property : for every $A \subset X$ infinite and $x\in A$ there exist $x_i\in A$ distinct such that $x_i \to x_0$. Suppose that $f : X \to Y$ is that for every $A \subset X$ connected, $f(A)$ is connected, and for every $B \subset X$ compact, $f(B)$ is compact. Then, $f: X \to Y$ is a continuous function(!)

I will only present the proofs of the two lemmas from McMillan's paper, and a proof sketch of the general statement for $\mathbb R^2$.

We begin with a two important lemmas, that I really like as independent results. These are independent consequences of mere compact preservation and connectedness preservation of $f$, and would be nice exam-type questions in themselves.

Suppose that $f : \mathbb R^2 \to \mathbb R^2$ preserves compacts. Then, for every $x_i \to x$ such that $f(x_i) \neq f(x_j)$ for $i \neq j$, we have $f(x_i) \to f(x)$. In other words, the sequential definition of continuity holds for all sequences with no repeated elements, restricted to which $f$ is injective.

Proof : Suppose not. Let $f(x) \in V \subset \mathbb R^2$ be an open set such that $V$ doesn't contain infinitely many of the $f(x_i)$. Let $y_i$ be a subsequence of the $x_i$ such that $f(y_i)$ lie in $\mathbb R^2 \setminus V$ for all $i$. Note that $\{y_i\} \cup \{x\}$ is compact since $y_i$ converges to $x$. So its image is compact. That means $f(\{y_i\} \cup \{x\})$ is sequentially compact : the particular subsequence $f(y_i)$ must have a limit point. Clearly that limit point isn't $f(x)$, so it must be $f(y_{j'})$ for some $j'$.
Now let $z_i$ index a subsequence of $y_i$ such that $f(z_i) \neq f(y_{j'})$ for all $i$. Then, $\{z_i\} \cup \{x\}$ is compact , and hence $f(\{z_i\} \cup \{x\})$ is compact, hence sequentially compact. Not possible : we know that a subsequence of $f(z_i)$ converges to $f(y_{j'})$, which doesn't belong in $f(\{z_i\} \cup \{x\})$.
Consequently, it must happen that $f(x_i) \to f(x)$. $\blacksquare$
Note the following extension to this : suppose that $f: \mathbb R^2 \to \mathbb R^2$ is a map preserving compacts, $x_i \to x$ is such that for every $y \in \mathbb R^2$, it true for only finitely many $i$ that $f(x_i) = y$. Then, $f(x_i) \to f(x)$. I'll leave the proof to the reader.

Here's a lovely lemma that shows the importance of connectedness-preserving maps. I've picked these up from a related paper,
Hamilton, O. H., Fixed points for certain noncontinuous transformations, Proc. Am. Math. Soc. 8, 750-756 (1957). ZBL0086.37101.>

Lemma : Let $f : \mathbb R^2 \to \mathbb R^2$ preserve connectedness. Let $C \subset \mathbb R^2$ be closed. Then , every connected component of $f^{-1}(C)$ is closed. So even if the preimage of every closed set isn't closed (which would lead to continuity), at least the connected components of that set are!

Proof : Suppose $E \subset f^{-1}(C)$ is a connected component but not closed. Let $p \in \overline E \setminus E$. Then $f(p) \notin C$, because if $f(p) \in C$ then $p \in f^{-1}(C)$, but then $E \cup \{p\}$ is a connected set(why? It's a connected set along with a limit point, hence remains connected) larger than $E$ which is contained in $f^{-1}(C)$, so $E$ can't be a connected component.
Now, if $f(p) \notin C$, pick an open set $B$ such that $f(p) \in B$ but $B \cap C = \emptyset$(can be done by picking a sufficiently small ball around $f(p)$ not containing $C$ as $C$ is closed, so $C^c$ is open). Thus, $f^{-1}(B) \cap E$ is also empty since $f(E) \subset C$.
However, this cannot happen : indeed, $E \cup \{p\}$ is connected, so $f(E \cup \{p\})$ is also connected. However, $f(p) \in B$ is separated from $f(E) \subset C$! So $f(p)$ would be a component of its own, a contradiction.
Consequently, it must happen that no such $p$ exists i.e. that $E$ is closed. $\blacksquare$.
We don't actually need McMillan's Lemma 3 now : this statement is just as good.

Now the proof sketch. It's very, very brief : only captures the very key points and where which hypothesis is used.
Theorem : $f : \mathbb R^2 \to \mathbb R^2$ preserving compacts and connectedness must be continuous.
Proof Sketch : By the extension of the lemma for compact preserving functions, if we assume for some $x_i \to x$ that $f(x_i) \not \to f(x)$, then there is a $y \in \mathbb R^2$ such that $f(x_i) = y$ for infinitely many $i$ but $f(x) \neq y$.
Let $U,V$ separate $f(x),y$ in the sense that they are disjoint open sets with $f(x) \in U, y \in V$. Let $W = f^{-1}(y)$ be the preimage of $y$, which recall has infinitely many elements. We break $W$ into three parts $W_1,W_2,W_3$, in light of the argument used in the compact-preserving lemma.
$W_1$ is the interior of $W$ so that $W \setminus W_1$ consists of points in $W$ that are limit points of $\mathbb R^2 \setminus W$. $W_3$ is the set of all points $z \in W \setminus W_1$ such that for every sequence $z_i \to z$, $\{f(z_i)\}$ is a finite set. Let $W_2 = W \setminus( W_1 \cup W_3)$.
Note that $x$ is a limit point of $W$, since if we consider the subsequence of $x_i$ whose image is $y$, they must converge to $x$, so that $x$ is obviously a limit point of $f^{-1}$ of that subsequence. Therefore, $x$ is either a limit point of $W_1,W_2$ or $W_3$. $W_2$ and $W_3$ lead to complicated contradictions, which I'll summarize.

*

*If $z_i \in W_3$ converges to $x$, it is possible to prove the following : there exist $w_i \in W$ distinct such that $z_i \in \overline {f^{-1}(w_i)}$, and the set $\{w_i\}$ does not contain $f(x)$ as a limit point. This is done using a repeated contradiction of the assumption that $f$ preserves connectedness. Once this is done, picking a subsequence $t_i$ of $z_i$ lying in the $f^{-1}(w_i)$ ensures that $t_i \to x$ but $f(t_i) \not \to f(x)$.This contradicts the compactness-preserving lemma.


*Suppose $z_i \in W_2$ converges to $x$. Note that each $z_i$ is the limit point of a sequence $z_{ij} \in f^{-1}(w_{ij})$ with $w_{ij} \neq w_{ik}$ for $j \neq k$.We can choose the $w_{ij}$ to be within a neighbourhood of $y$ avoiding $f(x)$ if necessary. It is possible to prove , using a removal argument independent of compactness/connectedness preservation, the following : we can choose $z_{ij}$ such that it preserves the above properties, and for each $i'$, the sequence $z_{i'j}$ has the property that for any $w_{i'j}$, $f^{-1}(w_{ij'}) \cap \{z_{i'j}\}$ is finite. (That is, for each $i'$, $z_{i'j}$ is a sequence similar to the one described in the extension to the compactness lemma). Once we do this, the fact that $z_i$ converges to $x$ enables us to pick a subsequence $s_j$ of $z_{ij}$ that converges to $x$ : so $f(s_j) \to f(x)$ by the compactness lemma, but that can't be because they're chosen to lie in a neighbourhood of $y$ avoiding $f(x)$.


*For the last one : if there is a sequence in $W_1$ converging to $x$, but not in $W_2$ or $W_3$, then $x \in U$ for an open connected(WLOG, by shrinking) set $U$ that intersects only $W_1$, and therefore ensures that $U \cap f^{-1}(y)$ is open. Now, $U \cap f^{-1}(y)$ isn't connected : that's because if it were, then $[U \cap f^{-1}(y)] \cap \{x\}$ is connected, but its image is $\{f(x),y\}$ which isn't connected. Once can use an arbitrary connected component $C$ of $U \cap f^{-1}(y)$ and show that it is closed (use result on connectedness preserving maps) and open (connected component of open set) : which can't happen unless it is empty or $\mathbb R$, both of which lead to a contradiction.
Thus, the result follows. $\blacksquare$

Perhaps it is not so much the sketch that should be taken away from here , but rather the two key lemmas , that allow us to generalize the phenomena to other , more involved spaces.
A: Here's a detailed sketch: Let $p$ be an arbitrary point of the plane, and for each $r > 0$ let $D_{r}$ denote the closed disk of radius $r$ about $p$. Since $D_{r}$ is compact and connected, $f(D_{r})$ is as well, by hypothesis. Further, the sets $f(D_{r})$ all contain $f(p)$, and are nested inward, i.e., $f(D_{r'}) \subset f(D_{r})$ if $0 < r' < r$. The intersection $Y = \bigcap_{r>0} f(D_{r})$ is therefore a compact, connected subset of the plane containing $f(p)$. It suffices to show $Y = \{f(p)\}$.
Suppose $Y$ is not a singleton. Since $Y$ is compact and connected, $Y$ contains a countably infinite, non-closed subset $F = \{F_{k}\} \subset Y$ of which $f(p)$ is neither an element nor a limit point. For each positive integer $k$, pick a point $x_{k}$ in the plane such that $|x_{k} - p| < 1/k$ and $f(x_{k}) = F_{k}$. The sequence $(x_{k})$ converges to $p$ by construction, so $\{x_{k}\} \cup \{p\}$ is compact; also by construction, the image of this set under $f$ is $F \cup \{f(p)\}$, which is not compact.
Contrapositively, since $f$ maps compact sets to compact sets, $Y$ is a singleton. Continuity of $f$ at $p$ follows easily. Since $p$ was arbitrary, $f$ is continuous in the plane. (Nothing about the proof is specific to the plane, however.)
