Path: blob/master/sage/groups/perm_gps/permgroup_morphism.py
4057 views
r"""1Permutation group homomorphisms23AUTHORS:45- David Joyner (2006-03-21): first version67- David Joyner (2008-06): fixed kernel and image to return a group,8instead of a string.910EXAMPLES::1112sage: G = CyclicPermutationGroup(4)13sage: H = DihedralGroup(4)14sage: g = G([(1,2,3,4)])15sage: phi = PermutationGroupMorphism_im_gens(G, H, map(H, G.gens()))16sage: phi.image(G)17Subgroup of (Dihedral group of order 8 as a permutation group) generated by [(1,2,3,4)]18sage: phi.kernel()19Subgroup of (Cyclic group of order 4 as a permutation group) generated by [()]20sage: phi.image(g)21(1,2,3,4)22sage: phi(g)23(1,2,3,4)24sage: phi.codomain()25Dihedral group of order 8 as a permutation group26sage: phi.codomain()27Dihedral group of order 8 as a permutation group28sage: phi.domain()29Cyclic group of order 4 as a permutation group30"""3132#*****************************************************************************33# Copyright (C) 2006 David Joyner and William Stein <[email protected]>34#35# Distributed under the terms of the GNU General Public License (GPL)36# http://www.gnu.org/licenses/37#*****************************************************************************3839from sage.misc.misc import deprecation40from sage.categories.morphism import Morphism41from sage.groups.perm_gps.permgroup import PermutationGroup, PermutationGroup_generic4243class PermutationGroupMorphism(Morphism):44"""45A set-theoretic map between PermutationGroups.46"""47def _repr_type(self):48"""49Returns the type of this morphism. This is used for printing50the morphism.5152EXAMPLES::5354sage: G = PSL(2,7)55sage: D, iota1, iota2, pr1, pr2 = G.direct_product(G)56sage: pr1._repr_type()57'Permutation group'58"""59return "Permutation group"6061def range(self):62"""63Returns the codomain of this morphism. This method is64deprecated. Please use :meth:`codomain` instead.6566EXAMPLES::6768sage: G = PSL(2,7)69sage: D, iota1, iota2, pr1, pr2 = G.direct_product(G)70sage: pr1.range()71doctest... DeprecationWarning: (Since Sage Version 5.0) range is deprecated. Please use codomain instead.72Permutation Group with generators [(3,7,5)(4,8,6), (1,2,6)(3,4,8)]73"""74deprecation('range is deprecated. Please use codomain instead.', 'Sage Version 5.0')75return self.codomain()7677def kernel(self):78"""79Returns the kernel of this homomorphism as a permutation group.8081EXAMPLES::8283sage: G = CyclicPermutationGroup(4)84sage: H = DihedralGroup(4)85sage: g = G([(1,2,3,4)])86sage: phi = PermutationGroupMorphism_im_gens(G, H, [1])87sage: phi.kernel()88Subgroup of (Cyclic group of order 4 as a permutation group) generated by [(1,2,3,4)]8990::9192sage: G = PSL(2,7)93sage: D = G.direct_product(G)94sage: H = D[0]95sage: pr1 = D[3]96sage: G.is_isomorphic(pr1.kernel())97True98"""99return self.domain().subgroup(gap_group=self._gap_().Kernel())100101def image(self, J):102"""103J must be a subgroup of G. Computes the subgroup of H which is the104image of J.105106EXAMPLES::107108sage: G = CyclicPermutationGroup(4)109sage: H = DihedralGroup(4)110sage: g = G([(1,2,3,4)])111sage: phi = PermutationGroupMorphism_im_gens(G, H, map(H, G.gens()))112sage: phi.image(G)113Subgroup of (Dihedral group of order 8 as a permutation group) generated by [(1,2,3,4)]114sage: phi.image(g)115(1,2,3,4)116117::118119sage: G = PSL(2,7)120sage: D = G.direct_product(G)121sage: H = D[0]122sage: pr1 = D[3]123sage: pr1.image(G)124Subgroup of (The projective special linear group of degree 2 over Finite Field of size 7) generated by [(3,7,5)(4,8,6), (1,2,6)(3,4,8)]125sage: G.is_isomorphic(pr1.image(G))126True127"""128H = self.codomain()129if J in self.domain():130J = PermutationGroup([J])131G = self._gap_().Image(J)132return H.subgroup(gap_group=G).gens()[0]133else:134G = self._gap_().Image(J)135return H.subgroup(gap_group=G)136137def __call__(self, g):138"""139Some python code for wrapping GAP's Images function but only for140permutation groups. Returns an error if g is not in G.141142EXAMPLES::143144sage: G = CyclicPermutationGroup(4)145sage: H = DihedralGroup(4)146sage: phi = PermutationGroupMorphism_im_gens(G, H, map(H, G.gens()))147sage: g = G([(1,3),(2,4)]); g148(1,3)(2,4)149sage: phi(g)150(1,3)(2,4)151"""152return self.image(g)153154class PermutationGroupMorphism_id(PermutationGroupMorphism):155pass156157class PermutationGroupMorphism_from_gap(PermutationGroupMorphism):158def __init__(self, G, H, gap_hom):159"""160This is a Python trick to allow Sage programmers to create a group161homomorphism using GAP using very general constructions. An example162of its usage is in the direct_product instance method of the163PermutationGroup_generic class in permgroup.py.164165Basic syntax:166167PermutationGroupMorphism_from_gap(domain_group,168range_group,'phi:=gap_hom_command;','phi') And don't forget the169line: from sage.groups.perm_gps.permgroup_morphism import170PermutationGroupMorphism_from_gap in your program.171172EXAMPLES::173174sage: from sage.groups.perm_gps.permgroup_morphism import PermutationGroupMorphism_from_gap175sage: G = PermutationGroup([[(1,2),(3,4)], [(1,2,3,4)]])176sage: H = G.subgroup([G([(1,2,3,4)])])177sage: PermutationGroupMorphism_from_gap(H, G, gap.Identity)178Permutation group morphism:179From: Subgroup of (Permutation Group with generators [(1,2)(3,4), (1,2,3,4)]) generated by [(1,2,3,4)]180To: Permutation Group with generators [(1,2)(3,4), (1,2,3,4)]181Defn: Identity182"""183if not all(isinstance(X, PermutationGroup_generic) for X in [G, H]):184raise TypeError, "Sorry, the groups must be permutation groups."185PermutationGroupMorphism.__init__(self, G, H)186self._gap_hom = gap_hom187188def _repr_defn(self):189"""190Returns the definition of this morphism. This is used when191printing the morphism.192193EXAMPLES::194195sage: from sage.groups.perm_gps.permgroup_morphism import PermutationGroupMorphism_from_gap196sage: G = PermutationGroup([[(1,2),(3,4)], [(1,2,3,4)]])197sage: H = G.subgroup([G([(1,2,3,4)])])198sage: phi = PermutationGroupMorphism_from_gap(H, G, gap.Identity)199sage: phi._repr_defn()200'Identity'201"""202return str(self._gap_hom).replace('\n', '')203204def _gap_(self, gap=None):205"""206Returns a GAP version of this morphism.207208EXAMPLES::209210sage: from sage.groups.perm_gps.permgroup_morphism import PermutationGroupMorphism_from_gap211sage: G = PermutationGroup([[(1,2),(3,4)], [(1,2,3,4)]])212sage: H = G.subgroup([G([(1,2,3,4)])])213sage: phi = PermutationGroupMorphism_from_gap(H, G, gap.Identity)214sage: phi._gap_()215Identity216"""217return self._gap_hom218219def __call__(self, g):220"""221Some python code for wrapping GAP's Images function but only for222permutation groups. Returns an error if g is not in G.223224EXAMPLES::225226sage: G = PSL(2,7)227sage: D = G.direct_product(G)228sage: H = D[0]229sage: pr1 = D[3]230sage: [pr1(g) for g in G.gens()]231[(3,7,5)(4,8,6), (1,2,6)(3,4,8)]232"""233return self.codomain()(self._gap_().Image(g))234235236class PermutationGroupMorphism_im_gens(PermutationGroupMorphism):237def __init__(self, G, H, gens=None, images=None):238"""239Some python code for wrapping GAP's GroupHomomorphismByImages240function but only for permutation groups. Can be expensive if G is241large. Returns "fail" if gens does not generate self or if the map242does not extend to a group homomorphism, self - other.243244EXAMPLES::245246sage: G = CyclicPermutationGroup(4)247sage: H = DihedralGroup(4)248sage: phi = PermutationGroupMorphism_im_gens(G, H, map(H, G.gens())); phi249Permutation group morphism:250From: Cyclic group of order 4 as a permutation group251To: Dihedral group of order 8 as a permutation group252Defn: [(1,2,3,4)] -> [(1,2,3,4)]253sage: g = G([(1,3),(2,4)]); g254(1,3)(2,4)255sage: phi(g)256(1,3)(2,4)257sage: images = ((4,3,2,1),)258sage: phi = PermutationGroupMorphism_im_gens(G, G, images)259sage: g = G([(1,2,3,4)]); g260(1,2,3,4)261sage: phi(g)262(1,4,3,2)263264AUTHORS:265266- David Joyner (2006-02)267"""268if not all([isinstance(X, PermutationGroup_generic) for X in [G, H]]):269raise TypeError, "Sorry, the groups must be permutation groups."270if images is not None:271deprecation('only the images need to be specified')272else:273images = gens274PermutationGroupMorphism.__init__(self, G, H)275self._images = [H(img) for img in images]276277def _repr_defn(self):278"""279Returns the definition of this morphism. This is used when280printing the morphism.281282EXAMPLES::283284sage: G = CyclicPermutationGroup(4)285sage: H = DihedralGroup(4)286sage: phi = PermutationGroupMorphism_im_gens(G, H, map(H, G.gens()))287sage: phi._repr_defn()288'[(1,2,3,4)] -> [(1,2,3,4)]'289"""290return "%s -> %s"%(self.domain().gens(), self._images)291292def _gap_(self):293"""294Returns a GAP representation of this morphism.295296EXAMPLES::297298sage: G = CyclicPermutationGroup(4)299sage: H = DihedralGroup(4)300sage: phi = PermutationGroupMorphism_im_gens(G, H, map(H, G.gens()))301sage: phi._gap_()302GroupHomomorphismByImages( Group( [ (1,2,3,4) ] ), Group(303[ (1,2,3,4), (1,4)(2,3) ] ), [ (1,2,3,4) ], [ (1,2,3,4) ] )304"""305return self.domain()._gap_().GroupHomomorphismByImages(self.codomain(), self.domain().gens(), self._images)306307def is_PermutationGroupMorphism(f):308"""309Returns True if the argument ``f`` is a PermutationGroupMorphism.310311EXAMPLES::312313sage: from sage.groups.perm_gps.permgroup_morphism import is_PermutationGroupMorphism314sage: G = CyclicPermutationGroup(4)315sage: H = DihedralGroup(4)316sage: phi = PermutationGroupMorphism_im_gens(G, H, map(H, G.gens()))317sage: is_PermutationGroupMorphism(phi)318True319"""320return isinstance(f, PermutationGroupMorphism)321322323