Prove $f$ is continuous iff for every closed set $K$ in $\mathbb R$, the set $f^{-1}(K)$ is closed in $\mathbb R$ This is a question from my Real Analysis class and was hoping someone could answer it for me. The question from the beginning is:
Consider the function $f: \mathbb R \to\mathbb R$. Prove that $f$ is continuous iff for every closed set $K$ in $\mathbb R$, the set $f^{-1}(K)$ is closed in $\mathbb R$.
I keep running into dead ends because $K$ is closed but not bounded since its for every closed $K$ in $\mathbb R$.
 A: By definition, $f: \mathbb{R} \rightarrow \mathbb{R}$ is continuous if for every open set $O \subseteq \mathbb{R}$, $f^{-1}(O)$ is open.
Let $K \subseteq \mathbb{R}$ be a closed set.
Then $K^{c} = \mathbb{R} \setminus K$ is open.
$f: \mathbb{R} \rightarrow \mathbb{R}$ is continuous if and only if $f^{-1}(K^{c})=\mathbb{R} \setminus f^{-1}(K)$ if and only if $f^{-1}(K)$ is closed.
A: *

*Suppose that $f$ is continuous. Let $\{x_n\} \subset f^{-1}(K)$ with $x_n \to x$ as $n \to \infty$. Our goal is to prove that $x\in f^{-1}(K)$. It is easy to see that $f(x_n) \subset K$ and $f(x_n) \to f(x)$ as $n\to \infty$. Since $K$ is closed, then $f(x)\in K$, and hence $x\in f^{-1}(K)$.

*Now suppose that for every closed $K$, $f^{-1}(K)$ is also closed. Our goal is to prove that $f$ is continuous, i.e., for any $\{x_n\}$ with $x_n \to x$ as $n \to \infty$, $f(x_n)\to f(x)$ as $n\to \infty$. Let $K=  \overline{\{f(x_n)\}}$. Clearly, $K$ is closed. Then $ f^{-1}(K)$ is closed.
If $f(x) \not=\lim_{n\to \infty}f(x_n)$, then $f(x) \notin K=\overline{\{f(x_n)\}}$, then $x \notin f^{-1}(K)$. However $\{x_n\}\subset f^{-1}(K)$, which shows that $x \in f^{-1}(K)$. This is a contradiction!
A: One approach: For arbitrary $K$, consider a Cauchy sequence $(a_n) \subset f^{-1}(K)$. Use continuity of $f$ and $K$ closed to show that the limit of $(a_n)$ is also in $f^{-1}(K)$.
A: Yet another solution using $\epsilon$-$\delta$.
Suppose $f$ is continuous, $U\subset \mathbb{R}$ is open and $a\in f^{-1}(U)$.
Since $f(a)\in U$ and $U$ is open, we can find $\epsilon>0$ s.t. $B(f(a),\epsilon)\subset U$. Now the continuity of $f$ means we can find a $\delta>0$ s.t. $|a-x|<\delta$ implies $|f(a)-f(x)|<\epsilon$, which means $f(x)\in B(f(a),\epsilon)\subset U$. Thus $B(a,\delta)\subset f^{-1}(U)$ and thus $f^{-1}(U)$ is open.
Assume then that for every open $U$, $f^{-1}(U)$ is open. Let $a\in \mathbb{R}$ be arbitrary point and let $\epsilon>0$. Now $B(f(a),\epsilon)=:B$ is open and $a \in f^{-1}(B)$. By the assumption we can find a $\delta>0$ s.t. $B(a,\delta)\subset f^{-1}(B)$. This means that if $|x-a|<\delta$, then $|f(a)-f(x)|<\epsilon$, and thus $f$ is continuous at $a$. The continuity of $f$ follows since $a$ was arbitrary.
Now the equivalent claim for closed sets follows using Cheung SW's answer.
