MathGroup Archive 1999

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

Search the Archive

Re: Is it a bug?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg17578] Re: [mg17548] Is it a bug?
  • From: "Tomas Garza" <tgarza at mail.internet.com.mx>
  • Date: Mon, 17 May 1999 02:14:29 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

F. Mittermayr [mitterma at linz.vai.co.at] wrote:

> A = {1 + Sqrt[2] I , 1 + 2 * 3 I};
> Cases[A, _Complex]
>
> Out[1] = {1+6 I}
>
> Isn't it a strange result?

It does look strange, indeed, but it so happens that although Sqrt[2] is
numeric, it is not a number (in Mathematica). Cf. The Book (2.3.5):

NumberQ[expr] returns False unless expr is manifestly a number (i.e., has
head Complex, Integer, Rational or Real). But, you see,


In[1]:=
Head[Sqrt[2]]
Out[1]=
Power

Hence it is not a number, i.e.

In[2]:=
NumberQ[Sqrt[2]]
Out[2]=
False

Then 1 + Sqrt[2] I is "not" a number, let alone a complex number. But...
Sqrt[2.] "is" a number, since

In[3]:=
Head[Sqrt[2.] ]
Out[3]=
Real

and so

In[4]:=
NumberQ[1+Sqrt[2.] I]
Out[4]=
True

Then

In[5]:=
Cases[A, _Complex]
Out[5]=
{1+1.41421 I,1+6 I}

as you would have expected, where 1.41421 is to be understood as an
approximation to Sqrt[2].

Good luck,

Tomas Garza
Mexico City



  • Prev by Date: Re: Is it a bug?
  • Next by Date: Re: Directed, Labeled Graphs
  • Previous by thread: Re: Is it a bug?
  • Next by thread: Re: Is it a bug?