Status: New
Owner: ----
Labels: Type-Defect Priority-Medium
New issue 1499 by [email protected]: Sum function seems to fail
http://code.google.com/p/sympy/issues/detail?id=1499
Hi everybody,
the Sum function in Sympy 0.6.4 fails for some cases. The first part of the
following test case runs fine, the second part ends in an infinite loop. I
aborted the execution and added the traceback at the end of this bugreport.
Thanks a lot for looking into this!
Alexander
Test case:
from sympy import *
m = Symbol('m')
I = Symbol('I')
s = Sum(exp(m), (m, -I, I))
# m should be -2 .. 2
s = s.subs(I,2).doit()
print(s)
# prints: (exp(-I) - exp(1 + I))/(1 - E)
s.subs(I,2).evalf()
# 11.61... the correct result
# now just slightly different:
s = Sum(m*exp(m), (m, -I, I))
# m should be -2 .. 2
s = s.subs(I,2).doit()
print(s)
# Sum(m*exp(m), (m, -I, I)), so it did not expand
# infinite loop here:
s.subs(I, 2).evalf()
Traceback after keyboard interrupt:
---------------------------------------------------------------------------
KeyboardInterrupt Traceback (most recent call last)
C:\Users\alex\User\Documents\Python\<ipython console> in <module>()
C:\Program Files\Dev\Python\lib\site-packages\sympy\core\evalf.pyc in
Basic_evalf(x, n, **options)
1008 options['maxprec'] = max(prec, DEFAULT_MAXPREC)
1009 try:
-> 1010 result = evalf(x, prec+4, options)
1011 except NotImplementedError:
1012 # Fall back to the ordinary evalf
C:\Program Files\Dev\Python\lib\site-packages\sympy\core\evalf.pyc in
evalf(x, prec, options)
948 try:
949 rf = evalf_table[x.func]
--> 950 r = rf(x, prec, options)
951 except KeyError:
952 #r = finalize_complex(x._eval_evalf(prec)._mpf_, fzero,
prec)
C:\Program Files\Dev\Python\lib\site-packages\sympy\core\evalf.pyc in
evalf_sum(expr, prec, options)
867 m = n = 2**i * prec
868 s, err = expr.euler_maclaurin(m=m, n=n, eps=eps, \
--> 869 eval_integral=False)
870 err = err.evalf()
871 if err <= eps:
C:\Program Files\Dev\Python\lib\site-packages\sympy\concrete\summations.pyc
in euler_maclaurin(self, m, n, eps, eval_integral)
148 if (eps and term and abs(term.evalf(3)) < eps) or (k >
n):
149 break
--> 150 s += term
151 g = g.diff(i, 2)
152 return s + iterm, abs(term)
C:\Program Files\Dev\Python\lib\site-packages\sympy\core\sympify.pyc in
__sympifyit_wrapper(a, b)
242 try:
243 # fast-path: let's hope b is already SymPy object
--> 244 return func(a, b)
245
246 except Exception, e:
C:\Program Files\Dev\Python\lib\site-packages\sympy\core\basic.pyc in
__add__(self, other)
645 @_sympifyit('other', NotImplemented)
646 def __add__(self, other):
--> 647 return Add(self, other)
648 @_sympifyit('other', NotImplemented)
649 def __radd__(self, other):
C:\Program Files\Dev\Python\lib\site-packages\sympy\core\cache.pyc in
wrapper(*args, **kw_args)
83 except KeyError:
84 pass
---> 85 func_cache_it_cache[k] = r = func(*args, **kw_args)
86 return r
87
C:\Program Files\Dev\Python\lib\site-packages\sympy\core\operations.pyc in
__new__(cls, *args, **assumptions)
30 if len(args)==1:
31 return _sympify(args[0])
---> 32 c_part, nc_part, order_symbols = cls.flatten(map(_sympify,
args))
33 if len(c_part) + len(nc_part) <= 1:
34 if c_part: obj = c_part[0]
C:\Program Files\Dev\Python\lib\site-packages\sympy\core\add.pyc in
flatten(cls, seq)
86 # 2*x**2 + 3*x**2 -> 5*x**2
87 if s in terms:
---> 88 terms[s] += c
89 else:
90 terms[s] = c
C:\Program Files\Dev\Python\lib\site-packages\sympy\core\sympify.pyc in
__sympifyit_wrapper(a, b)
242 try:
243 # fast-path: let's hope b is already SymPy object
--> 244 return func(a, b)
245
246 except Exception, e:
C:\Program Files\Dev\Python\lib\site-packages\sympy\core\numbers.pyc in
__add__(self, other)
565 if other.is_unbounded:
566 return other
--> 567 return Rational(self.p * other.q + self.q * other.p,
self.q
* other.q)
568 return Number.__add__(self, other)
569
C:\Program Files\Dev\Python\lib\site-packages\sympy\core\cache.pyc in
wrapper(*args, **kw_args)
276 return self.return_value_converter(cache[new_args,
new_kw_items])
277 except KeyError:
--> 278 r = func(*new_args, **new_kw_args)
279 try:
280 try:
C:\Program Files\Dev\Python\lib\site-packages\sympy\core\numbers.pyc in
__new__(cls, p, q)
513 q = -q
514 p = -p
--> 515 n = igcd(abs(p), q)
516 if n>1:
517 p //= n
C:\Program Files\Dev\Python\lib\site-packages\sympy\core\numbers.pyc in
igcd(a,
b)
44 b = -b
45
---> 46 while b:
47 a, b = b, a % b
48 else:
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sympy-issues" 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-issues?hl=en
-~----------~----~----~----~------~----~------~--~---