Correlating two lists

• To: mathgroup at smc.vnet.net
• Subject: [mg100150] Correlating two lists
• From: anguzman at ing.uchile.cl
• Date: Tue, 26 May 2009 05:11:05 -0400 (EDT)
• References: <gv2jr1\$9af\$1@smc.vnet.net>

```Hi all.
I have the following problem:
Two lists: "x" and "y";  and a boolean relation R[a,b] with a in x and
b in y, and for each "a" there is at most one "b" in "y" such that
R[xi,yj]is true.
R is also "expensive" to calculate. I would like to group each xi in
"x" with its partner in "y" (if there is one) and create a merged list:
{{x1,y1},{x2},{x3},{x4,y4},...}
such that R[xi,yi]  is true
I'm looking for the adequate Mathematica function to do this as
efficiently as possible. by the way, I'm using now this
straightforward-naive approach:

merged={};
Do[Do[If[R[xi,yj],merged=Append[merged,{xi,yj}]],{yj,y}];If[MemberQ[merge[[All,1]],xi],merged=Append[merged,{xi}]],{xi,x}]

but I'm sure there must be a better one (without the Do's would be beautiful).
Any thoughts will be greatly appreciated.
Thanks in advance, and cheers for the 100.000

Atte. Andres Guzman

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

```

• Prev by Date: Re: NIntegrate & Integrate
• Next by Date: Re: Accessing Dictionary definitions
• Previous by thread: Re: uncomplete NDSOlve results
• Next by thread: Re: Correlating two lists