On 12/04/2012 09:31 PM, Jason Grout wrote: > On 12/4/12 6:07 PM, Michael Orlitzky wrote: >> On 12/04/2012 07:01 PM, Tom Boothby wrote: >>> prod() does just what you want. >>> >> >> Duh, thanks. I swear I tried produ<tab>. >> > > Just FYI, the prod() function assumes your multiplication is associative > and often does a balanced multiplication. This can be significantly > faster than the operator.reduce version you mention, but it also can > behave differently in corner cases (like non-associative > multiplication). Do prod? to see details. >
Thanks, I did read the implementation and try to beat it out of curiosity. The only obvious win I found for the simple algorithm is with symbols, sage: from functools import reduce sage: def simple_prod(xs): ....: return reduce(operator.mul, xs, 1) ....: sage: a = SymbolSequence('a') sage: xs = [k*a[k] for k in range(0,100)] sage: timeit('simple_prod(xs)') 625 loops, best of 3: 324 盜 per loop sage: timeit('prod(xs)') 625 loops, best of 3: 524 盜 per loop But the performance is irrelevant to me anyway. I still have it defined in my init.sage, but now it's just, product = prod so I don't stumble about trying to remember the name next time. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To post to this group, send email to sage-devel@googlegroups.com. To unsubscribe from this group, send email to sage-devel+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel?hl=en.