From 4a5c06e99ef6d3a727cc119cf77ee4230fe729b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Philippe=20Labb=C3=A9?= Date: Sun, 20 Jan 2019 15:12:35 +0100 Subject: [PATCH] first version --- src/sage/geometry/polyhedron/base.py | 141 +++++++++------ src/sage/geometry/polyhedron/constructor.py | 13 +- src/sage/geometry/polyhedron/face.py | 187 ++++++++++++++++++-- 3 files changed, 269 insertions(+), 72 deletions(-) diff --git a/src/sage/geometry/polyhedron/base.py b/src/sage/geometry/polyhedron/base.py index bfc5a5b297d..5aae1a769cd 100644 --- a/src/sage/geometry/polyhedron/base.py +++ b/src/sage/geometry/polyhedron/base.py @@ -3676,14 +3676,14 @@ def face_truncation(self, face, linear_coefficients=None, cut_frac=None): sage: vertex_trunc1 = Cube.face_truncation(Cube.faces(0)[0]) sage: vertex_trunc1.f_vector() (1, 10, 15, 7, 1) - sage: vertex_trunc1.faces(2) - (<0,1,2,3>, - <2,3,4,5>, - <1,2,5,6>, - <0,1,6,7,8>, - <4,5,6,7,9>, - <7,8,9>, - <0,3,4,8,9>) + sage: tuple(f.ambient_V_indices() for f in vertex_trunc1.faces(2)) + ((0, 1, 2, 3), + (2, 3, 4, 5), + (1, 2, 5, 6), + (0, 1, 6, 7, 8), + (4, 5, 6, 7, 9), + (7, 8, 9), + (0, 3, 4, 8, 9)) sage: vertex_trunc1.vertices() (A vertex at (1, -1, -1), A vertex at (1, 1, -1), @@ -3698,14 +3698,14 @@ def face_truncation(self, face, linear_coefficients=None, cut_frac=None): sage: vertex_trunc2 = Cube.face_truncation(Cube.faces(0)[0],cut_frac=1/2) sage: vertex_trunc2.f_vector() (1, 10, 15, 7, 1) - sage: vertex_trunc2.faces(2) - (<0,1,2,3>, - <2,3,4,5>, - <1,2,5,6>, - <0,1,6,7,8>, - <4,5,6,7,9>, - <7,8,9>, - <0,3,4,8,9>) + sage: tuple(f.ambient_V_indices() for f in vertex_trunc2.faces(2)) + ((0, 1, 2, 3), + (2, 3, 4, 5), + (1, 2, 5, 6), + (0, 1, 6, 7, 8), + (4, 5, 6, 7, 9), + (7, 8, 9), + (0, 3, 4, 8, 9)) sage: vertex_trunc2.vertices() (A vertex at (1, -1, -1), A vertex at (1, 1, -1), @@ -3732,14 +3732,14 @@ def face_truncation(self, face, linear_coefficients=None, cut_frac=None): sage: edge_trunc = Cube.face_truncation(Cube.faces(1)[0]) sage: edge_trunc.f_vector() (1, 10, 15, 7, 1) - sage: edge_trunc.faces(2) - (<0,1,2,3>, - <1,2,4,5>, - <4,5,6,7>, - <0,1,5,6,8>, - <2,3,4,7,9>, - <6,7,8,9>, - <0,3,8,9>) + sage: tuple(f.ambient_V_indices() for f in edge_trunc.faces(2)) + ((0, 1, 2, 3), + (1, 2, 4, 5), + (4, 5, 6, 7), + (0, 1, 5, 6, 8), + (2, 3, 4, 7, 9), + (6, 7, 8, 9), + (0, 3, 8, 9)) sage: face_trunc = Cube.face_truncation(Cube.faces(2)[0]) sage: face_trunc.vertices() (A vertex at (1, -1, -1), @@ -4057,7 +4057,7 @@ def _make_polyhedron_face(self, Vindices, Hindices): sage: square = polytopes.hypercube(2) sage: square._make_polyhedron_face((0,2), (1,)) - <0,2> + A 1-dimensional face of a Polyhedron in ZZ^2 defined as the convex hull of 2 vertices """ from sage.geometry.polyhedron.face import PolyhedronFace return PolyhedronFace(self, Vindices, Hindices) @@ -4125,16 +4125,16 @@ def face_lattice(self): EXAMPLES:: sage: square = polytopes.hypercube(2) - sage: square.face_lattice() + sage: fl = square.face_lattice();fl Finite lattice containing 10 elements with distinguished linear extension - sage: list(_) - [<>, <0>, <1>, <2>, <3>, <0,1>, <0,2>, <2,3>, <1,3>, <0,1,2,3>] - sage: poset_element = _[6] + 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] sage: a_face = poset_element sage: a_face - <0,2> - sage: a_face.dim() - 1 + A 1-dimensional face of a Polyhedron in ZZ^2 defined as the convex hull of 2 vertices + sage: a_face.ambient_V_indices() + (0, 2) sage: set(a_face.ambient_Vrepresentation()) == \ ....: set([square.Vrepresentation(0), square.Vrepresentation(2)]) True @@ -4169,33 +4169,67 @@ def face_lattice(self): Graphics object consisting of 27 graphics primitives sage: level_sets = polytopes.cross_polytope(2).face_lattice().level_sets() sage: level_sets[0], level_sets[-1] - ([<>], [<0,1,2,3>]) + ([A -1-dimensional face of a Polyhedron in ZZ^2], + [A 2-dimensional face of a Polyhedron in ZZ^2 defined as the convex hull of 4 vertices]) Various degenerate polyhedra:: sage: Polyhedron(vertices=[[0,0,0],[1,0,0],[0,1,0]]).face_lattice().level_sets() - [[<>], [<0>, <1>, <2>], [<0,1>, <0,2>, <1,2>], [<0,1,2>]] + [[A -1-dimensional face of a Polyhedron in ZZ^3], + [A 0-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 1 vertex, + A 0-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 1 vertex, + A 0-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 1 vertex], + [A 1-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 2 vertices, + A 1-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 2 vertices, + A 1-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 2 vertices], + [A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 3 vertices]] sage: Polyhedron(vertices=[(1,0,0),(0,1,0)], rays=[(0,0,1)]).face_lattice().level_sets() - [[<>], [<1>, <2>], [<0,1>, <0,2>, <1,2>], [<0,1,2>]] + [[A -1-dimensional face of a Polyhedron in ZZ^3], + [A 0-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 1 vertex, + A 0-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 1 vertex], + [A 1-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 1 vertex and 1 ray, + A 1-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 1 vertex and 1 ray, + A 1-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 2 vertices], + [A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 2 vertices and 1 ray]] sage: Polyhedron(rays=[(1,0,0),(0,1,0)], vertices=[(0,0,1)]).face_lattice().level_sets() - [[<>], [<0>], [<0,1>, <0,2>], [<0,1,2>]] + [[A -1-dimensional face of a Polyhedron in ZZ^3], + [A 0-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 1 vertex], + [A 1-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 1 vertex and 1 ray, + A 1-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 1 vertex and 1 ray], + [A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 1 vertex and 2 rays]] sage: Polyhedron(rays=[(1,0),(0,1)], vertices=[(0,0)]).face_lattice().level_sets() - [[<>], [<0>], [<0,1>, <0,2>], [<0,1,2>]] + [[A -1-dimensional face of a Polyhedron in ZZ^2], + [A 0-dimensional face of a Polyhedron in ZZ^2 defined as the convex hull of 1 vertex], + [A 1-dimensional face of a Polyhedron in ZZ^2 defined as the convex hull of 1 vertex and 1 ray, + A 1-dimensional face of a Polyhedron in ZZ^2 defined as the convex hull of 1 vertex and 1 ray], + [A 2-dimensional face of a Polyhedron in ZZ^2 defined as the convex hull of 1 vertex and 2 rays]] sage: Polyhedron(vertices=[(1,),(0,)]).face_lattice().level_sets() - [[<>], [<0>, <1>], [<0,1>]] + [[A -1-dimensional face of a Polyhedron in ZZ^1], + [A 0-dimensional face of a Polyhedron in ZZ^1 defined as the convex hull of 1 vertex, + A 0-dimensional face of a Polyhedron in ZZ^1 defined as the convex hull of 1 vertex], + [A 1-dimensional face of a Polyhedron in ZZ^1 defined as the convex hull of 2 vertices]] sage: Polyhedron(vertices=[(1,0,0),(0,1,0)], lines=[(0,0,1)]).face_lattice().level_sets() - [[<>], [<0,1>, <0,2>], [<0,1,2>]] + [[A -1-dimensional face of a Polyhedron in ZZ^3], + [A 1-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 1 vertex and 1 line, + A 1-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 1 vertex and 1 line], + [A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 2 vertices and 1 line]] sage: Polyhedron(lines=[(1,0,0)], vertices=[(0,0,1)]).face_lattice().level_sets() - [[<>], [<0,1>]] + [[A -1-dimensional face of a Polyhedron in ZZ^3], + [A 1-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 1 vertex and 1 line]] sage: Polyhedron(lines=[(1,0),(0,1)], vertices=[(0,0)]).face_lattice().level_sets() - [[<>], [<0,1,2>]] + [[A -1-dimensional face of a Polyhedron in ZZ^2], + [A 2-dimensional face of a Polyhedron in ZZ^2 defined as the convex hull of 1 vertex and 2 lines]] sage: Polyhedron(lines=[(1,0)], rays=[(0,1)], vertices=[(0,0)])\ ....: .face_lattice().level_sets() - [[<>], [<0,1>], [<0,1,2>]] + [[A -1-dimensional face of a Polyhedron in ZZ^2], + [A 1-dimensional face of a Polyhedron in ZZ^2 defined as the convex hull of 1 vertex and 1 line], + [A 2-dimensional face of a Polyhedron in ZZ^2 defined as the convex hull of 1 vertex, 1 ray, 1 line]] sage: Polyhedron(vertices=[(0,)], lines=[(1,)]).face_lattice().level_sets() - [[<>], [<0,1>]] + [[A -1-dimensional face of a Polyhedron in ZZ^1], + [A 1-dimensional face of a Polyhedron in ZZ^1 defined as the convex hull of 1 vertex and 1 line]] sage: Polyhedron(lines=[(1,0)], vertices=[(0,0)]).face_lattice().level_sets() - [[<>], [<0,1>]] + [[A -1-dimensional face of a Polyhedron in ZZ^2], + [A 1-dimensional face of a Polyhedron in ZZ^2 defined as the convex hull of 1 vertex and 1 line]] """ coatom_to_Hindex = [ h.index() for h in self.inequality_generator() ] Hindex_to_coatom = [None] * self.n_Hrepresentation() @@ -4253,10 +4287,15 @@ def faces(self, face_dimension): facets of the four-dimensional hypercube:: sage: p = polytopes.hypercube(4) - sage: p.faces(3) - (<0,1,2,3,4,5,6,7>, <0,1,2,3,8,9,10,11>, <0,1,4,5,8,9,12,13>, - <0,2,4,6,8,10,12,14>, <2,3,6,7,10,11,14,15>, <8,9,10,11,12,13,14,15>, - <4,5,6,7,12,13,14,15>, <1,3,5,7,9,11,13,15>) + sage: list(f.ambient_V_indices() for f in p.faces(3)) + [(0, 1, 2, 3, 4, 5, 6, 7), + (0, 1, 2, 3, 8, 9, 10, 11), + (0, 1, 4, 5, 8, 9, 12, 13), + (0, 2, 4, 6, 8, 10, 12, 14), + (2, 3, 6, 7, 10, 11, 14, 15), + (8, 9, 10, 11, 12, 13, 14, 15), + (4, 5, 6, 7, 12, 13, 14, 15), + (1, 3, 5, 7, 9, 11, 13, 15)] sage: face = p.faces(3)[0] sage: face.ambient_Hrepresentation() @@ -4295,9 +4334,9 @@ def faces(self, face_dimension): sage: pr.faces(4) () sage: pr.faces(3) - (<0,1,2,3>,) + (A 3-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 1 vertex, 1 ray, 2 lines,) sage: pr.faces(2) - (<0,1,2>,) + (A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 1 vertex and 2 lines,) sage: pr.faces(1) () sage: pr.faces(0) @@ -4610,7 +4649,7 @@ def one_point_suspension(self, vertex): sage: cube.one_point_suspension(e) Traceback (most recent call last): ... - TypeError: The vertex <0,1> should be a Vertex or PolyhedronFace of dimension 0 + TypeError: The vertex A 1-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 2 vertices should be a Vertex or PolyhedronFace of dimension 0 """ from sage.geometry.polyhedron.representation import Vertex from sage.geometry.polyhedron.face import PolyhedronFace diff --git a/src/sage/geometry/polyhedron/constructor.py b/src/sage/geometry/polyhedron/constructor.py index 98b6bc93804..910b86e6059 100644 --- a/src/sage/geometry/polyhedron/constructor.py +++ b/src/sage/geometry/polyhedron/constructor.py @@ -100,11 +100,16 @@ sage: strip.lines() (A line in the direction (0, 1),) sage: strip.faces(1) - (<0,1>, <0,2>) + (A 1-dimensional face of a Polyhedron in ZZ^2 defined as the convex hull of 1 vertex and 1 line, + A 1-dimensional face of a Polyhedron in ZZ^2 defined as the convex hull of 1 vertex and 1 line) sage: for face in strip.faces(1): - ....: print("{} = {}".format(face, face.as_polyhedron().Vrepresentation())) - <0,1> = (A line in the direction (0, 1), A vertex at (-1, 0)) - <0,2> = (A line in the direction (0, 1), A vertex at (1, 0)) + ....: print(face.ambient_V_indices()) + (0, 1) + (0, 2) + sage: for face in strip.faces(1): + ....: print("{} = {}".format(face.ambient_V_indices(), face.as_polyhedron().Vrepresentation())) + (0, 1) = (A line in the direction (0, 1), A vertex at (-1, 0)) + (0, 2) = (A line in the direction (0, 1), A vertex at (1, 0)) EXAMPLES:: diff --git a/src/sage/geometry/polyhedron/face.py b/src/sage/geometry/polyhedron/face.py index 15cf2cccc6e..ba7ccbe7af4 100644 --- a/src/sage/geometry/polyhedron/face.py +++ b/src/sage/geometry/polyhedron/face.py @@ -8,11 +8,29 @@ sage: P = polytopes.cross_polytope(3) sage: P.faces(3) - (<0,1,2,3,4,5>,) + (A 3-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 6 vertices,) sage: P.faces(2) - (<0,1,2>, <0,1,3>, <0,2,4>, <0,3,4>, <3,4,5>, <2,4,5>, <1,3,5>, <1,2,5>) + (A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 3 vertices, + A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 3 vertices, + A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 3 vertices, + A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 3 vertices, + A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 3 vertices, + A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 3 vertices, + A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 3 vertices, + A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 3 vertices) sage: P.faces(1) - (<0,1>, <0,2>, <1,2>, <0,3>, <1,3>, <0,4>, <2,4>, <3,4>, <2,5>, <3,5>, <4,5>, <1,5>) + (A 1-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 2 vertices, + A 1-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 2 vertices, + A 1-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 2 vertices, + A 1-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 2 vertices, + A 1-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 2 vertices, + A 1-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 2 vertices, + A 1-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 2 vertices, + A 1-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 2 vertices, + A 1-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 2 vertices, + A 1-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 2 vertices, + A 1-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 2 vertices, + A 1-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 2 vertices) or :meth:`~sage.geometry.polyhedron.base.face_lattice` to get the whole face lattice as a poset:: @@ -25,7 +43,9 @@ Polyhedron's :meth:`~sage.geometry.polyhedron.base.Vrepresentation` :: sage: face = P.faces(1)[3]; face - <0,3> + A 1-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 2 vertices + sage: face.ambient_V_indices() + (0, 3) sage: P.Vrepresentation(0) A vertex at (-1, 0, 0) sage: P.Vrepresentation(3) @@ -93,9 +113,11 @@ class PolyhedronFace(SageObject): sage: from sage.geometry.polyhedron.face import PolyhedronFace sage: face = PolyhedronFace(octahedron, face_v_indices, face_h_indices) sage: face - <0,1,2> + A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 3 vertices sage: face.dim() 2 + sage: face.ambient_V_indices() + (0, 1, 2) sage: face.ambient_Hrepresentation() (An inequality (1, 1, 1) x + 1 >= 0,) sage: face.ambient_Vrepresentation() @@ -125,7 +147,7 @@ def __init__(self, polyhedron, V_indices, H_indices): sage: from sage.geometry.polyhedron.face import PolyhedronFace sage: PolyhedronFace(Polyhedron(), [], []) # indirect doctest - <> + A -1-dimensional face of a Polyhedron in ZZ^0 """ self._polyhedron = polyhedron self._ambient_Vrepresentation_indices = tuple(V_indices) @@ -182,6 +204,24 @@ def vertices(self): """ return tuple(self.vertex_generator()) + @cached_method + def n_vertices(self): + """ + Return the number of vertices of the face. + + OUTPUT: + + Integer. + + EXAMPLES:: + + sage: Q = polytopes.cross_polytope(3) + sage: face = Q.faces(2)[0] + sage: face.n_vertices() + 3 + """ + return len(self.vertices()) + def ray_generator(self): """ Return a generator for the rays of the face. @@ -215,6 +255,24 @@ def rays(self): """ return tuple(self.ray_generator()) + @cached_method + def n_rays(self): + """ + Return the number of rays of the face. + + OUTPUT: + + Integer. + + EXAMPLES:: + + sage: p = Polyhedron(ieqs = [[0,0,0,1],[0,0,1,0],[1,1,0,0]]) + sage: face = p.faces(2)[0] + sage: face.n_rays() + 2 + """ + return len(self.rays()) + def line_generator(self): """ Return a generator for the lines of the face. @@ -247,6 +305,23 @@ def lines(self): """ return tuple(self.line_generator()) + @cached_method + def n_lines(self): + """ + Return the number of lines of the face. + + OUTPUT: + + Integer. + + EXAMPLES:: + + sage: p = Polyhedron(rays = [[1,0],[-1,0],[0,1],[1,1]], vertices = [[-2,-2],[2,3]]) + sage: p.n_lines() + 1 + """ + return len(self.lines()) + def __richcmp__(self, other, op): """ Compare ``self`` and ``other``. @@ -378,7 +453,7 @@ def n_ambient_Hrepresentation(self): sage: p = polytopes.cross_polytope(4) sage: face = p.face_lattice()[10] sage: face - <0,2> + A 1-dimensional face of a Polyhedron in ZZ^4 defined as the convex hull of 2 vertices sage: face.ambient_Hrepresentation() (An inequality (1, -1, 1, -1) x + 1 >= 0, An inequality (1, 1, 1, 1) x + 1 >= 0, @@ -405,7 +480,7 @@ def n_ambient_Vrepresentation(self): sage: p = polytopes.cross_polytope(4) sage: face = p.face_lattice()[10] sage: face - <0,2> + A 1-dimensional face of a Polyhedron in ZZ^4 defined as the convex hull of 2 vertices sage: face.ambient_Vrepresentation() (A vertex at (-1, 0, 0, 0), A vertex at (0, 0, -1, 0)) sage: face.n_ambient_Vrepresentation() @@ -413,6 +488,62 @@ def n_ambient_Vrepresentation(self): """ return len(self.ambient_Vrepresentation()) + def ambient_H_indices(self): + """ + Return the indices of the H-representation objects of the + ambient polyhedron that make up the H-representation of ``self``. + + See also :meth:`ambient_Hrepresentation`. + + OUTPUT: + + Tuple of indices + + EXAMPLES:: + + sage: Q = polytopes.cross_polytope(3) + sage: F = Q.faces(1) + sage: [f.ambient_H_indices() for f in F] + [(1, 2), + (2, 3), + (2, 7), + (0, 1), + (1, 6), + (0, 3), + (3, 4), + (0, 5), + (4, 7), + (5, 6), + (4, 5), + (6, 7)] + """ + return self._ambient_Hrepresentation_indices + + def ambient_V_indices(self): + """ + Return the indices of the V-representation objects of the + ambient polyhedron that make up the V-representation of ``self``. + + See also :meth:`ambient_Vrepresentation`. + + OUTPUT: + + Tuple of indices + + EXAMPLES:: + + sage: P = polytopes.cube() + sage: F = P.faces(2) + sage: [f.ambient_V_indices() for f in F] + [(0, 1, 2, 3), + (0, 1, 4, 5), + (0, 2, 4, 6), + (1, 3, 5, 7), + (2, 3, 6, 7), + (4, 5, 6, 7)] + """ + return self._ambient_Vrepresentation_indices + def ambient_dim(self): r""" Return the dimension of the containing polyhedron. @@ -443,7 +574,7 @@ def dim(self): 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] """ - if self.n_ambient_Vrepresentation()==0: + if self.n_ambient_Vrepresentation() == 0: return -1 else: origin = vector(self.ambient_Vrepresentation(0)) @@ -463,12 +594,34 @@ def _repr_(self): sage: square = polytopes.hypercube(2) sage: a_face = list( square.face_lattice() )[8] sage: a_face.__repr__() - '<1,3>' + 'A 1-dimensional face of a Polyhedron in ZZ^2 defined as the convex hull of 2 vertices' """ - s = '<' - s += ','.join([ str(v.index()) for v in self.ambient_Vrepresentation() ]) - s += '>' - return s + desc = '' + desc += 'A ' + repr(self.dim()) + '-dimensional face' + desc += ' of a Polyhedron in ' + desc += self.polyhedron().parent()._repr_ambient_module() + + if self.n_vertices() > 0: + desc += ' defined as the convex hull of ' + desc += repr(self.n_vertices()) + if self.n_vertices() == 1: desc += ' vertex' + else: desc += ' vertices' + + if self.n_rays() > 0: + if self.n_lines() > 0: desc += ", " + else: desc += " and " + desc += repr(self.n_rays()) + if self.n_rays() == 1: desc += ' ray' + else: desc += ' rays' + + if self.n_lines() > 0: + if self.n_rays() > 0: desc += ", " + else: desc += " and " + desc += repr(self.n_lines()) + if self.n_lines() == 1: desc += ' line' + else: desc += ' lines' + + return desc def polyhedron(self): """ @@ -478,9 +631,9 @@ def polyhedron(self): sage: P = polytopes.cross_polytope(3); P A 3-dimensional polyhedron in ZZ^3 defined as the convex hull of 6 vertices - sage: face = P.faces(2)[3] + sage: face = P.faces(2)[3] sage: face - <0,3,4> + A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 3 vertices sage: face.polyhedron() A 3-dimensional polyhedron in ZZ^3 defined as the convex hull of 6 vertices """ @@ -501,7 +654,7 @@ def as_polyhedron(self): A 3-dimensional polyhedron in ZZ^3 defined as the convex hull of 6 vertices sage: face = P.faces(2)[3] sage: face - <0,3,4> + A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 3 vertices sage: face.as_polyhedron() A 2-dimensional polyhedron in ZZ^3 defined as the convex hull of 3 vertices