Prevent reordering in a derived product?

A recent Wolfram blog post suggested the following function for formatting derivatives in a more traditional way.

pdConv[f_] := 
 TraditionalForm[
  f /. Derivative[inds__][g_][vars__] :> 
    Apply[Defer[D[g[vars], ##]] &, 
     Transpose[{{vars}, {inds}}] /. {{var_, 0} :> 
        Sequence[], {var_, 1} :> {var}}]
 ]

An example of use Dt[d[x, a]] // pdConvgives:

enter image description here

Without breaking the general capabilities pdConv, can someone change it to maintain a given order of variables, producing the output shown below? (of course, this is purely for astral reasons, thereby facilitating differentiation for humans)

enter image description here

I suspect that this will not be trivial to implement --- unless someone knows the magic option Global, which can be temporarily overridden in Block.

For what it's worth, these SO questions may be related:

+5
3

, , , -

pdConv[f_, vv_] :=
 Module[{v},
  (HoldForm[
       Evaluate@
        TraditionalForm[((f /. Thread[vv -> #]) /. 
           Derivative[inds__][g_][vars__] :> 
            Apply[Defer[D[g[vars], ##]] &, 
             Transpose[{{vars}, {inds}}] /. {{var_, 0} :> 
                Sequence[], {var_, 1} :> {var}}])]] /. 
      Thread[# -> vv]) &@ Table[Unique[v], {Length[vv]}]]

vv - f , , . , -

pdConv[Dt[d[x, c]], {x, c}]

equations in right order

, , vv , , , , , HoldForm.

+4

Heike . , .

ClearAll[pdConv]

pdConv[order_List][f_] :=
  With[{R = Thread[order -> Sort@order]},
    HoldForm@TraditionalForm@# /. Reverse[R, 2] &[
     f /. R /. Derivative[inds__][g_][vars__] :>
        (Defer@D[g[vars], ##] & @@ Pick[{vars}, {inds}, 1])]
  ]

:

Dt[d[x, a]] // pdConv[{x, a}]

Dt[d[x, a, c, b]] // pdConv[{x, a, c, b}]

:

ClearAll[pdConvAuto]
SetAttributes[pdConvAuto, HoldFirst]

pdConvAuto[f : Dt@_@syms__] :=
  With[{R = Thread[{syms} -> Sort@{syms}]},
    HoldForm@TraditionalForm@# /. Reverse[R, 2] &[
     f /. R /. Derivative[inds__][g_][vars__] :>
        (Defer@D[g[vars], ##] & @@ Pick[{vars}, {inds}, 1])]
  ]

:

Dt[d[x, a, c, b]] // pdConvAuto
+1

I realized that it was Dt[d[x, a, c, b]]already giving an ordered conclusion, just the opposite. I probably misunderstand the situation, but for some cases this seems sufficient:

ClearAll[pdConv]

pdConv[f_] :=
 Apply[Plus, HoldForm@TraditionalForm@#, {2}] &[
  Reverse[List @@ f] /. Derivative[inds__][g_][vars__] :>
    (Defer@D[g[vars], ##] & @@ Pick[{vars}, {inds}, 1])
  ]

Dt[d[x, a, r, c, b]] // pdConv
0
source

All Articles