Fast Lattice Polygons using PPL¶
See 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
LatticePolygon_PPL_class
is used if the ambient space is of
dimension 2 or less. These all allow you to cyclically order (see
LatticePolygon_PPL_class.ordered_vertices()
) the vertices, which
is in general not possible in higher dimensions.
- class sage.geometry.polyhedron.ppl_lattice_polygon.LatticePolygon_PPL_class[source]¶
Bases:
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.
- find_isomorphism(polytope)[source]¶
Return a lattice isomorphism with
polytope
.INPUT:
polytope
– a polytope, potentially higher-dimensional
OUTPUT:
A
LatticeEuclideanGroupElement
. It is not necessarily invertible if the affine dimension ofself
orpolytope
is not two. ALatticePolytopesNotIsomorphicError
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
>>> from sage.all import * >>> from sage.geometry.polyhedron.ppl_lattice_polytope import LatticePolytope_PPL >>> L1 = LatticePolytope_PPL((Integer(1),Integer(0)),(Integer(0),Integer(1)),(Integer(0),Integer(0))) >>> L2 = LatticePolytope_PPL((Integer(1),Integer(0),Integer(3)),(Integer(0),Integer(1),Integer(0)),(Integer(0),Integer(0),Integer(1))) >>> iso = L1.find_isomorphism(L2) >>> iso(L1) == L2 True >>> L1 = LatticePolytope_PPL((Integer(0), Integer(1)), (Integer(3), Integer(0)), (Integer(0), Integer(3)), (Integer(1), Integer(0))) >>> L2 = LatticePolytope_PPL((Integer(0),Integer(0),Integer(2),Integer(1)),(Integer(0),Integer(1),Integer(2),Integer(0)),(Integer(2),Integer(0),Integer(0),Integer(3)),(Integer(2),Integer(3),Integer(0),Integer(0))) >>> iso = L1.find_isomorphism(L2) >>> iso(L1) == L2 True
from sage.geometry.polyhedron.ppl_lattice_polytope import LatticePolytope_PPL L1 = LatticePolytope_PPL((1,0),(0,1),(0,0)) L2 = LatticePolytope_PPL((1,0,3),(0,1,0),(0,0,1)) iso = L1.find_isomorphism(L2) iso(L1) == L2 L1 = LatticePolytope_PPL((0, 1), (3, 0), (0, 3), (1, 0)) L2 = LatticePolytope_PPL((0,0,2,1),(0,1,2,0),(2,0,0,3),(2,3,0,0)) iso = L1.find_isomorphism(L2) iso(L1) == L2
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
>>> from sage.all import * >>> L1 = LatticePolytope_PPL((Integer(1),Integer(0)),(Integer(0),Integer(1)),(-Integer(1),-Integer(1))) >>> L2 = LatticePolytope_PPL((Integer(0), Integer(0)), (Integer(0), Integer(1)), (Integer(1), Integer(0))) >>> L1.find_isomorphism(L2) Traceback (most recent call last): ... LatticePolytopesNotIsomorphicError: different number of integral points >>> L2.find_isomorphism(L1) Traceback (most recent call last): ... LatticePolytopesNotIsomorphicError: different number of integral points
L1 = LatticePolytope_PPL((1,0),(0,1),(-1,-1)) L2 = LatticePolytope_PPL((0, 0), (0, 1), (1, 0)) L1.find_isomorphism(L2) L2.find_isomorphism(L1)
- is_isomorphic(polytope)[source]¶
Test if
self
andpolytope
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
>>> from sage.all import * >>> from sage.geometry.polyhedron.ppl_lattice_polytope import LatticePolytope_PPL >>> L1 = LatticePolytope_PPL((Integer(1),Integer(0)),(Integer(0),Integer(1)),(Integer(0),Integer(0))) >>> L2 = LatticePolytope_PPL((Integer(1),Integer(0),Integer(3)),(Integer(0),Integer(1),Integer(0)),(Integer(0),Integer(0),Integer(1))) >>> L1.is_isomorphic(L2) True
from sage.geometry.polyhedron.ppl_lattice_polytope import LatticePolytope_PPL L1 = LatticePolytope_PPL((1,0),(0,1),(0,0)) L2 = LatticePolytope_PPL((1,0,3),(0,1,0),(0,0,1)) L1.is_isomorphic(L2)
- ordered_vertices()[source]¶
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))
>>> from sage.all import * >>> from sage.geometry.polyhedron.ppl_lattice_polytope import LatticePolytope_PPL >>> square = LatticePolytope_PPL((Integer(0),Integer(0)), (Integer(1),Integer(1)), (Integer(0),Integer(1)), (Integer(1),Integer(0))) >>> square.vertices() ((0, 0), (0, 1), (1, 0), (1, 1)) >>> square.ordered_vertices() ((0, 0), (1, 0), (1, 1), (0, 1))
from sage.geometry.polyhedron.ppl_lattice_polytope import LatticePolytope_PPL square = LatticePolytope_PPL((0,0), (1,1), (0,1), (1,0)) square.vertices() square.ordered_vertices()
- plot()[source]¶
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() # needs sage.plot Graphics object consisting of 6 graphics primitives sage: LatticePolytope_PPL([0], [1]).plot() # needs sage.plot Graphics object consisting of 3 graphics primitives sage: LatticePolytope_PPL([0]).plot() # needs sage.plot Graphics object consisting of 2 graphics primitives
>>> from sage.all import * >>> from sage.geometry.polyhedron.ppl_lattice_polytope import LatticePolytope_PPL >>> P = LatticePolytope_PPL((Integer(1),Integer(0)), (Integer(0),Integer(1)), (Integer(0),Integer(0)), (Integer(2),Integer(2))) >>> P.plot() # needs sage.plot Graphics object consisting of 6 graphics primitives >>> LatticePolytope_PPL([Integer(0)], [Integer(1)]).plot() # needs sage.plot Graphics object consisting of 3 graphics primitives >>> LatticePolytope_PPL([Integer(0)]).plot() # needs sage.plot Graphics object consisting of 2 graphics primitives
from sage.geometry.polyhedron.ppl_lattice_polytope import LatticePolytope_PPL P = LatticePolytope_PPL((1,0), (0,1), (0,0), (2,2)) P.plot() # needs sage.plot LatticePolytope_PPL([0], [1]).plot() # needs sage.plot LatticePolytope_PPL([0]).plot() # needs sage.plot
- sub_polytopes()[source]¶
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)
>>> from sage.all import * >>> from sage.geometry.polyhedron.ppl_lattice_polytope import LatticePolytope_PPL >>> P1xP1 = LatticePolytope_PPL((Integer(1),Integer(0)), (Integer(0),Integer(1)), (-Integer(1),Integer(0)), (Integer(0),-Integer(1))) >>> 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)
from sage.geometry.polyhedron.ppl_lattice_polytope import LatticePolytope_PPL P1xP1 = LatticePolytope_PPL((1,0), (0,1), (-1,0), (0,-1)) P1xP1.sub_polytopes()
- sage.geometry.polyhedron.ppl_lattice_polygon.polar_P1xP1_polytope()[source]¶
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))
>>> from sage.all import * >>> from sage.geometry.polyhedron.ppl_lattice_polygon import polar_P1xP1_polytope >>> polar_P1xP1_polytope() A 2-dimensional lattice polytope in ZZ^2 with 4 vertices >>> _.vertices() ((0, 0), (0, 2), (2, 0), (2, 2))
from sage.geometry.polyhedron.ppl_lattice_polygon import polar_P1xP1_polytope polar_P1xP1_polytope() _.vertices()
- sage.geometry.polyhedron.ppl_lattice_polygon.polar_P2_112_polytope()[source]¶
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))
>>> from sage.all import * >>> from sage.geometry.polyhedron.ppl_lattice_polygon import polar_P2_112_polytope >>> polar_P2_112_polytope() A 2-dimensional lattice polytope in ZZ^2 with 3 vertices >>> _.vertices() ((0, 0), (0, 2), (4, 0))
from sage.geometry.polyhedron.ppl_lattice_polygon import polar_P2_112_polytope polar_P2_112_polytope() _.vertices()
- sage.geometry.polyhedron.ppl_lattice_polygon.polar_P2_polytope()[source]¶
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))
>>> from sage.all import * >>> from sage.geometry.polyhedron.ppl_lattice_polygon import polar_P2_polytope >>> polar_P2_polytope() A 2-dimensional lattice polytope in ZZ^2 with 3 vertices >>> _.vertices() ((0, 0), (0, 3), (3, 0))
from sage.geometry.polyhedron.ppl_lattice_polygon import polar_P2_polytope polar_P2_polytope() _.vertices()
- sage.geometry.polyhedron.ppl_lattice_polygon.sub_reflexive_polygons()[source]¶
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
>>> from sage.all import * >>> from sage.geometry.polyhedron.ppl_lattice_polygon import sub_reflexive_polygons >>> l = sub_reflexive_polygons(); l[Integer(5)] (A 2-dimensional lattice polytope in ZZ^2 with 6 vertices, A 2-dimensional lattice polytope in ZZ^2 with 3 vertices) >>> len(l) 33
from sage.geometry.polyhedron.ppl_lattice_polygon import sub_reflexive_polygons l = sub_reflexive_polygons(); l[5] len(l)
- sage.geometry.polyhedron.ppl_lattice_polygon.subpolygons_of_polar_P1xP1()[source]¶
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
>>> from sage.all import * >>> from sage.geometry.polyhedron.ppl_lattice_polygon import subpolygons_of_polar_P1xP1 >>> len(subpolygons_of_polar_P1xP1()) 20
from sage.geometry.polyhedron.ppl_lattice_polygon import subpolygons_of_polar_P1xP1 len(subpolygons_of_polar_P1xP1())
- sage.geometry.polyhedron.ppl_lattice_polygon.subpolygons_of_polar_P2()[source]¶
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
>>> from sage.all import * >>> from sage.geometry.polyhedron.ppl_lattice_polygon import subpolygons_of_polar_P2 >>> len(subpolygons_of_polar_P2()) 27
from sage.geometry.polyhedron.ppl_lattice_polygon import subpolygons_of_polar_P2 len(subpolygons_of_polar_P2())
- sage.geometry.polyhedron.ppl_lattice_polygon.subpolygons_of_polar_P2_112()[source]¶
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
>>> from sage.all import * >>> from sage.geometry.polyhedron.ppl_lattice_polygon import subpolygons_of_polar_P2_112 >>> len(subpolygons_of_polar_P2_112()) 28
from sage.geometry.polyhedron.ppl_lattice_polygon import subpolygons_of_polar_P2_112 len(subpolygons_of_polar_P2_112())