Re: Relation Problem in Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg108449] Re: Relation Problem in Mathematica
- From: Peter Pein <petsie at dordos.net>
- Date: Thu, 18 Mar 2010 04:32:33 -0500 (EST)
- References: <hnqd1k$ql$1@smc.vnet.net>
Or define e.g. SmallCircle: In[1]:= X={1,2,3,4}; R=Transpose[{X,RotateLeft[X]}]; S=Reverse/@R; SmallCircle[{} | Sequence[], rel: {{_Integer, _} ...}] := rel; SmallCircle[rel1: ({{_Integer, _} ...} ...), rel2: {{_Integer, _} ...}] := SmallCircle[Sequence @@ Most[{rel1}], rel2 /. {a_Integer, b_} :> {a, b /. Rule @@@ Last[{rel1}]} ] In[5]:= S \[SmallCircle] R Out[5]= {{1, 1}, {2, 2}, {3, 3}, {4, 4}} (* enter the following as SmallCircle[R, S, R, S, R] and press <Strg><Shift><n> while the cursor is in the input-line *) In[6]:= R \[SmallCircle] S \[SmallCircle] R \[SmallCircle] S \[SmallCircle] R Out[6]= {{1, 2}, {2, 3}, {3, 4}, {4, 1}} Peter On 17.03.2010 12:05, Bob Hanlon wrote: > R = {{1, 2}, {2, 3}, {3, 4}, {4, 1}}; > > S = {{2, 1}, {3, 2}, {4, 3}, {1, 4}}; > > f[{a_, b_}, {b_, c_}] = {a, c}; > f[__] = Sequence[]; > > Flatten[Outer[f, R, S, 1], 1] > > {{1, 1}, {2, 2}, {3, 3}, {4, 4}} > > > Bob Hanlon > > ---- Paul Slevin<slevvio at hotmail.com> wrote: > > ============= > Hello - I was wondering if somebody could help me with this problem. I have the set X = {1,2,3,4}, and have computed the Cartesian Product X^2. > > Let R = {(1,2),(2,3),(3,4),(4,1)} > S = {(2,1),(3,2),(4,3),(1,4)} > > be relations on X. > > I want to compute the product S o R...