On Nov 13, 2008, at 6:12 AM, William Stein wrote: > On Thu, Nov 13, 2008 at 5:12 AM, Burcin Erocal <[EMAIL PROTECTED]> > wrote: >> >> Hi, >> >> I plan to start implementing a user interface to symbolic summation >> soon and I want to get some opinions on how this interface should be. >> >> The most natural construct for summation, either of a list or >> symbolic >> summation is of course "sum." Initially, I was thinking that it's >> a big >> sin to override the python "sum" function, since I also use it very >> often and consider it (performance) critical. However, I was >> encouraged >> to think again about this after Mike's comment here: >> >> http://trac.sagemath.org/sage_trac/ticket/3587#comment:3 >> >> >> For quick reference, here's the help for Python's sum function: >> >> sum(sequence, start=0) -> value >> >> Returns the sum of a sequence of numbers (NOT strings) plus the >> value of parameter 'start'. When the sequence is empty, returns >> start. >> >> >> We could easily extend this to check if the second parameter is a >> tuple >> which defines a range (e.g., (x, 1, n) where the upper and lower >> bounds are inclusive). If it is, try to solve the sum symbolically, >> otherwise call the python sum function. (Actually, I recall that >> there >> were plans to overwrite this function anyway with one that does >> balanced summation if the argument is a list.) >> >> So I propose the following: >> >> sage: var('i,n') >> (i, n) >> sage: sum(2^i, (i, 0, n)) >> 2^(n+1) - 1 >> sage: sum(1/i, (i, 1, n)) >> harmonic_number(1, n) >> >> (As far as I can see, Sage doesn't have a construct for harmonic >> numbers yet.) >> >> These still will work of course: >> >> sage: sum(range(5)) >> 10 >> sage: sum(i for i in range(5)) >> 10 >> sage: sum(range(5), 2) >> 12 >> >> >> Similarly, I suggest we extend prod the same way. >> >> >> Any comments or objections?
This certainly seems like the best notation. Sums with tuple endpoints are sometimes useful, e.g. sage: sum(zip(range(5), range(5)), ()) (0, 0, 1, 1, 2, 2, 3, 3, 4, 4) However, this is a much more obscure use case than what you're proposing. We could make our sum should take an optional keyword parameter "endpoint" so that this behavior is still possible (even though we're changing the default behavior). >> I should also add that I don't like to differentiate between upper >> and >> lowercase commands, so I don't think using "Sum" is an option. > > I agree. I'm strongly opposed to that Maple-style case-has-meaning > crap. Me too. - Robert --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---