> Moreover, I think that something like this would be extremely useful as > a function incorporated into the sympy distribution: > >>> collect(expr2.subs([(a**(n+1), u*a**(n+1)) for a in _]), u)
Another approach would be to use Wild symbols when calling collect(). Like this: >>> from sympy.tensor import Indexed >>> M = Indexed('M') >>> expr = x*M(k,m)**(n+1) + y*M(k,m)**(n+1) + M(k,m)**n + z*M(k,m)**n >>> w = Wild('w1') >>> collect(expr, w**(n+1)) M(k, m)**n + z*M(k, m)**n + (x + y)*M(k, m)**(1 + n) >>> collect(expr, w**n) (1 + z)*M(k, m)**n + x*M(k, m)**(1 + n) + y*M(k, m)**(1 + n) However, this does not work. Does anyone know if there is a particular reason for that, or is it a bug? Øyvind -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sy...@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.