Ask Your Question
2

Change order of multiplication/composition in SymmetricGroup

asked 2021-12-03 13:40:00 +0100

Thrash gravatar image

How can I change the order of multiplication/composition of elements in the symmetric group?

Example:

sage: S=SymmetricGroup(4)
sage: a=S((1,2))
sage: b=S((2,3))
sage: c=S((3,4))
sage: a*b*c
(1,4,3,2)

How can I change this behavior so that I can execute a*b*c and the output will be (1,2,3,4)? I want to keep using the star *, not an inconvenient command like a.__rmul__(b).__rmul__(c), otherwise I would have to rewrite all my code.

edit retag flag offensive close merge delete

Comments

There is something like this: Permutations.global_options(mult='r2l')

FrédéricC gravatar imageFrédéricC ( 2021-12-04 10:43:41 +0100 )edit

Thanks, but this command doesn't exist anymore. However, I tried Permutations.options(mult='r2l'), but it doesn't change the order, I still get (1,4,3,2).

Thrash gravatar imageThrash ( 2021-12-04 13:00:20 +0100 )edit

slelievre, thanks but is there any solution in the links you are providing? I just need a simple command to switch the behavior. It shouldn't be so complicated.

Thrash gravatar imageThrash ( 2021-12-05 13:22:43 +0100 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2021-12-04 14:19:21 +0100

FrédéricC gravatar image

Well, not perfect, but something:

sage: S = Permutations(4)
sage: a=S([2,1,3,4])
sage: b=S([1,3,2,4])
sage: c=S([1,2,4,3])
sage: a*b*c
[4, 1, 2, 3]
sage: S.options(mult='r2l')
sage: a*b*c
[2, 3, 4, 1]
edit flag offensive delete link more

Comments

Thanks, but then S((2,3)) doesn't work anymore. It seems that Permutations doesn't allow the cyclic notation, but I want to keep it.

Thrash gravatar imageThrash ( 2021-12-04 14:35:13 +0100 )edit

Permutation can take as input elements of symmetric groups:

sage: Permutation(SymmetricGroup(4)((1,2)))
[2, 1, 3, 4]
FrédéricC gravatar imageFrédéricC ( 2021-12-04 17:14:25 +0100 )edit

Look at

sage: S=SymmetricGroup(4)
sage: T=Permutations(4)
sage: a=T(S((1,2)))
sage: b=T(S((2,3)))
sage: c=T(S((3,4)))
sage: T.options(mult='r2l')
sage: d=a*b*c
sage: d.cycle_string()
'(1,2,3,4)'

Compared to my original code, I think this is a rather inconvenient solution because I have to introduce T and .cycle_string() in the end to get the final result as I wish and as it could be principally done via my original code. Can't it be done with only one additional line like .options(mult='r2l') or some other command?

Thrash gravatar imageThrash ( 2021-12-04 21:15:11 +0100 )edit

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: 2021-12-03 13:40:00 +0100

Seen: 389 times

Last updated: Dec 04 '21