First time here? Check out the FAQ!

Ask Your Question
2

Overloading the binary operation of symmetric groups to reverse the order

asked 6 years ago

Gonneman gravatar image

updated 2 years ago

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?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
1

answered 6 years ago

FrédéricC gravatar image

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.

Preview: (hide)
link

Comments

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 ( 6 years ago )
0

answered 6 years ago

slelievre gravatar image

updated 6 years ago

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)
Preview: (hide)
link

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 6 years ago

Seen: 486 times

Last updated: Dec 12 '18