Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Converting between sized and unsized Permutations

Sage has two similar classes of permutations with the names Standard permutations and Standard permutations of n. I wonder how to convert elements (of appropriate size) from one class to the other, and back.

Here an example of permutations from the two classes:

p = next(iter(Permutations(5)))
print('p =', p)
q = Permutation([1,2,3,4,5])
print('q =', q)

which prints

p = [1, 2, 3, 4, 5]
Standard permutations of 5
q = [1, 2, 3, 4, 5]
Standard permutations

How to add size to q and how to remove one from p most naturally? My solutions look ugly:

q_ = Permutations(len(q))(q)
p_ = Permutation(list(p))