MathGroup Archive 1999

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

Search the Archive

Re: Re: Is it a bug?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg17621] Re: [mg17590] Re: [mg17548] Is it a bug?
  • From: "Andrzej Kozlowski" <andrzej at tuins.ac.jp>
  • Date: Tue, 18 May 1999 02:45:21 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

First, I think I should apologze for my first answer to this question which
accidently came out sounding rather rude. In fact I did not notice the "I"
in 1+Sqrt[2] I  and since I thought it was simply 1+Sqrt[2] I really could
not see the point of the question (except perhaps the rather obvious one why
real numbers are not considered complex etc). Actually the question was very
sensible and fortunately various people have given more helpful answerst
than mine. In fact I myself  also used to find  Mathematica's using very
different FullForms for a+b*I (a+b*Complex[0,1]) when a and b are symbols
(including Numeric ones)   and when they are numbers e.g.  2+3*I
(Complex[2,3]) a very confusing matter, particulalry when trying to use
pattern matching. I eventually concluded that it is a good idea to avoid
when one can using patterns of the form a_+b_*I or Complex[a_,b_] and try to
use the functions Re and Im instead. Although good solutions to the problem
posed in this question have already been given (particularly by Allan Hayes)
I would like to suggest ones based on this idea (using Re and Im). In this
particular case the following approach is sufficient:

In[24]:=
Cases[{3,1+Sqrt[2]*I,2+3*I},_?(Im[#]!=0&)]
Out[24]=
{1 + I Sqrt[2], 2 + 3 I}

If one wants also to include symbolic expressions like a+b*I one can use:

In[25]:=
Cases[{d,1+Sqrt[2]*I,2+3I,b+3*I},_?(ComplexExpand[Im[#]]!=0&)]
Out[25]=
{1 + I Sqrt[2], 2 + 3 I, 3 I + b}


Clearly Allan Hayes' method also deals with all these cases. Here is one
where it does not work well:

In[26]:=
Cases[{Sqrt[2]*I,2+3I,b+3*I,I^I}, x_/;Not[Chop[FreeQ[x,Complex]]]]
Out[26]=
                               I
{I Sqrt[2], 2 + 3 I, 3 I + b, I }

but

In[27]:=
Cases[{1+Sqrt[2]*I,2+3I,b+3*I,I^I},_?(ComplexExpand[Im[#]]!=0&)]
Out[27]=
{1 + I Sqrt[2], 2 + 3 I, 3 I + b}

As everyone has known since Euler, I^I is just E^(-Pi/2), a real number!

In[28]:=
N[E^(-Pi/2)]==N[I^I]
Out[28]=
True


Andrzej Kozlowski
Toyama International University
JAPAN
http://sigma.tuins.ac.jp
http://eri2.tuins.ac.jp


----------
>From: "Andrzej Kozlowski" <andrzej at tuins.ac.jp>
To: mathgroup at smc.vnet.net
>To: mathgroup at smc.vnet.net
>Subject: [mg17621] [mg17590] Re: [mg17548] Is it a bug?
>Date: Mon, May 17, 1999, 3:14 PM
>

> What do you think the correct result should be?
> --
> Andrzej Kozlowski
> Toyama International University
> JAPAN
> http://sigma.tuins.ac.jp
> http://eri2.tuins.ac.jp
>
>
> ----------
>>From: "F. Mittermayr" <mitterma at linz.vai.co.at>
To: mathgroup at smc.vnet.net
> To: mathgroup at smc.vnet.net
>>To: mathgroup at smc.vnet.net
>>Subject: [mg17621] [mg17590] [mg17548] Is it a bug?
>>Date: Fri, May 14, 1999, 2:13 PM
>>
>
>> A = {1 + Sqrt[2] I , 1 + 2 * 3 I};
>> Cases[A, _Complex]
>>
>> Out[1] = {1+6 I}
>>
>> Isn't it a strange result?
>>
>>
>>
>> 


  • Prev by Date: RE: Re: Insertion Point Bug
  • Next by Date: RE: Re: Function evaluation
  • Previous by thread: Re: Is it a bug?
  • Next by thread: Re: Is it a bug?