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

Simplify nested exponentials and logs with sympy

如何让 sympy 将 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)`

这是由于缺乏信息而发生的。我想你想这样做:

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

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