Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Count the number of cycles for all possible cycle lengths in a permutation
ResourceFunction["CycleLengthCounts"][p] returns a SparseArray of the number of cycles of each length in the permutation p. |
Find the number of cycles of each length in a permutation:
In[1]:= |
Out[1]= |
Use Normal to see the values:
In[2]:= |
Out[2]= |
The identity permutation of length n has n trivial cycles, that is, n 1-cycles:
In[3]:= |
In[4]:= |
Out[4]= |
In[5]:= |
Out[5]= |
Verify by counting cycles:
In[6]:= |
Out[6]= |
A reverse of the even-length identity permutation of length n has 2-cycles:
In[7]:= |
Out[7]= |
The number of cycles in a permutation is the total of the cycle length counts:
In[8]:= |
Out[8]= |
In[9]:= |
Out[9]= |
In[10]:= |
Out[10]= |
The sum is n:
In[11]:= |
Out[11]= |
In[12]:= |
Out[12]= |
This work is licensed under a Creative Commons Attribution 4.0 International License