Ticket #4531: sage-4531.patch
File sage-4531.patch, 20.1 KB (added by , 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 84 84 sage: a = B.structures([1,2,3,4,5]).random_element(); a 85 85 2*((5*3)*(4*1)) 86 86 sage: a.automorphism_group() 87 Permutation Group with generators [() , ()]87 Permutation Group with generators [()] 88 88 89 89 TESTS: 90 90 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 85 85 sage: a = P.structures(["a", "b", "c", "d"]).random_element(); a 86 86 ['a', 'c', 'b', 'd'] 87 87 sage: a.automorphism_group() 88 Permutation Group with generators [( 1,4), (2,3)]88 Permutation Group with generators [(2,3), (1,4)] 89 89 90 90 sage: [a.transport(perm) for perm in a.automorphism_group()] 91 91 [['a', 'c', 'b', 'd'], -
sage/combinat/species/subset_species.py
diff -r 5e45f3ee796a -r e50562037671 sage/combinat/species/subset_species.py
a b 85 85 sage: a = F.structures([1,2,3,4])[6]; a 86 86 {1, 3} 87 87 sage: a.automorphism_group() 88 Permutation Group with generators [( 1,3), (2,4)]88 Permutation Group with generators [(2,4), (1,3)] 89 89 90 90 sage: [a.transport(g) for g in a.automorphism_group()] 91 91 [{1, 3}, {1, 3}, {1, 3}, {1, 3}] -
sage/geometry/polyhedra.py
diff -r 5e45f3ee796a -r e50562037671 sage/geometry/polyhedra.py
a b 528 528 EXAMPLES: 529 529 sage: g3 = polytopes.n_cube(3).graph() 530 530 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), 532 532 (1,8)(2,3)(4,5)(6,7)] 533 533 sage: s4 = polytopes.n_simplex(4).graph() 534 534 sage: s4.is_eulerian() -
sage/graphs/graph.py
diff -r 5e45f3ee796a -r e50562037671 sage/graphs/graph.py
a b 6271 6271 (6, [(2,3), (1,2)]) 6272 6272 (2, [(1,4)(2,3)]) 6273 6273 (2, [(1,2)]) 6274 (8, [(2,3), (1, 4), (1,3)(2,4)])6274 (8, [(2,3), (1,3)(2,4), (1,4)]) 6275 6275 (4, [(2,3), (1,4)]) 6276 6276 (24, [(2,3), (1,2), (1,4)]) 6277 6278 6277 sage: C = graphs.CubeGraph(4) 6279 6278 sage: G = C.automorphism_group() 6280 6279 sage: M = G.character_table() -
sage/groups/perm_gps/cubegroup.py
diff -r 5e45f3ee796a -r e50562037671 sage/groups/perm_gps/cubegroup.py
a b 419 419 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 420 420 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 421 421 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) 423 423 424 424 def gen_names(self): 425 425 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 160 160 srcs = map(G, srcs) 161 161 return srcs 162 162 163 def PermutationGroup(gens=None, gap_group=None ):163 def PermutationGroup(gens=None, gap_group=None, canonicalize=True): 164 164 """ 165 165 Return the permutation group associated to $x$ (typically a list 166 166 of generators). 167 167 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 168 177 EXAMPLES: 169 178 sage: G = PermutationGroup([[(1,2,3),(4,5)],[(3,4)]]) 170 179 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)] 172 181 173 182 We can also make permutation groups from PARI groups: 174 183 sage: H = pari('x^4 - 2*x^3 - 2*x + 1').polgalois() … … 199 208 sage: G = PermutationGroup([[(1,2,3),(4,5)],[(3,4)]]) 200 209 sage: current_randstate().set_seed_gap() 201 210 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) ] ) ] 203 212 204 213 TESTS: 205 214 sage: PermutationGroup(SymmetricGroup(5)) … … 212 221 return gens._permgroup_() 213 222 if gens is not None and not isinstance(gens, (tuple,list, GapElement)): 214 223 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) 216 225 217 226 218 227 class PermutationGroup_generic(group.FiniteGroup): … … 220 229 EXAMPLES: 221 230 sage: G = PermutationGroup([[(1,2,3),(4,5)],[(3,4)]]) 222 231 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)] 224 233 sage: G.center() 225 234 Permutation Group with generators [()] 226 235 sage: G.group_id() # requires optional database_gap … … 231 240 sage: loads(G.dumps()) == G 232 241 True 233 242 """ 234 def __init__(self, gens=None, gap_group=None ):243 def __init__(self, gens=None, gap_group=None, canonicalize=True): 235 244 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 236 254 EXAMPLES: 237 255 We explicitly construct the alternating group on four elements. 238 256 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)] 240 258 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)] 242 260 sage: A4.center() 243 261 Permutation Group with generators [()] 244 262 sage: loads(A4.dumps()) == A4 … … 256 274 gens = [PermutationGroupElement(x, check=False).list() for x in gens] 257 275 self._deg = max([1]+[max(g) for g in gens]) 258 276 gens = [PermutationGroupElement(x, self, check=False) for x in gens] 277 if canonicalize: 278 gens = list(set(gens)) 279 gens.sort() 259 280 self._gens = gens 260 281 self._gap_string = 'Group(%s)'%gens 261 282 … … 291 312 The \code{_gap_init_} method shows how you would define the Sage 292 313 \code{PermutationGroup_generic} object in Gap: 293 314 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)] 295 316 sage: A4._gap_init_() 296 'Group([( 1,2,3), (2,3,4)])'317 'Group([(2,3,4), (1,2,3)])' 297 318 """ 298 319 return self._gap_string 299 320 … … 305 326 We explicitly construct the alternating group on four elements. In 306 327 Magma, one would type the string below to construct the group. 307 328 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)] 309 330 sage: A4._magma_init_() 310 'PermutationGroup<4 | ( 1,2,3), (2,3,4)>'331 'PermutationGroup<4 | (2,3,4), (1,2,3)>' 311 332 """ 312 333 g = str(self.gens())[1:-1] 313 334 return 'PermutationGroup<%s | %s>'%(self.degree(), g) … … 513 534 EXAMPLES: 514 535 sage: G = PermutationGroup([[(1,2,3)], [(1,2)]]) 515 536 sage: G.gens() 516 [(1,2 ,3), (1,2)]537 [(1,2), (1,2,3)] 517 538 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)]]) 520 541 sage: G.gens() 521 [( 1,2), (1,2)]542 [(2,3), (1,2), (1,3)] 522 543 523 544 sage: G = PermutationGroup([[(1,2,3,4), (5,6)], [(1,2)]]) 524 545 sage: g = G.gens() 525 546 sage: g[0] 547 (1,2) 548 sage: g[1] 526 549 (1,2,3,4)(5,6) 527 sage: g[1]528 (1,2)529 550 530 551 TESTS: 531 552 We make sure that the trivial group gets handled correctly. … … 562 583 EXAMPLES: 563 584 We explicitly construct the alternating group on four elements: 564 585 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)] 566 587 sage: A4.gens() 567 [( 1,2,3), (2,3,4)]588 [(2,3,4), (1,2,3)] 568 589 sage: A4.gen(0) 590 (2,3,4) 591 sage: A4.gen(1) 569 592 (1,2,3) 570 sage: A4.gen (1)593 sage: A4.gens()[0]; A4.gens()[1] 571 594 (2,3,4) 572 sage: A4.gens()[0]; A4.gens()[1]573 595 (1,2,3) 574 (2,3,4)575 596 """ 576 597 return self.gens()[i] 577 598 … … 729 750 730 751 EXAMPLES: 731 752 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 734 755 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)] 736 757 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)]' 738 759 sage: AlternatingGroup(4)._repr_() 739 760 'Alternating group of order 4!/2 as a permutation group' 740 761 """ … … 749 770 EXAMPLES: 750 771 We explicitly construct the alternating group on four elements. 751 772 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)] 753 774 sage: latex(A4) 754 \langle ( 1,2,3), (2,3,4) \rangle775 \langle (2,3,4), (1,2,3) \rangle 755 776 sage: A4._latex_() 756 '\\langle ( 1,2,3), (2,3,4) \\rangle'777 '\\langle (2,3,4), (1,2,3) \\rangle' 757 778 """ 758 779 return '\\langle ' + \ 759 780 ', '.join([x._latex_() for x in self.gens()]) + ' \\rangle' … … 897 918 sage: G = PermutationGroup([(1,2,3),(3,4,5)]) 898 919 sage: g = G((1,2,3)) 899 920 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)] 901 922 902 923 """ 903 924 return PermutationGroup_subgroup(self, gens) … … 1244 1265 sage: G = PermutationGroup([[(1,2),(3,4)], [(1,2,3,4)]]) 1245 1266 sage: g = G([(1,3)]) 1246 1267 sage: G.normalizer(g) 1247 Permutation Group with generators [( 1,3), (2,4)]1268 Permutation Group with generators [(2,4), (1,3)] 1248 1269 sage: g = G([(1,2,3,4)]) 1249 1270 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)] 1251 1272 sage: H = G.subgroup([G([(1,2,3,4)])]) 1252 1273 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)] 1254 1275 1255 1276 """ 1256 1277 N = self._gap_().Normalizer(g) … … 1264 1285 sage: G = PermutationGroup([[(1,2),(3,4)], [(1,2,3,4)]]) 1265 1286 sage: g = G([(1,3)]) 1266 1287 sage: G.centralizer(g) 1267 Permutation Group with generators [( 1,3), (2,4)]1288 Permutation Group with generators [(2,4), (1,3)] 1268 1289 sage: g = G([(1,2,3,4)]) 1269 1290 sage: G.centralizer(g) 1270 1291 Permutation Group with generators [(1,2,3,4)] … … 1371 1392 sage: G = PermutationGroup([(1,2,3), (2,3)]) 1372 1393 sage: H = PermutationGroup([(1,2,4), (1,4)]) 1373 1394 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)] 1375 1396 """ 1376 1397 current_randstate().set_seed_gap() 1377 1398 … … 1832 1853 sage: K.gens() 1833 1854 [(1,2,3,4)] 1834 1855 """ 1835 def __init__(self, ambient, gens, from_group = False, check=True ):1856 def __init__(self, ambient, gens, from_group = False, check=True, canonicalize=True): 1836 1857 r""" 1837 1858 Initialization method for the \code{PermutationGroup_subgroup} class. 1838 1859 … … 1841 1862 gens -- the generators of the subgroup 1842 1863 from_group -- True: subroup is generated from a Gap string representation of the generators 1843 1864 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 1845 1868 EXAMPLES: 1846 1869 An example involving the dihedral group on four elements. $D_8$ 1847 1870 contains a cyclic subgroup or order four: … … 1884 1907 raise TypeError, "each generator must be in the ambient group" 1885 1908 self.__ambient_group = G 1886 1909 1887 PermutationGroup_generic.__init__(self, gens )1910 PermutationGroup_generic.__init__(self, gens, canonicalize=canonicalize) 1888 1911 1889 1912 def __cmp__(self, other): 1890 1913 r""" -
sage/groups/perm_gps/permgroup_element.pyx
diff -r 5e45f3ee796a -r e50562037671 sage/groups/perm_gps/permgroup_element.pyx
a b 185 185 First we construct elements by multiplying together generators 186 186 for a group. 187 187 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) 189 189 sage: s = G.gens() 190 190 sage: s[0] 191 191 (1,2)(3,4) … … 404 404 Compare group elements self and right. 405 405 406 406 EXAMPLES: 407 sage: G = PermutationGroup([[( 1,2,3),(4,5)],[(3,4)]])407 sage: G = PermutationGroup([[(3,4)], [(1,2,3),(4,5)]]) 408 408 sage: G.gen(0) < G.gen(1) 409 True 410 sage: G.gen(0) > G.gen(1) 409 411 False 410 sage: G.gen(0) > G.gen(1)411 True412 412 """ 413 413 cdef int i 414 414 cdef bint equal = 1 … … 812 812 functions "EpimorphismFromFreeGroup" and "PreImagesRepresentative". 813 813 814 814 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) 816 816 sage: g1 = G.gens()[0] 817 817 sage: g2 = G.gens()[1] 818 818 sage: h = g1^2*g2*g1 -
sage/misc/randstate.pyx
diff -r 5e45f3ee796a -r e50562037671 sage/misc/randstate.pyx
a b 51 51 52 52 sage: set_random_seed(0) 53 53 sage: 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) 55 55 sage: set_random_seed(1) 56 56 sage: 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) 58 58 sage: set_random_seed(2) 59 59 sage: rtest() 60 60 (207, 0.505364206568040, 4*x^2 + 1/2, (1,2)(4,5), [ 0, 0, 1, 0, 1 ], 2137873234, 27695, 0.19982565117278328) 61 61 sage: set_random_seed(0) 62 62 sage: 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) 64 64 sage: set_random_seed(1) 65 65 sage: 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) 67 67 sage: set_random_seed(2) 68 68 sage: rtest() 69 69 (207, 0.505364206568040, 4*x^2 + 1/2, (1,2)(4,5), [ 0, 0, 1, 0, 1 ], 2137873234, 27695, 0.19982565117278328) … … 210 210 211 211 sage: set_random_seed(0) 212 212 sage: 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) 214 214 sage: 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) 216 216 217 217 We get slightly different results with an intervening \code{with seed}. 218 218 … … 220 220 sage: r1 == rtest() 221 221 True 222 222 sage: 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) 224 224 sage: 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) 226 226 sage: r2m == r2 227 227 False 228 228 … … 237 237 sage: r1 == rtest() 238 238 True 239 239 sage: 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)) 241 241 sage: r2m == rtest() 242 242 True 243 243 … … 257 257 ... finally: 258 258 ... ctx.__exit__(None, None, None) 259 259 <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) 261 261 False 262 262 sage: r2m == rtest() 263 263 True