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.
 A: $f$ can be either $x + x^2$, or $x$ (depending on the value of $x$), right?
Firstly, you can prove that $f$ is continuous at 0, by noticing that $0 < |f(x)| \le |x| + x^2$
And, you know that these 2 functions ($x + x^2$, and $x$)' derivatives at 0 are both 1. So, in order to prove that the derivative at 0 is indeed 1, you should use Squeeze Theorem, like this:
Right derivative at 0
For $x > 0$, we have the inequality: $x < x + x^2$, so the upper bound for $f$ is $x + x^2$, and the lower bound is of course $x$. So we'll have:
$\begin{align} & x \le f(x) \le x + x^2 \\
\Rightarrow &\dfrac{x}{x} \le \dfrac{f(x)}{x} \le \dfrac{x + x^2}{x} \quad \mbox{since }x > 0\mbox{, the inequality sign doesn't change}\\
\Rightarrow &1 \le \dfrac{f(x) - 0}{x - 0} \le \dfrac{x + x^2}{x}\\
\Rightarrow &1 \le \dfrac{f(x) - f(0)}{x - 0} \le \dfrac{x + x^2}{x}
\end{align}$
...
From here, you can apply Squezze Theorem, it should be easy, let's give it a try.

Left derivative at 0
Since $x \rightarrow 0^-$, we'll still have the inequality: $x < x+x^2$, so the upper bound for $f$ is still $x + x^2$, and the lower bound is of course $x$. So we'll have:
$\begin{align} & x \le f(x) \le x + x^2 \\
&...\end{align}$
Can you take it from here? Remember that when dividing to $x$ in this case, you have to change the signs (from > to <; and from < to >), as $x < 0$.
A: For continuity at any arbitrary point $c\in\mathbb{R}$ and considering sequential criteria(first consider a rational sequence converging to $c$ and then a irrational sequence converging to $c$ and equate the limit) of continuity at $c$  you need $c^2+c=c$ so $c^2=0$ so $c=0$, so only at $c=0$ the function is continuos, Now consider the limit $\lim_{x\rightarrow 0}\frac{f(x)-f(0)}{x}$ take rational sequence $x_n\rightarrow 0$ and see what is the limit and take irrational sequence $x_n\rightarrow 0$ and see the limit, are they equal?
you need read this two topic first to understand the solution:Sequential Criterion For Limit Sequential Criterion For Continuity Here you can look the Sequential criterion for Derivative
A: A function $f$ defined in a neighborhood of $x=0$ is differentiable at $0$ if the limit
$$\lim_{x\to0}{f(x)-f(0)\over x-0}$$
exists. Now
$$m(x):={f(x)-f(0)\over x-0}=\cases{1+x\quad&$(x\in\Bbb Q)$\cr 1&$(x\notin\Bbb Q)$\cr}\qquad(x\ne0)\ .$$
It follows that $|m(x)-1|\leq|x|$ for all $x\ne0$, from which we immediately conclude that $\lim_{x\to0} m(x)=1$, or $f'(0)=1$.
A: 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$.) 
