1
$\begingroup$

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?

$\endgroup$
4
  • $\begingroup$ Rob Pratt, Thank you for your edit. $\endgroup$
    – tchappy ha
    Feb 13, 2022 at 4:41
  • $\begingroup$ Alexander Konovalov, Thank you for your edit. $\endgroup$
    – tchappy ha
    Feb 13, 2022 at 10:03
  • 1
    $\begingroup$ 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. $\endgroup$ Feb 13, 2022 at 13:02
  • $\begingroup$ @AlexanderKonovalov Thank you very much for teaching me. $\endgroup$
    – tchappy ha
    Feb 13, 2022 at 17:33

1 Answer 1

2
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ Alexander Konovalov, Thank you very much for your kind answer. $\endgroup$
    – tchappy ha
    Feb 13, 2022 at 17:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .