Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit eb9bae5

Browse files
author
Release Manager
committed
Trac #31143: shorten range(0, *) in combinat folder
URL: https://trac.sagemath.org/31143 Reported by: chapoton Ticket author(s): Frédéric Chapoton Reviewer(s): David Coudert
2 parents 9d4f2d1 + 46ed87b commit eb9bae5

File tree

12 files changed

+55
-62
lines changed

12 files changed

+55
-62
lines changed

src/sage/combinat/cartesian_product.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def __init__(self, *iters):
9898
category = EnumeratedSets()
9999
try:
100100
category = category.Finite() if self.is_finite() else category.Infinite()
101-
except ValueError: # Unable to determine if it is finite or not
101+
except ValueError: # Unable to determine if it is finite or not
102102
pass
103103

104104
def iterfunc():
@@ -141,7 +141,7 @@ def __reduce__(self):
141141
142142
TESTS::
143143
144-
sage: cp = cartesian_product([[1,2],range(0,9)])
144+
sage: cp = cartesian_product([[1,2],range(9)])
145145
sage: loads(dumps(cp)) == cp
146146
True
147147
"""

src/sage/combinat/finite_state_machine_generators.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ def AnyLetter(self, input_alphabet):
149149
initial_states=[z],
150150
final_states=[o])
151151

152-
153152
def AnyWord(self, input_alphabet):
154153
r"""
155154
Return an automaton recognizing any word of the given
@@ -1026,7 +1025,7 @@ def GrayCode(self):
10261025
sage: G = transducers.GrayCode()
10271026
sage: G
10281027
Transducer with 3 states
1029-
sage: for v in srange(0, 10):
1028+
sage: for v in srange(10):
10301029
....: print("{} {}".format(v, G(v.digits(base=2))))
10311030
0 []
10321031
1 [1]

src/sage/combinat/fully_packed_loop.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ class FullyPackedLoop(Element, metaclass=InheritComparisonClasscallMetaclass):
301301
sage: ncp = FullyPackedLoop(ASMs[1]).link_pattern() # fpl's gyration orbit size is 2
302302
sage: rotated_ncp=[]
303303
sage: for (a,b) in ncp:
304-
....: for i in range(0,5):
304+
....: for i in range(5):
305305
....: a,b=a%6+1,b%6+1;
306306
....: rotated_ncp.append((a,b))
307307
sage: PerfectMatching(ASMs[1].gyration().to_fully_packed_loop().link_pattern()) ==\
@@ -312,7 +312,7 @@ class FullyPackedLoop(Element, metaclass=InheritComparisonClasscallMetaclass):
312312
sage: ncp = fpl.link_pattern() # fpl's gyration size is 3
313313
sage: rotated_ncp=[]
314314
sage: for (a,b) in ncp:
315-
....: for i in range(0,5):
315+
....: for i in range(5):
316316
....: a,b=a%6+1,b%6+1;
317317
....: rotated_ncp.append((a,b))
318318
sage: PerfectMatching(ASMs[0].gyration().to_fully_packed_loop().link_pattern()) ==\
@@ -325,7 +325,7 @@ class FullyPackedLoop(Element, metaclass=InheritComparisonClasscallMetaclass):
325325
sage: ncp = fpl.link_pattern()
326326
sage: rotated_ncp=[]
327327
sage: for (a,b) in ncp:
328-
....: for i in range(0,13):
328+
....: for i in range(13):
329329
....: a,b=a%14+1,b%14+1;
330330
....: rotated_ncp.append((a,b))
331331
sage: PerfectMatching(mat.gyration().to_fully_packed_loop().link_pattern()) ==\
@@ -338,7 +338,7 @@ class FullyPackedLoop(Element, metaclass=InheritComparisonClasscallMetaclass):
338338
sage: ncp = fpl.link_pattern()
339339
sage: rotated_ncp=[]
340340
sage: for (a,b) in ncp:
341-
....: for i in range(0,11):
341+
....: for i in range(11):
342342
....: a,b=a%12+1,b%12+1;
343343
....: rotated_ncp.append((a,b))
344344
sage: PerfectMatching(mat.gyration().to_fully_packed_loop().link_pattern()) ==\
@@ -1086,7 +1086,7 @@ def link_pattern(self):
10861086
sage: ncp = FullyPackedLoop(ASMs[1]).link_pattern()
10871087
sage: rotated_ncp=[]
10881088
sage: for (a,b) in ncp:
1089-
....: for i in range(0,5):
1089+
....: for i in range(5):
10901090
....: a,b=a%6+1,b%6+1;
10911091
....: rotated_ncp.append((a,b))
10921092
sage: PerfectMatching(ASMs[1].gyration().to_fully_packed_loop().link_pattern()) ==\
@@ -1097,7 +1097,7 @@ def link_pattern(self):
10971097
sage: ncp = fpl.link_pattern()
10981098
sage: rotated_ncp=[]
10991099
sage: for (a,b) in ncp:
1100-
....: for i in range(0,5):
1100+
....: for i in range(5):
11011101
....: a,b=a%6+1,b%6+1;
11021102
....: rotated_ncp.append((a,b))
11031103
sage: PerfectMatching(ASMs[0].gyration().to_fully_packed_loop().link_pattern()) ==\
@@ -1110,7 +1110,7 @@ def link_pattern(self):
11101110
sage: ncp = fpl.link_pattern()
11111111
sage: rotated_ncp=[]
11121112
sage: for (a,b) in ncp:
1113-
....: for i in range(0,13):
1113+
....: for i in range(13):
11141114
....: a,b=a%14+1,b%14+1;
11151115
....: rotated_ncp.append((a,b))
11161116
sage: PerfectMatching(mat.gyration().to_fully_packed_loop().link_pattern()) ==\
@@ -1123,7 +1123,7 @@ def link_pattern(self):
11231123
sage: ncp = fpl.link_pattern()
11241124
sage: rotated_ncp=[]
11251125
sage: for (a,b) in ncp:
1126-
....: for i in range(0,11):
1126+
....: for i in range(11):
11271127
....: a,b=a%12+1,b%12+1;
11281128
....: rotated_ncp.append((a,b))
11291129
sage: PerfectMatching(mat.gyration().to_fully_packed_loop().link_pattern()) ==\
@@ -1367,7 +1367,7 @@ def _element_constructor_(self, generator):
13671367
elif isinstance(generator, SquareIceModel.Element) or \
13681368
isinstance(generator, SixVertexConfiguration):
13691369
SVM = generator
1370-
else: # Not ASM nor SVM
1370+
else: # Not ASM nor SVM
13711371
try:
13721372
SVM = AlternatingSignMatrix(generator).to_six_vertex_model()
13731373
except (TypeError, ValueError):
@@ -1404,7 +1404,7 @@ def cardinality(self):
14041404
14051405
EXAMPLES::
14061406
1407-
sage: [AlternatingSignMatrices(n).cardinality() for n in range(0, 11)]
1407+
sage: [AlternatingSignMatrices(n).cardinality() for n in range(11)]
14081408
[1, 1, 2, 7, 42, 429, 7436, 218348, 10850216, 911835460, 129534272700]
14091409
"""
14101410
return Integer(prod( [ factorial(3*k+1)/factorial(self._n+k)

src/sage/combinat/gelfand_tsetlin_patterns.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ def random_element(self):
11701170
True
11711171
sage: len(x)
11721172
4
1173-
sage: all(y in range(0, 5+1) for z in x for y in z)
1173+
sage: all(y in range(5+1) for z in x for y in z)
11741174
True
11751175
sage: x.check()
11761176
@@ -1182,7 +1182,7 @@ def random_element(self):
11821182
True
11831183
sage: len(x)
11841184
4
1185-
sage: all(y in range(0, 5+1) for z in x for y in z)
1185+
sage: all(y in range(5+1) for z in x for y in z)
11861186
True
11871187
sage: x.check()
11881188
sage: x.is_strict()

src/sage/combinat/partition.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5054,7 +5054,7 @@ def dimension(self, smaller = [], k = 1):
50545054
Checks that the dimension satisfies the obvious recursion relation::
50555055
50565056
sage: test = lambda larger, smaller: larger.dimension(smaller) == sum(mu.dimension(smaller) for mu in larger.down())
5057-
sage: all(test(larger,smaller) for l in range(1,10) for s in range(0,10)
5057+
sage: all(test(larger,smaller) for l in range(1,10) for s in range(10)
50585058
....: for larger in Partitions(l) for smaller in Partitions(s) if smaller != larger)
50595059
True
50605060
@@ -7434,8 +7434,8 @@ def list(self):
74347434
if h == 0:
74357435
return [self.element_class(self, [])]
74367436
else:
7437-
l = [[i] for i in range(0, w+1)]
7438-
add = lambda x: [ x+[i] for i in range(0, x[-1]+1)]
7437+
l = [[i] for i in range(w + 1)]
7438+
add = lambda x: [x + [i] for i in range(x[-1] + 1)]
74397439
for i in range(h-1):
74407440
new_list = []
74417441
for element in l:

src/sage/combinat/permutation.py

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,15 @@
223223
===================
224224
"""
225225

226-
#*****************************************************************************
226+
# ****************************************************************************
227227
# Copyright (C) 2007 Mike Hansen <[email protected]>
228228
#
229229
# This program is free software: you can redistribute it and/or modify
230230
# it under the terms of the GNU General Public License as published by
231231
# the Free Software Foundation, either version 2 of the License, or
232232
# (at your option) any later version.
233233
# https://www.gnu.org/licenses/
234-
#*****************************************************************************
234+
# ****************************************************************************
235235

236236
from sage.structure.parent import Parent
237237
from sage.structure.unique_representation import UniqueRepresentation
@@ -701,7 +701,7 @@ def size(self):
701701

702702
def cycle_string(self, singletons=False):
703703
"""
704-
Returns a string of the permutation in cycle notation.
704+
Return a string of the permutation in cycle notation.
705705
706706
If ``singletons=True``, it includes 1-cycles in the string.
707707
@@ -749,8 +749,8 @@ def __next__(self):
749749

750750
#Starting from the end, find the first o such that
751751
#p[o] < p[o+1]
752-
for i in reversed(range(0,n-1)):
753-
if p[i] < p[i+1]:
752+
for i in reversed(range(n - 1)):
753+
if p[i] < p[i + 1]:
754754
first = i
755755
break
756756

@@ -809,8 +809,8 @@ def prev(self):
809809

810810
#Starting from the end, find the first o such that
811811
#p[o] > p[o+1]
812-
for i in reversed(range(0, n-1)):
813-
if p[i] > p[i+1]:
812+
for i in reversed(range(n - 1)):
813+
if p[i] > p[i + 1]:
814814
first = i
815815
break
816816

@@ -968,7 +968,7 @@ def to_cycles(self, singletons=True, use_min=True):
968968

969969
def _to_cycles_orig(self, singletons=True):
970970
r"""
971-
Returns the permutation ``self`` as a list of disjoint cycles.
971+
Return the permutation ``self`` as a list of disjoint cycles.
972972
973973
EXAMPLES::
974974
@@ -1115,7 +1115,7 @@ def _to_cycles_list(self, singletons=True):
11151115

11161116
def to_permutation_group_element(self):
11171117
"""
1118-
Returns a PermutationGroupElement equal to self.
1118+
Return a PermutationGroupElement equal to self.
11191119
11201120
EXAMPLES::
11211121
@@ -1389,15 +1389,9 @@ def rank(self):
13891389
True
13901390
"""
13911391
n = len(self)
1392-
13931392
factoradic = self.to_lehmer_code()
1394-
1395-
#Compute the index
1396-
rank = 0
1397-
for i in reversed(range(0, n)):
1398-
rank += factoradic[n-1-i]*factorial(i)
1399-
1400-
return rank
1393+
return sum(factoradic[n - 1 - i] * factorial(i)
1394+
for i in reversed(range(n)))
14011395

14021396
##############
14031397
# Inversions #
@@ -1869,10 +1863,10 @@ def _icondition(self, i):
18691863
18701864
.. NOTE::
18711865
1872-
An imove (that is, an iswitch or an ishift) can only be applied
1873-
when the relative positions of `i-1,i,i+1` are one of '213',
1874-
'132', '231', or '312'. ``None`` is returned in the other cases
1875-
to signal that an imove cannot be applied.
1866+
An imove (that is, an iswitch or an ishift) can only be applied
1867+
when the relative positions of `i-1,i,i+1` are one of '213',
1868+
'132', '231', or '312'. ``None`` is returned in the other cases
1869+
to signal that an imove cannot be applied.
18761870
18771871
EXAMPLES::
18781872
@@ -2161,9 +2155,9 @@ def longest_increasing_subsequences(self):
21612155
r"""
21622156
Return the list of the longest increasing subsequences of ``self``.
21632157
2164-
.. note::
2158+
.. NOTE::
21652159
2166-
The algorithm is not optimal.
2160+
The algorithm is not optimal.
21672161
21682162
EXAMPLES::
21692163
@@ -2704,7 +2698,7 @@ def to_lehmer_cocode(self):
27042698
n = len(p)
27052699
cocode = [0] * n
27062700
for i in range(1, n):
2707-
for j in range(0, i):
2701+
for j in range(i):
27082702
if p[j] > p[i]:
27092703
cocode[i] += 1
27102704
return cocode
@@ -3652,7 +3646,7 @@ def bruhat_smaller(self):
36523646

36533647
def bruhat_greater(self):
36543648
r"""
3655-
Returns the combinatorial class of permutations greater than or
3649+
Return the combinatorial class of permutations greater than or
36563650
equal to ``self`` in the Bruhat order (on the symmetric group
36573651
containing ``self``).
36583652
@@ -3799,7 +3793,7 @@ def permutohedron_succ(self, side="right"):
37993793
P = Permutations()
38003794
succ = []
38013795
if side == "right":
3802-
rise = lambda perm: [i for i in range(0,n-1) if perm[i] < perm[i+1]]
3796+
rise = lambda perm: [i for i in range(n - 1) if perm[i] < perm[i+1]]
38033797
for i in rise(p):
38043798
pp = p[:]
38053799
pp[i] = p[i+1]
@@ -4313,7 +4307,7 @@ def simion_schmidt(self, avoid=[1,2,3]):
43134307
@combinatorial_map(order=2,name='reverse')
43144308
def reverse(self):
43154309
"""
4316-
Returns the permutation obtained by reversing the list.
4310+
Return the permutation obtained by reversing the list.
43174311
43184312
EXAMPLES::
43194313
@@ -4379,7 +4373,7 @@ def permutation_poset(self):
43794373

43804374
def dict(self):
43814375
"""
4382-
Returns a dictionary corresponding to the permutation.
4376+
Return a dictionary corresponding to the permutation.
43834377
43844378
EXAMPLES::
43854379

src/sage/combinat/plane_partition.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -583,12 +583,12 @@ def is_SPP(self):
583583
c1 = len(Z)
584584
c2 = len(Z[0])
585585
size = max(c1, c2)
586-
T = [[0 for i in range(0,size)] for j in range(0,size)]
587-
for i in range(0,c1):
588-
for j in range(0,c2):
589-
T[i][j]=Z[i][j]
586+
T = [[0 for i in range(size)] for j in range(size)]
587+
for i in range(c1):
588+
for j in range(c2):
589+
T[i][j] = Z[i][j]
590590
return all(T[r][c] == T[c][r]
591-
for r in range(0,size)
591+
for r in range(size)
592592
for c in range(r, size))
593593

594594
def is_CSPP(self):

src/sage/combinat/rigged_configurations/bij_type_B.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ def next_state(self, height):
817817
end = ell[a]
818818
if a < height:
819819
end = len(self.cur_partitions[a])
820-
for i in reversed(range(0, end)):
820+
for i in reversed(range(end)):
821821
if self.cur_partitions[a][i] >= last_size and \
822822
self.cur_partitions[a].vacancy_numbers[i] == self.cur_partitions[a].rigging[i]:
823823
ell[n + a] = i

src/sage/combinat/rigged_configurations/bij_type_D.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ def next_state(self, height):
616616
end = ell[a]
617617
if a < height:
618618
end = len(self.cur_partitions[a])
619-
for i in reversed(range(0, end)):
619+
for i in reversed(range(end)):
620620
if self.cur_partitions[a][i] >= last_size and \
621621
self.cur_partitions[a].vacancy_numbers[i] == self.cur_partitions[a].rigging[i]:
622622
ell[n + a] = i

src/sage/combinat/root_system/root_lattice_realization_algebras.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def isobaric_divided_difference_on_basis(self, weight, i):
202202
raise ValueError("the weight does not have an integral scalar product with the coroot")
203203
alphai = P.simple_root(i)
204204
if n >= 0:
205-
return self.sum_of_monomials(weight-j*alphai for j in range(0,n+1))
205+
return self.sum_of_monomials(weight-j*alphai for j in range(n + 1))
206206
else:
207207
return -self.sum_of_monomials(weight-j*alphai for j in range(n+1,0))
208208

0 commit comments

Comments
 (0)