0
$\begingroup$

In Sage, the symmetric group is a list. For instance if G = SymmetricGroup(3), we have

\begin{align*} G[0] & = e \\ G[1] & = (1,3,2)\\ G[2] & = (1,2,3) \\ G[3] &= (2,3)\\ G[4] &= (1,3) \\ G[5] & = (1,2) \end{align*}

I am simply wondering what is the ordering that Sage is using. I am fairly certain it's not "random".

$\endgroup$
4
  • $\begingroup$ Perhaps if you write the permutations in one line notation, you get something interesting? $\endgroup$ Commented Mar 16, 2023 at 6:45
  • 1
    $\begingroup$ Cross-posted to MSE $\endgroup$
    – Derek Holt
    Commented Mar 16, 2023 at 7:58
  • 9
    $\begingroup$ Please don't cross-post so quickly. If you asked this on math.stackexchange, and no one could answer it after some days, then assuming theres a research angle, posting it here with a link back is the way to go. $\endgroup$
    – David Roberts
    Commented Mar 16, 2023 at 9:13
  • 2
    $\begingroup$ I posted an answer on MSE. $\endgroup$
    – joriki
    Commented Mar 16, 2023 at 13:07

1 Answer 1

21
$\begingroup$

I disagree with the question, starting with the first sentence. In Sage, the symmetric group is not a list. In fact clearly it isn't, because I can ask it for SymmetricGroup(100).order() and it tells me the answer in 1ms.

Rather, Sage (and GAP, to which it is closely related) stores permutation groups as a collection of generators. In the case of $S_n$, it uses the generators $(1,2,\dots,n)$ and $(1,2)$ (try SymmetricGroup(5).gens()). From the generators it computes a "strong generating set", and from that it can answer many of the most important questions by being intelligent.

In fact, the first rule of computational group theory is never to enumerate all the elements in the group.

Of course if $n$ is small enough then list(SymmetricGroup(n)) will output an answer. The exact order in which the elements are output is best thought of as an unimportant implementation detail, in my opinion. If you want them in a specific order, sort them that way.

If you dig into the code (see https://github.com/sagemath/sage/blob/f449b14ecae7a704739467245cf5e7561dfec490/src/sage/groups/perm_gps/permgroup.py#L1104) of course you can find out exactly how sage forms a list of the elements. But currently it is marked by a "todo: this is too slow for moderately small permutation groups", which just proves my point that it is an implementation detail and liable to change.

Also, note that list(SymmetricGroup(3)) and sorted(SymmetricGroup(3)) have different outputs. The latter seems to sort elements by one-line notation lexicographically.

$\endgroup$

You must log in to answer this question.

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