Reputation: 380
How can an expression of the form exp(a * x) * exp(b * x) be transformed to exp(a * x +b * x) using sympy?
The starting point would be something like:
from sympy import symbols, exp
from sympy import exp
x, a, b = symbols('x, a, b', real=True)
f = exp(a*x)*exp(b*x)
The inverse transformation has been explained in [1]
[1] Sympy: Multiplications of exponential rather than exponential of sum
Upvotes: 0
Views: 396
Reputation: 71
The simplify
command does the job
from sympy import symbols, simplify, exp
x, a, b = symbols('x, a, b', real=True)
f = exp(a*x)*exp(b*x)
fs = simplify(f)
Output
>>> f
exp(ax)exp(bx)
>>> fs
exp(x(a + b))
Upvotes: 2
Reputation: 2522
I found that powsimp
could do what you want
from sympy import symbols, exp
from sympy import exp, powsimp
x, a, b = symbols('x, a, b', real=True)
f = exp(a*x)*exp(b*x)
powsimp(f)
Output
exp(a*x + b*x)
powdenest
also (in this case) do the same
Reference to powsimp
Reference to powdenest
Upvotes: 3