Re: Re: MemberQ

*To*: mathgroup at smc.vnet.net*Subject*: [mg68677] Re: [mg68655] Re: MemberQ*From*: leigh pascoe <leigh at cephb.fr>*Date*: Wed, 16 Aug 2006 03:36:06 -0400 (EDT)*References*: <0533005404FE2E45B90AF737DE5A991A015312F3@de01exm67.ds.mot.com> <ebmt7i$6cj$1@smc.vnet.net> <200608141044.GAA25407@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Peter Pein wrote: > 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 > > > > Dear Peter, Thanks for your reply. Bruce Colletti was the original poster of this topic and will probably be interested in your function NMemberQ[]. As others have pointed out the use of MemberQ to compare fixed precision (Real) and Rational numbers produces unpredictable (machine and version dependent) results. My main point was that any such comparison should produce an error or warning that the comparison is not reliable, rather than True or False. It still strikes me as strange that In[8]:=.7//FullForm Range[0.,1.,.1][[8]]//FullForm MemberQ[Range[0.,1.,.1],.7] Out[8]//FullForm=0.7` Out[9]//FullForm=0.7000000000000001` Out[10]=True returns True for two numbers that Ma tells me are different. Leigh

**References**:**Re: MemberQ***From:*Peter Pein <petsie@dordos.net>