Sharedsupport / 2017-01-22-limit-bug.sagewsOpen in CoCalc
Author: William A. Stein
License: GNU General Public License v3.0
Description: Examples for support purposes.
((2^(2*x+1)+(2^x*x^100)^(3/2))/(4^x-100*2^x)).limit(x=infinity)
-Infinity
((2^(2*x+1)+(2^x*x^100)^(3/2))/(4^x-100*2^x)).limit(x=infinity, algorithm="sympy")
2
((2^(2*x+1)+(2^x*x^100)^(3/2))/(4^x-100*2^x)).limit(x=infinity, algorithm="maxima_taylor")
-Infinity
((2^(2*x+1)+(2^x*x^100)^(3/2))/(4^x-100*2^x)).limit(x=infinity, algorithm="maxima")
-Infinity
f(x) = ((2^(2*x+1)+(2^x*x^100)^(3/2))/(4^x-100*2^x))
f.limit(x=+infinity)
x |--> -Infinity
plot(f, 0, 100)
N(f(100000))
2.00000000000000
f._sympy_().limit(x._sympy_(), oo._sympy_())
2
f.limit??
File: /projects/sage/sage-7.3/src/sage/symbolic/expression.pyx Source: def limit(self, *args, **kwds): """ Return a symbolic limit. See :obj:`sage.calculus.calculus.limit` EXAMPLES:: sage: (sin(x)/x).limit(x=0) 1 """ from sage.calculus.calculus import limit return limit(self, *args, **kwds)
sage.calculus.calculus.limit??
File: /projects/sage/sage-7.3/local/lib/python2.7/site-packages/sage/calculus/calculus.py Source: def limit(ex, dir=None, taylor=False, algorithm='maxima', **argv): r""" Return the limit as the variable `v` approaches `a` from the given direction. :: expr.limit(x = a) expr.limit(x = a, dir='+') INPUT: - ``dir`` - (default: None); dir may have the value 'plus' (or '+' or 'right') for a limit from above, 'minus' (or '-' or 'left') for a limit from below, or may be omitted (implying a two-sided limit is to be computed). - ``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). - ``**argv`` - 1 named parameter .. note:: The output may also use 'und' (undefined), 'ind' (indefinite but bounded), and 'infinity' (complex infinity). EXAMPLES:: sage: x = var('x') sage: f = (1+1/x)^x sage: f.limit(x = oo) e sage: f.limit(x = 5) 7776/3125 sage: f.limit(x = 1.2) 2.06961575467... sage: f.limit(x = I, taylor=True) (-I + 1)^I sage: f(x=1.2) 2.0696157546720... sage: f(x=I) (-I + 1)^I sage: CDF(f(x=I)) 2.0628722350809046 + 0.7450070621797239*I sage: CDF(f.limit(x = I)) 2.0628722350809046 + 0.7450070621797239*I Notice that Maxima may ask for more information:: sage: var('a') a sage: limit(x^a,x=0) Traceback (most recent call last): ... ValueError: Computation failed since Maxima requested additional constraints; using the 'assume' command before evaluation *may* help (example of legal syntax is 'assume(a>0)', see `assume?` for more details) Is a positive, negative or zero? With this example, Maxima is looking for a LOT of information:: sage: assume(a>0) sage: limit(x^a,x=0) Traceback (most recent call last): ... ValueError: Computation failed since Maxima requested additional constraints; using the 'assume' command before evaluation *may* help (example of legal syntax is 'assume(a>0)', see `assume?` for more details) Is a an integer? sage: assume(a,'integer') sage: limit(x^a,x=0) Traceback (most recent call last): ... ValueError: Computation failed since Maxima requested additional constraints; using the 'assume' command before evaluation *may* help (example of legal syntax is 'assume(a>0)', see `assume?` for more details) Is a an even number? sage: assume(a,'even') sage: limit(x^a,x=0) 0 sage: forget() More examples:: sage: limit(x*log(x), x = 0, dir='+') 0 sage: lim((x+1)^(1/x), x = 0) e sage: lim(e^x/x, x = oo) +Infinity sage: lim(e^x/x, x = -oo) 0 sage: lim(-e^x/x, x = oo) -Infinity sage: lim((cos(x))/(x^2), x = 0) +Infinity sage: lim(sqrt(x^2+1) - x, x = oo) 0 sage: lim(x^2/(sec(x)-1), x=0) 2 sage: lim(cos(x)/(cos(x)-1), x=0) -Infinity sage: lim(x*sin(1/x), x=0) 0 sage: limit(e^(-1/x), x=0, dir='right') 0 sage: limit(e^(-1/x), x=0, dir='left') +Infinity :: sage: f = log(log(x))/log(x) sage: forget(); assume(x<-2); lim(f, x=0, taylor=True) 0 sage: forget() Here ind means "indefinite but bounded":: sage: lim(sin(1/x), x = 0) ind TESTS:: sage: lim(x^2, x=2, dir='nugget') Traceback (most recent call last): ... ValueError: dir must be one of None, 'plus', '+', 'right', 'minus', '-', 'left' We check that :trac:`3718` is fixed, so that Maxima gives correct limits for the floor function:: sage: limit(floor(x), x=0, dir='-') -1 sage: limit(floor(x), x=0, dir='+') 0 sage: limit(floor(x), x=0) und Maxima gives the right answer here, too, showing that :trac:`4142` is fixed:: sage: f = sqrt(1-x^2) sage: g = diff(f, x); g -x/sqrt(-x^2 + 1) sage: limit(g, x=1, dir='-') -Infinity :: sage: limit(1/x, x=0) Infinity sage: limit(1/x, x=0, dir='+') +Infinity sage: limit(1/x, x=0, dir='-') -Infinity Check that :trac:`8942` is fixed:: sage: f(x) = (cos(pi/4-x) - tan(x)) / (1 - sin(pi/4+x)) sage: limit(f(x), x = pi/4, dir='minus') +Infinity sage: limit(f(x), x = pi/4, dir='plus') -Infinity sage: limit(f(x), x = pi/4) Infinity Check that we give deprecation warnings for 'above' and 'below', :trac:`9200`:: sage: limit(1/x, x=0, dir='above') doctest:...: DeprecationWarning: the keyword 'above' is deprecated. Please use 'right' or '+' instead. See http://trac.sagemath.org/9200 for details. +Infinity sage: limit(1/x, x=0, dir='below') doctest:...: DeprecationWarning: the keyword 'below' is deprecated. Please use 'left' or '-' instead. See http://trac.sagemath.org/9200 for details. -Infinity Check that :trac:`12708` is fixed:: sage: limit(tanh(x),x=0) 0 Check that :trac:`15386` is fixed:: sage: n = var('n') sage: assume(n>0) sage: sequence = -(3*n^2 + 1)*(-1)^n/sqrt(n^5 + 8*n^3 + 8) sage: limit(sequence, n=infinity) 0 """ if not isinstance(ex, Expression): ex = SR(ex) if len(argv) != 1: raise ValueError("call the limit function like this, e.g. limit(expr, x=2).") else: k = argv.keys()[0] v = var(k) a = argv[k] if taylor and algorithm == 'maxima': algorithm = 'maxima_taylor' if dir not in [None, 'plus', '+', 'right', 'minus', '-', 'left', 'above', 'below']: raise ValueError("dir must be one of None, 'plus', '+', 'right', 'minus', '-', 'left'") if algorithm == 'maxima': if dir is None: l = maxima.sr_limit(ex, v, a) elif dir in ['plus', '+', 'right', 'above']: if dir == 'above': from sage.misc.superseded import deprecation deprecation(9200, "the keyword 'above' is deprecated. Please use 'right' or '+' instead.") l = maxima.sr_limit(ex, v, a, 'plus') elif dir in ['minus', '-', 'left', 'below']: if dir == 'below': from sage.misc.superseded import deprecation deprecation(9200, "the keyword 'below' is deprecated. Please use 'left' or '-' instead.") l = maxima.sr_limit(ex, v, a, 'minus') elif algorithm == 'maxima_taylor': if dir is None: l = maxima.sr_tlimit(ex, v, a) elif dir == 'plus' or dir == 'above' or dir == 'from_right': l = maxima.sr_tlimit(ex, v, a, 'plus') elif dir == 'minus' or dir == 'below' or dir == 'from_left': l = maxima.sr_tlimit(ex, v, a, 'minus') elif algorithm == 'sympy': if dir is None: import sympy l = sympy.limit(ex._sympy_(), v._sympy_(), a._sympy_()) else: raise NotImplementedError("sympy does not support one-sided limits") #return l.sage() return ex.parent()(l)