On Thu, Nov 08, 2012 at 10:16:36AM -0600, Jason Grout wrote: > On 11/8/12 6:26 AM, Simon King wrote: > >Hi David and John, > > > >On 2012-11-08, David Loeffler <d.a.loeff...@warwick.ac.uk> wrote: > >>It is *really awful* that V.sum(W) attempts to sum all the elements of > >>W! I don't know what general design decision underlies this but I > >>don't like it. > > > >That's easy to explain. All additive semigroups should be able to sum up a > >list of their elements. Hence, such as summation method is defined by > >the category framework. > > Are there any examples where it is more complicated than just > sum(args, self.zero())? If not, I think I side with John in > questioning the value of the function.
The main point is that writing V.sum(args) gives more information to the system than sum(args, self.zero()): this is making a promise that all elements in args are elements of V. This gives an opportunity for optimizations: typically one could resolve once for all what the appropriate method is for adding two elements, and avoid that resolution at runtime for each addition. We had such an optimization in MuPAD-Combinat; I don't remember if we have one yet in Sage, but we definitely should. In the mean time we want to encourage the use of V.sum so that later on the relevant pieces of code will benefit from the optimization. Other points: - V.sum could be made to work for additive semigroups that don't have a zero - V.sum could possibly optimize away one addition (which sum does not do) - Experience tells that people just write sum(args) and forget about the self.zero(), which leads to broken corner cases that hit hard down the road. Granted, it would be nice if there was a minimum of type checking so that V.sum(...) would bark if the elements are not in V. Cheers, Nicolas -- Nicolas M. ThiƩry "Isil" <nthi...@users.sf.net> http://Nicolas.Thiery.name/ -- 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.