Edits:
Additional illustrations are provided for comparison with
D[]
in Mathematica 12, as clarifying examples, supplemented at the end.An erroneous Derivative construct (as pointed out in yurie's comment and elaborated in xzczd's Answer) is removed from the examples. The issue raised in the examples remains unchanged.
This question is a follow up from my previous raising the issue with a derivative computing anomaly in Mathematica 13.
It was established (most helpfully in the Answer by bRost03) that the problem described in relation to the derivative function D[]
is likely caused by DifferenceRoot[]
, introduced in Mathematica 13. The problem was reported to Mathematica Customer Service.
In the meantime I am trying to find a workaround, as my project, built up with Mathematica 12, uses derivatives of order n = 0,1,2,3
of expressions. While in the previous question, referenced above, it was shown that Derivative[n][expr]/.n->0
and Derivative[0][expr]
both gave correct result, unlike D[expr,{x,n}]/.n->0
, compared to D[expr,{x,0}]
, subsequent attempts to use Derivative[]
instead of D[]
revealed further apparently anomalous output. The issue is described below, using the expression $-x10^{(-x^3)}$.
The following illustrates the output of three different ways of applying the Derivative[]
function to the same expression.
expr = -x 10^(-x^3);
f[x_] := -x 10^(-x^3);
{Derivative[n][-x 10^(-x^3)], Derivative[n][expr],
Derivative[n][f][x]}
It is the last of the three above, which involves using
DifferenceRoot
, apparently causing the problems with the Derivative[]
and D[]
functions.
The next two lines illustrate, the results from specifying the derivative order directly. For $n=0$ the output from all three cases is correct. With $n=1$ specified directly, however, the third construct gives the correct result, while the first two remain unevaluated.
{Derivative[0][-x 10^(-x^3)], Derivative[0][expr],
Derivative[0][f][x]}
{Derivative[1][-x 10^(-x^3)], Derivative[1][expr],
Derivative[1][f][x]} //Simplify
The problem becomes more apparent, when the derivative order is given as a replacement rule. The output of the next line demonstrates that the third Derivative construct appears to miscalculate the 0th derivative, which should reproduce the original expression, as do the first two.
{Derivative[n][-x 10^(-x^3)], Derivative[n][expr],
Derivative[n][f][x]}/.n->0//Simplify
The situation seems to improve, when computing the first derivative with $n=1$, specified as a replacement rule below. The third of the derivative constructs produces the correct result, while, for some reason, the first two, which 'did well' with $n=0$, this time 'do not compute'.
{Derivative[n][-x 10^(-x^3)], Derivative[n][expr],
Derivative[n][f][x]}/.n->1//Simplify
The following lines show that, somehow,
Derivative[n][f][x]
, which fails with $n=0$, computes the derivatives for n={1,2,3}
correctly, while Derivative[n][-x 10^(-x^3)]
and Derivative[n][expr]
, which correctly reproduce the expression, as a 0th derivative, apparently do not output derivative expressions for $n>0$. What is more, they do not show the 0th derivative, when it is specified as a replacement rule in a list, n->{0,1,2,3}
. The functions corresponding to the derivative constructs are given separately below for readability.
{Derivative[n][-x 10^(-x^3)], Derivative[n][expr]}/.n->{0,1,2,3}//FullSimplify
Derivative[n][f][x] /. n -> {0, 1, 2, 3} // FullSimplify
The question is:
Would it be possible to find a workaround, so that a single general derivative construct computes correctly the n-th derivative, where n is given as a list n->{0,1,2,3}, in Mathematica 13?
(I remain conscious of the apparent problem with DifferenceRoot, as identified in the answer to my previous question, referenced at the beginning, which may prevent finding a solution until the anomaly is cleared by Mathematica developers.)
Edit: The following four lines of code, show the results from the D[]
and Derivative[]
functions in Mathematica 13, for comparison with the CORRECT output from the same functions in Mathematica 12. The same expression, $-x10^{(-x^3)}$, with f[x_] := -x 10^(-x^3)
is used in the examples.
Two lines with the corresponding output from the derivative functions in Mathematica 13, both showing the anomalous 0th derivative output:
Multicolumn[
Flatten[{n, D[-x 10^(-x^3), {x, n}], Derivative[n][-x 10^(-x^3)]}
/. n -> {0, 1, 2, 3}], {4, 3}, Spacings -> 3] // FullSimplify
Multicolumn[
Flatten[{n, D[f[x], {x, n}], Derivative[n][f][x]} /.
n -> {0, 1, 2, 3}], 3, Spacings -> 3] // FullSimplify
Two lines with the corresponding output from the derivative functions in Mathematica 12. The first one shows the desired CORRECT output in v.12, for which an equivalent (or a workaround) is so much needed in v.13. The second line shows that Derivative[] does not provide the answer in in v.12, either:
Multicolumn[
Flatten[{n, D[f[x], {x, n}], D[-x 10^(-x^3), {x, n}]} /.
n -> {0, 1, 2, 3}], 3, Spacings -> 3] // FullSimplify
Multicolumn[
Flatten[{n, Derivative[n][f][x], Derivative[n][-x 10^(-x^3)]} /.
n -> {0, 1, 2, 3}], {4, 3}, Spacings -> 3] // Simplify
Derivative[n][f[x]]
is neitherDerivative[n][f][x]
norD[f[x],{x,n}]
, see the document ofDerivative
$\endgroup$