问题
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