From 869a623f64754cd24a937de038486068215946b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Philippe=20Labb=C3=A9?= Date: Sun, 5 Mar 2017 12:51:42 +0100 Subject: [PATCH 1/4] First version --- src/sage/geometry/polyhedron/base.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/sage/geometry/polyhedron/base.py b/src/sage/geometry/polyhedron/base.py index 2cb1a18e80e..70305f515c3 100644 --- a/src/sage/geometry/polyhedron/base.py +++ b/src/sage/geometry/polyhedron/base.py @@ -2275,6 +2275,21 @@ def gale_transform(self): A_ker = A.right_kernel() return A_ker.basis_matrix().transpose().rows() + @cached_method + def normal_fan(self): + r""" + Return the normal fan of a compact full-dimensional rational polyhedron. + + OUTPUT: + + A complete fan of the ambient space as a + :class:`~sage.geometry.fan.RationalPolyhedralFan`. + """ + + return NormalFan(self) + + + def triangulate(self, engine='auto', connected=True, fine=False, regular=None, star=None): r""" Returns a triangulation of the polytope. From b13f5958fbc1b090342583b1bb819cc93507aa70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Philippe=20Labb=C3=A9?= Date: Mon, 6 Mar 2017 11:01:42 +0100 Subject: [PATCH 2/4] Added also face fan and reference --- src/doc/en/reference/references/index.rst | 5 ++++- src/sage/geometry/polyhedron/base.py | 27 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/doc/en/reference/references/index.rst b/src/doc/en/reference/references/index.rst index c9338391dd1..5e84ce89024 100644 --- a/src/doc/en/reference/references/index.rst +++ b/src/doc/en/reference/references/index.rst @@ -1640,9 +1640,12 @@ REFERENCES: constrained optimization. ACM Transactions on Mathematical Software, Vol 23, Num. 4, pp.550--560, 1997. -.. [Zie1998] G. Ziegler. *Shelling polyhedral 3-balls and +.. [Zie1998] G. M. Ziegler. *Shelling polyhedral 3-balls and 4-polytopes*. Discrete Comput. Geom. 19 (1998), 159-174. +.. [Zie2007] G. M. Ziegler. *Lectures on polytopes*, Volume + 152 of Graduate Texts in Mathematics, 7th printing of 1st edition, Springer, 2007. + .. [Zor2008] \A. Zorich "Explicit Jenkins-Strebel representatives of all strata of Abelian and quadratic differentials", Journal of Modern Dynamics, vol. 2, no 1, 139-185 (2008) diff --git a/src/sage/geometry/polyhedron/base.py b/src/sage/geometry/polyhedron/base.py index 70305f515c3..b8f45e54d9b 100644 --- a/src/sage/geometry/polyhedron/base.py +++ b/src/sage/geometry/polyhedron/base.py @@ -2284,11 +2284,38 @@ def normal_fan(self): A complete fan of the ambient space as a :class:`~sage.geometry.fan.RationalPolyhedralFan`. + + .. SEEALSO:: + + :meth:`~sage.geometry.polyhedron.base.face_fan`. + + REFERENCES: + + For more information, see Chapter 7 of [Zie2007]_. """ return NormalFan(self) + @cached_method + def face_fan(self): + r""" + Return the face fan of a compact full-dimensional rational polyhedron. + + OUTPUT: + + A complete fan of the ambient space as a + :class:`~sage.geometry.fan.RationalPolyhedralFan`. + + .. SEEALSO:: + + :meth:`~sage.geometry.polyhedron.base.normal_fan`. + + REFERENCES: + + For more information, see Chapter 7 of [Zie2007]_. + """ + return FaceFan(self) def triangulate(self, engine='auto', connected=True, fine=False, regular=None, star=None): r""" From 16648a857b2e1366e2cab37c6f30b9d48da58474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Philippe=20Labb=C3=A9?= Date: Tue, 7 Mar 2017 11:55:17 +0100 Subject: [PATCH 3/4] Added examples and fixed import --- src/sage/geometry/polyhedron/base.py | 74 ++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 4 deletions(-) diff --git a/src/sage/geometry/polyhedron/base.py b/src/sage/geometry/polyhedron/base.py index 5e68649aa2a..567f91a4049 100644 --- a/src/sage/geometry/polyhedron/base.py +++ b/src/sage/geometry/polyhedron/base.py @@ -463,7 +463,7 @@ def _is_subpolyhedron(self, other): for self_V in self.Vrepresentation()) def plot(self, - point=None, line=None, polygon=None, # None means unspecified by the user + point=None, line=None, polygon=None, # None means unspecified by the user wireframe='blue', fill='green', projection_direction=None, **kwds): @@ -1553,9 +1553,9 @@ def vertices_matrix(self, base_ring=None): if base_ring is None: base_ring = self.base_ring() m = matrix(base_ring, self.ambient_dim(), self.n_vertices()) - for i,v in enumerate(self.vertices()): + for i, v in enumerate(self.vertices()): for j in range(self.ambient_dim()): - m[j,i] = v[j] + m[j, i] = v[j] return m def ray_generator(self): @@ -2282,10 +2282,44 @@ def normal_fan(self): :meth:`~sage.geometry.polyhedron.base.face_fan`. + EXAMPLES:: + + sage: S = Polyhedron(vertices = [[0, 0], [1, 0], [0, 1]]) + sage: S.normal_fan() + Rational polyhedral fan in 2-d lattice N + + sage: C = polytopes.hypercube(4) + sage: NF = C.normal_fan(); NF + Rational polyhedral fan in 4-d lattice N + + Currently, it is only possible to get the normal fan of a bounded rational polytope:: + + sage: P = Polyhedron(rays = [[1, 0], [0, 1]]) + sage: P.normal_fan() + Traceback (most recent call last): + ... + NotImplementedError: the normal fan is only supported for polytopes (compact polyhedra). + + sage: Q = Polyhedron(vertices = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]) + sage: Q.normal_fan() + Traceback (most recent call last): + ... + ValueError: the normal fan is only defined for full-dimensional polytopes + + sage: R = Polyhedron(vertices = [[0, 0], [AA(sqrt(2)), 0], [0, AA(sqrt(2))]]) + sage: R.normal_fan() + Traceback (most recent call last): + ... + NotImplementedError: normal fan handles only polytopes over the rationals + REFERENCES: For more information, see Chapter 7 of [Zie2007]_. """ + from sage.geometry.fan import NormalFan + + if not QQ.has_coerce_map_from(self.base_ring()): + raise NotImplementedError('normal fan handles only polytopes over the rationals') return NormalFan(self) @@ -2298,15 +2332,47 @@ def face_fan(self): A complete fan of the ambient space as a :class:`~sage.geometry.fan.RationalPolyhedralFan`. - + .. SEEALSO:: :meth:`~sage.geometry.polyhedron.base.normal_fan`. + EXAMPLES:: + + sage: T = polytopes.cuboctahedron() + sage: T.face_fan() + Rational polyhedral fan in 3-d lattice M + + The polytope should contain the origin in the interior:: + + sage: P = Polyhedron(vertices = [[1/2, 1], [1, 1/2]]) + sage: P.face_fan() + Traceback (most recent call last): + ... + ValueError: face fans are defined only for polytopes containing the origin as an interior point! + + sage: Q = Polyhedron(vertices = [[-1, 1/2], [1, -1/2]]) + sage: Q.contains([0,0]) + True + sage: FF = Q.face_fan(); FF + Rational polyhedral fan in 2-d lattice M + + The polytope has to have rational coordinates:: + + sage: S = polytopes.dodecahedron() + sage: S.face_fan() + Traceback (most recent call last): + ... + NotImplementedError: face fan handles only polytopes over the rationals + REFERENCES: For more information, see Chapter 7 of [Zie2007]_. """ + from sage.geometry.fan import FaceFan + + if not QQ.has_coerce_map_from(self.base_ring()): + raise NotImplementedError('face fan handles only polytopes over the rationals') return FaceFan(self) From b5c49e6ec798b08ad4a9659791d7d80433919518 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Philippe=20Labb=C3=A9?= Date: Tue, 7 Mar 2017 12:07:42 +0100 Subject: [PATCH 4/4] Corrected doc of face_fan --- src/sage/geometry/polyhedron/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/geometry/polyhedron/base.py b/src/sage/geometry/polyhedron/base.py index 567f91a4049..a50f58d75bf 100644 --- a/src/sage/geometry/polyhedron/base.py +++ b/src/sage/geometry/polyhedron/base.py @@ -2326,11 +2326,11 @@ def normal_fan(self): @cached_method def face_fan(self): r""" - Return the face fan of a compact full-dimensional rational polyhedron. + Return the face fan of a compact rational polyhedron. OUTPUT: - A complete fan of the ambient space as a + A fan of the ambient space as a :class:`~sage.geometry.fan.RationalPolyhedralFan`. .. SEEALSO::