# Is it differentiable?

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?

-
So it's differentiable! and $f'(0)=0$ i.e. it has a horizontal tangent line on $0$. –  Sami Ben Romdhane Jul 12 at 11:04
Seems differentiable to me. –  Brad Jul 12 at 11:06
You're deceived by the fact that $f$ is not twice differentiable at $0$. Graphs are useful, but they can be misleading. –  egreg Jul 12 at 11:32
This is the classical example of a function differentiable but not $C^1$ (the limit of $f'$ in $0$ does not exist). –  enzotib Jul 12 at 12:17

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).$$

-
It is usually implied (or explicitly stated) that the function is defined to be zero at zero. –  Brad Jul 12 at 11:08
@Brad Well the OP didn't explicitly state it, but if he define it that way then according to my answer the function is differentiable at $x=0$. –  Hakim Jul 12 at 11:09
@Hakim But i do have one doubt--Do the left hand derivative and right hand derivative at $x=0$ match? That condition should be satisfied for $f$ to be differentiable, right? –  Pkwssis Jul 12 at 11:58
@user157130 You mean the left hand limit and right hand limit as $x\to0$? –  Hakim Jul 12 at 12:26
@Hakim No i mean left and right hand derivatives –  Pkwssis Jul 12 at 12:28

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.

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.
By the definition of a derivative, the function doesn't need to be defined. A tangent is a $\textbf{limiting}$ case of a chord. –  Pkwssis Jul 12 at 11:07
To have a chord passing through $(0,f(0))$ you need to know what is $f(0)$. –  Emanuele Paolini Jul 12 at 11:08
@user157130 If you define $f(0)$ to be $0$, then the chord does pass through $(0,f(0))$. –  Hakim Jul 12 at 11:17