MathGroup Archive 2002

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

Search the Archive

Re: Intersection[...,SameTest] ?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg33071] Re: Intersection[...,SameTest] ?
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Fri, 1 Mar 2002 06:51:17 -0500 (EST)
  • Organization: Universitaet Leipzig
  • References: <a5htcj$hsk$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

a) what is not clear in 
  
  "Intersection[list1,list2,..] gives a sorted 
   list of the elements common to all the listi."

> 1. It is not clear from the manual (book or help browser), what this command
> is supposed to return.

  from the manual I would assume a sorted list of the elements common to
all 
  arguments ?   


> 2. It simply does not work:
> 
> In[83]:=
> a={1,2,3,4};
> b={2,4,7,8};
> Intersection[a,b,SameTest->(#1==2*#2&)]

A intersection can't be unsymmetric and
Intersection[a,b]===Intersection[b,a]
and this is violated by your SameTest.

a = {1, 2, 3, 4};
b = {2, 4, 7, 8};
Intersection[2*a, b]/2

gives what you want as well as a symmetric test

a = {1, 2, 3, 4};
b = {2, 4, 7, 8};
Intersection[a, b, 
  SameTest -> ((If[#2 < #1, #1 === 2*#2, #2 === 2*#1]) &)]


> 
> Out[83]=
> {1}
> 
> or more sophisticated:
> 
> In[85]:=
> a={1,2,3,4};
> b={2,4,7,8};
> Intersection[a,b,SameTest->
>         ((Print[#1,"=?=",#2]||True)
>         &&#1==2*#2
>         &&(Print[True]||True)&)
> ]
> 
> 2 =?= 1
> True
> 3 =?= 1
> 4 =?= 3
> 2 =?= 1
> True
> 4 =?= 3
> 4 =?= 4
> 
> Out[85]=
> {1}
> 
> which does not seem to enumerate all pairs.

That's why it return a *sorted* list of the common elements.

> 
> What idea stands behind this function? what is supposed to do?

  "Intersection[list1,list2,..] gives a sorted 
   list of the elements common to all the listi."


Regards
  Jens


  • Prev by Date: Re: How to read in the output of another nb file?
  • Next by Date: Re: need a function for sums of subsets
  • Previous by thread: Re: Intersection[...,SameTest] ?
  • Next by thread: Re: Intersection[...,SameTest] ?