# Derivative function anomaly in Mathematica v. 13.1 (identified as a DifferenceRoot issue)

Bug introduced after 12.1.1, in or before 12.3, persisting through 13.2.1., fixed in 13.3.0

Edit: For a quick reference - the first Answer (most helpfully) identified the problem as related to DifferenceRoot[].

Recently I upgraded to Mathematica v. 13.1. It appears that applying the built-in derivative function, D[expr,{x,n}], as I used to with version 12.1.1, produces a different output, for which I was unable to find an explanation. In Mathematica v. 12.1.1, applying the $$n$$-th derivative, with D[expr,{x,n}], for $$n=0$$, gives the same result as with the Derivative[n][expr] function, which is effectively, equivalent to 'not taking a derivative', leaving the original expression unchanged.

The intention is to express the order of the derivative in general, i.e. $$\frac{d^n}{x^n} (x 10^{-x^3})$$ and to specify $$n$$ in the process of further computation. The expression $$x 10^{-x^3}$$is only a representative example. It illustrates the apparent discrepancy for a derivative order $$n=0$$, when specified in two different ways, by applying the functions Derivative[n][x*10^(-x^3)] and D[x*10^(-x^3),{x,n}] for comparison, as follows:

{Derivative[n][x*10^(-x^3)],D[x*10^(-x^3),{x,n}]}/.n->0//Simplify

(* {10^-x^3 x,10^-x^3 x} *)

{Derivative[0][x*10^(-x^3)],D[x*10^(-x^3),{x,0}]}

(* {10^-x^3 x,10^-x^3 x} *)


In Mathematica 13.1, applying the $$n$$-th derivative with D[expr,{x,n}], for $$n=0$$, gives a different result, as shown below:

{Derivative[n][x*10^(-x^3)],D[x*10^(-x^3),{x, n}]}/.n->0//Simplify

(* {10^-x^3 x,(10^-x^3 (-2 + 3 x Log[10] + 6 x^3 Log[10] - 27 x^6 Log[10]^2)) / (3 Log[10])} *)

{Derivative[0][x*10^(-x^3)],D[x*10^(-x^3),{x, 0}]}

(* {10^-x^3 x, 10^-x^3 x} *)


The unexpected result does not verify with the expression ($$0$$-th derivative), which could be an erroneous function in version 13. It should be also noted that exactly the same lines of code correctly output higher derivatives, for $$n=1,2,...$$? in both Mathematica versions!

The question is:

Why, in Mathematica version 13.1, D[expression, {x,n}]/.n->0 does not output the original expression, as it does in Mathematica version 12.1.1, as well as with the alternative specifying the $$0$$-th derivative?.

• I can confirm this behavior, looks like a bug. Have you reported it? Commented Nov 2, 2022 at 14:58
• Yes, I have. The reply: "I discussed this with the developers and a report has been filed. From the code perspective the current behavior is correct but but from the mathematical perspective the old behavior is preferred. In any case we should document such changes if they are intended and correct them if they are not intended. Harry Calkins Wolfram Technical Support" Commented Nov 2, 2022 at 16:25
• Tech Support's claim is incorrect. The current behavior is wrong from the code perspective. Commented Nov 21, 2022 at 18:58

# TL;DR

Appears to be a bug in DifferenceRoot introduced in Mathematica 13.

# Minimal Working Example

f = DifferenceRoot[Function[{y, n},
{c0 y[n] + c1 y[1 + n] + c2 y[2 + n] == 0,
y[0] == y0,
y[1] == y1}]];
FullSimplify[f[-1]]


Gives $$-\frac{c_1 y_0+c_2 y_1}{c_0}$$ in Mathematica 12, but $$\frac{c_1^2 y_0+c_2 c_1 y_1-c_0 c_2 y_0}{c_0^2}$$ in Mathematica 13

# Details

This is very strange and looks like a bug indeed, but not in D. The bug appears to be in DifferenceRoot, which is returned by your call to D.

In both 12 and 13 I find

D[x 10^(-x^3), {x, n}]


gives identical output of

n! (

DifferenceRoot[Function[{y, n}, {(3 + n) y[3 + n] + 3 y[n] Log[10] +
6 x y[1 + n] Log[10] + 3 x^2 y[2 + n] Log[10] == 0,
y[0] == 10^-x^3, y[1] == -3 10^-x^3 x^2 Log[10],
y[2] == 3 2^(-1 - x^3) 5^-x^3 x Log[10] (-2 + 3 x^3 Log[10])}]][-1 + n] +

x DifferenceRoot[Function[{y,n}, {(3 + n) y[3 + n] + 3 y[n] Log[10] +
6 x y[1 + n] Log[10] + 3 x^2 y[2 + n] Log[10] == 0,
y[0] == 10^-x^3, y[1] == -3 10^-x^3 x^2 Log[10],
y[2] == 3 2^(-1 - x^3)5^-x^3 x Log[10] (-2 + 3 x^3 Log[10])}]][n]

)


Which is the same DifferenceRoot twice, evaluated at $$n-1$$ and $$n$$. When this DifferenceRoot is evaluated at $$-1$$, it gives back different results in Mathematica 12 vs 13. Namely

DifferenceRoot[Function[{y, n}, {(3 + n) y[3 + n] + 3 y[n] Log[10] +
6 x y[1 + n] Log[10] + 3 x^2 y[2 + n] Log[10] == 0,
y[0] == 10^-x^3, y[1] == -3 10^-x^3 x^2 Log[10],
y[2] == 3 2^(-1 - x^3) 5^-x^3 x Log[10] (-2 + 3 x^3 Log[10])}]][-1]//FullSimplify


gives back $$0$$ in Mathematica 12 but

$$\frac{10^{-x^3} \left(3 x^3 \log (10) \left(2-9 x^3 \log (10)\right)-2\right)}{3 \log (10)}$$

in Mathematica 13. I also tried for integer arguments $$-5\leq k\leq 5$$ and 12 vs 13 disagreed for all $$k<0$$ but agreed for $$k\geq 0$$. For $$k<0$$, they were all $$0$$ in 12 and all something non-zero in 13. This is indeed very curious and just looks like a plain old bug. Please report, I'll do the same.

• Quite interesting that although f[-1] gives unexpected result, FunctionExpand[f[n]]/.n->-1//Simplify gives (-c1 y0+y1)/c0 Commented Nov 8, 2022 at 23:25
• @yurie interesting, that seems to poke some holes in the support response to OP of "I discussed this with the developers and a report has been filed. From the code perspective the current behavior is correct but but from the mathematical perspective the old behavior is preferred. In any case we should document such changes if they are intended and correct them if they are not intended. - Harry Calkins Wolfram Technical Support" Commented Nov 9, 2022 at 22:37
• Another observation: (f /. {c0 -> 1, c1 -> 2, c2 -> 3, y0 -> 4, y1 -> 5})[-1] gives -23, this is the correct result. Commented Nov 18, 2022 at 3:02