Skip to content

Commit

Permalink
sagemathgh-39315: partial pep8 cleanup in Lie conformal algebras
Browse files Browse the repository at this point in the history
just adding spaces after comma, mostly

alos using `.items()` in several places

### 📝 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#39315
Reported by: Frédéric Chapoton
Reviewer(s): David Coudert, Frédéric Chapoton
  • Loading branch information
Release Manager committed Jan 12, 2025
2 parents 78d7825 + 14d64f9 commit 11e5445
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 70 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=4a5eaad5588796001c3610853d00d8a2e7bb8682
sha256=e869359c2633c491498b2826f94888f9cdc8fbbaf25dffece871cd40e0b155b8
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
50b0d01a55d3e127f0e8bb6e01bb53afbe218a73
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,17 @@ def __init__(self, R, ngens=1, weights=None,
names = 'a'
self._latex_names = tuple(r'a_{%d}' % i for i in range(ngens))

names,index_set = standardize_names_index_set(names=names,
index_set=index_set,
ngens=ngens)
names, index_set = standardize_names_index_set(names=names,
index_set=index_set,
ngens=ngens)
abeliandict = {}

GradedLieConformalAlgebra.__init__(self, R, abeliandict, names=names,
index_set=index_set, weights=weights,
index_set=index_set,
weights=weights,
parity=parity)

def _repr_(self):
def _repr_(self) -> str:
"""
String representation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def cartan_type(self):
"""
return self._ct

def _repr_(self):
def _repr_(self) -> str:
"""
The name of this Lie conformal algebra.
Expand All @@ -152,4 +152,4 @@ def _repr_(self):
The affine Lie conformal algebra of type ['A', 1] over Rational Field
"""
return "The affine Lie conformal algebra of type {} over {}".format(
self._ct,self.base_ring())
self._ct, self.base_ring())
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def __init__(self, R, ngens=2, names=None, index_set=None):
weights=weights,
central_elements=('K',))

def _repr_(self):
def _repr_(self) -> str:
"""
String representation.
Expand All @@ -130,4 +130,4 @@ def _repr_(self):
The Bosonic ghosts Lie conformal algebra with generators (beta, gamma, K) over Algebraic Field
"""
return "The Bosonic ghosts Lie conformal algebra with generators {} "\
"over {}".format(self.gens(),self.base_ring())
"over {}".format(self.gens(), self.base_ring())
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __init__(self, R, ngens=2, names=None, index_set=None):
parity=parity,
central_elements=('K',))

def _repr_(self):
def _repr_(self) -> str:
"""
String representation.
Expand All @@ -127,4 +127,4 @@ def _repr_(self):
The Fermionic ghosts Lie conformal algebra with generators (b, c, K) over Rational Field
"""
return "The Fermionic ghosts Lie conformal algebra with generators {} "\
"over {}".format(self.gens(),self.base_ring())
"over {}".format(self.gens(), self.base_ring())
Original file line number Diff line number Diff line change
Expand Up @@ -114,37 +114,39 @@ def __init__(self, R, ngens=None, gram_matrix=None, names=None,
if ngens is None:
ngens = gram_matrix.dimensions()[0]
try:
assert (gram_matrix in MatrixSpace(R,ngens,ngens))
assert (gram_matrix in MatrixSpace(R, ngens, ngens))
except AssertionError:
raise ValueError("the gram_matrix should be a symmetric " +
"{0} x {0} matrix, got {1}".format(ngens,gram_matrix))
"{0} x {0} matrix, got {1}".format(ngens, gram_matrix))
if not gram_matrix.is_symmetric():
raise ValueError("the gram_matrix should be a symmetric " +
"{0} x {0} matrix, got {1}".format(ngens,gram_matrix))
"{0} x {0} matrix, got {1}".format(ngens, gram_matrix))
else:
if ngens is None:
ngens = 1
gram_matrix = identity_matrix(R, ngens, ngens)

latex_names = None
if (names is None) and (index_set is None):
if names is None and index_set is None:
names = 'alpha'
latex_names = tuple(r'\alpha_{%d}' % i
for i in range(ngens)) + ('K',)
names,index_set = standardize_names_index_set(names=names,
index_set=index_set,
ngens=ngens)
bosondict = {(i,j): {1: {('K',0): gram_matrix[index_set.rank(i),
index_set.rank(j)]}} for i in index_set for j in index_set}

GradedLieConformalAlgebra.__init__(self,R,bosondict,names=names,
names, index_set = standardize_names_index_set(names=names,
index_set=index_set,
ngens=ngens)
bosondict = {(i, j): {1: {('K', 0): gram_matrix[index_set.rank(i),
index_set.rank(j)]}}
for i in index_set for j in index_set}

GradedLieConformalAlgebra.__init__(self, R, bosondict,
names=names,
latex_names=latex_names,
index_set=index_set,
central_elements=('K',))

self._gram_matrix = gram_matrix

def _repr_(self):
def _repr_(self) -> str:
"""
String representation.
Expand All @@ -154,7 +156,7 @@ def _repr_(self):
The free Bosons Lie conformal algebra with generators (alpha, K) over Algebraic Real Field
"""
return "The free Bosons Lie conformal algebra with generators {}"\
" over {}".format(self.gens(),self.base_ring())
" over {}".format(self.gens(), self.base_ring())

def gram_matrix(self):
r"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,52 +94,51 @@ def __init__(self, R, ngens=None, gram_matrix=None, names=None,
"""
from sage.matrix.matrix_space import MatrixSpace
from sage.matrix.special import identity_matrix
if (gram_matrix is not None):
if gram_matrix is not None:
if ngens is None:
ngens = gram_matrix.dimensions()[0]
try:
assert (gram_matrix in MatrixSpace(R,ngens,ngens))
assert (gram_matrix in MatrixSpace(R, ngens, ngens))
except AssertionError:
raise ValueError("The gram_matrix should be a symmetric " +
"{0} x {0} matrix, got {1}".format(ngens,gram_matrix))
"{0} x {0} matrix, got {1}".format(ngens, gram_matrix))
if not gram_matrix.is_symmetric():
raise ValueError("The gram_matrix should be a symmetric " +
"{0} x {0} matrix, got {1}".format(ngens,gram_matrix))
"{0} x {0} matrix, got {1}".format(ngens, gram_matrix))
else:
if ngens is None:
ngens = 1
gram_matrix = identity_matrix(R, ngens, ngens)

latex_names = None

if (names is None) and (index_set is None):
if ngens == 1:
names = 'psi'
else:
names = 'psi_'
if names is None and index_set is None:
names = 'psi' if ngens == 1 else 'psi_'
latex_names = tuple(r"\psi_{%d}" % i
for i in range(ngens)) + ('K',)

from sage.structure.indexed_generators import \
standardize_names_index_set
names,index_set = standardize_names_index_set(names=names,
index_set=index_set,
ngens=ngens)
fermiondict = {(i,j): {0: {('K', 0): gram_matrix[index_set.rank(i),
index_set.rank(j)]}} for i in index_set for j in index_set}
standardize_names_index_set
names, index_set = standardize_names_index_set(names=names,
index_set=index_set,
ngens=ngens)
fermiondict = {(i, j): {0: {('K', 0): gram_matrix[index_set.rank(i),
index_set.rank(j)]}}
for i in index_set for j in index_set}

from sage.rings.rational_field import QQ
weights = (QQ(1/2),)*ngens
parity = (1,)*ngens
GradedLieConformalAlgebra.__init__(self,R,fermiondict,names=names,
weights = (QQ((1, 2)),) * ngens
parity = (1,) * ngens
GradedLieConformalAlgebra.__init__(self, R, fermiondict, names=names,
latex_names=latex_names,
index_set=index_set,weights=weights,
index_set=index_set,
weights=weights,
parity=parity,
central_elements=('K',))

self._gram_matrix = gram_matrix

def _repr_(self):
def _repr_(self) -> str:
"""
String representation.
Expand All @@ -149,8 +148,8 @@ def _repr_(self):
The free Fermions super Lie conformal algebra with generators (psi, K) over Rational Field
"""
return "The free Fermions super Lie conformal algebra "\
"with generators {} over {}".format(self.gens(),
self.base_ring())
"with generators {} over {}".format(self.gens(),
self.base_ring())

def gram_matrix(self):
r"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def lie_conformal_algebra_generators(self):
(B[alpha[1]], B[alphacheck[1]], B[-alpha[1]], B['K'])
"""
F = Family(self._generators,
lambda i: self.monomial((i,Integer(0))),
name="generator map")
lambda i: self.monomial((i, Integer(0))),
name="generator map")
from sage.categories.sets_cat import Sets
if F in Sets().Finite():
return tuple(F)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def __classcall_private__(cls, R=None, arg0=None, index_set=None,
if key not in known_keywords:
raise ValueError("got an unexpected keyword argument '%s'" % key)

if isinstance(arg0,dict) and arg0:
if isinstance(arg0, dict) and arg0:
graded = kwds.pop("graded", False)
if weights is not None or graded:
from .graded_lie_conformal_algebra import \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ class LieConformalAlgebraWithStructureCoefficients(
`\lambda`-brackets of the generators::
sage: betagamma_dict = {('b','a'):{0:{('K',0):1}}}
sage: V = LieConformalAlgebra(QQ, betagamma_dict, names=('a','b'), weights=(1,0), central_elements=('K',))
sage: V = LieConformalAlgebra(QQ, betagamma_dict, names=('a','b'),
....: weights=(1,0), central_elements=('K',))
sage: V.category()
Category of H-graded finitely generated Lie conformal algebras with basis over Rational Field
Category of H-graded finitely generated Lie conformal algebras
with basis over Rational Field
sage: V.inject_variables()
Defining a, b, K
sage: a.bracket(b)
Expand Down Expand Up @@ -148,9 +150,8 @@ def _standardize_s_coeff(s_coeff, index_set, ce, parity=None):
index_to_parity = dict(zip(index_set, parity))
sc = {}
# mypair has a pair of generators
for mypair in s_coeff.keys():
for mypair, v in s_coeff.items():
# e.g. v = { 0: { (L,2):3, (G,3):1}, 1:{(L,1),2} }
v = s_coeff[mypair]
key = tuple(mypair)
vals = {}
for l in v:
Expand Down Expand Up @@ -186,7 +187,7 @@ def _standardize_s_coeff(s_coeff, index_set, ce, parity=None):
kth_product[(i[0], i[1] + j)] = \
kth_product.get((i[0], i[1] + j), 0)
kth_product[(i[0], i[1] + j)] += parsgn *\
v[k+j][i]*(-1)**(k+j+1)*binomial(i[1]+j,j)
v[k+j][i]*(-1)**(k+j+1)*binomial(i[1]+j, j)
kth_product = {k: v for k, v in kth_product.items() if v}
if kth_product:
vals[k] = kth_product
Expand All @@ -212,21 +213,22 @@ def __init__(self, R, s_coeff, index_set=None, central_elements=None,
sage: V = lie_conformal_algebras.NeveuSchwarz(QQ)
sage: TestSuite(V).run()
"""
names, index_set = standardize_names_index_set(names,index_set)
names, index_set = standardize_names_index_set(names, index_set)
if central_elements is None:
central_elements = ()

if names is not None and names != tuple(index_set):
names2 = names + tuple(central_elements)
index_set2 = DisjointUnionEnumeratedSets((index_set,
Family(tuple(central_elements))))
d = {x:index_set2[i] for i,x in enumerate(names2)}
d = {x: index_set2[i] for i, x in enumerate(names2)}
try:
#If we are given a dictionary with names as keys,
#convert to index_set as keys
s_coeff = {(d[k[0]],d[k[1]]):{a:{(d[x[1]],x[2]):
s_coeff[k][a][x] for x in
s_coeff[k][a]} for a in s_coeff[k]} for k in s_coeff.keys()}
# If we are given a dictionary with names as keys,
# convert to index_set as keys
s_coeff = {(d[k[0]], d[k[1]]):
{a: {(d[x[1]], x[2]): sck[a][x] for x in sck[a]}
for a in s_coeff[k]}
for k, sck in s_coeff.items()}

except KeyError:
# We assume the dictionary was given with keys in the
Expand Down Expand Up @@ -274,9 +276,12 @@ def __init__(self, R, s_coeff, index_set=None, central_elements=None,
prefix=prefix, names=names, latex_names=latex_names, **kwds)

s_coeff = dict(s_coeff)
self._s_coeff = Family({k: tuple((j, sum(c*self.monomial(i)
for i,c in v)) for j,v in s_coeff[k]) for k in s_coeff})
self._parity = dict(zip(self.gens(),parity+(0,)*len(central_elements)))
self._s_coeff = Family({k:
tuple((j, sum(c * self.monomial(i)
for i, c in v)) for j, v in sck)
for k, sck in s_coeff.items()})
self._parity = dict(zip(self.gens(),
parity + (0,) * len(central_elements)))

def structure_coefficients(self):
"""
Expand All @@ -289,11 +294,14 @@ def structure_coefficients(self):
Finite family {('L', 'L'): ((0, TL), (1, 2*L), (3, 1/2*C))}
sage: lie_conformal_algebras.NeveuSchwarz(QQ).structure_coefficients()
Finite family {('G', 'G'): ((0, 2*L), (2, 2/3*C)), ('G', 'L'): ((0, 1/2*TG), (1, 3/2*G)), ('L', 'G'): ((0, TG), (1, 3/2*G)), ('L', 'L'): ((0, TL), (1, 2*L), (3, 1/2*C))}
Finite family {('G', 'G'): ((0, 2*L), (2, 2/3*C)),
('G', 'L'): ((0, 1/2*TG), (1, 3/2*G)),
('L', 'G'): ((0, TG), (1, 3/2*G)),
('L', 'L'): ((0, TL), (1, 2*L), (3, 1/2*C))}
"""
return self._s_coeff

def _repr_generator(self, x):
def _repr_generator(self, x) -> str:
"""
String representation of the generator ``x``.
Expand All @@ -316,4 +324,4 @@ def _repr_generator(self, x):
"""
if x in self:
return repr(x)
return IndexedGenerators._repr_generator(self,x)
return IndexedGenerators._repr_generator(self, x)

0 comments on commit 11e5445

Please sign in to comment.