Derivatives of list elements


Bug introduced in 8.0.0 and fixed in 9.0.0

Could someone explain the odd behavior of the Derivative function when drawing arguments from lists? We have,

Derivative[1][a + #*(b - c) &]
(* b - c & *)

and analogously,

Derivative[1][{a1, a2} + #*({b1, b2} - {c1, c2}) &]
(* {0, 0} + {b1, b2} - {c1, c2} + ({0, 0} + {0, 0}) #1 & *)

So far so good. However,

lst = {{a1, a2}, {b1, b2}, {c1, c2}};
Derivative[1][lst[[1]] + #*(lst[[2]] - lst[[3]]) &]
(* {lst[[2]] - lst[[3]], lst[[2]] - lst[[3]]} & *)

Why is the output in the last case not,

lst[[2]] - lst[[3]] &

as one would expect based on the previous examples? Why do I get a list of lists as an answer, instead of just a list? (And what should I do to get the expected result?)

Ted Pudlik

Posted 2013-04-29T19:21:27.853

Reputation: 345

What version are you running? I cannot reproduce your final result on v9.0.1. – rcollyer – 2013-04-29T20:53:05.967

I'm running Could it be a bug that's been corrected? – Ted Pudlik – 2013-04-29T20:57:34.740

Quite possibly. I can reproduce it on v8.0.1, and v8.0.4, but not on v9.0.0, or higher. So, retagging. I'll let someone else add [tag:bugs]. – rcollyer – 2013-04-29T20:59:17.650

@rcollyer Reproduced here too. Tagged. – Dr. belisarius – 2013-04-29T21:48:06.083

I updated to v9.0.1 and get the expected result now. Thanks for your help! – Ted Pudlik – 2013-04-29T22:01:25.257



As indicated in the comments, this has been fixed as of version 9.0.0.

lst = {{a1, a2}, {b1, b2}, {c1, c2}};                                   
Derivative[1][lst[[1]] + #*(lst[[2]] - lst[[3]]) &]                     

(* lst[[2]] - lst[[3]] & *)


Posted 2013-04-29T19:21:27.853

Reputation: 24 492

This is perhaps something to look at? At least the non-working example should be removed from the documentation. – Szabolcs – 2015-08-09T09:29:04.520

@Szabolcs Agreed, in fact there are several open bug reports for that issue, and I've updated them to link to the MSE discussion. Personally I'd prefer it to work as it used to (long ago), but updating the documentation may be more realistic at this point. – ilian – 2015-08-09T16:15:47.733