How to calculate the length of a cycle $(i_1,i_2,\dots,i_k)\in S_n$ in GAP(Groups, Algorithms, Programming)?

52 Views Asked by At

I am new to GAP ( - Groups, Algorithms, Programming - a System for Computational Discrete Algebra).
I want to calculate the length of a cycle $(i_1,i_2,\dots,i_k)\in S_n$. (I want to get $k$ from $(i_1,i_2,\dots,i_k)\in S_n$.)
Please tell me how to calculate the length of a cycle $(i_1,i_2,\dots,i_k)\in S_n$ in GAP?

Length(1,2,3);

didn't work.

Order(1,2,3);

worked.

But is this a right way to calculate the length of a cycle in GAP?

1

There are 1 best solutions below

1
On BEST ANSWER

If you have a cycle, then I think that using Order will be the best way. It will use fast implementation from the GAP kernel - as you can see, repeating this calculation a million times takes a bit more than a second:

gap> for i in [1..1000000] do Order((1,2,3,4,5,6,7,8,9,10));od;time;
1238

If you have a product of several cycles, then CycleStructurePerm would be a proper way to get the number of cycles of each length. It's also fast:

gap> for i in [1..1000000] do CycleStructurePerm((1,2,3,4,5,6,7,8,9,10));od;time;
1400

P.S. Of course, one should be careful when dealing with the identity permutation:

gap> Order(());
1
gap> NrMovedPoints(());
0
gap> CycleStructurePerm(());
[  ]

These functions are documented in this manual chapter.