Skip to content

Commit 384493c

Browse files
author
Release Manager
committed
gh-36392: a few details in combinat, as suggested by ruff this is fixing a few things in combinat, as suggested by the very fast linter `ruff` ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. URL: #36392 Reported by: Frédéric Chapoton Reviewer(s): David Coudert
2 parents d0073b2 + bdc43e7 commit 384493c

File tree

10 files changed

+32
-32
lines changed

10 files changed

+32
-32
lines changed

src/sage/combinat/bijectionist.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,7 @@ def different_values(p1, p2):
16721672
def merge_until_split():
16731673
for tZ in list(multiple_preimages):
16741674
tP = multiple_preimages[tZ]
1675-
for i2 in range(len(tP)-1, -1, -1):
1675+
for i2 in range(len(tP) - 1, -1, -1):
16761676
for i1 in range(i2):
16771677
try:
16781678
solution = different_values(tP[i1], tP[i2])
@@ -1767,17 +1767,16 @@ def possible_values(self, p=None, optimal=False):
17671767
{'a': {0, 1}, 'b': {0, 1}}
17681768
sage: bij.possible_values(p="a", optimal=True)
17691769
{'a': set(), 'b': set()}
1770-
17711770
"""
17721771
# convert input to set of block representatives
17731772
blocks = set()
17741773
if p in self._A:
17751774
blocks.add(self._P.find(p))
1776-
elif type(p) is list: # TODO: this looks very brittle
1775+
elif isinstance(p, list): # TODO: this looks very brittle
17771776
for p1 in p:
17781777
if p1 in self._A:
17791778
blocks.add(self._P.find(p1))
1780-
elif type(p1) is list:
1779+
elif isinstance(p1, list):
17811780
for p2 in p1:
17821781
blocks.add(self._P.find(p2))
17831782

@@ -2084,7 +2083,7 @@ def minimal_subdistributions_blocks_iterator(self):
20842083
minimal_subdistribution.add_constraint(sum(D[p] for p in P) >= 1)
20852084
for p in P:
20862085
minimal_subdistribution.add_constraint(D[p] <= len(self._P.root_to_elements_dict()[p]))
2087-
minimal_subdistribution.add_constraint(X[p]*len(self._P.root_to_elements_dict()[p]) >= D[p] >= X[p])
2086+
minimal_subdistribution.add_constraint(X[p] * len(self._P.root_to_elements_dict()[p]) >= D[p] >= X[p])
20882087

20892088
def add_counter_example_constraint(s):
20902089
for v in self._Z:
@@ -2176,7 +2175,7 @@ def _preprocess_intertwining_relations(self):
21762175
P = self._P
21772176
images = defaultdict(set) # A^k -> A, a_1,...,a_k +-> {pi(a_1,...,a_k) for all pi}
21782177
for pi_rho in self._pi_rho:
2179-
for a_tuple in itertools.product(*([A]*pi_rho.numargs)):
2178+
for a_tuple in itertools.product(*([A] * pi_rho.numargs)):
21802179
if pi_rho.domain is not None and not pi_rho.domain(*a_tuple):
21812180
continue
21822181
a = pi_rho.pi(*a_tuple)
@@ -2566,9 +2565,9 @@ def show(self, variables=True):
25662565
varid_name[i] = default_name
25672566
for i, (lb, (indices, values), ub) in enumerate(self.milp.constraints()):
25682567
if b.row_name(i):
2569-
print(" "+b.row_name(i)+":", end=" ")
2568+
print(" " + b.row_name(i) + ":", end=" ")
25702569
if lb is not None:
2571-
print(str(ZZ(lb))+" <=", end=" ")
2570+
print(str(ZZ(lb)) + " <=", end=" ")
25722571
first = True
25732572
for j, c in sorted(zip(indices, values)):
25742573
c = ZZ(c)
@@ -2582,7 +2581,7 @@ def show(self, variables=True):
25822581
+ varid_name[j]), end=" ")
25832582
first = False
25842583
# Upper bound
2585-
print("<= "+str(ZZ(ub)) if ub is not None else "")
2584+
print("<= " + str(ZZ(ub)) if ub is not None else "")
25862585

25872586
if variables:
25882587
print("Variables are:")
@@ -2864,8 +2863,8 @@ def add_distribution_constraints(self):
28642863
Z_dict = {z: i for i, z in enumerate(Z)}
28652864
zero = self.milp.linear_functions_parent().zero()
28662865
for tA, tZ in self._bijectionist._elements_distributions:
2867-
tA_sum = [zero]*len(Z_dict)
2868-
tZ_sum = [zero]*len(Z_dict)
2866+
tA_sum = [zero] * len(Z_dict)
2867+
tZ_sum = [zero] * len(Z_dict)
28692868
for a in tA:
28702869
p = self._bijectionist._P.find(a)
28712870
for z in self._bijectionist._possible_block_values[p]:
@@ -3046,12 +3045,13 @@ def add_homomesic_constraints(self):
30463045
tZ = self._bijectionist._possible_block_values
30473046

30483047
def sum_q(q):
3049-
return sum(sum(z*self._x[P.find(a), z] for z in tZ[P.find(a)])
3048+
return sum(sum(z * self._x[P.find(a), z] for z in tZ[P.find(a)])
30503049
for a in q)
30513050
q0 = Q[0]
30523051
v0 = sum_q(q0)
30533052
for q in Q[1:]:
3054-
self.milp.add_constraint(len(q0)*sum_q(q) == len(q)*v0, name=f"h: ({q})~({q0})")
3053+
self.milp.add_constraint(len(q0) * sum_q(q) == len(q) * v0,
3054+
name=f"h: ({q})~({q0})")
30553055

30563056

30573057
def _invert_dict(d):

src/sage/combinat/binary_recurrence_sequences.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ def pthpowers(self, p, Bound):
693693
#gather congruence data for the sequence mod ell, which will be mod period(ell) = modu
694694
cong1, modu = _find_cong1(p, self, ell)
695695

696-
CongNew = [] #makes a new list from cong that is now mod M = lcm(M1, modu) instead of M1
696+
CongNew = [] # makes a new list from cong that is now mod M = lcm(M1, modu) instead of M1
697697
M = lcm(M1, modu)
698698
for k in range(M // M1):
699699
for i in cong:
@@ -702,18 +702,18 @@ def pthpowers(self, p, Bound):
702702

703703
M1 = M
704704

705-
killed_something = False #keeps track of when cong1 can rule out a congruence in cong
705+
killed_something = False # keeps track of when cong1 can rule out a congruence in cong
706706

707-
#CRT by hand to gain speed
707+
# CRT by hand to gain speed
708708
for i in list(cong):
709-
if i % modu not in cong1: #congruence in cong is inconsistent with any in cong1
710-
cong.remove(i) #remove that congruence
709+
if i % modu not in cong1: # congruence in cong is inconsistent with any in cong1
710+
cong.remove(i) # remove that congruence
711711
killed_something = True
712712

713713
if M1 == M2:
714714
if not killed_something:
715715
tries += 1
716-
if tries == 2: #try twice to rule out congruences
716+
if tries == 2: # try twice to rule out congruences
717717
cong = list(cong)
718718
qqold = qq
719719
qq = next_prime_power(qq)

src/sage/combinat/composition_tableau.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def __init__(self, parent, t):
9595
if not all(isinstance(row, list) for row in t):
9696
raise ValueError("a composition tableau must be a list of lists")
9797

98-
if not [len(r) for r in t] in Compositions():
98+
if any(not r for r in t):
9999
raise ValueError("a composition tableau must be a list of non-empty lists")
100100

101101
# Verify rows weakly decrease from left to right

src/sage/combinat/crystals/crystals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def _rec(self, x, state):
246246
for j in self._index_set:
247247
if j == i:
248248
break
249-
if not y.e(j) is None:
249+
if y.e(j) is not None:
250250
hasParent = True
251251
break
252252
if hasParent:

src/sage/combinat/designs/database.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2504,7 +2504,6 @@ def QDM_57_9_1_1_8():
25042504
(3 ,6 ) : ((0,1,3,7), _ref_Handbook),
25052505
(3 ,26) : ((0,1,3,8), _ref_Handbook),
25062506
(3 ,32) : ((0,1,3,9), _ref_Handbook),
2507-
(3 ,6 ) : ((0,1,3,7), _ref_Handbook),
25082507
(3 ,14) : ((0,1,4,13), _ref_Handbook),
25092508
(3 ,24) : ((0,1,3,15), _ref_Handbook),
25102509
(3 ,34) : ((0,1,3,7), _ref_Handbook),

src/sage/combinat/matrices/hadamard_matrix.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -994,12 +994,12 @@ def hadamard_matrix_from_sds(n, existence=False, check=True):
994994
sage: hadamard_matrix_from_sds(14)
995995
Traceback (most recent call last):
996996
...
997-
ValueError: n must be a positive multiple of four.
997+
ValueError: n must be a positive multiple of four
998998
"""
999999
from sage.combinat.designs.difference_family import supplementary_difference_set_hadamard
10001000

10011001
if n <= 0 or n % 4 != 0:
1002-
raise ValueError(f'n must be a positive multiple of four.')
1002+
raise ValueError('n must be a positive multiple of four')
10031003
t = n // 4
10041004

10051005
if existence:

src/sage/combinat/partition.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4201,8 +4201,9 @@ def zero_one_sequence(self):
42014201
sage: all(Partitions().from_zero_one(mu.zero_one_sequence()) == mu for n in range(10) for mu in Partitions(n))
42024202
True
42034203
"""
4204-
tmp = [self[i]-i for i in range(len(self))]
4205-
return ([Integer(not (i in tmp)) for i in range(-len(self)+1,self.get_part(0)+1)])
4204+
tmp = set(self[i] - i for i in range(len(self)))
4205+
return [Integer(i not in tmp)
4206+
for i in range(-len(self) + 1, self.get_part(0) + 1)]
42064207

42074208
def core(self, length):
42084209
r"""

src/sage/combinat/root_system/root_lattice_realization_algebras.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,14 @@ def _test_demazure_operators(self, **options):
313313
alphacheck = L.simple_coroots()
314314
s = L.simple_reflections()
315315
for i in self.cartan_type().index_set():
316-
emalphai = self.monomial(-alpha[i]) # X^{-\alpha_i}
316+
emalphai = self.monomial(-alpha[i]) # X^{-\alpha_i}
317317
for weight in L.some_elements():
318-
if not weight.scalar(alphacheck[i]) in ZZ:
318+
if weight.scalar(alphacheck[i]) not in ZZ:
319319
# Demazure operators are not defined in this case
320320
continue
321321
x = self.monomial(weight)
322322
result = pi[i](x)
323-
tester.assertEqual(result * (self.one()-emalphai),
323+
tester.assertEqual(result * (self.one() - emalphai),
324324
x - emalphai * x.map_support(s[i]))
325325
except ImportError:
326326
pass

src/sage/combinat/skew_partition.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,11 +1005,11 @@ def frobenius_rank(self):
10051005
True
10061006
"""
10071007
N = len(self[0])
1008-
mu_betas = [x - j for (j, x) in enumerate(self[1])]
1008+
mu_betas = [x - j for j, x in enumerate(self[1])]
10091009
mu_betas.extend([- j for j in range(len(self[1]), N)])
10101010
res = 0
10111011
for i, x in enumerate(self[0]):
1012-
if not x - i in mu_betas:
1012+
if (x - i) not in mu_betas:
10131013
res += 1
10141014
return res
10151015

src/sage/combinat/words/abstract_word.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ def _to_integer_iterator(self, use_parent_alphabet=False):
632632
"""
633633
from sage.combinat.words.words import FiniteWords, InfiniteWords
634634
if use_parent_alphabet and\
635-
isinstance(self.parent(), (FiniteWords, InfiniteWords)):
635+
isinstance(self.parent(), (FiniteWords, InfiniteWords)):
636636
A = self.parent().alphabet()
637637
for letter in self:
638638
yield A.rank(letter)

0 commit comments

Comments
 (0)