Skip to content

Commit 3142b99

Browse files
author
Release Manager
committed
gh-40817: some details about imports in combinat just a few minor suggestions by `ruff` in the combinat folder ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #40817 Reported by: Frédéric Chapoton Reviewer(s): Frédéric Chapoton, Martin Rubey
2 parents 4f4d6e7 + d32f8dd commit 3142b99

File tree

6 files changed

+49
-59
lines changed

6 files changed

+49
-59
lines changed

src/sage/combinat/colored_permutations.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from sage.combinat.permutation import Permutations
2323
from sage.combinat.free_module import CombinatorialFreeModule
2424
from sage.combinat.specht_module import SpechtModule as SymGroupSpechtModule
25-
from sage.combinat.partition_tuple import PartitionTuples, PartitionTuple
25+
from sage.combinat.partition_tuple import PartitionTuples
2626
from sage.groups.conjugacy_classes import ConjugacyClass
2727
from sage.modules.with_basis.subquotient import SubmoduleWithBasis, QuotientModuleWithBasis
2828
from sage.modules.with_basis.representation import Representation_abstract
@@ -280,7 +280,7 @@ def to_matrix(self):
280280
"""
281281
Cp = CyclotomicField(self.parent()._m)
282282
g = Cp.gen()
283-
D = diagonal_matrix(Cp, [g ** i for i in self._colors])
283+
D = diagonal_matrix(Cp, [g**i for i in self._colors])
284284
return self._perm.to_matrix() * D
285285

286286
def has_left_descent(self, i) -> bool:
@@ -478,7 +478,7 @@ def __classcall_private__(cls, m, p, n):
478478
return ColoredPermutations(m, n)
479479
return super().__classcall__(cls, m, p, n)
480480

481-
def __init__(self, m, p, n):
481+
def __init__(self, m, p, n) -> None:
482482
r"""
483483
Initialize ``self``.
484484
@@ -509,9 +509,7 @@ def __init__(self, m, p, n):
509509
self._C = IntegerModRing(self._m)
510510
self._P = Permutations(self._n)
511511

512-
if (self._p == 1 and (self._m == 1 or self._m == 2)
513-
or (self._p == 2 and self._m == 2)
514-
or (self._n == 2 and self._p == self._m)):
512+
if self._p <= self._m <= 2 or (self._n == 2 and self._p == self._m):
515513
from sage.categories.finite_coxeter_groups import FiniteCoxeterGroups
516514
category = FiniteCoxeterGroups()
517515
if not (self._n == self._m == self._p == 2): # special case of type D_2
@@ -523,7 +521,7 @@ def __init__(self, m, p, n):
523521
category = category.WellGenerated()
524522
Parent.__init__(self, category=category)
525523

526-
def _repr_(self):
524+
def _repr_(self) -> str:
527525
"""
528526
Return a string representation of ``self``.
529527
@@ -743,8 +741,8 @@ def simple_reflection(self, i):
743741
if i == self._n + 1 or self._n == 1:
744742
return sn ** self._p
745743

746-
snm = self.simple_reflection(self._n-1)
747-
return sn**(self._m-1) * snm * sn
744+
snm = self.simple_reflection(self._n - 1)
745+
return sn**(self._m - 1) * snm * sn
748746

749747
@cached_method
750748
def _inverse_simple_reflections(self):
@@ -2227,7 +2225,7 @@ def __init__(self, G, base_ring, diagram):
22272225
data = [cartesian_product([OrderedSetPartitions([val * x for x, val in zip(sorted(X), signs)], la),
22282226
OrderedSetPartitions(sorted(Y), mu)])
22292227
for (X, Y) in OrderedSetPartitions(G._n, [sum(la), sum(mu)])
2230-
for signs in product([1,-1], repeat=sum(la))]
2228+
for signs in product([1, -1], repeat=sum(la))]
22312229
tabloids = DisjointUnionEnumeratedSets(data)
22322230
tabloids.rename(f"Tabloids of shape {self._diagram}")
22332231

@@ -2527,8 +2525,8 @@ def group_elements(sigma):
25272525
n = T.size()
25282526
for sigma in T.column_stabilizer():
25292527
sigma = sigma.tuple()
2530-
for signs in product(*[[1,-1] if i not in mu_vals else [1]
2531-
for i in range(1,n+1)]):
2528+
for signs in product(*[[1, -1] if i not in mu_vals else [1]
2529+
for i in range(1, n+1)]):
25322530
yield self._semigroup([s * val for s, val in zip(signs, sigma)])
25332531

25342532
return ambient.sum_of_terms((ambient._semigroup_basis_action(elt, tab),
@@ -2922,7 +2920,7 @@ class SimpleModule(Representation_abstract, QuotientModuleWithBasis):
29222920
[0 0 0 0 0 0 1 0]
29232921
[0 0 0 0 0 0 0 1]
29242922
"""
2925-
def __init__(self, specht_module):
2923+
def __init__(self, specht_module) -> None:
29262924
r"""
29272925
Initialize ``self``.
29282926
@@ -2932,18 +2930,19 @@ def __init__(self, specht_module):
29322930
sage: D = B4.simple_module([[2,1], [1]], GF(3))
29332931
sage: TestSuite(D).run()
29342932
"""
2935-
self._diagram = specht_module._diagram
29362933
p = specht_module.base_ring().characteristic()
2937-
if (not all(la.is_regular(p) for la in specht_module._diagram)
2938-
or (p == 2 and specht_module._diagram[0])):
2934+
d = self._diagram = specht_module._diagram
2935+
if (p == 2 and d[0]) or not all(la.is_regular(p) for la in d):
29392936
raise ValueError(f"the partition must be {p}-regular")
2940-
Representation_abstract.__init__(self, specht_module._semigroup, specht_module._side,
2937+
Representation_abstract.__init__(self, specht_module._semigroup,
2938+
specht_module._side,
29412939
algebra=specht_module._semigroup_algebra)
29422940
cat = specht_module.category()
2943-
QuotientModuleWithBasis.__init__(self, specht_module.maximal_submodule(),
2941+
QuotientModuleWithBasis.__init__(self,
2942+
specht_module.maximal_submodule(),
29442943
cat, prefix='D', bracket='')
29452944

2946-
def _repr_(self):
2945+
def _repr_(self) -> str:
29472946
r"""
29482947
Return a string representation of ``self``.
29492948
@@ -2955,7 +2954,7 @@ def _repr_(self):
29552954
"""
29562955
return f"Simple module of {self._diagram} over {self.base_ring()}"
29572956

2958-
def _latex_(self):
2957+
def _latex_(self) -> str:
29592958
r"""
29602959
Return a latex representation of ``self``.
29612960

src/sage/combinat/crystals/infinity_crystals.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
- Travis Scrimshaw: initial version
1212
"""
1313

14-
#*****************************************************************************
14+
# ***************************************************************************
1515
# Copyright (C) 2013 Ben Salisbury <bsalisbury1 at gmail.com>
1616
# Travis Scrimshaw <tscrim at ucdavis.edu>
1717
#
@@ -24,13 +24,12 @@
2424
#
2525
# The full text of the GPL is available at:
2626
#
27-
# http://www.gnu.org/licenses/
28-
#****************************************************************************
27+
# https://www.gnu.org/licenses/
28+
# **************************************************************************
2929

3030
from sage.structure.parent import Parent
3131
from sage.categories.infinite_enumerated_sets import InfiniteEnumeratedSets
3232
from sage.categories.highest_weight_crystals import HighestWeightCrystals
33-
from sage.categories.crystals import Crystals
3433
from sage.categories.supercrystals import SuperCrystals
3534
from sage.categories.homset import Hom
3635
from sage.misc.cachefunc import cached_method
@@ -40,9 +39,10 @@
4039
from sage.combinat.root_system.cartan_type import CartanType
4140
from sage.combinat.crystals.letters import CrystalOfLetters
4241
from sage.combinat.crystals.tensor_product import CrystalOfWords
43-
from sage.combinat.crystals.tensor_product_element import (CrystalOfTableauxElement,
44-
InfinityCrystalOfTableauxElement, InfinityCrystalOfTableauxElementTypeD,
45-
InfinityQueerCrystalOfTableauxElement)
42+
from sage.combinat.crystals.tensor_product_element import (
43+
CrystalOfTableauxElement,
44+
InfinityCrystalOfTableauxElement, InfinityCrystalOfTableauxElementTypeD,
45+
InfinityQueerCrystalOfTableauxElement)
4646

4747

4848
class InfinityCrystalOfTableaux(CrystalOfWords):
@@ -502,28 +502,28 @@ def seg(self):
502502
for r in range(len(tab)):
503503
for c in range(len(tab[r])):
504504
if tab[r][c] != r+1:
505-
if [r,tab[r][c]] not in segments:
506-
segments.append([r,tab[r][c]])
505+
if [r, tab[r][c]] not in segments:
506+
segments.append([r, tab[r][c]])
507507
if self.parent().cartan_type().type() == 'B':
508508
for r in range(len(tab)):
509509
for c in range(len(tab[r])):
510510
if tab[r][c] == 0 and tab[r][-1] == -r-1:
511-
segments.remove([r,tab[r][c]])
511+
segments.remove([r, tab[r][c]])
512512
if self.parent().cartan_type().type() == 'D':
513513
n = self.parent().cartan_type().rank()
514514
add = []
515515
for r in range(len(tab)):
516516
if tab[r][-1] == -1*(r+1):
517517
for c in range(len(tab[r])):
518518
if tab[r][c] != n and tab[r][c] != -n:
519-
if [r,n] not in add:
520-
add.append([r,n])
519+
if [r, n] not in add:
520+
add.append([r, n])
521521
if len(add) > 0:
522-
segments.append([r,n])
522+
segments.append([r, n])
523523
if self.parent().cartan_type().type() == 'G':
524524
for c in range(len(tab[0])):
525525
if tab[0][c] == 0 and tab[0][-1] == -1:
526-
segments.remove([0,tab[0][c]])
526+
segments.remove([0, tab[0][c]])
527527
return len(segments)
528528

529529
def content(self):
@@ -556,11 +556,11 @@ def content(self):
556556
tab = self.to_tableau()
557557
count = 0
558558
ct = self.parent().cartan_type().type()
559-
for i,row in enumerate(tab):
559+
for i, row in enumerate(tab):
560560
for entry in row:
561-
if entry == -i-1 and ct in ('B', 'D', 'G'):
561+
if entry == -i - 1 and ct in ('B', 'D', 'G'):
562562
count += 2
563-
elif entry != i+1:
563+
elif entry != i + 1:
564564
count += 1
565565
return count
566566

@@ -636,7 +636,7 @@ class Element(InfinityCrystalOfTableauxElementTypeD, InfinityCrystalOfTableaux.E
636636

637637

638638
#########################################################
639-
## Queer superalgebra
639+
# Queer superalgebra
640640

641641
class DualInfinityQueerCrystalOfTableaux(CrystalOfWords):
642642
@staticmethod

src/sage/combinat/diagram_algebras.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4491,7 +4491,6 @@ def cellular_involution(self, x):
44914491
o o o o o o o o o o o o
44924492
"""
44934493
M = x.monomial_coefficients(copy=False)
4494-
I = self._indices
44954494
return self._from_dict({d.dual(): c for d, c in M.items()},
44964495
remove_zeros=False)
44974496

src/sage/combinat/fully_commutative_elements.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
# (at your option) any later version.
2929
# https://www.gnu.org/licenses/
3030
# ****************************************************************************
31-
from collections import deque
32-
3331
from sage.categories.coxeter_groups import CoxeterGroups
3432
from sage.categories.enumerated_sets import EnumeratedSets
3533
from sage.misc.lazy_import import lazy_import

src/sage/combinat/regular_sequence_bounded.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
- Gabriel Lipnik is supported by the
2727
Austrian Science Fund (FWF): P 24644-N26.
2828
"""
29-
#*****************************************************************************
29+
# ***************************************************************************
3030
# Copyright (C) 2017 Gabriel Lipnik <[email protected]>
3131
#
3232
# This program is free software: You can redistribute it and/or modify
3333
# it under the terms of the GNU General Public License as published by
3434
# the Free Software Foundation, either version 3 of the License, or
3535
# (at your option) any later version.
36-
# http://www.gnu.org/licenses/
37-
#*****************************************************************************
36+
# https://www.gnu.org/licenses/
37+
# ***************************************************************************
3838

3939

4040
def multiply_reduce(A, B):
@@ -75,7 +75,7 @@ def multiply_reduce(A, B):
7575
[ -8 -14 -20]
7676
[ 2 2 2]
7777
"""
78-
return (A*B).apply_map(lambda m: min(m, 2))
78+
return (A * B).apply_map(lambda m: min(m, 2))
7979

8080

8181
def construct_phi(matrices):
@@ -144,7 +144,6 @@ def construct_phi(matrices):
144144
[2 2 2], [0 2 0], [0 2 2], [1 1 2], [2 0 0], [2 2 2], [1 2 2]
145145
]
146146
"""
147-
from sage.arith.srange import srange
148147
length = len(matrices)
149148

150149
def get_immutable(M):
@@ -389,7 +388,6 @@ def make_positive(matrices) -> list:
389388
...
390389
ValueError: There is a matrix which is neither non-negative nor non-positive.
391390
"""
392-
from sage.arith.srange import srange
393391

394392
def do(mat):
395393
if is_non_negative(mat):
@@ -513,10 +511,7 @@ def regular_sequence_is_bounded(S):
513511
sage: regular_sequence_is_bounded(S)
514512
True
515513
"""
516-
from sage.arith.srange import srange
517-
518514
matrices = list(S.mu)
519-
length = len(matrices)
520515
try:
521516
return is_bounded_via_mandel_simon_algorithm(make_positive(matrices))
522517
except ValueError:
@@ -526,7 +521,7 @@ def regular_sequence_is_bounded(S):
526521
if not has_bounded_matrix_powers(matrices):
527522
return False
528523

529-
matricesProd = list(ell*em for ell in matrices for em in matrices
524+
matricesProd = list(ell * em for ell in matrices for em in matrices
530525
if ell != em)
531526
if not has_bounded_matrix_powers(matricesProd):
532527
return False

src/sage/combinat/symmetric_group_algebra.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,7 +2176,6 @@ def _dft_unitary(self):
21762176
...
21772177
NotImplementedError: not implemented when p|n!; dimension of invariant forms may be greater than one
21782178
"""
2179-
from sage.matrix.special import diagonal_matrix
21802179
F = self.base_ring()
21812180
G = self.group()
21822181

@@ -2209,9 +2208,9 @@ def conj_square_root(u):
22092208
return F.zero()
22102209
z = F.multiplicative_generator()
22112210
k = u.log(z)
2212-
if k % (q+1) != 0:
2211+
if k % (q + 1) != 0:
22132212
raise ValueError(f"unable to factor as {u} is not in base field GF({q})")
2214-
return z ** ((k//(q+1)) % (q-1))
2213+
return z ** ((k // (q + 1)) % (q - 1))
22152214

22162215
dft_matrix = self.dft()
22172216
n = dft_matrix.nrows()
@@ -2536,7 +2535,7 @@ def _column_antistabilizer(self, la):
25362535
T = []
25372536
total = 1 # make it 1-based
25382537
for r in la:
2539-
T.append(list(range(total, total+r)))
2538+
T.append(list(range(total, total + r)))
25402539
total += r
25412540
T = Tableau(T)
25422541
G = self.group()
@@ -2634,7 +2633,7 @@ def kazhdan_lusztig_basis_element(self, w):
26342633
self._cellular_KL = KazhdanLusztigPolynomial(self._KLG, q)
26352634
polyfunc = self._cellular_KL.P
26362635
else:
2637-
self._cellular_KL = Coxeter3Group(['A', self.n+1])
2636+
self._cellular_KL = Coxeter3Group(['A', self.n + 1])
26382637
self._KLG = self._cellular_KL
26392638
polyfunc = self._cellular_KL.kazhdan_lusztig_polynomial
26402639

@@ -3565,9 +3564,9 @@ def _element_constructor_(self, x):
35653564
if x in Permutations():
35663565
if len(x) < self.n:
35673566
return self.monomial(self._indices(
3568-
list(x) + list(range(len(x) + 1, self.n + 1))
3569-
))
3570-
if all(x[i] == i+1 for i in range(self.n, len(x))):
3567+
list(x) + list(range(len(x) + 1, self.n + 1))
3568+
))
3569+
if all(x[i] == i + 1 for i in range(self.n, len(x))):
35713570
return self.monomial(self._indices(x[:self.n]))
35723571

35733572
return self._indices(x)

0 commit comments

Comments
 (0)