Skip to content

Commit ee1385a

Browse files
committed
some ruff suggestions in algebras/
1 parent 1be0a58 commit ee1385a

File tree

6 files changed

+34
-35
lines changed

6 files changed

+34
-35
lines changed

src/sage/algebras/cluster_algebra.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,12 +572,12 @@ def homogeneous_components(self) -> dict:
572572
components[g_vect] += self.parent().retract(x.monomial_coefficient(m) * m)
573573
else:
574574
components[g_vect] = self.parent().retract(x.monomial_coefficient(m) * m)
575-
for g_vect in components:
576-
components[g_vect]._is_homogeneous = True
577-
components[g_vect]._g_vector = g_vect
575+
for g_vect, compo in components.items():
576+
compo._is_homogeneous = True
577+
compo._g_vector = g_vect
578578
self._is_homogeneous = (len(components) == 1)
579579
if self._is_homogeneous:
580-
self._g_vector = list(components.keys())[0]
580+
self._g_vector = next(iter(components))
581581
return components
582582

583583
def theta_basis_decomposition(self):

src/sage/algebras/fusion_rings/fusion_ring.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,15 +1564,14 @@ def q_dimension(self, base_coercion=True):
15641564
R = ZZ['q']
15651565
q = R.gen()
15661566
expr = R.fraction_field().one()
1567-
for val in powers:
1568-
exp = powers[val]
1567+
for val, exp in powers.items():
15691568
if exp > 0:
15701569
expr *= q_int(P._nf * val, q)**exp
15711570
elif exp < 0:
15721571
expr /= q_int(P._nf * val, q)**(-exp)
15731572
expr = R(expr)
1574-
expr = expr.substitute(q=q**4) / (q**(2*expr.degree()))
1575-
zet = P.field().gen() ** (P._cyclotomic_order/P._l)
1573+
expr = expr.substitute(q=q**4) / (q**(2 * expr.degree()))
1574+
zet = P.field().gen() ** (P._cyclotomic_order / P._l)
15761575
ret = expr.substitute(q=zet)
15771576

15781577
if (not base_coercion) or (self.parent()._basecoer is None):

src/sage/algebras/hecke_algebras/ariki_koike_algebra.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -954,9 +954,8 @@ def _product_LTwTv(self, L, w, v):
954954
ret = {v: self.base_ring().one()}
955955
qm1 = self._q - self.base_ring().one()
956956
for i in reversed(w.reduced_word()):
957-
temp = {} # start from 0
958-
for p in ret:
959-
c = ret[p]
957+
temp = {} # start from 0
958+
for p, c in ret.items():
960959
# We have to flip the side due to Sage's
961960
# convention for multiplying permutations
962961
pi = p.apply_simple_reflection(i, side='left')
@@ -965,7 +964,7 @@ def _product_LTwTv(self, L, w, v):
965964
else:
966965
iaxpy(1, {pi: c}, temp)
967966
ret = temp
968-
return {(L, p): ret[p] for p in ret}
967+
return {(L, p): c for p, c in ret.items()}
969968

970969
def _product_Tw_L(self, w, L):
971970
r"""
@@ -1011,10 +1010,9 @@ def _product_Tw_L(self, w, L):
10111010
q = self._q
10121011
one = q.parent().one()
10131012
for i in w.reduced_word()[::-1]:
1014-
iL = {} # this will become T_i * L, written in standard form
1015-
for lv in wL:
1016-
c = wL[lv]
1017-
L = list(lv[0]) # make a copy
1013+
iL = {} # this will become T_i * L, written in standard form
1014+
for lv, c in wL.items():
1015+
L = list(lv[0]) # make a copy
10181016
v = lv[1]
10191017
a, b = L[i-1], L[i]
10201018
L[i-1], L[i] = L[i], L[i-1] # swap L_i=L[i-1] and L_{i+1}=L[i]
@@ -1038,7 +1036,7 @@ def _product_Tw_L(self, w, L):
10381036
c *= (one - q)
10391037
iaxpy(1, {(tuple(l), v): c for l in Ls}, iL)
10401038

1041-
wL = iL # replace wL with iL and repeat
1039+
wL = iL # replace wL with iL and repeat
10421040
return self._from_dict(wL, remove_zeros=False, coerce=False)
10431041

10441042
@cached_method

src/sage/algebras/lie_algebras/verma_module.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -701,21 +701,23 @@ def _homogeneous_component_f(self, d):
701701
"""
702702
if not d:
703703
return frozenset([self.highest_weight_vector()])
704-
f = {i: self._pbw(g) for i,g in enumerate(self._g.f())}
705-
basis = d.parent().basis() # Standard basis vectors
704+
f = {i: self._pbw(g) for i, g in enumerate(self._g.f())}
705+
basis = d.parent().basis() # Standard basis vectors
706706
ret = set()
707707

708708
def degree(m):
709709
m = m.dict()
710710
if not m:
711711
return d.parent().zero()
712-
return sum(e * self._g.degree_on_basis(k) for k,e in m.items()).to_vector()
713-
for i in f:
712+
return sum(e * self._g.degree_on_basis(k)
713+
for k, e in m.items()).to_vector()
714+
for i, fi in f.items():
714715
if d[i] == 0:
715716
continue
716717
for b in self._homogeneous_component_f(d + basis[i]):
717-
temp = f[i] * b
718-
ret.update([self.monomial(m) for m in temp.support() if degree(m) == d])
718+
temp = fi * b
719+
ret.update([self.monomial(m) for m in temp.support()
720+
if degree(m) == d])
719721
return frozenset(ret)
720722

721723
def _Hom_(self, Y, category=None, **options):

src/sage/algebras/rational_cherednik_algebra.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -369,18 +369,19 @@ def commute_w_hd(w, al): # al is given as a dictionary
369369
# so we must commute Lac Rs = Rs Lac'
370370
# and obtain La (Ls Rs) (Lac' Rac)
371371
ret = P.one()
372-
for k in dl:
372+
r1_red = right[1].reduced_word()
373+
for k, dlk in dl.items():
373374
x = sum(c * gens_dict[i]
374-
for i,c in alphacheck[k].weyl_action(right[1].reduced_word(),
375-
inverse=True))
376-
ret *= x**dl[k]
375+
for i, c in alphacheck[k].weyl_action(r1_red,
376+
inverse=True))
377+
ret *= x**dlk
377378
ret = ret.monomial_coefficients()
378-
w = left[1]*right[1]
379+
w = left[1] * right[1]
379380
return self._from_dict({(left[0], w,
380-
self._h({I[i]: e for i,e in enumerate(k)
381-
if e != 0}) * right[2]
381+
self._h({I[i]: e for i, e in enumerate(k)
382+
if e != 0}) * right[2]
382383
): ret[k]
383-
for k in ret})
384+
for k in ret})
384385

385386
# Otherwise dr is non-trivial and we have La Ls Ra Rs Rac,
386387
# so we must commute Ls Ra = Ra' Ls

src/sage/algebras/steenrod/steenrod_algebra.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,10 +1346,9 @@ def coprod_list(t):
13461346
right_q = sorted(all_q - a)
13471347
sign = Permutation(convert_perm(left_q + right_q)).signature()
13481348
tens_q[(tuple(left_q), tuple(right_q))] = sign
1349-
tens = {}
1350-
for l, r in zip(left_p, right_p):
1351-
for q in tens_q:
1352-
tens[((q[0], l), (q[1], r))] = tens_q[q]
1349+
tens = {((q[0], l), (q[1], r)): tq
1350+
for l, r in zip(left_p, right_p)
1351+
for q, tq in tens_q.items()}
13531352
return self.tensor_square()._from_dict(tens, coerce=True)
13541353
elif basis == 'serre-cartan':
13551354
result = self.tensor_square().one()

0 commit comments

Comments
 (0)