# Something wrong when I apply Derivative on a SparseArray

Bug introduced in v5.0 or earlier, and persisting through v11.0.1 or later

There, I create a SparseArray using command

y[t] = SparseArray[{{i_, 1} -> Subscript[y, i][t]}, {5, 1}]


And I want to get its third order derivative, Firstly I used Map to get the result

aa = D[#, {t, 3}] & /@ y[t] // MatrixForm


But the result is as follow

(*{{Derivative[1][Subscript[y, 1]][t]},
{Derivative[1][Subscript[y, 2]][t]},
{Derivative[1][Subscript[y, 3]][t]},
{Derivative[1][Subscript[y, 4]][t]},
{Derivative[1][Subscript[y, 5]][t]}}*)


And I know that the right result can be get by @@@

aa = D[#, {t, 3}] & @@@ y[t] // MatrixForm


With the result of

(*{Derivative[3][Subscript[y, 1]][t],
Derivative[3][Subscript[y, 2]][t],
Derivative[3][Subscript[y, 3]][t],
Derivative[3][Subscript[y, 4]][t],
Derivative[3][Subscript[y, 5]][t]}*)


Here what I wondered is that why the first command can get a result, and the result is wrong

Here, I get another method to solve this problem. Use Normal to this SparseArray

y[t] = SparseArray[{{i_, 1} -> Subscript[y, i][t]}, {5, 1}] // Normal
aa = D[y[t], {t, 3}]


then I get the result again

(*{{Derivative[3][Subscript[y, 1]][t]},
{Derivative[3][Subscript[y, 2]][t]},
{Derivative[3][Subscript[y, 3]][t]},
{Derivative[3][Subscript[y, 4]][t]},
{Derivative[3][Subscript[y, 5]][t]}}*)

• I have contacted support, [CASE:3606416] – vapor May 17 '16 at 4:03
• @happyfish Thanks for reporting it. I didn't do it because I was still waiting in case anybody had a rational explanation... – Jens May 17 '16 at 5:25
• @Jens bug confirmed by support. – vapor May 18 '16 at 2:46

There is definitely something wrong here. The alternative form of the third derivative would be to do three successive differentiations on the same object. The result in that approach is correct:

D[y[t], t, t, t] // MatrixForm


$$\left( \begin{array}{c} y_1{}^{(3)}(t) \\ y_2{}^{(3)}(t) \\ y_3{}^{(3)}(t) \\ y_4{}^{(3)}(t) \\ y_5{}^{(3)}(t) \\ \end{array} \right)$$

The fact that you get a different result with D[y[t], {t,3}] is not consistent with this result, and I would therefore consider it a bug.

The successive differentiations work even though they still return a SparseArray object, so it should definitely not be necessary to unpack the SparseArray before doing D, as you're effectively doing when using @@@.

To show how crazy things get with this bug, here is another attempt that produces the desired result in a silly way:

D[D[D[y[t], {t, 3}], {t, 3}], {t, 3}] // MatrixForm


$$\left( \begin{array}{c} y_1{}^{(3)}(t) \\ y_2{}^{(3)}(t) \\ y_3{}^{(3)}(t) \\ y_4{}^{(3)}(t) \\ y_5{}^{(3)}(t) \\ \end{array} \right)$$

This should of course be the ninth derivative if Mathematica had done it right.

• Thx. This answer means (D[y[t], t, t, t]) and (D[y[t], {t,3}]) works in different ways in mathematica? – 小菜220 May 17 '16 at 3:23
• Yes, it does indeed. The version I used does the first derivative three times in a row, as in D[D[D[y[t],t],t],t], and that is different from D[y[t],{t,3}] because in this case Mathematica will try to be more efficient. However, it's clearly doing this wrong. – Jens May 17 '16 at 3:27