Proving that this function is continuous based on definitions of two sets Question: Let $f : \mathbb{R}^n \to \mathbb{R}$ such that $\{ \textbf{x} \in \mathbb{R}^n : f(x) > d\}$ and $\{ \textbf{x} \in \mathbb{R}^n : f(x) < d\}$ are both open sets for all real values of $d$. Show that $f$ is continuous.
My idea: For a function to be continuous, the limits of all values in the domain must converge. We can perhaps write the function's range as $f(x) \in \mathbb{R} / \{d\}$ and prove that the function is somehow continuous here. I'm not sure if this is even correct, but I'm not sure how else to approach this problem. Any help or guidance would be greatly appreciated!
 A: We are going to show that $f$ is continuous, according to the epsilon-delta definition of continuity. Note that for $\mathbf{x}\in\mathbb{R}^n$, for $r>0$ in $\mathbb{R}$, we denote $$B_{r}(\mathbf{x})=\{\mathbf{y}\in\mathbb{R}^n:||\mathbf{x}-\mathbf{y}||<r\}$$
Fix $\mathbf{x}_0\in\mathbb{R}^n$. Let $\varepsilon>0$. The sets
$$A=\{\mathbf{y}\in\mathbb{R}^n:f(\mathbf{y})<f(\mathbf{x}_0)+\varepsilon\}\text{ and }B=\{\mathbf{y}\in\mathbb{R}^n:f(\mathbf{y})>f(\mathbf{x}_0)-\varepsilon\}$$
are both open in $\mathbb{R}^n$. Since $x_0\in A\cap B$, then there exists a $\delta>0$ such that $B_{\delta}(\mathbf{x_0})\subseteq A\cap B$ (this is because $A$ and $B$ are open sets). Now, for any $\mathbf{x}\in B_{\delta}(\mathbf{x_0})$, we have $$f(\mathbf{x}_0)-\varepsilon<f(\mathbf{x})<f(\mathbf{x_0})+\varepsilon$$ which implies $$|f(\mathbf{x})-f(\mathbf{x_0})|<\varepsilon$$hence $f$ is continuous.
If you are familiar with continuity in terms of open sets, then this proof gets shortened as follows:
The collections of all intervals $(-\infty,d)$ and $(d,\infty)$ for all real values of $d$ forms a subbase for the topology on $\mathbb{R}$. Since every open subset of the reals is a union of finite intersections of these basis elements, it follows that $f$ is continuous.
