MathGroup Archive 1999

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

Search the Archive

Re: Q: Union and SameTest Option


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

Clemens,

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:

In[1]:=
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]]&)]]
Out[1]=
{{a,b,1},{a,b,2}}

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