MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Algebra on complex expressions: Collect

  • To: mathgroup at
  • Subject: [mg15244] Re: [mg15225] Algebra on complex expressions: Collect
  • From: Andrzej Kozlowski <andrzej at>
  • Date: Sun, 27 Dec 1998 03:58:35 -0500
  • Sender: owner-wri-mathgroup at

I am not quite sure why you find the existing Re and Im functions
unsatisfactory, but here are a few comments which may be helpful. I
assume you want to be able to deal both with numberic complex numbers,
like 2+3I and symboloc ones like a+b*I, where a and b are meant to be
real. It is useful first to load the package 


This make sit possible to declare certain symbols to be real, e.g.:
a/:Im[a]=0;b/:Im[b]=0;c/:Im[c]=0;d/:Im[d]=0; declares a, b, c, d to be

Mathematica can now find real and imaginary parts of symboloc
expressions like:

  b c       a d
------- - -------
 2    2    2    2
c  + d    c  + d

You can if you want define your own complexcollect function:


This will work well in the above example:

  a c       b d          b c       a d 
------- + ------- + I (------- - -------)
 2    2    2    2       2    2    2    2 
c  + d    c  + d       c  + d    c  + d

but now always, e.g. 

3 + I (4 + E) + Pi

The point is that Mathematica will order the symbols according to its
built in ordering principle and, depending on the names of your
symbols, the real numbers may be separated by the complex part. Of
course you can make things look right by choosing the letters you use
for your real and imaginary parts carefully, but sometimes, as in the
above example, you have no choice! I do not know of any simple way of
solving this "problem", if it is a problem, though it would be easy
enough to do if you were only concerned with the expression "looking

Finally, if you decide to use ComplexExpand you will get:

     a c            I b c           I a d            b d 
------------- + ------------- - ------------- + -------------
            2               2               2               2 
Abs[c + I d]    Abs[c + I d]    Abs[c + I d]    Abs[c + I d]

Abs disregards the fact that we declared c and d to be real. One can
modify Abs to pay attention to this:

Abs[a_+b_*I]/;(Im[a]==0&&Im[b]==0):=Sqrt[a^2+b^2] Protect[Abs]


  a c      I b c     I a d      b d
------- + ------- - ------- + -------
 2    2    2    2    2    2    2    2 
c  + d    c  + d    c  + d    c  + d

I hope this is of some help. If any one knows of a better way to answer
this question I would like to hear of it myself

On Wed, Dec 23, 1998, Ross, Sean <rosss at> wrote:

D>Does anyone know a way to have a Collect -like function work on
>expressions with complex numbers?  If I have an expression with "x" in
>it, I can use Collect[expr,x], but if I have an expression with "I" in
>it, Collect[expr,I] does not separate the expression into a part with
>and without "I" which would be equivalent to separating the expression
>into real and imaginary parts given all symbols were real.
>The RealOnly package does not seem to apply as it excludes imaginary
>numbers alltogether.  ComplexExpand results in a ridiculous amount of
>complexity and is worse than nothing for this purpose.  Expanding and
>multiplying numerator and denominator separately by the complex
>conjugate of the denominator is tedious to do manually and results in
>the same problem of no way to neatly separate the real and imaginary
>parts of a symbolic expression given that all symbols are real.
>Sean Ross
>Please reply to rosss at as I no longer subscribe to the

Andrzej Kozlowski
Toyama International University

  • Prev by Date: List of Matrices
  • Next by Date: RE: Getting rid of annoying zeroes in algebraic expressions
  • Previous by thread: Re: Algebra on complex expressions: Collect
  • Next by thread: Re: Algebra on complex expressions: Collect