Is this function differentiable at 0? I would like to know if this function is differentiable at the origin:
$$f(x) =
\left\{
 \begin{array}{cl}
  x+x^2  & \mbox{if } x \in \mathbb{Q}; \\
  x & \mbox{if } x \not\in \mathbb{Q}. \end{array}
\right.$$
Intuitively, I know it is, but I don't know how to prove it. 
Any ideas?
Thanks a lot.

You need to show that if $h$ is near $0$, then $\displaystyle\frac{f(h)}h$ is near $1$ (which should be the value of $f'(0)$). 
But $\displaystyle \frac{f(h)}h$ is either $1$ or $1+h$.

In detail: We have that $f(0)=0$. 
We can anticipate that, if it exists, the derivative of $f$ at $0$ is $1$, since $g'(0)=j'(0)=1$ where $g(x)=x$ and $j(x)=x+x^2$. However, to see whether $f'(0)$ exists and what its value is, we simply use the definition of the derivative at $0$: 
 $$ \lim_{h\to0}\frac{f(0+h)-f(0)}h=\lim_{h\to0}\frac{f(h)}h. $$
From the definition of $f$, we see that the fraction $\displaystyle \frac{f(h)}h$ equals either $1$ or $1+h$, depending on whether $h$ is irrational or not. 
It should be clear now that the limit of this expression is $1$ as $h$ approaches $0$, but we can proceed to verify this from the definition of limit:
We have that $\displaystyle\lim_{h\to0}\frac{f(h)}h=1$ if and only if for every $\epsilon>0$ there is a $\delta>0$ such that if $0<|h-0|<\delta$, then 
 $$\left|\frac{f(h)}h-1\right|<\epsilon.$$ 
That is, given $\epsilon>0$, we must find a $\delta>0$ such that $0<|h|<\delta$ implies that both $|1-1|<\epsilon$ and $|(1+h)-1|<\epsilon$. 
The first of these inequalities always holds, so we only need to look at the second one, which simplifies to $|h|<\epsilon$. Now we see that if we take $\delta=\epsilon$, then what we need to verify is that $0<|h|<\epsilon$ implies $|h|<\epsilon$, which is always the case, and we are done: We have shown that $f'(0)$ exists, and equals $1$.
(Of course, we could just as well take as $\delta$ anything that is both positive and less than $\epsilon$.) 
