0
$\begingroup$

Let's assume I have the following expression :

D[K[x,y],{x,1}] + D[J[x,y],{x,2},{y,2}] + D[U[x,y],{x,2},{y,1}].

Can we sort it by the order corresponding to given list of dependent variables. For example in case of depVars = {J, U, K}, I need to get:

D[J[x,y],{x,2},{y,2}] + D[U[x,y],{x,2},{y,1}] + D[K[x,y],{x,1}].

Is it possible to write such sorting function ?

$\endgroup$
  • $\begingroup$ Plus[] is Orderless, so any sorting of terms would be mere pretty-printing. $\endgroup$ – J. M. will be back soon Nov 1 '17 at 14:42
  • $\begingroup$ I think it can be transferred into list by /.Plus->List in order to transfer back after sorting. $\endgroup$ – Davit Shahnazaryan Nov 1 '17 at 14:48
  • $\begingroup$ Sure, I'm just saying that no matter what you do, b + a will be converted to a + b. $\endgroup$ – J. M. will be back soon Nov 1 '17 at 14:51
  • $\begingroup$ Hmm, now got it. That's bad !!! $\endgroup$ – Davit Shahnazaryan Nov 1 '17 at 14:52
  • $\begingroup$ I tried. For Mathematica the priority is the derivation orders. So it is converted into : D[K[x,y],{x,1}] + D[U[x,y],{x,2},{y,1}] + D[J[x,y],{x,2},{y,2}] $\endgroup$ – Davit Shahnazaryan Nov 1 '17 at 14:54

Your Answer

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

Browse other questions tagged or ask your own question.