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

Commit

Permalink
improved documentation and check for elements to be of the correct po…
Browse files Browse the repository at this point in the history
…lyhedron
  • Loading branch information
Jonathan Kliem committed Jun 19, 2021
1 parent 3b09b68 commit fe428aa
Showing 1 changed file with 54 additions and 8 deletions.
62 changes: 54 additions & 8 deletions src/sage/geometry/polyhedron/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6943,7 +6943,7 @@ def join_of_Vrep(self, *Vrepresentatives):
INPUT:
- ``Vrepresentatives`` -- vertices/rays/lines or indices of such
- ``Vrepresentatives`` -- vertices/rays/lines of ``self`` or indices of such
OUTPUT: a :class:`~sage.geometry.polyhedron.face.PolyhedronFace`
Expand Down Expand Up @@ -6988,18 +6988,40 @@ def join_of_Vrep(self, *Vrepresentatives):
Traceback (most recent call last):
...
ValueError: the join is not well-defined
The ``Vrepresentatives`` must be of ``self``::
sage: P = polytopes.cube(backend='ppl')
sage: Q = polytopes.cube(backend='field')
sage: v = P.vertices()[0]
sage: P.join_of_Vrep(v)
A 0-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 1 vertex
sage: Q.join_of_Vrep(v)
Traceback (most recent call last):
...
ValueError: not a Vrepresentative of ``self``
sage: f = P.faces(0)[0]
sage: P.join_of_Vrep(v)
A 0-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 1 vertex
sage: Q.join_of_Vrep(v)
Traceback (most recent call last):
...
ValueError: not a Vrepresentative of ``self``
"""
from sage.geometry.polyhedron.representation import Vrepresentation
from sage.geometry.polyhedron.face import PolyhedronFace

new_indices = [0]*len(Vrepresentatives)
for i, v in enumerate(Vrepresentatives):
if isinstance(v, PolyhedronFace) and v.dim() == 0:
v = v.ambient_V_indices()[0]

if v in ZZ:
if v.polyhedron() is not self:
raise ValueError("not a Vrepresentative of ``self``")
new_indices[i] = v.ambient_V_indices()[0]
elif v in ZZ:
new_indices[i] = v
elif isinstance(v, Vrepresentation):
if v.polyhedron() is not self:
raise ValueError("not a Vrepresentative of ``self``")
new_indices[i] = v.index()
else:
raise ValueError("{} is not a Vrepresentative".format(v))
Expand All @@ -7012,7 +7034,7 @@ def meet_of_facets(self, *facets):
INPUT:
- ``facets`` -- facets or indices of facets;
- ``facets`` -- facets or indices of facets of ``self``;
the indices are assumed to be the indices of the Hrepresentation
OUTPUT: a :class:`~sage.geometry.polyhedron.face.PolyhedronFace`
Expand All @@ -7031,18 +7053,38 @@ def meet_of_facets(self, *facets):
sage: P.meet_of_facets(1,3,7).ambient_H_indices()
(0, 1, 3, 7)
The indices are the indices of the Hrepresentation::
The indices are the indices of the Hrepresentation.
``0`` corresponds to an equation and is not permitted as input::
sage: P.meet_of_facets(0)
Traceback (most recent call last):
...
ValueError: 0 is not a facet
ValueError: 0 is the index of an equation and not of an inequality
The input is flexible::
sage: P.meet_of_facets(P.facets()[-1], P.inequalities()[2], 7)
A 1-dimensional face of a Polyhedron in ZZ^5 defined as the convex hull of 2 vertices
The facets must be facets of ``self``::
sage: P = polytopes.cube(backend='ppl')
sage: Q = polytopes.cube(backend='field')
sage: f = P.facets()[0]
sage: P.meet_of_facets(f)
A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 4 vertices
sage: Q.meet_of_facets(f)
Traceback (most recent call last):
...
ValueError: not a facet of ``self``
sage: f = P.inequalities()[0]
sage: P.meet_of_facets(f)
A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 4 vertices
sage: Q.meet_of_facets(f)
Traceback (most recent call last):
...
ValueError: not a facet of ``self``
TESTS:
Equations are not considered by the combinatorial polyhedron.
Expand Down Expand Up @@ -7083,15 +7125,19 @@ def meet_of_facets(self, *facets):
new_indices = [0]*len(facets)
for i, facet in enumerate(facets):
if isinstance(facet, PolyhedronFace) and facet.dim() + 1 == self.dim():
if facet.polyhedron() is not self:
raise ValueError("not a facet of ``self``")
H_indices = facet.ambient_H_indices()
facet = H_indices[0] if H_indices[0] >= offset else H_indices[-1]

if facet in ZZ and facet >= offset:
new_indices[i] = facet - offset
elif isinstance(facet, Inequality):
if facet.polyhedron() is not self:
raise ValueError("not a facet of ``self``")
new_indices[i] = facet.index() - offset
else:
raise ValueError("{} is not a facet".format(facet))
raise ValueError("{} is the index of an equation and not of an inequality".format(facet))

return self.face_generator().meet_of_facets(*new_indices)

Expand Down

0 comments on commit fe428aa

Please sign in to comment.