Ask Your Question
0

Converting between sized and unsized Permutations

asked 2024-02-10 14:53:33 +0100

Max Alekseyev gravatar image

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)
print(p.parent())
q = Permutation([1,2,3,4,5])
print('q =', q)
print(q.parent())

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))
edit retag flag offensive close merge delete

Comments

There is Permutations()(p). I don't know how to get more natural than this without adding new methods.

rburing gravatar imagerburing ( 2024-02-11 13:05:38 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2024-02-12 19:49:23 +0100

dan_fulea gravatar image

Let us use names for the objects, i am working with particular examples.

P = Permutations(7)
Q = Permutations(9) 

s = Permutation([(1,2,3), (4,5,6)])

Then we have:

sage: s.parent()
Standard permutations of 6
sage: P(s)
[2, 3, 1, 5, 6, 4, 7]
sage: P(s).parent()
Standard permutations of 7
sage: Q(s)
[2, 3, 1, 5, 6, 4, 7, 8, 9]
sage: Q(s).parent()
Standard permutations of 9
sage: s.cycle_type()
[3, 3]

When $s$ is moved to the group of permutations of seven symbols, its cycle type changes:

sage: P(s).cycle_type()
[3, 3, 1]

It turns out, that there are some "glitches" when we coerce the element $Q(s)$ (a permutation of nine elements) "back to" $P$ (permutations of seven elements):

sage: P(Q(s))
[2, 3, 1, 5, 6, 4, 7, 8, 9]
sage: P(Q(s)).parent()
Standard permutations of 7

In the background there is a dictionary that also knows about the values in 7,8,9.

sage: s.dict()
{1: 2, 2: 3, 3: 1, 4: 5, 5: 6, 6: 4}
sage: Q(s).dict()
{1: 2, 2: 3, 3: 1, 4: 5, 5: 6, 6: 4, 7: 7, 8: 8, 9: 9}
sage: P(Q(s)).dict()
{1: 2, 2: 3, 3: 1, 4: 5, 5: 6, 6: 4, 7: 7, 8: 8, 9: 9}
sage: P(s).dict()
{1: 2, 2: 3, 3: 1, 4: 5, 5: 6, 6: 4, 7: 7}

But as a rule, always find a large level that will cover all needed levels and work directly in there. Coercions to this bigger group of permutations will always work. An other way of working with permutations is by working in the symmetric group. For instance:

sage: S6 = SymmetricGroup(6)
sage: S7 = SymmetricGroup(7)
sage: S9 = SymmetricGroup(9)

And now the way elements are printed makes it easier to avoid the glitch.

sage: S6(s)
(1,2,3)(4,5,6)
sage: S7(s)
(1,2,3)(4,5,6)
sage: S9(s)
(1,2,3)(4,5,6)

We also compare dictionaries, and they match the parent:

sage: S6(s).dict()
{1: 2, 2: 3, 3: 1, 4: 5, 5: 6, 6: 4}
sage: S7(s).dict()
{1: 2, 2: 3, 3: 1, 4: 5, 5: 6, 6: 4, 7: 7}
sage: S9(s).dict()
{1: 2, 2: 3, 3: 1, 4: 5, 5: 6, 6: 4, 7: 7, 8: 8, 9: 9}
sage: S7(S9(s)).dict()
{1: 2, 2: 3, 3: 1, 4: 5, 5: 6, 6: 4, 7: 7}
edit flag offensive delete link more

Comments

All permutations in your answer are sized. I asked about conversion between sized and unsized ones.

Max Alekseyev gravatar imageMax Alekseyev ( 2024-02-13 13:17:41 +0100 )edit

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: 2024-02-10 14:53:33 +0100

Seen: 91 times

Last updated: Feb 12