Expand complex exponentials to trig functions in Sympy

Viewed 551

I have the following sympy code:

W, k = symbols('W k', real=True)
expr = exp(W)*(exp(I*k) - exp(-I*k))
print(expr)

and I would like sympy to simplify it to:

exp*(W)(2*I*sin(k)

I have tried expr.simplify() and expr.trigsimp() but they don't substitute any trig functions. The only partial solution I was able to find is

expr.rewrite(cos).trigsimp()

but this also expands exp(W) to hyperbolic sine/cosine, which I don't want.

2 Answers

Ok, using

expr.rewrite(cos).simplify()

worked.

expr.expand(complex = True).simplify()

should work.

Related