2015-05-18 42 views
1

如何獲取sympy以簡化表達式,如log(exp(exp(x)))exp(x)?它似乎適用於更簡單的表達式,如exp(log(x)) =>x。這是一個最小的例子,顯示了我迄今爲止所嘗試的:簡化嵌套指數並用sympy記錄

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)` 

回答

2

這是因爲缺乏信息而發生的。我想你想這樣做:

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

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