Path: blob/master/src/sage/geometry/polyhedron/lattice_euclidean_group_element.py
8817 views
"""1Lattice Euclidean Group Elements23The classes here are used to return particular isomorphisms of4:class:`PPL lattice5polytopes<sage.geometry.polyhedron.ppl_lattice_polytope.LatticePolytope_PPL_class>`.6"""7########################################################################8# Copyright (C) 2012 Volker Braun <[email protected]>9#10# Distributed under the terms of the GNU General Public License (GPL)11#12# http://www.gnu.org/licenses/13########################################################################1415from sage.structure.sage_object import SageObject16from sage.rings.integer_ring import ZZ17from sage.modules.all import vector18from sage.matrix.constructor import matrix192021########################################################################22class LatticePolytopeError(Exception):23"""24Base class for errors from lattice polytopes25"""26pass272829########################################################################30class LatticePolytopesNotIsomorphicError(LatticePolytopeError):31"""32Raised when two lattice polytopes are not isomorphic.33"""34pass353637########################################################################38class LatticePolytopeNoEmbeddingError(LatticePolytopeError):39"""40Raised when no embedding of the desired kind can be found.41"""42pass434445########################################################################46class LatticeEuclideanGroupElement(SageObject):4748def __init__(self, A, b):49"""50An element of the lattice Euclidean group.5152Note that this is just intended as a container for results from53LatticePolytope_PPL. There is no group-theoretic functionality to54speak of.5556EXAMPLES::5758sage: from sage.geometry.polyhedron.ppl_lattice_polytope \59....: import LatticePolytope_PPL, C_Polyhedron60sage: from sage.geometry.polyhedron.lattice_euclidean_group_element \61....: import LatticeEuclideanGroupElement62sage: M = LatticeEuclideanGroupElement([[1,2],[2,3],[-1,2]], [1,2,3])63sage: M64The map A*x+b with A=65[ 1 2]66[ 2 3]67[-1 2]68b =69(1, 2, 3)70sage: M._A71[ 1 2]72[ 2 3]73[-1 2]74sage: M._b75(1, 2, 3)76sage: M(vector([0,0]))77(1, 2, 3)78sage: M(LatticePolytope_PPL((0,0),(1,0),(0,1)))79A 2-dimensional lattice polytope in ZZ^3 with 3 vertices80sage: _.vertices()81((1, 2, 3), (2, 4, 2), (3, 5, 5))82"""83self._A = matrix(ZZ, A)84self._b = vector(ZZ, b)85assert self._A.nrows() == self._b.degree()8687def __call__(self, x):88"""89Return the image of ``x``9091INPUT:9293- ``x`` -- a vector or lattice polytope.9495EXAMPLES::9697sage: from sage.geometry.polyhedron.ppl_lattice_polytope \98....: import LatticePolytope_PPL, C_Polyhedron99sage: from sage.geometry.polyhedron.lattice_euclidean_group_element \100....: import LatticeEuclideanGroupElement101sage: M = LatticeEuclideanGroupElement([[1,2],[2,3],[-1,2]], [1,2,3])102sage: M(vector(ZZ, [11,13]))103(38, 63, 18)104sage: M(LatticePolytope_PPL((0,0),(1,0),(0,1)))105A 2-dimensional lattice polytope in ZZ^3 with 3 vertices106"""107from sage.geometry.polyhedron.ppl_lattice_polytope import (108LatticePolytope_PPL, LatticePolytope_PPL_class)109if isinstance(x, LatticePolytope_PPL_class):110if x.is_empty():111from sage.libs.ppl import C_Polyhedron112return LatticePolytope_PPL(C_Polyhedron(self._b.degree(),113'empty'))114return LatticePolytope_PPL(*[self(v) for v in x.vertices()])115pass116v = self._A*x+self._b117v.set_immutable()118119return v120121def _repr_(self):122"""123Return a string representation124125EXAMPLES::126127sage: from sage.geometry.polyhedron.lattice_euclidean_group_element \128....: import LatticeEuclideanGroupElement129sage: M = LatticeEuclideanGroupElement([[1,2],[2,3],[-1,2]], [1,2,3])130sage: M._repr_()131'The map A*x+b with A=\n[ 1 2]\n[ 2 3]\n[-1 2]\nb = \n(1, 2, 3)'132"""133s = 'The map A*x+b with A=\n'+str(self._A)134s += '\nb = \n'+str(self._b)135return s136137def domain_dim(self):138"""139Return the dimension of the domain lattice140141EXAMPLES::142143sage: from sage.geometry.polyhedron.lattice_euclidean_group_element \144....: import LatticeEuclideanGroupElement145sage: M = LatticeEuclideanGroupElement([[1,2],[2,3],[-1,2]], [1,2,3])146sage: M147The map A*x+b with A=148[ 1 2]149[ 2 3]150[-1 2]151b =152(1, 2, 3)153sage: M.domain_dim()1542155"""156return self._A.ncols()157158def codomain_dim(self):159"""160Return the dimension of the codomain lattice161162EXAMPLES::163164sage: from sage.geometry.polyhedron.lattice_euclidean_group_element \165....: import LatticeEuclideanGroupElement166sage: M = LatticeEuclideanGroupElement([[1,2],[2,3],[-1,2]], [1,2,3])167sage: M168The map A*x+b with A=169[ 1 2]170[ 2 3]171[-1 2]172b =173(1, 2, 3)174sage: M.codomain_dim()1753176177Note that this is not the same as the rank. In fact, the178codomain dimension depends only on the matrix shape, and not179on the rank of the linear mapping::180181sage: zero_map = LatticeEuclideanGroupElement([[0,0],[0,0],[0,0]], [0,0,0])182sage: zero_map.codomain_dim()1833184"""185return self._A.nrows()186187188