btw, trying to sort the args yourself doesn't work because the printers (unfortunately?) reorder them:
>>> eq h*Derivative(f(x), x, x) + Derivative(f(x), x) + Derivative(f(x), x, x) >>> new = Add(*ordered(eq.args, lambda w: (sum(len(d.variables) if >>> isinstance(d, Derivative) else 0 for d in Mul.make_args(w)), sum(d.exp for >>> d in Mul.make_args(w) if d.is_Pow and d.base == h))), evaluate=False) >>> new.args (Derivative(f(x), x), Derivative(f(x), x, x), h*Derivative(f(x), x, x)) Note that by using evaluate=False, the order of the actual arguments is different but when you print them... >>> print new h*Derivative(f(x), x, x) + Derivative(f(x), x) + Derivative(f(x), x, x) they come out as they did before. Here, a string is created manually from the args in the unevaluted Add: >>> ' + '.join(str(arg) for arg in new.args)'Derivative(f(x), x) + >>> Derivative(f(x), x, x) + h*Derivative(f(x), x, x)' -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com. To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.