Path: blob/master/src/sage/groups/abelian_gps/abelian_group_element.py
8815 views
"""1Abelian group elements23AUTHORS:45- David Joyner (2006-02); based on free_abelian_monoid_element.py, written by David Kohel.67- David Joyner (2006-05); bug fix in order89- David Joyner (2006-08); bug fix+new method in pow for negatives+fixed corresponding examples.1011- David Joyner (2009-02): Fixed bug in order.1213- Volker Braun (2012-11) port to new Parent base. Use tuples for immutables.141516EXAMPLES:1718Recall an example from abelian groups::1920sage: F = AbelianGroup(5,[4,5,5,7,8],names = list("abcde"))21sage: (a,b,c,d,e) = F.gens()22sage: x = a*b^2*e*d^20*e^1223sage: x24a*b^2*d^6*e^525sage: x = a^10*b^12*c^13*d^20*e^1226sage: x27a^2*b^2*c^3*d^6*e^428sage: y = a^13*b^19*c^23*d^27*e^7229sage: y30a*b^4*c^3*d^631sage: x*y32a^3*b*c*d^5*e^433sage: x.list()34[2, 2, 3, 6, 4]35"""3637###########################################################################38# Copyright (C) 2006 William Stein <[email protected]>39# Copyright (C) 2006 David Joyner <[email protected]>40# Copyright (C) 2012 Volker Braun <[email protected]>41#42# Distributed under the terms of the GNU General Public License (GPL)43# http://www.gnu.org/licenses/44###########################################################################454647from sage.rings.integer import Integer48from sage.rings.infinity import infinity49from sage.rings.arith import LCM, GCD50from sage.groups.abelian_gps.element_base import AbelianGroupElementBase5152def is_AbelianGroupElement(x):53"""54Return true if x is an abelian group element, i.e., an element of55type AbelianGroupElement.5657EXAMPLES: Though the integer 3 is in the integers, and the integers58have an abelian group structure, 3 is not an AbelianGroupElement::5960sage: from sage.groups.abelian_gps.abelian_group_element import is_AbelianGroupElement61sage: is_AbelianGroupElement(3)62False63sage: F = AbelianGroup(5, [3,4,5,8,7], 'abcde')64sage: is_AbelianGroupElement(F.0)65True66"""67return isinstance(x, AbelianGroupElement)686970class AbelianGroupElement(AbelianGroupElementBase):71"""72Elements of an73:class:`~sage.groups.abelian_gps.abelian_group.AbelianGroup`7475INPUT:7677- ``x`` -- list/tuple/iterable of integers (the element vector)7879- ``parent`` -- the parent80:class:`~sage.groups.abelian_gps.abelian_group.AbelianGroup`8182EXAMPLES::8384sage: F = AbelianGroup(5, [3,4,5,8,7], 'abcde')85sage: a, b, c, d, e = F.gens()86sage: a^2 * b^3 * a^2 * b^-487a*b^388sage: b^-1189b90sage: a^-1191a92sage: a*b in F93True94"""9596def as_permutation(self):97r"""98Return the element of the permutation group G (isomorphic to the99abelian group A) associated to a in A.100101EXAMPLES::102103sage: G = AbelianGroup(3,[2,3,4],names="abc"); G104Multiplicative Abelian group isomorphic to C2 x C3 x C4105sage: a,b,c=G.gens()106sage: Gp = G.permutation_group(); Gp107Permutation Group with generators [(6,7,8,9), (3,4,5), (1,2)]108sage: a.as_permutation()109(1,2)110sage: ap = a.as_permutation(); ap111(1,2)112sage: ap in Gp113True114"""115from sage.groups.perm_gps.permgroup import PermutationGroup116from sage.interfaces.all import gap117G = self.parent()118invs = list(G.gens_orders())119s1 = 'A:=AbelianGroup(%s)'%invs120gap.eval(s1)121s2 = 'phi:=IsomorphismPermGroup(A)'122gap.eval(s2)123s3 = "gens := GeneratorsOfGroup(A)"124gap.eval(s3)125L = self.list()126gap.eval("L1:="+str(L))127s4 = "L2:=List([1..%s], i->gens[i]^L1[i]);"%len(L)128gap.eval(s4)129pg = gap.eval("Image(phi,Product(L2))")130Gp = G.permutation_group()131gp = Gp(pg)132return gp133134def word_problem(self, words):135"""136TODO - this needs a rewrite - see stuff in the matrix_grp137directory.138139G and H are abelian groups, g in G, H is a subgroup of G generated140by a list (words) of elements of G. If self is in H, return the141expression for self as a word in the elements of (words).142143This function does not solve the word problem in Sage. Rather144it pushes it over to GAP, which has optimized (non-deterministic)145algorithms for the word problem.146147.. warning::148149Don't use E (or other GAP-reserved letters) as a generator150name.151152EXAMPLE::153154sage: G = AbelianGroup(2,[2,3], names="xy")155sage: x,y = G.gens()156sage: x.word_problem([x,y])157[[x, 1]]158sage: y.word_problem([x,y])159[[y, 1]]160sage: v = (y*x).word_problem([x,y]); v #random161[[x, 1], [y, 1]]162sage: prod([x^i for x,i in v]) == y*x163True164"""165from sage.groups.abelian_gps.abelian_group import AbelianGroup, word_problem166return word_problem(words,self)167168169