Sum is an unevaluated summation.  It will always remain unevaluated.
If you want to get a closed form answer, use summation:

In [27]: print summation(SYMi, (SYMi, 0, SYMN - 1))
N**2/2 - N/2

Also, evalf is only for getting numerical answers.  If you want an
exact answer, again just use summation instead of Sum.  Or, if you
have a Sum, you can call .doit(), like

In [28]: print Sum(1/n**2, (n, 1, sympy.oo)).doit()
pi**2/6

Note that the same is true for Product vs. product and Integral vs.
integrate.  The former (with the capital letter) is unevaluated
always, and the latter (with the lowercase letter) attempts to give a
closed form answer and only returns the unevaluated form if it can't
find one (you can then try .evalf() on the unevaluated form to try
getting a numerical answer).

Aaron Meurer

On Thu, Sep 13, 2012 at 3:15 AM, RCU <[email protected]> wrote:
>  Hello.
>   I am trying to compute sums with symbolic values as limits:
>     n = sympy.var("n")
>     SYMM = sympy.Symbol("M")
>     SYMN = sympy.Symbol("N")
>     SYMi = sympy.Symbol("i")
>
>     print sympy.Sum(SYMi, (SYMi, 0, SYMN - 1)).evalf()
>   This prints however Sum(i, (i, 0, N - 1)), instead of N*(N-1)/2
>   Could you please tell me if I can compute the final result as desired. I
> got inspired from other code like sympy.Sum(1/n**2, (n, 1,
> sympy.oo)).evalf() or sympy.nsimplify(sympy.Sum(1/n**2, (n, 1, sympy.oo)),
> [sympy.pi]), but I couldn't figure out how to achieve my goal.
>
>   With best regards,
>     Alex Susu
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to