Calculus Real Analysis – Why $f(x) = x\cos\frac{\pi}{x}$ is Not Differentiable at $x=0$

analysiscalculusderivativesreal-analysis

Consider $$f(x)=\begin{cases}
x\cos\frac{\pi}{x} & \text{for} \ x\ne0 \\
0 & \text{for} \ x=0.
\end{cases}
$$

Its difference quotient $\frac{\Delta\left(f(x)\right)}{\Delta(x)}$ approaches $\cos\frac{\pi}{h}$ as $x$ gets closer to $0$, and thus $f$ is not differentiable in the origin because $\lim\limits_{h\to0}\cos\frac{\pi}{h}$ does not exist. This is the plot of $y=x \cos \frac{\pi}{x}$:

But here's how my book goes on:

Examining the figure we can foresee that the tangent line in a generic point $P$ of the graph doesn't tend to any limiting position as $P$ tends to the origin along the curve itself. One may think this happens because the graph of the function completes infinitely many oscillations in any neighbourhood of the origin. In fact, no: indeed the function thus defined: $$g(x)=\begin{cases}
x^2\cos\frac{\pi}{x} & \text{for} \ x\ne0 \\
0 & \text{for} \ x=0
\end{cases}
$$
has a graph that completes infinitely many oscillations in any neighbourhood of the origin, but, as you can verify, it is differentiable at $x=0$ and we have $g'(0)=0$.

This is the plot of $y=x^2 \cos \frac{\pi}{x}$:

So, I have two questions related to what I quoted from the book: how do we foresee the non-differentiability of $f$, given that, correctly, the infinitude of the oscillations is not an argument for it? And then, why isn't $f$ differentiable, instead of $g$?

I shall emphasise that I know that, simply, the limit as $h\to 0$ of the difference ratio of $f$ doesn't exist, while that of $g$ does, but I've been wondering about an other kind of reason after reading that excerpt. Or is my book wrong in mentioning other reasons?

Best Answer

One way to "foresee" it is that there are clearly two lines in the first image you posted that serve as an envelope to $f(x)$. These two lines crossing at the origin make it impossible to approximate $f$ near $x=0$ as a linear function. This is the criterion of differentiability you want to keep in mind when trying to make this kind of judgement.

On the other hand, in the second image, the envelope is two parabolas touching at the origin. Since the parabolas are tangent at the origin, they force $y=0\cdot x$ to be the only way to approximate $f(x)$ as a linear function near $x=0$.

In the end, the criterion for differentiability of functions squeezed inside an envelope $$e_-(x)\leq f(x)\leq e_+(x)$$ is: no matter how wildly $f(x)$ oscillates inside the envelope, $f(x)$ will be differentiable at $x=0$ if (i) the envelopes touch each other: $$e_-(0)=e_+(0)$$ that is, they do squeeze $f(x)$ appropriately; and (ii) they are both differentiable with equal derivatives: $${e'}_{\!-}(0)={e'}_{\!+}(0)$$ thus forcing $f(x)$ to be differentiable with the same derivative.