Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
Collect[Expand[(x + I y)^6], I]


x^6 + 6 I x^5 y - 15 x^4 y^2 - 20 I x^3 y^3 + 15 x^2 y^4 + 6 I x y^5 - y^6

How can I obtain

x^6 - 15 x^4 y^2 + 15 x^2 y^4 - y^6 + (6 x^5 y - 20 x^3 y^3 + 6 x y^5) I 
share|improve this question
up vote 5 down vote accepted
ComplexExpand[(x + I y)^6]
x^6 - 15 x^4 y^2 + 15 x^2 y^4 - y^6 + I (6 x^5 y - 20 x^3 y^3 + 6 x y^5)

Collect is not especially designed for your purpose. Nonetheless if one insists on using it we can take e.g. ComplexExpand for the third argument in Collect to get the former result (Expand is not needed anymore):

Collect[ (x + I y)^6, I, ComplexExpand]

In case that you'd like to get the result in the form a I instead of I a, I'd use a simple replacement rule I a_ :> HoldForm[a I], e.g.

ComplexExpand[(x + I y)^6] /. I a_ :> HoldForm[a I]
x^6 - 15 x^4 y^2 + 15 x^2 y^4 - y^6 + (6 x^5 y - 20 x^3 y^3 + 6 x y^5) I
share|improve this answer
I am not committed to Collect. If you know of a more appropriate solution, please share it. – Phillip Dukes Jul 14 '13 at 23:23
@PhillipDukes ComplexExpand is an appropriate solution. You can take a look at its options (TargetFunctions) if there might be some specific needs for customizing the output form. In general it is difficult to guess what kind of results one expects if not provided more specific example. If you doubt about ComplexExpand universality, please provide an example where it doesn't work as you expect. I'll try to help anyway. – Artes Jul 14 '13 at 23:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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