# Why isn't $f(x) = x\cos\frac{\pi}{x}$ differentiable at $x=0$, and how do we foresee it?

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?

• Since non-differentiability is so common I would rather suspect every point of being non-differentiable locus and focus on foreseeing differentiability instead.
– Pp..
Jan 5, 2015 at 21:47
• @Pp.. that would be a good point of view if you were choosing functions at random. But we don't do that and since most functions we look at are infinitely differentiable.... Jan 5, 2015 at 22:04
• @IttayWeiss Actually, that is exactly what we do, don't get confused. It just happens that we use theorems like the properties of differentiation with respect to the arithmetic operations and elementary functions to get rid of big chunks of suspects.
– Pp..
Jan 5, 2015 at 22:15
• What the quoted passage is trying to say is that there is a big difference between the statements "$f'(0)=A$ exists" and "$f'(x)\to A$ as $x\to 0$". The function $g$ is a classic example of a function where the derivative exists at every point, but the function $g'$ is not continuous at the origin, since $g'(0)=0$ even though $g'(x)$ doesn't have a limit as $x \to 0$. Jan 6, 2015 at 9:33
• In other words: the way to think about $f'(0)$ is not to look at the tangent line at a nearby point $P$ on the curve and then let that point $P$ approach the origin. Rather, you take a rubber band ("infinitely shrinkable"), connect one end to the origin and the other end to a moving point $P$ on the curve, let $P$ approach the origin along the curve, and see if the rubber band can "make up its mind" about what slope to have in the limit. Jan 6, 2015 at 9:38

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.

• Perhaps you might comment that the parabolas have their vertices at $x=0$.
– Ian
Jan 5, 2015 at 22:04
• Indeed, this is the case in this function. However, it is not a necessary condition for differentiability. It just indicates that the derivative is $0$. Jan 5, 2015 at 22:05
• It's not necessary, but the envelope could be two parabolas that don't have their vertex at the point and which have different derivatives at the point. Then you'd be back in the first circumstance.
– Ian
Jan 5, 2015 at 22:07
• Muito obrigado, Pedro (ou se você prefere, Angelo)! (minha mae é de Rio) Até já! Jan 5, 2015 at 22:49
• haha :) Just for the record, envelope is envoltória in Portuguese. Might be similar in Italian. Jan 5, 2015 at 22:56

Normally the rules of differentiation show that any elementary function is continuous and differentiable wherever it is defined. The problems arise when the function's formula is undefined at some point and then we need to check the differentiability via the definition of derivative. Another case is when we define functions via multiple formulas in different parts of the domain. Then we need to check for existence of derivative at the boundary points.

The point which your book has highlighted is very important but perhaps been left out by other answers. It says that most common functions are differentiable except for exceptional points. Thus $f(x) = x\cos (\pi/x)$ is an example where $f$ is differentiable at all $x \neq 0$ and $$f'(x) = \cos (\pi/x) + \frac{\pi}{x}\sin(\pi/x)$$ When we define $f(0) = 0$ then we get continuity. But $f$ is still not differentiable at $0$.

Now your book mentions a very deep idea. Normally people try to look at the formula for $f'(x)$ and try to see if it tends to a particular value as $x \to 0$. In the above example the limit of $f'(x)$ does not exist and hence we conclude that $f$ is not differentiable at $0$.

The book says that this is not the right way to go and gives another example which sort of is a failure case for above technique. The example is $f(x) = x^{2}\cos (\pi/x), f(0) = 0$. We have $$f'(x) = 2x\cos(\pi/x) + \pi\sin(\pi/x)$$ and again we see that $f'(x)$ does not tend to a limit as $x \to 0$. And hence we conclude that $f'(0)$ does not exist. This is wrong.

We have the following theorem:

Theorem: If $f$ is continuous at $a$ and $\lim_{x \to a}f'(x) = L$ then $f'(a) = L$.

But the converse of the theorem does not hold. Thus if $f'(a) = L$ it does not mean that $\lim_{x \to a}f'(x)$ exists necessarily.

Thus the method of using limit of $f'(x)$ works only when the limit exists. Better not to try this approach and rather use the definition of derivative. I must say that your book has done a great job to highlight this fact about limit of derivative at a point and its relation to existence of derivative at that point (although not in the formal manner which I have given in my answer).

• Excellent. I took me a while to discern what the real Q is, which is "Why did the book say that?" Sep 6, 2017 at 18:55
• Thanks @DanielWainfleet for your encouraging words. Such feedback means a lot to me. Btw I was really impressed by the book excerpt given in the question where it talked about limiting position of tangent. Sep 6, 2017 at 21:47

The enveloping curves define differentiability. During infinite oscillations first curve tangent cannot decide between two slopes. But for the second, slopes are both equal to zero, makes it differentiable with its coinciding slope of tangent.

The book is giving a WARNING: "One $may$ think this (i.e. non-differentiable at $0$) happens because ( of the oscillations)...." and then shows that the same type of pattern of oscillations also exists for $g(x)=x^2\cos (\pi /x),$ so the occurrence of such an oscillatory pattern is insufficient to determine whether the function is differentiable at $0$.

Perhaps a different phrasing would have made this clearer. And I think it would have been more emphatic to have said that the oscillations in $g(x)$ near $0$ are large enough that $\lim_{x\to 0}g'(x)$ does not exist, but $g'(0)$ does exist, so the non-existence of $\lim_{x\to 0}f'(x)$ is, by itself, insufficient to determine whether $f'(0)$ exists.