# Understanding higher order derivative result

I have problems in understating the result of the computation of higher order derivates.

D[(w - 1) f[w], {w, n}]


returns:

Inactive[Sum][
Binomial[n, K[1]]*D[f[w], {w, n - K[1]}]*Piecewise[{{1, K[1] == 1}}, 0],
{K[1], 0, n}
]


that, for $$n=1$$ reduces to $$f(w)$$ (which is wrong) and for $$n=2$$ gives $$2f'(w)$$ which is also wrong. What am I missing?

• This is the corresponding Latex expression for the answer that I could not include in the original post $$\sum_{k=0}^n \binom{n}{k}\partial_{w,n-k}f(w)\left(\left\{ \begin{array}{cc}1 & k=1\\0 & True\end{array}\right. \right)$$ – haran76 Feb 18 at 13:29
• What do you get if you manually apply the Leibniz rule to your function? – J. M.'s ennui Feb 18 at 13:41
• Let me specify that the function that I am studying is more complicated than $(w-1)f(w)$. I am just wondering why the result provided by Mathematica seems wrong to me, and this is the simplest case in which I encountered a difference between the expected solution and that given by the software – haran76 Feb 18 at 13:47
• @haran76 I've replaced a readable InputForm expression for your box-form code; for future reference, take a look at How to copy code from Mathematica so it looks good on this site. – MarcoB Feb 18 at 14:50
• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Michael E2 Feb 18 at 17:13

I can reproduce the error with version 12.0.0; however, it has been fixed, and with either version 12.1.1 or 12.2.0 I get correct results.

Clear["Global*"]

\$Version

(* "12.2.0 for Mac OS X x86 (64-bit) (December 12, 2020)" *)

dn[n_] = D[(w - 1) f[w], {w, n}]

(* Inactive[Sum][Binomial[n, K[1]]*
D[f[w], {w, n - K[1]}]*
(Piecewise[{{-1, K[1] == 0}},
0] + Piecewise[
{{w, K[1] == 0},
{1, K[1] == 1}}, 0]),
{K[1], 0, n}] *)


Or as a single Piecewise function:

dn[n] // PiecewiseExpand

(* Piecewise[{{Inactive[Sum][
(-1 + w)*Binomial[n, K[1]]*
D[f[w], {w, n - K[1]}],
{K[1], 0, n}], K[1] == 0},
{Inactive[Sum][
Binomial[n, K[1]]*
D[f[w], {w, n - K[1]}],
{K[1], 0, n}], K[1] == 1}},
Inactive[Sum][0, {K[1], 0, n}]] *)


seq = dn /@ Range[0, 3] // Activate

(* {(-1 + w)*f[w], f[w] +
(-1 + w)*Derivative[1][f][w],
2*Derivative[1][f][w] +
(-1 + w)*Derivative[2][f][w],
3*Derivative[2][f][w] +
(-1 + w)*Derivative[3][f][w]} *)


seq === (D[(w - 1) f[w], {w, #}] & /@ Range[0, 3])

(* True *)
`

I get these same results with version 12.1.1

• Thanks, I'll update my software as soon as I can. – haran76 Feb 18 at 22:24