Skip to content

Commit

Permalink
sagemathgh-39333: some ruff suggestions in algebras/
Browse files Browse the repository at this point in the history
This is fixing ruff PLC warnings in the algebra folder.

### 📝 Checklist

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.

URL: sagemath#39333
Reported by: Frédéric Chapoton
Reviewer(s): David Coudert
  • Loading branch information
Release Manager committed Jan 17, 2025
2 parents 8468f45 + ee1385a commit 5eb3724
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 38 deletions.
4 changes: 2 additions & 2 deletions build/pkgs/configure/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
tarball=configure-VERSION.tar.gz
sha1=852d0d200a6a73aa5ddb9e00874cbe4a61c211e9
sha256=c4b089d90850dfdf15b905f66e4f6a0d961b96eb0663d8603beaff1a9efb2cbe
sha1=0c3839396c1925ed5f34ae2332f2af284d42bd4f
sha256=f15f6168285c6503516ab8787770f805324f8b3a74414cd4409ad382b9859328
2 changes: 1 addition & 1 deletion build/pkgs/configure/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a2ba1f943f88775218c385efe55509c4548d1b44
9b7fe9ce8099decea34168e2dc536ce64465ceda
8 changes: 4 additions & 4 deletions src/sage/algebras/cluster_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 3 additions & 4 deletions src/sage/algebras/fusion_rings/fusion_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
16 changes: 7 additions & 9 deletions src/sage/algebras/hecke_algebras/ariki_koike_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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"""
Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand Down
14 changes: 8 additions & 6 deletions src/sage/algebras/lie_algebras/verma_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
17 changes: 9 additions & 8 deletions src/sage/algebras/rational_cherednik_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions src/sage/algebras/steenrod/steenrod_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 5eb3724

Please sign in to comment.