Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Fast Lattice Polygons using PPL.
See :mod:`ppl_lattice_polytope` for the implementation of arbitrary-dimensional lattice polytopes. This module is about the specialization to 2 dimensions. To be more precise, the :class:`LatticePolygon_PPL_class` is used if the ambient space is of dimension 2 or less. These all allow you to cyclically order (see :meth:`LatticePolygon_PPL_class.ordered_vertices`) the vertices, which is in general not possible in higher dimensions. """
######################################################################## # Copyright (C) 2012 Volker Braun <vbraun.name@gmail.com> # # Distributed under the terms of the GNU General Public License (GPL) # # http://www.gnu.org/licenses/ ########################################################################
Poly_Con_Relation) LatticeEuclideanGroupElement) LatticePolytope_PPL, LatticePolytope_PPL_class)
######################################################################## """ A lattice polygon
This includes 2-dimensional polytopes as well as degenerate (0 and 1-dimensional) lattice polygons. Any polytope in 2d is a polygon. """
def ordered_vertices(self): """ Return the vertices of a lattice polygon in cyclic order.
OUTPUT:
A tuple of vertices ordered along the perimeter of the polygon. The first point is arbitrary.
EXAMPLES::
sage: from sage.geometry.polyhedron.ppl_lattice_polytope import LatticePolytope_PPL sage: square = LatticePolytope_PPL((0,0), (1,1), (0,1), (1,0)) sage: square.vertices() ((0, 0), (0, 1), (1, 0), (1, 1)) sage: square.ordered_vertices() ((0, 0), (1, 0), (1, 1), (0, 1)) """ else:
""" Helper to pick an isomorphism of degenerate polygons
INPUT:
- ``polytope`` -- a :class:`LatticePolytope_PPL_class`. The polytope to compare with.
EXAMPLES::
sage: from sage.geometry.polyhedron.ppl_lattice_polytope import LatticePolytope_PPL, C_Polyhedron sage: L1 = LatticePolytope_PPL(C_Polyhedron(2, 'empty')) sage: L2 = LatticePolytope_PPL(C_Polyhedron(3, 'empty')) sage: iso = L1.find_isomorphism(L2) # indirect doctest sage: iso(L1) == L2 True sage: iso = L1._find_isomorphism_degenerate(L2) sage: iso(L1) == L2 True
sage: L1 = LatticePolytope_PPL((-1,4)) sage: L2 = LatticePolytope_PPL((2,1,5)) sage: iso = L1.find_isomorphism(L2) sage: iso(L1) == L2 True
sage: L1 = LatticePolytope_PPL((-1,), (3,)) sage: L2 = LatticePolytope_PPL((2,1,5), (2,-3,5)) sage: iso = L1.find_isomorphism(L2) sage: iso(L1) == L2 True
sage: L1 = LatticePolytope_PPL((-1,-1), (3,-1)) sage: L2 = LatticePolytope_PPL((2,1,5), (2,-3,5)) sage: iso = L1.find_isomorphism(L2) sage: iso(L1) == L2 True
sage: L1 = LatticePolytope_PPL((-1,2), (3,1)) sage: L2 = LatticePolytope_PPL((1,2,3),(1,2,4)) sage: iso = L1.find_isomorphism(L2) sage: iso(L1) == L2 True
sage: L1 = LatticePolytope_PPL((-1,2), (3,2)) sage: L2 = LatticePolytope_PPL((1,2,3),(1,2,4)) sage: L1.find_isomorphism(L2) Traceback (most recent call last): ... LatticePolytopesNotIsomorphicError: different number of integral points
sage: L1 = LatticePolytope_PPL((-1,2), (3,1)) sage: L2 = LatticePolytope_PPL((1,2,3),(1,2,5)) sage: L1.find_isomorphism(L2) Traceback (most recent call last): ... LatticePolytopesNotIsomorphicError: different number of integral points """ LatticePolytopesNotIsomorphicError # handle degenerate cases except TypeError: raise LatticePolytopesNotIsomorphicError('different lattice') raise LatticePolytopesNotIsomorphicError('different polygons')
polytope_origin, p_ray_left, p_ray_right): """ Helper to find an isomorphism of polygons
INPUT:
- ``polytope`` -- the lattice polytope to compare to.
- ``polytope_origin`` -- `\ZZ`-vector. a vertex of ``polytope``
- ``p_ray_left`` - vector. the vector from ``polytope_origin`` to one of its neighboring vertices.
- ``p_ray_right`` - vector. the vector from ``polytope_origin`` to the other neighboring vertices.
OUTPUT:
The element of the lattice Euclidean group that maps ``self`` to ``polytope`` with given origin and left/right neighboring vertex. A :class:`~sage.geometry.polyhedron.lattice_euclidean_group_element.LatticePolytopesNotIsomorphicError` is raised if no such isomorphism exists.
EXAMPLES::
sage: from sage.geometry.polyhedron.ppl_lattice_polytope import LatticePolytope_PPL sage: L1 = LatticePolytope_PPL((1,0),(0,1),(0,0)) sage: L2 = LatticePolytope_PPL((1,0,3),(0,1,0),(0,0,1)) sage: v0, v1, v2 = L2.vertices() sage: L1._find_cyclic_isomorphism_matching_edge(L2, v0, v1-v0, v2-v0) The map A*x+b with A= [ 0 1] [-1 -1] [ 1 3] b = (0, 1, 0) """ LatticePolytopesNotIsomorphicError p_ray_right.column()]) # three consecutive vertices r_right.column()])
""" Return a lattice isomorphism with ``polytope``.
INPUT:
- ``polytope`` -- a polytope, potentially higher-dimensional.
OUTPUT:
A :class:`~sage.geometry.polyhedron.lattice_euclidean_group_element.LatticeEuclideanGroupElement`. It is not necessarily invertible if the affine dimension of ``self`` or ``polytope`` is not two. A :class:`~sage.geometry.polyhedron.lattice_euclidean_group_element.LatticePolytopesNotIsomorphicError` is raised if no such isomorphism exists.
EXAMPLES::
sage: from sage.geometry.polyhedron.ppl_lattice_polytope import LatticePolytope_PPL sage: L1 = LatticePolytope_PPL((1,0),(0,1),(0,0)) sage: L2 = LatticePolytope_PPL((1,0,3),(0,1,0),(0,0,1)) sage: iso = L1.find_isomorphism(L2) sage: iso(L1) == L2 True
sage: L1 = LatticePolytope_PPL((0, 1), (3, 0), (0, 3), (1, 0)) sage: L2 = LatticePolytope_PPL((0,0,2,1),(0,1,2,0),(2,0,0,3),(2,3,0,0)) sage: iso = L1.find_isomorphism(L2) sage: iso(L1) == L2 True
The following polygons are isomorphic over `\QQ`, but not as lattice polytopes::
sage: L1 = LatticePolytope_PPL((1,0),(0,1),(-1,-1)) sage: L2 = LatticePolytope_PPL((0, 0), (0, 1), (1, 0)) sage: L1.find_isomorphism(L2) Traceback (most recent call last): ... LatticePolytopesNotIsomorphicError: different number of integral points sage: L2.find_isomorphism(L1) Traceback (most recent call last): ... LatticePolytopesNotIsomorphicError: different number of integral points """ LatticePolytopesNotIsomorphicError
polytope.minimized_generators())))
p_ray_left, p_ray_right) p_ray_right, p_ray_left)
""" Test if ``self`` and ``polytope`` are isomorphic.
INPUT:
- ``polytope`` -- a lattice polytope.
OUTPUT:
Boolean.
EXAMPLES::
sage: from sage.geometry.polyhedron.ppl_lattice_polytope import LatticePolytope_PPL sage: L1 = LatticePolytope_PPL((1,0),(0,1),(0,0)) sage: L2 = LatticePolytope_PPL((1,0,3),(0,1,0),(0,0,1)) sage: L1.is_isomorphic(L2) True """ LatticePolytopesNotIsomorphicError
""" Return a list of all lattice sub-polygons up to isomorphism.
OUTPUT:
All non-empty sub-lattice polytopes up to isomorphism. This includes ``self`` as improper sub-polytope, but excludes the empty polytope. Isomorphic sub-polytopes that can be embedded in different places are only returned once.
EXAMPLES::
sage: from sage.geometry.polyhedron.ppl_lattice_polytope import LatticePolytope_PPL sage: P1xP1 = LatticePolytope_PPL((1,0), (0,1), (-1,0), (0,-1)) sage: P1xP1.sub_polytopes() (A 2-dimensional lattice polytope in ZZ^2 with 4 vertices, A 2-dimensional lattice polytope in ZZ^2 with 3 vertices, A 2-dimensional lattice polytope in ZZ^2 with 3 vertices, A 1-dimensional lattice polytope in ZZ^2 with 2 vertices, A 1-dimensional lattice polytope in ZZ^2 with 2 vertices, A 0-dimensional lattice polytope in ZZ^2 with 1 vertex) """
""" Plot the lattice polygon.
OUTPUT:
A graphics object.
EXAMPLES::
sage: from sage.geometry.polyhedron.ppl_lattice_polytope import LatticePolytope_PPL sage: P = LatticePolytope_PPL((1,0), (0,1), (0,0), (2,2)) sage: P.plot() Graphics object consisting of 6 graphics primitives sage: LatticePolytope_PPL([0], [1]).plot() Graphics object consisting of 3 graphics primitives sage: LatticePolytope_PPL([0]).plot() Graphics object consisting of 2 graphics primitives """ for p in points) zorder=-1, thickness=2)
######################################################################## # # Reflexive lattice polygons and their subpolygons # ########################################################################
def polar_P2_polytope(): """ The polar of the `P^2` polytope
EXAMPLES::
sage: from sage.geometry.polyhedron.ppl_lattice_polygon import polar_P2_polytope sage: polar_P2_polytope() A 2-dimensional lattice polytope in ZZ^2 with 3 vertices sage: _.vertices() ((0, 0), (0, 3), (3, 0)) """
def polar_P1xP1_polytope(): r""" The polar of the `P^1 \times P^1` polytope
EXAMPLES::
sage: from sage.geometry.polyhedron.ppl_lattice_polygon import polar_P1xP1_polytope sage: polar_P1xP1_polytope() A 2-dimensional lattice polytope in ZZ^2 with 4 vertices sage: _.vertices() ((0, 0), (0, 2), (2, 0), (2, 2)) """
def polar_P2_112_polytope(): """ The polar of the `P^2[1,1,2]` polytope
EXAMPLES::
sage: from sage.geometry.polyhedron.ppl_lattice_polygon import polar_P2_112_polytope sage: polar_P2_112_polytope() A 2-dimensional lattice polytope in ZZ^2 with 3 vertices sage: _.vertices() ((0, 0), (0, 2), (4, 0)) """
def subpolygons_of_polar_P2(): """ The lattice sub-polygons of the polar `P^2` polytope
OUTPUT:
A tuple of lattice polytopes.
EXAMPLES::
sage: from sage.geometry.polyhedron.ppl_lattice_polygon import subpolygons_of_polar_P2 sage: len(subpolygons_of_polar_P2()) 27 """
def subpolygons_of_polar_P2_112(): """ The lattice sub-polygons of the polar `P^2[1,1,2]` polytope
OUTPUT:
A tuple of lattice polytopes.
EXAMPLES::
sage: from sage.geometry.polyhedron.ppl_lattice_polygon import subpolygons_of_polar_P2_112 sage: len(subpolygons_of_polar_P2_112()) 28 """
def subpolygons_of_polar_P1xP1(): r""" The lattice sub-polygons of the polar `P^1 \times P^1` polytope
OUTPUT:
A tuple of lattice polytopes.
EXAMPLES::
sage: from sage.geometry.polyhedron.ppl_lattice_polygon import subpolygons_of_polar_P1xP1 sage: len(subpolygons_of_polar_P1xP1()) 20 """
def sub_reflexive_polygons(): """ Return all lattice sub-polygons of reflexive polygons.
OUTPUT:
A tuple of all lattice sub-polygons. Each sub-polygon is returned as a pair sub-polygon, containing reflexive polygon.
EXAMPLES::
sage: from sage.geometry.polyhedron.ppl_lattice_polygon import sub_reflexive_polygons sage: l = sub_reflexive_polygons(); l[5] (A 2-dimensional lattice polytope in ZZ^2 with 6 vertices, A 2-dimensional lattice polytope in ZZ^2 with 3 vertices) sage: len(l) 33 """
|