TITLE: Is it differentiable?
QUESTION [6 upvotes]: Let us consider the function 
$$
f(x)=
\begin{cases}
x^2\sin {\dfrac{\pi}{x}} & x \neq 0\\
0                        & x=0
\end{cases}
$$
We want to check its differentiability at $x=0$.
By the definition of $f'(x)$, the derivative of $f$ at $x=0$ would be $$f'(0)=\displaystyle\lim_{h \rightarrow 0}\dfrac{h^2\sin {\dfrac{\pi}{h}}}{h}$$ which would be $$f'(0)=\displaystyle\lim_{h \rightarrow 0} h\sin \frac{\pi}{h}$$
Using the squeeze theorem, we can prove that this limit is equal to $0$.
So according to the above procedure, the function is differentiable at $x=0$.
But, when we look at the graph of this function, it doesn't seem differentiable (below)

In addition to this, when we find $f'(x)$ by using the $u.v$ rule and the chain rule, $f'(x)$ does not exist.
So, is it differentiable or not?

REPLY [8 votes]: You can't check if a function is differentiable at $x=a$ if the function is not defined at $a$. In general, a function $f$ is differentiable at $a$ if $f^\prime(a)$ exists for $a\in\operatorname{domain}f$. If you define $f(0)$ in this case to be $0$ then your function is indeed differentiable at $x=0$ by what we said above.
Edit: You claimed that using the product rule and the chain rule means that $f^\prime(x)$ doesn't exist. Well let's check: $$\eqalign{\dfrac{\mathrm d}{\mathrm dx}\left[\,x^2\sin\left(\tfrac \pi x\right)\right]&=x^2\dfrac{\mathrm d}{\mathrm dx}\cos\left(\tfrac\pi x\right)+\sin\left(\tfrac\pi x\right)\dfrac{\mathrm d}{\mathrm dx}x^2\\&=x^2\left(-\dfrac{\pi\cos\left(\tfrac\pi x\right)}{x^2}\right) +\sin\left(\tfrac\pi x\right)\cdot2x\\&=2x\sin\left(\tfrac\pi x\right)-\pi\cos\left(\tfrac\pi x\right).\\}$$
So $f^\prime(x)$ seems to not exist when $x=0$, but you have to keep in mind that since you have defined $f(0)$ to be $0$ then what you're really differentiating is the piecewise function $$f(x)=\begin{cases}
x^2\sin\left(\tfrac\pi x\right), & x\neq0 \\
0, & x=0
\end{cases}.$$
And its derivative is: $$f'(x)=\begin{cases}
2x\sin\left(\tfrac\pi x\right)-\pi\cos\left(\tfrac\pi x\right), & x\neq0 \\
0, & x=0
\end{cases},$$ which makes sense since $f$ is continuous: $x\mapsto x^2\sin\left(\tfrac\pi x\right)$ being defined everywhere given that $x\neq0$, so the remaining thing is to check that: $$\lim_{x\to0^-}x^2\sin\left(\tfrac\pi x\right)=0=\lim_{x\to0^+}x^2\sin\left(\tfrac\pi x\right).$$

REPLY [4 votes]: First you must extend your function in $x=0$ by setting $f(0)=0$. Then your computation is correct, the function is differentiable in $0$. The graph also confirms this, since in $x=0$ the function is very close to the horizontal line. 
addendum
You can use the chain rule and product rule when you compute the derivative of two differentiable functions. So you can safely use that rule when $x\neq 0$ and you find the correct derivative. For $x=0$, however, the function is not a product: it is a function defined by cases. When $x\neq 0$ you can restrict your function to $x\neq 0$ so that it becomes a product of differentiable functions. When $x=0$ you cannot. So your last resort is apply the very definition of limit. 
Once that you have found the derivative in every point you can observe that the derivative in $x=0$ is not the limit of the derivative for $x\to 0$. In other words: this is (the most famous example of) a differentiable function whose derivative is not continuous.
The only possibility for this to happen is when the derivative $f'(x)$ has no limit when $x\to 0$, and this is exactly the case.