On Nov 14, 1:51 am, William Stein <wst...@gmail.com> wrote: > 1. Dima said: > > I don't think sum() method is needed. It's certainly a code bloat. > > Yes, the two methods accomplish the same thing.
Actually, there is also a slight (but sometimes significant) functional difference between the two methods: sage: from __builtin__ import sum sage: x = vector(RDF, [1, 2, 3]) sage: y = vector(RDF, []) sage: print x.sum(), type(x.sum()) 6.0 <type 'sage.rings.real_double.RealDoubleElement'> sage: print sum(x), type(sum(x)) 6.0 <type 'sage.rings.real_double.RealDoubleElement'> sage: print y.sum(), type(y.sum()) 0.0 <type 'sage.rings.real_double.RealDoubleElement'> sage: print sum(y), type(sum(y)) 0 <type 'int'> The builtin Python sum() returns the int 0 when summing an empty container, whereas self.sum() usually returns the zero of the base ring for empty containers. I've been bitten a few times by functions which unexpectedly return an int instead of an Integer, or a zero element with the wrong type; it's sometimes hard to debug, and always annoying! Mathieu -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org