Skip to content

Commit

Permalink
Trac #33666: Mutable polyhedron (ppl) saves incorrect Vrepresentation
Browse files Browse the repository at this point in the history
{{{
sage: P = polytopes.cube()
sage: Q = 1/2*P
sage: parent = P.parent()
sage: R = parent._element_constructor_(Q, mutable=True)
sage: R
/home/jonathan/Applications/sage/local/lib/python3.8/site-
packages/sage/repl/rich_output/display_manager.py:608: RichReprWarning:
Exception in _rich_repr_ while displaying object: no conversion of this
rational to integer
  warnings.warn(
The empty polyhedron in ZZ^3
sage: R.Hrepresentation()
(An inequality (0, 0, -2) x + 1 >= 0,
 An inequality (0, -2, 0) x + 1 >= 0,
 An inequality (-2, 0, 0) x + 1 >= 0,
 An inequality (2, 0, 0) x + 1 >= 0,
 An inequality (0, 0, 2) x + 1 >= 0,
 An inequality (0, 2, 0) x + 1 >= 0)
sage: R.Vrepresentation()
[]
}}}

While obtaining the Vrepresentation from the backend, a `TypeError` is
not handled properly. We end up with a broken object, which isn't
communicated well to the user.

URL: https://trac.sagemath.org/33666
Reported by: gh-kliem
Ticket author(s): Jonathan Kliem
Reviewer(s): Matthias Koeppe
  • Loading branch information
Release Manager committed Apr 19, 2022
2 parents a00769f + ed109ae commit 3285e37
Showing 1 changed file with 67 additions and 2 deletions.
69 changes: 67 additions & 2 deletions src/sage/geometry/polyhedron/backend_ppl.py
Expand Up @@ -178,9 +178,38 @@ def set_immutable(self):
sage: p.set_immutable()
sage: hasattr(p, "_Vrepresentation")
True
TESTS:
Check that :trac:`33666` is fixed::
sage: cube = polytopes.cube()
sage: parent = cube.parent()
sage: smaller_cube_ZZ = parent._element_constructor_(1/2 * cube, mutable=True)
sage: smaller_cube_ZZ.set_immutable()
Traceback (most recent call last):
...
TypeError: no conversion of this rational to integer
sage: smaller_cube_ZZ.is_immutable()
False
sage: smaller_cube_ZZ.set_immutable()
Traceback (most recent call last):
...
TypeError: no conversion of this rational to integer
sage: smaller_cube_ZZ.is_immutable()
False
sage: smaller_cube_QQ = smaller_cube_ZZ.base_extend(QQ)
sage: smaller_cube_QQ.set_immutable()
sage: smaller_cube_QQ.is_immutable()
True
"""
if not hasattr(self, '_Vrepresentation'):
self._init_Vrepresentation_from_ppl(True)
try:
self._init_Vrepresentation_from_ppl(True)
except TypeError as e:
# Apparently the polyhedron is (no longer) integral.
self._clear_cache()
raise e
if not hasattr(self, '_Hrepresentation'):
self._init_Hrepresentation_from_ppl(True)
self._is_mutable = False
Expand Down Expand Up @@ -221,9 +250,45 @@ def Vrepresentation(self, index=None):
sage: p.Vrepresentation(0)
A vertex at (-1, -1, -1)
sage: TestSuite(p).run()
TESTS:
Check that :trac:`33666` is fixed::
sage: cube = polytopes.cube()
sage: parent = cube.parent()
sage: smaller_cube_ZZ = parent._element_constructor_(1/2 * cube, mutable=True)
sage: smaller_cube_ZZ.Hrepresentation()
(An inequality (0, 0, -2) x + 1 >= 0,
An inequality (0, -2, 0) x + 1 >= 0,
An inequality (-2, 0, 0) x + 1 >= 0,
An inequality (2, 0, 0) x + 1 >= 0,
An inequality (0, 0, 2) x + 1 >= 0,
An inequality (0, 2, 0) x + 1 >= 0)
sage: smaller_cube_ZZ.Vrepresentation()
Traceback (most recent call last):
...
TypeError: the polyhedron is not integral; do a base extension ``self.base_extend(QQ)``
sage: smaller_cube_ZZ.Vrepresentation()
Traceback (most recent call last):
...
TypeError: the polyhedron is not integral; do a base extension ``self.base_extend(QQ)``
sage: smaller_cube_QQ = smaller_cube_ZZ.base_extend(QQ)
sage: smaller_cube_QQ.Hrepresentation()
(An inequality (0, 0, -2) x + 1 >= 0,
An inequality (0, -2, 0) x + 1 >= 0,
An inequality (-2, 0, 0) x + 1 >= 0,
An inequality (2, 0, 0) x + 1 >= 0,
An inequality (0, 0, 2) x + 1 >= 0,
An inequality (0, 2, 0) x + 1 >= 0)
"""
if not hasattr(self, '_Vrepresentation'):
self._init_Vrepresentation_from_ppl(True)
try:
self._init_Vrepresentation_from_ppl(True)
except TypeError:
# Apparently the polyhedron is (no longer) integral.
self._clear_cache()
raise TypeError("the polyhedron is not integral; do a base extension ``self.base_extend(QQ)``")
if index is None:
return self._Vrepresentation
else:
Expand Down

0 comments on commit 3285e37

Please sign in to comment.