如何简化sympy中指数的对数? [英] How to simplify logarithm of exponent in sympy?

查看:392
本文介绍了如何简化sympy中指数的对数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我键入

import sympy as sp
x = sp.Symbol('x')
sp.simplify(sp.log(sp.exp(x)))

我获得

log(e^x)

而不是x.我知道此功能没有保证".

Instead of x. I know that "there are no guarantees" on this function.

问题.是否有一些特定的简化(通过级数展开或其他方式)将指数的对数转换为恒等函数?

Question. Is there some specific simplification (through series expansion or whatsoever) to convert logarithm of exponent into identity function?

推荐答案

您必须将x设置为实型,您的代码才能正常工作:

You have to set x to real type and your code will work:

import sympy as sp
x = sp.Symbol('x', real=True)
print(sp.simplify(sp.log(sp.exp(x))))

输出:x.

对于复杂的x,此公式的结果并不总是等于x.示例是此处.

For complex x result of this formula is not always is equal to x. Example is here.

这篇关于如何简化sympy中指数的对数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆