Path: blob/master/sage/groups/abelian_gps/abelian_group_morphism.py
4100 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):37Morphism.__init__(self, parent)3839def _repr_type(self):40return "AbelianGroup"4142class AbelianGroupMorphism_id(AbelianGroupMap):43"""44Return the identity homomorphism from X to itself.4546EXAMPLES:47"""48def __init__(self, X):49AbelianGroupMorphism.__init__(self, X.Hom(X))5051def _repr_defn(self):52return "Identity map of "+str(X)5354class AbelianGroupMorphism:55"""56Some python code for wrapping GAP's GroupHomomorphismByImages57function for abelian groups. Returns "fail" if gens does not58generate self or if the map does not extend to a group59homomorphism, self - other.6061EXAMPLES::6263sage: G = AbelianGroup(3,[2,3,4],names="abc"); G64Multiplicative Abelian Group isomorphic to C2 x C3 x C465sage: a,b,c = G.gens()66sage: H = AbelianGroup(2,[2,3],names="xy"); H67Multiplicative Abelian Group isomorphic to C2 x C368sage: x,y = H.gens()6970::7172sage: from sage.groups.abelian_gps.abelian_group_morphism import AbelianGroupMorphism73sage: phi = AbelianGroupMorphism(H,G,[x,y],[a,b])7475AUTHORS:7677- David Joyner (2006-02)78"""7980# There is a homomorphism from H to G but not from G to H:81#82# sage: phi = AbelianGroupMorphism_im_gens(G,H,[a*b,a*c],[x,y])83#------------------------------------------------------------84#Traceback (most recent call last):85# File "<ipython console>", line 1, in ?86# File ".abeliangp_hom.sage.py", line 737, in __init__87# raise TypeError, "Sorry, the orders of the corresponding elements in %s, %s must be equal."%(genss,imgss)88#TypeError: Sorry, the orders of the corresponding elements in [a*b, a*c], [x, y] must be equal.89#90# sage: phi = AbelianGroupMorphism_im_gens(G,H,[a*b,(a*c)^2],[x*y,y])91#------------------------------------------------------------92#Traceback (most recent call last):93# File "<ipython console>", line 1, in ?94# File ".abeliangp_hom.sage.py", line 730, in __init__95# raise TypeError, "Sorry, the list %s must generate G."%genss96#TypeError: Sorry, the list [a*b, c^2] must generate G.9798def __init__(self, G, H, genss, imgss ):99if len(genss) != len(imgss):100raise TypeError, "Sorry, the lengths of %s, %s must be equal."%(genss,imgss)101self._domain = G102self._codomain = H103if not(G.is_abelian()):104raise TypeError, "Sorry, the groups must be abelian groups."105if not(H.is_abelian()):106raise TypeError, "Sorry, the groups must be abelian groups."107G_domain = G.subgroup(genss)108if G_domain.order() != G.order():109raise TypeError, "Sorry, the list %s must generate G."%genss110self.domain_invs = G.invariants()111self.codomaininvs = H.invariants()112self.domaingens = genss113self.codomaingens = imgss114#print genss, imgss115for i in range(len(self.domaingens)):116if (self.domaingens[i]).order() != (self.codomaingens[i]).order():117raise TypeError, "Sorry, the orders of the corresponding elements in %s, %s must be equal."%(genss,imgss)118119def _gap_init_(self):120"""121Only works for finite groups.122123EXAMPLES::124125sage: G = AbelianGroup(3,[2,3,4],names="abc"); G126Multiplicative Abelian Group isomorphic to C2 x C3 x C4127sage: a,b,c = G.gens()128sage: H = AbelianGroup(2,[2,3],names="xy"); H129Multiplicative Abelian Group isomorphic to C2 x C3130sage: x,y = H.gens()131sage: phi = AbelianGroupMorphism(H,G,[x,y],[a,b])132sage: phi._gap_init_()133'phi := GroupHomomorphismByImages(G,H,[x, y],[a, b])'134"""135G = (self.domain())._gap_init_()136H = (self.range())._gap_init_()137# print G,H138s3 = 'G:=%s; H:=%s'%(G,H)139#print s3,"\n"140gap.eval(s3)141gensG = self.domain().variable_names() ## the Sage group generators142gensH = self.range().variable_names()143#print gensG, gensH144s1 = "gensG := GeneratorsOfGroup(G)" ## the GAP group generators145gap.eval(s1)146s2 = "gensH := GeneratorsOfGroup(H)"147gap.eval(s2)148for i in range(len(gensG)): ## making the Sage group gens149cmd = ("%s := gensG["+str(i+1)+"]")%gensG[i] ## correspond to the Sage group gens150#print i," \n",cmd151gap.eval(cmd)152for i in range(len(gensH)):153cmd = ("%s := gensH["+str(i+1)+"]")%gensH[i]154#print i," \n",cmd155gap.eval(cmd)156args = str(self.domaingens)+","+ str(self.codomaingens)157#print args,"\n"158gap.eval("phi := GroupHomomorphismByImages(G,H,"+args+")")159self.gap_hom_string = "phi := GroupHomomorphismByImages(G,H,"+args+")"160return self.gap_hom_string161162def _repr_type(self):163return "AbelianGroup"164165def domain(self):166return self._domain167168def range(self):169return self._codomain170171def codomain(self):172return self._codomain173174def kernel(self):175"""176Only works for finite groups.177178TODO: not done yet; returns a gap object but should return a Sage179group.180181EXAMPLES::182183sage: H = AbelianGroup(3,[2,3,4],names="abc"); H184Multiplicative Abelian Group isomorphic to C2 x C3 x C4185sage: a,b,c = H.gens()186sage: G = AbelianGroup(2,[2,3],names="xy"); G187Multiplicative Abelian Group isomorphic to C2 x C3188sage: x,y = G.gens()189sage: phi = AbelianGroupMorphism(G,H,[x,y],[a,b])190sage: phi.kernel()191'Group([ ])'192"""193cmd = self._gap_init_()194gap.eval(cmd)195return gap.eval("Kernel(phi)")196197def image(self, J):198"""199Only works for finite groups.200201J must be a subgroup of G. Computes the subgroup of H which is the202image of J.203204EXAMPLES::205206sage: G = AbelianGroup(2,[2,3],names="xy")207sage: x,y = G.gens()208sage: H = AbelianGroup(3,[2,3,4],names="abc")209sage: a,b,c = H.gens()210sage: phi = AbelianGroupMorphism(G,H,[x,y],[a,b])211"""212G = self.domain()213gensJ = J.gens()214for g in gensJ:215print g216print self(g),"\n"217L = [self(g) for g in gensJ]218return G.subgroup(L)219220def __call__( self, g ):221"""222Some python code for wrapping GAP's Images function but only for223permutation groups. Returns an error if g is not in G.224225EXAMPLES::226227sage: H = AbelianGroup(3, [2,3,4], names="abc")228sage: a,b,c = H.gens()229sage: G = AbelianGroup(2, [2,3], names="xy")230sage: x,y = G.gens()231sage: phi = AbelianGroupMorphism(G,H,[x,y],[a,b])232sage: phi(y*x)233a*b234sage: phi(y^2)235b^2236"""237G = g.parent()238w = g.word_problem(self.domaingens)239n = len(w)240#print w,g.word_problem(self.domaingens)241# g.word_problem is faster in general than word_problem(g)242gens = self.codomaingens243h = prod([gens[(self.domaingens).index(w[i][0])]**(w[i][1]) for i in range(n)])244return h245246247248249250251252