I am stuck on a simple consideration, I think. I have the function $$f(x) = \begin{cases} x-2 & x < 0 \\ x+2 & x \geq 0 \end{cases}$$
This is indeed a function, mapping $\mathbb{R}\to \mathbb{R}$, and both of the pieces are continuous. Yet $f(x)$ is not continuous: the inverse image of the open set $(1, 3)$ is the non open set $[0, 1)$.
Here I am stuck: I don't get how it finds the non open set $[0, 1)$. The function is never $1$, so why consider the open set $(1, 3)$? And anyway why $[0, 1)$?
Couldn't we just pick $(\frac{1}{2}, 1)$?
We have $f(x)\in(1,3)$ iff either $x-2\in (1,3)$ and $x<0$, or $x+2\in(1,3)$ and $x\ge0$. In other words, iff either $3<x<5$ and $x<0$, or $-1<x<1$ and $x\ge 0$. The first can never happen and the second can be combined as $0\le x<1$. So $f(x)\in(1,3)$ iff $x\in[0,1)$, i.e., the inverse image of the open set $(1,3)$ is the non-open set $[0,1)$.
If we pick $(\frac12,1)$ instead, we find that the inverse image is the empty set: $f(x)\in(\frac12,1)$ iff $2\frac12<x<3$ and $x<0$, or $-1\frac12<x<-1$ and $x\ge 0$, and both options are impossible. Since the empty set is open, this finding would still be consistent with $f$ being continuous, so it doesn't help here.