Ask Your Question

Revision history [back]

The question can be simplified quite a bit.

In short, you define two lattices:

B = posets.BooleanLattice(3)
Y = posets.YoungsLattice(3)

and you want to apply the following function

def format_pt(k):
    return "'x{0}'".format(k+1)

to each node of these lattices.

Observe however what these nodes are.

For B:

sage: for a in B: print a
0
1
2
3
4
5
6
7

For Y:

sage: for a in Y: print a
[]
[1]
[1, 1]
[1, 1, 1]
[2]
[2, 1]
[3]

So the k+1 in the definition of format_pt might work for nodes of B, which are integers, but will not work for nodes of Y, which are lists.

The error boils down to the following (not so surprising) error:

sage: [] + 1
Traceback (most recent call last)
...
TypeError: unsupported operand parent(s) for +: '<type 'list'>' and 'Integer Ring'

The question can be simplified quite a bit.

In short, you define two lattices:

B = posets.BooleanLattice(3)
Y = posets.YoungsLattice(3)

and you want to apply the following function

def format_pt(k):
    return "'x{0}'".format(k+1)

to each node of these lattices.

Observe however what these nodes are.

For B:

sage: for a in B: print a
0
1
2
3
4
5
6
7

For Y:

sage: for a in Y: print a
[]
[1]
[1, 1]
[1, 1, 1]
[2]
[2, 1]
[3]

So the k+1 in the definition of format_pt might work for nodes of B, which are integers, but will not work for nodes of Y, which are lists.

The error boils down to the following (not so surprising) error:

sage: [] + 1
Traceback (most recent call last)
...
TypeError: unsupported operand parent(s) for +: '<type 'list'>' and 'Integer Ring'

Maybe the k+1 was just to renumber nodes of B to start from 1 instead of from 0?

Defining format_pt in a simpler way, and the other functions as in your question:

def le_relations(P):
    return [(a, b) if P.le(a, b) else (b, a) for a, b in P.comparability_graph().edges(labels=None)]

def cover_relations(P):
    return [(a,b) if P.le(a, b) else (b, a) for a, b in P.hasse_diagram().edges(labels=None)]

def format_pt(k):
    return "'x{}'".format(k)

def format_relations(relations):
    return [[format_pt(a), format_pt(b)] for a, b in relations]

def format_pts(P):
    return [format_pt(a) for a in P]

def format_poset(P):
    return [format_pts(P), format_relations(cover_relations(P)), format_relations(le_relations(P))]

we get the following, which might be what you were expecting.

sage: format_poset(B)
[["'x0'", "'x1'", "'x2'", "'x3'", "'x4'", "'x5'", "'x6'", "'x7'"],
 [["'x0'", "'x1'"],
  ["'x0'", "'x2'"],
  ["'x0'", "'x4'"],
  ["'x1'", "'x3'"],
  ["'x1'", "'x5'"],
  ["'x2'", "'x3'"],
  ["'x2'", "'x6'"],
  ["'x3'", "'x7'"],
  ["'x4'", "'x5'"],
  ["'x4'", "'x6'"],
  ["'x5'", "'x7'"],
  ["'x6'", "'x7'"]],
 [["'x0'", "'x1'"],
  ["'x0'", "'x2'"],
  ["'x0'", "'x3'"],
  ["'x0'", "'x4'"],
  ["'x0'", "'x5'"],
  ["'x0'", "'x6'"],
  ["'x0'", "'x7'"],
  ["'x1'", "'x3'"],
  ["'x1'", "'x5'"],
  ["'x1'", "'x7'"],
  ["'x2'", "'x3'"],
  ["'x2'", "'x6'"],
  ["'x2'", "'x7'"],
  ["'x3'", "'x7'"],
  ["'x4'", "'x5'"],
  ["'x4'", "'x6'"],
  ["'x4'", "'x7'"],
  ["'x5'", "'x7'"],
  ["'x6'", "'x7'"]]]
sage: format_poset(Y)
[["'x[]'",
  "'x[1]'",
  "'x[1, 1]'",
  "'x[1, 1, 1]'",
  "'x[2]'",
  "'x[2, 1]'",
  "'x[3]'"],
 [["'x[]'", "'x[1]'"],
  ["'x[1]'", "'x[1, 1]'"],
  ["'x[1]'", "'x[2]'"],
  ["'x[1, 1]'", "'x[1, 1, 1]'"],
  ["'x[1, 1]'", "'x[2, 1]'"],
  ["'x[2]'", "'x[2, 1]'"],
  ["'x[2]'", "'x[3]'"]],
 [["'x[]'", "'x[1]'"],
  ["'x[]'", "'x[1, 1]'"],
  ["'x[]'", "'x[1, 1, 1]'"],
  ["'x[]'", "'x[2]'"],
  ["'x[]'", "'x[2, 1]'"],
  ["'x[]'", "'x[3]'"],
  ["'x[1]'", "'x[1, 1]'"],
  ["'x[1]'", "'x[1, 1, 1]'"],
  ["'x[1]'", "'x[2]'"],
  ["'x[1]'", "'x[2, 1]'"],
  ["'x[1]'", "'x[3]'"],
  ["'x[1, 1]'", "'x[1, 1, 1]'"],
  ["'x[1, 1]'", "'x[2, 1]'"],
  ["'x[2]'", "'x[2, 1]'"],
  ["'x[2]'", "'x[3]'"]]]