# Simplifying factorials, limits, Maxima crash

I am trying to simplify some binomial expressions using Sage.

var('a,n,c,m')
H = binomial(2*m-c,m-c)-binomial(2*m-c,m+1)
Cn = binomial(2*n,n)/(n+1)
Uan = (H.substitute(m=n,c=a+1) + a*H.substitute(m=n-1,c=a))/Cn
assume(a>0)
assume(n>0)
assume(n,'integer')
assume(a,'integer')
UUan=Uan.full_simplify()
UUan


Now I want the limit of this expression as n -> +Infininty. Maple can do it, it correctly returns

                                                             2                  (-a)
(a  + 3 a + 4) 2
--------------------
4


I can get Sage to calculate the limit for specific values of a:

limit(UUan.substitute(a=5),n=+Infinity)


However, when I try

limit(UUan,n=+Infinity)


I get an error from the underlying Maxima engine:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-70-59aa81a6cc92> in <module>
----> 1 limit(UUan,n=+Infinity)

~/sage/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/sage/calculus/calculus.py in limit(ex, dir, taylor, algorithm, **argv)
1415     if algorithm == 'maxima':
1416         if dir is None:
-> 1417             l = maxima.sr_limit(ex, v, a)
1418         elif dir in dir_plus:
1419             l = maxima.sr_limit(ex, v, a, 'plus')

~/sage/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/sage/interfaces/maxima_lib.py in sr_limit(self, expr, v, a, dir)
985             elif dir == "minus":
986                 L.append(max_minus)
--> 987             return max_to_sr(maxima_eval(([max_limit], L)))
988         except RuntimeError as error:
989             s = str(error)

~/sage/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/sage/libs/ecl.pyx in sage.libs.ecl.EclObject.__call__ (build/cythonized/sage/libs/ecl.c:8511)()
836         """
837         lispargs = EclObject(list(args))
--> 838         return ecl_wrap(ecl_safe_apply(self.obj,(<EclObject>lispargs).obj))
839
840     def __richcmp__(left, right, int op):

~/sage/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/sage/libs/ecl.pyx in sage.libs.ecl.ecl_safe_apply (build/cythonized/sage/libs/ecl.c:6053)()
357             raise KeyboardInterrupt("ECL says: {}".format(message))
358         else:
--> 359             raise RuntimeError("ECL says: {}".format(message))
360     else:
361         return ret

RuntimeError: ECL says: BINDING-STACK overflow at size 10240. Stack can probably be resized.
Proceed with caution.

---------------------------------------------------------------------------------------------------------------------------------------------


Is SAGE able to compute this limit? Should i provide other provisos? Is there another approach I should try?

Edit: The following works:

Uan.limit(n=Infinity,dir='+',taylor=True)


so I guess all is well. I do not know if the fact that Maxima throws an exception when the taylor keyword is ommitted is a bug or not. The documentation for limit says

• "taylor" - (default: False); if True, use Taylor series, which allows more limits to be computed (but may also crash in some obscure cases due to bugs in Maxima).

Maybe this should be amended to indicate that in some cases, taylor=False causes crashes.

edit retag close merge delete

++++++++++

( 2022-06-21 15:37:02 +0200 )edit

Sort by ยป oldest newest most voted

Workarounds :

sage: import sympy
sage: sympy.limit(*map (sympy.sympify, (UUan, n, oo)))._sage_()
1/4*(a^2 + 3*a + 4)/2^a


Or, more simply :

sage: limit(UUan, n=oo, algorithm="sympy")
1/4*(a^2 + 3*a + 4)/2^a


Also :

sage: mathematica.Limit(UUan, mathematica.Rule(n, oo))._sage_()
(a^2 + 3*a + 4)*2^(-a - 2)


Fricas and Giac have some infelicities in this department...

more

The function limit() has a keyword taylor, which might help or hinder. In this case,

Uan.limit(n=Infinity,dir='+',taylor=True)


works, whereas the computation crashes with BINDING-STACK overflow when taylor=False. Unclear if bug.

more