3
$\begingroup$

Edits:

  1. Additional illustrations are provided for comparison with D[] in Mathematica 12, as clarifying examples, supplemented at the end.

  2. 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]}

Out 1_13 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]}

Out 2_13

{Derivative[1][-x 10^(-x^3)], Derivative[1][expr],
 Derivative[1][f][x]} //Simplify

Out 3_13 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

Out 4_13 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

Out 5_13 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

Out 6_13

Derivative[n][f][x] /. n -> {0, 1, 2, 3} // FullSimplify

Out 7 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

Out 8_13

Multicolumn[
  Flatten[{n, D[f[x], {x, n}], Derivative[n][f][x]} /. 
    n -> {0, 1, 2, 3}], 3, Spacings -> 3] // FullSimplify

Out 9_13

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

Out 10_12

Multicolumn[
  Flatten[{n, Derivative[n][f][x], Derivative[n][-x 10^(-x^3)]} /. 
    n -> {0, 1, 2, 3}], {4, 3}, Spacings -> 3] // Simplify

Out 11_12

$\endgroup$
2
  • $\begingroup$ Derivative[n][f[x]] is neither Derivative[n][f][x] nor D[f[x],{x,n}], see the document of Derivative $\endgroup$
    – Lacia
    Commented Nov 8, 2022 at 23:19
  • $\begingroup$ @yurie I did, however it turned out that I had misunderstood a Detailed Option for D[]. The wrong construct was edited out. Apologies for not appreciating your comment initially. $\endgroup$
    – ghogoh
    Commented Nov 10, 2022 at 18:11

1 Answer 1

5
$\begingroup$

Two issues here.

The first one is, as pointed out by yurie, you have a serious misunderstanding for how Derivative works. The code Derivative[n][f[x]] won't work as expected, because for Derivative[n][something], the something should be a function relationship rather than a function value. Just compare the output of

Derivative[1][Sin]
(* Cos[#1] & *)

and

Derivative[1][Sin[x]]
(* Sin[x]' *)

and think about what has happened. Actually this isn't even a Mathematica problem but a logical problem in my view: How will Mathematica know what's the independent variable if you write Derivative[1][Sin[x y z]]? (Notice the output of Derivative[0][Sin[x]] looks correct because the whole Sin[x] has been treated as a function relationship. )

OK, then how to circumvent the mentioned bug of DifferenceRoot? That's simple, just avoid the symbolic derivative order that is supported since v11.1_:

TableForm@Table[{n, D[f[x], {x, n}], D[expr, {x, n}]}, 
                {n, 0, 3}] // FullSimplify

(* Alternatively: *)
TableForm@Table[{n, Derivative[n][f][x], Derivative[n][x |-> Evaluate@expr][x]}, 
                {n, 0, 3}] // FullSimplify

Notice the difference of evaluation order here. In my code the D[f[x], {x, n}] is evaluated after the numeric value of n is substituted into the expression, so the DifferenceRoot[…] is never generated.

$\endgroup$
6
  • $\begingroup$ thanks! Admitting my lesser understanding, I am grateful for the explanation. I misinterpreted "The derivative D[f[x],{x,n}] for a symbolic f is represented as Derivative[n][f][x]." The Derivative[n][f[x]] included not to leave out a tested possibility. The offending construct is removed still leaving a valid issue in search of resolutions. On avoidance of symbolic order - helpful examples appreciated. Symbolic derivatives order is need in my project as I try to set up dynamic evaluation of functions, including simultaneous Manipulated Plots, where the order is computed in the process. $\endgroup$
    – ghogoh
    Commented Nov 10, 2022 at 18:05
  • $\begingroup$ @ghogoh If the general derivative is not needed as the final output, symbolic derivative order should always be avoidable with proper evaluation order adjustion. Can you add a sample in which you think symbolic derivative order cannot be avoided? $\endgroup$
    – xzczd
    Commented Nov 11, 2022 at 0:31
  • $\begingroup$ Expressions/functions are obtained as solutions of differential equations with initial/boundary conditions varied as parameters. The initial conditions are expressions and their derivatives. The results are investigated over a list of values for the order n (not necessarily consecutive) with the following sample of graphical output. Manipulate[Plot[Evaluate[Re[(1/(n + 1)!) D[f[x], {x, n}]*Exp[-I (n + 1/2) t] /.t->tt]],{x,0,1.5},PlotRange->{-1,1}],Control[{{n,1,"n"},{0,1,2,3}}],{{tt,0,"t ="},0,(8-5n/2)Pi}]. Expressions are selected from n-th derivative tests so n is an arbitrary list. $\endgroup$
    – ghogoh
    Commented Nov 11, 2022 at 15:44
  • $\begingroup$ @ghogoh In this sample, the derivative order is not symbolic. You can use a Echo (modify the D[…] to Echo@D[…]) to confirm it. $\endgroup$
    – xzczd
    Commented Nov 12, 2022 at 1:27
  • $\begingroup$ Thank you for bearing with my clumsy expositions. Assumed the symbolic part was deducible from the explanation, referring to standard equation solving steps: g[x_,n_]:=(1/n!)D[-x 10^(-x^3),{x,n}]; weg=I D[wg[x,t],t]==2D[wg[x,t],{x,2}]; icg=wg[x,0]==g[x,n]; solg=DSolve[{weg,icg},wg,{x,t},Assumptions->t>=0]; The solution is tested over values for n against range/domain criteria and an list n= {...} corresponding to complying functions is selected for further investigation like the example in the previous comment. Better ways of doing it are awaiting for my progress into Mathematica. $\endgroup$
    – ghogoh
    Commented Nov 12, 2022 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.