MathGroup Archive 1996

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

Search the Archive

Re: Not[OddQ] is not the same as EvenQ (sometimes)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg3911] Re: Not[OddQ] is not the same as EvenQ (sometimes)
  • From: roth at sunny.mpimf-heidelberg.mpg.de (Arnd Roth)
  • Date: Sun, 5 May 1996 23:13:04 -0400
  • Organization: Max-Planck-Institut fuer Medizinische Forschung
  • Sender: owner-wri-mathgroup at wolfram.com

In article <4m1hq2$pq4 at dragonfly.wolfram.com>
"Arnold Seiken" <SEIKENA at gar.union.edu> writes:

> Position[{2,3,4,5,6,7}, x_?(EvenQ[#]&)]
> {{1}, {3}, {5}}
> Position[{2,3,4,5,6,7}, x_?(!OddQ[#]&)]
> {{0}, {1}, {3}, {5}}
> Therefore, for this example, the pattern x_?(EvenQ[#]&) is not equivalent to
> the pattern x_?(!OddQ[#]&). The latter matches with the head List of {2,3,4,5,6,7}, the former does not. But
> Position[{-2,3,4,-5,6,7}, x_?(NonNegative[#]&)]
> {{2}, {3}, {5}, {6}}
> Position[{-2,3,4,-5,6,7}, x_?(!Negative[#]&)]
> {{2}, {3}, {5}, {6}}
> shows that the Head List is sometimes ignored by Position. Finally
> Position[{1,3,5}, x_?(!OddQ[#]&)]
> {{0}}
> Position[{2,3,4,5,6,7}, x_?(!NumberQ[#]&)]
> {{0}, {}}
> Position[{2,3,4,5,6,7}, x_?(!Positive[#]&)]
> {}
> seems to show that there are really three possible outcomes  when using Not in a pattern involving the Position command. This does not occur for either the Count or Cases command where you get what you expect to get. 
> 
> Count[{1,3,5,7}, x_?(EvenQ[#]&)]
> 0
> Count[{1,3,5,7}, x_?(!OddQ[#]&)]
> 0
> Any explanations?

The differences can be easily explained by noting that

In[1]:= Options[Position]
Out[1]= {Heads -> True}

In[2]:= Options[Count]
Out[2]= {Heads -> False}

and

In[3]:= Attributes[NumberQ]
Out[3]= {Protected}

In[4]:= Attributes[Positive]
Out[4]= {Listable, Protected}

and the the fact that EvenQ[] and NonNegativeQ[] also
behave differently on the Head List:

In[5]:= EvenQ[List]
Out[5]= False

In[6]:= NonNegative[List]
Out[6]= NonNegative[List]

(Negative and NonNegative are also Listable.)
Try wrapping your inputs in Trace[] to see what
happens depending on the Option for Position. I'm
reluctant to put the Trace output here because it
is a bit long.


Sincerely,

Arnd Roth
Abteilung Zellphysiologie
Max-Planck-Insitut fuer Medizinische Forschung
Postfach 10 38 20, D-69028 Heidelberg, Germany
http://sunny.mpimf-heidelberg.mpg.de/people/roth/ArndRoth.html

==== [MESSAGE SEPARATOR] ====


  • Prev by Date: An "Assume" type command
  • Next by Date: Re: Tick marks and labels
  • Previous by thread: Re: Not[OddQ] is not the same as EvenQ (sometimes)
  • Next by thread: Re: Not[OddQ] is not the same as EvenQ (sometimes)