Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1996
*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 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: [mg3899] Re: Not[OddQ] is not the same as EvenQ (sometimes)
  • From: wagner at motel6.cs.colorado.edu (Dave Wagner)
  • Date: Sat, 4 May 1996 23:24:13 -0400
  • Organization: University of Colorado, Boulder
  • Sender: owner-wri-mathgroup at wolfram.com

In article <4m1hq2$pq4 at dragonfly.wolfram.com>,
Arnold Seiken <SEIKENA at gar.union.edu> wrote:
>Dear Mathematica experts,
>
>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.

That's because if a is a symbol without any numeric values (e.g., a = List),
OddQ[a] == EvenQ[a] == False.

> 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.

Wrong explanation.  Negative[List] returns Negative[List].  Therefore
Not[Negative[List]] is not equal to True, so Position does not return {0}.

The general rule is that functions ending with "Q" always return either
True or False (there are some exceptions, such as LegendreQ, which is not
a predicate); functions that do not end with "Q" may return unevaluated.
You can force any function that doesn't return an explicit False to do
so by wrapping TrueQ around it.

    NegativeQ[x_] := TrueQ[Negative[x]]

The fact that Negative, Positive, etc. don't do quite what you expect
is understandably annoying.

> Finally
>Position[{1,3,5}, x_?(!OddQ[#]&)]
>{{0}}

Consistent with above explanation.

>Position[{2,3,4,5,6,7}, x_?(!NumberQ[#]&)]
>{{0}, {}}

{0} is consistent with above explanation.
I don't know the cause of the empty set of list braces here.
Try using Trace to see where they're coming from.

>Position[{2,3,4,5,6,7}, x_?(!Positive[#]&)]
>{}

Consistent with above explanation.

		Dave Wagner
		Principia Consulting
		(303) 786-8371
		dbwagner at princon.com
		http://www.princon.com/princon

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


  • Prev by Date: Re: What is the best General Mathematica Book?
  • Next by Date: Arc of ellipse
  • 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)