Hello there I was wondering if someone could give me a hand with a problem I'm having on Mathematica. I have the set X := {1,2,3,4}, and I have computed the Cartesian product of this set using Combinatorica.

I have inputted the two subsets

R:= {(1,2),(2,3),(3,4),(4,1)}

S:= {(2,1),(3,2),(4,3),(1,4)}

and I want to find the set

$\displaystyle R \bullet S = \{(x,y) \in X^2: \exists $ a unique z [depending on the pair (x,y)] such that $\displaystyle (x,z) \in S $ and $\displaystyle (z,y) \in R \} \$

So i want mathematica to run through all the elements in X^2 and do a check to see if the condition in $\displaystyle R \bullet S $ is satisified. Is this possible? I have no idea how to define the set $\displaystyle R \bullet S $ or how to get mathematica to even run through all the 16 elements in X^2 to see if they satisfy certain conditions.

To clarify, (1,1) is in $\displaystyle R \bullet S $ because (1,4) is in S and (4,1) is in S. 4 is the unique element that joins x = 1 to y = 1. there is no other element except from 4 that does this.

Thanks for listening to my request and I hope someone can guide me on this.