Skip to content Skip to sidebar Skip to footer

Sympy: Multiplications Of Exponential Rather Than Exponential Of Sum

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

Solution 1:

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.

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

It's clear that power_exp is the relevant hint:

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

Turning it to False leaves the expression unchanged:

>>>expr.expand(power_exp=False)
exp(a + b)

Post a Comment for "Sympy: Multiplications Of Exponential Rather Than Exponential Of Sum"