$f : \mathbb{R} \to \mathbb{R}$ is continuous iff $\{(x,y):y\lt f(x)\}$ and $\{(x,y):y\gt f(x)\}$ are both open sets in $\mathbb R^2$ Given $f: \mathbb{R} \to \mathbb{R}$ define two sets $A$ and $B$ as $ A = \{(x, y) : y < f(x)\}$ and $B = \{ (x, y) : y > f(x)\}$ in $\mathbb{R^2}$. Show that $f$ is continuous iff  both $A$ and $B$ are open.
I'm not sure if this follows from the definition of continuity. Can someone help?
 A: Given a function $f:\mathbb R\to\mathbb R$ define
$$A_f=\{(x,y)\in\mathbb R\times\mathbb R:f(x)\gt y\},$$
$$B_f=\{(x,y)\in\mathbb R\times\mathbb R:f(x)\lt y\}.$$
Lemma 1. The function $f:\mathbb R\to\mathbb R$ is upper semicontinuous if and only if $B_f$ is open in $\mathbb R\times\mathbb R$.
Proof. First, suppose $f$ is USC. Let $(x_0,y_0)$ be any point in $B_f$. Let $\varepsilon=\frac{y_0-f(x_0)}2\gt0.$ Choose $\delta\gt0$ so that $|x-x_0|\lt\delta\implies f(x)\lt f(x_0)+\varepsilon$. Then
$$|x-x_0|\lt\delta,\ |y-y_0|\lt\varepsilon\implies f(x)\lt f(x_0)+\varepsilon=y_0-\varepsilon\lt y\implies(x,y)\in B_f.$$
This shows that $B_f$ is open.
Conversely, suppose $B_f$ is open. Let $x_0\in\mathbb R$ and $\varepsilon\gt0$ be given. Since $(x_0,f(x_0)+\varepsilon)\in B_f$, we can find $\delta\gt0$ such that
$$|x-x_0|\lt\delta\implies(x,f(x_0)+\varepsilon)\in B_f\implies f(x)\lt f(x_0)+\varepsilon.$$
This shows that $f$ is USC.
Lemma 2. The function $f:\mathbb R\to\mathbb R$ is lower semicontinuous if and only if $A_f$ is open in $\mathbb R\times\mathbb R$.
Proof. Similar to Lemma 1.
Theorem. The function $f:\mathbb R\to\mathbb R$ is continuous if and only if both of the sets $A_f$ and $B_f$ are open in $\mathbb R\times\mathbb R$.
Proof. Lemmas 1 and 2.
Example. The function $f=\{(x,0):x\le0\}\cup\{(x,\frac1x):x\gt0\}$ is lower semicontinuous but not upper semicontinuous; the sets $A_f$ and $A_f\cup B_f$ are open, but $B_f$ is not open.
Example. The function $f=\{(x,y): xy=1\}\cup\{(0,0)\}$ is neither upper semicontinuous nor lower semicontinuous; $A_f\cup B_f$ is open, but neither $A_f$ nor $B_f$ is open.
A: Okay I think this is how it works.
$=>$ As @bof mentioned, define $g(x, y)=f(x)-y$ which is clearly continuous as $f$ is so. So the sets where $g >0$ and $g<0$ would obviously be open.
$<=$ $A \cup B$ is open, hence graph $f$ is closed. We take a sequence $(x_n, y_n) \in$ Graph $f$ converging to $(x, y)$ in the graph. We have $f(x_n)=y_n$  and $\lim f(x_n) =\lim y_n = y = f(x)$. Hence $f$ is continuous.
A: $\Rightarrow:$ Suppose that $f$ is continuous. Observe that
\begin{eqnarray*}
A & = & \cup_{r\in\mathbb{Q}}\{(x,y)\mid y<r<f(x)\}\\
 & = & \cup_{r\in\mathbb{Q}}\{(x,y)\mid y<r\}\bigcap\{(x,y)\mid r<f(x)\}\\
 & = & \cup_{r\in\mathbb{Q}}\mathbb{R}\times(-\infty,r)\bigcap f^{-1}(r,\infty)\times\mathbb{R},
\end{eqnarray*}
which is an open subset of $\mathbb{R}^{2}$. Similarly, we can prove
that $B$ is open.
$\Leftarrow:$ Suppose that $A$ and $B$ are open. Let $x_{0}\in\mathbb{R}$
be arbitrary. Let $\varepsilon>0$. Denote $p_{1}=(x_{0},f(x_{0})-\varepsilon)$
and $p_{2}=(x_{0},f(x_{0})+\varepsilon)$. Observe that $p_{1}\in A$.
Since $A$ is open, there exists $r_{1}>0$ such that $B(p_{1},r_{1})\subseteq A$.
Similarly, $p_{2}\in B$, so there exists $r_{2}>0$ such that $B(p_{2},r_{2})\subseteq B$.
Let $r=\min(r_{1},r_{2})$. Let $x\in(x_{0}-r,x_{0}+r)$. Since $d((x,f(x_{0})-\varepsilon),p_{1})<r$,
so $(x,f(x_{0})-\varepsilon)\in B(p_{1},r_{1})\subseteq A$. Hence,
$f(x_{0})-\varepsilon<f(x)$. Similarly, $d((x,f(x_{0})+\varepsilon),p_{2})<r$
implies that $(x,f(x_{0})+\varepsilon)\in B(p_{2},r_{2})\subseteq B$
. Hence $f(x_{0})+\varepsilon>f(x)$. Combining, we have $f(x)\in(f(x_{0})-\varepsilon,f(x_{0})+\varepsilon)$.
This show that $f$ is continuous at $x_{0}$. Since $x_{0}$ is arbitrary,
$f$ is continuous.
