@@ -436,7 +436,7 @@ class ColoredPermutations(Parent, UniqueRepresentation):
436
436
[[0, 1, 0], [1, 2, 3]]
437
437
438
438
We can also create a colored permutation by passing
439
- either a list of tuples consisting of ``(color, element)``::
439
+ an iterable consisting of tuples consisting of ``(color, element)``::
440
440
441
441
sage: x = C([(2,1), (3,3), (3,2)]); x
442
442
[[2, 3, 3], [1, 3, 2]]
@@ -445,13 +445,21 @@ class ColoredPermutations(Parent, UniqueRepresentation):
445
445
446
446
sage: C([[3,3,1], [1,3,2]])
447
447
[[3, 3, 1], [1, 3, 2]]
448
+ sage: C(([3,3,1], [1,3,2]))
449
+ [[3, 3, 1], [1, 3, 2]]
448
450
449
451
There is also the natural lift from permutations::
450
452
451
453
sage: P = Permutations(3)
452
454
sage: C(P.an_element())
453
455
[[0, 0, 0], [3, 1, 2]]
454
456
457
+
458
+ A colored permutation::
459
+
460
+ sage: C(C.an_element()) == C.an_element()
461
+ True
462
+
455
463
REFERENCES:
456
464
457
465
- :wikipedia:`Generalized_symmetric_group`
@@ -688,20 +696,22 @@ def _element_constructor_(self, x):
688
696
sage: x == C([[2,3,3], [1,3,2]])
689
697
True
690
698
"""
691
- if isinstance (x , list ):
692
- if isinstance (x [0 ], tuple ):
693
- c = []
694
- p = []
695
- for k in x :
696
- if len (k ) != 2 :
697
- raise ValueError ("input must be pairs (color, element)" )
698
- c .append (self ._C (k [0 ]))
699
- p .append (k [1 ])
700
- return self .element_class (self , c , self ._P (p ))
701
-
702
- if len (x ) != 2 :
703
- raise ValueError ("input must be a pair of a list of colors and a permutation" )
704
- return self .element_class (self , [self ._C (v ) for v in x [0 ]], self ._P (x [1 ]))
699
+ if isinstance (x , self .element_class ) and x .parent () is self :
700
+ return self
701
+ x = list (x )
702
+ if isinstance (x [0 ], tuple ):
703
+ c = []
704
+ p = []
705
+ for k in x :
706
+ if len (k ) != 2 :
707
+ raise ValueError ("input must be pairs (color, element)" )
708
+ c .append (self ._C (k [0 ]))
709
+ p .append (k [1 ])
710
+ return self .element_class (self , c , self ._P (p ))
711
+
712
+ if len (x ) != 2 :
713
+ raise ValueError ("input must be a pair of a list of colors and a permutation" )
714
+ return self .element_class (self , [self ._C (v ) for v in x [0 ]], self ._P (x [1 ]))
705
715
706
716
def _coerce_map_from_ (self , C ):
707
717
"""
@@ -989,6 +999,11 @@ def __classcall_private__(cls, pi):
989
999
sage: SignedPermutation([2, 1, -3])
990
1000
[2, 1, -3]
991
1001
1002
+ sage: SignedPermutation((2,1,-3))
1003
+ [2, 1, -3]
1004
+
1005
+ sage: SignedPermutation(range(1,4))
1006
+ [1, 2, 3]
992
1007
"""
993
1008
return SignedPermutations (len (list (pi )))(pi )
994
1009
@@ -1360,38 +1375,43 @@ def _element_constructor_(self, x):
1360
1375
sage: S([]) == list(S)[0]
1361
1376
True
1362
1377
1363
- """
1364
- if isinstance (x , list ):
1365
- if x and isinstance (x [0 ], tuple ):
1366
- c = []
1367
- p = []
1368
- for k in x :
1369
- if len (k ) != 2 :
1370
- raise ValueError ("input must be pairs (sign, element)" )
1371
- if k [0 ] != 1 and k [0 ] != - 1 :
1372
- raise ValueError ("the sign must be +1 or -1" )
1373
- c .append (ZZ (k [0 ]))
1374
- p .append (k [1 ])
1375
- return self .element_class (self , c , self ._P (p ))
1376
-
1377
- if len (x ) == self ._n :
1378
- c = []
1379
- p = []
1380
- one = ZZ .one ()
1381
- for v in x :
1382
- if v > 0 :
1383
- c .append (one )
1384
- p .append (v )
1385
- else :
1386
- c .append (- one )
1387
- p .append (- v )
1388
- return self .element_class (self , c , self ._P (p ))
1389
-
1390
- if len (x ) != 2 :
1391
- raise ValueError ("input must be a pair of a list of signs and a permutation" )
1392
- if any (s != 1 and s != - 1 for s in x [0 ]):
1393
- raise ValueError ("the sign must be +1 or -1" )
1394
- return self .element_class (self , [ZZ (v ) for v in x [0 ]], self ._P (x [1 ]))
1378
+ sage: T = SignedPermutation(range(1,4))
1379
+ sage: SignedPermutations(3)(T)
1380
+ [1, 2, 3]
1381
+ """
1382
+ if isinstance (x , self .element_class ) and x .parent () is self :
1383
+ return self
1384
+ x = list (x )
1385
+ if x and isinstance (x [0 ], tuple ):
1386
+ c = []
1387
+ p = []
1388
+ for k in x :
1389
+ if len (k ) != 2 :
1390
+ raise ValueError ("input must be pairs (sign, element)" )
1391
+ if k [0 ] != 1 and k [0 ] != - 1 :
1392
+ raise ValueError ("the sign must be +1 or -1" )
1393
+ c .append (ZZ (k [0 ]))
1394
+ p .append (k [1 ])
1395
+ return self .element_class (self , c , self ._P (p ))
1396
+
1397
+ if len (x ) == self ._n :
1398
+ c = []
1399
+ p = []
1400
+ one = ZZ .one ()
1401
+ for v in x :
1402
+ if v > 0 :
1403
+ c .append (one )
1404
+ p .append (v )
1405
+ else :
1406
+ c .append (- one )
1407
+ p .append (- v )
1408
+ return self .element_class (self , c , self ._P (p ))
1409
+
1410
+ if len (x ) != 2 :
1411
+ raise ValueError ("input must be a pair of a list of signs and a permutation" )
1412
+ if any (s != 1 and s != - 1 for s in x [0 ]):
1413
+ raise ValueError ("the sign must be +1 or -1" )
1414
+ return self .element_class (self , [ZZ (v ) for v in x [0 ]], self ._P (x [1 ]))
1395
1415
1396
1416
def __iter__ (self ):
1397
1417
"""
0 commit comments