New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

limit fails with "maximum recursion depth exceeded" / Python crash #9449

Open
x-or opened this Issue May 31, 2015 · 0 comments

Comments

Projects
None yet
1 participant
@x-or
Copy link

x-or commented May 31, 2015

SymPy 0.7.6 code:

import sys
import sympy as sy

#sys.setrecursionlimit(100000)

x, eps = sy.symbols('x eps', real=True)
e = (sy.Abs(eps + x)-sy.Abs(eps - x))/(2*eps)
print e
print e.limit(eps, 0)

fails with exception:

Traceback (most recent call last):
  File "issue.py", line 9, in <module>
    print e.limit(eps, 0)
  File "C:\Python27\lib\site-packages\sympy\core\expr.py", line 2662, in limit
    return limit(self, x, xlim, dir)
  File "C:\Python27\lib\site-packages\sympy\series\limits.py", line 42, in limit
    return Limit(e, z, z0, dir).doit(deep=False)
  File "C:\Python27\lib\site-packages\sympy\series\limits.py", line 157, in doit
    r = gruntz(e, z, z0, dir)
  File "C:\Python27\lib\site-packages\sympy\series\gruntz.py", line 651, in gruntz
    r = limitinf(e0, z)
  File "C:\Python27\lib\site-packages\sympy\core\cache.py", line 91, in wrapper
    retval = cfunc(*args, **kwargs)
  File "C:\Python27\lib\site-packages\sympy\core\compatibility.py", line 872, in wrapper
    result = user_function(*args, **kwds)
  File "C:\Python27\lib\site-packages\sympy\series\gruntz.py", line 424, in limitinf
    c0, e0 = mrv_leadterm(e, x)
  File "C:\Python27\lib\site-packages\sympy\core\cache.py", line 91, in wrapper
    retval = cfunc(*args, **kwargs)
  File "C:\Python27\lib\site-packages\sympy\core\compatibility.py", line 872, in wrapper
    result = user_function(*args, **kwds)
  File "C:\Python27\lib\site-packages\sympy\series\gruntz.py", line 507, in mrv_leadterm
    return series.leadterm(w)

  ... skipped ....

  File "C:\Python27\lib\site-packages\sympy\core\basic.py", line 396, in __str__
    return sstr(self, order=None)
  File "C:\Python27\lib\site-packages\sympy\printing\str.py", line 731, in sstr
    s = p.doprint(expr)
  File "C:\Python27\lib\site-packages\sympy\printing\printer.py", line 233, in doprint
    return self._str(self._print(expr))
  File "C:\Python27\lib\site-packages\sympy\printing\printer.py", line 257, in _print
    return getattr(self, printmethod)(expr, *args, **kwargs)
  File "C:\Python27\lib\site-packages\sympy\printing\str.py", line 52, in _print_Add
    terms = self._as_ordered_terms(expr, order=order)
  File "C:\Python27\lib\site-packages\sympy\printing\printer.py", line 271, in _as_ordered_terms
    return expr.as_ordered_terms(order=order)
  File "C:\Python27\lib\site-packages\sympy\core\expr.py", line 853, in as_ordered_terms
    terms, gens = self.as_terms()
  File "C:\Python27\lib\site-packages\sympy\core\expr.py", line 884, in as_terms
    coeff = complex(coeff)
  File "C:\Python27\lib\site-packages\sympy\core\expr.py", line 229, in __complex__
    re, im = result.as_real_imag()
  File "C:\Python27\lib\site-packages\sympy\core\expr.py", line 1614, in as_real_imag
    return (C.re(self), C.im(self))
  File "C:\Python27\lib\site-packages\sympy\core\cache.py", line 91, in wrapper
    retval = cfunc(*args, **kwargs)
  File "C:\Python27\lib\site-packages\sympy\core\compatibility.py", line 854, in wrapper
    key = make_key(args, kwds, typed) if kwds or typed else args
  File "C:\Python27\lib\site-packages\sympy\core\compatibility.py", line 786, in _make_key
    return _HashedSeq(key)
  File "C:\Python27\lib\site-packages\sympy\core\compatibility.py", line 764, in __init__
    self.hashvalue = hash(tup)
  File "C:\Python27\lib\site-packages\sympy\core\numbers.py", line 947, in __hash__
    return super(Float, self).__hash__()
  File "C:\Python27\lib\site-packages\sympy\core\numbers.py", line 413, in __hash__
    return super(Number, self).__hash__()
  File "C:\Python27\lib\site-packages\sympy\core\basic.py", line 107, in __hash__
    h = hash((type(self).__name__,) + self._hashable_content())
RuntimeError: maximum recursion depth exceeded while calling a Python object

Uncomment 'setrecursionlimit' line causes Python's crash.

Python 2.7.3 (32bit), Windows 7 x64.

skirpichev added a commit to diofant/diofant that referenced this issue Dec 26, 2015

skirpichev added a commit to diofant/diofant that referenced this issue Dec 26, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment