Ask Your Question

Overloading the binary operation of symmetric groups to reverse the order

asked 2018-12-11 16:49:40 +0200

Gonneman gravatar image

updated 2023-01-09 23:59:48 +0200

tmonteil gravatar image

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 flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2018-12-11 20:09:15 +0200

FrédéricC gravatar image

Well, this is sort of a known problem..

There is something for permutations:

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

But this does not seem to be available for SymmetricGroup.

edit flag offensive delete link 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.

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

answered 2018-12-12 12:35:08 +0200

slelievre gravatar image

updated 2018-12-12 12:35:24 +0200

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
sage: a.__rmul__(b)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2018-12-11 16:49:40 +0200

Seen: 351 times

Last updated: Dec 12 '18