Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/sage/geometry/polyhedron/lattice_euclidean_group_element.py
8817 views
1
"""
2
Lattice Euclidean Group Elements
3
4
The classes here are used to return particular isomorphisms of
5
:class:`PPL lattice
6
polytopes<sage.geometry.polyhedron.ppl_lattice_polytope.LatticePolytope_PPL_class>`.
7
"""
8
########################################################################
9
# Copyright (C) 2012 Volker Braun <[email protected]>
10
#
11
# Distributed under the terms of the GNU General Public License (GPL)
12
#
13
# http://www.gnu.org/licenses/
14
########################################################################
15
16
from sage.structure.sage_object import SageObject
17
from sage.rings.integer_ring import ZZ
18
from sage.modules.all import vector
19
from sage.matrix.constructor import matrix
20
21
22
########################################################################
23
class LatticePolytopeError(Exception):
24
"""
25
Base class for errors from lattice polytopes
26
"""
27
pass
28
29
30
########################################################################
31
class LatticePolytopesNotIsomorphicError(LatticePolytopeError):
32
"""
33
Raised when two lattice polytopes are not isomorphic.
34
"""
35
pass
36
37
38
########################################################################
39
class LatticePolytopeNoEmbeddingError(LatticePolytopeError):
40
"""
41
Raised when no embedding of the desired kind can be found.
42
"""
43
pass
44
45
46
########################################################################
47
class LatticeEuclideanGroupElement(SageObject):
48
49
def __init__(self, A, b):
50
"""
51
An element of the lattice Euclidean group.
52
53
Note that this is just intended as a container for results from
54
LatticePolytope_PPL. There is no group-theoretic functionality to
55
speak of.
56
57
EXAMPLES::
58
59
sage: from sage.geometry.polyhedron.ppl_lattice_polytope \
60
....: import LatticePolytope_PPL, C_Polyhedron
61
sage: from sage.geometry.polyhedron.lattice_euclidean_group_element \
62
....: import LatticeEuclideanGroupElement
63
sage: M = LatticeEuclideanGroupElement([[1,2],[2,3],[-1,2]], [1,2,3])
64
sage: M
65
The map A*x+b with A=
66
[ 1 2]
67
[ 2 3]
68
[-1 2]
69
b =
70
(1, 2, 3)
71
sage: M._A
72
[ 1 2]
73
[ 2 3]
74
[-1 2]
75
sage: M._b
76
(1, 2, 3)
77
sage: M(vector([0,0]))
78
(1, 2, 3)
79
sage: M(LatticePolytope_PPL((0,0),(1,0),(0,1)))
80
A 2-dimensional lattice polytope in ZZ^3 with 3 vertices
81
sage: _.vertices()
82
((1, 2, 3), (2, 4, 2), (3, 5, 5))
83
"""
84
self._A = matrix(ZZ, A)
85
self._b = vector(ZZ, b)
86
assert self._A.nrows() == self._b.degree()
87
88
def __call__(self, x):
89
"""
90
Return the image of ``x``
91
92
INPUT:
93
94
- ``x`` -- a vector or lattice polytope.
95
96
EXAMPLES::
97
98
sage: from sage.geometry.polyhedron.ppl_lattice_polytope \
99
....: import LatticePolytope_PPL, C_Polyhedron
100
sage: from sage.geometry.polyhedron.lattice_euclidean_group_element \
101
....: import LatticeEuclideanGroupElement
102
sage: M = LatticeEuclideanGroupElement([[1,2],[2,3],[-1,2]], [1,2,3])
103
sage: M(vector(ZZ, [11,13]))
104
(38, 63, 18)
105
sage: M(LatticePolytope_PPL((0,0),(1,0),(0,1)))
106
A 2-dimensional lattice polytope in ZZ^3 with 3 vertices
107
"""
108
from sage.geometry.polyhedron.ppl_lattice_polytope import (
109
LatticePolytope_PPL, LatticePolytope_PPL_class)
110
if isinstance(x, LatticePolytope_PPL_class):
111
if x.is_empty():
112
from sage.libs.ppl import C_Polyhedron
113
return LatticePolytope_PPL(C_Polyhedron(self._b.degree(),
114
'empty'))
115
return LatticePolytope_PPL(*[self(v) for v in x.vertices()])
116
pass
117
v = self._A*x+self._b
118
v.set_immutable()
119
120
return v
121
122
def _repr_(self):
123
"""
124
Return a string representation
125
126
EXAMPLES::
127
128
sage: from sage.geometry.polyhedron.lattice_euclidean_group_element \
129
....: import LatticeEuclideanGroupElement
130
sage: M = LatticeEuclideanGroupElement([[1,2],[2,3],[-1,2]], [1,2,3])
131
sage: M._repr_()
132
'The map A*x+b with A=\n[ 1 2]\n[ 2 3]\n[-1 2]\nb = \n(1, 2, 3)'
133
"""
134
s = 'The map A*x+b with A=\n'+str(self._A)
135
s += '\nb = \n'+str(self._b)
136
return s
137
138
def domain_dim(self):
139
"""
140
Return the dimension of the domain lattice
141
142
EXAMPLES::
143
144
sage: from sage.geometry.polyhedron.lattice_euclidean_group_element \
145
....: import LatticeEuclideanGroupElement
146
sage: M = LatticeEuclideanGroupElement([[1,2],[2,3],[-1,2]], [1,2,3])
147
sage: M
148
The map A*x+b with A=
149
[ 1 2]
150
[ 2 3]
151
[-1 2]
152
b =
153
(1, 2, 3)
154
sage: M.domain_dim()
155
2
156
"""
157
return self._A.ncols()
158
159
def codomain_dim(self):
160
"""
161
Return the dimension of the codomain lattice
162
163
EXAMPLES::
164
165
sage: from sage.geometry.polyhedron.lattice_euclidean_group_element \
166
....: import LatticeEuclideanGroupElement
167
sage: M = LatticeEuclideanGroupElement([[1,2],[2,3],[-1,2]], [1,2,3])
168
sage: M
169
The map A*x+b with A=
170
[ 1 2]
171
[ 2 3]
172
[-1 2]
173
b =
174
(1, 2, 3)
175
sage: M.codomain_dim()
176
3
177
178
Note that this is not the same as the rank. In fact, the
179
codomain dimension depends only on the matrix shape, and not
180
on the rank of the linear mapping::
181
182
sage: zero_map = LatticeEuclideanGroupElement([[0,0],[0,0],[0,0]], [0,0,0])
183
sage: zero_map.codomain_dim()
184
3
185
"""
186
return self._A.nrows()
187
188