       Re: Intersection[...,SameTest] ?

• To: mathgroup at smc.vnet.net
• Subject: [mg33076] Re: Intersection[...,SameTest] ?
• From: "Allan Hayes" <hay at haystack.demon.co.uk>
• Date: Fri, 1 Mar 2002 06:51:29 -0500 (EST)
• References: <a5htcj\$hsk\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Konstantin,

With
a = {1,3, 5, 0,0,8};
b = {7,6, 8, 0,0};

Default Intersection[a,b] gives a the list of elements which occur in both a
and b; no element is included twice; and the answer is sorted.

Intersection[a, b]

{0,8}

Intersection[a, b, SameTest -> (#1 == 2 #2 & )]

{0,0}

We might expect {0,1,3}.
Change the test so as to use the equivalence relation generated:

tst = #1/2^IntegerExponent[#1, 2] ===  #2/2^IntegerExponent[#2, 2] & ;

But we still get the following

Intersection[a, b, SameTest -> tst]

{0,0,1,3,8}

However the following corrects this

Union[%, SameTest -> tst]

{0,1,3}

--
Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Konstantin L Kouptsov" <klk206 at is5.nyu.edu> wrote in message
news:a5htcj\$hsk\$1 at smc.vnet.net...
>
> Intersection[..., SameTest->test] seem to do just that. However:
>
> 1. It is not clear from the manual (book or help browser), what this
command
> is supposed to return.
>
> 2. It simply does not work:
>
> In:=
> a={1,2,3,4};
> b={2,4,7,8};
> Intersection[a,b,SameTest->(#1==2*#2&)]
>
> Out=
> {1}
>
> or more sophisticated:
>
> In:=
> 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=
> {1}
>
> which does not seem to enumerate all pairs.
>
> What idea stands behind this function? what is supposed to do?
>
> (well, for my task I sure could run double For[] cycle, but I am