Re: Is it a bug?
- To: mathgroup at smc.vnet.net
- Subject: [mg17570] Re: Is it a bug?
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Mon, 17 May 1999 02:14:25 -0400
- References: <7hgdfs$4bu@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
F. Mittermayr <mitterma at linz.vai.co.at> wrote in message news:7hgdfs$4bu at smc.vnet.net... > A = {1 + Sqrt[2] I , 1 + 2 * 3 I}; > Cases[A, _Complex] > > Out[1] = {1+6 I} > > Isn't it a strange result? > A = {1 + Sqrt[2] I , 1 + 2 * 3 I}; The reason is that Cases is lookin for members of the list that are of the *form* Complex[ x, y] (*check its FullForm*) but 1 + Sqrt[2] I is of the form 1 + Sqrt[2] Complex[0,1] To get the kind of behaviour that you are seeking we can use expressions like Cases[A, x_/;Not[FreeQ[x,Complex]]] {1 + I*Sqrt[2], 1 + 6*I} Cases[A, x_/;Not[Chop[FreeQ[x,Complex]]]] {1 + I*Sqrt[2], 1 + 6*I} (the Chop is to get rid of accidental small maginary numbers) Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565