MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Relation Problem in Mathematica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg108441] Re: [mg108438] Relation Problem in Mathematica
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Wed, 17 Mar 2010 06:04:55 -0500 (EST)
  • Reply-to: hanlonr at cox.net

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 = {(x,y) in X^2: there exists one z in X (for each (x,y) pair) such that (x,z) is in R and (z,y) is in S }.

i.e. I want mathematica to run through each (x,y) pair in X^2 and check if that pair is in S o R.

To clarify, (1,1) is in S o R, because (1,4) is in S and (4,1) is in R. 4 joins 1 to 1, and it is the only element that does so (so it is unique). 

Clearly the output I want should be the diagonal on X := {(1,1),(2,2),(3,3),(4,4)}. However I am really struggling here to get mathematica to work.

Could anybody help me with this idea? Thanks very much.




  • Prev by Date: Re: Axeslabel containing capital n
  • Next by Date: How to set $UserBaseDirectory in the Workbench?
  • Previous by thread: Relation Problem in Mathematica
  • Next by thread: Re: Relation Problem in Mathematica