Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: Cases

  • To: mathgroup at smc.vnet.net
  • Subject: [mg50442] Re: [mg50423] Cases
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Sat, 4 Sep 2004 01:43:18 -0400 (EDT)
  • References: <200409030735.DAA15539@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

*This message was transferred with a trial version of CommuniGate(tm) Pro*
On 3 Sep 2004, at 16:35, Blimbaum, Jerry AA R22 wrote:

> *This message was transferred with a trial version of CommuniGate(tm) 
> Pro*
>
> Given:   x = {a,b,c,d,d};
>
> Applying   Cases[x,d]   gives an output of {a,b,c}......
>
> However, Cases[x,Not[d]] gives as output an empty list  { }... I
> expected   {a,b,c}.....
>
> Why didnt I get that?
>
> This issue came up when using Thread on vectors...and in some cases the
> Thread resulted in 0 == 0  so it's output in the list  was
> True....and I
> wanted to remove them....
>
> thanks.....jerry blimbaum
>
>
This is because Not[d] is not a pattern matched by something that is 
not d. There are several  ways to construct what is effectively such a 
pattern, e.g.


Cases[x,_?(#=!=d&)]

{a,b,c}


Cases[x,_?(Not[MatchQ[#,d]]&)]

{a,b,c}

but I don't think there is any way that does not use PatternTest. That 
means that  this is a situation you can make your program simpler if 
you use Select, e.g.


Select[x,#=!=d&]


{a,b,c}


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


  • References:
    • Cases
      • From: "Blimbaum, Jerry AA R22" <jerry.blimbaum@navy.mil>
  • Prev by Date: Re: ExpandAll Problem with Rules
  • Next by Date: Re : definite and indefinite Integrate
  • Previous by thread: Cases
  • Next by thread: Re: Cases