How to add assumptions in limit in Sympy?

混江龙づ霸主 提交于 2019-12-10 20:09:30

问题


I want to add some assumptions in limit.
Suppose 0<x<1, then $$limit_{n \to \infty} x^n = 0$$

from sympy import *
x = var('x, n')
limit(x**n, n, oo)

But I get an error NotImplementedError: Result depends on the sign of sign(log(x)).

Is there some way in sympy to handle this?


回答1:


EDIT: As pointed out in the comments the solution below fails with the same NotImplementedError as in the question (as of November 2019) saying that the answer depends on sign(log(x)). It seems that this sign problem can not be solved with assuming but only with the positive parameter of Symbol. So one way around the issue is to describe 0 < x < 1 as exp(-y) for y > 0:

from sympy import *

y = Symbol("y", positive=True)
n = Symbol("n")

print(limit(exp(-y)**n, n, oo)) # outputs 0

To assume something you can say:

from sympy.assumptions import assuming, Q
with assuming(...):

see here: http://docs.sympy.org/latest/modules/assumptions/assume.html

In your case:

from sympy import *
from sympy.assumptions import assuming, Q

x, n = symbols("x n")
with assuming(Q.is_true(0 < x), Q.is_true(x <1)):
    print(limit(x**n, n, oo))


来源:https://stackoverflow.com/questions/27587985/how-to-add-assumptions-in-limit-in-sympy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!