$f(x)=x-x^2$ if $x$ is rational, $x+x^2$ if $x$ is irrational 
$$f(x)= \left\{\begin{array}{ll}
  x-x^2 &\mbox{if $x$ is rational,}\\
  x+x^2 &\mbox{if $x$ is irrational.}
  \end{array}\right.$$
  Show that $f'(0)=1$ and yet there is no neighborhood $I$ of the point $0$ on which this function is monotonically increasing.

 A: To show that $f'(0)=1$, it suffices to prove that $\lim_{x\rightarrow 0}\frac{f(x)-x}x = 0$ (since $f(0) = 0$). Since $f(x)-x=\pm x^2$, it is always true that $|f(x)-x|=x^2$. Dividing by $x$ and making $x\rightarrow 0$ gives the answer.
As for the second part. Suppose such a neighborhood $I$ exists. Then let $x\in I$ be irrational. Since $\mathbb Q$ is dense in $\mathbb R$, there exists a sequence $r_n$ of rationals in $I$ such as $r_n\rightarrow x$ and $r_n > x$.
Since $r_n$ is rational, $f(r_n) = r-r_n^2$, on the other hand $f(x) = x+x^2$. $f$ is monotically increasing on $I$, so that $f(x)\leq f(r_n)$ for all $n$. In other words
$x+x^2\leq r_n-r_n^2$ for all $n$.
Passing to the limit, it is found $x+x^2\leq x-x^2$ which is absurd (if $x\neq 0$). Therefore $I$ does not exist.
A: $f'(x) := \lim_{\Delta x \to 0} \frac{f(x+\Delta x) - f(x)}{\Delta x}$
since f(0) = 0,
$f'(0) = \lim_{\Delta x \to 0} \frac{f(\Delta x)}{\Delta x}$
Using $\epsilon - \delta$ method : above equation is equal to (substitute k to $\Delta x$) "for every $\epsilon > 0$, there exists $\delta > 0$ that
$k \in (-\delta,\delta), k \neq 0 \implies \frac{f(k)}k \in (1-\epsilon,1+\epsilon)$."
If k is rational, then $f(k) = k - k^2$, and $\frac{f(k)}k = 1-k$. Therefore, if $\delta = \epsilon$, then $\frac{f(k)}k$ is between $1+\delta$ and $1-\delta$, which is $(1-\epsilon,1+\epsilon)$.
Similar method works if k is irrational ($\delta = \epsilon$)
$\therefore$ whether k is rational or not, for every $\epsilon>0$, there exists $\delta$.
$\therefore$, $f'(0) = 1$.
PS : some error can exists in $\epsilon - \delta$ method
