I am trying to prove:
Let $g$ be defined on all of $\mathbb{R}$. If $B$ is a subset of $\mathbb{R}$, define the set $g^{-1}(B)$ by \begin{equation*} g^{-1}(B) = \{x \in \mathbb{R}: g(x) \in B\} \end{equation*} Show that $g$ is continuous iff $g^{-1}(B)$ is open whenever $B \subseteq \mathbb{R}$ is an open set.
My attempt:
$(\Rightarrow)$Suppose $g$ is continuous on $\mathbb{R}$ and $B \subseteq \mathbb{R}$ is open. Let $b \in B$. Then, $\exists N_r(b)$ such that $N_r(b) \subseteq B$, that is, $(b - r, b+ r) \in B$. Since $g$ is continuous at $b - r \in \mathbb{R}$, for $r > 0, \exists \delta > 0$ such that \begin{equation*} \left|(b+ r) - (b- r)\right| < \delta \implies \left|g(b+ r) - g(b- r)\right| < r \end{equation*} That is, $g[N_r(b)] \subseteq B \implies N_r(b) \subseteq g^{-1}(B) \implies g^{-1}(B)$ is open.
$(\Leftarrow)$ Suppose $B \subseteq \mathbb{R}$ is open so that $g^{-1}(B)$ is open. Let $b \in B \textrm{ such that } g(b) \in B$. The openness of $B$ tells us that $\exists N_r(b)$ such that $N_r(b) \subseteq B$, that is, \begin{equation*} \left|(b+r) - (b-r)\right| \le \operatorname{diam} B < \operatorname{diam} B +1 \end{equation*} But, the openness of $B$ implies that $g^{-1}(B)$ is open. So, $N_r(b) \subseteq g^{-1}(B) \implies g[N_r(b)] \subseteq B$, that is, \begin{equation*} \left|g(b+r) - g(b-r)\right| < \color{blue}{\operatorname{diam} B + 1} \end{equation*}
My questions:
Is my proof correct so far?
In the proof for $(\Leftarrow)$, I ideally want to replace the blue expression with something like an arbitrary $\epsilon > 0$. How can this be made possible? Then, the continuity of $g$ would follow immediately. (Currently, $\operatorname{diam} B > 0$ is not arbitrary.) Thanks!
I think you are mixing up different notions in your proof, which makes it incorrect.
Here is a simple proof:
Suppose $g$ is continuous and that $B$ is a (non-empty) open set in $\mathbb R$. Let $x\in g^{-1}(B)$. We have $g(x) \in B$ and $B$ is open so there exists $\varepsilon > 0$ such that $N_\varepsilon(g(x)) \subset B$. By continuity of $G$, there exists $\delta >0$ such that for all $x'$, $|x'-x|<\delta$ implies $|g(x') - g(x)| < \varepsilon$. Therefore $g(N_\delta(x)) \subset N_{\varepsilon}(g(x)) \subset B$ so $N_\delta(x) \subset g^{-1}(B)$. Therefore $g^{-1}(B)$ is open.
Now suppose $g^{-1}(B)$ is open for all open subset $B$. Take $x\in \mathbb R$ and $\varepsilon > 0$. $N_\varepsilon(g(x))$ is open so the $g^{-1}(N_\varepsilon(g(x)))$ is also open. Since $x$ is in $g^{-1}(N_\varepsilon(g(x))$, there exists $\delta > 0$ such that $N_\delta(x) \subset g^{-1}(N_\varepsilon(g(x))$. This translates as
$$ \forall x' \in \mathbb R, |x'-x| <\delta \Longrightarrow \ |g(x) - g(x')| < \varepsilon. $$
so $g$ is continuous.