Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: Union - simple question

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

koopman at (Ray Koopman) wrote in message news:<cbrcmd$is6$1 at>...

> 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:

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

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

{a, a, b, c}

Online documentation (
) 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:

Union[{1`20, 1`30}]
Union[{1`20, 1`30}, SameTest -> SameQ]

{1.0000000000000000000, 1.00000000000000000000000000000}


Definitely there are grounds for confusion.

Maxim Rytin
m.r at

  • 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