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.Tue, 05 Mar 2019 14:11:45 -0600Obtaining integers from a linear extension of a poset.http://ask.sagemath.org/question/45668/obtaining-integers-from-a-linear-extension-of-a-poset/I'm quite new to Sage so this might be a very easy question.
Suppose that I have defined a linear extension of a poset in Sage like this:
P = Poset(([1,2,3,4], [[1,3],[1,4],[2,3]]), linear_extension=True, facade=False)
p = P.linear_extension([1,4,2,3])
Is there a way for me to make this linear extension into a permutation? That is, I would like to obtain the permutation [1,4,2,3] from p.Tue, 05 Mar 2019 09:21:13 -0600http://ask.sagemath.org/question/45668/obtaining-integers-from-a-linear-extension-of-a-poset/Answer by rburing for <p>I'm quite new to Sage so this might be a very easy question.</p>
<p>Suppose that I have defined a linear extension of a poset in Sage like this:</p>
<pre><code>P = Poset(([1,2,3,4], [[1,3],[1,4],[2,3]]), linear_extension=True, facade=False)
p = P.linear_extension([1,4,2,3])
</code></pre>
<p>Is there a way for me to make this linear extension into a permutation? That is, I would like to obtain the permutation [1,4,2,3] from p.</p>
http://ask.sagemath.org/question/45668/obtaining-integers-from-a-linear-extension-of-a-poset/?answer=45672#post-id-45672This is not my field, but it seems you can do
sage: map(lambda x: x.element, p)
[1, 4, 2, 3]
sage: sigma = Permutation(map(lambda x: x.element, p))
sage: sigma
[1, 4, 2, 3]
sage: sigma(2)
4Tue, 05 Mar 2019 11:27:22 -0600http://ask.sagemath.org/question/45668/obtaining-integers-from-a-linear-extension-of-a-poset/?answer=45672#post-id-45672Comment by FrédéricC for <p>This is not my field, but it seems you can do</p>
<pre><code>sage: map(lambda x: x.element, p)
[1, 4, 2, 3]
sage: sigma = Permutation(map(lambda x: x.element, p))
sage: sigma
[1, 4, 2, 3]
sage: sigma(2)
4
</code></pre>
http://ask.sagemath.org/question/45668/obtaining-integers-from-a-linear-extension-of-a-poset/?comment=45673#post-id-45673More pythonic:
sage: Permutation(x.element for x in p)
[1, 4, 2, 3]
Or just use facade=TrueTue, 05 Mar 2019 14:11:45 -0600http://ask.sagemath.org/question/45668/obtaining-integers-from-a-linear-extension-of-a-poset/?comment=45673#post-id-45673