On Thu, Jul 30, 2009 at 5:39 PM, Phillip M. Feldman<pfeld...@verizon.net> wrote:
>
> When I type something like the following, I would expect to get a
> result of oo, indicating that the sum diverges to infinity:
>
> sum(1/n, (n, 2, oo))
>
> Instead, I get the same thing back (actually not quite-- the 's'
> changes to a capital 'S').  Any idea why this doesn't work?

This is what I get:

In [1]: sum(1/n, (n, 2, oo))
Out[1]: Sum(1/n, (n, 2, oo))

This just returns the Sum instance, meaning, that you can do stuff on it, like:

In [2]: a = sum(1/n, (n, 2, oo))

In [3]: a.n()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)

/home/ondrej/repos/sympy/<ipython console> in <module>()

/home/ondrej/repos/sympy/sympy/core/evalf.pyc in Basic_evalf(x, n, **options)
   1006         options['maxprec'] = max(prec, DEFAULT_MAXPREC)
   1007     try:
-> 1008         result = evalf(x, prec+4, options)
   1009     except NotImplementedError:
   1010         # Fall back to the ordinary evalf


/home/ondrej/repos/sympy/sympy/core/evalf.pyc in evalf(x, prec, options)
    946     try:
    947         rf = evalf_table[x.func]
--> 948         r = rf(x, prec, options)
    949     except KeyError:
    950         #r = finalize_complex(x._eval_evalf(prec)._mpf_, fzero, prec)


/home/ondrej/repos/sympy/sympy/core/evalf.pyc in evalf_sum(expr, prec, options)
    854             raise NotImplementedError
    855         # Use fast hypergeometric summation if possible

--> 856         v = hypsum(func, n, int(a), prec2)
    857         delta = prec - fastlog(v)
    858         if fastlog(v) < -10:

/home/ondrej/repos/sympy/sympy/core/evalf.pyc in hypsum(expr, n, start, prec)
    818             raise ValueError("Sum diverges like (%i)^n" % abs(1/g))
    819         if p < 1 or (p == 1 and not alt):
--> 820             raise ValueError("Sum diverges like n^%i" % (-p))
    821         # We have polynomial convergence: use Richardson extrapolation

    822         # Need to use at least quad precision because a lot of
cancellation


ValueError: Sum diverges like n^-1


E.g. this tells you that the sum diverges.

Maybe the sum could return oo immediately.

Ondrej

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

Reply via email to