# limit() throws TypeError: an integer is required #5172

Open
opened this Issue Oct 10, 2010 · 6 comments

Projects
None yet
6 participants
Contributor

### bgoodri commented Oct 10, 2010

 ``````See http://groups.google.com/group/sympy/t/5df0421f2c4396e In [32]: c,n,r = symbols('cnr') In [33]: limit( (( 2*n*(n-r+1)/(n + r*(n-r+1)) )**c + (r-1)*( n*(n-r +2)/(n + r*(n-r+1)) )**c - n)/(n**c - n), n, oo ) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ in () /usr/lib/pymodules/python2.6/sympy/series/limits.pyc in limit(e, z, z0, dir) 89 90 try: ---> 91 r = gruntz(e, z, z0, dir) 92 except PoleError: 93 r = heuristics(e, z, z0, dir) /usr/lib/pymodules/python2.6/sympy/series/gruntz.pyc in gruntz(e, z, z0, dir) 496 #convert all limits to the limit z->oo 497 elif z0 == oo: --> 498 return limitinf(e, z) 499 elif z0 == -oo: 500 return limitinf(e.subs(z,-z), z) /usr/lib/pymodules/python2.6/sympy/series/gruntz.pyc in limitinf(e, x) 337 if e.has(log): 338 e = e.normal() --> 339 c0, e0 = mrv_leadterm(e,x) 340 sig=sign(e0,x) 341 if sig==1: return S.Zero # e0>0: lim f = 0 /usr/lib/pymodules/python2.6/sympy/series/gruntz.pyc in mrv_leadterm(e, x, Omega) 395 e_up = moveup([e],x)[0] 396 #calculate the lead term --> 397 mrv_leadterm_up = mrv_leadterm(e_up, x, Omega_up) 398 #move the result (c0, e0) down 399 return tuple(movedown(mrv_leadterm_up, x)) /usr/lib/pymodules/python2.6/sympy/series/gruntz.pyc in mrv_leadterm(e, x, Omega) 404 wsym = Symbol("w", real=True, positive=True, dummy=True) 405 f, logw=rewrite(e, set(Omega), x, wsym) --> 406 series = calculate_series(f, wsym) 407 series=series.subs(log(wsym), logw) 408 return series.leadterm(wsym) /usr/lib/pymodules/python2.6/sympy/series/gruntz.pyc in calculate_series(e, x) 370 371 f = e --> 372 series=f.nseries(x, 0, 2).removeO() 373 if series == 0: 374 #we need to calculate more terms, let's try 4: /usr/lib/pymodules/python2.6/sympy/core/basic.pyc in nseries(self, x, x0, n) 2253 See also lseries(). 2254 """ -> 2255 return self._eval_nseries(x, x0, n) 2256 2257 def _eval_nseries(self, x, x0, n): /usr/lib/pymodules/python2.6/sympy/core/mul.pyc in _eval_nseries(self, x, x0, n) 934 def _eval_nseries(self, x, x0, n): 935 from sympy import powsimp --> 936 terms = [t.nseries(x, x0, n) for t in self.args] 937 return powsimp(Mul(*terms).expand(), combine='exp', deep=True) 938 /usr/lib/pymodules/python2.6/sympy/core/basic.pyc in nseries(self, x, x0, n) 2253 See also lseries(). 2254 """ -> 2255 return self._eval_nseries(x, x0, n) 2256 2257 def _eval_nseries(self, x, x0, n): /usr/lib/pymodules/python2.6/sympy/core/add.pyc in _eval_nseries(self, x, x0, n) 178 179 def _eval_nseries(self, x, x0, n): --> 180 terms = [t.nseries(x, x0, n) for t in self.args] 181 return Add(*terms) 182 /usr/lib/pymodules/python2.6/sympy/core/basic.pyc in nseries(self, x, x0, n) 2253 See also lseries(). 2254 """ -> 2255 return self._eval_nseries(x, x0, n) 2256 2257 def _eval_nseries(self, x, x0, n): /usr/lib/pymodules/python2.6/sympy/core/mul.pyc in _eval_nseries(self, x, x0, n) 934 def _eval_nseries(self, x, x0, n): 935 from sympy import powsimp --> 936 terms = [t.nseries(x, x0, n) for t in self.args] 937 return powsimp(Mul(*terms).expand(), combine='exp', deep=True) 938 /usr/lib/pymodules/python2.6/sympy/core/basic.pyc in nseries(self, x, x0, n) 2253 See also lseries(). 2254 """ -> 2255 return self._eval_nseries(x, x0, n) 2256 2257 def _eval_nseries(self, x, x0, n): /usr/lib/pymodules/python2.6/sympy/core/power.pyc in _eval_nseries(self, x, x0, n) 700 lt = b.as_leading_term(x) 701 o = order * lt**(1-e) --> 702 bs = b.nseries(x, x0, n-e) 703 if bs.is_Add: 704 bs = bs.removeO() /usr/lib/pymodules/python2.6/sympy/core/basic.pyc in nseries(self, x, x0, n) 2253 See also lseries(). 2254 """ -> 2255 return self._eval_nseries(x, x0, n) 2256 2257 def _eval_nseries(self, x, x0, n): /usr/lib/pymodules/python2.6/sympy/core/mul.pyc in _eval_nseries(self, x, x0, n) 934 def _eval_nseries(self, x, x0, n): 935 from sympy import powsimp --> 936 terms = [t.nseries(x, x0, n) for t in self.args] 937 return powsimp(Mul(*terms).expand(), combine='exp', deep=True) 938 /usr/lib/pymodules/python2.6/sympy/core/basic.pyc in nseries(self, x, x0, n) 2253 See also lseries(). 2254 """ -> 2255 return self._eval_nseries(x, x0, n) 2256 2257 def _eval_nseries(self, x, x0, n): /usr/lib/pymodules/python2.6/sympy/core/power.pyc in _eval_nseries(self, x, x0, n) 656 from sympy.functions import ceiling 657 terms = [1/prefactor] --> 658 for m in xrange(1,ceiling(n/l)): 659 new_term = terms[-1]*(-rest) 660 if new_term.is_Pow: TypeError: an integer is required `````` Original issue for #5172: http://code.google.com/p/sympy/issues/detail?id=2073 Original author: https://code.google.com/u/103082715153826424591/
Member

### smichr commented Oct 10, 2010

 ``````I was running into a similar problem in branch 2003 as I was working with large numbers. I believe it is related to the limit on xrange taking an integer: h[1] >>> xrange(2**30) xrange(1073741824) h[1] >>> xrange(2**31) Traceback (most recent call last): File "", line 1, in OverflowError: long int too large to convert to int The solution (at the shallow level) is to use a while loop rather than an xrange. Now why it was generating such a large number in the loop is another (deeper) issue. `````` Original comment: http://code.google.com/p/sympy/issues/detail?id=2073#c1 Original author: https://code.google.com/u/117933771799683895267/
Contributor

### bgoodri commented Oct 10, 2010

 ``````On the mailinglist thread, Aaron traced the problem back to this line xrange(1,ceiling(n/l)) which in my case n/l is symbolic due to the symbolic exponent c. So, ceiling() does not return an integer. But like you said, probably a similar problem would occur if ceiling() returned an integer that was too big. `````` Original comment: http://code.google.com/p/sympy/issues/detail?id=2073#c2 Original author: https://code.google.com/u/103082715153826424591/
Member

### asmeurer commented Oct 10, 2010

 ``````Well, if we converted it to a while loop, it would just hang. Actually, it would hang anyway for a large exponent (remember that xrange(2**30) means 2**30 loops!) **Status:** Accepted **Labels:** Series `````` Original comment: http://code.google.com/p/sympy/issues/detail?id=2073#c3 Original author: https://code.google.com/u/asmeurer@gmail.com/
Member

### asmeurer commented Mar 20, 2012

 ``````**Status:** Valid `````` Original comment: http://code.google.com/p/sympy/issues/detail?id=2073#c4 Original author: https://code.google.com/u/asmeurer@gmail.com/
Contributor

### skirpichev commented Jul 26, 2013

 ``````Now limit is working, but gruntz fails: In [9]: n = Symbol('n') In [10]: r = Symbol('r', positive=True) In [11]: c = Symbol('c') In [12]: p = Symbol('p', positive=True) In [13]: m = Symbol('m', negative=True) In [14]: expr = ((2*n*(n - r + 1)/(n + r*(n - r + 1)))**c + \ ....: (r - 1)*(n*(n - r + 2)/(n + r*(n - r + 1)))**c - n)/(n**c - n) In [15]: expr = expr.subs(c, c + 1) In [16]: gruntz(expr, n, oo) Out[16]: 1 In [17]: gruntz(expr.subs(c, p), n, oo) Out[17]: 1 Tests: https://github.com/sympy/sympy/pull/2326 **Labels:** WrongResult `````` Original comment: http://code.google.com/p/sympy/issues/detail?id=2073#c5 Original author: https://code.google.com/u/113518207426301808764/

### skirpichev added a commit to skirpichev/diofant that referenced this issue Jun 23, 2016

``` Drop outdated comment (see 56ba80f) ```
`Closes sympy/sympy#5172`
``` 7d75b2c ```

### skirpichev added a commit to skirpichev/diofant that referenced this issue Jun 25, 2016

``` Drop outdated comment (see 56ba80f) ```
`Closes sympy/sympy#5172`
``` d41cacf ```

Merged

Member

### smichr commented Jun 24, 2017

 If `expand_power_exp` is used on the expression before sending it to gruntz a different value is obtained: ``````>>> eq = expand_power_exp(eq) >>> gruntz(eq, n, oo).simplify() -oo*sign(2**(p + 1) + r - 1) # should be -oo*1 since p and r are positive `````` This is still not right but `gruntz` appears to be sensitive to such rewriting of expressions.