Re: Intersection[...,SameTest] ?
- To: mathgroup at smc.vnet.net
- Subject: [mg33068] Re: Intersection[...,SameTest] ?
- From: "Avraham Shinnar" <as1619 at columbia.edu>
- Date: Fri, 1 Mar 2002 06:51:10 -0500 (EST)
- Organization: Columbia University
- References: <a5htcj$hsk$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Apparently you have to test in both directions: Intersection[a, b, SameTest -> ((#1 == 2*#2 || #2 == 2*#1 ) &)] similarly, a = {1, 2, 3, 4}; b = {2, 4, 7, 8}; Intersection[a, b, SameTest -> ((Print[#1, "=?=", #2] || True) && (#1 == 2*#2 || 2*#1 == #2) && (Print[True] || True) &) which outputs (correctly) 1\[InvisibleSpace]"=?="\[InvisibleSpace]2 True 2\[InvisibleSpace]"=?="\[InvisibleSpace]2 2\[InvisibleSpace]"=?="\[InvisibleSpace]4 True 3\[InvisibleSpace]"=?="\[InvisibleSpace]2 3\[InvisibleSpace]"=?="\[InvisibleSpace]4 3\[InvisibleSpace]"=?="\[InvisibleSpace]7 3\[InvisibleSpace]"=?="\[InvisibleSpace]8 4\[InvisibleSpace]"=?="\[InvisibleSpace]2 True Out[6]= {1, 2, 4} -- Avraham "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[83]:= > a={1,2,3,4}; > b={2,4,7,8}; > Intersection[a,b,SameTest->(#1==2*#2&)] > > 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) > &==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. > > 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 > curious about Intersection[]) >