Path: blob/master/src/sage/groups/affine_gps/euclidean_group.py
8815 views
r"""1Euclidean Groups23AUTHORS:45- Volker Braun: initial version6"""78##############################################################################9# Copyright (C) 2013 Volker Braun <[email protected]>10#11# Distributed under the terms of the GNU General Public License (GPL)12#13# The full text of the GPL is available at:14#15# http://www.gnu.org/licenses/16##############################################################################171819from sage.categories.groups import Groups20from sage.groups.group import Group21from sage.matrix.all import MatrixSpace22from sage.modules.all import FreeModule23from sage.structure.unique_representation import UniqueRepresentation24from sage.misc.cachefunc import cached_method2526from sage.groups.affine_gps.group_element import AffineGroupElement27from sage.groups.affine_gps.affine_group import AffineGroup282930class EuclideanGroup(AffineGroup):31r"""32A Euclidean group.3334The Euclidean group `E(A)` (or general affine group) of an affine35space `A` is the group of all invertible affine transformations from36the space into itself preserving the Euclidean metric.3738If we let `A_V` be the affine space of a vector space `V`39(essentially, forgetting what is the origin) then the Euclidean group40`E(A_V)` is the group generated by the general linear group `SO(V)`41together with the translations. Recall that the group of translations42acting on `A_V` is just `V` itself. The general linear and translation43subgroups do not quite commute, and in fact generate the semidirect44product4546.. MATH::4748E(A_V) = SO(V) \ltimes V.4950As such, the group elements can be represented by pairs `(A,b)` of a51matrix and a vector. This pair then represents the transformation5253.. MATH::5455x \mapsto A x + b.5657We can also represent this as a linear transformation in `\dim(V) + 1`58dimensional space as5960.. MATH::6162\begin{pmatrix}63A & b \\640 & 165\end{pmatrix}6667and lifting `x = (x_1, \ldots, x_n)` to `(x_1, \ldots, x_n, 1)`.6869.. SEEALSO::7071- :class:`AffineGroup`7273INPUT:7475Something that defines an affine space. For example7677- An affine space itself:7879* ``A`` -- affine space8081- A vector space:8283* ``V`` -- a vector space8485- Degree and base ring:8687* ``degree`` -- An integer. The degree of the affine group, that88is, the dimension of the affine space the group is acting on.8990* ``ring`` -- A ring or an integer. The base ring of the affine91space. If an integer is given, it must be a prime power and92the corresponding finite field is constructed.9394* ``var`` -- (Defalut: ``'a'``) Keyword argument to specify the finite95field generator name in the case where ``ring`` is a prime power.9697EXAMPLES::9899sage: E3 = EuclideanGroup(3, QQ); E3100Euclidean Group of degree 3 over Rational Field101sage: E3(matrix(QQ,[(6/7, -2/7, 3/7), (-2/7, 3/7, 6/7), (3/7, 6/7, -2/7)]), vector(QQ,[10,11,12]))102[ 6/7 -2/7 3/7] [10]103x |-> [-2/7 3/7 6/7] x + [11]104[ 3/7 6/7 -2/7] [12]105sage: E3([[6/7, -2/7, 3/7], [-2/7, 3/7, 6/7], [3/7, 6/7, -2/7]], [10,11,12])106[ 6/7 -2/7 3/7] [10]107x |-> [-2/7 3/7 6/7] x + [11]108[ 3/7 6/7 -2/7] [12]109sage: E3([6/7, -2/7, 3/7, -2/7, 3/7, 6/7, 3/7, 6/7, -2/7], [10,11,12])110[ 6/7 -2/7 3/7] [10]111x |-> [-2/7 3/7 6/7] x + [11]112[ 3/7 6/7 -2/7] [12]113114Instead of specifying the complete matrix/vector information, you can115also create special group elements::116117sage: E3.linear([6/7, -2/7, 3/7, -2/7, 3/7, 6/7, 3/7, 6/7, -2/7])118[ 6/7 -2/7 3/7] [0]119x |-> [-2/7 3/7 6/7] x + [0]120[ 3/7 6/7 -2/7] [0]121sage: E3.reflection([4,5,6])122[ 45/77 -40/77 -48/77] [0]123x |-> [-40/77 27/77 -60/77] x + [0]124[-48/77 -60/77 5/77] [0]125sage: E3.translation([1,2,3])126[1 0 0] [1]127x |-> [0 1 0] x + [2]128[0 0 1] [3]129130Some additional ways to create Euclidean groups::131132sage: A = AffineSpace(2, GF(4,'a')); A133Affine Space of dimension 2 over Finite Field in a of size 2^2134sage: G = EuclideanGroup(A); G135Euclidean Group of degree 2 over Finite Field in a of size 2^2136sage: G is EuclideanGroup(2,4) # shorthand137True138139sage: V = ZZ^3; V140Ambient free module of rank 3 over the principal ideal domain Integer Ring141sage: EuclideanGroup(V)142Euclidean Group of degree 3 over Integer Ring143144sage: EuclideanGroup(2, QQ)145Euclidean Group of degree 2 over Rational Field146147TESTS::148149sage: E6 = EuclideanGroup(6, QQ)150sage: E6 is E6151True152sage: V = QQ^6153sage: E6 is EuclideanGroup(V)154True155sage: G = EuclideanGroup(2, GF(5)); G156Euclidean Group of degree 2 over Finite Field of size 5157sage: TestSuite(G).run()158159REFERENCES:160161- :wikipedia:`Euclidean_group`162"""163def _element_constructor_check(self, A, b):164"""165Verify that ``A``, ``b`` define an affine group element.166167This is called from the group element constructor and can be168overridden for subgroups of the affine group. It is guaranteed169that ``A``, ``b`` are in the correct matrix/vetor space.170171INPUT:172173- ``A`` -- an element of :meth:`matrix_space`.174175- ``b`` -- an element of :meth:`vector_space`.176177OUTPUT:178179The return value is ignored. You must raise a ``TypeError`` if180the input does not define a valid group element.181182TESTS::183184sage: E3 = EuclideanGroup(3, QQ)185sage: A = E3.matrix_space()([6/7,-2/7,3/7,-2/7,3/7,6/7,3/7,6/7,-2/7])186sage: det(A)187-1188sage: b = E3.vector_space().an_element()189sage: E3._element_constructor_check(A, b)190191sage: A = E3.matrix_space()([1,2,3,4,5,6,7,8,0])192sage: det(A)19327194sage: E3._element_constructor_check(A, b)195Traceback (most recent call last):196...197TypeError: A must be orthogonal (unitary)198"""199if not A.is_unitary():200raise TypeError('A must be orthogonal (unitary)')201202def _latex_(self):203r"""204EXAMPLES::205206sage: G = EuclideanGroup(6, GF(5))207sage: latex(G)208\mathrm{E}_{6}(\Bold{F}_{5})209"""210return "\\mathrm{E}_{%s}(%s)"%(self.degree(), self.base_ring()._latex_())211212def _repr_(self):213"""214String representation of this group.215216EXAMPLES::217218sage: EuclideanGroup(6, GF(5))219Euclidean Group of degree 6 over Finite Field of size 5220"""221return "Euclidean Group of degree %s over %s"%(self.degree(), self.base_ring())222223def random_element(self):224"""225Return a random element of this group.226227EXAMPLES::228229sage: G = EuclideanGroup(4, GF(3))230sage: G.random_element() # random231[2 1 2 1] [1]232[1 2 2 1] [0]233x |-> [2 2 2 2] x + [1]234[1 1 2 2] [2]235sage: G.random_element() in G236True237238TESTS::239240sage: G.random_element().A().is_unitary()241True242"""243while True:244v = self.vector_space().random_element()245try:246g1 = self.reflection(v)247break248except ValueError: # v has norm zero249pass250g2 = self.translation(self.vector_space().random_element())251return g1 * g2252253254255