13
13
# ****************************************************************************
14
14
from itertools import repeat
15
15
16
- from sage .arith .misc import binomial
17
16
from sage .categories .affine_weyl_groups import AffineWeylGroups
18
17
from sage .combinat .composition import Composition
19
18
from sage .combinat .partition import Partition
23
22
from sage .misc .lazy_import import lazy_import
24
23
from sage .misc .misc_c import prod
25
24
from sage .misc .prandom import randint
26
- from sage .rings .integer_ring import ZZ
25
+ from sage .rings .integer import Integer
27
26
from sage .structure .list_clone import ClonableArray
28
27
from sage .structure .parent import Parent
29
28
from sage .structure .unique_representation import UniqueRepresentation
@@ -76,14 +75,14 @@ def __init__(self, parent, lst, check=True):
76
75
Type A affine permutation with window [1, 2, 3, 4]
77
76
"""
78
77
if check :
79
- lst = [ZZ (val ) for val in lst ]
78
+ lst = [Integer (val ) for val in lst ]
80
79
self .k = parent .k
81
80
self .n = self .k + 1
82
- #This N doesn't matter for type A, but comes up in all other types.
81
+ # This N doesn't matter for type A, but comes up in all other types.
83
82
if parent .cartan_type ()[0 ] == 'A' :
84
83
self .N = self .n
85
84
elif parent .cartan_type ()[0 ] in ['B' , 'C' , 'D' ]:
86
- self .N = 2 * self .k + 1
85
+ self .N = 2 * self .k + 1
87
86
elif parent .cartan_type ()[0 ] == 'G' :
88
87
self .N = 6
89
88
else :
@@ -245,7 +244,7 @@ def is_i_grassmannian(self, i=0, side='right') -> bool:
245
244
"""
246
245
return self == self .parent ().one () or self .descents (side ) == [i ]
247
246
248
- def index_set (self ):
247
+ def index_set (self ) -> tuple :
249
248
r"""
250
249
Index set of the affine permutation group.
251
250
@@ -255,7 +254,7 @@ def index_set(self):
255
254
sage: A.index_set()
256
255
(0, 1, 2, 3, 4, 5, 6, 7)
257
256
"""
258
- return tuple (range (self .k + 1 ))
257
+ return tuple (range (self .k + 1 ))
259
258
260
259
def lower_covers (self , side = 'right' ):
261
260
r"""
@@ -305,7 +304,7 @@ def reduced_word(self):
305
304
sage: p.reduced_word()
306
305
[0, 7, 4, 1, 0, 7, 5, 4, 2, 1]
307
306
"""
308
- #This is about 25% faster than the default algorithm.
307
+ # This is about 25% faster than the default algorithm.
309
308
x = self
310
309
i = 0
311
310
word = []
@@ -410,10 +409,10 @@ def grassmannian_quotient(self, i=0, side='right'):
410
409
411
410
412
411
class AffinePermutationTypeA (AffinePermutation ):
413
- #----------------------
414
- #Type-specific methods.
415
- #(Methods existing in all types, but with type-specific definition.)
416
- #----------------------
412
+ # ----------------------
413
+ # Type-specific methods.
414
+ # (Methods existing in all types, but with type-specific definition.)
415
+ # ----------------------
417
416
def check (self ):
418
417
r"""
419
418
Check that ``self`` is an affine permutation.
@@ -440,13 +439,14 @@ def check(self):
440
439
if not self :
441
440
return
442
441
k = self .parent ().k
443
- #Type A.
442
+ # Type A
444
443
if len (self ) != k + 1 :
445
- raise ValueError ("length of list must be k+1=" + str (k + 1 ))
446
- if binomial (k + 2 ,2 ) != sum (self ):
447
- raise ValueError ("window does not sum to " + str (binomial ((k + 2 ),2 )))
448
- l = sorted ([i % (k + 1 ) for i in self ])
449
- if l != list (range (k + 1 )):
444
+ raise ValueError (f"length of list must be k+1={ k + 1 } " )
445
+ sigma = (k + 2 ).binomial (2 )
446
+ if sigma != sum (self ):
447
+ raise ValueError (f"window does not sum to { sigma } " )
448
+ l = sorted (i % (k + 1 ) for i in self )
449
+ if any (i != j for i , j in enumerate (l )):
450
450
raise ValueError ("entries must have distinct residues" )
451
451
452
452
def value (self , i , base_window = False ):
@@ -510,11 +510,11 @@ def apply_simple_reflection_right(self, i):
510
510
Type A affine permutation with window [3, -1, 6, 0, 5, 4, 10, 9]
511
511
"""
512
512
j = i % (self .k + 1 )
513
- #Cloning is currently kinda broken, in that caches don't clear which
514
- #leads to strangeness with the cloned object.
515
- #The clone approach is quite a bit (2x) faster, though, so this should
516
- #switch once the caching situation is fixed.
517
- #with self.clone(check=False) as l:
513
+ # Cloning is currently kinda broken, in that caches don't clear which
514
+ # leads to strangeness with the cloned object.
515
+ # The clone approach is quite a bit (2x) faster, though, so this should
516
+ # switch once the caching situation is fixed.
517
+ # with self.clone(check=False) as l:
518
518
l = self [:]
519
519
if j == 0 :
520
520
a = l [0 ]
@@ -524,7 +524,6 @@ def apply_simple_reflection_right(self, i):
524
524
a = l [j - 1 ]
525
525
l [j - 1 ] = l [j ]
526
526
l [j ] = a
527
- #return l
528
527
return type (self )(self .parent (), l , check = False )
529
528
530
529
def apply_simple_reflection_left (self , i ):
@@ -539,18 +538,18 @@ def apply_simple_reflection_left(self, i):
539
538
sage: p.apply_simple_reflection_left(11)
540
539
Type A affine permutation with window [4, -1, 0, 6, 5, 3, 10, 9]
541
540
"""
542
- #Here are a couple other methods we tried out, but turned out
543
- #to be slower than the current implementation.
544
- #1) This one was very bad:
545
- # return self.inverse().apply_simple_reflection_right(i).inverse()
546
- #2) Also bad, though not quite so bad:
547
- # return (self.parent().simple_reflection(i))*self
548
- i = i % (self .k + 1 )
549
- #Cloning is currently kinda broken, in that caches don't clear which
550
- #leads to strangeness with the cloned object.
551
- #The clone approach is quite a bit faster, though, so this should switch
552
- #once the caching situation is fixed.
553
- #with self.clone(check=False) as l:
541
+ # Here are a couple other methods we tried out, but turned out
542
+ # to be slower than the current implementation.
543
+ # 1) This one was very bad:
544
+ # return self.inverse().apply_simple_reflection_right(i).inverse()
545
+ # 2) Also bad, though not quite so bad:
546
+ # return (self.parent().simple_reflection(i))*self
547
+ i = i % (self .k + 1 )
548
+ # Cloning is currently kinda broken, in that caches don't clear which
549
+ # leads to strangeness with the cloned object.
550
+ # The clone approach is quite a bit faster, though,
551
+ # so this should switch once the caching situation is fixed.
552
+ # with self.clone(check=False) as l:
554
553
l = []
555
554
if i != self .k :
556
555
for m in range (self .k + 1 ):
@@ -627,10 +626,10 @@ def to_type_a(self):
627
626
"""
628
627
return self
629
628
630
- #----------------------
631
- #Type-A-specific methods.
632
- #Only available in Type A.
633
- #----------------------
629
+ # ----------------------
630
+ # Type-A-specific methods.
631
+ # Only available in Type A.
632
+ # ----------------------
634
633
635
634
def flip_automorphism (self ):
636
635
r"""
@@ -699,7 +698,7 @@ def maximal_cyclic_factor(self, typ='decreasing', side='right', verbose=False):
699
698
else :
700
699
descents = self .descents (side = 'left' )
701
700
side = 'left'
702
- #for now, assume side is 'right')
701
+ # for now, assume side is 'right')
703
702
best_T = []
704
703
for i in descents :
705
704
y = self .clone ().apply_simple_reflection (i ,side )
@@ -834,18 +833,18 @@ def to_lehmer_code(self, typ='decreasing', side='right'):
834
833
"""
835
834
code = [0 for i in range (self .k + 1 )]
836
835
if typ [0 ] == 'i' and side [0 ] == 'r' :
837
- #Find number of positions to the right of position i with smaller
838
- #value than the number in position i.
836
+ # Find number of positions to the right of position i with smaller
837
+ # value than the number in position i.
839
838
for i in range (self .k + 1 ):
840
839
a = self (i )
841
840
for j in range (i + 1 , i + self .k + 1 ):
842
841
b = self (j )
843
842
if b < a :
844
843
code [i ] += (a - b ) // (self .k + 1 ) + 1
845
844
elif typ [0 ] == 'd' and side [0 ] == 'r' :
846
- #Find number of positions to the left of position i with larger
847
- #value than the number in position i. Then cyclically shift
848
- #the resulting vector.
845
+ # Find number of positions to the left of position i with larger
846
+ # value than the number in position i. Then cyclically shift
847
+ # the resulting vector.
849
848
for i in range (self .k + 1 ):
850
849
a = self (i )
851
850
for j in range (i - self .k , i ):
@@ -855,18 +854,18 @@ def to_lehmer_code(self, typ='decreasing', side='right'):
855
854
if a < b :
856
855
code [i - 1 ] += ((b - a )// (self .k + 1 )+ 1 )
857
856
elif typ [0 ] == 'i' and side [0 ] == 'l' :
858
- #Find number of positions to the right of i smaller than i, then
859
- #cyclically shift the resulting vector.
857
+ # Find number of positions to the right of i smaller than i, then
858
+ # cyclically shift the resulting vector.
860
859
for i in range (self .k + 1 ):
861
860
pos = self .position (i )
862
861
for j in range (pos + 1 , pos + self .k + 1 ):
863
862
b = self (j )
864
- #A small rotation is necessary for the reduced word from
865
- #the lehmer code to match the element.
863
+ # A small rotation is necessary for the reduced word from
864
+ # the lehmer code to match the element.
866
865
if b < i :
867
866
code [i - 1 ] += (i - b ) // (self .k + 1 ) + 1
868
867
elif typ [0 ] == 'd' and side [0 ] == 'l' :
869
- #Find number of positions to the left of i larger than i.
868
+ # Find number of positions to the left of i larger than i.
870
869
for i in range (self .k + 1 ):
871
870
pos = self .position (i )
872
871
for j in range (pos - self .k , pos ):
@@ -1103,7 +1102,7 @@ def value(self, i):
1103
1102
1104
1103
sage: C = AffinePermutationGroup(['C',4,1])
1105
1104
sage: x = C.one()
1106
- sage: [ x.value(i) for i in range(-10,10)] == list( range(-10,10))
1105
+ sage: all( x.value(i) == i for i in range(-10,10))
1107
1106
True
1108
1107
"""
1109
1108
N = 2 * self .k + 1
@@ -1124,7 +1123,7 @@ def position(self, i):
1124
1123
1125
1124
sage: C = AffinePermutationGroup(['C',4,1])
1126
1125
sage: x = C.one()
1127
- sage: [ x.position(i) for i in range(-10,10)] == list( range(-10,10))
1126
+ sage: all( x.position(i) == i for i in range(-10,10))
1128
1127
True
1129
1128
"""
1130
1129
N = 2 * self .k + 1
@@ -2001,9 +2000,9 @@ class AffinePermutationGroupGeneric(UniqueRepresentation, Parent):
2001
2000
methods for the specific affine permutation groups.
2002
2001
"""
2003
2002
2004
- #----------------------
2005
- #Type-free methods.
2006
- #----------------------
2003
+ # ----------------------
2004
+ # Type-free methods.
2005
+ # ----------------------
2007
2006
2008
2007
def __init__ (self , cartan_type ):
2009
2008
r"""
@@ -2014,13 +2013,13 @@ def __init__(self, cartan_type):
2014
2013
"""
2015
2014
Parent .__init__ (self , category = AffineWeylGroups ())
2016
2015
ct = CartanType (cartan_type )
2017
- self .k = ct .n
2016
+ self .k = Integer ( ct .n )
2018
2017
self .n = ct .rank ()
2019
- #This N doesn't matter for type A, but comes up in all other types.
2018
+ # This N doesn't matter for type A, but comes up in all other types.
2020
2019
if ct .letter == 'A' :
2021
2020
self .N = self .k + 1
2022
2021
elif ct .letter == 'B' or ct .letter == 'C' or ct .letter == 'D' :
2023
- self .N = 2 * self .k + 1
2022
+ self .N = 2 * self .k + 1
2024
2023
elif ct .letter == 'G' :
2025
2024
self .N = 6
2026
2025
self ._cartan_type = ct
@@ -2034,14 +2033,14 @@ def _element_constructor_(self, *args, **keywords):
2034
2033
"""
2035
2034
return self .element_class (self , * args , ** keywords )
2036
2035
2037
- def _repr_ (self ):
2036
+ def _repr_ (self ) -> str :
2038
2037
r"""
2039
2038
TESTS::
2040
2039
2041
2040
sage: AffinePermutationGroup(['A',7,1])
2042
2041
The group of affine permutations of type ['A', 7, 1]
2043
2042
"""
2044
- return "The group of affine permutations of type " + str (self .cartan_type ())
2043
+ return "The group of affine permutations of type " + str (self .cartan_type ())
2045
2044
2046
2045
def _test_enumeration (self , n = 4 , ** options ):
2047
2046
r"""
@@ -2242,12 +2241,12 @@ def one(self):
2242
2241
True
2243
2242
sage: TestSuite(A).run()
2244
2243
"""
2245
- return self (list ( range (1 , self .k + 2 ) ))
2244
+ return self (range (1 , self .k + 2 ))
2246
2245
2247
- #------------------------
2248
- #Type-unique methods.
2249
- #(Methods which do not exist in all types.)
2250
- #------------------------
2246
+ # ------------------------
2247
+ # Type-unique methods.
2248
+ # (Methods which do not exist in all types.)
2249
+ # ------------------------
2251
2250
def from_lehmer_code (self , C , typ = 'decreasing' , side = 'right' ):
2252
2251
r"""
2253
2252
Return the affine permutation with the supplied Lehmer code (a weak
@@ -2353,7 +2352,7 @@ def one(self):
2353
2352
True
2354
2353
sage: TestSuite(C).run()
2355
2354
"""
2356
- return self (list ( range (1 , self .k + 1 ) ))
2355
+ return self (range (1 , self .k + 1 ))
2357
2356
2358
2357
Element = AffinePermutationTypeC
2359
2358
0 commit comments