RE: Union & Select for removing duplicates in a list

• To: mathgroup at smc.vnet.net
• Subject: [mg47950] RE: [mg47933] Union & Select for removing duplicates in a list
• From: "DrBob" <drbob at bigfoot.com>
• Date: Sun, 2 May 2004 04:50:47 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```Select doesn't remove duplicates at all, except in the sense that all
duplicates of a number either satisfy the selection test (or don't) together
(depending on the test).

You used NotEqual (the opposite of Equal) to test whether Real numbers are
the same. Look up Equal to see what that means. When you say "what looked
like duplicates", you're probably talking about agreement to the six places
you see in a default display. If they differ in the seventh (or fifteenth)
place, they may or may not be equal (in the sense of Equal). It depends on
how much precision the numbers have.

Union, on the other hand, uses SameQ to test for sameness, and that's a much
stricter test. Hence, your numbers come out all "different". Use
Union[list,SameTest->Equal] to get what you probably want.

1.234567 == 1.23456700000001
1.234567 != 1.23456700000001
1.234567 == 1.2345670000001
1.234567 != 1.2345670000001
True
False
False
True

Union at {1.234567, 1.2345670000000000001}
{1.234567, 1.2345670000000000001}

Union at {1.234567,1.234567`50}
{1.234567,1.2345670000000000000000000000000000000000000000000}

Union[{1.234567, 1.234567`50.}, SameTest -> Equal]
{1.234567}

In the last two inputs, the two numbers are different only BEYOND the usual
machine precision.

(RealDigits[#1, 2] & ) /@
{1.234567, 1.234567`50.}
{{{1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0,
1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1,
1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,
0, 1, 1, 1}, 1},
{{1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0,
0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0,
1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0,
0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0,
1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1,
1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1,
0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1,
0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0,
0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0,
0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0,
0, 0, 1, 0, 0, 0}, 1}}

DrBob

www.eclecticdreams.net

-----Original Message-----
From: Blimbaum, Jerry AA R22 [mailto:jerry.blimbaum at navy.mil]
To: mathgroup at smc.vnet.net
Subject: [mg47950] [mg47933] Union & Select for removing duplicates in a list

I got list of numbers using FindRoot...which had duplicates...or, at
least, what looked like duplicates....I used Union to sort and ,
according to documentation, remove duplicates....but it didnt
work.....so list , after Union, looks like this for example....

{.0035, .0035, .005, .006...etc..}

I was actually building up {x,y} pairs from several  lists one entry of
which came up as {.0035, .0035} for example.....I then applied Select
...

Select[{x,y} pairs, #[[1]]NotEqual#[[2]]&]......and to my surprise this
worked, it removed {.0035, .0035}.....I assume that 'duplicate' for
Union and Select mean the same thing.....but then not according to the
actual operations.....

what am I missing?

thanks....jerry blimbaum

```

• Prev by Date: Re: bug in IntegerPart ?
• Next by Date: RE: on ColorFunction and combined images?
• Previous by thread: Re: Union & Select for removing duplicates in a list
• Next by thread: Numerically computing partial derivatives