Re: Is it a bug?
- To: mathgroup at smc.vnet.net
- Subject: [mg17593] Re: [mg17548] Is it a bug?
- From: BobHanlon at aol.com
- Date: Mon, 17 May 1999 02:14:36 -0400
- Sender: owner-wri-mathgroup at wolfram.com
In a message dated 5/14/99 9:15:27 AM, mitterma at linz.vai.co.at writes:
>A = {1 + Sqrt[2] I , 1 + 2 * 3 I};
>Cases[A, _Complex]
>
>Out[1] = {1+6 I}
>
>Isn't it a strange result?
>
No, it is not a strange result. Merely, not what you expected.
A = {1 + Sqrt[2] I , 1 + 2 * 3 I};
FullForm[A]
List[Plus[1,Times[Complex[0,1],Power[2,Rational[1,2]]]],Complex[1,6]]
Note that the head of the first term is not Complex; consequently, asking for
terms whose Head is Complex will not do what you want.
Cases[A, _Complex]
{1 + 6*I}
Nor would this test work:
Cases[A, a_ + I*b_]
{1 + I*Sqrt[2]}
The test for which you are apparently looking would be
Cases[A, _?(!FreeQ[#, Complex]&)]
{1 + I*Sqrt[2], 1 + 6*I}
Bob Hanlon