Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing some E502 outside of schemes and combinat #35317

Merged
merged 2 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,24 @@ def __init__(self, R, ct, names=None, prefix=None, bracket=None):
if S.rank(k2) <= S.rank(k1):
myb = B[k1].bracket(B[k2]).monomial_coefficients()
myf = R(2).inverse_of_unit()*R(hv).inverse_of_unit()\
*g.killing_form(B[k1],B[k2])
* g.killing_form(B[k1], B[k2])
if myb or myf:
gdict[(k1,k2)] = {}
gdict[(k1, k2)] = {}
if myb:
gdict[(k1,k2)][0] = {(nk,0):v for nk,v in \
myb.items()}
gdict[(k1, k2)][0] = {(nk, 0): v
for nk, v in myb.items()}
if myf:
gdict[(k1,k2)][1] = {('K',0):myf}
gdict[(k1, k2)][1] = {('K', 0): myf}

weights = (1,)*B.cardinality()
weights = (1,) * B.cardinality()
self._ct = ct
if prefix is None and names is None:
prefix = 'B'

GradedLieConformalAlgebra.__init__(self,
R, gdict, index_set=S,
central_elements=('K',), weights=weights,
names=names, prefix=prefix,bracket=bracket)
R, gdict, index_set=S,
central_elements=('K',), weights=weights,
names=names, prefix=prefix, bracket=bracket)

def cartan_type(self):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,29 +87,31 @@ def __init__(self, R, ngens=2, names=None, index_set=None):
"""
from sage.rings.integer_ring import ZZ
try:
assert (ngens in ZZ and ngens > 0 and ngens % 2 == 0)
assert (ngens in ZZ and ngens > 0 and not ngens % 2)
except AssertionError:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of this replacement. Seems harder to read for me after the change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more pythonic and slightly faster.

raise ValueError("ngens should be an even positive integer, " +
"got {}".format(ngens))
latex_names = None
half = ngens // 2
if (names is None) and (index_set is None):
from sage.misc.defaults import variable_names as varnames
from sage.misc.defaults import latex_variable_names as laxnames
names = varnames(ngens/2,'beta') + varnames(ngens/2,'gamma')
latex_names = tuple(laxnames(ngens/2,r'\beta') +\
laxnames(ngens/2,r'\gamma')) + ('K',)
names = varnames(half, 'beta') + varnames(half, 'gamma')
latex_names = tuple(laxnames(half, r'\beta') +
laxnames(half, r'\gamma')) + ('K',)

names,index_set = standardize_names_index_set(names=names,
names, index_set = standardize_names_index_set(names=names,
index_set=index_set,
ngens=ngens)
A = identity_matrix(R, ngens // 2)
A = identity_matrix(R, half)
from sage.matrix.special import block_matrix
gram_matrix = block_matrix([[R.zero(),A],[-A,R.zero()]])
ghostsdict = { (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}
weights = (1,)*(ngens//2) + (0,)*(ngens//2)
gram_matrix = block_matrix([[R.zero(), A], [-A, R.zero()]])
ghostsdict = {(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}
weights = (1,) * half + (0,) * half
super().__init__(R,
ghostsdict,names=names,
ghostsdict, names=names,
latex_names=latex_names,
index_set=index_set,
weights=weights,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,33 +80,35 @@ def __init__(self,R,ngens=2,names=None,index_set=None):
sage: TestSuite(V).run()
"""
try:
assert (ngens > 0 and ngens % 2 == 0)
assert (ngens > 0 and not ngens % 2)
except AssertionError:
raise ValueError("ngens should be an even positive integer, " +
"got {}".format(ngens))
latex_names = None
half = ngens // 2
if (names is None) and (index_set is None):
from sage.misc.defaults import variable_names as varnames
from sage.misc.defaults import latex_variable_names as laxnames
names = varnames(ngens/2,'b') + varnames(ngens/2,'c')
latex_names = tuple(laxnames(ngens/2,'b') +\
laxnames(ngens/2,'c')) + ('K',)
names = varnames(half, 'b') + varnames(half, 'c')
latex_names = tuple(laxnames(half, 'b') +
laxnames(half, 'c')) + ('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)
standardize_names_index_set
names, index_set = standardize_names_index_set(names=names,
index_set=index_set,
ngens=ngens)
from sage.matrix.special import identity_matrix
A = identity_matrix(R, ngens // 2)
A = identity_matrix(R, half)
from sage.matrix.special import block_matrix
gram_matrix = block_matrix([[R.zero(),A],[A,R.zero()]])
ghostsdict = { (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}
weights = (1,)*(ngens//2) + (0,)*(ngens//2)
parity = (1,)*ngens
gram_matrix = block_matrix([[R.zero(), A], [A, R.zero()]])
ghostsdict = {(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}
weights = (1,) * half + (0,) * half
parity = (1,) * ngens
super().__init__(R,
ghostsdict,names=names,
ghostsdict, names=names,
latex_names=latex_names,
index_set=index_set,
weights=weights,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ def T(self, n=1):
raise ValueError("n must be a nonnegative Integer")
if n == 0 or self.is_zero():
return self
#it's faster to sum than to use recursion
# it's faster to sum than to use recursion
if self.is_monomial():
p = self.parent()
a,m = self.index()
coef = self._monomial_coefficients[(a,m)]
if (a,m+n) in p._indices:
return coef*prod(j for j in range(m+1,m+n+1))\
*p.monomial((a,m+n))
a, m = self.index()
coef = self._monomial_coefficients[(a, m)]
if (a, m + n) in p._indices:
return coef * prod(j for j in range(m + 1, m + n + 1))\
* p.monomial((a, m + n))
else:
return p.zero()
return sum(mon.T(n) for mon in self.terms())
Expand Down Expand Up @@ -121,23 +121,25 @@ def _bracket_(self, right):
if self.is_zero() or right.is_zero():
return {}
s_coeff = p._s_coeff
a,k = self.index()
coefa = self.monomial_coefficients()[(a,k)]
b,m = right.index()
coefb = right.monomial_coefficients()[(b,m)]
a, k = self.index()
coefa = self.monomial_coefficients()[(a, k)]
b, m = right.index()
coefb = right.monomial_coefficients()[(b, m)]
try:
mbr = dict(s_coeff[(a,b)])
mbr = dict(s_coeff[(a, b)])
except KeyError:
return {}
pole = max(mbr.keys())
ret = {l: coefa*coefb*(-1)**k/factorial(k)*sum(factorial(l)\
/factorial(m+k+j-l)/factorial(l-k-j)/factorial(j)*\
mbr[j].T(m+k+j-l) for j in mbr if j >= l-m-k and\
j <= l-k) for l in range(m+k+pole+1)}
ret = {l: coefa * coefb * (-1)**k / factorial(k) *
sum(factorial(l) / factorial(m + k + j - l)
/ factorial(l - k - j) / factorial(j)
* mbr[j].T(m + k + j - l)
for j in mbr if l - m - k <= j <= l - k)
for l in range(m + k + pole + 1)}
return {k: v for k, v in ret.items() if v}

diclist = [i._bracket_(j) for i in self.terms() for
j in right.terms()]
diclist = [i._bracket_(j) for i in self.terms()
for j in right.terms()]
ret = {}
pz = p.zero()
for d in diclist:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,18 @@ def _standardize_s_coeff(s_coeff, index_set, ce, parity=None):
if lth_product:
vals[l]=lth_product

myvals = tuple([(k,tuple(v.items())) for k,v in vals.items() if v])
myvals = tuple((k, tuple(v.items())) for k, v in vals.items() if v)

if key in sc.keys() and sorted(sc[key]) != sorted(myvals):
raise ValueError("two distinct values given for one "\
"and the same bracket, skew-symmetry"\
raise ValueError("two distinct values given for one "
"and the same bracket, skew-symmetry"
"is not satisfied?")
if myvals:
sc[key] = myvals

#We now add the skew-symmetric part to optimize
#brackets computations later
key=(mypair[1],mypair[0])
# We now add the skew-symmetric part to optimize
# brackets computations later
key = (mypair[1], mypair[0])
if index_to_parity[mypair[0]]*index_to_parity[mypair[1]]:
parsgn = -1
else:
Expand All @@ -191,11 +191,11 @@ def _standardize_s_coeff(s_coeff, index_set, ce, parity=None):
if kth_product:
vals[k]=kth_product

myvals = tuple([(k,tuple(v.items())) for k,v in vals.items() if v])
myvals = tuple((k, tuple(v.items())) for k, v in vals.items() if v)

if key in sc.keys() and sorted(sc[key]) != sorted(myvals):
raise ValueError("two distinct values given for one "\
"and the same bracket. "\
raise ValueError("two distinct values given for one "
"and the same bracket. "
"Skew-symmetry is not satisfied?")
if myvals:
sc[key] = myvals
Expand Down Expand Up @@ -233,31 +233,31 @@ def __init__(self, R, s_coeff, index_set=None, central_elements=None,
# index_set
pass

issuper=kwds.pop('super', False)
issuper = kwds.pop('super', False)
if parity is None:
parity = (0,)*index_set.cardinality()
parity = (0,) * index_set.cardinality()
else:
issuper = True

try:
assert len(parity) == index_set.cardinality()
except AssertionError:
raise ValueError("parity should have the same length as the "\
"number of generators, got {}".format(parity))
raise ValueError("parity should have the same length as the "
f"number of generators, got {parity}")

s_coeff = LieConformalAlgebraWithStructureCoefficients\
._standardize_s_coeff(s_coeff, index_set, central_elements,
parity)
._standardize_s_coeff(s_coeff, index_set, central_elements,
parity)

if names is not None and central_elements is not None:
names += tuple(central_elements)

self._index_to_pos = {k: i for i,k in enumerate(index_set)}
#Add central parameters to index_to_pos so that we can
#represent names
self._index_to_pos = {k: i for i, k in enumerate(index_set)}
# Add central parameters to index_to_pos so that we can
# represent names
if central_elements is not None:
for i,ce in enumerate(central_elements):
self._index_to_pos[ce] = len(index_set)+i
for i, ce in enumerate(central_elements):
self._index_to_pos[ce] = len(index_set) + i

default_category = LieConformalAlgebras(R).WithBasis().FinitelyGenerated()
if issuper:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,17 @@ def __init__(self, R):
sage: V = lie_conformal_algebras.NeveuSchwarz(QQ)
sage: TestSuite(V).run()
"""
nsdict = {('L','L'):{0:{('L',1):1}, 1:{('L',0): 2},
3:{('C', 0):R(2).inverse_of_unit()}},
('L','G'):{0:{('G',1):1}, 1:{('G',0):R(3)*R(2).\
inverse_of_unit()}}, ('G','G'): {0:{('L',0):2},
2:{('C',0):R(2)*R(3).inverse_of_unit()}}}
nsdict = {('L', 'L'): {0: {('L', 1): 1},
1: {('L', 0): 2},
3: {('C', 0): R(2).inverse_of_unit()}},
('L', 'G'): {0: {('G', 1): 1},
1: {('G', 0): R(3) * R(2).inverse_of_unit()}},
('G', 'G'): {0: {('L', 0): 2},
2: {('C', 0): R(2) * R(3).inverse_of_unit()}}}
from sage.rings.rational_field import QQ
weights = (2,QQ(3/2))
parity = (0,1)
GradedLieConformalAlgebra.__init__(self, R, nsdict, names=('L','G'),
weights = (2, QQ((3, 2)))
parity = (0, 1)
GradedLieConformalAlgebra.__init__(self, R, nsdict, names=('L', 'G'),
central_elements=('C',), weights=weights, parity=parity)

def _repr_(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class WeylLieConformalAlgebra(LieConformalAlgebraWithStructureCoefficients):
[0 1 0]
[0 0 1]
"""
def __init__(self,R,ngens=None, gram_matrix=None, names=None,
def __init__(self, R, ngens=None, gram_matrix=None, names=None,
index_set=None):
"""
Initialize self.
Expand All @@ -131,31 +131,29 @@ def __init__(self,R,ngens=None, gram_matrix=None, names=None,
"""
from sage.matrix.matrix_space import MatrixSpace
if ngens:
try:
from sage.rings.integer_ring import ZZ
assert ngens in ZZ and ngens % 2 == 0
except AssertionError:
raise ValueError("ngens needs to be an even positive "+
"Integer, got {}".format(ngens))
if (gram_matrix is not None):
from sage.rings.integer_ring import ZZ
if not(ngens in ZZ and not ngens % 2):
raise ValueError("ngens needs to be an even positive Integer, "
f"got {ngens}")
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 skew-symmetric "+
"{0} x {0} matrix, got {1}".format(ngens,gram_matrix))
if (not gram_matrix.is_skew_symmetric()) or \
(gram_matrix.is_singular()):
raise ValueError("The gram_matrix should be a non degenerate " +
"skew-symmetric {0} x {0} matrix, got {1}"\
.format(ngens,gram_matrix))
elif (gram_matrix is None):
raise ValueError("The gram_matrix should be a skew-symmetric "
"{0} x {0} matrix, got {1}".format(ngens, gram_matrix))
if (not gram_matrix.is_skew_symmetric() or
gram_matrix.is_singular()):
raise ValueError("The gram_matrix should be a non degenerate "
"skew-symmetric {0} x {0} matrix, got {1}"
.format(ngens, gram_matrix))
elif gram_matrix is None:
if ngens is None:
ngens = 2
A = identity_matrix(R, ngens // 2)
from sage.matrix.special import block_matrix
gram_matrix = block_matrix([[R.zero(),A],[-A,R.zero()]])
gram_matrix = block_matrix([[R.zero(), A], [-A, R.zero()]])

latex_names = None
if (names is None) and (index_set is None):
Expand Down
4 changes: 2 additions & 2 deletions src/sage/categories/drinfeld_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def characteristic(self):
0
"""
if self._characteristic is None:
raise NotImplementedError('function ring characteristic not ' \
raise NotImplementedError('function ring characteristic not '
'implemented in this case')
return self._characteristic

Expand Down Expand Up @@ -496,7 +496,7 @@ def object(self, gen):
gen = self._ore_polring(gen)
T = self._function_ring.gen()
if gen[0] != self._base_morphism(T):
raise ValueError('constant coefficient must equal that of the ' \
raise ValueError('constant coefficient must equal that of the '
'category')
return DrinfeldModule(self._function_ring, gen)

Expand Down
11 changes: 4 additions & 7 deletions src/sage/coding/linear_code_no_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ def __eq__(self, other):
False
"""
# Fail without computing the generator matrix if possible:
if not (isinstance(other, AbstractLinearCodeNoMetric)\
and self.length() == other.length()\
and self.dimension() == other.dimension()\
if not (isinstance(other, AbstractLinearCodeNoMetric)
and self.length() == other.length()
and self.dimension() == other.dimension()
and self.base_ring() == other.base_ring()):
return False
# Check that basis elements of `other` are all in `self.`
Expand All @@ -276,10 +276,7 @@ def __eq__(self, other):
# This implementation may avoid linear algebra altogether, if `self`
# implements an efficient way to obtain a parity check matrix, and in
# the worst case does only one system solving.
for c in other.gens():
if not (c in self):
return False
return True
return all(c in self for c in other.gens())

def __ne__(self, other):
r"""
Expand Down
Loading