How to extract a list from the result of Hrepresentation?

In SageMath, I use the following command to compute Hrepresentations.

P1 = Polyhedron(vertices = [[3, 1, 5, 3], [3, 1, 4, 4], [3, 1, 3, 5], [2, 2, 5, 3], [2, 2, 4, 4], [2, 2, 3, 5], [1, 3, 4, 4], [1, 3, 3, 5]])
r1=P1.Hrepresentation()
r1


The result I got is

(An equation (0, 0, 1, 1) x - 8 == 0,
An equation (1, 1, 0, 0) x - 4 == 0,
An inequality (-1, 0, 0, 0) x + 3 >= 0,
An inequality (1, 0, 0, 1) x - 5 >= 0,
An inequality (1, 0, 0, 0) x - 1 >= 0,
An inequality (0, 0, 0, -1) x + 5 >= 0,
An inequality (0, 0, 0, 1) x - 3 >= 0)


How to get the list

[ [0,0,1,1], [1,1,0,0], [-1,0,0,0], [1,0,0,1], [1,0,0,0], [0,0,0,-1] ]


from r1? Thank you very much.

edit retag close merge delete

Sort by ยป oldest newest most voted

If you look at r1, you see that it is a tuple:

sage: type(r1)
<class 'tuple'>


Now, if you look at the first element of r1, you see it is an equation:

sage: type(r1[0])
<class 'sage.geometry.polyhedron.representation.Equation'>


You can try to extract its coefficients by making it a list:

sage: list(r1[0])
[-8, 0, 0, 1, 1]


You see that the constant term is the first, which you can remove as follows:

sage: list(r1[0])[1:]
[0, 0, 1, 1]


You can put all those remarks together to do:

sage: [list(eq)[1:] for eq in r1]
[[0, 0, 1, 1],
[1, 1, 0, 0],
[-1, 0, 0, 0],
[1, 0, 0, 1],
[1, 0, 0, 0],
[0, 0, 0, -1],
[0, 0, 0, 1]]

more