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 1999

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

Search the Archive

Re: Q: Union and SameTest Option

  • To: mathgroup at
  • Subject: [mg16141] Re: [mg16016] Q: Union and SameTest Option
  • From: "Tomas Garza" <tgarza at>
  • Date: Sat, 27 Feb 1999 03:23:09 -0500
  • Sender: owner-wri-mathgroup at

Clemens Frey wrote:

> Can anybody explain to me what's going on here ?
> In[270]:=
> Union[ {{a,b,1},{a,c,1},{x,y,2},{a,b,2}},
>        SameTest->(#1[[2]]===#2[[2]]&) ]
> Out[270]=
> {{a,b,1},{a,c,1},{x,y,2}}
> is ok since the first and the last list element have the same second
> component. But what is wrong here now ?
> In[272]:=
> Union[ {{a,b,1},{a,c,1},{x,y,2},{a,b,2}},
>        SameTest->(#1[[3]]===#2[[3]]&) ]
> Out[272]=
> {{a,b,1},{a,b,2},{a,c,1},{x,y,2}}


Most intriguing, and I would venture that there is a bug somewhere. In fact,
if you split your original list into two parts, perform the Union operation
on each of them, and finally perform a Union on the two results, you get the
right answer:

Union[Union[ {{a,b,1},{a,c,1}},SameTest->(#1[[3]]===#2[[3]]&)],
  Union[ {{x,y,2},{a,b,2}},SameTest->(#1[[3]]===#2[[3]]&)]]

Tomas Garza
Mexico City

  • Prev by Date: Re: Q: Union and SameTest Option
  • Next by Date: Re: Re: Re: Re: Bug?
  • Previous by thread: Re: Q: Union and SameTest Option
  • Next by thread: Strange results from Integrate