Which of the following condition ensure that the function $f:R^n\to R$ is continuous? I encountered an interesting problem in my Economics class about continuity.
Which of the following conditions on the function $f:\mathbb R^n\to \mathbb R$ ensures that the function $f$ is continuous?


*

*For all $y$ the sets $\{x:x\in \mathbb R^n, f(x) < y\}$ and $\{x:x\in \mathbb R^n, f(x) > y\}$ are open;

*For all $y$ the sets $\{x:x\in \mathbb R^n, f(x) \le y\}$ and $\{x:x\in \mathbb R^n, f(x) \ge y\}$ are open;

*For all $y$ the sets $\{x:x\in \mathbb R^n, f(x) < y\}$ and $\{x:x\in \mathbb R^n, f(x)> y\}$ are closed;

*For all $y$ the sets $\{x:x\in \mathbb R^n, f(x) \le y\}$ and $\{x:x\in \mathbb R^n, f(x)\ge y\}$ are closed;


I have proved using contradiction that 3, 4 implies continuity.

The proof follows as below:
Suppose we assume 3, and suppose to the contrary that $f$ is not continuous. Then there exists sequence $x_n\to x_0$ such that $f(x_n) \not\to f(x_0)$. So given $\epsilon>0$, there exists some $N\in \mathbb{N}$ such that for all $n > N$, $|f(x_n)-f(x_0)|>\epsilon$. The last inequality is equivalent to $f(x_n)<f(x_0)-\epsilon$ or $f(x_n)>f(x_0)+\epsilon$.
Now from the assumption 3, the sets $\{x:x\in R^n, f(x) < f(x_0)\}$ and $\{x:x\in R^n, f(x)> f(x_0)\}$ are closed. Hence, it contains all its limit points. Without loss of generality, let us consider just left case. Since $f(x_n)<f(x_0)-\epsilon<f(x_0)$ for all $n>N$, the limit point of $x_n$ which is $x_0\in \{x:x\in R^n, f(x) < f(x_0)\}$. This implies $f(x_0)<f(x_0)-\epsilon$, a contradiction.

But I was not quite sure how to prove/disprove 1, 2 implies continuity. Number 1 seems close to topological definition of continuity, but it is weak (I think). Any helps, hints, or counter examples will be appreciated.
 A: 
So, given $\epsilon > 0$, there exists some $N\in\mathbb N$ such that for all $n>N$, $|f(x_n)-f(x_0)|>\epsilon$

This statement is not true. For example, if $f(x_n)$ is the sequence $1,0,1,0,1,0,1,0$ (which does not converge to $1$) given $\epsilon =\frac12$, it is not true that $f(x)_n$ is more than $\epsilon$ away from $1$.
What you can say is this:

If the sequence $f(x_n)$ does not converge to $f(x_0)$, then there exists some $\epsilon > 0$ such that for every $N\in\mathbb N$, there exists some $n>N$ such that $|f(x_n)-f(x_0)| > \epsilon$.

This is because the negation of the statement
$$\forall \epsilon \exists N\forall n: P(\epsilon, N,n)$$
is the statement
$$\exists \epsilon \forall N \exists n: \neg P(\epsilon, N,n)$$
A: For (1): Take $a,b \in \mathbb{R}, a < b$ and note that $$f^{-1}(a,b) = \{x \in \mathbb{R}^n : f(x) > a \} \cap \{x \in \mathbb{R}^n : f(x) < b \}$$
is open.
Since the $(a,b)$ are a basis for the topology of $\mathbb{R}$, this implies that $f$ has to be continuous.
A: The answer is yes.
$(1)$ means $f^{-1}(\bigl((-\infty,y)\bigr)$ and  $f^{-1}(\bigl((y,+\infty)\bigr)$ are open sets for any $y\in\mathbf R$. 
As the $(-\infty,y)$ and $(y,+\infty)$, for all $y\in\mathbf R$, constitute a basis for the topology of $\mathbf R$, this means the inverse image by $f$ of any open set  is open. This is one of the criteria that ensures continuity of $f$.
A: Hint: 
Claim 1: Let $M,N$ be metric spaces. $f: M \to N$ is continuous if, and only if, the inverse image $f^{-1}(A')$ of every open subset $A' \subseteq N$, is open in $M$.
Claim 2: A subset $A \subset M$ is open, if, and only if, is a union of open balls. 
Now in (1), assume $\{x ; f(x) < y\}$ and  $\{x ; f(x) > y\}$ for all $y$ in $\mathbb R$. By Claim 2 we have that for anay open set $U$ in $\mathbb R$, $U = \bigcup_{\alpha \in I} (a_{\alpha}, b_{\alpha})$ and also 
$$(a_{\alpha}, b_{\alpha}) = (a_{\alpha}, \infty) \cap (-\infty, b_{\alpha}) \implies \begin{align}f^{-1}((a_{\alpha}, b_{\alpha})) &= f^{-1} ((a_{\alpha}, \infty)) \cap f^{-1}((-\infty, b_{\alpha})) \\&= \{x ; f(x) < a_{\alpha}\} \cap \{x ; f(x) > \alpha\}\end{align}$$
the intersection of any two open sets is open. Then $f^{-1} (a_{\alpha}, b_{\alpha}) $ is open. It follows that $$f^{-1}(U) = \bigcup_{\alpha \in I} f^{-1} ((a_{\alpha}, b_{\alpha}))$$
is open. Finally by Claim 1 $f$ is continuous. 
For (4) remember that if $A$ is closed in $M$ then $M - A$ is open. 
A: Let me express your conditions in terms of preimages:


*

*For all $y$ the sets $f^{-1}((-\infty,y))$ and $f^{-1}((y,+\infty))$ are open;

*For all $y$ the sets $f^{-1}((-\infty,y])$ and $f^{-1}([y,+\infty))$ are open;

*For all $y$ the preimages of 1. are closed;

*For all $y$ the preimages of 2. are closed.


First of all, we can exclude 2 and 3, since those conditions do not hold for continuous functions, and in fact continuity implies conditions that are incompatible with those, precisely 1 and 4.
It is 1 and 4 that do imply continuity. Remember that the union of preimages and the preimage of a union coincide, and analogously for intersections and complements. If $X$ is open, then it is a (possibly infinite) union of open intervals, as being open equates to having an open interval around each point contained in it. So for all $x\in X$ we have $a(x),b(x)\in\mathbb{R}$ such that $(a(x),b(x))\subseteq X$. Thus:
$$X=\bigcup_{x\in X}(a(x),b(x)),$$
and consequently:
$$f^{-1}(X)=\bigcup_{x\in X}f^{-1}((a(x),b(x))).$$
SO if we prove 1. implies all open intervals have open preimages we prove continuity. But then $(a,b)=(-\infty,b)\cap(a,\infty)$, and those two have open preimage, so their preimage is the intersection of two open sets, which is open. I erred on the side of speed above: that the preimage of $X$ is open follows from the preimages of open intervals being open since an arbitrary union of open sets is always open, be it finite, countable or uncountable.
In a similar way, with all closed half-lines having closed preimage, you can show all closed intervals have closed preimage. But then it is easier to go about proving 4 and 1 are equivalent. That is because if $f^{-1}(\text{closed half-line})$ is open, its complement is closed and viceversa, but the complement is the preimage of the complementary half-line, so if all closed half-lines have closed preimage, all open half-lines have preimages that are complements of closed sets (the preimages of the complementary closed half-lines), and thus are open, proving 4 implies 1. Similarly, 1 implies 4. But 1 implies continuity by the above argument, so 4 implies continuity through 1.
Note that if a set is closed in $\mathbb{R}$ then it can't be open, and viceversa, unless it is either empty or the whole $\mathbb{R}$. THat is because $\mathbb{R}$ is connected. So 2 implies open half-lines have closed, hence not open, preimage, so $f$ is not continuous. 3 implies the same as 2, only stating it directly. Unless of course all open half-lines have all $\mathbb{R}$ or the empty set as a preimage. That implies $f$ is constant. So 3 and continuity imply $f$ is constant. And so do 2 and continuity.
