Closed and open sets through a function between metric spaces My professor started an exercise in class with various points. He did not finish it though: he left some of the points as homework and said that he will finish the last one in class. I'm trying it and I would like to have some hints (not full answers, he is going to solve it anyway) and maybe some clarification.
I shall write the previous point first, since the other starts from there:


*Let $(X, d_x)$ and $(\Bbb R, \vert \cdot \vert)$ be metric spaces where $\vert \cdot \vert $ is the absolute value function, let $f:X \to \Bbb R$ be a function between these two metric spaces.
Let $ A= \{(x,y)  \in X\times \Bbb R \mid y\gt f(x)\} $ and $ B=\{(x,y)  \in X\times \Bbb R \mid y\ge f(x) \} $. Show that, if $f$ is continuous, then $A$ is open and $B$ is closed.

I managed to prove this, and I'm interested in the next request.


*Show that, in general, the converse is not true

I interpeted it as : "give an example of a non continuous function such that $A$ is open and $B$ is closed, thus showing that the fact that $A$ is open and $B$ is closed does not imply that $f$ must be continuous"
However, I'm having some problems finding such a function. I tried choosing $X=\Bbb R$, but it seems to me that the only good candidate would be a step-like function, and this kind fails to induce both the closed and the open set at the same time, only one of the two. This makes me think that with $(X,d_x)=(\Bbb R,d_x)$ the double implication holds, but I did not try to prove this: does it? If yes, where should I look for finding such function? If no, what am I doing wrong in $\Bbb R$? In general, is my approach correct or I should use something else?
Thank you.
Edit: As we all suspected, and as the user Jochen kindly showed in one of the replies, with the phrase "show that in general the converse is not true" he meant that we had to assume only one of the two hypothesis (i.e. assuming either that $A$ is open or that $B$ is closed, not both at the sames time), and in that case using the step function mentioned above it becomes trivial.
 A: I do not believe your Prof. If $A=\{(x,y)\in X\times \mathbb R: y> f(x)\}$ is open, and $t\in \mathbb R$ is fixed, then $A_t=\{x\in X: t>f(x)\}$ is open in $X$: Indeed, for $x\in A_t$, we have $(x,t)\in A$ and hence there is a neighbourhood $U$ of $(x,t)$ in the product topology of $X\times \mathbb R$ with $U\subseteq A$. But $U$
contains $B(x,\varepsilon)\times (t-\varepsilon,t+\varepsilon)$ for some $\varepsilon>0$
(where $B(x,\varepsilon)$ is a ball in the metric space $X$) so that, in particular $(\xi,t)\in U\subseteq A$ for all $\xi\in B(x,\varepsilon)$ and thus $t>f(\xi)$. This shows $B(x,\varepsilon)\subseteq A_t$, and hence $A_t$ is open. (Another argument would be the continuity of $X\to X\times \mathbb R$, $x\mapsto (x,t)$.)
Since the complement $B^c=\{(x,y)\in X\times \mathbb R: y< f(x)\}$ is open, the same argument shows that $\{x\in X:r<f(x)\}$ is open for every $r\in\mathbb R$. Hence the intersection $\{x\in X: f(x)\in (r,t)\}$ is open and therefore, the preimage of every open subset of $\mathbb R$ is open, which is the continuity of $f$.
Anything wrong with this argument?

Edit.
Perhaps the question is to be interpreted that neither the openess of $A$ nor the closedness of $B$ alone imply continuity. It seems that openess of $A$ is upper semi-continuity (which does not imply continuity as, e.g., the zero function on $\mathbb R$ modified to $f(0)=-1$ shows) and closedness of $B$ is lower semi-continuity.
Anyway, don't forget to tell us the solution of your Prof.
A: Take $d_1$ to be the usual metric on $\mathbb{R}$ and $d_2$ to be the discrete metric on $\mathbb{R}$. Then take $f:(\mathbb{R},d_1)\to(\mathbb{R},d_2)$ where $f(x)=x$. It can be shown that this function is discontinuous.
Then $A$ is the strict upper left triangular region of the plane. This can be shown to be open, since for each point $(x,y)\in A$, there will be an interval $I$ containing $x$ so that $I\times \{y\}$ is an open set - in the product topology - contained in $A$. For $I$, think about $r=y-f(x)$. To show that $B$ is closed, show that $\mathbb{R}^2\setminus B$ is open, which should be very similar to showing that $A$ is open.
Edit: In th above example, I did not catch that the codomain had to be $\mathbb{R}$ with the usual metric.
Take $(X,d_x)=(\mathbb{R},|\cdot|)$. Consider the function $f:X\to\mathbb{R}$ given by $$f(x)=\begin{cases}x+1&\text{ if }x\geq 0\\ 0&\text{ if }x<0\end{cases} $$ Then $f$ is not continuous at $x=0$. However, $A$ is open and $B$ is closed. For showing that $A$ is open, we can split in to cases. $x\geq 0$ or $x<0$. In the case where $x\geq 0$, again, think of $r=y-f(x)$ and this time create an open ball. For $x<0$, take $r=\min\{y,|x|\}$ and consider $B_{r/2}(x,y)$. To show $B$ is closed, show that $\mathbb{R}^2\setminus B$ is open by cases around $x\geq 0$ and $x<0$. If $x\geq 0$, consider the sub-cases when $y< 1$ and when $y\geq 1$. If you want to avoid cases, it might not be bad to show that any sequence in $B$ must converge to a point in $B$.
