The preimage of a closed set is closed

There must exist a continuous surjective function $f$ from $(0,1)$ to $[0,1]$. Since $f$ is continuous and $[0,1]$ is closed, then $f^{-1}([0,1])$ is closed either. However, $f^{-1}([0,1])=(0,1)$, which is open in $\mathbb{R}$.

How should I understand the statement that "the preimage of a closed set is closed"?

• $(0,1)$ is open in $\mathbb{R}$, sure. But it's closed in the subspace topology on $(0,1)$, which is the relevant space. – Patrick Stevens Mar 29 '17 at 7:52
• The domain of $f$ is $(0,1)$, not $\mathbb{R}$, and $(0,1)$ is certainly closed in itself. – quasi Mar 29 '17 at 7:53
• For an example of a continuous surjective function from $(0,1)$ to $[0,1],\;$ let $$f\;{:}\;(0,1) \to [0,1]\;\;\text{be defined by}\;\;f(x) = \sin{2\pi x}$$ – quasi Mar 29 '17 at 8:06

To talk about a continuous function, we need to specify the domain, the codomain, and the topology on each of them. In particular, if the domain is a subset of the reals, we need to treat that subset as a topological space of its own rather than as a subset. As the whole space, it is certainly closed.

Note that if your function (that takes (0,1) to [0,1]) is defined continuously on a larger subset of the reals that includes 0 and 1, then the preimage of [0,1] will indeed also include 0 and 1.