Skip to content

Commit 0b08a8d

Browse files
author
Release Manager
committed
gh-40219: simplify the for loops in combinat (no parentheses) by just removing some parentheses where they are useless ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #40219 Reported by: Frédéric Chapoton Reviewer(s): Travis Scrimshaw
2 parents 720a7f6 + e1e520a commit 0b08a8d

37 files changed

+219
-219
lines changed

src/sage/combinat/alternating_sign_matrix.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,8 @@ def inversion_number(self):
321321
inversion_num = 0
322322
asm_matrix = self.to_matrix()
323323
nonzero_cells = asm_matrix.nonzero_positions()
324-
for (i, j) in nonzero_cells:
325-
for (k, l) in nonzero_cells:
324+
for i, j in nonzero_cells:
325+
for k, l in nonzero_cells:
326326
if i > k and j < l:
327327
inversion_num += asm_matrix[i][j] * asm_matrix[k][l]
328328
return inversion_num
@@ -926,7 +926,7 @@ def to_permutation(self):
926926
if not self.is_permutation():
927927
raise ValueError('not a permutation matrix')
928928
asm_matrix = self.to_matrix()
929-
return Permutation([j + 1 for (i, j) in asm_matrix.nonzero_positions()])
929+
return Permutation([j + 1 for _, j in asm_matrix.nonzero_positions()])
930930

931931
@combinatorial_map(name='to semistandard tableau')
932932
def to_semistandard_tableau(self):
@@ -1471,7 +1471,7 @@ def last(self):
14711471
m.set_immutable()
14721472
return self.element_class(self, m)
14731473

1474-
def _lattice_initializer(self):
1474+
def _lattice_initializer(self) -> tuple:
14751475
r"""
14761476
Return a 2-tuple to use in argument of ``LatticePoset``.
14771477
@@ -1492,7 +1492,7 @@ def _lattice_initializer(self):
14921492
"""
14931493
mts, rels = MonotoneTriangles(self._n)._lattice_initializer()
14941494
bij = {t: self.from_monotone_triangle(t) for t in mts}
1495-
return (bij.values(), [(bij[a], bij[b]) for (a, b) in rels])
1495+
return (bij.values(), [(bij[a], bij[b]) for a, b in rels])
14961496

14971497
def cover_relations(self):
14981498
r"""
@@ -1502,7 +1502,7 @@ def cover_relations(self):
15021502
EXAMPLES::
15031503
15041504
sage: A = AlternatingSignMatrices(3)
1505-
sage: for (a,b) in A.cover_relations():
1505+
sage: for a, b in A.cover_relations():
15061506
....: eval('a, b')
15071507
(
15081508
[1 0 0] [0 1 0]
@@ -1734,7 +1734,7 @@ def cover_relations(self):
17341734
EXAMPLES::
17351735
17361736
sage: M = MonotoneTriangles(3)
1737-
sage: for (a,b) in M.cover_relations():
1737+
sage: for a, b in M.cover_relations():
17381738
....: eval('a, b')
17391739
([[3, 2, 1], [2, 1], [1]], [[3, 2, 1], [2, 1], [2]])
17401740
([[3, 2, 1], [2, 1], [1]], [[3, 2, 1], [3, 1], [1]])
@@ -1779,7 +1779,7 @@ def _is_a_cover(mt0, mt1):
17791779
False
17801780
"""
17811781
diffs = 0
1782-
for (a, b) in zip(flatten(mt0), flatten(mt1)):
1782+
for a, b in zip(flatten(mt0), flatten(mt1)):
17831783
if a != b:
17841784
if a + 1 == b:
17851785
diffs += 1

src/sage/combinat/bijectionist.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
sage: def alpha1(p): return len(p.weak_excedences())
6060
sage: def alpha2(p): return len(p.fixed_points())
6161
sage: def beta1(p): return len(p.descents(final_descent=True)) if p else 0
62-
sage: def beta2(p): return len([e for (e, f) in zip(p, p[1:]+[0]) if e == f+1])
62+
sage: def beta2(p): return len([e for e, f in zip(p, p[1:]+[0]) if e == f+1])
6363
sage: tau = Permutation.longest_increasing_subsequence_length
6464
sage: def rotate_permutation(p):
6565
....: cycle = Permutation(tuple(range(1, len(p)+1)))
@@ -690,7 +690,7 @@ def set_statistics(self, *alpha_beta):
690690
sage: def wex(p): return len(p.weak_excedences())
691691
sage: def fix(p): return len(p.fixed_points())
692692
sage: def des(p): return len(p.descents(final_descent=True)) if p else 0
693-
sage: def adj(p): return len([e for (e, f) in zip(p, p[1:]+[0]) if e == f+1])
693+
sage: def adj(p): return len([e for e, f in zip(p, p[1:]+[0]) if e == f+1])
694694
sage: bij = Bijectionist(A, B, fix)
695695
sage: bij.set_statistics((wex, des), (len, len))
696696
sage: for solution in sorted(list(bij.solutions_iterator()), key=lambda d: tuple(sorted(d.items()))):
@@ -800,7 +800,7 @@ def statistics_fibers(self):
800800
sage: def wex(p): return len(p.weak_excedences())
801801
sage: def fix(p): return len(p.fixed_points())
802802
sage: def des(p): return len(p.descents(final_descent=True)) if p else 0
803-
sage: def adj(p): return len([e for (e, f) in zip(p, p[1:]+[0]) if e == f+1])
803+
sage: def adj(p): return len([e for e, f in zip(p, p[1:]+[0]) if e == f+1])
804804
sage: bij = Bijectionist(A, B, tau)
805805
sage: bij.set_statistics((len, len), (wex, des), (fix, adj))
806806
sage: table([[key, AB[0], AB[1]] for key, AB in bij.statistics_fibers().items()])
@@ -844,7 +844,7 @@ def statistics_table(self, header=True):
844844
sage: def wex(p): return len(p.weak_excedences())
845845
sage: def fix(p): return len(p.fixed_points())
846846
sage: def des(p): return len(p.descents(final_descent=True)) if p else 0
847-
sage: def adj(p): return len([e for (e, f) in zip(p, p[1:]+[0]) if e == f+1])
847+
sage: def adj(p): return len([e for e, f in zip(p, p[1:]+[0]) if e == f+1])
848848
sage: bij = Bijectionist(A, B, tau)
849849
sage: bij.set_statistics((wex, des), (fix, adj))
850850
sage: a, b = bij.statistics_table()
@@ -1553,7 +1553,7 @@ def _forced_constant_blocks(self):
15531553
sage: def alpha1(p): return len(p.weak_excedences())
15541554
sage: def alpha2(p): return len(p.fixed_points())
15551555
sage: def beta1(p): return len(p.descents(final_descent=True)) if p else 0
1556-
sage: def beta2(p): return len([e for (e, f) in zip(p, p[1:] + [0]) if e == f + 1])
1556+
sage: def beta2(p): return len([e for e, f in zip(p, p[1:] + [0]) if e == f + 1])
15571557
sage: tau = Permutation.longest_increasing_subsequence_length
15581558
sage: def rotate_permutation(p):
15591559
....: cycle = Permutation(tuple(range(1, len(p) + 1)))
@@ -3173,7 +3173,7 @@ def _non_copying_intersection(sets):
31733173
sage: def alpha1(p): return len(p.weak_excedences())
31743174
sage: def alpha2(p): return len(p.fixed_points())
31753175
sage: def beta1(p): return len(p.descents(final_descent=True)) if p else 0
3176-
sage: def beta2(p): return len([e for (e, f) in zip(p, p[1:]+[0]) if e == f+1])
3176+
sage: def beta2(p): return len([e for e, f in zip(p, p[1:]+[0]) if e == f+1])
31773177
sage: gamma = Permutation.longest_increasing_subsequence_length
31783178
sage: def rotate_permutation(p):
31793179
....: cycle = Permutation(tuple(range(1, len(p)+1)))

src/sage/combinat/chas/fsym.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def duality_pairing(self, x, y):
327327
328328
sage: z = G[[1,3,5],[2,4]]
329329
sage: all(F.duality_pairing(F[p1] * F[p2], z) == c
330-
....: for ((p1, p2), c) in z.coproduct())
330+
....: for (p1, p2), c in z.coproduct())
331331
True
332332
333333
TESTS:
@@ -341,7 +341,7 @@ def duality_pairing(self, x, y):
341341
Rational Field
342342
"""
343343
y = self.dual_basis()(y)
344-
return self.base_ring().sum(coeff * y[t] for (t, coeff) in x)
344+
return self.base_ring().sum(coeff * y[t] for t, coeff in x)
345345

346346
def duality_pairing_matrix(self, basis, degree):
347347
r"""
@@ -1113,7 +1113,7 @@ def ascent_set(t):
11131113
[2, 4, 5]
11141114
"""
11151115
row_locations = {}
1116-
for (i, row) in enumerate(t):
1116+
for i, row in enumerate(t):
11171117
for entry in row:
11181118
row_locations[entry] = i
11191119
n = len(row_locations)

src/sage/combinat/chas/wqsym.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ def algebraic_complement(self):
761761
# for the formula we're using here.
762762
Q = self.parent()
763763
OSPs = Q.basis().keys()
764-
return Q._from_dict({OSPs(A.reversed()): c for (A, c) in self},
764+
return Q._from_dict({OSPs(A.reversed()): c for A, c in self},
765765
remove_zeros=False)
766766

767767
def coalgebraic_complement(self):
@@ -798,7 +798,7 @@ def coalgebraic_complement(self):
798798
# for the formula we're using here.
799799
Q = self.parent()
800800
OSPs = Q.basis().keys()
801-
return Q._from_dict({OSPs(A.complement()): c for (A, c) in self},
801+
return Q._from_dict({OSPs(A.complement()): c for A, c in self},
802802
remove_zeros=False)
803803

804804
def star_involution(self):
@@ -834,7 +834,7 @@ def star_involution(self):
834834
# for the formula we're using here.
835835
Q = self.parent()
836836
OSPs = Q.basis().keys()
837-
return Q._from_dict({OSPs(A.complement().reversed()): c for (A, c) in self},
837+
return Q._from_dict({OSPs(A.complement().reversed()): c for A, c in self},
838838
remove_zeros=False)
839839

840840
X = Characteristic
@@ -1280,7 +1280,7 @@ def img(A):
12801280
return {OSPs(P): (one if (len(R) % 2 == len(P) % 2)
12811281
else mine)
12821282
for R in Rs for P in R.strongly_fatter()}
1283-
return Q._from_dict(linear_combination((img(A), c) for (A, c) in self))
1283+
return Q._from_dict(linear_combination((img(A), c) for A, c in self))
12841284

12851285
def coalgebraic_complement(self):
12861286
r"""
@@ -1328,7 +1328,7 @@ def img(A):
13281328
return {OSPs(P): (one if (len(R) % 2 == len(P) % 2)
13291329
else mine)
13301330
for R in Rs for P in R.strongly_fatter()}
1331-
return Q._from_dict(linear_combination((img(A), c) for (A, c) in self))
1331+
return Q._from_dict(linear_combination((img(A), c) for A, c in self))
13321332

13331333
def star_involution(self):
13341334
r"""
@@ -1363,7 +1363,7 @@ def star_involution(self):
13631363
# for the formula we're using here.
13641364
Q = self.parent()
13651365
OSPs = Q.basis().keys()
1366-
return Q._from_dict({OSPs(A.complement().reversed()): c for (A, c) in self},
1366+
return Q._from_dict({OSPs(A.complement().reversed()): c for A, c in self},
13671367
remove_zeros=False)
13681368

13691369
Q = StronglyCoarser
@@ -1633,7 +1633,7 @@ def product_on_basis(self, x, y):
16331633
return self.monomial(x)
16341634
xlist = [(j, (k == 0))
16351635
for part in x
1636-
for (k, j) in enumerate(sorted(part))]
1636+
for k, j in enumerate(sorted(part))]
16371637
# xlist is a list of the form
16381638
# [(e_1, s_1), (e_2, s_2), ..., (e_n, s_n)],
16391639
# where e_1, e_2, ..., e_n are the entries of the parts of
@@ -1643,7 +1643,7 @@ def product_on_basis(self, x, y):
16431643
m = max(max(part) for part in x) # The degree of x
16441644
ylist = [(m + j, (k == 0))
16451645
for part in y
1646-
for (k, j) in enumerate(sorted(part))]
1646+
for k, j in enumerate(sorted(part))]
16471647
# ylist is like xlist, but for y instead of x, and with
16481648
# a shift by m.
16491649

@@ -1748,7 +1748,7 @@ def standardize(P): # standardize an ordered set partition
17481748
deconcatenates.append((left, right))
17491749
T = self.tensor_square()
17501750
return T.sum_of_monomials((standardize(left), standardize(right))
1751-
for (left, right) in deconcatenates)
1751+
for left, right in deconcatenates)
17521752

17531753
class Element(WQSymBasis_abstract.Element):
17541754
def algebraic_complement(self):
@@ -1797,7 +1797,7 @@ def img(A):
17971797
return {OSPs(P): (one if (len(R) % 2 == len(P) % 2)
17981798
else mine)
17991799
for R in Rs for P in R.strongly_finer()}
1800-
return Phi._from_dict(linear_combination((img(A), c) for (A, c) in self))
1800+
return Phi._from_dict(linear_combination((img(A), c) for A, c in self))
18011801

18021802
def coalgebraic_complement(self):
18031803
r"""
@@ -1845,7 +1845,7 @@ def img(A):
18451845
return {OSPs(P): (one if (len(R) % 2 == len(P) % 2)
18461846
else mine)
18471847
for R in Rs for P in R.strongly_finer()}
1848-
return Phi._from_dict(linear_combination((img(A), c) for (A, c) in self))
1848+
return Phi._from_dict(linear_combination((img(A), c) for A, c in self))
18491849

18501850
def star_involution(self):
18511851
r"""
@@ -1880,7 +1880,7 @@ def star_involution(self):
18801880
# for the formula we're using here.
18811881
Phi = self.parent()
18821882
OSPs = Phi.basis().keys()
1883-
return Phi._from_dict({OSPs(A.complement().reversed()): c for (A, c) in self},
1883+
return Phi._from_dict({OSPs(A.complement().reversed()): c for A, c in self},
18841884
remove_zeros=False)
18851885

18861886
Phi = StronglyFiner
@@ -2262,7 +2262,7 @@ def algebraic_complement(self):
22622262
# complement componentwise, then convert back.
22632263
parent = self.parent()
22642264
M = parent.realization_of().M()
2265-
dct = {I.reversed(): coeff for (I, coeff) in M(self)}
2265+
dct = {I.reversed(): coeff for I, coeff in M(self)}
22662266
return parent(M._from_dict(dct, remove_zeros=False))
22672267

22682268
def coalgebraic_complement(self):
@@ -2427,7 +2427,7 @@ def coalgebraic_complement(self):
24272427
# complement componentwise, then convert back.
24282428
parent = self.parent()
24292429
M = parent.realization_of().M()
2430-
dct = {I.complement(): coeff for (I, coeff) in M(self)}
2430+
dct = {I.complement(): coeff for I, coeff in M(self)}
24312431
return parent(M._from_dict(dct, remove_zeros=False))
24322432

24332433
def star_involution(self):
@@ -2555,7 +2555,7 @@ def star_involution(self):
25552555
# complement componentwise, then convert back.
25562556
parent = self.parent()
25572557
M = parent.realization_of().M()
2558-
dct = {I.reversed().complement(): coeff for (I, coeff) in M(self)}
2558+
dct = {I.reversed().complement(): coeff for I, coeff in M(self)}
25592559
return parent(M._from_dict(dct, remove_zeros=False))
25602560

25612561
def to_quasisymmetric_function(self):
@@ -2597,4 +2597,4 @@ def to_quasisymmetric_function(self):
25972597
M = QuasiSymmetricFunctions(self.parent().base_ring()).Monomial()
25982598
MW = self.parent().realization_of().M()
25992599
return M.sum_of_terms((i.to_composition(), coeff)
2600-
for (i, coeff) in MW(self))
2600+
for i, coeff in MW(self))

0 commit comments

Comments
 (0)