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

Commit

Permalink
face lattice by CombinatorialPolyhedron
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Kliem committed Jun 14, 2019
1 parent 25407f8 commit c4ccf86
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 66 deletions.
49 changes: 13 additions & 36 deletions src/sage/geometry/polyhedron/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4340,7 +4340,7 @@ def combinatorial_polyhedron(self):
return CombinatorialPolyhedron(self)

@cached_method
def face_lattice(self):
def face_lattice(self, labels=True):
"""
Return the face-lattice poset.
Expand Down Expand Up @@ -4403,10 +4403,10 @@ def face_lattice(self):
sage: square = polytopes.hypercube(2)
sage: fl = square.face_lattice();fl
Finite lattice containing 10 elements with distinguished linear extension
sage: list(f.ambient_V_indices() for f in fl)
[(), (0,), (1,), (2,), (3,), (0, 1), (0, 2), (2, 3), (1, 3), (0, 1, 2, 3)]
sage: poset_element = fl[6]
Finite lattice containing 10 elements
sage: sorted(list(f.ambient_V_indices() for f in fl))
[(), (0,), (0, 1), (0, 1, 2, 3), (0, 2), (1,), (1, 3), (2,), (2, 3), (3,)]
sage: poset_element = sorted(fl)[4]
sage: a_face = poset_element
sage: a_face
A 1-dimensional face of a Polyhedron in ZZ^2 defined as the convex hull of 2 vertices
Expand Down Expand Up @@ -4473,39 +4473,16 @@ def face_lattice(self):
sage: [[ls.ambient_V_indices() for ls in lss] for lss in Polyhedron(lines=[(1,0)], vertices=[(0,0)]).face_lattice().level_sets()]
[[()], [(0, 1)]]
"""
coatom_to_Hindex = [ h.index() for h in self.inequality_generator() ]
Hindex_to_coatom = [None] * self.n_Hrepresentation()
for i in range(len(coatom_to_Hindex)):
Hindex_to_coatom[ coatom_to_Hindex[i] ] = i

atom_to_Vindex = [ v.index() for v in self.Vrep_generator() if not v.is_line() ]
Vindex_to_atom = [None] * self.n_Vrepresentation()
for i in range(len(atom_to_Vindex)):
Vindex_to_atom[ atom_to_Vindex[i] ] = i

atoms_incidences = [ tuple([ Hindex_to_coatom[h.index()]
for h in v.incident() if h.is_inequality() ])
for v in self.Vrepresentation() if not v.is_line() ]

coatoms_incidences = [ tuple([ Vindex_to_atom[v.index()]
for v in h.incident() if not v.is_line() ])
for h in self.Hrepresentation() if h.is_inequality() ]

atoms_vertices = [ Vindex_to_atom[v.index()] for v in self.vertex_generator() ]
equations = [ e.index() for e in self.equation_generator() ]
lines = [ l.index() for l in self.line_generator() ]
unlabeled = self.combinatorial_polyhedron().face_lattice()
if labels:
combinatorial_face_meth = self.combinatorial_polyhedron().face_by_face_lattice_index

def face_constructor(atoms, coatoms):
if len(atoms) == 0:
Vindices = ()
else:
Vindices = tuple(sorted([ atom_to_Vindex[i] for i in atoms ]+lines))
Hindices = tuple(sorted([ coatom_to_Hindex[i] for i in coatoms ]+equations))
return self._make_polyhedron_face(Vindices, Hindices)
def label_func(i):
return combinatorial_face_to_polyhedral_face(self, combinatorial_face_meth(i))

from sage.geometry.hasse_diagram import lattice_from_incidences
return lattice_from_incidences(atoms_incidences, coatoms_incidences,
face_constructor=face_constructor, required_atoms=atoms_vertices)
return unlabeled.relabel(label_func)
else:
return unlabeled

def face_iter(self, dimension=None, dual=None):
it = self.combinatorial_polyhedron().face_iter(dimension=dimension, dual=dual)
Expand Down
67 changes: 37 additions & 30 deletions src/sage/geometry/polyhedron/face.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
whole face lattice as a poset::
sage: P.face_lattice()
Finite lattice containing 28 elements with distinguished linear extension
Finite lattice containing 28 elements
The faces are printed in shorthand notation where each integer is the
index of a vertex/ray/line in the same order as the containing
Expand Down Expand Up @@ -378,19 +378,21 @@ def ambient_Hrepresentation(self, index=None):
EXAMPLES::
sage: square = polytopes.hypercube(2)
sage: for face in square.face_lattice():
....: print(face.ambient_Hrepresentation())
(An inequality (1, 0) x + 1 >= 0, An inequality (0, 1) x + 1 >= 0,
An inequality (-1, 0) x + 1 >= 0, An inequality (0, -1) x + 1 >= 0)
(An inequality (1, 0) x + 1 >= 0, An inequality (0, 1) x + 1 >= 0)
(An inequality (1, 0) x + 1 >= 0, An inequality (0, -1) x + 1 >= 0)
(An inequality (0, 1) x + 1 >= 0, An inequality (-1, 0) x + 1 >= 0)
(An inequality (-1, 0) x + 1 >= 0, An inequality (0, -1) x + 1 >= 0)
(An inequality (1, 0) x + 1 >= 0,)
(An inequality (0, 1) x + 1 >= 0,)
(An inequality (-1, 0) x + 1 >= 0,)
(An inequality (0, -1) x + 1 >= 0,)
()
sage: sorted([face.ambient_Hrepresentation()
....: for face in square.face_lattice()])
[(),
(An inequality (-1, 0) x + 1 >= 0,),
(An inequality (-1, 0) x + 1 >= 0, An inequality (0, -1) x + 1 >= 0),
(An inequality (0, -1) x + 1 >= 0,),
(An inequality (0, 1) x + 1 >= 0,),
(An inequality (0, 1) x + 1 >= 0, An inequality (-1, 0) x + 1 >= 0),
(An inequality (1, 0) x + 1 >= 0,),
(An inequality (1, 0) x + 1 >= 0, An inequality (0, -1) x + 1 >= 0),
(An inequality (1, 0) x + 1 >= 0, An inequality (0, 1) x + 1 >= 0),
(An inequality (1, 0) x + 1 >= 0,
An inequality (0, 1) x + 1 >= 0,
An inequality (-1, 0) x + 1 >= 0,
An inequality (0, -1) x + 1 >= 0)]
"""
if index is None:
return self._ambient_Hrepresentation
Expand Down Expand Up @@ -419,19 +421,21 @@ def ambient_Vrepresentation(self, index=None):
EXAMPLES::
sage: square = polytopes.hypercube(2)
sage: for fl in square.face_lattice():
....: print(fl.ambient_Vrepresentation())
()
(A vertex at (-1, -1),)
(A vertex at (-1, 1),)
(A vertex at (1, -1),)
(A vertex at (1, 1),)
(A vertex at (-1, -1), A vertex at (-1, 1))
(A vertex at (-1, -1), A vertex at (1, -1))
(A vertex at (1, -1), A vertex at (1, 1))
(A vertex at (-1, 1), A vertex at (1, 1))
(A vertex at (-1, -1), A vertex at (-1, 1),
A vertex at (1, -1), A vertex at (1, 1))
sage: sorted([face.ambient_Vrepresentation()
....: for face in square.face_lattice()])
[(),
(A vertex at (-1, -1),),
(A vertex at (-1, -1), A vertex at (-1, 1)),
(A vertex at (-1, -1),
A vertex at (-1, 1),
A vertex at (1, -1),
A vertex at (1, 1)),
(A vertex at (-1, -1), A vertex at (1, -1)),
(A vertex at (-1, 1),),
(A vertex at (-1, 1), A vertex at (1, 1)),
(A vertex at (1, -1),),
(A vertex at (1, -1), A vertex at (1, 1)),
(A vertex at (1, 1),)]
"""
if index is None:
return self._ambient_Vrepresentation
Expand All @@ -452,7 +456,7 @@ def n_ambient_Hrepresentation(self):
EXAMPLES::
sage: p = polytopes.cross_polytope(4)
sage: face = p.face_lattice()[10]
sage: face = sorted(p.face_lattice())[12]
sage: face
A 1-dimensional face of a Polyhedron in ZZ^4 defined as the convex hull of 2 vertices
sage: face.ambient_Hrepresentation()
Expand All @@ -479,7 +483,7 @@ def n_ambient_Vrepresentation(self):
EXAMPLES::
sage: p = polytopes.cross_polytope(4)
sage: face = p.face_lattice()[10]
sage: face = sorted(p.face_lattice())[12]
sage: face
A 1-dimensional face of a Polyhedron in ZZ^4 defined as the convex hull of 2 vertices
sage: face.ambient_Vrepresentation()
Expand Down Expand Up @@ -570,7 +574,7 @@ def dim(self):
EXAMPLES::
sage: fl = polytopes.dodecahedron().face_lattice()
sage: [ x.dim() for x in fl ]
sage: sorted([ x.dim() for x in fl ])
[-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3]
Expand Down Expand Up @@ -672,4 +676,7 @@ def combinatorial_face_to_polyhedral_face(polyhedron, combinatorial_face):
n_equations = polyhedron.n_equations()
H_indices = tuple(range(n_equations))
H_indices += tuple(x+n_equations for x in combinatorial_face.Hrepr(names=False))
if polyhedron.dimension() == 0:
# The polyhedron of dimension 0 has a facet, but not any inequalities.
H_indices = ()
return PolyhedronFace(polyhedron, V_indices, H_indices)

0 comments on commit c4ccf86

Please sign in to comment.