Skip to content

Commit

Permalink
Trac #31253: Put equations in stable position for backend cdd
Browse files Browse the repository at this point in the history
Currently, equations positions in Hrepresentation of backend `cdd`
depends on the input:

{{{
sage: P = polytopes.permutahedron(2, backend='cdd')
sage: P.Hrepresentation()
(An equation (1, 1) x - 3 == 0,
 An inequality (0, 1) x - 1 >= 0,
 An inequality (1, 0) x - 1 >= 0)
sage: Q = Polyhedron(P.vertices(), backend='cdd')
sage: Q.Hrepresentation()
(An inequality (-1, 0) x + 2 >= 0,
 An inequality (1, 0) x - 1 >= 0,
 An equation (1, 1) x - 3 == 0)
}}}

This leads to the following failure:

{{{
sage: [x.ambient_Hrepresentation() for x in P.facets()]
[(An inequality (1, 0) x - 1 >= 0, An inequality (0, 1) x - 1 >= 0),
 (An inequality (1, 0) x - 1 >= 0, An equation (1, 1) x - 3 == 0)]
}}}

We fix this by putting equations always in the same position.

URL: https://trac.sagemath.org/31253
Reported by: gh-kliem
Ticket author(s): Jonathan Kliem
Reviewer(s): Matthias Koeppe
  • Loading branch information
Release Manager committed Mar 20, 2021
2 parents badd79c + 1c6c90a commit ba54691
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
6 changes: 3 additions & 3 deletions build/pkgs/configure/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tarball=configure-VERSION.tar.gz
sha1=48014f7cb1b4058977e37a8a24b356b8f49cb407
md5=05f179d63fdbf1d2115190e056adcb6c
cksum=3494189359
sha1=69e3dffde527833c504246a159deee707b293c26
md5=2bc896e7c3a7188b8ff0b02eaf52cbc2
cksum=1400865248
2 changes: 1 addition & 1 deletion build/pkgs/configure/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
313fa89231831703c8da1840c71435517b72624c
e18e9db0b62dbc8f531d8891de3777255769ca57
23 changes: 22 additions & 1 deletion src/sage/geometry/polyhedron/backend_cdd.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,22 @@ def _init_from_cdd_output(self, cddout):
sage: V.points()[1], R[V.points()[1]]
(P(-2686.81000000000, -2084.19000000000),
A 2-dimensional polyhedron in RDF^2 defined as the convex hull of 1 vertex, 1 ray, 1 line)
Check that :trac:`31253` is fixed::
sage: P = polytopes.permutahedron(2, backend='cdd')
sage: P.Hrepresentation()
(An inequality (0, 1) x - 1 >= 0,
An inequality (1, 0) x - 1 >= 0,
An equation (1, 1) x - 3 == 0)
sage: Q = Polyhedron(P.vertices(), backend='cdd')
sage: Q.Hrepresentation()
(An inequality (-1, 0) x + 2 >= 0,
An inequality (1, 0) x - 1 >= 0,
An equation (1, 1) x - 3 == 0)
sage: [x.ambient_Hrepresentation() for x in P.facets()]
[(An equation (1, 1) x - 3 == 0, An inequality (1, 0) x - 1 >= 0),
(An equation (1, 1) x - 3 == 0, An inequality (0, 1) x - 1 >= 0)]
"""
cddout = cddout.splitlines()

Expand Down Expand Up @@ -271,7 +287,12 @@ def parse_H_representation(intro, data):
assert self.ambient_dim() == dimension - 1, "Unexpected ambient dimension"
assert len(data) == count, "Unexpected number of lines"
R = self.base_ring()
for i, line in enumerate(data):
from itertools import chain
# We add equations to the end of the Hrepresentation.
for i in chain(
(j for j in range(len(data)) if not j in equations),
equations):
line = data[i]
coefficients = [R(x) for x in line]
if coefficients[0] != 0 and all(e == 0 for e in coefficients[1:]):
# cddlib sometimes includes an implicit plane at infinity: 1 0 0 ... 0
Expand Down

0 comments on commit ba54691

Please sign in to comment.