Find the domain at which $ f(X)=x|x|$ is differentiable? Okay this question was on our math exam today, which states that

Find the domain at which $ f(X)=x|x|$ is differentiable?
    (a) $\mathbb R$ 
  (b) $\mathbb R-\{0\}$
   (c) $\mathbb R$+
   (d) none of the above

I was thinking about two ways to solve the question:- 

the first one is to take the derivative of the function using the product rule which will be  $ f'(x) = |x| + x    \frac d {dx}|x| $ 
while I know that the function $|x|$ is not differentiable at zero then I deduced that $f'(x) $ is not differentiable at zero so I chose (b)   " $\mathbb R-\{0\}$ ".


the second way to think about the problem is to deal with it as ordinary $ |X| $ which will give us $X^2$ and $-x^2$, and taking their derivative which is $2x$ and $-2x$ by substituting by zero then both sides will be zero so it will be differentiable at zero so i chose  (a)  $\mathbb R$

So, i need help to find the most correct one, and why the another is wrong.
Thanks.
 A: You are correct, indeed


*

*for $x\ge 0 \implies f(x)=x^2$

*for $x < 0 \implies f(x)=-x^2$


and the derivative at $x=0$ is $0$.
We can also show this fact directly by definition of derivative at the origin.
Note that $f(x)$ in not twice differentiable then $f\in C^1$ but $f\not \in C^2$.
A: As gimusi states, it is in fact true that the function is differentiable on $\mathbb{R}$. I'd like to add some explanation of why the first method failed you.
You make good use of the product rule here, but one important point is that the product rule assumes that the two functions being multiplied are differentiable. That is, the result from the product rule is only valid at those points where $x$ and $|x|$ are both differentiable. As for the other points, there may be a derivative there or there may not be, but the product rule will not determine that. Thus you will see that it is at least differentiable on $\mathbb{R}-\{0\}$, but you will have to do further analysis to determine if it is differentiable at $0$.
Note also that $x \frac{d|x|}{dx} = |x|$ when $x\neq0$, so $f^\prime(x) = 2|x|$ when $x\neq0$. If we ignore the condition on the product rule, we can see intuitively why $f^\prime(0)=0$ should be true.
A: Find the domain at which f(X)=x|x| is differentiable?
Note that$$ f(x) =\begin{cases}-x^2,&\text {if $x\le 0$}\\ x^2,&\text {if $x\ge 0$}\end{cases} $$
The derivative is then 
$$f'(x) =\begin{cases}-2x,&\text {if $x\le 0$}\\ 2x,&\text {if $x\ge 0$}\end{cases} $$
Note that at $x=0$ the right derivative and the left derivative are the same so $f'(0)=0.$
Thus this function is differentiable on $\mathbb R $ 
