Continuous functions do not necessarily map closed sets to closed sets I found this comment in my lecture notes, and it struck me because up until now I simply assumed that continuous functions map closed sets to closed sets.
What are some insightful examples of continuous functions that map closed sets to non-closed sets?
 A: Here’s a small sample of examples.
The graph $G$ of $y=1/x$ is closed in $\Bbb R^2$, and the map $p:\Bbb R^2\to\Bbb R:\langle x,y\rangle\mapsto x$ is continuous, but $p[G]=(\leftarrow,0)\cup(0,\to)$, which is not closed in $\Bbb R$.
The map $\Bbb R\to\Bbb R:x\mapsto e^{-x}$ sends the closed subset $[0,\to)$ of $\Bbb R$ to the non-closed subset $(0,1]$. Other functions with horizontal asymptotes provide similar examples.
If $X$ is any non-closed subset of a space $Y$, the inclusion map $i:X\to Y:x\mapsto x$ gives a trivial example, since $X$ is a closed subset of itself.
Another trivial example is obtained by taking any infinite set $X$, letting $\tau_d$ be the discrete topology on $X$, and letting $\tau$ be any other topology on $X$. The identity map from $\langle X,\tau_d\rangle$ to $\langle X,\tau\rangle$ is automatically continuous. However, there is at least one $x_0\in X$ such that $\{x_0\}\notin\tau$ (i.e., $x_0$ isn’t an isolated point of $\langle X, \tau \rangle$); if $A=X\setminus\{x_0\}$, then $A$ is closed in $\langle X,\tau_d\rangle$ (as is every subset of $X$), but $A$ is not closed in $\langle X,\tau\rangle$.
A: In addition to the excellent examples presented by Brian, I want to point out what exactly all of these have in common.
The key property that is making these examples work (i.e. closed sets whose images under a continuous function are not closed) is that they're unbounded. If instead we were dealing with closed and bounded sets, then their images would always be closed (and bounded). This is a result that can be summarized by saying "the image of a compact set under a continuous function is compact".
Here's my attempt at explaining why this is, informally, by restricting ourselves to real functions (functions from $\mathbb{R}$ to $\mathbb{R}$) with the usual Euclidean metric. In this special case, by the Heine-Borel theorem, a set is compact if and only if it is closed and bounded. (In a more general setting we would need to work with the general definition of compactness, which is not quite as intuitive.)
Intuitively, the only way you can make the image of a set under a function not closed is if, on that set, the function comes arbitrarily close to a certain value but never actually reaches it. (This is because you will not be able to draw any open ball in the codomain around that value—which will be part of the complement of the image—that doesn't contain some points from the image, which implies the complement isn't open and hence the image isn't closed.) Here are some examples of functions, continuous and discontinuous, that exhibit this behaviour (apologies for the hand-drawing):

*

*The function $f \colon \mathbb{R} \to \mathbb{R}$ defined as $f(x) = e^x$:

The image of $\mathbb{R}$ under $f$ is $(0, +\infty)$. This function gets arbitrarily close to $0$ as $x$ tends to $-\infty$, but never attains that value; this is what causes the image to not be closed. This is a continuous function on a closed but unbounded set.


*The function $f \colon (0, 1) \to \mathbb{R}$ defined as $f(x) = x$:

The image here is $(-1, 1)$. The cuplrits for the non-closedness of the image are $-1$ and $1$; again, the function approaches these values but never actually reaches them. This is a continuous function on a non-closed (and in particular,  open) and bounded set.


*The function $f \colon [0, 1] \to \mathbb{R}$ defined as $\displaystyle f(x) = \begin{cases} \displaystyle\frac{1}{e^{x^2}} \quad &\text{if $x \ne 0$} \\ 0 \quad &\text{if $x = 0$} \end{cases}$:

Here the image is $\{0\}\cup [\frac{1}{e}, 1)$. Once again, $f$ approaches 1 but doesn't reach it. This is a discontinuous function on a closed and bounded set.
Now, what are the ways in which a continuous function on a closed set can approach a value without reaching it? If the domain is unbounded, that's easy: just let the function approach a value asymptotically as $x$ tends to $\pm\infty$ (like in our first example, $f(x) = e^x$). Are there any other ways? (Spoiler alert: no!)
If we try something like the third example above, approaching a value from both sides, the continuity of the function will force us to "fill in" the missing image with the value we're approaching:

But this is not specific to closed sets. What about approaching a value towards a point at the boundary of our domain? A key property of a closed set is that it contains all its limit points (in fact, we can even define closed sets by this property), hence the point on the boundary we approach will also be part of the domain. So, our function will also be defined there: which value will it take? Continuity, once again, forces the image at that limit point to be the limit of the images, i.e., the value we were approaching. Therefore this value is included in the image of the domain and thus the latter remains closed.

We have thus (intuitively) shown that the only way to make a continuous function on a closed set produce a non-closed image is to make the domain unbounded. In other words, if a set is closed and bounded (we call this compact), then the image of that set under a continuous function will also be closed.

Here's a little addendum: the result I cited at the top of this answer said that the image of a closed and bounded set under a continuous function is closed and bounded, but so far we have only seen the "closed" part.
Again, an intuitive explanation runs along the same lines. For the sake of illustration let's restrict ourselves to intervals. If you have a bounded domain, i.e. "limited horizontal space to draw your graph", and you have to draw a graph from one endpoint to another without lifting your pen, you can only "grow" your function a finite amount. You can't blow off to infinity, because then you would have to "return" from infinity to connect back to the second endpoint, creating a discontinuity (an asymptote):

The fact that the interval is closed is key: this ensures that the function is defined at the endpoints and thus, by continuity, the graph must "connect" to $(a, f(a))$, $(b, f(b))$. Otherwise, if the endpoints weren't included, the function could grow to infinity asymptotically as it approaches $a$ or $b$, as it doesn't need to be defined there. For example, $x \mapsto \frac{1}{x}$ defined on $(0, 1]$ has a vertical asymptote at $0$.
