3
$\begingroup$

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]]

enter image description here

$\endgroup$
5
  • 2
    $\begingroup$ Please upload more test cases. $\endgroup$
    – Syed
    Commented Dec 14, 2023 at 9:50
  • 1
    $\begingroup$ 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. $\endgroup$
    – march
    Commented Dec 14, 2023 at 16:47
  • $\begingroup$ 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? $\endgroup$ Commented Dec 15, 2023 at 10:18
  • $\begingroup$ @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. $\endgroup$
    – march
    Commented Dec 15, 2023 at 16:52
  • $\begingroup$ @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 :-))) $\endgroup$ Commented Dec 16, 2023 at 9:24

2 Answers 2

3
$\begingroup$

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!

$\endgroup$
1
  • $\begingroup$ 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) $\endgroup$
    – ChaSta
    Commented Dec 14, 2023 at 13:44
4
$\begingroup$

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]))) *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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