Differentiability of function for $\Bbb{Q}$ and $\Bbb{R}\setminus \Bbb{Q}$ A function $f:\Bbb{R}\to\Bbb{R}$ is defined by $f(x)=x$, if $x$ is rational; $\sin(x)$ if $x$ is irrational.
Show that $f$ is differentiable at $0$ and $f'(0)=1$.
Here I'm thinking to apply definition separately for rational and irrational.. and I'm getting same limit... But can we conclude the differentiability with this result??
 A: Yes, the fact that this holds for rationals and irrationals separately (but consistently) does allow you to conclude differentiability. In particular, you are trying to show that the limit
$$\lim_{h\rightarrow 0}\frac{f(h)}h=1$$
and you have that $f(x)$ at every point is equal to either $f_1(x)=x$ or $f_2(x)=\sin(x)$ at every point. You have
$$\lim_{h\rightarrow 0}\frac{f_1(h)}h=1$$
$$\lim_{h\rightarrow 0}\frac{f_2(h)}h=1$$
Then, you can conclude that the original limit exists as follows: For any $\varepsilon$, you can choose $\delta_1$ and $\delta_2$ such that for any $|x|<\delta_1$ you have $\left|\frac{f_1(h)}h-1\right|<\varepsilon$ and for any $|x|<\delta_2$ you have $\left|\frac{f_2(h)}h-1\right|<\varepsilon$. This is just from definition of the latter two limits. Then, for any $|x|<\min(\delta_1,\delta_2)$ you get that $\left|\frac{f(h)}h-1\right|<\varepsilon$, since one of the two above inequalities will be applicable. Thus, $f(h)$ must have the same derivative as $f_1$ and $f_2$ where those two functions and their derivatives agree.
A: By definition we need to compute $\displaystyle \lim_{h\to 0}\frac{f(0+h)-f(0)}{h}=\displaystyle \lim_{h\to 0}\frac{f(h)-0}{h}=\lim_{h\to 0}\frac{f(h)}{h}$
Notice for any $x\in \mathbb{R}$ we have $|x|\geq|\sin(x)|$ (Easy to check using mean value theorem). That means for $h>0$, we have $\sin(h)\leq f(h)\leq h\Rightarrow \frac{\sin(h)}{h}\leq \frac{f(h)}{h}\leq 1$, by squeeze theorem $\displaystyle \lim_{h\to 0^{+}}\frac{f(h)}{h}=1$. When $h<0$ the inequality reverses and we can also use squeeze theorem to conclude $\displaystyle \lim_{h\to 0^{-}}\frac{f(h)}{h}=1$.
Therefore  $\displaystyle \lim_{h\to 0}\frac{f(h)}{h}=1$, the function is differentiable at $0$ and the derivative is 1.
A: If you put $g(x)=f(x)-x$, then it suffices to show $g'(x)=0$.
If you are able to show that $|g(x)|\le x^2$ then you have
$$-x \le \frac{g(x)}x \le x$$
which implies $g'(x)=\lim\limits_{x\to0}\frac{g(x)}x=0$ (using squeeze theorem).
To prove the inequality for $|g(x)|$ you may use some inequality for $\sin x$. Some such inequalities can be found on this site. For example, see this question: Prove that $x - \frac{x^3}{3!} < \sin x < x$ for all $x>0$ 
