7
$\begingroup$

Update

This is a bug in v11.3 or earlier and is fixed in v12.

Original Post

Check this out:

f[y_] := RootSum[Function[x, x^2 - 1], Function[x, y - x]]
{f'[y], D[f[y], y]}
(*==>{2, 2}*)

g[y_] := RootSum[1 - #1^2 &, y - #1 &]
{g'[y], D[f[y], y]}
(*==>{0, 2}*)

The documentation says

Whenever Derivative[n][f] is generated, the Wolfram Language rewrites it as D[f[#],{#,n}]&.

A simple trace can show the flaw of this rewriting. Compare the last line but one:

Trace[g'[y]]

{{g^\[Prime],{g[#1],RootSum[#1^2-1&,#1-#1&],
  {(#1^2-1&)[Integrate`$$a[1]],
  Integrate`$$a[1]^2-1,-1+Integrate`$$a[1]^2},
  {(#1-#1&)[Integrate`$$a[1]],
Integrate`$$a[1]-Integrate`$$a[1],-Integrate`$$a[1]+Integrate`$$a[1],0},0},0&},(0&)[y],0}

with :

Trace[f'[y]]

{{f^\[Prime],{f[#1],RootSum[Function[x,x^2-1],Function[x$,#1-x$]],
  {Function[x,x^2-1][Integrate`$$a[1]],Integrate`$$a[1]^2-1,
  -1+Integrate`$$a[1]^2},
  {Function[x$,#1-x$][Integrate`$$a[1]],
  #1-Integrate`$$a[1]},2 #1},2&},(2&)[y],2}

The #1-#1& clearly shows the conflict.

Due to some reasons, I prefer to use Derivative to D, however in some cases, Integration returns functions like RootSum where #1 is ubiquitous.

Is this a bug in Derivative? If it is, how can I bypass this issue while still using Derivative?

$\endgroup$
  • $\begingroup$ In order to bypass it, define g with Set = instead SetDelayed := . g[y_] = RootSum[1 - #1^2 &, y - #1 &]; {g'[y], D[g[y], y]} yields {2,2} $\endgroup$ – Akku14 Jun 18 '18 at 15:42
  • 1
    $\begingroup$ @Akku14 This only counts on the fact that RootSum can be simplified at the beginning, for the more complicated cases, it is not correct either, such as RootSum[1 - #1 + #1^2 - #1^3 &, Log[y - #1] &] . Here I only post the toy model to show the issue. $\endgroup$ – luyuwuli Jun 18 '18 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.