使用sympy简化嵌套的指数和日志

时间:2015-05-18 16:20:02

标签: python sympy symbolic-math

如何简化log(exp(exp(x)))exp(x)这样的表达方式?它似乎适用于更简单的表达式,如exp(log(x)) => x。这是一个显示我迄今为止尝试过的最小例子:

import sympy
from sympy import exp, log

x = sympy.symbols('x')

a = exp(log(x))
print a

# Gives `x` automatically, no call to simplify needed

b = log(exp(exp(x)))
print sympy.simplify(b), sympy.powsimp(b,deep=True)

# Gives `log(exp(exp(x)))` back, expected `exp(x)`

1 个答案:

答案 0 :(得分:3)

由于缺乏信息,这种情况正在发生。我想你想这样做:

In [7]: x = Symbol('x', real=True)

In [8]: (log(exp(exp(x)))).simplify()
Out[8]: exp(x)