Path: blob/master/src/sage/groups/abelian_gps/abelian_group_morphism.py
8815 views
"""1Homomorphisms of abelian groups23TODO:45- there must be a homspace first67- there should be hom and Hom methods in abelian group89AUTHORS:1011- David Joyner (2006-03-03): initial version12"""1314#*****************************************************************************15# Copyright (C) 2006 David Joyner and William Stein <[email protected]>16#17# Distributed under the terms of the GNU General Public License (GPL)18#19# http://www.gnu.org/licenses/20#*****************************************************************************2122from sage.groups.perm_gps.permgroup import *23from sage.interfaces.gap import *24from sage.categories.morphism import *25from sage.categories.homset import *2627from sage.misc.misc import prod2829def is_AbelianGroupMorphism(f):30return isinstance(f, AbelianGroupMorphism);3132class AbelianGroupMap(Morphism):33"""34A set-theoretic map between AbelianGroups.35"""36def __init__(self, parent):37"""38The Python constructor.39"""40Morphism.__init__(self, parent)4142def _repr_type(self):43return "AbelianGroup"4445class AbelianGroupMorphism_id(AbelianGroupMap):46"""47Return the identity homomorphism from X to itself.4849EXAMPLES:50"""51def __init__(self, X):52AbelianGroupMorphism.__init__(self, X.Hom(X))5354def _repr_defn(self):55return "Identity map of "+str(X)5657class AbelianGroupMorphism(Morphism):58"""59Some python code for wrapping GAP's GroupHomomorphismByImages60function for abelian groups. Returns "fail" if gens does not61generate self or if the map does not extend to a group62homomorphism, self - other.6364EXAMPLES::6566sage: G = AbelianGroup(3,[2,3,4],names="abc"); G67Multiplicative Abelian group isomorphic to C2 x C3 x C468sage: a,b,c = G.gens()69sage: H = AbelianGroup(2,[2,3],names="xy"); H70Multiplicative Abelian group isomorphic to C2 x C371sage: x,y = H.gens()7273::7475sage: from sage.groups.abelian_gps.abelian_group_morphism import AbelianGroupMorphism76sage: phi = AbelianGroupMorphism(H,G,[x,y],[a,b])7778AUTHORS:7980- David Joyner (2006-02)81"""8283# There is a homomorphism from H to G but not from G to H:84#85# sage: phi = AbelianGroupMorphism_im_gens(G,H,[a*b,a*c],[x,y])86#------------------------------------------------------------87#Traceback (most recent call last):88# File "<ipython console>", line 1, in ?89# File ".abeliangp_hom.sage.py", line 737, in __init__90# raise TypeError, "Sorry, the orders of the corresponding elements in %s, %s must be equal."%(genss,imgss)91#TypeError: Sorry, the orders of the corresponding elements in [a*b, a*c], [x, y] must be equal.92#93# sage: phi = AbelianGroupMorphism_im_gens(G,H,[a*b,(a*c)^2],[x*y,y])94#------------------------------------------------------------95#Traceback (most recent call last):96# File "<ipython console>", line 1, in ?97# File ".abeliangp_hom.sage.py", line 730, in __init__98# raise TypeError, "Sorry, the list %s must generate G."%genss99#TypeError: Sorry, the list [a*b, c^2] must generate G.100101def __init__(self, G, H, genss, imgss ):102from sage.categories.homset import Hom103Morphism.__init__(self, Hom(G, H))104if len(genss) != len(imgss):105raise TypeError, "Sorry, the lengths of %s, %s must be equal."%(genss,imgss)106self._domain = G107self._codomain = H108if not(G.is_abelian()):109raise TypeError, "Sorry, the groups must be abelian groups."110if not(H.is_abelian()):111raise TypeError, "Sorry, the groups must be abelian groups."112G_domain = G.subgroup(genss)113if G_domain.order() != G.order():114raise TypeError, "Sorry, the list %s must generate G."%genss115# self.domain_invs = G.gens_orders()116# self.codomaininvs = H.gens_orders()117self.domaingens = genss118self.codomaingens = imgss119#print genss, imgss120for i in range(len(self.domaingens)):121if (self.domaingens[i]).order() != (self.codomaingens[i]).order():122raise TypeError, "Sorry, the orders of the corresponding elements in %s, %s must be equal."%(genss,imgss)123124def _gap_init_(self):125"""126Only works for finite groups.127128EXAMPLES::129130sage: G = AbelianGroup(3,[2,3,4],names="abc"); G131Multiplicative Abelian group isomorphic to C2 x C3 x C4132sage: a,b,c = G.gens()133sage: H = AbelianGroup(2,[2,3],names="xy"); H134Multiplicative Abelian group isomorphic to C2 x C3135sage: x,y = H.gens()136sage: phi = AbelianGroupMorphism(H,G,[x,y],[a,b])137sage: phi._gap_init_()138'phi := GroupHomomorphismByImages(G,H,[x, y],[a, b])'139"""140G = (self.domain())._gap_init_()141H = (self.codomain())._gap_init_()142# print G,H143s3 = 'G:=%s; H:=%s'%(G,H)144#print s3,"\n"145gap.eval(s3)146gensG = self.domain().variable_names() ## the Sage group generators147gensH = self.codomain().variable_names()148#print gensG, gensH149s1 = "gensG := GeneratorsOfGroup(G)" ## the GAP group generators150gap.eval(s1)151s2 = "gensH := GeneratorsOfGroup(H)"152gap.eval(s2)153for i in range(len(gensG)): ## making the Sage group gens154cmd = ("%s := gensG["+str(i+1)+"]")%gensG[i] ## correspond to the Sage group gens155#print i," \n",cmd156gap.eval(cmd)157for i in range(len(gensH)):158cmd = ("%s := gensH["+str(i+1)+"]")%gensH[i]159#print i," \n",cmd160gap.eval(cmd)161args = str(self.domaingens)+","+ str(self.codomaingens)162#print args,"\n"163gap.eval("phi := GroupHomomorphismByImages(G,H,"+args+")")164self.gap_hom_string = "phi := GroupHomomorphismByImages(G,H,"+args+")"165return self.gap_hom_string166167def _repr_type(self):168return "AbelianGroup"169170def kernel(self):171"""172Only works for finite groups.173174TODO: not done yet; returns a gap object but should return a Sage175group.176177EXAMPLES::178179sage: H = AbelianGroup(3,[2,3,4],names="abc"); H180Multiplicative Abelian group isomorphic to C2 x C3 x C4181sage: a,b,c = H.gens()182sage: G = AbelianGroup(2,[2,3],names="xy"); G183Multiplicative Abelian group isomorphic to C2 x C3184sage: x,y = G.gens()185sage: phi = AbelianGroupMorphism(G,H,[x,y],[a,b])186sage: phi.kernel()187'Group([ ])'188"""189cmd = self._gap_init_()190gap.eval(cmd)191return gap.eval("Kernel(phi)")192193def image(self, J):194"""195Only works for finite groups.196197J must be a subgroup of G. Computes the subgroup of H which is the198image of J.199200EXAMPLES::201202sage: G = AbelianGroup(2,[2,3],names="xy")203sage: x,y = G.gens()204sage: H = AbelianGroup(3,[2,3,4],names="abc")205sage: a,b,c = H.gens()206sage: phi = AbelianGroupMorphism(G,H,[x,y],[a,b])207"""208G = self.domain()209gensJ = J.gens()210for g in gensJ:211print g212print self(g),"\n"213L = [self(g) for g in gensJ]214return G.subgroup(L)215216def _call_( self, g ):217"""218Some python code for wrapping GAP's Images function but only for219permutation groups. Returns an error if g is not in G.220221EXAMPLES::222223sage: H = AbelianGroup(3, [2,3,4], names="abc")224sage: a,b,c = H.gens()225sage: G = AbelianGroup(2, [2,3], names="xy")226sage: x,y = G.gens()227sage: phi = AbelianGroupMorphism(G,H,[x,y],[a,b])228sage: phi(y*x)229a*b230sage: phi(y^2)231b^2232"""233G = g.parent()234w = g.word_problem(self.domaingens)235n = len(w)236#print w,g.word_problem(self.domaingens)237# g.word_problem is faster in general than word_problem(g)238gens = self.codomaingens239h = prod([gens[(self.domaingens).index(w[i][0])]**(w[i][1]) for i in range(n)])240return h241242243244245246247248