Sympy:指数乘而不是总和的指数 [英] Sympy: Multiplications of exponential rather than exponential of sum

查看:197
本文介绍了Sympy:指数乘而不是总和的指数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在搜索如何告诉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.

推荐答案

您可以使用

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:

sympy.core.function.expand(e, deep=True, modulus=None, power_base=True, power_exp=True, mul=True, log=True, multinomial=True, basic=True, **hints)

使用作为提示给出的方法来扩展表达式.

Expand an expression using methods given as hints.

除非明确设置为False,否则评估的提示为:basiclogmultinomialmulpower_basepower_exp ...

Hints evaluated unless explicitly set to False are: basic, log, multinomial, mul, power_base, and power_exp ...

很明显,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:指数乘而不是总和的指数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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