Ask Your Question
1

Generating output in SAGE in a certain form.

asked 2018-04-30 17:17:49 +0100

sagequstions gravatar image

updated 2020-06-01 10:47:00 +0100

FrédéricC gravatar image

I want to use SAGE to generate an output that is suitable for GAP to do further stuff with it.

The input should be a natural number $n \geq 2$.

The output should be a list of tuples containing the non-trivial permutations in their standard form (for example [2,3,1] is the permutation mapping 1->2,2->3,3->1) as the first entry of the tuple and the second entry of the tuple should be their reduced word from ( for [2,3,1] it is [1, 2], obtained via Permutation([2,3,1]).reduced_word_lexmin() ).

So for $n=3$ the output should look as follows:

[ [[1,3,2], [2]], [[2,1,3], [1]], [[2,3,1] , [1, 2]], [[3,1,2], [2, 1]],[[3,2,1] ,[1, 2, 1]] ]

So the question is more how to do this quickly with SAGE and is not really mathematical. Sorry in case this question is very elementary, but I have no much experience with SAGE and rarely use it.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
4

answered 2018-04-30 22:10:22 +0100

Sébastien gravatar image

updated 2018-04-30 22:14:19 +0100

All you need to know is how to use list comprehensions in Python:

sage: def f(n):
....:     P = Permutations(n)
....:     return [[p,p.reduced_word_lexmin()] for p in P if not p.is_one()]
....: 
sage: f(2)
[[[2, 1], [1]]]
sage: f(3)
[[[1, 3, 2], [2]],
 [[2, 1, 3], [1]],
 [[2, 3, 1], [1, 2]],
 [[3, 1, 2], [2, 1]],
 [[3, 2, 1], [1, 2, 1]]]

Do the following if you need everything to be of type list:

sage: def f(n):
....:     P = Permutations(n)
....:     return [[list(p),p.reduced_word_lexmin()] for p in P if not p.is_one()]
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

1 follower

Stats

Asked: 2018-04-30 17:17:49 +0100

Seen: 438 times

Last updated: Apr 30 '18