Simplifying exponential representation of hyperbolic functions in sympy

Deadly 提交于 2019-12-10 20:27:25

问题


I am trying to rewrite some exponential functions in an expression to cosh and sinh. The rewrite() function works to get from a hyperbolic function to its exponential representation. But it does not work to get back.

>>> import sympy
>>> x=sympy.Symbol('x')
>>> sympy.cosh(x).rewrite(sympy.exp)
exp(x)/2 + exp(-x)/2
>>> sympy.cosh(x).rewrite(sympy.exp).rewrite(sympy.cosh)
exp(x)/2 + exp(-x)/2

I would expect the result of the last command to be 'cosh(x)'. Can someone explain to me why it is not? I tried to find some documentation on the rewrite() function but the only bit I found was the short section in http://docs.sympy.org/latest/tutorial/simplification.html that is not really helpful.


回答1:


Applying .rewrite(sympy.cos) returns cosh(x) as you wanted. Apparently, the hyperbolic cosine is treated by rewrite as a variant of the normal one.

Here is a reference on rewrite method.

Alternatively, simplify(expr) also transforms exp(x)/2 + exp(-x)/2 into cosh(x).



来源:https://stackoverflow.com/questions/44157724/simplifying-exponential-representation-of-hyperbolic-functions-in-sympy

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