Skip to content

Commit 882116c

Browse files
author
Release Manager
committed
gh-39441: some details in KR crystals in particular using `next` where possible and avoiding `list(range(...))` ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #39441 Reported by: Frédéric Chapoton Reviewer(s): David Coudert
2 parents 021ad3e + a9027a4 commit 882116c

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

src/sage/combinat/crystals/kirillov_reshetikhin.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ def module_generator(self):
519519
r = self.r()
520520
s = self.s()
521521
weight = s*Lambda[r] - s*Lambda[0] * Lambda[r].level() / Lambda[0].level()
522-
return [b for b in self.module_generators if b.weight() == weight][0]
522+
return next(b for b in self.module_generators if b.weight() == weight)
523523

524524
def r(self):
525525
"""
@@ -993,8 +993,8 @@ def from_pm_diagram_to_highest_weight_vector(self, pm):
993993
sage: K.from_pm_diagram_to_highest_weight_vector(pm)
994994
[[2], [-2]]
995995
"""
996-
u = [b for b in self.classical_decomposition().module_generators
997-
if b.to_tableau().shape() == pm.outer_shape()][0]
996+
u = next(b for b in self.classical_decomposition().module_generators
997+
if b.to_tableau().shape() == pm.outer_shape())
998998
ct = self.cartan_type()
999999
rank = ct.rank() - 1
10001000
ct_type = ct.classical().type()
@@ -1031,7 +1031,7 @@ class KR_type_E6(KirillovReshetikhinCrystalFromPromotion):
10311031
[(1,)]
10321032
sage: b.e(0)
10331033
[(-2, 1)]
1034-
sage: b = [t for t in K if t.epsilon(1) == 1 and t.phi(3) == 1 and t.phi(2) == 0 and t.epsilon(2) == 0][0]
1034+
sage: b = next(t for t in K if t.epsilon(1) == 1 and t.phi(3) == 1 and t.phi(2) == 0 and t.epsilon(2) == 0)
10351035
sage: b
10361036
[(-1, 3)]
10371037
sage: b.e(0)
@@ -1622,7 +1622,7 @@ def module_generator(self):
16221622
weight = s*Lambda[r] - s*Lambda[0]
16231623
if r == self.cartan_type().rank() - 1:
16241624
weight += s*Lambda[r] # Special case for r == n
1625-
return [b for b in self.module_generators if b.weight() == weight][0]
1625+
return next(b for b in self.module_generators if b.weight() == weight)
16261626

16271627
def classical_decomposition(self):
16281628
r"""
@@ -2489,7 +2489,8 @@ def from_pm_diagram_to_highest_weight_vector(self, pm):
24892489
sage: K.from_pm_diagram_to_highest_weight_vector(pm)
24902490
[[2, 2], [3, 3], [-3, -1]]
24912491
"""
2492-
u = [b for b in self.classical_decomposition().module_generators if b.to_tableau().shape() == pm.outer_shape()][0]
2492+
u = next(b for b in self.classical_decomposition().module_generators
2493+
if b.to_tableau().shape() == pm.outer_shape())
24932494
ct = self.cartan_type()
24942495
rank = ct.rank()-1
24952496
ct_type = ct.classical().type()
@@ -2537,7 +2538,7 @@ def e0(self):
25372538
[[3, -3], [-3, -2], [-1, -1]]
25382539
"""
25392540
n = self.parent().cartan_type().n
2540-
b, l = self.lift().to_highest_weight(index_set=list(range(2, n + 1)))
2541+
b, l = self.lift().to_highest_weight(index_set=range(2, n + 1))
25412542
pm = self.parent().from_highest_weight_vector_to_pm_diagram(b)
25422543
l1, l2 = pm.pm_diagram[n-1]
25432544
if l1 == 0:
@@ -2562,7 +2563,7 @@ def f0(self):
25622563
sage: b.f(0) # indirect doctest
25632564
"""
25642565
n = self.parent().cartan_type().n
2565-
b, l = self.lift().to_highest_weight(index_set=list(range(2, n + 1)))
2566+
b, l = self.lift().to_highest_weight(index_set=range(2, n + 1))
25662567
pm = self.parent().from_highest_weight_vector_to_pm_diagram(b)
25672568
l1, l2 = pm.pm_diagram[n-1]
25682569
if l2 == 0:
@@ -2585,7 +2586,7 @@ def epsilon0(self):
25852586
1
25862587
"""
25872588
n = self.parent().cartan_type().n
2588-
b = self.lift().to_highest_weight(index_set=list(range(2, n + 1)))[0]
2589+
b = self.lift().to_highest_weight(index_set=range(2, n + 1))[0]
25892590
pm = self.parent().from_highest_weight_vector_to_pm_diagram(b)
25902591
l1, l2 = pm.pm_diagram[n-1]
25912592
return l1
@@ -2602,7 +2603,7 @@ def phi0(self):
26022603
0
26032604
"""
26042605
n = self.parent().cartan_type().n
2605-
b = self.lift().to_highest_weight(index_set=list(range(2, n + 1)))[0]
2606+
b = self.lift().to_highest_weight(index_set=range(2, n + 1))[0]
26062607
pm = self.parent().from_highest_weight_vector_to_pm_diagram(b)
26072608
l1, l2 = pm.pm_diagram[n-1]
26082609
return l2
@@ -2825,7 +2826,7 @@ def e0(self):
28252826
"""
28262827
n = self.parent().cartan_type().rank()-1
28272828
s = self.parent().s()
2828-
b, l = self.lift().to_highest_weight(index_set=list(range(2, n + 1)))
2829+
b, l = self.lift().to_highest_weight(index_set=range(2, n + 1))
28292830
pm = self.parent().from_highest_weight_vector_to_pm_diagram(b)
28302831
l1, l2 = pm.pm_diagram[n-1]
28312832
l3 = pm.pm_diagram[n-2][0]
@@ -2860,7 +2861,7 @@ def f0(self):
28602861
"""
28612862
n = self.parent().cartan_type().rank()-1
28622863
s = self.parent().s()
2863-
b, l = self.lift().to_highest_weight(index_set=list(range(2, n + 1)))
2864+
b, l = self.lift().to_highest_weight(index_set=range(2, n + 1))
28642865
pm = self.parent().from_highest_weight_vector_to_pm_diagram(b)
28652866
l1, l2 = pm.pm_diagram[n-1]
28662867
l3 = pm.pm_diagram[n-2][0]
@@ -2907,7 +2908,7 @@ def epsilon0(self):
29072908
True
29082909
"""
29092910
n = self.parent().cartan_type().rank() - 1
2910-
b, l = self.lift().to_highest_weight(index_set=list(range(2, n + 1)))
2911+
b, l = self.lift().to_highest_weight(index_set=range(2, n + 1))
29112912
pm = self.parent().from_highest_weight_vector_to_pm_diagram(b)
29122913
l1 = pm.pm_diagram[n-1][0]
29132914
l4 = pm.pm_diagram[n][0]
@@ -2940,7 +2941,7 @@ def phi0(self):
29402941
True
29412942
"""
29422943
n = self.parent().cartan_type().rank() - 1
2943-
b, l = self.lift().to_highest_weight(index_set=list(range(2, n + 1)))
2944+
b, l = self.lift().to_highest_weight(index_set=range(2, n + 1))
29442945
pm = self.parent().from_highest_weight_vector_to_pm_diagram(b)
29452946
l2 = pm.pm_diagram[n-1][1]
29462947
l4 = pm.pm_diagram[n][0]
@@ -3075,9 +3076,9 @@ def classical_decomposition(self):
30753076
C = self.cartan_type().classical()
30763077
s = QQ(self.s())
30773078
if self.r() == C.n:
3078-
c = [s/QQ(2)]*C.n
3079+
c = [s / QQ(2)]*C.n
30793080
else:
3080-
c = [s/QQ(2)]*(C.n-1)+[-s/QQ(2)]
3081+
c = [s / QQ(2)]*(C.n-1) + [-s / QQ(2)]
30813082
return CrystalOfTableaux(C, shape=c)
30823083

30833084
def dynkin_diagram_automorphism(self, i):
@@ -3155,6 +3156,7 @@ def neg(x):
31553156
y = list(x) # map a (shallow) copy
31563157
y[0] = -y[0]
31573158
return tuple(y)
3159+
31583160
return {dic_weight[w]: dic_weight_dual[neg(w)] for w in dic_weight}
31593161

31603162
@cached_method
@@ -3779,7 +3781,7 @@ def __init__(self, pm_diagram, from_shapes=None):
37793781
self._list = [i for a in reversed(pm_diagram) for i in a]
37803782
self.width = sum(self._list)
37813783

3782-
def _repr_(self):
3784+
def _repr_(self) -> str:
37833785
r"""
37843786
Turning on pretty printing allows to display the `\pm` diagram as a
37853787
tableau with the `+` and `-` displayed.
@@ -3791,7 +3793,7 @@ def _repr_(self):
37913793
"""
37923794
return repr(self.pm_diagram)
37933795

3794-
def _repr_diagram(self):
3796+
def _repr_diagram(self) -> str:
37953797
"""
37963798
Return a string representation of ``self`` as a diagram.
37973799
@@ -3910,7 +3912,7 @@ def intermediate_shape(self):
39103912
p = [p[i] + ll[2*i+1] for i in range(self.n)]
39113913
return Partition(p)
39123914

3913-
def heights_of_minus(self):
3915+
def heights_of_minus(self) -> list:
39143916
r"""
39153917
Return a list with the heights of all minus in the `\pm` diagram.
39163918
@@ -3930,7 +3932,7 @@ def heights_of_minus(self):
39303932
heights += [n-2*i]*((self.outer_shape()+[0]*n)[n-2*i-1]-(self.intermediate_shape()+[0]*n)[n-2*i-1])
39313933
return heights
39323934

3933-
def heights_of_addable_plus(self):
3935+
def heights_of_addable_plus(self) -> list:
39343936
r"""
39353937
Return a list with the heights of all addable plus in the `\pm` diagram.
39363938
@@ -4176,7 +4178,7 @@ def _call_(self, x):
41764178
self._cache[x] = y
41774179
return y
41784180

4179-
def _repr_type(self):
4181+
def _repr_type(self) -> str:
41804182
"""
41814183
Return a string describing ``self``.
41824184
@@ -4188,7 +4190,7 @@ def _repr_type(self):
41884190
"""
41894191
return "Diagram automorphism"
41904192

4191-
def is_isomorphism(self):
4193+
def is_isomorphism(self) -> bool:
41924194
"""
41934195
Return ``True`` as ``self`` is a crystal isomorphism.
41944196

0 commit comments

Comments
 (0)