Let $f: \mathbb{R} \rightarrow \mathbb{R}$ be continuous. If $f(x) \ge 0$ for every rational x, show that $f(x) \ge 0$ for all real $x$. Will this result hold with "$\ge 0$" replaced by "$>0$"? Explain.
My approach for the first part of the question:
Let us assume that $\exists \ x_{0} \in \mathbb{R}$ such that $f(x_{0}) < 0$. Since, f is continuous then for $\epsilon > 0 \ \exists \ \delta > 0$ such that $f(B_{\delta}(x_{0})) \subset B_{\epsilon}(f(x_{0})$. Now, there exists $y \in B_{\delta}(x_{0}) \cap \mathbb{Q} $ such that $f(y) \in B_{\epsilon}(f(x_{0})$ and particularly, $f(y) < 0$. Contradiction !
I am not sure about the second part. Kindly help me with the problems.
Thanks !
Let's start with the example from the comment by Hagen:
Let $f: \Bbb R \to \Bbb R$ be given by $f(x)=(x^2-2)^2$.
Then $q \in \Bbb Q$ implies $q^2 - 2 \neq 0$ (as $\sqrt{2}$ is irrational!) and so $f(q) >0$ as the square of a non-zero real.
But $f(\sqrt{2}) = 0$ is not $ > 0$ .....
For the $\ge 0$ proof: $f^{-1}[[0,\infty)]$ is closed by continuity and contains $\Bbb Q$ so also $\overline{\Bbb Q}=\Bbb R$. QED.