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?

Just a simple:

  +1

Note that Robert Bradshaw wrote the current prod (in Cython), and it is
balanced and very fast.

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

> If overriding "sum" is not accepted, "SymbolicSum" might be an alternative.
>
>
> Thanks.
>
> Burcin
>
> >
>



-- 
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

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

Reply via email to