Generating output in SAGE in a certain form.

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

Sort by » oldest newest most voted

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()]

more