When attempting to deal with replacements a good general rule is to examine the FullForm
of the components.
Expression 1
FullForm[Exp[I m phiA]]

Expression 2
FullForm[Exp[-2 I (phiA + phiB)]]

Expression 3
FullForm[Exp[2 I phiA + 2 I phiB]]

Note carefully that even though Exp[-2 I (phiA + phiB)]
is algebraically equivalent to Exp[-2 I phiA -2 I phiB]
the two FullForms are not the same.
Pattern matching uses the syntax to find matches.
We can make replacement rules as follows.
Take the FullForm
of the expression and insert named patterns.
Note: You can stay with the exact FullForm
syntax but it doesn't print well on Stack Exchange so I will use the expanded FullForm
.
Expression 1
Exp[I m phiA] /. E^(I m_ phiA_) -> f[m, phiA]
f[m, phiA]
We will come back to Expression 2 in a moment.
Expression 3
Exp[2 I phiA + 2 I phiB] /. E^(Complex[0, m_] phiA_ + Complex[0, n_] phiB_) ->
f[m, phiA] f[n, phiB]
f[2, phiA] f[2, phiB]
Expression 2
The question was asked in a comment if it would be possible to generalize expression 2 to an arbitrary number of components. This can be done as follows:
FullForm[Exp[-2 I (phiA + phiB + phiC)]]

Replace the Plus
with List
and use Map
.
Exp[-2 I (phiA + phiB + phiC)] /. E^(Complex[0, m_] (first_ + rest__)) :>
Times@@Map[f[m, #] &, List[first, rest]]
produces
f[-2, phiA] f[-2, phiB] f[-2, phiC]
Summary
All of the rules would be placed in a list to transform expressions containing exponents with arguments that match the forms in expressions one, two and three.
expr /. {
E^(I m_ phiA_) -> f[m, phiA],
E^(Complex[0, m_] (phiA_ + phiB_)) -> f[m, phiA] f[m, phiB],
E^(Complex[0, m_] (first_ + rest__)) :>
Times @@ Map[f[m, #] &, List[first, rest]]
}
Exp[m I phi]
usingComplex
. How can I transformExp[-2 I (phiA + phiB)]
to a product of elements likeExp[m I phi]
? $\endgroup$ – Pincopallino Dec 3 '13 at 18:03Exp[-2 I (phiA + phiB)] /. Exp[a_ (b_ + c_)] :> HoldForm[Exp[a b] Exp[a c]]
. $\endgroup$ – Artes Dec 3 '13 at 18:08