# A function that is differentiable at exactly two points

As homework we were given 2 questions:

1. Find a function that is continuous at exactly one point and not differentiable there.

2. Find a function that is differentiable at exactly two points.

The answer to the first one was somewhat simple - $$f(x) = x*D(x)$$, wherein $$D(x)$$ stands for Dirichlet function.

I've been thinking about the second question for a while, and someone suggested me the following: $$g(x) = x^2*D(x)$$

$$f(x) = (x-1)^2 * g(x)$$

Claiming that $$f(x)$$ is only differentiable in $$x = 0, x = 1$$. Why is that?

• It follows the exactly same proof to that $x^2D(x)$ is only differentiable in $x=0$. Note that $g(x-1) = (x-1)^2 D(x-1)$ and $D(x-1)=D(x)$. – Yanko Jan 12 '19 at 17:39

It is simplier to say that$$g(x)=\begin{cases}x^2(x-1)^2&\text{ if }x\in\mathbb Q\\0&\text{ otherwise.}\end{cases}$$And, yes, this exmple works. Outside $$\{0,1\}$$ $$g$$ is discontinuous, and therefore non-differentiable. And it follows from the definition of $$g'$$ that $$g'(0)=g'(1)=0$$.
Clearly, $$f$$ is not differentiable away from $$0$$ and $$1$$: the $$x^2$$ and $$(x-1)^2$$ factors don't fix the horribleness of the Dirichlet function there: a rational $$y$$ near some $$x$$ is sent near to $$x^2(x-1)^2$$, while an irrational $$y$$ near $$x$$ is sent to $$0$$, and those differ, so $$f$$ isn't even continuous away from $$0$$ and $$1$$.
So, why is it differentiable at $$0$$ and $$1$$: well, let's just check the definition.
$$\lim_{x\to 0}\frac{f(x)-f(0)}{x} = \lim_{x\to 0}\frac{x^2(x-1)^2D(x)}{x} = \lim_{x\to 0}x(x-1)^2D(x),$$ and $$|x(x-1)^2D(x)| \leq |x|(x-1)^2 \to 0$$ as $$x \to 0$$, so the limit exists, and is zero, at $$0$$. Similarly, $$\lim_{x\to 1}\frac{f(x)-f(1)}{x-1} = \lim_{x\to 1}x^2(x-1)D(x),$$ and $$|x^2(x-1)D(x)| \leq x^2|x-1| \to 0$$ as $$x \to 1$$.