I'm trying to solve a couple (independently) of equations of the following type $ a_0 x + 3 a_1 y(1 + xe^{i3q} + e^{-iq + 2ip}) + ... = 0, \forall x, y, q, p$.

Using SolveAlways doesn't work well. So my idea was to substitute the exponential terms by $e^{inq} -> z^n, e^{imp} -> u^m$. Unfortunately, using the rule (similarly for p)

{Exp[n_*I*q] -> z^n, Exp[I*q] -> z, Exp[-I*q] -> 1/z}

doesn't work. The substitution seems pretty basic, what's going wrong here? Is there maybe a way to perform the comparison of coefficients directly?

  • $\begingroup$ Please include the expression you are working in as text in Mathematica code. $\endgroup$
    – MarcoB
    Mar 21, 2021 at 19:06

2 Answers 2



expr = Exp[I 3 q] + Exp[-I q + 2 I p];

You can do something like

expr /. {p -> -I Log[z], q -> -I Log[w]}
(* w^3 + z^2/w *)

In general, I try to keep the left hand side of any rules as simple as possible. I'm sure there is a workable rule that is a more direct match to what you need, but I rarely find it worth the effort to work out what it is.


When I cannot get a substitution to work I look at the FullForm of the expression.

FullForm[a0+3 a1 y(1+x E^(I 3 q)+E^(-I q+2 I p))==0]

which shows me


That can sometimes surprise you that the internal form is somewhat or even quite different from the pretty printed version on the screen. I write my substitution to exactly match that internal hidden structure.

The first substitution you wanted appears to be

a0+3 a1 y(1+x E^(I 3 q)+E^(-I q+2 I p))==0/.Power[E,Times[Complex[0,n_],q]]->z^n

which returns

a0 + 3*a1*y*(1 + E^((2*I)*p - I*q) + x*z^3) == 0

That worked on the first try.

Well, actually, to be really honest, I tried to do both your substitutions at the same time and the second substitution was somewhat different and I didn't succeed with that on my first try.

Can you study what I did here and try to understand the strategy and use this method on similar problems and get the substitution to work on the first try? And then can you look at the second substitution that you want and see if you can understand how to use this to make that substitution work?

Hopefully this method can help you solve substitution problems that don't work for you.


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.