Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1999
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*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 smc.vnet.net
  • Subject: [mg16125] Re: [mg16016] Q: Union and SameTest Option
  • From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
  • Date: Sat, 27 Feb 1999 03:23:01 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

I think you have discovered a curious bug. Look at the following two examples:

In[94]:=
Union[{{x,b},{y,a},{z,b}},SameTest->(#1[[2]]===#2[[2]]&)]
Out[94]=
{{x,b},{y,a},{z,b}}

In[95]:=
Union[{{x,b},{z,a},{y,b}},SameTest->(#1[[2]]===#2[[2]]&)]
Out[95]=
{{x,b},{z,a}}

What seems to happen is that when comparing various pairs (to check if
they should be considered the same) Mathematica sorts the pairs  and the
result you get depends on the ordering of the pairs. Changing the
ordering gives a differnt result.  It seems that this does not happen if
the comparison is based only on the first elements. So one way to avoid
this problem is this first arrange your lists so that the elements on
which  SameTest is based come first. Then apply Union and then again
rearrange them. Here is what happens in your case:

In[96]:=
Map[Reverse,Union[ Map[Reverse,{{a,b,1},{a,c,1},{x,y,2},{a,b,2}}],
       SameTest->(#1[[1]]===#2[[1]]&) ]]
Out[96]=
{{a,b,1},{a,b,2}}


On Sat, Feb 20, 1999, Clemens Frey <btml01 at uni-bayreuth.de> wrote:

>Hi Mathematica-Groupers!
>
>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}} 
>
>Thanks in advance
>Clemens
>
>------------------------------------------------------------
>Clemens Frey
>Doctoral Student at the 
>Department of Mathematics/BITOEK
>University of Bayreuth(Germany)
>
>clemens.frey at uni-bayreuth.de
>http://www.bitoek.uni-bayreuth.de/~Clemens.Frey
>------------------------------------------------------------
>


Andrzej Kozlowski
Toyama International University
JAPAN
http://sigma.tuins.ac.jp/
http://eri2.tuins.ac.jp/

Andrzej Kozlowski
Toyama International University
JAPAN
http://sigma.tuins.ac.jp/
http://eri2.tuins.ac.jp/



  • Prev by Date: Re: "Display", "ESP" and "MathLink"
  • Next by Date: Re: Q: Union and SameTest Option
  • Previous by thread: Re: Q: Union and SameTest Option
  • Next by thread: Re: Q: Union and SameTest Option