# Why is the differentiability of a piecewise defined function studied using the definition of derivative?

Why is the differentiability of a piecewise defined function often studied using the definition of derivative?

For example, let: \begin{align*} f(x) &= x\cdot |x-1|\\ &= \left\{ \begin{array}{lcl}x (-x+1)& \text{if} & x < 1 \\ x (x-1) & \text{if} & x \geq 1 \end{array} \right.\\ &= \left\{ \begin{array}{lcl}-x^2+x& \text{if} & x < 1 \\ x^2-x & \text{if} & x \geq 1 \end{array} \right. \end{align*}

$f$ is continuous in $\mathbb{R}$ except, maybe, when $x=1$: \begin{align*} \lim_{x \to 1^{-}} f(x) &= \lim_{x \to 1} (-x^2+x) = 0\\ \lim_{x \to 1^{+}} f(x)&= \lim_{x \to 1} (x^2 -x) = 0 \end{align*}

$f$ is continuous when $x=1$ because: $$\lim_{x \to 1^{-}} f(x) = \lim_{x \to 1^{+}} f(x) = f(1)$$

As to the differentiability at that point (by derivative's definition):

\begin{align*} \lim_{h \to 0^{-}} \frac{f(1+h)-f(1)}{h} &= \lim_{h \to 0} \frac{\left[-(1+h)^2 + (1+h)\right] - \left[-1^2 + 1\right]}{h}\\ &= \lim_{h\to 0} \frac{- h(h+1)}{h} = -1\\ \strut\\ \lim_{h \to 0^{+}} \frac{f(1+h)-f(1)}{h} &= \lim_{h \to 0} \frac{\left[(1+h)^2 - (1+h)\right] - \left[1^2 - 1\right]}{h}\\ &= \lim_{h\to 0} \frac{h(h+1)}{h} = 1 \end{align*}

$$\lim_{h \to 0^{-}} \frac{f(1+h)-f(1)}{h} \neq \lim_{h \to 0^{+}} \frac{f(1+h)-f(1)}{h}$$

so $f$ is not differentiable when $x=0$.

The "second" method is:

$$f'(x) = \left\{ \begin{array}{lcl} -2x + 1& \text{if} & x < 1 \\ 2x-1 & \text{if} & x > 1 \end{array} \right.$$

$$f'(1^{-}) = -1 \neq f'(1^{+}) = 1$$

Is there any case in which the differentiability study by using the derivative (the second method) would be wrong?

-

Consider the function $$f(x) = \left\{\begin{array}{ll} x^2\sin\left(\frac{1}{x}\right) &\text{if }x\neq 0,\\ 0 &\text{if }x=0. \end{array}\right.$$
The function is differentiable at $0$, with derivative equal to $0$: \begin{align*} \lim_{h\to 0}\frac{f(h)-f(0)}{h} &= \lim_{h\to 0}\frac{h^2\sin(\frac{1}{h})}{h} \\ &=\lim_{h\to 0}h\sin(\frac{1}{h}) = 0. \end{align*} However, using the "second method", we look at the derivative of $x^2\sin(\frac{1}{x})$: $$\left(x^2\sin\left(\frac{1}{x}\right)\right)' = 2x\sin\frac{1}{x} - \cos\frac{1}{x}.$$ And $$\lim_{x\to 0}\left(2x\sin\frac{1}{x}-\cos\frac{1}{x}\right)$$ does not exist. Using the method, we would incorrectly conclude that the derivative does not exist at $0$.