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

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?

• Rob Pratt, Thank you for your edit. Feb 13, 2022 at 4:41
• Alexander Konovalov, Thank you for your edit. Feb 13, 2022 at 10:03
• You're welcome! Also use backticks for short code fragments and three backticks fo longer blocks of code instead of indenting by 4 spaces (see how I use them in my answer). This makes it easy to copy and paste code and fragments of GAP sessions to/from this site. Feb 13, 2022 at 13:02
• @AlexanderKonovalov Thank you very much for teaching me. Feb 13, 2022 at 17:33

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.

• Alexander Konovalov, Thank you very much for your kind answer. Feb 13, 2022 at 17:34