Ask Your Question
0

How to extract a list from the result of Hrepresentation?

asked 2022-09-20 15:19:58 +0200

lijr07 gravatar image

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-09-20 15:33:48 +0200

tmonteil gravatar image

updated 2022-09-20 15:34:06 +0200

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]]
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-09-20 15:19:58 +0200

Seen: 22 times

Last updated: Sep 20