问题描述
我正在搜索如何告诉SymPy使用指数的乘法而不是总和的指数.也就是说,当前它给我exp(a + b),而我想得到exp(a)* exp(b).一定有一种相当简单的方法,但是我似乎找不到它.
I'm searching how to tell SymPy to use a multiplication of exponentials rather than an exponential of a sum. That is, it currently gives me exp(a + b) and I would want to get exp(a)*exp(b). There must be a fairly easy way but I can't seem to find it.
推荐答案
您可以使用 expand()
函数显示带底数而不是指数和的乘法表达式:
You could use the expand()
function to show the expression with multiplication of bases rather than the sum of exponents:
>>> from sympy import *
>>> a, b = symbols('a b')
>>> expr = exp(a + b)
>>> expr
exp(a + b)
>>> expr.expand()
exp(a)*exp(b)
此功能的文档位于此处.相关部分总结如下:
The documentation for this function is here. The relevant parts are summarised below:
使用作为提示给出的方法来扩展表达式.
Expand an expression using methods given as hints.
除非明确设置为False,否则评估的提示为:basic
,log
, multinomial
,mul
,power_base
和power_exp
...
Hints evaluated unless explicitly set to False are: basic
, log
, multinomial
, mul
, power_base
, and power_exp
...
很明显,power_exp
是相关提示:
将指数中的加法扩展为乘法的底数.
Expand addition in exponents into multiplied bases.
>>> exp(x + y).expand(power_exp=True)
exp(x)*exp(y)
>>> (2**(x + y)).expand(power_exp=True)
2**x*2**y
将其转到False
可使表达式保持不变:
Turning it to False
leaves the expression unchanged:
>>> expr.expand(power_exp=False)
exp(a + b)
这篇关于Sympy:指数乘而不是总和的指数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!