ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 13 Feb 2024 13:17:41 +0100Converting between sized and unsized Permutationshttps://ask.sagemath.org/question/75905/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)
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))
Sat, 10 Feb 2024 14:53:33 +0100https://ask.sagemath.org/question/75905/converting-between-sized-and-unsized-permutations/Comment by rburing for <p>Sage has two similar classes of permutations with the names <strong>Standard permutations</strong> and <strong>Standard permutations of n</strong>. I wonder how to convert elements (of appropriate size) from one class to the other, and back.</p>
<p>Here an example of permutations from the two classes:</p>
<pre><code>p = next(iter(Permutations(5)))
print('p =', p)
print(p.parent())
q = Permutation([1,2,3,4,5])
print('q =', q)
print(q.parent())
</code></pre>
<p>which prints</p>
<pre><code>p = [1, 2, 3, 4, 5]
Standard permutations of 5
q = [1, 2, 3, 4, 5]
Standard permutations
</code></pre>
<p>How to add size to <code>q</code> and how to remove one from <code>p</code> most naturally? My solutions look ugly:</p>
<pre><code>q_ = Permutations(len(q))(q)
p_ = Permutation(list(p))
</code></pre>
https://ask.sagemath.org/question/75905/converting-between-sized-and-unsized-permutations/?comment=75933#post-id-75933There is `Permutations()(p)`. I don't know how to get more natural than this without adding new methods.Sun, 11 Feb 2024 13:05:38 +0100https://ask.sagemath.org/question/75905/converting-between-sized-and-unsized-permutations/?comment=75933#post-id-75933Answer by dan_fulea for <p>Sage has two similar classes of permutations with the names <strong>Standard permutations</strong> and <strong>Standard permutations of n</strong>. I wonder how to convert elements (of appropriate size) from one class to the other, and back.</p>
<p>Here an example of permutations from the two classes:</p>
<pre><code>p = next(iter(Permutations(5)))
print('p =', p)
print(p.parent())
q = Permutation([1,2,3,4,5])
print('q =', q)
print(q.parent())
</code></pre>
<p>which prints</p>
<pre><code>p = [1, 2, 3, 4, 5]
Standard permutations of 5
q = [1, 2, 3, 4, 5]
Standard permutations
</code></pre>
<p>How to add size to <code>q</code> and how to remove one from <code>p</code> most naturally? My solutions look ugly:</p>
<pre><code>q_ = Permutations(len(q))(q)
p_ = Permutation(list(p))
</code></pre>
https://ask.sagemath.org/question/75905/converting-between-sized-and-unsized-permutations/?answer=75961#post-id-75961Let 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}
Mon, 12 Feb 2024 19:49:23 +0100https://ask.sagemath.org/question/75905/converting-between-sized-and-unsized-permutations/?answer=75961#post-id-75961Comment by Max Alekseyev for <p>Let us use names for the objects, i am working with particular examples.</p>
<pre><code>P = Permutations(7)
Q = Permutations(9)
s = Permutation([(1,2,3), (4,5,6)])
</code></pre>
<p>Then we have:</p>
<pre><code>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]
</code></pre>
<p>When $s$ is moved to the group of permutations of seven symbols, its cycle type changes:</p>
<pre><code>sage: P(s).cycle_type()
[3, 3, 1]
</code></pre>
<p>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):</p>
<pre><code>sage: P(Q(s))
[2, 3, 1, 5, 6, 4, 7, 8, 9]
sage: P(Q(s)).parent()
Standard permutations of 7
</code></pre>
<p>In the background there is a dictionary that also knows about the values in <code>7,8,9</code>.</p>
<pre><code>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}
</code></pre>
<p>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:</p>
<pre><code>sage: S6 = SymmetricGroup(6)
sage: S7 = SymmetricGroup(7)
sage: S9 = SymmetricGroup(9)
</code></pre>
<p>And now the way elements are printed makes it easier to avoid the glitch.</p>
<pre><code>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)
</code></pre>
<p>We also compare dictionaries, and they match the parent:</p>
<pre><code>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}
</code></pre>
https://ask.sagemath.org/question/75905/converting-between-sized-and-unsized-permutations/?comment=75973#post-id-75973All permutations in your answer are sized. I asked about conversion between sized and unsized ones.Tue, 13 Feb 2024 13:17:41 +0100https://ask.sagemath.org/question/75905/converting-between-sized-and-unsized-permutations/?comment=75973#post-id-75973