Skip to content

Commit 2c2c1e1

Browse files
committed
a few details in combinat, as suggested by ruff
1 parent 1cf0c13 commit 2c2c1e1

File tree

11 files changed

+34
-34
lines changed

11 files changed

+34
-34
lines changed

src/sage/combinat/bijectionist.py

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

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

20882087
def add_counter_example_constraint(s):
20892088
for v in self._Z:
@@ -2175,7 +2174,7 @@ def _preprocess_intertwining_relations(self):
21752174
P = self._P
21762175
images = defaultdict(set) # A^k -> A, a_1,...,a_k +-> {pi(a_1,...,a_k) for all pi}
21772176
for pi_rho in self._pi_rho:
2178-
for a_tuple in itertools.product(*([A]*pi_rho.numargs)):
2177+
for a_tuple in itertools.product(*([A] * pi_rho.numargs)):
21792178
if pi_rho.domain is not None and not pi_rho.domain(*a_tuple):
21802179
continue
21812180
a = pi_rho.pi(*a_tuple)
@@ -2565,9 +2564,9 @@ def show(self, variables=True):
25652564
varid_name[i] = default_name
25662565
for i, (lb, (indices, values), ub) in enumerate(self.milp.constraints()):
25672566
if b.row_name(i):
2568-
print(" "+b.row_name(i)+":", end=" ")
2567+
print(" " + b.row_name(i) + ":", end=" ")
25692568
if lb is not None:
2570-
print(str(ZZ(lb))+" <=", end=" ")
2569+
print(str(ZZ(lb)) + " <=", end=" ")
25712570
first = True
25722571
for j, c in sorted(zip(indices, values)):
25732572
c = ZZ(c)
@@ -2581,7 +2580,7 @@ def show(self, variables=True):
25812580
+ varid_name[j]), end=" ")
25822581
first = False
25832582
# Upper bound
2584-
print("<= "+str(ZZ(ub)) if ub is not None else "")
2583+
print("<= " + str(ZZ(ub)) if ub is not None else "")
25852584

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

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

30553055

30563056
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
@@ -692,7 +692,7 @@ def pthpowers(self, p, Bound):
692692
#gather congruence data for the sequence mod ell, which will be mod period(ell) = modu
693693
cong1, modu = _find_cong1(p, self, ell)
694694

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

702702
M1 = M
703703

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

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

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

src/sage/combinat/cluster_algebra_quiver/cluster_seed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4345,7 +4345,7 @@ def oriented_exchange_graph(self):
43454345
j = i.mutate(k, inplace=False)
43464346
Varj = tuple(sorted(j.cluster()))
43474347
covers.append((Vari, Varj))
4348-
if not(Varj in known_clusters):
4348+
if Varj not in known_clusters:
43494349
known_clusters += [Varj]
43504350
stack.append(j)
43514351

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
@@ -245,7 +245,7 @@ def _rec(self, x, state):
245245
for j in self._index_set:
246246
if j == i:
247247
break
248-
if not y.e(j) is None:
248+
if y.e(j) is not None:
249249
hasParent = True
250250
break
251251
if hasParent:

src/sage/combinat/e_one_star.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ def __init__(self, sigma, method='suffix'):
14181418
raise ValueError("the substitution (%s) must be unimodular" % sigma)
14191419

14201420
first_letter = sigma.codomain().alphabet()[0]
1421-
if not (first_letter in ZZ) or (first_letter < 1):
1421+
if first_letter not in ZZ or first_letter < 1:
14221422
raise ValueError("the substitution (%s) must be defined on positive integers" % sigma)
14231423

14241424
self._sigma = WordMorphism(sigma)

src/sage/combinat/matrices/hadamard_matrix.py

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

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

10041004
if existence:

src/sage/combinat/partition.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4201,8 +4201,8 @@ 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 = [self[i] - i for i in range(len(self))]
4205+
return [Integer(i not in tmp) for i in range(-len(self) + 1, self.get_part(0) + 1)]
42064206

42074207
def core(self, length):
42084208
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

0 commit comments

Comments
 (0)