Hi, On 27 May 2011 14:22, smichr <smi...@gmail.com> wrote:
> Does anyone have a better idea for how to canonicalize the args for > Add (perhaps Mul, too). > > >>> from sympy.abc import * > >>> from sympy import * > >>> 3*x+6*y > 3*x + 6*y > >>> _.args > (3*x, 6*y) > >>> (x+2*y).args > (2*y, x) > >>> (2*x+2*y+z).args > (2*y, z, 2*x) > >>> > > See how the args are unsorted -- at least in the sorted_key sense? > Work that I did in https://github.com/sympy/sympy/pull/370 on > primitive would be easier if all coefficient-1 args appeared at the > end of the args in the way that the Rational appears first. (How they > get printed is another matter and immaterial to this request.) > Basically, if this were true -- that the coeff=1 args were last in the > args -- then those that get their coefficient cleared out in the > removal of the primitive could be simply appended one by one to the > end of the args which could then be rebuilt with _new_rawargs. > > Here are some more permutations showing how the args shift around: > > >>> (4*x+y+2*z).args > (y, 2*z, 4*x) > >>> (4*x+z+2*y).args > (2*y, 4*x, z) > >>> (4*y+x+2*z).args > (4*y, 2*z, x) > >>> (4*y+z+2*x).args > (4*y, z, 2*x) > >>> (4*z+x+2*y).args > (4*z, 2*y, x) > >>> (4*z+y+2*x).args > (4*z, y, 2*x) > We should consider adding get_ordered_args (or similar) to Basic (see epathtools.py for an example implementation and usage). Basic.args is very low-level. It should be easy to obtain args, but it may be painful to use them (note that we don't live in a perfect world ;) Unless we can make Basic.args "fast" and easy to use, wherever necessary we should use higher-level functions (like get_ordered_args). > > -- > 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. > > Mateusz -- 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.