MathGroup Archive 2003

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

Search the Archive

Re: Extracting Terms From a List


On Saturday, October 25, 2003, at 07:26 PM, Bruce W. Colletti wrote:

>
> How would I cull integers and squared terms from {3, Sqrt[2], (x+y)^2, 
> x+y^2}?   The desired output is {3, (x+y)^2, y^2}.  Unfortunately:
>
> Cases[{3, Sqrt[2], (x+y)^2, x+y^2}, _Integer | _^2]
>
> returns {3, (x+y)^2} .
>
> Thankx.
>
> Bruce
>
>
>

Probably you either have to use a rather elaborate pattern or apply 
Cases twice:



Join[Cases[{3, Sqrt[2], (x + y)^2, x + y^2}, _Integer],
   Cases[{3, Sqrt[2], (x + y)^2, x + y^2}, _^2, {1, 2}]]


{3, (x + y)^2, y^2}


Andrzej Kozlowski
Yokohama, Japan
http://www.mimuw.edu.pl/~akoz/


  • Prev by Date: Re: imposing parameter assumptions
  • Next by Date: Re: Extracting Terms From a List
  • Previous by thread: Extracting Terms From a List
  • Next by thread: Re: Extracting Terms From a List