RE: Multiplying permutations
- To: mathgroup at smc.vnet.net
- Subject: [mg41762] RE: [mg41723] Multiplying permutations
- From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
- Date: Wed, 4 Jun 2003 08:34:43 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
>-----Original Message----- >From: Dr. Wolfgang Hintze [mailto:weh at snafu.de] To: mathgroup at smc.vnet.net >Sent: Tuesday, June 03, 2003 1:13 PM >To: mathgroup at smc.vnet.net >Subject: [mg41762] [mg41723] Multiplying permutations > > >Is there a simple command in Mathematica to multiply two permutations, >i.e. to carry out one after the other? > >I looked at the packages DiscreteMath`Permutations` and >DiscreteMath`Combinatorica` but couldn't find it. > >Example > >p = {3,1,2} mapping: 1->3, 2->1, 3->2 >q = {2,1,3} mapping: 1->2, 2->1, 3->3 >p.q = mappings (p first, then q) > [1-p->3-q->3, 2-p->1-q->2, 3-p->2-q->1] >= {3,2,1} > >Any help appreciated > Wolfgang, perhaps this in not what you wanted, but observe: In[1]:= << DiscreteMath`Combinatorica` In[2]:= p = RandomPermutation[8] Out[2]= {6, 3, 5, 4, 1, 2, 7, 8} In[3]:= q = InversePermutation[p] Out[3]= {5, 6, 2, 4, 3, 1, 7, 8} In[4]:= p /. Thread[Range[8] -> q] Out[4]= {1, 2, 3, 4, 5, 6, 7, 8} In[5]:= ToCycles[p] Out[5]= {{6, 2, 3, 5, 1}, {4}, {7}, {8}} In[6]:= ptimes[p_, q___] := Fold[#1 /. Thread[Range[Length[p]] -> #2] &, p, {q}] In[7]:= ptimes[p] Out[7]= {6, 3, 5, 4, 1, 2, 7, 8} In[8]:= ptimes[p, q] Out[8]= {1, 2, 3, 4, 5, 6, 7, 8} In[10]:= ptimes[p, p, p, p] Out[10]= {5, 6, 2, 4, 3, 1, 7, 8} In[11]:= q Out[11]= {5, 6, 2, 4, 3, 1, 7, 8} -- Hartmut Wolf >