# A bug in Derivative?

## 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], Integrate$$a^2-1,-1+Integrate$$a^2}, {(#1-#1&)[Integrate$$a],
Integrate$$a-Integrate$$a,-Integrate$$a+Integrate$$a,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],Integrate$$a^2-1, -1+Integrate$$a^2}, {Function[x$$,#1-x$$][Integrate$$a],
#1-Integratea},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?

• 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} – Akku14 Jun 18 '18 at 15:42
• @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. – luyuwuli Jun 18 '18 at 16:20