MathGroup Archive 2005

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

Search the Archive

Re: Complex Oddity

  • To: mathgroup at
  • Subject: [mg57471] Re: [mg57455] Complex Oddity
  • From: Bob Hanlon <hanlonr at>
  • Date: Sun, 29 May 2005 01:03:29 -0400 (EDT)
  • Reply-to: hanlonr at
  • Sender: owner-wri-mathgroup at

Whenever a replacement does not seem to work, look at the FullForm and you 
will usually see why it works the way that it does.



To define a variable as real, use TagSet to define upvalues

x /: Re[x]=x;
x /: Im[x]=0;
y /: Re[y]=y;
y /: Im[y]=0;




or use Simplify with assumptions


Simplify[{Re[z],Im[z]}, Element[{a,b}, Reals]]


Bob Hanlon

> From: "John Reed" <nospamjreed at>
To: mathgroup at
> Date: 2005/05/28 Sat AM 05:39:32 EDT
> Subject: [mg57471] [mg57455] Complex Oddity
> I was trying to separate the real and imaginary parts of a complicated 
> expression, and ended up with something strange.  Here is a short version 
> what happened.
> Let z = x + I y, then realPart = z /. {Complex[a_,b_]->a} gives realPart = 
> x.  Great!
> Now, try imagPart = z /. {Complex[a_,b_]->b}  returns with imagPart = x + 
> Oops
> In my original expression, it was harder to see, but the same error was 
> occuring.  What I tried first was using Re[z] and Im[z], but then I have to 
> work with Im[y] and Im[x].  It seems to me two things need to be done 
> First, be able to assign variables so that they always stay real or else 
> indicate an error is occuring if they turn out to be complex, and second do 
> something to avoid errors like the above.  I have to say that I don't trust 
> Mathematica's answers as much as I did before this came up. Now I feel like 
> I better have a good idea of what the answer is before I  trust Mathematica.
> John Reed 

  • Prev by Date: Re: global fit
  • Next by Date: Re: FindRoot: Failed to converge to the requested accuracy - CORRECTION
  • Previous by thread: Re: Complex Oddity
  • Next by thread: Re: Complex Oddity