If function is positive and continuous at a point, then it is positive in a neighborhood of the point? Let $f:\mathbb R\rightarrow \mathbb R$ be defined as
$$
f(x) = \left\{ \begin{array}{c}
x-x^2 & \text{ if } x\in\mathbb Q \\
x+x^2 & \text{ if } x\notin \mathbb Q.
\end{array}
\right.
$$
Show that $f'(0)=1$ and yet there is no neighborhood of the point $0$ on which $f$ is  monotonically increasing.
For the first part, using the density of irrationals we have
$$f'(0)=\text{lim}_{x\rightarrow0^-}\frac{f(x)-f(0)}{x-0}=\text{lim}_{x\rightarrow0^+}\frac{f(x)-f(0)}{x-0}=\frac{x+x^2-0}{x-0}=1.$$ Is it correct?
For the second part, I've read in the book that "if a function is positive and continuous at a point, then it is positive in a neighborhood of the point." So why is this not working here? And how should I prove that there is no neighborhood of the point $0$ on which $f$ is  monotonically increasing? 
 A: $a)$: We can rewrite $f(x) - x =  \left \{ \begin {array} {c} -x^2 & \text{ if } x \in \mathbb{Q}\\ 
x^2 & \text{ if } x \notin \mathbb{Q}. \end{array}\\ 
\right.$. Thus $\displaystyle \lim_{x \to 0} \left|\dfrac{f(x) - f(0)}{x-0} - 1\right|= \displaystyle \lim_{x \to 0} \left|\dfrac{f(x)-x}{x}\right|= \displaystyle \lim_{x \to 0} \left|\dfrac{x^2}{x}\right|= \displaystyle \lim_{x \to 0} |x| = 0\implies \displaystyle \lim_{x \to 0} \left(\dfrac{f(x)-f(0)}{x-0} - 1\right) = 0\implies \displaystyle \lim_{x \to 0} \dfrac{f(x) - f(0)}{x-0} = 1\implies f'(0) = 1$. 
$b)$: Let $a > 0$ and consider $(-a,a)$ be a neighborhood of $0$. We might consider further that $a < \dfrac{1}{2}, a \in \mathbb{Q}$. Observe that $\dfrac{-1+\sqrt{1+4a-4a^2}}{2}< a\implies $ if we take an irrational number $b \in \left(\dfrac{-1+\sqrt{1+4a-4a^2}}{2}, a\right)$ then $b+b^2 > a-a^2\implies f(b) > f(a)$. Next we choose a rational number $d \in (0, b)\implies d < b \implies d-d^2 < b < b+b^2 \implies d-d^2 < b+b^2\implies f(d) < f(b)$. Thus we have: $d < b < a $ and $f(d) < f(b) > f(a)$, proving $f$ is not monotonically increasing. 
A: Keep in mind that a function can only be differentiable where it is continuous (and not always there, either).
The density of the rationals and irrationals in the reals means that this piecewise function will only be continuous (and, therefore, may only be differentiable) where the two definitional formulas agree. That is, for $f$ to be continuous, we require that $$x-x^2=x+x^2\\0=2x^2\\0=x^2\\0=x.$$
Now, to prove that $f'(0)$ even exists, we have to show that $$\lim_{x\to 0}\frac{x-x^2-f(0)}{x-0}=\lim_{x\to 0}\frac{x+x^2-f(0)}{x-0},$$ but this is easily seen, since $f(0)=0,$ so that we need only show that $$\lim_{x\to 0}\frac{x-x^2}{x}=\lim_{x\to 0}\frac{x+x^2}{x},$$ or (equivalently) that $$\lim_{x\to 0}1-x=\lim_{x\to 0}1+x.$$ I leave it to you to show that both limits exist, and that both are equal to $1,$ so that $f'(0)=1.$
On the other hand, given any $x_0\neq 0,$ we can readily show that $$\lim_{x\to x_0}\frac{x-x^2}{x}\neq\lim_{x\to x_0}\frac{x+x^2}{x},$$ so that $f'$ is defined only at $x=0.$
What your book leaves out (apparently) is that the neighborhood of the point must be a relative neighborhood of the function's domain. In this case, this means that there must be some (more general) neighborhood (say $U$) of the point $0$ such that, for all $x\in\operatorname{dom}(f')\cap U,$ we have that $f(x)>0.$ But this is trivially true, regardless of the neighborhood $U$ we choose, since $f'$ is defined only at $x=0,$ so that $\operatorname{dom}(f')\cap U=\{0\},$ whence $f'$ is positive in a relative neighborhood of $x=0,$ as desired.
