Home > Archive > Mathematica > August 2006 > MemberQ
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Bruce Colletti 2006-08-08, 8:03 am |
| Re Mathematica 5.2.0.0.
Since 0.7 is in the set {0.0, 0.1, 0.2,..., 0.9, 1.0}, why does MemberQ[Range[0., 1., .1], .7] return False?
Thankx.
Bruce
| |
| Sseziwa Mukasa 2006-08-09, 4:06 am |
|
On Aug 8, 2006, at 6:28 AM, Bruce Colletti wrote:
> Re Mathematica 5.2.0.0.
>
> Since 0.7 is in the set {0.0, 0.1, 0.2,..., 0.9, 1.0}, why does
> MemberQ[Range[0., 1., .1], .7] return False?
It doesn't for me
In[25]:=
MemberQ[Range[0., 1., .1], .7]
Out[25]=
True
Regards,
Ssezi
| |
| Adriano Pascoletti 2006-08-09, 4:06 am |
| Bruce Colletti wrote ..
> Re Mathematica 5.2.0.0.
>
> Since 0.7 is in the set {0.0, 0.1, 0.2,..., 0.9, 1.0}, why does MemberQ[Range[0.,
> 1., .1], .7] return False?
>
> Thankx.
>
> Bruce
>
Because the 0.7 in Range[0.0, 1.0, 0.1] is
In[11]:=
Range[0.0,1.0,0.1][[8]]//FullForm
Out[11]//FullForm=
0.7000000000000001`
and
In[9]:=
FullForm[0.7]
Out[9]//FullForm=
0.7`
They differ on the 16th decimal place as can be seen evaluating
0.7 - Range[0.0, 1.0, 0.1]
Adriano Pascoletti
| |
| Murray Eisenberg 2006-08-09, 4:06 am |
| Roundoff error? Remember that decimals are converted to, and
manipulated arithmetically as binary, then converted back. Look at this:
$Version
5.2 for Microsoft Windows (June 20, 2005)
$MachinePrecision
15.9546
NumberForm[Range[0., 1., .1], 16]
{0.,0.1,0.2,0.3,0.4,0.5,0.6000000000000001,0.7000000000000001,0.8,0.9,1.}
NumberForm[.7, 16]
0.7
Bruce Colletti wrote:
> Re Mathematica 5.2.0.0.
>
> Since 0.7 is in the set {0.0, 0.1, 0.2,..., 0.9, 1.0}, why does MemberQ[Range[0., 1., .1], .7] return False?
--
Murray Eisenberg murray@math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305
| |
| Peter Pein 2006-08-09, 4:06 am |
| Bruce Colletti schrieb:
> Re Mathematica 5.2.0.0.
>
> Since 0.7 is in the set {0.0, 0.1, 0.2,..., 0.9, 1.0}, why does MemberQ[Range[0., 1., .1], .7] return False?
>
> Thankx.
>
> Bruce
>
It returns False, because 0.7 is definitely _not_ a member of
In[1]:= Range[0.,1.,.1]//InputForm
Out[1]//InputForm=
{0., 0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6000000000000001,
0.7000000000000001, 0.8, 0.9, 1.}
Don't expect exact results, when using inexact numbers.
MemberQ[lst,elm] looks for exactly the same as elm in lst. You can write
your own MemberQ using == instead of ===, because Equal[] considers
"very similar" reals to be equal:
In[2]:= sloppyMemberQ = Cases[#1, x_ /; x == #2, 1, 1] =!= {} & ;
In[3]:= sloppyMemberQ[Range[0., 1., 0.1], 0.7]
Out[3]= True
Peter
| |
| Erickson Paul-CPTP18 2006-08-09, 4:06 am |
| Bruce,
In[2]:=
Range[0., 1., .1][[8]] - .7
Out[2]=
1.1102230246251565x10^-16
Looks like ye old precision problem of accumulated error. That is 7
increments of 0.1 as a real machine precision number is not equal to
0.7.
One of probably many ways around this would be to wrap Range with a
rounding function like Rationalize and then convert each element
separately back to machine precision:
In[9]:=
MemberQ[ N[ Rationalize[ Range[0., 1., .1] ] ], .7]
Out[9]=
True
Another is of course to normalize to integers so as to avoid the problem
in the first place.
Paul
-----Original Message-----
From: Bruce Colletti [mailto:vze269bv@verizon.net]
Subject: MemberQ
Re Mathematica 5.2.0.0.
Since 0.7 is in the set {0.0, 0.1, 0.2,..., 0.9, 1.0}, why does
MemberQ[Range[0., 1., .1], .7] return False?
Thankx.
Bruce
| |
| Norbert Marxer 2006-08-09, 4:06 am |
| Hello
As you can see if you output your list in InputForm
InputForm@Range[0., 1., .1]
Out[61]//InputForm=
{0., 0.1, 0.2, 0.30000000000000004, 0.4, 0.5,
0.6000000000000001, 0.7000000000000001, 0.8, 0.9, 1.}
the specific element does not correspond exactly to 0.7 and therefore
MemberQ returns False. This has to do with the precision of real
numbers.
Nevertheless there are some possibilities to perform your test. Here
are some of them:
Use Integers:
MemberQ[Range[0, 10, 1]/10, 7/10]
Convert to Integers
MemberQ[Round /@ (10 Range[0., 1., .1]), 7]
Use Chop, Select and test for the Length:
Length@Select[Range[0., 1., .1], Chop[# - 0.7] == 0 &] = 0
Use the exact same real number (throughout your calculation):
r = Range[0., 1., .1];
MemberQ[r, r[[8]]]
Type in your array by hand (instead of using Range)
MemberQ[{0.1, 0.2, 0.7}, 0.7]
etc.
They all return True.
Best Regards
Norbert Marxer
www.mec.li
Bruce Colletti wrote:
> Re Mathematica 5.2.0.0.
>
> Since 0.7 is in the set {0.0, 0.1, 0.2,..., 0.9, 1.0}, why does MemberQ[Range[0., 1., .1], .7] return False?
>
> Thankx.
>
> Bruce
| |
|
| "Bruce Colletti" <vze269bv@verizon.net>
news:eb9pkt$t4j$1@smc.vnet.net...
> Re Mathematica 5.2.0.0.
>
> Since 0.7 is in the set {0.0, 0.1, 0.2,..., 0.9, 1.0}, why does
> MemberQ[Range[0., 1., .1], .7] return False?
>
> Thankx.
>
> Bruce
>
Hi Bruce,
you could have strange behaviors if you try to compare real numbers.
It could happen that on different systems that equality gives True.
I suggest you to use an alternative representation for Reals or to try to
use the operator ==
with commands such as Rationalize[], Round[], Chop [], N [], etc.
Using exact Rational numbers:
In[]:= i=Range[0, 1, 1/10];
In[]:= MemberQ[i, 7/10]
Out[]= True
HTH,
~Scout~
| |
| Bill Rowe 2006-08-09, 4:06 am |
| On 8/8/06 at 6:28 AM, vze269bv@verizon.net (Bruce Colletti) wrote:
>Re Mathematica 5.2.0.0.
>Since 0.7 is in the set {0.0, 0.1, 0.2,..., 0.9, 1.0}, why does
>MemberQ[Range[0., 1., .1], .7] return False?
It is due to using inexact numbers, i.e.
In[22]:=
RealDigits[Range[0.,1.,.1][[8]]]
Out[22]=
{{7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},0}
but
In[23]:=
RealDigits[.7]
Out[23]=
{{7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},0}
In[24]:=
$Version
Out[24]=
5.2 for Mac OS X (June 20, 2005)
--
To reply via email subtract one hundred and four
| |
| dimmechan@yahoo.com 2006-08-09, 4:06 am |
|
Ο/Η Bruce Colletti _γραψε:
> Re Mathematica 5.2.0.0.
>
> Since 0.7 is in the set {0.0, 0.1, 0.2,..., 0.9, 1.0}, why does MemberQ[Range[0., 1., .1], .7] return False?
>
> Thankx.
>
> Bruce
I face the same problem with you (both in version 5.1 and 5.2).
However, the strange thing is that using version 4.0 everything works
fine!!! I
ndeed,
In[1]:=
$Version
Out[2]=
"4.0 for Microsoft Windows (April 21, 1999)"
In[3]:=
lst=Range[0,1,0.1]
Out[3]=
{0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.}
In[4]:=
MemberQ[lst,0.7]
Out[4]=
True
In[5]:=
FreeQ[lst,0.7]
Out[5]=
False
Cheers,
Jim
| |
| Jean-Marc Gulliet 2006-08-09, 4:06 am |
| Bruce Colletti wrote:
> Re Mathematica 5.2.0.0.
>
> Since 0.7 is in the set {0.0, 0.1, 0.2,..., 0.9, 1.0},
The above is only true to one decimal place. I am sure what you have in
mind is 0.7 == 7/10; however this is not the case in computer sciences
because of the way numbers are coded at the hardware level.
0.7 is a machine-precision number so anything, for example, from 0.66 to
0.74 will do it.
> why does MemberQ[Range[0., 1., .1], .7] return False?
0.7 is a machine-precision number so anything, for example, from 0.66 to
0.74 will do it. Now MemberQ looks for strict equality since its a
pattern matching function.
What you must do is either using exact arithmetic
MemberQ[Range[0, 1, 1/10], 7/10]
--> True
or arbitrary precision
MemberQ[Range[0, 1.`20., 0.1`20.], 0.7`20.]
--> True
or machine precision but you must fix the precision anyway. Below, I
typed in MemberQ[Range[0.`2, 1.`2, .1`2], .7`2]: look how the number two
is represented in InputForm.
MemberQ[Range[0, 1.`1.9999999999999998, 0.1`1.9999999999999998],
0.7`1.9999999999999991]
--> True
Section 3.1.4 "Numerical Precision" of the Mathematica Book might be of
interest.
http://documents.wolfram.com/mathem...k/section-3.1.4
HTH,
Jean-Marc
| |
| David Park 2006-08-09, 4:06 am |
| Bruce,
Because...
set1 = Range[0.0, 1.0, 0.1]
% // InputForm
{0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.}
{0., 0.1, 0.2, 0.30000000000000004, 0.4, 0.5,
0.6000000000000001, 0.7000000000000001, 0.8, 0.9,
1.}
Try..
set2 = Table[x/10, {x, 0, 10}] // N
% // InputForm
{0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.}
{0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9,
1.}
MemberQ[set2, 0.7]
True
But in general you're going to get poor results testing set inclusion with
approximate numbers. You could use something like
Count[set1, x_ /; 0.699 < x < 0.701] > 0
True
David Park
djmp@earthlink.net
http://home.earthlink.net/~djmp/
From: Bruce Colletti [mailto:vze269bv@verizon.net]
Re Mathematica 5.2.0.0.
Since 0.7 is in the set {0.0, 0.1, 0.2,..., 0.9, 1.0}, why does
MemberQ[Range[0., 1., .1], .7] return False?
Thankx.
Bruce
| |
| Chris Chiasson 2006-08-09, 4:06 am |
| Even though the two entries are formatted as .7, the one generated by
the Range statement has already accumulated enough error to make it
fail MatchQ. You can see this with {Range[0., 1., .1], .7} // FullForm
On 8/8/06, Bruce Colletti <vze269bv@verizon.net> wrote:
> Re Mathematica 5.2.0.0.
>
> Since 0.7 is in the set {0.0, 0.1, 0.2,..., 0.9, 1.0}, why does MemberQ[Range[0., 1., .1], .7] return False?
>
> Thankx.
>
> Bruce
>
>
--
http://chris.chiasson.name/
| |
| gardyloo 2006-08-09, 4:06 am |
|
Hi, Bruce,
I suspect the same thing is happening here as in the documentation
for Position: the numbers are imprecise. It seems strange to me to do
this for MemberQ, but it works:
In[81]:=
MemberQ[Range[0, 1, 0.1],
_?(Inequality[0.69, Less, #1, LessEqual, 0.700001] & )]
Out[81]=
True
Hope that helps!
C.O.
Bruce Colletti wrote:
> Re Mathematica 5.2.0.0.
>
> Since 0.7 is in the set {0.0, 0.1, 0.2,..., 0.9, 1.0}, why does MemberQ[Range[0., 1., .1], .7] return False?
>
> Thankx.
>
> Bruce
>
>
>
--
========================================
==================
Curtis Osterhoudt
gardyloo@mail.remove_this.wsu.and_this.edu
PGP Key ID: 0x088E6D7A
Please avoid sending me Word or PowerPoint attachments
See http://www.gnu.org/philosophy/no-word-attachments.html
========================================
==================
| |
| Igor Antonio 2006-08-09, 4:06 am |
| Bruce Colletti wrote:
> Re Mathematica 5.2.0.0.
>
> Since 0.7 is in the set {0.0, 0.1, 0.2,..., 0.9, 1.0}, why does MemberQ[Range[0., 1., .1], .7] return False?
>
> Thankx.
>
> Bruce
I don't know what function MemberQ uses to identify if something is part
of the list, but it seems to be related to the precision of the 0.7:
In[8]:=
MemberQ[Range[0., 1.0, 0.1], 0.7]
Out[8]=
False
In[9]:=
MemberQ[Range[0., 1.0, 0.1], 0.1]
Out[9]=
True
In[19]:= Range[0.0, 1.0, 0.1] // InputForm
Out[19]//InputForm=
{0., 0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6000000000000001,
0.7000000000000001, 0.8, 0.9, 1.}
Two alternatives:
1) use exact numbers
In[14]:=
MemberQ[Range[0, 1, 1/10], 7/10]
Out[14]=
True
2) Use a condition statement, which allows you to use the == function.
Note that even == will not work in some cases, however. It will depend
on the precision of the numbers involved.
In[29]:= MemberQ[Range[0., 1.0, 0.1], x_ /; x == 0.7]
Out[29]= True
Igor
--
Igor C. Antonio
Wolfram Research, Inc.
http://www.wolfram.com
To email me personally, remove the dash.
| |
| leigh pascoe 2006-08-09, 10:03 pm |
| Adriano Pascoletti wrote:
> Bruce Colletti wrote ..
>
>
> Because the 0.7 in Range[0.0, 1.0, 0.1] is
>
> In[11]:=
> Range[0.0,1.0,0.1][[8]]//FullForm
> Out[11]//FullForm=
> 0.7000000000000001`
>
> and
>
> In[9]:=
> FullForm[0.7]
> Out[9]//FullForm=
> 0.7`
>
> They differ on the 16th decimal place as can be seen evaluating
> 0.7 - Range[0.0, 1.0, 0.1]
>
>
>
> Adriano Pascoletti
>
>
>
>
So the curious thing is that it returns True for Ssezi and for me!
In[8]:=Range[0.,1.,.1][[8]]//FullForm
MemberQ[Range[0.,1.,.1],.7]
Out[8]//FullForm=0.7000000000000001`
Out[9]=True
LP
| |
| Erickson Paul-CPTP18 2006-08-11, 4:08 am |
| Only curious if for you
..7//FullForm
doesn't return 0.7000000000000001`
-----Original Message-----
From: leigh pascoe [mailto:leigh@cephb.fr]
Subject: Re: MemberQ
Adriano Pascoletti wrote:
> Bruce Colletti wrote ..
>
>
> Because the 0.7 in Range[0.0, 1.0, 0.1] is
>
> In[11]:=
> Range[0.0,1.0,0.1][[8]]//FullForm
> Out[11]//FullForm=
> 0.7000000000000001`
>
> and
>
> In[9]:=
> FullForm[0.7]
> Out[9]//FullForm=
> 0.7`
>
> They differ on the 16th decimal place as can be seen evaluating
> 0.7 - Range[0.0, 1.0, 0.1]
>
>
>
> Adriano Pascoletti
>
>
>
>
So the curious thing is that it returns True for Ssezi and for me!
In[8]:=Range[0.,1.,.1][[8]]//FullForm
MemberQ[Range[0.,1.,.1],.7]
Out[8]//FullForm=0.7000000000000001`
Out[9]=True
LP
| |
| leigh pascoe 2006-08-13, 4:08 am |
| Erickson Paul-CPTP18 wrote:
> Only curious if for you
> .7//FullForm
> doesn't return 0.7000000000000001`
>
> -----Original Message-----
> From: leigh pascoe [mailto:leigh@cephb.fr]
> Subject: Re: MemberQ
>
> Adriano Pascoletti wrote:
>
> So the curious thing is that it returns True for Ssezi and for me!
>
> In[8]:=Range[0.,1.,.1][[8]]//FullForm
> MemberQ[Range[0.,1.,.1],.7]
>
> Out[8]//FullForm=0.7000000000000001`
>
> Out[9]=True
>
> LP
>
>
>
>
>
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
It seems to me that a better behavior would be an error message: "Exact
numbers and fixed precision numbers cannot be compared with MemberQ" or
perhaps just "False".
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?? 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
LP
| |
| Peter Pein 2006-08-14, 8:03 am |
| 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_Berl...berQ/NMemberQ.m
and
http://people.freenet.de/Peter_Berl...erQ/NMemberQ.nb
Feel free to add the function NMemberQ to your own collection of utilities.
Cheers,
Peter
| |
| dimmechan@yahoo.com 2006-08-14, 8:03 am |
| Hi leigh,
I am not a specialist, but everything seems ok to me
In[1]:=
$Version
Out[1]=
"4.0 for Microsoft Windows (April 21, 1999)"
In[2]:=
InputForm[lst=Range[0,1,1/10]]
Out[2]//InputForm=
{0, 1/10, 1/5, 3/10, 2/5, 1/2, 3/5, 7/10, 4/5, 9/10, 1}
In[3]:=
MemberQ[lst,2/10]//Trace//InputForm
Out[3]//InputForm=
{{HoldForm[lst], HoldForm[{0, 1/10, 1/5, 3/10, 2/5, 1/2, 3/5, 7/10,
4/5, 9/10, 1}]},
{{HoldForm[10^(-1)], HoldForm[1/10]}, HoldForm[2/10], HoldForm[1/5]},
HoldForm[MemberQ[{0, 1/10, 1/5, 3/10, 2/5, 1/2, 3/5, 7/10, 4/5, 9/10,
1}, 1/5]], HoldForm[True]}
In[4]:=
MemberQ[lst,HoldForm[2/10]]//Trace//InputForm
Out[4]//InputForm=
{{HoldForm[lst], HoldForm[{0, 1/10, 1/5, 3/10, 2/5, 1/2, 3/5, 7/10,
4/5, 9/10, 1}]},
HoldForm[MemberQ[{0, 1/10, 1/5, 3/10, 2/5, 1/2, 3/5, 7/10, 4/5, 9/10,
1}, HoldForm[2/10]]], HoldForm[False]}
Cheers
Jim
| |
| leigh pascoe 2006-08-16, 4:07 am |
| Peter Pein wrote:
> leigh pascoe schrieb:
> ...
>
>
> Mathematica automagically cancels 2/10.
>
>
>
> 1/2 has head Rational, 0.5 has got head _Real. So they must not be the same.
>
>
>
> I wrote a (very) small package:
>
> http://people.freenet.de/Peter_Berl...berQ/NMemberQ.m
> and
> http://people.freenet.de/Peter_Berl...erQ/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
| |
| Erickson Paul-CPTP18 2006-08-17, 4:03 am |
| Do you find that any stranger than the following?
In[7]:=
2 == 2.00000000000000000001
Out[7]=
True
If you don't want Mathematica to make assumptions on your behalf, then
you have to tell it exactly what you do want, as in:
In[9]:=
2 == 2.00000000000000000001``50
Out[9]=
False (* as in the exact number 2 isn't equal to the very accurate
number close to 2 *)
In[12]:=
2. == 2.00000000000000000001``50
Out[12]=
True (* But the real number 2. with limited accuracy is close enough to
the very accurate number close to 2 *)
In[13]:=
2``50 == 2.00000000000000000001``50 (* where two very accurate close
number aren't equal *)
Out[13]=
False
In[10]:=
2 // FullForm
Out[10]//FullForm=
2
In[11]:=
2.00000000000000000001``50// FullForm
Out[11]//FullForm=
2.00000000000000000001`50.30102999566398
So in general, it appears that Mathematica tries to call two numbers
equal if they are close compared the accuracy of the less accurate
number. Some of the postings would indicate that Mathematica doesn't
always succeed in this wrt MemberQ and it would appear that it may be
machine dependant. Still seems best to just avoid the problem or deal
explicitly with it.
As to an earlier question about 2/10 vs 1/5, I think Mathematica is
don't exactly what it says it should in that it simplifies the rational
2/10 to 1/5 as the two rational fraction are equivalent. This is
illustrated by:
In[15]:=
2/10 === 1/5
Out[15]=
True
In[16]:=
2/10 //FullForm
Out[16]//FullForm=
Rational[1,5]
Now it's reasonable that someone may want a set of rationals with a
common denominator (perhaps because it is easier to look at, perhaps
other reasons), but it would seem that this operation is appropriate
most of the time and the burden of extra effort in the other cases is
acceptable.
Paul
-----Original Message-----
From: leigh pascoe [mailto:leigh@cephb.fr]
Subject: Re: MemberQ
Peter Pein wrote:
> leigh pascoe schrieb:
> ...
>
behavior?[color=darkred]
>
> Mathematica automagically cancels 2/10.
>
>
>
> 1/2 has head Rational, 0.5 has got head _Real. So they must not be the
same.
>
>
>
> I wrote a (very) small package:
>
> http://people.freenet.de/Peter_Berl...berQ/NMemberQ.m
> and
> http://people.freenet.de/Peter_Berl...erQ/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
|
|
|
|
|