I have a permutation a in a product of disjoint cycles form as follows

$a = {{(1,9,3,7)(2,11,6)(4,8,5,10)}}$

I want to represent it in a matrix form A such that

$A = \begin{pmatrix}1&2&3&4&5&6&7&8&9&10&11\\9&11&7&8&10&2&1&5&3&4&6 \end{pmatrix}$

I believe a can be defined in Mathematica as

a = Cycles[{{1, 9, 3, 7}, {2, 11, 6}, {4, 8, 5, 10}}]

How do I convert a to A?

up vote 10 down vote accepted
mat = {Sort @ #, #} & @ PermutationList[a];
MatrixForm @ mat // TeXForm

$ \left( \begin{array}{ccccccccccc} 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 \\ 9 & 11 & 7 & 8 & 10 & 2 & 1 & 5 & 3 & 4 & 6 \\ \end{array} \right)$

One idea is to overload MatrixForm so that it does this for you automatically:

Unprotect[MatrixForm];
MatrixForm /: MakeBoxes[MatrixForm[cyc_Cycles], StandardForm] := With[
    {list=PermutationList[cyc]},
    ToBoxes[MatrixForm[{Range@Length@list, list}], StandardForm]
]
Protect[MatrixForm];

Then:

Cycles[{{1, 9, 3, 7}, {2, 11, 6}, {4, 8, 5, 10}}] //MatrixForm

enter image description here

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.