Skip to content

Commit

Permalink
sagemathgh-38612: pep8 cleanup in algebras
Browse files Browse the repository at this point in the history
fixing a few pep8 suggestions in algebras/

partly done using autopep8, partly by hand

### 📝 Checklist

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.

URL: sagemath#38612
Reported by: Frédéric Chapoton
Reviewer(s): gmou3
  • Loading branch information
Release Manager committed Sep 5, 2024
2 parents 95fa3e3 + e712c07 commit 4d73a2c
Show file tree
Hide file tree
Showing 32 changed files with 134 additions and 131 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=0f6355fc136bb6619585863b9e4bc954cc6e0e3d
sha256=5b618581d51997afa78b5e6647584f7ef4e6d5844823dd44e607f2accd7abba5
sha1=33f3d273b4fa6ab23b4b1ca0ea7feab6a93e602e
sha256=16caf05e6afbc450cb0b10c05a82768d726c8afc0cc515ce728baf6bcc83d047
2 changes: 1 addition & 1 deletion build/pkgs/configure/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b9cb7bc2559cde857d84d77f0b37a3616ce1eb6c
ed3e8871a0c37bbbf3e9d65b3efbfa45f3b9c9cd
2 changes: 1 addition & 1 deletion src/sage/algebras/clifford_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -2914,7 +2914,7 @@ def __richcmp__(self, other, op):
return contained and contains
if op == op_NE:
return not (contained and contains)
# remaining case <
# remaining case <
return contained and not contains

def __mul__(self, other):
Expand Down
2 changes: 1 addition & 1 deletion src/sage/algebras/fusion_rings/fusion_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ def is_multiplicity_free(self):
return k <= 2

###################################
### Braid group representations ###
# Braid group representations #
###################################

def get_computational_basis(self, a, b, n_strands):
Expand Down
5 changes: 3 additions & 2 deletions src/sage/algebras/group_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,9 @@ def _coerce_map_from_(self, S):
hom_G = G.coerce_map_from(S_G)
if hom_K is not None and hom_G is not None:
return SetMorphism(S.Hom(self, category=self.category() | S.category()),
lambda x: self.sum_of_terms( (hom_G(g), hom_K(c)) for g,c in x ))
lambda x: self.sum_of_terms((hom_G(g), hom_K(c)) for g, c in x))


from sage.misc.persist import register_unpickle_override
register_unpickle_override('sage.algebras.group_algebras', 'GroupAlgebra', GroupAlgebra_class)
register_unpickle_override('sage.algebras.group_algebras', 'GroupAlgebra',
GroupAlgebra_class)
8 changes: 4 additions & 4 deletions src/sage/algebras/hall_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def coproduct_on_basis(self, la):
S = self.tensor_square()
if all(x == 1 for x in la):
n = len(la)
return S.sum_of_terms([( (Partition([1]*r), Partition([1]*(n-r))), self._q**(-r*(n-r)) )
return S.sum_of_terms([((Partition([1]*r), Partition([1]*(n-r))), self._q**(-r*(n-r)))
for r in range(n+1)], distinct=True)

I = HallAlgebraMonomials(self.base_ring(), self._q)
Expand Down Expand Up @@ -482,9 +482,9 @@ def scalar(self, y):
(4*q^2 + 9)/(q^2 - q)
"""
q = self.parent()._q
f = lambda la: ~( q**(sum(la) + 2*la.weighted_size())
f = lambda la: ~(q**(sum(la) + 2*la.weighted_size())
* prod(prod((1 - q**-i) for i in range(1,k+1))
for k in la.to_exp()) )
for k in la.to_exp()))
y = self.parent()(y)
ret = q.parent().zero()
for mx, cx in self:
Expand Down Expand Up @@ -687,7 +687,7 @@ def coproduct_on_basis(self, a):
+ (q^-1)*I[1, 1] # I[1] + I[2] # I[1] + I[2, 1] # I[]
"""
S = self.tensor_square()
return S.prod(S.sum_of_terms([( (Partition([r]), Partition([n-r]) ), self._q**(-r*(n-r)) )
return S.prod(S.sum_of_terms([((Partition([r]), Partition([n-r])), self._q**(-r*(n-r)))
for r in range(n+1)], distinct=True) for n in a)

def antipode_on_basis(self, a):
Expand Down
33 changes: 17 additions & 16 deletions src/sage/algebras/hecke_algebras/ariki_koike_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,10 +738,10 @@ def algebra_generators(self):
for i in range(self._n):
r = list(self._zero_tuple) # Make a copy
r[i] = 1
d['L%s' % (i+1)] = self.monomial( (tuple(r), self._one_perm) )
d['L%s' % (i+1)] = self.monomial((tuple(r), self._one_perm))
G = self._Pn.group_generators()
for i in range(1, self._n):
d['T%s' % i] = self.monomial( (self._zero_tuple, G[i]) )
d['T%s' % i] = self.monomial((self._zero_tuple, G[i]))
return Family(sorted(d), lambda i: d[i])

def T(self, i=None):
Expand Down Expand Up @@ -896,9 +896,9 @@ def product_on_basis(self, m1, m2):
# combination of standard basis elements using the method and then,
# recursively, multiply on the left and right by L1 and T2,
# respectively. In other words, we multiply as L1*(T1*L2)*T2.
return ( self.monomial((L1, self._one_perm))
return (self.monomial((L1, self._one_perm))
* self._product_Tw_L(T1, L2)
* self.monomial((self._zero_tuple, T2)) )
* self.monomial((self._zero_tuple, T2)))

def _product_LTwTv(self, L, w, v):
r"""
Expand Down Expand Up @@ -1023,15 +1023,15 @@ def _product_Tw_L(self, w, L):
iaxpy(c, self._product_LTwTv(tuple(L), self._Pn.simple_reflections()[i], v), iL) # need T_i*T_v

if a < b:
Ls = [ list(L) for k in range(b-a) ] # make copies of L
Ls = [list(L) for k in range(b-a)] # make copies of L
for k in range(b-a):
Ls[k][i-1] = a + k
Ls[k][i] = b - k
c *= (q - one)
iaxpy(1, {(tuple(l), v): c for l in Ls}, iL)

elif a > b:
Ls = [ list(L) for k in range(a-b) ] # make copies of L
Ls = [list(L) for k in range(a-b)] # make copies of L
for k in range(a-b):
Ls[k][i-1] = b + k
Ls[k][i] = a - k
Expand Down Expand Up @@ -1110,25 +1110,26 @@ def Ltuple(a, b):

# return "small" powers of the generators without change
if m < self._r:
return self.monomial( (Ltuple(0, m), self._one_perm) )
return self.monomial((Ltuple(0, m), self._one_perm))

if i > 1:
si = self._Pn.simple_reflections()[i-1]
qsum = self.base_ring().one() - self._q**-1
# by calling _Li_power we avoid infinite recursion here
return ( self.sum_of_terms( ((Ltuple(c, m-c), si), qsum) for c in range(1, m) )
+ self._q**-1 * self.T(i-1) * self._Li_power(i-1, m) * self.T(i-1) )
return (self.sum_of_terms(((Ltuple(c, m-c), si), qsum) for c in range(1, m))
+ self._q**-1 * self.T(i-1) * self._Li_power(i-1, m) * self.T(i-1))

# now left with the case i = 1 and m >= r
if m > self._r:
return self.monomial((Ltuple(0, 1), self._one_perm)) * self._Li_power(i,m-1)

z = PolynomialRing(self.base_ring(), 'DUMMY').gen()
p = list(prod(z - val for val in self._u))#[:-1]
p.pop() # remove the highest power
p = list(prod(z - val for val in self._u)) # [:-1]
p.pop() # remove the highest power
zero = self.base_ring().zero()
return self._from_dict({(Ltuple(0, exp), self._one_perm): -coeff
for exp,coeff in enumerate(p) if coeff != zero},
for exp, coeff in enumerate(p)
if coeff != zero},
remove_zeros=False, coerce=False)

@cached_method
Expand Down Expand Up @@ -1294,7 +1295,7 @@ def _from_LT_basis(self, m):
True
"""
ret = self.prod(self.L(i+1)**k for i,k in enumerate(m[0]))
return ret * self.monomial( (self._zero_tuple, m[1]) )
return ret * self.monomial((self._zero_tuple, m[1]))

@cached_method
def algebra_generators(self):
Expand Down Expand Up @@ -1337,9 +1338,9 @@ def T(self, i=None):
return [self.T(j) for j in range(self._n)]

if i == 0:
return self.monomial( ((1,) + self._zero_tuple[1:], self._one_perm) )
return self.monomial(((1,) + self._zero_tuple[1:], self._one_perm))
s = self._Pn.simple_reflections()
return self.monomial( (self._zero_tuple, s[i]) )
return self.monomial((self._zero_tuple, s[i]))

@cached_method
def L(self, i=None):
Expand Down Expand Up @@ -1514,7 +1515,7 @@ def product_on_basis(self, m1, m2):
return L * M * R

# The current product of T's and the type A Hecke algebra
tprod = [( [(k, a) for k, a in enumerate(t2) if a != 0], {s2: one} )]
tprod = [([(k, a) for k, a in enumerate(t2) if a != 0], {s2: one})]

# s1 through t2
for i in reversed(s1.reduced_word()):
Expand Down
2 changes: 1 addition & 1 deletion src/sage/algebras/lie_algebras/bgg_dual_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def _acted_upon_(self, scalar, self_on_left=False):


#####################################################################
## Simple modules
# Simple modules


# This is an abuse as the monoid is not free.
Expand Down
12 changes: 6 additions & 6 deletions src/sage/algebras/lie_algebras/center_uea.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
- Travis Scrimshaw (2024-01-02): Initial version
"""

#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2024 Travis Scrimshaw <tcscrims at gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
# https://www.gnu.org/licenses/
# ****************************************************************************

#from sage.structure.unique_representation import UniqueRepresentation
#from sage.structure.parent import Parent
# from sage.structure.unique_representation import UniqueRepresentation
# from sage.structure.parent import Parent
from sage.combinat.free_module import CombinatorialFreeModule
from sage.combinat.integer_lists.invlex import IntegerListsLex
from sage.matrix.constructor import matrix
from sage.monoids.indexed_free_monoid import IndexedFreeAbelianMonoid #, IndexedFreeAbelianMonoidElement
from sage.monoids.indexed_free_monoid import IndexedFreeAbelianMonoid
from sage.monoids.indexed_free_monoid import IndexedMonoid
from sage.combinat.root_system.coxeter_group import CoxeterGroup
from sage.combinat.integer_vector_weighted import iterator_fast as intvecwt_iterator
Expand Down
14 changes: 7 additions & 7 deletions src/sage/algebras/lie_algebras/classical_lie_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,15 +379,15 @@ def build_assoc(row):
continue
basis_pivots.add(p)
if self._sparse:
added.append(self.element_class( self, build_assoc(cur_mat[i]) ))
added.append(self.element_class(self, build_assoc(cur_mat[i])))
else:
added.append(self.element_class( self, self._assoc(cur_mat[i].list()) ))
added.append(self.element_class(self, self._assoc(cur_mat[i].list())))
cur_mat = cur_mat.submatrix(nrows=len(pivots))
if self._sparse:
basis = [self.element_class( self, build_assoc(cur_mat[i]) )
basis = [self.element_class(self, build_assoc(cur_mat[i]))
for i in range(cur_mat.rank())]
else:
basis = [self.element_class( self, self._assoc(cur_mat[i].list()) )
basis = [self.element_class(self, self._assoc(cur_mat[i].list()))
for i in range(cur_mat.rank())]
return Family(basis)

Expand Down Expand Up @@ -1077,7 +1077,7 @@ def __init__(self, R):


#######################################
## Compact real form
# Compact real form

class MatrixCompactRealForm(FinitelyGeneratedLieAlgebra):
r"""
Expand Down Expand Up @@ -1558,7 +1558,7 @@ def monomial_coefficients(self, copy=False):


#######################################
## Chevalley Basis
# Chevalley Basis

class LieAlgebraChevalleyBasis(LieAlgebraWithStructureCoefficients):
r"""
Expand Down Expand Up @@ -2054,7 +2054,7 @@ def _weight_action(self, m, wt):
# enough in the ambient space to correctly convert things to do
# the scalar product.
alc = wt.parent().simple_coroots()
return R(wt.scalar( alc[aci[m]] ))
return R(wt.scalar(alc[aci[m]]))

def affine(self, kac_moody=True):
r"""
Expand Down
18 changes: 9 additions & 9 deletions src/sage/algebras/lie_algebras/onsager.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def alternating_central_extension(self):
Element = LieAlgebraElement

#####################################################################
## q-Onsager algebra (the quantum group)
# q-Onsager algebra (the quantum group)


class QuantumOnsagerAlgebra(CombinatorialFreeModule):
Expand Down Expand Up @@ -795,10 +795,10 @@ def a(m, p):
assert m > 0
terms = q**-2 * self.monomial(B[kr] * B[kl])
terms -= self.monomial(B[1,m])
temp = ( -sum(q**(-2*(p-1)) * self.monomial(B[1,m-2*p])
temp = (-sum(q**(-2*(p-1)) * self.monomial(B[1,m-2*p])
for p in range(1, (m - 1) // 2 + 1))
+ sum(a(m,p) * self.monomial(B[0,kr[1]-p]) * self.monomial(B[0,p+kl[1]])
for p in range(1, m // 2 + 1)) )
for p in range(1, m // 2 + 1)))
terms += (q**-2 - 1) * temp
else:
r = -kr[1] - 1
Expand All @@ -812,10 +812,10 @@ def a(m, p):
terms -= (q**2-q**-2) * sum(q**(2*(r-1-k)) * self.monomial(B[0,-(k+1)]) * self.monomial(B[0,-r+kl[1]+k])
for k in range(r))
m = -r + kl[1] + 1
temp = ( -sum(q**(-2*(p-1)) * self.monomial(B[1,m-2*p])
temp = (-sum(q**(-2*(p-1)) * self.monomial(B[1,m-2*p])
for p in range(1, (m - 1) // 2 + 1))
+ sum(a(m,p) * self.monomial(B[0,m-p-1]) * self.monomial(B[0,p-1])
for p in range(1, m // 2 + 1)) )
for p in range(1, m // 2 + 1)))
terms += (q**-2 - 1) * q**(2*r) * temp
else:
# [B[rd+a0], B[sd+a1]] r > s
Expand All @@ -826,10 +826,10 @@ def a(m, p):
terms -= (q**2-q**-2) * sum(q**(2*(kl[1]-1-k)) * self.monomial(B[0,-(r-kl[1]+k+1)]) * self.monomial(B[0,k])
for k in range(kl[1]))
m = r - kl[1] + 1
temp = ( -sum(q**(-2*(p-1)) * self.monomial(B[1,m-2*p])
temp = (-sum(q**(-2*(p-1)) * self.monomial(B[1,m-2*p])
for p in range(1, (m - 1) // 2 + 1))
+ sum(a(m,p) * self.monomial(B[0,-p]) * self.monomial(B[0,p-m])
for p in range(1, m // 2 + 1)) )
for p in range(1, m // 2 + 1)))
terms += (q**-2 - 1) * q**(2*kl[1]) * temp
terms = -q**2 * terms
elif kl[0] == 1 and kr[0] == 0:
Expand Down Expand Up @@ -877,7 +877,7 @@ def a(m, p):
for h in range(1, ell))
- q**(2*(ell-1)) * self.monomial(B[0,-(p-ell+1)] * B[1,kl[1]-ell])
for ell in range(1, kl[1]))
else: #kl[0] == 0 and kr[0] == 1:
else: # kl[0] == 0 and kr[0] == 1:
terms = self.monomial(B[kr] * B[kl])
if kl[1] < kr[1]:
# [B[pd+a1], B[md]] with p < m
Expand Down Expand Up @@ -923,7 +923,7 @@ def a(m, p):
return self.monomial(lhs // B[kl]) * terms * self.monomial(rhs // B[kr])

#####################################################################
## ACE of the Onsager algebra
# ACE of the Onsager algebra


class OnsagerAlgebraACE(InfinitelyGeneratedLieAlgebra, IndexedGenerators):
Expand Down
20 changes: 10 additions & 10 deletions src/sage/algebras/lie_algebras/rank_two_heisenberg_virasoro.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def K(self, i=None):
"""
if i is None:
return Family(self._KI, self.K)
return self.monomial( ('K', i) )
return self.monomial(('K', i))

def t(self, a, b):
r"""
Expand All @@ -225,7 +225,7 @@ def t(self, a, b):
"""
if a == b == 0:
raise ValueError("no t(0, 0) element")
return self.monomial( ('t', self._v(a,b)) )
return self.monomial(('t', self._v(a,b)))

def E(self, a, b):
r"""
Expand All @@ -239,7 +239,7 @@ def E(self, a, b):
"""
if a == b == 0:
raise ValueError("no E(0, 0) element")
return self.monomial( ('E', self._v(a,b)) )
return self.monomial(('E', self._v(a,b)))

def _v(self, a, b):
r"""
Expand Down Expand Up @@ -324,10 +324,10 @@ def _an_element_(self):
d = self.monomial
v = self._v
return (
d( ('E',v(1,-3)) )
- self.base_ring().an_element() * d( ('t',v(-1,3)) )
+ d( ('E',v(2,2)) )
+ d( ('K',3) )
d(('E',v(1,-3)))
- self.base_ring().an_element() * d(('t',v(-1,3)))
+ d(('E',v(2,2)))
+ d(('K',3))
)

def some_elements(self):
Expand All @@ -345,9 +345,9 @@ def some_elements(self):
"""
d = self.monomial
v = self._v
return [d( ('E',v(1,1)) ), d( ('E',v(-2,-2)) ), d( ('E',v(0,1)) ),
d( ('t',v(1,1)) ), d( ('t',v(4,-1)) ), d( ('t',v(2,3)) ),
d( ('K',2) ), d( ('K',4) ), self.an_element()]
return [d(('E',v(1,1))), d(('E',v(-2,-2))), d(('E',v(0,1))),
d(('t',v(1,1))), d(('t',v(4,-1))), d(('t',v(2,3))),
d(('K',2)), d(('K',4)), self.an_element()]

class Element(LieAlgebraElement):
pass
Loading

0 comments on commit 4d73a2c

Please sign in to comment.