Re: Algebra on complex expressions: Collect

• To: mathgroup at smc.vnet.net
• Subject: [mg15242] Re: [mg15225] Algebra on complex expressions: Collect
• From: "Carl K.Woll" <carlw at fermi.phys.washington.edu>
• Date: Sun, 27 Dec 1998 03:58:33 -0500
• Organization: Department of Physics
• References: <199812230604.BAA02088@smc.vnet.net.>
• Sender: owner-wri-mathgroup at wolfram.com

```Hi Sean,

Have you tried using the option

TargetFunctions->{Re,Im}

when you use ComplexExpand? Could you give an example where
ComplexExpand doesn't function the way you want?

As far as your question goes, here is a post by Daniel Lichtblau:

> The entity I is a number (it is a symbolic convenience for Complex[0,1])
> and Collect cannot use a number for its variable. Roughly, this is
> because Complex[a,b] is an atomic entity (for integer/rational/real
> a,b), hence will not be split for purposes of collection.
>
> You can work around this with simple replacement rules. I do it inside a
> module in order to localize the
>
> complexCollect[expr_, var_] := Module[
>         {myI,e2,v2},
>         {e2,v2} = {expr,var} /. Complex[a_,b_]->a+myI*b;
>         Collect[e2,v2] /. myI->I
>         ]
>
> In[18]:= complexCollect[(a+I)b + c I , I] Out[18]= a b + I (b + c)
>
>
> Daniel Lichtblau
> Wolfram Research

Carl Woll
Dept of Physics
U of Washington

Ross, Sean wrote:

> 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.
>
> Thanks.
>
> Sean Ross
>
> Please reply to rosss at plk.af.mil as I no longer subscribe to the
> mathgroup.

```

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