# Better Factorization

It seems Mathematica likes to factor some things in less than optimal ways. For example, for the oscillating exponential function (F) below, is there any way to force it to reduce both the number of exponential terms and appearance of constants like A? I can of course look at the result and manually rewrite it as function G, but this gets trickier for more complex equations.

F = A E^(-I t (\[Omega] + Subscript[\[Omega], 12])) (-1 + E^(I t (\[Omega] + Subscript[\[Omega], 12])))
Expand[F]
G = A*(1 - E^(-I t (\[Omega] + Subscript[\[Omega], 12])) )
Simplify[F == G]
Factor[Expand[F]]


– Syed
Commented Dec 14, 2023 at 9:50
• Depending on your use cases, sometimes using Collect instead of Factor does the factoring that you want. For instance, Collect[F, A, Simplify] does things nicely. Commented Dec 14, 2023 at 16:47
• ChaSta, Factor's intended use is to factor in P[ℤ], it's certainly not the right function to use. @march, your answer is entirely correct. Would you like writing an answer? Commented Dec 15, 2023 at 10:18
• @kkm-stillwaryofSEpromises I think without more use cases, I don't know if this is actually the correct answer. And if it is, I would suggest closing this question using the "found in documentation" close reason. Commented Dec 15, 2023 at 16:52
• @march Right, I see. But I'd wait if OP could add more info early next week. Not everyone spends their weekends on MMA.SO (it's Saturday, 01:20 here :-))) Commented Dec 16, 2023 at 9:24

From your question it is not quite clear, what are you after. My guess is that you want to take A out of the parantheses, while the exponential term should stay intact, is it? If yes, try this:

Factor[(F // Simplify) /. E^(-I t (ω + ω12)) -> -x] /.
x -> -E^(-I t (ω + ω12))

(*  A (1 - E^(-I t (ω + ω12)))  *)


If it is not what you need, explain please clearer.

Have fun!

• Yes, although I'm looking for a general form for this. The goal is to show as few terms as possible, without multiple A's or multiple Exponentials. I think the function below may be good enough, although in some cases it doesn't quite factor out -1*(-1)'s. Thanks! Factor[Simplify[F] /. E^(y_) -> x[y]] /. x[y_] -> E^(y) Commented Dec 14, 2023 at 13:44

You could also look into making a ComplexityFunction which suits your needs. This could be an example or starting point:

FullSimplify[F,
ComplexityFunction ->
(100 Count[#, A | Exp, {0, Infinity}] + 10 Count[#, (-1), {1}] + LeafCount[#] &)]
(* A (1 - E^(-I t (ω + Subscript[ω, 12]))) *)