# Prove the function $f(x)= \begin{cases}x^2 & x\in\mathbb{Q}\\-x^2 & else\end{cases}$ is differentiable at $x=0$

Prove the function $$f:\mathbb{R}\rightarrow\mathbb{R}$$ defined by $$f(x)= \begin{cases}x^2 & x\in\mathbb{Q}\\-x^2 & else\end{cases}$$

is differentiable at $$x=0$$ and that $$f'(0)=0$$.

Hey everyone, this is a simple calculus problem I've encountered, but I don't really know how to prove this using the definition $$lim_{x\to 0} \frac{f(x)-f(0)}{x-0}=f'(x)$$ because of the cases. It is trivial that if $$x\in\mathbb{Q}$$ then $$f'(x)=2x$$, else $$f'(x)=-2x \Rightarrow$$ both limits of these functions are zero when $$x$$ is approaching zero, but how do I formally prove the function is differentiable at $$0$$? Thanks :)

• $f$ is not differentiable at any $x\neq0$. Mar 1, 2018 at 9:49

$$\lim_{x \to 0} \left| \frac{f(x)-f(0)}{x}\right|=\lim_{x \to 0} \left| \frac{f(x)}{x}\right|=\lim_{x \to 0}\frac{x^2}{|x|}=\lim_{x \to 0}|x|=0$$
Hence $$\lim_{x \to 0} \frac{f(x)-f(0)}{x}=0$$
$$\frac {f(x)-f(0)}{x-0}= \begin{cases} x & x\in\mathbb{Q}\\-x & else\end{cases}$$ Thus $$\frac {f(x)-f(0)}{x-0}\to 0\implies$$
$$f'(0)=0$$
Even more: $g$ differentiable at $0$, $g(0) = g'(0) = 0,|f|\le |g|\implies$ $f$ differentiable at $0$, $f'(0) = 0$. Proof: when $x\to 0$, $$\left|\frac{f(x) - f(0)}{x - 0}\right| = \left|\frac{f(x)}{x}\right|\le \left|\frac{g(x)}{x}\right| = \left|\frac{g(x) - g(0)}{x - 0}\right|\rightarrow|g'(0)| = 0.$$