5
$\begingroup$

I have been struggling with an issue that I believe has a simple way to solve. Given that I have extracted a term of a partial differential equation: f(1,2,0) [x,y,z]. In this case, it is similar to the operation D[f,{x,1},{y,2}].

Is there a function that extracts the information of the derivatives? In other words, that if applied to f(1,2,0) [x,y,z] would give me ans = {1,2,0}?

Thank you very much!!!

$\endgroup$
1
  • $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$
    – bbgodfrey
    May 29 at 19:37
9
$\begingroup$
exp = D[f[x, y, z], {x, 1}, {y, 2}]

produces the expression given in the question. Its internal representation is

FullForm[exp]
(* Derivative[1, 2, 0] [f] [x, y, z] *)

Therefore, the desired result can be extracted by

List @@ Head[Head[exp]]
(* {1, 2, 0} *)
$\endgroup$
1
  • $\begingroup$ Thank you very much! Worked perfectly! $\endgroup$ May 30 at 16:39
7
$\begingroup$

The following needs an input of the indicated form If you need a more general input you must adapt your question. The reason is, that the indicated form is the displayed form of Derivative[1,2,0][f][x,y,z]. This is what MMA actually stores. Only for display on the screen it is change to the displayed form. Of course, you can also give the full form as input.

Here is a simple function that does what you are asking:

getInfo[d_] := d /. Derivative[x__][_][__] :> {x}

If you the say:

enter image description here

$\endgroup$
6
$\begingroup$

If you have a Derivative object (you can find out via FullForm) then you can use something like

derivativeOrder[Derivative[o___][f_][x___]] :=  AssociationThread[{x} -> {o}]

Then, running it on your example,

derivativeOrder[Derivative[1, 2, 0][f][x, y, z]]

gives <|x -> 1, y -> 2, z -> 0|>

$\endgroup$

Your Answer

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

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