A question about expanding complex functions of real arguments


I have the following problem. There is such an expression as:

P[x_,y_] := z[y] E^(I beta x) + Conjugate[z[y] E^(I beta x)];

The variables x, y, beta are real but the function z[y] is complex. I need to expand P[x, y]^2. So I try this:

ComplexExpand[P[x, y]^2, z[y]]

The output contains Re[z[y]], Im[z[y]], Cos[...] and Sin[...]. In my case, I need the output to be like this:

z[y]^2 E(2 I beta x) + 2 z[y] Conjugate[z[y]] + Conjugate[z[y]]^2 E^(-2 I beta x)

What should I change in my approach? I have already tried TrigToExpand, FullSimplify and Hold but I did not get the desirable result.


Posted 2014-10-06T11:43:44.183

Reputation: 25

You can get rid of the Re and Im by using the option TargetFunctions->{Conjugate}. But that still gives Sin and Cos for the exponential functions. – celtschk – 2014-10-06T11:54:43.067

Welcome to Mathematica.SE! I suggest the following:

  1. As you receive help, try to give it too, by answering questions in your area of expertise.
  2. Read the [faq]!
  3. When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge.

Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign!

– Dr. belisarius – 2014-10-06T12:10:37.360



The following gives what you intended:

Refine[Expand[P[x, y]^2], (x|y|beta) \[Element] Reals]
==> Conjugate[z[y]]^2/E^((2*I)*beta*x) + 2*Conjugate[z[y]]*z[y] + 

In cases where you can live with expansion of complex exponentials into Sin and Cos you can also use

ComplexExpand[P[x, y]^2, z[y], TargetFunctions->{Conjugate}]
==> Conjugate[z[y]]^2*Cos[beta*x]^2 - (2*I)*Conjugate[z[y]]^2*Cos[beta*x]*
      Sin[beta*x] - Conjugate[z[y]]^2*Sin[beta*x]^2 + 
     2*Conjugate[z[y]]*Cos[beta*x]^2*z[y] + 2*Conjugate[z[y]]*Sin[beta*x]^2*
      z[y] + Cos[beta*x]^2*z[y]^2 + (2*I)*Cos[beta*x]*Sin[beta*x]*z[y]^2 - 


Posted 2014-10-06T11:43:44.183

Reputation: 18 543

Nice one. I think the question title is misleading b/c the problem isn't about ComplexExpand[] but about expressing a Complex expression in terms of certain things. Can you find a better title? I'm not sure about the better option. – Dr. belisarius – 2014-10-06T12:03:41.407

@celtschk Thank you a lot! – Vladimir – 2014-10-06T12:06:42.010

@belisarius I agree with you that the title does not express the very problem. I will rename it. – Vladimir – 2014-10-06T12:07:39.013