I have an expression like this

(E^(-(j + k) y) (-1 + E^(i y)))/(j k)

I would like to take E^(i y) out of the brackets to get

(E^(i y + (-j - k) y) (1 - E^(-i y)))/(j k)

Of course, I can do such thing by copy and paste, but I wonder if there is a trick to do it programmatically.


You can try the following:

factorOut[fac_][expr_] := Replace[expr, p_Plus :> fac Simplify[p/fac], All]

It is used as

factorOut[E^(i y)][(E^(-(j + k) y) (-1 + E^(i y)))/(j k)]
(* (E^(i y + (-j - k) y) (1 - E^(-i y)))/(j k) *)

$\frac{\left(1-e^{-i y}\right) e^{i y+y (-j-k)}}{j k}$

The idea is to try to pull out the specified factor from every sum. This is always correct as $p=f\cdot\frac pf$.The trick is that Mathematica doesn't revert this instantly since $\frac pf$ can be simplified.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.