# Random behaviour of Derivative(D[...]) with option "NonConstants"

Bug introduced in 8.0 or earlier and fixed in 11.1.0

Take the following example code:

D[c + h, {{x, y}}, NonConstants -> {c, h}]
D[a + h, {{x, y}}, NonConstants -> {a, h}]


Which generates the output:

{D[c, x, NonConstants -> {c, h}] + D[h, x, NonConstants -> {c, h}], D[c, y, NonConstants -> {c, h}] + D[h, y, NonConstants -> {c, h}]}
{0,0}


Why does this happen? I'm using a clean kernel. This doesn't only happen with the variable name a. However I couldn't find a pattern on which names work and which do not.

Mathematica version: 11.0.0

• Both inputs generate {0,0} (incorrect) in Mathematica 9 or earlier. In version 10 and later, only D[c + h, {{x, y}}, NonConstants -> {c, h}] and D[i + h, {{x, y}}, NonConstants -> {i, h}] generate correct results; all others returning 0. I'm thinking this is a bug. Jan 20 '17 at 18:57
• D[a + b, {{x}}, NonConstants -> {a}] gives {0} in all versions from 8.0 to 11.0.1. Looks like a bug to me, please report it to WRI. Jan 21 '17 at 14:23
• @jkuczm: I did. I'm waiting for a support response and then I'll update my answer. Jan 21 '17 at 16:59
• Maybe related: Dt is not able to handle gradients (at least not in a documented way), so I get the same wrong result with Dt[a+h,{{x,y}}] or Dt[c+h,{{x,y}}]. At least in this case both outputs are the same...
– Jens
Jan 21 '17 at 17:04

bug fixed in 11.1 Here is screen shot of both systems

I've found a partial answer to this. The documentation says:

D[f,v1,...,NonConstants->{u1,...}] specifies that every ui implicitly depends on every vj, so that they do not have zero partial derivative.


It seems the option is not designed to work with D[f,{{v1,...}},NonConstants->{u1,...}], i.e. gradients.

Still, this is pretty embarrassing considering there is no syntax error for this basic function and the behaviour is pretty random for different variable names. I spend like two days figuring out where my derivatives went missing.

It's probably a bug, but maybe someone has a better answer.

UPDATE: The Wolfram support has forwarded this issue to their developers, so it might be fixed in future versions.

possible workaround: Replace

D[f,{{v1,...}},NonConstants->{u1,...}]


by

Table[D[f,{{v1,...}}[[1,i]],NonConstants->{u1,...}], {i,1,Length[{{v1,...}}[[1]]]}]


and similar expressions for higher derivatives.