Ticket #4531: sage-4531.patch

File sage-4531.patch, 20.1 KB (added by was, 14 years ago)
  • sage/combinat/species/library.py

    # HG changeset patch
    # User William Stein <wstein@gmail.com>
    # Date 1227027051 28800
    # Node ID e50562037671b82e59ff59dcfbfffc111046b233
    # Parent  5e45f3ee796ad08b6a3467a21f4809ba9e2d69dc
    trac #4531 -- change permutation groups so that input gens are canonicalized by default.
    
    diff -r 5e45f3ee796a -r e50562037671 sage/combinat/species/library.py
    a b  
    8484        sage: a = B.structures([1,2,3,4,5]).random_element(); a
    8585        2*((5*3)*(4*1))
    8686        sage: a.automorphism_group()
    87         Permutation Group with generators [(), ()]
     87        Permutation Group with generators [()]
    8888
    8989    TESTS:
    9090        sage: seq = B.isotype_generating_series().counts(10)[1:] #optional
  • sage/combinat/species/permutation_species.py

    diff -r 5e45f3ee796a -r e50562037671 sage/combinat/species/permutation_species.py
    a b  
    8585            sage: a = P.structures(["a", "b", "c", "d"]).random_element(); a
    8686            ['a', 'c', 'b', 'd']
    8787            sage: a.automorphism_group()
    88             Permutation Group with generators [(1,4), (2,3)]
     88            Permutation Group with generators [(2,3), (1,4)]
    8989
    9090            sage: [a.transport(perm) for perm in a.automorphism_group()]
    9191            [['a', 'c', 'b', 'd'],
  • sage/combinat/species/subset_species.py

    diff -r 5e45f3ee796a -r e50562037671 sage/combinat/species/subset_species.py
    a b  
    8585            sage: a = F.structures([1,2,3,4])[6]; a
    8686            {1, 3}
    8787            sage: a.automorphism_group()
    88             Permutation Group with generators [(1,3), (2,4)]
     88            Permutation Group with generators [(2,4), (1,3)]
    8989
    9090            sage: [a.transport(g) for g in a.automorphism_group()]
    9191            [{1, 3}, {1, 3}, {1, 3}, {1, 3}]
  • sage/geometry/polyhedra.py

    diff -r 5e45f3ee796a -r e50562037671 sage/geometry/polyhedra.py
    a b  
    528528        EXAMPLES:
    529529            sage: g3 = polytopes.n_cube(3).graph()
    530530            sage: g3.automorphism_group()
    531             Permutation Group with generators [(1,2)(5,6), (2,4)(3,5),
     531            Permutation Group with generators [(2,4)(3,5), (1,2)(5,6),
    532532            (1,8)(2,3)(4,5)(6,7)]
    533533            sage: s4 = polytopes.n_simplex(4).graph()
    534534            sage: s4.is_eulerian()
  • sage/graphs/graph.py

    diff -r 5e45f3ee796a -r e50562037671 sage/graphs/graph.py
    a b  
    62716271            (6, [(2,3), (1,2)])
    62726272            (2, [(1,4)(2,3)])
    62736273            (2, [(1,2)])
    6274             (8, [(2,3), (1,4), (1,3)(2,4)])
     6274            (8, [(2,3), (1,3)(2,4), (1,4)])
    62756275            (4, [(2,3), (1,4)])
    62766276            (24, [(2,3), (1,2), (1,4)])
    6277            
    62786277            sage: C = graphs.CubeGraph(4)
    62796278            sage: G = C.automorphism_group()
    62806279            sage: M = G.character_table()
  • sage/groups/perm_gps/cubegroup.py

    diff -r 5e45f3ee796a -r e50562037671 sage/groups/perm_gps/cubegroup.py
    a b  
    419419        B = "(33,35,40,38)(34,37,39,36)( 3, 9,46,32)( 2,12,47,29)( 1,14,48,27)" ## B = back or rear
    420420        D = "(41,43,48,46)(42,45,47,44)(14,22,30,38)(15,23,31,39)(16,24,32,40)" ## D = down or bottom
    421421        self.__gens = [B,D,F,L,R,U]
    422         self._group = PermutationGroup([B,D,F,L,R,U])
     422        self._group = PermutationGroup([B,D,F,L,R,U], canonicalize=False)
    423423   
    424424    def gen_names(self):
    425425        return ['B','D','F','L','R','U']
  • sage/groups/perm_gps/permgroup.py

    diff -r 5e45f3ee796a -r e50562037671 sage/groups/perm_gps/permgroup.py
    a b  
    160160    srcs = map(G, srcs)
    161161    return srcs
    162162
    163 def PermutationGroup(gens=None, gap_group=None):
     163def PermutationGroup(gens=None, gap_group=None, canonicalize=True):
    164164    """
    165165    Return the permutation group associated to $x$ (typically a list
    166166    of generators).
    167167
     168    INPUT:
     169        gens -- list of generators
     170        gap_group -- a gap permutation group
     171        canonicalize -- bool (default: True), if True sort generators
     172                        and remove duplicates
     173
     174    OUTPUT:
     175        a permutation group
     176
    168177    EXAMPLES:
    169178        sage: G = PermutationGroup([[(1,2,3),(4,5)],[(3,4)]])
    170179        sage: G
    171         Permutation Group with generators [(1,2,3)(4,5), (3,4)]
     180        Permutation Group with generators [(3,4), (1,2,3)(4,5)]
    172181   
    173182    We can also make permutation groups from PARI groups:
    174183        sage: H = pari('x^4 - 2*x^3 - 2*x + 1').polgalois()
     
    199208        sage: G = PermutationGroup([[(1,2,3),(4,5)],[(3,4)]])
    200209        sage: current_randstate().set_seed_gap()
    201210        sage: G._gap_().DerivedSeries()
    202         [ Group( [ (1,2,3)(4,5), (3,4) ] ), Group( [ (1,5)(3,4), (1,5)(2,3), (1,5,4) ] ) ]
     211        [ Group( [ (3,4), (1,2,3)(4,5) ] ), Group( [ (1,5)(3,4), (1,5)(2,4), (1,5,3) ] ) ]
    203212
    204213    TESTS:
    205214        sage: PermutationGroup(SymmetricGroup(5))
     
    212221        return gens._permgroup_()
    213222    if gens is not None and not isinstance(gens, (tuple,list, GapElement)):
    214223        raise TypeError, "gens must be a tuple, list, or GapElement"
    215     return PermutationGroup_generic(gens=gens, gap_group=gap_group)
     224    return PermutationGroup_generic(gens=gens, gap_group=gap_group, canonicalize=canonicalize)
    216225   
    217226
    218227class PermutationGroup_generic(group.FiniteGroup):
     
    220229    EXAMPLES:
    221230        sage: G = PermutationGroup([[(1,2,3),(4,5)],[(3,4)]])
    222231        sage: G
    223         Permutation Group with generators [(1,2,3)(4,5), (3,4)]
     232        Permutation Group with generators [(3,4), (1,2,3)(4,5)]
    224233        sage: G.center()
    225234        Permutation Group with generators [()]
    226235        sage: G.group_id()          # requires optional database_gap
     
    231240        sage: loads(G.dumps()) == G
    232241        True
    233242    """
    234     def __init__(self, gens=None, gap_group=None):
     243    def __init__(self, gens=None, gap_group=None, canonicalize=True):
    235244        r"""
     245        INPUT:
     246            gens -- list of generators
     247            gap_group -- a gap permutation group
     248            canonicalize -- bool (default: True), if True sort generators
     249                            and remove duplicates
     250
     251         OUTPUT:
     252            a permutation group
     253
    236254        EXAMPLES:
    237255        We explicitly construct the alternating group on four elements.
    238256            sage: A4 = PermutationGroup([[(1,2,3)],[(2,3,4)]]); A4
    239             Permutation Group with generators [(1,2,3), (2,3,4)]
     257            Permutation Group with generators [(2,3,4), (1,2,3)]
    240258            sage: A4.__init__([[(1,2,3)],[(2,3,4)]]); A4
    241             Permutation Group with generators [(1,2,3), (2,3,4)]
     259            Permutation Group with generators [(2,3,4), (1,2,3)]
    242260            sage: A4.center()
    243261            Permutation Group with generators [()]
    244262            sage: loads(A4.dumps()) == A4
     
    256274        gens = [PermutationGroupElement(x, check=False).list() for x in gens]
    257275        self._deg = max([1]+[max(g) for g in gens])
    258276        gens = [PermutationGroupElement(x, self, check=False) for x in gens]
     277        if canonicalize:
     278             gens = list(set(gens))
     279             gens.sort()
    259280        self._gens = gens
    260281        self._gap_string = 'Group(%s)'%gens
    261282
     
    291312        The \code{_gap_init_} method shows how you would define the Sage
    292313        \code{PermutationGroup_generic} object in Gap:
    293314            sage: A4 = PermutationGroup([[(1,2,3)],[(2,3,4)]]); A4
    294             Permutation Group with generators [(1,2,3), (2,3,4)]
     315            Permutation Group with generators [(2,3,4), (1,2,3)]
    295316            sage: A4._gap_init_()
    296             'Group([(1,2,3), (2,3,4)])'
     317            'Group([(2,3,4), (1,2,3)])'
    297318        """
    298319        return self._gap_string
    299320
     
    305326        We explicitly construct the alternating group on four elements. In
    306327        Magma, one would type the string below to construct the group.
    307328            sage: A4 = PermutationGroup([[(1,2,3)],[(2,3,4)]]); A4
    308             Permutation Group with generators [(1,2,3), (2,3,4)]
     329            Permutation Group with generators [(2,3,4), (1,2,3)]
    309330            sage: A4._magma_init_()
    310             'PermutationGroup<4 | (1,2,3), (2,3,4)>'
     331            'PermutationGroup<4 | (2,3,4), (1,2,3)>'
    311332        """
    312333        g = str(self.gens())[1:-1]
    313334        return 'PermutationGroup<%s | %s>'%(self.degree(), g)
     
    513534        EXAMPLES:
    514535            sage: G = PermutationGroup([[(1,2,3)], [(1,2)]])
    515536            sage: G.gens()
    516             [(1,2,3), (1,2)]
     537            [(1,2), (1,2,3)]
    517538
    518         Note that the generators need not be minimal.
    519             sage: G = PermutationGroup([[(1,2)], [(1,2)]])
     539        Note that the generators need not be minimal though duplicates are removed.
     540            sage: G = PermutationGroup([[(1,2)], [(1,3)], [(2,3)], [(1,2)]])
    520541            sage: G.gens()
    521             [(1,2), (1,2)]
     542            [(2,3), (1,2), (1,3)]
    522543           
    523544            sage: G = PermutationGroup([[(1,2,3,4), (5,6)], [(1,2)]])
    524545            sage: g = G.gens()
    525546            sage: g[0]
     547            (1,2)
     548            sage: g[1]
    526549            (1,2,3,4)(5,6)
    527             sage: g[1]
    528             (1,2)
    529550
    530551        TESTS:
    531552        We make sure that the trivial group gets handled correctly.
     
    562583        EXAMPLES:
    563584        We explicitly construct the alternating group on four elements:
    564585            sage: A4 = PermutationGroup([[(1,2,3)],[(2,3,4)]]); A4
    565             Permutation Group with generators [(1,2,3), (2,3,4)]
     586            Permutation Group with generators [(2,3,4), (1,2,3)]
    566587            sage: A4.gens()
    567             [(1,2,3), (2,3,4)]
     588            [(2,3,4), (1,2,3)]
    568589            sage: A4.gen(0)
     590            (2,3,4)
     591            sage: A4.gen(1)
    569592            (1,2,3)
    570             sage: A4.gen(1)
     593            sage: A4.gens()[0]; A4.gens()[1]
    571594            (2,3,4)
    572             sage: A4.gens()[0]; A4.gens()[1]
    573595            (1,2,3)
    574             (2,3,4)
    575596        """
    576597        return self.gens()[i]
    577598
     
    729750
    730751        EXAMPLES:
    731752        We explicitly construct the alternating group on four elements. Note
    732         that
    733         the \code{AlternatingGroup} class has its own representation string:
     753        that the \code{AlternatingGroup} class has its own representation string.
     754       
    734755            sage: A4 = PermutationGroup([[(1,2,3)],[(2,3,4)]]); A4
    735             Permutation Group with generators [(1,2,3), (2,3,4)]
     756            Permutation Group with generators [(2,3,4), (1,2,3)]
    736757            sage: A4._repr_()
    737             'Permutation Group with generators [(1,2,3), (2,3,4)]'
     758            'Permutation Group with generators [(2,3,4), (1,2,3)]'
    738759            sage: AlternatingGroup(4)._repr_()
    739760            'Alternating group of order 4!/2 as a permutation group'
    740761        """
     
    749770        EXAMPLES:
    750771        We explicitly construct the alternating group on four elements.
    751772            sage: A4 = PermutationGroup([[(1,2,3)],[(2,3,4)]]); A4
    752             Permutation Group with generators [(1,2,3), (2,3,4)]
     773            Permutation Group with generators [(2,3,4), (1,2,3)]
    753774            sage: latex(A4)
    754             \langle (1,2,3), (2,3,4) \rangle
     775            \langle (2,3,4), (1,2,3) \rangle
    755776            sage: A4._latex_()
    756             '\\langle (1,2,3), (2,3,4) \\rangle'
     777            '\\langle (2,3,4), (1,2,3) \\rangle'
    757778        """
    758779        return '\\langle ' + \
    759780               ', '.join([x._latex_() for x in self.gens()]) + ' \\rangle'
     
    897918            sage: G = PermutationGroup([(1,2,3),(3,4,5)])
    898919            sage: g = G((1,2,3))
    899920            sage: G.subgroup([g])
    900             Subgroup of Permutation Group with generators [(1,2,3), (3,4,5)] generated by [(1,2,3)]
     921            Subgroup of Permutation Group with generators [(3,4,5), (1,2,3)] generated by [(1,2,3)]
    901922
    902923        """
    903924        return PermutationGroup_subgroup(self, gens)
     
    12441265            sage: G = PermutationGroup([[(1,2),(3,4)], [(1,2,3,4)]])
    12451266            sage: g = G([(1,3)])
    12461267            sage: G.normalizer(g)
    1247             Permutation Group with generators [(1,3), (2,4)]
     1268            Permutation Group with generators [(2,4), (1,3)]
    12481269            sage: g = G([(1,2,3,4)])
    12491270            sage: G.normalizer(g)
    1250             Permutation Group with generators [(1,2,3,4), (1,3)(2,4), (2,4)]
     1271            Permutation Group with generators [(2,4), (1,2,3,4), (1,3)(2,4)]
    12511272            sage: H = G.subgroup([G([(1,2,3,4)])])
    12521273            sage: G.normalizer(H)
    1253             Permutation Group with generators [(1,2,3,4), (1,3)(2,4), (2,4)]
     1274            Permutation Group with generators [(2,4), (1,2,3,4), (1,3)(2,4)]
    12541275
    12551276        """
    12561277        N = self._gap_().Normalizer(g)
     
    12641285            sage: G = PermutationGroup([[(1,2),(3,4)], [(1,2,3,4)]])
    12651286            sage: g = G([(1,3)])
    12661287            sage: G.centralizer(g)
    1267             Permutation Group with generators [(1,3), (2,4)]
     1288            Permutation Group with generators [(2,4), (1,3)]
    12681289            sage: g = G([(1,2,3,4)])
    12691290            sage: G.centralizer(g)
    12701291            Permutation Group with generators [(1,2,3,4)]
     
    13711392            sage: G = PermutationGroup([(1,2,3), (2,3)])
    13721393            sage: H = PermutationGroup([(1,2,4), (1,4)])
    13731394            sage: G.isomorphism_to(H)
    1374             Homomorphism : Permutation Group with generators [(1,2,3), (2,3)] --> Permutation Group with generators [(1,2,4), (1,4)]
     1395            Homomorphism : Permutation Group with generators [(2,3), (1,2,3)] --> Permutation Group with generators [(1,2,4), (1,4)]
    13751396        """
    13761397        current_randstate().set_seed_gap()
    13771398
     
    18321853        sage: K.gens()
    18331854        [(1,2,3,4)]
    18341855    """
    1835     def __init__(self, ambient, gens, from_group = False, check=True):
     1856    def __init__(self, ambient, gens, from_group = False, check=True, canonicalize=True):
    18361857        r"""
    18371858        Initialization method for the \code{PermutationGroup_subgroup} class.
    18381859
     
    18411862            gens -- the generators of the subgroup
    18421863            from_group -- True: subroup is generated from a Gap string representation of the generators
    18431864            check-- True: checks if gens are indeed elements of the ambient group
    1844            
     1865            canonicalize -- bool (default: True), if True sort generators
     1866                            and remove duplicates
     1867
    18451868        EXAMPLES:
    18461869        An example involving the dihedral group on four elements. $D_8$
    18471870        contains a cyclic subgroup or order four:
     
    18841907                    raise TypeError, "each generator must be in the ambient group"
    18851908        self.__ambient_group = G
    18861909       
    1887         PermutationGroup_generic.__init__(self, gens)
     1910        PermutationGroup_generic.__init__(self, gens, canonicalize=canonicalize)
    18881911
    18891912    def __cmp__(self, other):
    18901913        r"""
  • sage/groups/perm_gps/permgroup_element.pyx

    diff -r 5e45f3ee796a -r e50562037671 sage/groups/perm_gps/permgroup_element.pyx
    a b  
    185185        First we construct elements by multiplying together generators
    186186        for a group.
    187187
    188             sage: G = PermutationGroup(['(1,2)(3,4)', '(3,4,5,6)'])
     188            sage: G = PermutationGroup(['(1,2)(3,4)', '(3,4,5,6)'], canonicalize=False)
    189189            sage: s = G.gens()
    190190            sage: s[0]
    191191            (1,2)(3,4)
     
    404404        Compare group elements self and right.
    405405       
    406406        EXAMPLES:
    407             sage: G = PermutationGroup([[(1,2,3),(4,5)],[(3,4)]])
     407            sage: G = PermutationGroup([[(3,4)], [(1,2,3),(4,5)]])
    408408            sage: G.gen(0) < G.gen(1)
     409            True
     410            sage: G.gen(0) > G.gen(1)
    409411            False
    410             sage: G.gen(0) > G.gen(1)
    411             True
    412412        """
    413413        cdef int i
    414414        cdef bint equal = 1
     
    812812        functions "EpimorphismFromFreeGroup" and "PreImagesRepresentative".
    813813
    814814        EXAMPLE:
    815             sage: G = PermutationGroup([[(1,2,3),(4,5)],[(3,4)]])
     815            sage: G = PermutationGroup([[(1,2,3),(4,5)],[(3,4)]], canonicalize=False)
    816816            sage: g1 = G.gens()[0]
    817817            sage: g2 = G.gens()[1]
    818818            sage: h = g1^2*g2*g1
  • sage/misc/randstate.pyx

    diff -r 5e45f3ee796a -r e50562037671 sage/misc/randstate.pyx
    a b  
    5151
    5252sage: set_random_seed(0)
    5353sage: rtest()
    54 (303, -0.187141682737491, 1/2*x^2 - 1/95*x - 1/2, (1,2), [ 0, 0, 0, 0, 1 ], 1698070399, 8045, 0.96619117347084138)
     54(303, -0.187141682737491, 1/2*x^2 - 1/95*x - 1/2, (1,2,3)(4,5), [ 0, 0, 0, 0, 1 ], 1698070399, 8045, 0.96619117347084138)
    5555sage: set_random_seed(1)
    5656sage: rtest()
    57 (978, 0.184109262667515, -3*x^2 - 1/12, (2,3), [ 0, 1, 1, 0, 0 ], 1046254370, 60359, 0.83350776541997362)
     57(978, 0.184109262667515, -3*x^2 - 1/12, (4,5), [ 0, 1, 1, 0, 0 ], 1046254370, 60359, 0.83350776541997362)
    5858sage: set_random_seed(2)
    5959sage: rtest()
    6060(207, 0.505364206568040, 4*x^2 + 1/2, (1,2)(4,5), [ 0, 0, 1, 0, 1 ], 2137873234, 27695, 0.19982565117278328)
    6161sage: set_random_seed(0)
    6262sage: rtest()
    63 (303, -0.187141682737491, 1/2*x^2 - 1/95*x - 1/2, (1,2), [ 0, 0, 0, 0, 1 ], 1698070399, 8045, 0.96619117347084138)
     63(303, -0.187141682737491, 1/2*x^2 - 1/95*x - 1/2, (1,2,3)(4,5), [ 0, 0, 0, 0, 1 ], 1698070399, 8045, 0.96619117347084138)
    6464sage: set_random_seed(1)
    6565sage: rtest()
    66 (978, 0.184109262667515, -3*x^2 - 1/12, (2,3), [ 0, 1, 1, 0, 0 ], 1046254370, 60359, 0.83350776541997362)
     66(978, 0.184109262667515, -3*x^2 - 1/12, (4,5), [ 0, 1, 1, 0, 0 ], 1046254370, 60359, 0.83350776541997362)
    6767sage: set_random_seed(2)
    6868sage: rtest()
    6969(207, 0.505364206568040, 4*x^2 + 1/2, (1,2)(4,5), [ 0, 0, 1, 0, 1 ], 2137873234, 27695, 0.19982565117278328)
     
    210210
    211211sage: set_random_seed(0)
    212212sage: r1 = rtest(); r1
    213 (303, -0.187141682737491, 1/2*x^2 - 1/95*x - 1/2, (1,2), [ 0, 0, 0, 0, 1 ], 1698070399, 8045, 0.96619117347084138)
     213(303, -0.187141682737491, 1/2*x^2 - 1/95*x - 1/2, (1,2,3)(4,5), [ 0, 0, 0, 0, 1 ], 1698070399, 8045, 0.96619117347084138)
    214214sage: r2 = rtest(); r2
    215 (105, -0.581229341007821, -x^2 - x - 6, (1,3,2)(4,5), [ 1, 0, 0, 1, 1 ], 697338742, 1271, 0.001767155077382232)
     215(105, -0.581229341007821, -x^2 - x - 6, (1,3), [ 1, 0, 0, 1, 1 ], 697338742, 1271, 0.001767155077382232)
    216216
    217217We get slightly different results with an intervening \code{with seed}.
    218218
     
    220220sage: r1 == rtest()
    221221True
    222222sage: with seed(1): rtest()
    223 (978, 0.184109262667515, -3*x^2 - 1/12, (2,3), [ 0, 1, 1, 0, 0 ], 1046254370, 60359, 0.83350776541997362)
     223(978, 0.184109262667515, -3*x^2 - 1/12, (4,5), [ 0, 1, 1, 0, 0 ], 1046254370, 60359, 0.83350776541997362)
    224224sage: r2m = rtest(); r2m
    225 (105, -0.581229341007821, -x^2 - x - 6, (1,3,2)(4,5), [ 1, 0, 0, 1, 1 ], 697338742, 19769, 0.001767155077382232)
     225(105, -0.581229341007821, -x^2 - x - 6, (1,3), [ 1, 0, 0, 1, 1 ], 697338742, 19769, 0.001767155077382232)
    226226sage: r2m == r2
    227227False
    228228
     
    237237sage: r1 == rtest()
    238238True
    239239sage: with seed(1): (rtest(), rtest())
    240 ((978, 0.184109262667515, -3*x^2 - 1/12, (2,3), [ 0, 1, 1, 0, 0 ], 1046254370, 60359, 0.83350776541997362), (138, -0.247578366457583, 2*x - 24, (), [ 1, 1, 1, 0, 1 ], 1077419109, 10234, 0.0033332230808060803))
     240((978, 0.184109262667515, -3*x^2 - 1/12, (4,5), [ 0, 1, 1, 0, 0 ], 1046254370, 60359, 0.83350776541997362), (138, -0.247578366457583, 2*x - 24, (), [ 1, 1, 1, 0, 1 ], 1077419109, 10234, 0.0033332230808060803))
    241241sage: r2m == rtest()
    242242True
    243243
     
    257257... finally:
    258258...       ctx.__exit__(None, None, None)
    259259<sage.misc.randstate.randstate object at 0x...>
    260 (978, 0.184109262667515, -3*x^2 - 1/12, (2,3), [ 0, 1, 1, 0, 0 ], 1046254370, 60359, 0.83350776541997362)
     260(978, 0.184109262667515, -3*x^2 - 1/12, (4,5), [ 0, 1, 1, 0, 0 ], 1046254370, 60359, 0.83350776541997362)
    261261False
    262262sage: r2m == rtest()
    263263True