On 11/09/2012 12:16 AM, 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.

If each element of args was changed into an element of V before summing,
then it seems that the function's utility might be argued more strongly.
Something like:

sum((self(i) for i in args), self.zero())

Thanks,

Jason




According to the doc it is supposed to return an element of V.


Definition:     V.sum(self, args)
Docstring:
       n-ary sum

       INPUT:

          * "args" -- a list (or iterable) of elements of "self"

       Returns the sum of the elements in args, as an element of self.




Also, according to the doc, the input should have been a list of "self" (whatever it refers to -- that's another gripe I have with writing the word 'self' in the docs). But again, the explanation below it is confusing since it seems to indicate that the elements could be changed to belong to V. Perhaps that's why self.zero() is used?


However, it is not always changed to an element of V, which is not surprising given the code.

sage: type(QQ.sum([ZZ(1), ZZ(2)]))
<type 'sage.rings.rational.Rational'>
sage: type(QQ.sum([RR(1), RR(2)]))
<type 'sage.rings.real_mpfr.RealNumber'>


--
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.


Reply via email to