0

I would like to write a function to change the notation of derivative in an expression. For instance, the function rep will take Derivative[0, 0, 1, 0][F][x, y, z, t] and output diff[F[x,y,z,t],z]:

rep[Derivative[0, 0, 1, 1][F][x, y, z, t]] = diff[F[x,y,z,t],z,t].

Any help to achieve this is appreciated.

Bran
  • 275
  • 1
  • 7
  • But F^(0,0,1,0)[x,y,z,t] itself is not valid syntax. What is exactly the problem you are trying to solve? i.e. why do you need to do this in first place? – Nasser Apr 16 '20 at 20:26
  • That's the plain text form of the output of D[F[x,y,z,t],z]. – Bran Apr 16 '20 at 20:29
  • 1
    That's the plain text form of the output of D[F[x,y,z,t],z] On my version of Mathematica, this is the plain text of D[F[x,y,z,t],z] I get InputForm[D[F[x, y, z, t], z]] gives Derivative[0, 0, 1, 0][F][x, y, z, t] so how did it come to be F^(0,0,1,0)[x,y,z,t] on your end? Since this is not valid mathematica syntax. It gives error Syntax::sntxf: "(" cannot be followed by "0,0,1,0)". I am using V 12.1., which version of Mathematica are you using? – Nasser Apr 16 '20 at 20:32
  • (F^(0,1,0,0))[x,y,t,z] - output copied as plain text. – Bran Apr 16 '20 at 20:35
  • I have added a screenshot. – Bran Apr 16 '20 at 20:39
  • I see where the confusion. What you see on the screen is not the actual code. To see the actual code, you need to use InputForm. That is what is read by Mathematica. Screen thing is just formatting for display purposes only. So your question should be How to change Derivative[0, 0, 1, 0][F][x, y, z, t] to diff[F[x,y,z,t],z] that is all. (but what is diff? Is this your own function? – Nasser Apr 16 '20 at 20:41
  • If your purpose is for display only, then here is the answer how-to-make-traditional-output-for-derivatives Notice that D[F[x, y, z, t], z] is really Derivative[0, 0, 1, 0][F][x, y, z, t]. Try D[F[x, y, z, t], z]// InputForm to see. – Nasser Apr 16 '20 at 20:59
  • You are right. I have changed the question. – Bran Apr 16 '20 at 21:06

2 Answers2

3

Perhaps this is what is wanted:

rep[Derivative[ords__][f_][args__]] /; Length[{ords}] == Length[{args}] := 
    diff[f[args], ##] & @@ Flatten[MapThread[ConstantArray, {{args}, {ords}}]]

For instance,

rep[Derivative[0, 2, 0, 1][F][x, y, z, w]]
   diff[F[x, y, z, w], y, y, w]

rep[Derivative[0, 0, 1, 1][F][x, y, z, w]]
   diff[F[x, y, z, w], z, w]
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
  • very nice. I did not know one could do it that way, i.e. write it as Derivative[ords__][f_][args__]. Makes it much easier to pick up the items I wanted instead of using indexing. – Nasser Apr 17 '20 at 04:14
  • Of course, this fails if Derivative[ords][f] auto-evaluates to something that no longer has Derivative[]. ;) Otherwise, it works well for OP's specific examples. – J. M.'s missing motivation Apr 17 '20 at 04:16
  • Yes ofcourse, I think my code will also fail if the input does not have same structure as well, as it uses fixed indexing assuming same structure. I think I will have to remember your method from now on. Makes doing some things I wanted to do much simpler. – Nasser Apr 17 '20 at 04:23
2

function rep will take Derivative[0, 0, 1, 0][F][x, y, z, t] and output diff[F[x,y,z,t],z]:

Just a quick hack, as I do not know of direct MMA command. Will let someone else come up with a one liner answer ;)

ClearAll[F, x, y, z, t];
rep[f_, g_] := Module[{h, vars = {}, n, i, deps = {}},
  h = f[[0, 1]];
  n = Length@f[[0, 0]];
  Do[
   If[(f[[0, 0]][[i]]) == 1, AppendTo[deps, f[[i]]]];
   AppendTo[vars, f[[i]]]
   , {i, 1, n}];

  g[h[Sequence @@ vars], Sequence @@ deps]
  ]

Call as

 rep[Derivative[0, 0, 0, 1][F][x, y, z, t], diff]

Mathematica graphics

 rep[Derivative[0, 0, 1, 1][F][x, y, z, t], diff]

Mathematica graphics

 rep[Derivative[1, 0, 1, 0][F][x, y, z, t], diff]

Mathematica graphics

I am not sure how are you going to use this result, but this is what you asked for.

Nasser
  • 143,286
  • 11
  • 154
  • 359