# Overloading the binary operation of symmetric groups to reverse the order

I believe the Sage implementation of symmetric groups uses GAP which composes permutations in the opposite order to what I am used to. E.g. if (1,2) denotes the permutations switching 1 and 2, and (2,3) switches 2 and 3, then I would say (1,2) * (2,3) = (1,2,3), because I would first evaluate (2,3) and then (1,2) (the order in which one evaluates functions). Sage on the other hand produces (1,2) * (2,3) = (1,3,2).

About a year ago, a friend helped me overload the definition of the binary operation to have the composition of permutations evaluated in the order I am used to. The code that worked was

class NewSymmetricGroupElement(sage.groups.perm_gps.permgroup_element.SymmetricGroupElement):
def _mul_(self, other):
"""Calling the original class method with order inverted"""
return sage.groups.perm_gps.permgroup_element.SymmetricGroupElement._mul_(other, self)

class NewSymmetricGroup(SymmetricGroup):
def _element_class(self):
return NewSymmetricGroupElement


I recently updated to Sage 8.4 and the code no longer works. Here is what happens, after executing the code above, I run:

NS3=NewSymmetricGroup(3); NS3
> Symmetric group of order 3! as a permutation group
a=NS3((1,2)); b=NS3((2,3));

a*b = (1,3,2) # I would expect (1,2,3)


Can anyone spot what I am doing wrong?

edit retag close merge delete

Sort by » oldest newest most voted

Well, this is sort of a known problem.. https://trac.sagemath.org/ticket/14885

There is something for permutations:

sage: Permutations.options(mult='r2l',display='cycle')
sage: a=Permutation([(1,2),(3,)]);a
(1,2)
sage: b=Permutation([(2,3),(1,)]);b
(2,3)
sage: a*b
(1,2,3)


But this does not seem to be available for SymmetricGroup.

more

Thanks for the link to the bug report. That report also mentions setting multiplication to right-to-left (r2l), as you do, but then notes that this breaks code elsewhere. Quite unsatisfying.

I'm surprised that the _mul_ method is so hard to overload.

( 2018-12-12 10:03:41 +0200 )edit

As a workaround, instead of multiplying with *, one can explicitly use right multiplication with __rmul__:

sage: S3 = SymmetricGroup(3)
sage: a = S3((1, 2))
sage: b = S3((2, 3))
sage: a * b
(1,3,2)
sage: a.__rmul__(b)
(1,2,3)

more