Consider the function $$f: \mathbb R\to\mathbb R, x\mapsto\begin{cases}\frac{\sin^2(x)}x, & x\neq 0, \\ 0, & x=0.\end{cases}$$
It is true that $f\in\mathcal C^1(\mathbb R)$ and that $$f'(x)=\begin{cases}\frac{2 \sin (x) \cos (x)}{x}-\frac{\sin ^2(x)}{x^2}, & x\neq 0, \\ 1, & x=0.\end{cases}$$
(The fact that $f'(0)=1$ can be derived directly from the definition of the derivative.)
However, when I enter $f'(0)$ into Mathematica (in this case Wolfram Alpha but it makes no difference), I get $f'(0)=0$. Even more astonishingly, if I define $$g:\mathbb R\to\mathbb R, x\mapsto\begin{cases} \frac{\sin^2(x)}x, & x\neq0, \\ x, & x=0,\end{cases}$$
then $f=g$. However, Mathematica gives $g'(0)=1\color{red}\neq f'(0)$. It seems that Mathematica has a massive programming error when it comes to differentiating piecewise functions!
Is this a known error?
Note: This bug was originally discovered by Micah Windsor in a discussion on $f'(0)$ here.
Limit[D[f[x], x], x -> 0]
it gives1
I do not know why it does not work on the Piecewise function itself. $\endgroup$SeriesCoefficient[f[x], {x, 0, 1}]
works (12.1.0), butSeriesCoefficient[f[$x], {$x, x, 1}, Assumptions -> x \[Element] Reals]
gives a rather interesting answer. $\endgroup$x
in the derivative gives an indeterminate form that happens to be at a removable singularity.Series
can be quite useful in such cases (and so canLimit
, but that's a heavier hammer). $\endgroup$Limit[D[Sinc[x] Sin[x], x], x -> 0]
works perfectly fine. $\endgroup$