Re: Re: A way around the limitations of Re[] and Im[]

*To*: mathgroup at smc.vnet.net*Subject*: [mg51144] Re: [mg51118] Re: A way around the limitations of Re[] and Im[]*From*: Murray Eisenberg <murray at math.umass.edu>*Date*: Wed, 6 Oct 2004 04:34:19 -0400 (EDT)*Organization*: Mathematics & Statistics, Univ. of Mass./Amherst*References*: <cjr8lg$opp$1@smc.vnet.net> <200410050837.EAA08379@smc.vnet.net>*Reply-to*: murray at math.umass.edu*Sender*: owner-wri-mathgroup at wolfram.com

I see no advantage of this definition of ReadPart over a use of the built-in ComplexExpand composed with the built-in Re. That is, RealPart[c_] := ComplexExpand[Re[c]] gives the same results in the 4 examples shown below as does the definition of RealPart also shown below. Are there other situations where there would be a significant distinction? Analogously: ImaginaryPart[c_] := ComplexExpand[Im[c]] Carlos Felippa wrote: > carlos at colorado.edu (Carlos Felippa) wrote in message news:<cjr8lg$opp$1 at smc.vnet.net>... > >>As you know, Re[expr] and Im[expr] are left unevaluated when expr is >>not numeric. I had good luck in simple cases with the following >>substitution trick: >> >> Real[c_]:=c/.I->0; Imag[c_]:=(c-Real[c])/.I->1; >> >>Do you see any problem with these definitions? > > > Not yet there. Found limitations because n*I is internally stored as > Complex[0,n]. This version has done better: > > RealPart[c_]:=ComplexExpand[c]/.{Complex[0,_]->0}; > > Examples: > > Print[ RealPart[(a+I*b)^2] //InputForm]; > Print[ RealPart[(a+I*b)^n] //InputForm]; > Print[ RealPart[Exp[I*x]/I] //InputForm]; > Print[ RealPart[Cosh[x+y*I]] //InputForm]; > > Results: > > a^2 - b^2 > Abs[a]^n*Cos[n*Arg[a]] > Sin[x] > Cos[y]*Cosh[x] > > > -- Murray Eisenberg murray at math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305

**References**:**Re: A way around the limitations of Re[] and Im[]***From:*carlos@colorado.edu (Carlos Felippa)