Path: blob/master/src/sage/groups/finitely_presented_named.py
8814 views
r"""1Named Finitely Presented Groups23Construct groups of small order and "named" groups as quotients of free groups. These4groups are available through tab completion by typing ``groups.presentation.<tab>``5or by importing the required methods. Tab completion is made available through6Sage's :ref:`group catalog <sage.groups.groups_catalog>`. Some examples are engineered7from entries in [THOMAS-WOODS]_.89Groups available as finite presentations:1011- Alternating group, `A_n` of order `n!/2` --12:func:`groups.presentation.Alternating <sage.groups.finitely_presented_named.AlternatingPresentation>`1314- Cyclic group, `C_n` of order `n` --15:func:`groups.presentation.Cyclic <sage.groups.finitely_presented_named.CyclicPresentation>`1617- Dicyclic group, nonabelian groups of order `4n` with a unique element of18order 2 --19:func:`groups.presentation.DiCyclic <sage.groups.finitely_presented_named.DiCyclicPresentation>`2021- Dihedral group, `D_n` of order `2n` --22:func:`groups.presentation.Dihedral <sage.groups.finitely_presented_named.DihedralPresentation>`2324- Finitely generated abelian group, `\ZZ_{n_1} \times \ZZ_{n_2} \times \cdots \times \ZZ_{n_k}` --25:func:`groups.presentation.FGAbelian <sage.groups.finitely_presented_named.FinitelyGeneratedAbelianPresentation>`2627- Klein four group, `C_2 \times C_2` --28:func:`groups.presentation.KleinFour <sage.groups.finitely_presented_named.KleinFourPresentation>`2930- Quaternion group of order 8 --31:func:`groups.presentation.Quaternion <sage.groups.finitely_presented_named.QuaternionPresentation>`3233- Symmetric group, `S_n` of order `n!` --34:func:`groups.presentation.Symmetric <sage.groups.finitely_presented_named.SymmetricPresentation>`3536AUTHORS:3738- Davis Shurbert (2013-06-21): initial version3940EXAMPLES::4142sage: groups.presentation.Cyclic(4)43Finitely presented group < a | a^4 >4445You can also import the desired functions::4647sage: from sage.groups.finitely_presented_named import CyclicPresentation48sage: CyclicPresentation(4)49Finitely presented group < a | a^4 >50"""51#*****************************************************************************52# Copyright (C) 2013 Davis Shurbert <[email protected]>53#54# Distributed under the terms of the GNU General Public License (GPL)55# http://www.gnu.org/licenses/56#*****************************************************************************5758from sage.rings.all import Integer59from sage.groups.free_group import FreeGroup60from sage.groups.finitely_presented import FinitelyPresentedGroup61from sage.libs.gap.libgap import libgap62from sage.matrix.constructor import diagonal_matrix63from sage.modules.fg_pid.fgp_module import FGP_Module64from sage.rings.integer_ring import ZZ65from sage.sets.set import Set6667def CyclicPresentation(n):68r"""69Build cyclic group of order `n` as a finitely presented group.7071INPUT:7273- ``n`` -- The order of the cyclic presentation to be returned.7475OUTPUT:7677The cyclic group of order `n` as finite presentation.7879EXAMPLES::8081sage: groups.presentation.Cyclic(10)82Finitely presented group < a | a^10 >83sage: n = 8; C = groups.presentation.Cyclic(n)84sage: C.as_permutation_group().is_isomorphic(CyclicPermutationGroup(n))85True8687TESTS::8889sage: groups.presentation.Cyclic(0)90Traceback (most recent call last):91...92ValueError: finitely presented group order must be positive93"""94n = Integer(n)95if n < 1:96raise ValueError('finitely presented group order must be positive')97F = FreeGroup( 'a' )98rls = F([1])**n,99return FinitelyPresentedGroup( F, rls )100101def FinitelyGeneratedAbelianPresentation(int_list):102r"""103Return canonical presentation of finitely generated abelian group.104105INPUT:106107- ``int_list`` -- List of integers defining the group to be returned, the defining list108is reduced to the invariants of the input list before generating the corresponding109group.110111OUTPUT:112113Finitely generated abelian group, `\ZZ_{n_1} \times \ZZ_{n_2} \times \cdots \times \ZZ_{n_k}`114as a finite presentation, where `n_i` forms the invariants of the input list.115116EXAMPLES::117118sage: groups.presentation.FGAbelian([2,2])119Finitely presented group < a, b | a^2, b^2, a^-1*b^-1*a*b >120sage: groups.presentation.FGAbelian([2,3])121Finitely presented group < a | a^6 >122sage: groups.presentation.FGAbelian([2,4])123Finitely presented group < a, b | a^2, b^4, a^-1*b^-1*a*b >124125You can create free abelian groups::126127sage: groups.presentation.FGAbelian([0])128Finitely presented group < a | >129sage: groups.presentation.FGAbelian([0,0])130Finitely presented group < a, b | a^-1*b^-1*a*b >131sage: groups.presentation.FGAbelian([0,0,0])132Finitely presented group < a, b, c | a^-1*c^-1*a*c, a^-1*b^-1*a*b, c^-1*b^-1*c*b >133134And various infinite abelian groups::135136sage: groups.presentation.FGAbelian([0,2])137Finitely presented group < a, b | a^2, a^-1*b^-1*a*b >138sage: groups.presentation.FGAbelian([0,2,2])139Finitely presented group < a, b, c | a^2, b^2, a^-1*c^-1*a*c, a^-1*b^-1*a*b, c^-1*b^-1*c*b >140141Outputs are reduced to minimal generators and relations::142143sage: groups.presentation.FGAbelian([3,5,2,7,3])144Finitely presented group < a, b | a^3, b^210, a^-1*b^-1*a*b >145sage: groups.presentation.FGAbelian([3,210])146Finitely presented group < a, b | a^3, b^210, a^-1*b^-1*a*b >147148The trivial group is an acceptable output::149150sage: groups.presentation.FGAbelian([])151Finitely presented group < | >152sage: groups.presentation.FGAbelian([1])153Finitely presented group < | >154sage: groups.presentation.FGAbelian([1,1,1,1,1,1,1,1,1,1])155Finitely presented group < | >156157Input list must consist of positive integers::158159sage: groups.presentation.FGAbelian([2,6,3,9,-4])160Traceback (most recent call last):161...162ValueError: input list must contain nonnegative entries163sage: groups.presentation.FGAbelian([2,'a',4])164Traceback (most recent call last):165...166TypeError: unable to convert x (=a) to an integer167168TESTS::169170sage: ag = groups.presentation.FGAbelian([2,2])171sage: ag.as_permutation_group().is_isomorphic(groups.permutation.KleinFour())172True173sage: G = groups.presentation.FGAbelian([2,4,8])174sage: C2 = CyclicPermutationGroup(2)175sage: C4 = CyclicPermutationGroup(4)176sage: C8 = CyclicPermutationGroup(8)177sage: gg = (C2.direct_product(C4)[0]).direct_product(C8)[0]178sage: gg.is_isomorphic(G.as_permutation_group())179True180sage: all([groups.presentation.FGAbelian([i]).as_permutation_group().is_isomorphic(groups.presentation.Cyclic(i).as_permutation_group()) for i in [2..35]])181True182"""183from sage.groups.free_group import _lexi_gen184check_ls = [Integer(x) for x in int_list if Integer(x) >= 0]185if len(check_ls) != len(int_list):186raise ValueError('input list must contain nonnegative entries')187188col_sp = diagonal_matrix(int_list).column_space()189invariants = FGP_Module(ZZ**(len(int_list)), col_sp).invariants()190name_gen = _lexi_gen()191F = FreeGroup([name_gen.next() for i in invariants])192ret_rls = [F([i+1])**invariants[i] for i in range(len(invariants)) if invariants[i]!=0]193194# Build commutator relations195gen_pairs = list(Set(F.gens()).subsets(2))196ret_rls = ret_rls + [x[0]**(-1)*x[1]**(-1)*x[0]*x[1] for x in gen_pairs]197return FinitelyPresentedGroup(F, tuple(ret_rls))198199def DihedralPresentation(n):200r"""201Build the Dihedral group of order `2n` as a finitely presented group.202203INPUT:204205- ``n`` -- The size of the set that `D_n` is acting on.206207OUTPUT:208209Dihedral group of order `2n`.210211EXAMPLES::212213sage: D = groups.presentation.Dihedral(7); D214Finitely presented group < a, b | a^7, b^2, (a*b)^2 >215sage: D.as_permutation_group().is_isomorphic(DihedralGroup(7))216True217218TESTS::219220sage: n = 9221sage: D = groups.presentation.Dihedral(n)222sage: D.ngens() == 2223True224sage: groups.presentation.Dihedral(0)225Traceback (most recent call last):226...227ValueError: finitely presented group order must be positive228"""229n = Integer( n )230if n < 1:231raise ValueError('finitely presented group order must be positive')232F = FreeGroup([ 'a', 'b' ])233rls = F([1])**n, F([2])**2, (F([1])*F([2]))**2234return FinitelyPresentedGroup( F, rls )235236def DiCyclicPresentation(n):237r"""238Build the dicyclic group of order `4n`, for `n \geq 2`, as a finitely239presented group.240241INPUT:242243- ``n`` -- positive integer, 2 or greater, determining the order of244the group (`4n`).245246OUTPUT:247248The dicyclic group of order `4n` is defined by the presentation249250.. MATH::251252\langle a, x \mid a^{2n}=1, x^{2}=a^{n}, x^{-1}ax=a^{-1} \rangle253254.. NOTE::255256This group is also available as a permutation group via257:class:`groups.permutation.DiCyclic <sage.groups.perm_gps.permgroup_named.DiCyclicGroup>`.258259EXAMPLES::260261sage: D = groups.presentation.DiCyclic(9); D262Finitely presented group < a, b | a^18, b^2*a^-9, b^-1*a*b*a >263sage: D.as_permutation_group().is_isomorphic(groups.permutation.DiCyclic(9))264True265266TESTS::267268sage: Q = groups.presentation.DiCyclic(2)269sage: Q.as_permutation_group().is_isomorphic(QuaternionGroup())270True271sage: all([groups.presentation.DiCyclic(i).as_permutation_group(272....: ).is_isomorphic(groups.permutation.DiCyclic(i)) for i in [5,8,12,2^5]])273True274sage: groups.presentation.DiCyclic(1)275Traceback (most recent call last):276...277ValueError: input integer must be greater than 1278"""279n = Integer(n)280if n < 2:281raise ValueError('input integer must be greater than 1')282283F = FreeGroup(['a','b'])284rls = F([1])**(2*n), F([2,2])*F([-1])**n, F([-2,1,2,1])285return FinitelyPresentedGroup(F, rls)286287def SymmetricPresentation(n):288r"""289Build the Symmetric group of order `n!` as a finitely presented group.290291INPUT:292293- ``n`` -- The size of the underlying set of arbitrary symbols being acted294on by the Symmetric group of order `n!`.295296OUTPUT:297298Symmetric group as a finite presentation, implementation uses GAP to find an299isomorphism from a permutation representation to a finitely presented group300representation. Due to this fact, the exact output presentation may not be301the same for every method call on a constant ``n``.302303EXAMPLES::304305sage: S4 = groups.presentation.Symmetric(4)306sage: S4.as_permutation_group().is_isomorphic(SymmetricGroup(4))307True308309TESTS::310311sage: S = [groups.presentation.Symmetric(i) for i in range(1,4)]; S[0].order()3121313sage: S[1].order(), S[2].as_permutation_group().is_isomorphic(DihedralGroup(3))314(2, True)315sage: S5 = groups.presentation.Symmetric(5)316sage: perm_S5 = S5.as_permutation_group(); perm_S5.is_isomorphic(SymmetricGroup(5))317True318sage: groups.presentation.Symmetric(8).order()31940320320"""321from sage.groups.perm_gps.permgroup_named import SymmetricGroup322from sage.groups.free_group import _lexi_gen323324n = Integer(n)325perm_rep = SymmetricGroup(n)326GAP_fp_rep = libgap.Image(libgap.IsomorphismFpGroupByGenerators(perm_rep, perm_rep.gens()))327image_gens = GAP_fp_rep.FreeGeneratorsOfFpGroup()328name_itr = _lexi_gen() # Python generator object for variable names329F = FreeGroup([name_itr.next() for x in perm_rep.gens()])330ret_rls = tuple([F(rel_word.TietzeWordAbstractWord(image_gens).sage())331for rel_word in GAP_fp_rep.RelatorsOfFpGroup()])332return FinitelyPresentedGroup(F,ret_rls)333334def QuaternionPresentation():335r"""336Build the Quaternion group of order 8 as a finitely presented group.337338OUTPUT:339340Quaternion group as a finite presentation.341342EXAMPLES::343344sage: Q = groups.presentation.Quaternion(); Q345Finitely presented group < a, b | a^4, b^2*a^-2, a*b*a*b^-1 >346sage: Q.as_permutation_group().is_isomorphic(QuaternionGroup())347True348349TESTS::350351sage: Q = groups.presentation.Quaternion()352sage: Q.order(), Q.is_abelian()353(8, False)354sage: Q.is_isomorphic(groups.presentation.DiCyclic(2))355True356"""357F = FreeGroup(['a','b'])358rls = F([1])**4, F([2,2,-1,-1]), F([1,2,1,-2])359return FinitelyPresentedGroup(F, rls)360361def AlternatingPresentation(n):362r"""363Build the Alternating group of order `n!/2` as a finitely presented group.364365INPUT:366367- ``n`` -- The size of the underlying set of arbitrary symbols being acted368on by the Alternating group of order `n!/2`.369370OUTPUT:371372Alternating group as a finite presentation, implementation uses GAP to find an373isomorphism from a permutation representation to a finitely presented group374representation. Due to this fact, the exact output presentation may not be375the same for every method call on a constant ``n``.376377EXAMPLES::378379sage: A6 = groups.presentation.Alternating(6)380sage: A6.as_permutation_group().is_isomorphic(AlternatingGroup(6)), A6.order()381(True, 360)382383TESTS::384385sage: #even permutation test..386sage: A1 = groups.presentation.Alternating(1); A2 = groups.presentation.Alternating(2)387sage: A1.is_isomorphic(A2), A1.order()388(True, 1)389sage: A3 = groups.presentation.Alternating(3); A3.order(), A3.as_permutation_group().is_cyclic()390(3, True)391sage: A8 = groups.presentation.Alternating(8); A8.order()39220160393"""394from sage.groups.perm_gps.permgroup_named import AlternatingGroup395from sage.groups.free_group import _lexi_gen396397n = Integer(n)398perm_rep = AlternatingGroup(n)399GAP_fp_rep = libgap.Image(libgap.IsomorphismFpGroupByGenerators(perm_rep, perm_rep.gens()))400image_gens = GAP_fp_rep.FreeGeneratorsOfFpGroup()401name_itr = _lexi_gen() # Python generator object for variable names402F = FreeGroup([name_itr.next() for x in perm_rep.gens()])403ret_rls = tuple([F(rel_word.TietzeWordAbstractWord(image_gens).sage())404for rel_word in GAP_fp_rep.RelatorsOfFpGroup()])405return FinitelyPresentedGroup(F,ret_rls)406407def KleinFourPresentation():408r"""409Build the Klein group of order `4` as a finitely presented group.410411OUTPUT:412413Klein four group (`C_2 \times C_2`) as a finitely presented group.414415EXAMPLES::416417sage: K = groups.presentation.KleinFour(); K418Finitely presented group < a, b | a^2, b^2, a^-1*b^-1*a*b >419"""420F = FreeGroup(['a','b'])421rls = F([1])**2, F([2])**2, F([-1])*F([-2])*F([1])*F([2])422return FinitelyPresentedGroup(F, rls)423424425