MathGroup Archive 2006

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

Search the Archive

Re: MemberQ


leigh pascoe schrieb:
...
> While we are talking about MemberQ, what about the following behavior?
> In[15]:=Range[0,1,1/10]
>              MemberQ[Range[0,1,1/10],2/10]
> 
> Out[15]=\!\({0, 1\/10, 1\/5, 3\/10, 2\/5, 1\/2, 3\/5, 7\/10, 4\/5, 
> 9\/10, 1}\)
> 
> Out[16]=True
> 
> Is the above result correct given that 2/10 doesn't appear in the list 
> produced by the range statement??

Mathematica automagically cancels 2/10.

> On the other hand 0.5 can be
> represented exactly as a binary number, but
> In[29]:=MemberQ[Range[0,1,1/10],.5]
> 
> Out[29]=False
> 

1/2 has head Rational, 0.5 has got head _Real. So they must not be the same.

> LP
> 

I wrote a (very) small package:

http://people.freenet.de/Peter_Berlin/Mathe/NMemberQ/NMemberQ.m
and
http://people.freenet.de/Peter_Berlin/Mathe/NMemberQ/NMemberQ.nb

Feel free to add the function NMemberQ to your own collection of utilities.

Cheers,
   Peter


  • Prev by Date: Re: ContourPlot and finite approximation to level sets
  • Next by Date: Re: Solving integrals
  • Previous by thread: Re: MemberQ
  • Next by thread: Re: Re: MemberQ