problem with limit

7 views
Skip to first unread message

Ben Goodrich

unread,
Oct 9, 2010, 10:21:08 PM10/9/10
to sympy
Hi,

I didn't see this problem exactly when I searched through the Issues,
but I wanted to check that it was not a known problem first.

Thanks,
Ben

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/<ipython console> in <module>()

/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

Aaron S. Meurer

unread,
Oct 9, 2010, 10:27:53 PM10/9/10
to sy...@googlegroups.com
I've never seen it before, and I didn't come up with anything in the issues when I searched for the error message, so I think it is safe to report this one. :)

Any idea what is happening, by the way?

Aaron Meurer

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

Aaron S. Meurer

unread,
Oct 9, 2010, 10:32:38 PM10/9/10
to sy...@googlegroups.com
I tried running the limit through Maple, and it couldn't do it (it just returned an unevaluated form), and Wolphram Alpha times out. Any idea what the answer should be?

Aaron Meurer

Ben Goodrich

unread,
Oct 9, 2010, 11:07:25 PM10/9/10
to sympy
Hi Aaron,

On Oct 9, 10:32 pm, "Aaron S. Meurer" <asmeu...@gmail.com> wrote:
> I tried running the limit through Maple, and it couldn't do it (it just returned an unevaluated form), and Wolphram Alpha times out.  Any idea what the answer should be?

I conjecture the limit is 1 based on its similarity to some other
functions whose limit is 1, and I suspect the problem is the ceiling()
somehow is evaluating to NaN because I can't think of any other way
for that xrange() to bomb out with TypeError: an integer is required

I'll open an Issue for it.

Thanks,
Ben

Ben Goodrich

unread,
Oct 9, 2010, 11:12:05 PM10/9/10
to sympy
On Oct 9, 11:07 pm, Ben Goodrich <goodrich....@gmail.com> wrote:
> > I tried running the limit through Maple, and it couldn't do it (it just returned an unevaluated form), and Wolphram Alpha times out.  Any idea what the answer should be?
>
> I conjecture the limit is 1

for c in the (0,1) interval I meant to add.

Ben Goodrich

unread,
Oct 9, 2010, 11:22:16 PM10/9/10
to sympy
On Oct 9, 11:07 pm, Ben Goodrich <goodrich....@gmail.com> wrote:
> I'll open an Issue for it.

Now issue 2073

http://code.google.com/p/sympy/issues/detail?id=2073

Aaron S. Meurer

unread,
Oct 9, 2010, 11:17:08 PM10/9/10
to sy...@googlegroups.com
I put a print statement in there, and it seems that your symbolic power is throwing it off. It wants to compute xrange(1, 2 + ceiling(-c)).

I know that the limit algorithm relies on the series algorithm to work. I don't know if this is just a bug there if there really isn't a way to deal with symbolic powers in full generality like this (others, like Ondrej, would know better).

Aaron Meurer

Aaron S. Meurer

unread,
Oct 9, 2010, 11:45:28 PM10/9/10
to sy...@googlegroups.com
Ah! If I plug that important bit of information into Maple, I get that the answer is 2^c*(1/(1+r))^c+(1/(1+r))^c*r-(1/(1+r))^c.

No doubt SymPy would need to know it at some point, too.

Aaron Meurer

Aaron S. Meurer

unread,
Oct 10, 2010, 1:56:17 AM10/10/10
to Aaron S. Meurer, sy...@googlegroups.com
Playing around with the assumptions more (in Maple), that is the answer when c is positive, and the answer is 1 when c is zero or negative.

Aaron Meurer

Reply all
Reply to author
Forward
0 new messages