ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 30 Apr 2018 15:10:22 -0500Generating output in SAGE in a certain form.http://ask.sagemath.org/question/42228/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.Mon, 30 Apr 2018 10:17:49 -0500http://ask.sagemath.org/question/42228/generating-output-in-sage-in-a-certain-form/Answer by Sébastien for <p>I want to use SAGE to generate an output that is suitable for GAP to do further stuff with it.</p>
<p>The input should be a natural number $n \geq 2$.</p>
<p>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() ).</p>
<p>So for $n=3$ the output should look as follows:</p>
<p>[ [[1,3,2], [2]], [[2,1,3], [1]], [[2,3,1] , [1, 2]], [[3,1,2], [2, 1]],[[3,2,1] ,[1, 2, 1]] ]</p>
<p>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.</p>
http://ask.sagemath.org/question/42228/generating-output-in-sage-in-a-certain-form/?answer=42236#post-id-42236All you need to know is how to use [list comprehensions](http://doc.sagemath.org/html/en/thematic_tutorials/tutorial-comprehensions.html) 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()]Mon, 30 Apr 2018 15:10:22 -0500http://ask.sagemath.org/question/42228/generating-output-in-sage-in-a-certain-form/?answer=42236#post-id-42236