Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
fix small dimensional cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Kliem committed Apr 3, 2020
1 parent 77433d7 commit 7e25b29
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/sage/geometry/polyhedron/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3170,6 +3170,17 @@ def is_pyramid(self, certificate=False):
sage: Q = polytopes.octahedron()
sage: Q.is_pyramid()
False
For the `0`-dimensional polyhedron, the output is ``True``,
but it cannot be constructed as a pyramid over the empty polyhedron::
sage: P = Polyhedron([[0]])
sage: P.is_pyramid()
True
sage: Polyhedron().pyramid()
Traceback (most recent call last):
...
ZeroDivisionError: rational division by zero
"""
if not self.is_compact():
raise ValueError("polyhedron has to be compact")
Expand Down
29 changes: 28 additions & 1 deletion src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,15 @@ cdef class CombinatorialPolyhedron(SageObject):
# one can give an Integer as Input.
if data < -1:
ValueError("any polyhedron must have dimension at least -1")
self._n_facets = 0
self._dimension = data

if self._dimension == 0:
self._n_facets = 1
self._n_Vrepresentation = 1
else:
self._n_facets = 0
self._n_Vrepresentation = 0

# Initializing the facets in their Bit-representation.
self._bitrep_facets = facets_tuple_to_bit_repr_of_facets((), 0)

Expand Down Expand Up @@ -1831,10 +1837,31 @@ cdef class CombinatorialPolyhedron(SageObject):
Traceback (most recent call last):
...
ValueError: polyhedron has to be compact
TESTS::
sage: CombinatorialPolyhedron(-1).is_pyramid()
False
sage: CombinatorialPolyhedron(-1).is_pyramid(True)
(False, None)
sage: CombinatorialPolyhedron(0).is_pyramid()
True
sage: CombinatorialPolyhedron(0).is_pyramid(True)
(True, 0)
"""
if not self.is_bounded():
raise ValueError("polyhedron has to be compact")

if self.dim() == -1:
if certificate:
return (False, None)
return False

if self.dim() == 0:
if certificate:
return (True, self.Vrepresentation()[0])
return True

# Find a vertex that is incident to all elements in Hrepresentation but one.
vertex_iter = self._face_iter(True, 0)
n_facets = self.n_facets()
Expand Down

0 comments on commit 7e25b29

Please sign in to comment.