Re: And and Not for patterns
- To: mathgroup at smc.vnet.net
- Subject: [mg35990] Re: [mg35965] And and Not for patterns
- From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
- Date: Sun, 11 Aug 2002 05:13:50 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
No there isn't one. In fact the only sensible cases in which you might wish to use a "And" for patterns seem to be the cases where either all patterns arise from pure functions by means of _? (PatternTest) or where at most one pattern does not arise in that way. In the first case it is clearly simpler to use ordinary && as in: In[13]:= Cases[Range[10], _?(PrimeQ[#1] && #1 > 3 & )] Out[13]= {5, 7} the other case is when you mix a true pattern and a pattern test. e.g: IIn[14]:= Cases[{0,1,1.5,2},_Integer?(#>1&)] Out[14]= {2} I can't think of any way you could try to combine two patterns that do not arise from pure functions, so I don't think such an "And" would be very useful. A "Not" for patterns might be perhaps somewhat useful, but it can always be constructed by means of the MatchQ predicate: In[15]:= Cases[{0,1,1.5,2},_?(!MatchQ[#,_Integer]&)] Out[15]= {1.5} On Saturday, August 10, 2002, at 05:05 AM, Julio Vera wrote: > > Dear members, > > There is an equivalent of Or (||) to be used with patterns: Alternative > (|). I couldn't find an equivalent for And (&&) and Not (!). I don't > know if they don't exist, or it is just that I can`t find them. > > Thanks for your help, > > Julio > > > Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/