On Thu, Aug 11, 2011 at 12:40 AM, Roberto Colistete Jr. <roberto.colist...@gmail.com> wrote: > Hi, > > I have not found a simple way to map a function to a mathematical > expression with sum of items. Is there anything simple to do it ? I > was thinking it would be simples, like "map(expand,expr)" but it > doesn't work. > > In the meantime, I have solved this issue with the code : > > def mapexpr(self,expr,func): > if isinstance(expr,Add): > return apply(Add,map(func,expr.args)) > else: > return func(expr) >
It sounds like you want to apply the function term-wise. What you have written above can be simplified to def map_termwise(func, expr): return Add(*[func(a) for a in Add.make_args(expr)]) There is also a Mul.make_args. Both Add and Mul make_args methods interpret the expr as an Add or Mul, respectively. -- 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.