1
$\begingroup$

I am looking for a way to get {5,2} for a Cycles object, like: Cycles[{{1,2,3,4,5},{6,7}}]. This could help with conjugacy classes.

The function should give back the length of the cycles the permutation consists of, in the natural ordering of the cycles as defined by Mathematica (e.g. Cycles[{{6,7},{1,2,3,4,5}}] would still have a "shape" of {5,2}).

$\endgroup$
6
  • 1
    $\begingroup$ Are you looking for something like Length /@ First @ Cycles[{{1, 2, 3, 4, 5}, {6, 7}}]? (It could be useful to apply a Sort to the result as well, I'm not sure) As a function definition: cycleShape[Cycles[x_List]] := Sort[Length /@ x] $\endgroup$
    – thorimur
    Oct 4, 2021 at 16:55
  • $\begingroup$ It is not clear what you are asking. Please be explicit about what you want to achieve. Don't just give an example and let people guess. $\endgroup$
    – Szabolcs
    Oct 4, 2021 at 16:57
  • $\begingroup$ @Szabolcs, I added a clarification. $\endgroup$ Oct 4, 2021 at 17:16
  • $\begingroup$ @thorimur, yes, that's exactly I was looking for. Thank you for the help, if you add a response, I'll accept it as an answer. $\endgroup$ Oct 4, 2021 at 17:16
  • $\begingroup$ That is not what numpy's shape does ... The equivalent of np.shape is Dimensions. $\endgroup$
    – Szabolcs
    Oct 4, 2021 at 18:37

2 Answers 2

2
$\begingroup$

If you're looking for something like Length /@ First @ Cycles[{{1, 2, 3, 4, 5}, {6, 7}}], we can easily package that in a function:

cycleShape[Cycles[x_List]] := Length /@ x

The question then is how you want the "shape" to be ordered; for example, should Cycles[{{1, 2, 3, 4, 5}, {6, 7}}] have shape {5, 2} or {2, 5}? If we want to put the shape into a canonical form based only on the list of cycle lengths we can just use Sort:

cycleShape[Cycles[x_List]] := Sort[Length /@ x]

But if we want it to reflect the canonical ordering of the cycles, we can simply use the original definition. This is because Cycles automatically sorts its argument (try evaluating Cycles[{{6, 7}, {1, 2, 3, 4, 5}}] by itself). However, using the first definition (without Sort applied afterwards) would mean that, for example, Cycles[{{1, 2}, {3, 4, 5}}] and Cycles[{{1, 2, 5}, {3, 4}}] (both of which are in canonical Mathematica form) would have different shapes, despite being conjugate permutations (by the permutation Cycles[{{1, 3}, {2, 4}}]).

$\endgroup$
1
$\begingroup$
shape = Apply[Map @ Length];

shape @ Cycles[{{1, 2, 3, 4, 5}, {6, 7}}]
{5, 2}
shape @ Cycles[{{6, 7}, {1, 2, 3, 4, 5}}]
{5, 2}
$\endgroup$

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