A recent post on the Wolfram Blog offered the following function to format 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 use, Dt[d[x, a]] // pdConv
gives:
Without breaking the general capabilities of pdConv
, can someone alter it to maintain the given order of variables, producing the output shown below? (of course this is purely for asthetic reasons, making derivations easier for a human to follow)
I suspect this will be nontrivial to implement---unless someone knows of a magical Global
option that can be temporarily overridden within a Block
.
For what it's worth, these SO questions may be related:
There is probably a cleaner way to do s, but if it's purely for presentation purposes, you could do something like
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]}]]
Here, the extra parameter vv
is a list of the variables in f
in the order you want the partial derivatives to appear. To use this function, you would do something like
pdConv[Dt[d[x, c]], {x, c}]
Basically what this solution does is to temporarily replace the list of variables vv
with a list of dummy variables which are in the right lexicographical order, apply the transformation, and then replace the dummy variables with the original variables while preserving the desired order by wrapping the transformed expression in HoldForm
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With