Re: Union - simple question

• To: mathgroup at smc.vnet.net
• Subject: [mg49086] Re: Union - simple question
• From: ab_def at prontomail.com (Maxim)
• Date: Wed, 30 Jun 2004 05:34:31 -0400 (EDT)
• References: <cbol4e\$4e0\$1@smc.vnet.net> <cbrcmd\$is6\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```koopman at sfu.ca (Ray Koopman) wrote in message news:<cbrcmd\$is6\$1 at smc.vnet.net>...

> It looks like Union first sorts the list, and then uses SameTest only to
> check adjacent elements (which it passes to SameTest in reverse order!).

That was how Union used to work in earlier versions, but not anymore:

In[1]:=
Union[{a, c, b, a}, SameTest -> ((Print[{##}]; False) &)]

{a, a}
{b, a}
{b, a}
{c, b}
{c, a}
{c, a}

Out[1]=
{a, a, b, c}

Online documentation (
http://support.wolfram.com/mathematica/kernel/Symbols/System/Union.html
) still says that only adjacent elements are compared, but that's not
true about Mathematica 5.0: as we can see, now Union honestly performs
n(n-1)/2 comparisons.

Another point is that SameTest->Automatic is something rather obscure,
it is not the same as SameTest->SameQ or SameTest->Equal:

In[2]:=
Union[{1`20, 1`30}]
Union[{1`20, 1`30}, SameTest -> SameQ]

Out[2]=
{1.0000000000000000000, 1.00000000000000000000000000000}

Out[3]=
{1.0000000000000000000}

Definitely there are grounds for confusion.

Maxim Rytin
m.r at inbox.ru

```

• Prev by Date: Re: extracting powers and coefficients from a polynomial
• Next by Date: converting table output and plotting
• Previous by thread: Re: Union - simple question
• Next by thread: Trigonometric simplification - newbe question