From ee1385ac4da43e3ecce9fecf5f3f95f2870be304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Thu, 16 Jan 2025 14:39:29 +0100 Subject: [PATCH] some ruff suggestions in algebras/ --- src/sage/algebras/cluster_algebra.py | 8 ++++---- src/sage/algebras/fusion_rings/fusion_ring.py | 7 +++---- .../hecke_algebras/ariki_koike_algebra.py | 16 +++++++--------- src/sage/algebras/lie_algebras/verma_module.py | 14 ++++++++------ src/sage/algebras/rational_cherednik_algebra.py | 17 +++++++++-------- src/sage/algebras/steenrod/steenrod_algebra.py | 7 +++---- 6 files changed, 34 insertions(+), 35 deletions(-) diff --git a/src/sage/algebras/cluster_algebra.py b/src/sage/algebras/cluster_algebra.py index 6772673cbcb..ca34a34acfc 100644 --- a/src/sage/algebras/cluster_algebra.py +++ b/src/sage/algebras/cluster_algebra.py @@ -572,12 +572,12 @@ def homogeneous_components(self) -> dict: components[g_vect] += self.parent().retract(x.monomial_coefficient(m) * m) else: components[g_vect] = self.parent().retract(x.monomial_coefficient(m) * m) - for g_vect in components: - components[g_vect]._is_homogeneous = True - components[g_vect]._g_vector = g_vect + for g_vect, compo in components.items(): + compo._is_homogeneous = True + compo._g_vector = g_vect self._is_homogeneous = (len(components) == 1) if self._is_homogeneous: - self._g_vector = list(components.keys())[0] + self._g_vector = next(iter(components)) return components def theta_basis_decomposition(self): diff --git a/src/sage/algebras/fusion_rings/fusion_ring.py b/src/sage/algebras/fusion_rings/fusion_ring.py index 56045d2dce6..e454b07dfcb 100644 --- a/src/sage/algebras/fusion_rings/fusion_ring.py +++ b/src/sage/algebras/fusion_rings/fusion_ring.py @@ -1564,15 +1564,14 @@ def q_dimension(self, base_coercion=True): R = ZZ['q'] q = R.gen() expr = R.fraction_field().one() - for val in powers: - exp = powers[val] + for val, exp in powers.items(): if exp > 0: expr *= q_int(P._nf * val, q)**exp elif exp < 0: expr /= q_int(P._nf * val, q)**(-exp) expr = R(expr) - expr = expr.substitute(q=q**4) / (q**(2*expr.degree())) - zet = P.field().gen() ** (P._cyclotomic_order/P._l) + expr = expr.substitute(q=q**4) / (q**(2 * expr.degree())) + zet = P.field().gen() ** (P._cyclotomic_order / P._l) ret = expr.substitute(q=zet) if (not base_coercion) or (self.parent()._basecoer is None): diff --git a/src/sage/algebras/hecke_algebras/ariki_koike_algebra.py b/src/sage/algebras/hecke_algebras/ariki_koike_algebra.py index 8d674d0aaf1..e6368ea8389 100644 --- a/src/sage/algebras/hecke_algebras/ariki_koike_algebra.py +++ b/src/sage/algebras/hecke_algebras/ariki_koike_algebra.py @@ -954,9 +954,8 @@ def _product_LTwTv(self, L, w, v): ret = {v: self.base_ring().one()} qm1 = self._q - self.base_ring().one() for i in reversed(w.reduced_word()): - temp = {} # start from 0 - for p in ret: - c = ret[p] + temp = {} # start from 0 + for p, c in ret.items(): # We have to flip the side due to Sage's # convention for multiplying permutations pi = p.apply_simple_reflection(i, side='left') @@ -965,7 +964,7 @@ def _product_LTwTv(self, L, w, v): else: iaxpy(1, {pi: c}, temp) ret = temp - return {(L, p): ret[p] for p in ret} + return {(L, p): c for p, c in ret.items()} def _product_Tw_L(self, w, L): r""" @@ -1011,10 +1010,9 @@ def _product_Tw_L(self, w, L): q = self._q one = q.parent().one() for i in w.reduced_word()[::-1]: - iL = {} # this will become T_i * L, written in standard form - for lv in wL: - c = wL[lv] - L = list(lv[0]) # make a copy + iL = {} # this will become T_i * L, written in standard form + for lv, c in wL.items(): + L = list(lv[0]) # make a copy v = lv[1] a, b = L[i-1], L[i] 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): c *= (one - q) iaxpy(1, {(tuple(l), v): c for l in Ls}, iL) - wL = iL # replace wL with iL and repeat + wL = iL # replace wL with iL and repeat return self._from_dict(wL, remove_zeros=False, coerce=False) @cached_method diff --git a/src/sage/algebras/lie_algebras/verma_module.py b/src/sage/algebras/lie_algebras/verma_module.py index 01320616c5a..71ea8e68cb9 100644 --- a/src/sage/algebras/lie_algebras/verma_module.py +++ b/src/sage/algebras/lie_algebras/verma_module.py @@ -701,21 +701,23 @@ def _homogeneous_component_f(self, d): """ if not d: return frozenset([self.highest_weight_vector()]) - f = {i: self._pbw(g) for i,g in enumerate(self._g.f())} - basis = d.parent().basis() # Standard basis vectors + f = {i: self._pbw(g) for i, g in enumerate(self._g.f())} + basis = d.parent().basis() # Standard basis vectors ret = set() def degree(m): m = m.dict() if not m: return d.parent().zero() - return sum(e * self._g.degree_on_basis(k) for k,e in m.items()).to_vector() - for i in f: + return sum(e * self._g.degree_on_basis(k) + for k, e in m.items()).to_vector() + for i, fi in f.items(): if d[i] == 0: continue for b in self._homogeneous_component_f(d + basis[i]): - temp = f[i] * b - ret.update([self.monomial(m) for m in temp.support() if degree(m) == d]) + temp = fi * b + ret.update([self.monomial(m) for m in temp.support() + if degree(m) == d]) return frozenset(ret) def _Hom_(self, Y, category=None, **options): diff --git a/src/sage/algebras/rational_cherednik_algebra.py b/src/sage/algebras/rational_cherednik_algebra.py index 1ded26a1112..537f39e8f68 100644 --- a/src/sage/algebras/rational_cherednik_algebra.py +++ b/src/sage/algebras/rational_cherednik_algebra.py @@ -369,18 +369,19 @@ def commute_w_hd(w, al): # al is given as a dictionary # so we must commute Lac Rs = Rs Lac' # and obtain La (Ls Rs) (Lac' Rac) ret = P.one() - for k in dl: + r1_red = right[1].reduced_word() + for k, dlk in dl.items(): x = sum(c * gens_dict[i] - for i,c in alphacheck[k].weyl_action(right[1].reduced_word(), - inverse=True)) - ret *= x**dl[k] + for i, c in alphacheck[k].weyl_action(r1_red, + inverse=True)) + ret *= x**dlk ret = ret.monomial_coefficients() - w = left[1]*right[1] + w = left[1] * right[1] return self._from_dict({(left[0], w, - self._h({I[i]: e for i,e in enumerate(k) - if e != 0}) * right[2] + self._h({I[i]: e for i, e in enumerate(k) + if e != 0}) * right[2] ): ret[k] - for k in ret}) + for k in ret}) # Otherwise dr is non-trivial and we have La Ls Ra Rs Rac, # so we must commute Ls Ra = Ra' Ls diff --git a/src/sage/algebras/steenrod/steenrod_algebra.py b/src/sage/algebras/steenrod/steenrod_algebra.py index 540cb6ee92d..63b9ac3d9b4 100644 --- a/src/sage/algebras/steenrod/steenrod_algebra.py +++ b/src/sage/algebras/steenrod/steenrod_algebra.py @@ -1346,10 +1346,9 @@ def coprod_list(t): right_q = sorted(all_q - a) sign = Permutation(convert_perm(left_q + right_q)).signature() tens_q[(tuple(left_q), tuple(right_q))] = sign - tens = {} - for l, r in zip(left_p, right_p): - for q in tens_q: - tens[((q[0], l), (q[1], r))] = tens_q[q] + tens = {((q[0], l), (q[1], r)): tq + for l, r in zip(left_p, right_p) + for q, tq in tens_q.items()} return self.tensor_square()._from_dict(tens, coerce=True) elif basis == 'serre-cartan': result = self.tensor_square().one()