# Obtaining a poset from Posets(n)

I have defined function that takes a poset $P$ as input and outputs the major index generating polynomial over all linear extensions of $P$. Here, the major index of a certain linear extension of $P$ is given by the major index of the corresponding permutation, see e.g. http://mathworld.wolfram.com/LinearEx... for an example of this correspondence.

def major_index(pos):
poly = 0
lst = pos.linear_extensions()
for le in lst:
perm = Permutation(x.element for x in le)
maj = perm.major_index()
poly += x^maj
return poly


If I write, for example

P = Poset(([1,2,3,4], [[1,3],[1,4],[2,3]]), linear_extension=True, facade=False)
major_index(P)


Then I get

x^4 + x^3 + x^2 + x + 1


which is the correct output. I would like to use Posets(n) to generate all posets (up to isomorphism) with $n$ vertices. However, when I write

lst = Posets(3)
P = lst
major_index(P)


I get the error:

Traceback (click to the left of this block for traceback)
...
AttributeError: 'sage.rings.integer.Integer' object has no attribute
'element'


Clearly the error is due to the line

perm = Permutation(x.element for x in le)


But I don't understand how Posets(n) works and why I cannot just write lst to obtain a poset.

edit retag close merge delete

Sort by » oldest newest most voted This is because all these posets are "facade". Try something like that :

sage: P = Posets(4)
sage: Q = next(iter(P))
True
sage: Permutation(x+1 for x in Q.linear_extension())
[4, 3, 2, 1]

more

This partially solved my issues. But I would, if possible, like to use the major_index-function on the posets of Poset(n). So I would like to write something like

P = Posets(3)

Q = next(iter(P))

major_index(Q)

but this gives me a similar error.