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

Commit

Permalink
Merge branch 'public/28605' of git://trac.sagemath.org/sage into publ…
Browse files Browse the repository at this point in the history
…ic/28606
  • Loading branch information
Jonathan Kliem committed Oct 18, 2019
2 parents c8c49c5 + 9b5bcaa commit 6fb97dc
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ List of Polyhedron methods
:widths: 30, 70
:delim: |

:meth:`~sage.geometry.polyhedron.base.Polyhedron_base.combinatorial_polyhedron` | the combinatorial polyhedron
:meth:`~sage.geometry.polyhedron.base.Polyhedron_base.face_lattice` | the face lattice
:meth:`~sage.geometry.polyhedron.base.Polyhedron_base.combinatorial_automorphism_group` | the automorphism group of the underlying combinatorial polytope
:meth:`~sage.geometry.polyhedron.base.Polyhedron_base.graph`, :meth:`~sage.geometry.polyhedron.base.Polyhedron_base.vertex_graph` | underlying graph
Expand Down
23 changes: 22 additions & 1 deletion src/sage/geometry/polyhedron/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2731,6 +2731,27 @@ def is_compact(self):
"""
return self.n_rays() == 0 and self.n_lines() == 0

@cached_method
def combinatorial_polyhedron(self):
r"""
Return the combinatorial type of ``self``.
See :class:`sage.geometry.polyhedron.combinatorial_polyhedron.base.CombinatorialPolyhedron`.
EXAMPLES::
sage: polytopes.cube().combinatorial_polyhedron()
A 3-dimensional combinatorial polyhedron with 6 facets
sage: polytopes.cyclic_polytope(4,10).combinatorial_polyhedron()
A 4-dimensional combinatorial polyhedron with 35 facets
sage: Polyhedron(rays=[[0,1], [1,0]]).combinatorial_polyhedron()
A 2-dimensional combinatorial polyhedron with 2 facets
"""
from sage.geometry.polyhedron.combinatorial_polyhedron.base import CombinatorialPolyhedron
return CombinatorialPolyhedron(self)

def is_simple(self):
"""
Test for simplicity of a polytope.
Expand Down Expand Up @@ -5325,7 +5346,7 @@ def f_vector(self):
sage: p.f_vector()
(1, 7, 12, 7, 1)
"""
return vector(ZZ, [len(x) for x in self.face_lattice().level_sets()])
return self.combinatorial_polyhedron().f_vector()

def vertex_graph(self):
"""
Expand Down
48 changes: 35 additions & 13 deletions src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ cdef class CombinatorialPolyhedron(SageObject):
an integer::
sage: CombinatorialPolyhedron(-1).f_vector()
(1,)
(1)
sage: CombinatorialPolyhedron(0).f_vector()
(1, 1)
sage: CombinatorialPolyhedron(5).f_vector()
Expand All @@ -206,7 +206,9 @@ cdef class CombinatorialPolyhedron(SageObject):
sage: C
A 2-dimensional combinatorial polyhedron with 2 facets
sage: C.f_vector()
(1, 1, 2, 1)
Traceback (most recent call last):
...
ValueError: not all vertices are intersections of facets
sage: C.vertices()
(A line in the direction (0, 1), A vertex at (1, 0), A vertex at (-1, 0))
Expand Down Expand Up @@ -252,15 +254,6 @@ cdef class CombinatorialPolyhedron(SageObject):
(A vertex at (0, 0),)
sage: data = P.incidence_matrix()
sage: vert = P.Vrepresentation()
sage: C = CombinatorialPolyhedron(data, Vrepr=vert)
sage: C
A 2-dimensional combinatorial polyhedron with 2 facets
sage: C.f_vector()
(1, 1, 2, 1)
sage: C.vertices()
(A vertex at (0, 0),
A ray in the direction (0, 1),
A ray in the direction (1, 0))
sage: far_face = [i for i in range(3) if not P.Vrepresentation()[i].is_vertex()]
sage: C = CombinatorialPolyhedron(data, Vrepr=vert, unbounded=True, far_face=far_face)
sage: C
Expand All @@ -272,7 +265,19 @@ cdef class CombinatorialPolyhedron(SageObject):
sage: CombinatorialPolyhedron(3r)
A 3-dimensional combinatorial polyhedron with 0 facets
Check that on wrong input subsequent calls of ``f_vector`` fail::
sage: data = P.incidence_matrix()
sage: vert = P.Vrepresentation()
sage: C = CombinatorialPolyhedron(data, Vrepr=vert)
sage: C.f_vector()
Traceback (most recent call last):
...
ValueError: not all vertices are intersections of facets
sage: C.f_vector()
Traceback (most recent call last):
...
ValueError: not all vertices are intersections of facets
"""
def __init__(self, data, Vrepr=None, facets=None, unbounded=False, far_face=None):
r"""
Expand Down Expand Up @@ -759,7 +764,7 @@ cdef class CombinatorialPolyhedron(SageObject):
sage: C = CombinatorialPolyhedron(-1)
sage: C.f_vector()
(1,)
(1)
sage: C.n_facets()
0
Expand Down Expand Up @@ -1117,12 +1122,19 @@ cdef class CombinatorialPolyhedron(SageObject):
sage: C = CombinatorialPolyhedron(P)
sage: C.f_vector()
(1, 10, 45, 120, 185, 150, 50, 1)
TESTS::
sage: type(C.f_vector())
<type 'sage.modules.vector_integer_dense.Vector_integer_dense'>
"""
if not self._f_vector:
self._compute_f_vector()
if not self._f_vector:
raise ValueError("could not determine f_vector")
return self._f_vector
from sage.modules.free_module_element import vector
from sage.rings.all import ZZ
return vector(ZZ, self._f_vector)

def face_iter(self, dimension=None, dual=None):
r"""
Expand Down Expand Up @@ -1526,11 +1538,21 @@ cdef class CombinatorialPolyhedron(SageObject):

# Copy ``f_vector``.
if dual:
if dim > 1 and f_vector[1] < self.n_facets():
# The input seemed to be wrong.
raise ValueError("not all facets are joins of vertices")

# We have computed the ``f_vector`` of the dual.
# Reverse it:
self._f_vector = \
tuple(smallInteger(f_vector[dim+1-i]) for i in range(dim+2))

else:
if not self.unbounded() and dim > 1 \
and f_vector[1] < self.length_Vrepr() - len(self.far_face_tuple()):
# The input seemed to be wrong.
raise ValueError("not all vertices are intersections of facets")

self._f_vector = tuple(smallInteger(f_vector[i]) for i in range(dim+2))

cdef int _compute_edges(self, dual) except -1:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/geometry/polyhedron/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ def truncated_dodecahedron(self, exact=True, base_ring=None, backend=None):
sage: td.f_vector()
Traceback (most recent call last):
...
KeyError: ...
ValueError: not all vertices are intersections of facets
sage: td.base_ring()
Real Double Field
Expand Down

0 comments on commit 6fb97dc

Please sign in to comment.