Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
1

Generating output in SAGE in a certain form.

asked 6 years ago

sagequstions gravatar image

updated 4 years ago

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 n2.

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.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
4

answered 6 years ago

Sébastien gravatar image

updated 6 years ago

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

1 follower

Stats

Asked: 6 years ago

Seen: 454 times

Last updated: Apr 30 '18