Skip to content

Commit

Permalink
gh-36664: ruff auto-fix for C4 in modular
Browse files Browse the repository at this point in the history
this was scripted using
```
ruff check --select=C4 --fix src/sage/modular/
```
and is about simplifying list,set,dict comprehensions

### 📝 Checklist

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

URL: #36664
Reported by: Frédéric Chapoton
Reviewer(s): David Ayotte
  • Loading branch information
Release Manager committed Dec 5, 2023
2 parents 3253ed9 + 46a1441 commit 9b1e18f
Show file tree
Hide file tree
Showing 24 changed files with 61 additions and 61 deletions.
6 changes: 3 additions & 3 deletions build/pkgs/configure/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tarball=configure-VERSION.tar.gz
sha1=c769dfca6414cc453b22e64863aee153c4041e6f
md5=b098e551614a15569894e0b99b4909ff
cksum=2514200459
sha1=09ed008d1bdba4837fdb078f8f50a67cac9a9d7f
md5=eeed6bf17634e46f99f44c1f8dcd010a
cksum=1753047461
2 changes: 1 addition & 1 deletion build/pkgs/configure/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b2813506039143e6f0abe859ab67a343abf72c2e
c3f06e4734ef325db812d73dcdb2bf846b590104
8 changes: 4 additions & 4 deletions src/sage/modular/abvar/abvar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2060,8 +2060,8 @@ def newform_level(self, none_if_not_known=False):
if none_if_not_known:
return None
level = LCM([f.level() for f in self.newform_decomposition('a')])
groups = sorted(set([f.group() for f in
self.newform_decomposition('a')]))
groups = sorted({f.group() for f in
self.newform_decomposition('a')})
if len(groups) == 1:
groups = groups[0]
self.__newform_level = level, groups
Expand Down Expand Up @@ -3870,7 +3870,7 @@ def _factors_with_same_label(self, other):
if not isinstance(other, ModularAbelianVariety_abstract):
raise TypeError("other must be an abelian variety")
D = self.decomposition()
C = set([A.newform_label() for A in other.decomposition()])
C = {A.newform_label() for A in other.decomposition()}
Z = []
for X in D:
lbl = X.newform_label()
Expand Down Expand Up @@ -4899,7 +4899,7 @@ def tamagawa_number_bounds(self, p):
else:
raise NotImplementedError("Atkin-Lehner at p must act as a scalar")
else:
mul_primes = sorted(set([p] + [q for q in prime_range(2, 2 * self.dimension() + 2)]))
mul_primes = sorted(set([p] + list(prime_range(2, 2 * self.dimension() + 2))))
div = Integer(div)
mul = Integer(mul)
mul_primes = tuple(mul_primes)
Expand Down
36 changes: 18 additions & 18 deletions src/sage/modular/abvar/homspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@
- Craig Citro, Robert Bradshaw (2008-03): Rewrote with modabvar overhaul
"""

#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2007 William Stein <wstein@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 copy import copy
Expand All @@ -188,7 +188,6 @@

from . import morphism

import sage.rings.integer_ring
from sage.rings.infinity import Infinity

from sage.rings.ring import Ring
Expand Down Expand Up @@ -276,7 +275,7 @@ def _matrix_space(self):
sage: Hom(J0(11), J0(22))._matrix_space
Full MatrixSpace of 2 by 4 dense matrices over Integer Ring
"""
return MatrixSpace(ZZ,2*self.domain().dimension(), 2*self.codomain().dimension())
return MatrixSpace(ZZ, 2*self.domain().dimension(), 2*self.codomain().dimension())

def _element_constructor_from_element_class(self, *args, **keywords):
"""
Expand Down Expand Up @@ -479,7 +478,7 @@ def free_module(self):
"""
self.calculate_generators()
V = ZZ**(4*self.domain().dimension() * self.codomain().dimension())
return V.submodule([ V(m.matrix().list()) for m in self.gens() ])
return V.submodule([V(m.matrix().list()) for m in self.gens()])

def gen(self, i=0):
"""
Expand Down Expand Up @@ -570,7 +569,7 @@ def calculate_generators(self):
return

if (self.domain() == self.codomain()) and (self.domain().dimension() == 1):
self._gens = tuple([ identity_matrix(ZZ,2) ])
self._gens = (identity_matrix(ZZ, 2),)
return

phi = self.domain()._isogeny_to_product_of_powers()
Expand All @@ -583,9 +582,9 @@ def calculate_generators(self):
Mt = psi.complementary_isogeny().matrix()

R = ZZ**(4*self.domain().dimension()*self.codomain().dimension())
gens = R.submodule([ (M*self._get_matrix(g)*Mt).list()
for g in im_gens ]).saturation().basis()
self._gens = tuple([ self._get_matrix(g) for g in gens ])
gens = R.submodule([(M*self._get_matrix(g)*Mt).list()
for g in im_gens]).saturation().basis()
self._gens = tuple([self._get_matrix(g) for g in gens])

def _calculate_product_gens(self):
"""
Expand Down Expand Up @@ -746,7 +745,8 @@ def _calculate_simple_gens(self):
Mf = f.matrix()
Mg = g.matrix()

return [ Mf * self._get_matrix(e) * Mg for e in ls ]
return [Mf * self._get_matrix(e) * Mg for e in ls]


# NOTE/WARNING/TODO: Below in the __init__, etc. we do *not* check
# that the input gens are give something that spans a sub*ring*, as apposed
Expand Down Expand Up @@ -820,7 +820,7 @@ def __init__(self, A, gens=None, category=None):
if gens is None:
self._gens = None
else:
self._gens = tuple([ self._get_matrix(g) for g in gens ])
self._gens = tuple([self._get_matrix(g) for g in gens])
self._is_full_ring = gens is None

def _repr_(self):
Expand Down Expand Up @@ -903,7 +903,7 @@ def index_in_saturation(self):
A = self.abelian_variety()
d = A.dimension()
M = ZZ**(4*d**2)
gens = [ x.matrix().list() for x in self.gens() ]
gens = [x.matrix().list() for x in self.gens()]
R = M.submodule(gens)
return R.index_in_saturation()

Expand Down Expand Up @@ -934,8 +934,8 @@ def discriminant(self):
2
"""
g = self.gens()
M = Matrix(ZZ,len(g), [ (g[i]*g[j]).trace()
for i in range(len(g)) for j in range(len(g)) ])
M = Matrix(ZZ, len(g), [(g[i]*g[j]).trace()
for i in range(len(g)) for j in range(len(g))])
return M.determinant()

def image_of_hecke_algebra(self, check_every=1):
Expand Down Expand Up @@ -1002,18 +1002,18 @@ def image_of_hecke_algebra(self, check_every=1):
EndVecZ = ZZ**(4*d**2)

if d == 1:
self.__hecke_algebra_image = EndomorphismSubring(A, [[1,0,0,1]])
self.__hecke_algebra_image = EndomorphismSubring(A, [[1, 0, 0, 1]])
return self.__hecke_algebra_image

V = EndVecZ.submodule([A.hecke_operator(1).matrix().list()])

for n in range(2,M.sturm_bound()+1):
for n in range(2, M.sturm_bound()+1):
if (check_every > 0 and
n % check_every == 0 and
V.dimension() == d and
V.index_in_saturation() == 1):
break
V += EndVecZ.submodule([ A.hecke_operator(n).matrix().list() ])
V += EndVecZ.submodule([A.hecke_operator(n).matrix().list()])

self.__hecke_algebra_image = EndomorphismSubring(A, V.basis())
return self.__hecke_algebra_image
4 changes: 2 additions & 2 deletions src/sage/modular/arithgroup/arithgroup_perm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1798,7 +1798,7 @@ def cusp_widths(self,exp=False):
"""
inv = self.S2()**2
L = self.L()
cusps = set(c[0] for c in L.cycle_tuples(singletons=True))
cusps = {c[0] for c in L.cycle_tuples(singletons=True)}
if exp:
widths = {}
else:
Expand Down Expand Up @@ -2603,7 +2603,7 @@ def odd_subgroups(self):
s3 = PermutationConstructor([x + tuple(y + n for y in x) for x in s3cycs])
H = ArithmeticSubgroup_Permutation(S2=s2,S3=s3)

bucket = set([H])
bucket = {H}
res = [H]
# We use a set *and* a list since checking whether an element is in a
# set is very fast, but on the other hand we want the order the results
Expand Down
10 changes: 5 additions & 5 deletions src/sage/modular/arithgroup/congroup_gammaH.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def _normalize_H(H, level):
for h in H:
if gcd(h, level) > 1:
raise ArithmeticError('The generators %s must be units modulo %s' % (H, level))
H = set(u for u in H if u > 1)
H = {u for u in H if u > 1}
final_H = set()
for h in H:
inv_h = h.inverse_mod(level)
Expand Down Expand Up @@ -1140,7 +1140,7 @@ def ncusps(self):
c = ZZ(0)
for d in (d for d in N.divisors() if d**2 <= N):
Nd = lcm(d, N // d)
Hd = set([x % Nd for x in H])
Hd = {x % Nd for x in H}
lenHd = len(Hd)
if Nd - 1 not in Hd:
lenHd *= 2
Expand Down Expand Up @@ -1182,7 +1182,7 @@ def nregcusps(self):
c = ZZ(0)
for d in (d for d in divisors(N) if d**2 <= N):
Nd = lcm(d, N // d)
Hd = set([x % Nd for x in H])
Hd = {x % Nd for x in H}
if Nd - 1 not in Hd:
summand = euler_phi(d) * euler_phi(N // d) // (2 * len(Hd))
if d**2 == N:
Expand Down Expand Up @@ -1395,7 +1395,7 @@ def _list_subgroup(N, gens):
sage: sage.modular.arithgroup.congroup_gammaH._list_subgroup(11, [3])
[1, 3, 4, 5, 9]
"""
H = set([1])
H = {1}
N = int(N)
for g in gens:
if gcd(g, N) != 1:
Expand All @@ -1405,7 +1405,7 @@ def _list_subgroup(N, gens):
while not (gk in H):
gk = (gk * g) % N
sbgrp.append(gk)
H = set([(x * h) % N for x in sbgrp for h in H])
H = {(x * h) % N for x in sbgrp for h in H}
return sorted(H)


Expand Down
2 changes: 1 addition & 1 deletion src/sage/modular/btquotients/btquotient.py
Original file line number Diff line number Diff line change
Expand Up @@ -3710,7 +3710,7 @@ def _compute_quotient(self, check=True):
'from expected.')

self._nontorsion_generators = nontorsion_generators
self._boundary = dict([(vv.rep, vv) for vv in vertex_list])
self._boundary = {vv.rep: vv for vv in vertex_list}
self._edge_list = edge_list
self._vertex_list = vertex_list
self._num_edges = num_edges
Expand Down
2 changes: 1 addition & 1 deletion src/sage/modular/dirichlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ def galois_orbit(self, sort=True):
P = self.parent()
z = self.element()
o = int(z.additive_order())
Auts = set([m % o for m in P._automorphisms()])
Auts = {m % o for m in P._automorphisms()}
v = [P.element_class(P, m * z, check=False) for m in Auts]
if sort:
v.sort()
Expand Down
2 changes: 1 addition & 1 deletion src/sage/modular/etaproducts.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def basis(self, reduce=True):
nf = (i < S.ncols() and S[i, i]) or 0 # ?
good_vects.append((vect * 24 / gcd(nf, 24)).list())
for v in good_vects:
v.append(-sum([r for r in v]))
v.append(-sum(list(v)))
dicts = []
for v in good_vects:
dicts.append({})
Expand Down
2 changes: 1 addition & 1 deletion src/sage/modular/hypergeometric_motive.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ def wild_primes(self):
[2, 3, 5]
"""
gamma = self.gamma_array()
return sorted(set([p for n in gamma.keys() for (p, _) in n.factor()]))
return sorted({p for n in gamma.keys() for (p, _) in n.factor()})

def zigzag(self, x, flip_beta=False):
r"""
Expand Down
8 changes: 4 additions & 4 deletions src/sage/modular/local_comp/smoothchar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ def quadratic_chars(self):
q = 1
ram = [self.from_dirichlet(chi) for chi in DirichletGroup(self.prime() ** q, QQ) if not chi.is_trivial()]
nr = self.character(0, [-1])
return sorted([nr] + [f for f in ram] + [f*nr for f in ram])
return sorted([nr] + list(ram) + [f*nr for f in ram])

class SmoothCharacterGroupQuadratic(SmoothCharacterGroupGeneric):
r"""
Expand Down Expand Up @@ -1793,12 +1793,12 @@ def exponents(self, c):
c = ZZ(c)
p = self.prime()
if c == 0:
return tuple([0])
return (0,)
elif c == 1:
return tuple([p - 1, 0])
return (p - 1, 0)
elif p > 3 or self._unif_sqr == 3 or c <= 3:
d = (c + 1) // 2
return tuple([p**(d - 1) * (p - 1), p**(c // 2), 0])
return (p**(d - 1) * (p - 1), p**(c // 2), 0)
else:
# awkward case, see above
return self.ideal(c).idealstar(2).gens_orders() + (0,)
Expand Down
4 changes: 2 additions & 2 deletions src/sage/modular/modform_hecketriangle/abstract_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ def aut_factor(self, gamma, t):
elif (gamma.is_reflection()):
return self._ep * (t/QQbar(I))**self._weight
else:
L = [v for v in gamma.word_S_T()[0]]
L = list(gamma.word_S_T()[0])
aut_f = ZZ(1)
while (len(L) > 0):
M = L.pop(-1)
Expand Down Expand Up @@ -1857,7 +1857,7 @@ def _quasi_form_matrix(self, min_exp=0, order_1=ZZ(0), incr_prec_by=0):
return A

B = A
A = A.delete_rows([r for r in range(column_size + (row_size-column_size)//2 - 1, row_size)])
A = A.delete_rows(list(range(column_size + (row_size-column_size)//2 - 1, row_size)))

# Next we simply delete row by row. Note that A is still modified here...
while (B.rank() == column_size):
Expand Down
4 changes: 2 additions & 2 deletions src/sage/modular/modform_hecketriangle/analytic_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def __init__(self):
linear_extension=True, facade=False)

L = self._base_poset.order_ideals_lattice()
H = L._hasse_diagram.relabel({i: x for i, x in enumerate(L._elements)},
H = L._hasse_diagram.relabel(dict(enumerate(L._elements)),
inplace=False)
FiniteLatticePoset.__init__(self, hasse_diagram=H,
elements=L._elements, category=L.category(),
Expand Down Expand Up @@ -485,7 +485,7 @@ def __call__(self, *args, **kwargs):
True
"""
if len(args) > 1:
return super().__call__([arg for arg in args], **kwargs)
return super().__call__(list(args), **kwargs)
else:
return super().__call__(*args, **kwargs)

Expand Down
4 changes: 2 additions & 2 deletions src/sage/modular/modform_hecketriangle/constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ def rational_type(f, n=ZZ(3), base_ring=ZZ):

num = R(f.numerator())
denom = R(f.denominator())
ep_num = set([ZZ.one() - 2*((sum([g.exponents()[0][m] for m in [1, 2]])) % 2) for g in dhom(num).monomials()])
ep_denom = set([ZZ.one() - 2*((sum([g.exponents()[0][m] for m in [1, 2]])) % 2) for g in dhom(denom).monomials()])
ep_num = {ZZ.one() - 2*((sum([g.exponents()[0][m] for m in [1, 2]])) % 2) for g in dhom(num).monomials()}
ep_denom = {ZZ.one() - 2*((sum([g.exponents()[0][m] for m in [1, 2]])) % 2) for g in dhom(denom).monomials()}

if (n == infinity):
hom_num = R( num.subs(x=x**4, y=y**2, z=z**2) )
Expand Down
2 changes: 1 addition & 1 deletion src/sage/modular/modform_hecketriangle/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def lseries(self, num_prec=None, max_imaginary_part=0, max_asymp_coeffs=40):

# num_coeffs = L.num_coeffs()
num_coeffs = L.num_coeffs(1.2)
coeff_vector = [coeff for coeff in self.q_expansion_vector(min_exp=0, max_exp=num_coeffs + 1, fix_d=True)]
coeff_vector = list(self.q_expansion_vector(min_exp=0, max_exp=num_coeffs + 1, fix_d=True))
pari_precode = "coeff = {};".format(coeff_vector)

L.init_coeffs(v="coeff[k+1]", pari_precode=pari_precode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ def root_extension_embedding(self, D, K=None):
else:
K = AlgebraicField()

L = [emb for emb in F.embeddings(K)]
L = list(F.embeddings(K))

# Three possibilities up to numerical artefacts:
# (1) emb = e, purely imaginary
Expand Down
4 changes: 2 additions & 2 deletions src/sage/modular/modform_hecketriangle/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def coordinate_vector(self, v):
ambient_space = self.graded_ring().reduce_type("holo", degree=(gens[0].weight(), gens[0].ep()))
subspace = ambient_space.subspace(gens)
vector_part_in_subspace = subspace(parts[r])
coord_part = [v for v in vector_part_in_subspace.coordinate_vector()]
coord_part = list(vector_part_in_subspace.coordinate_vector())
coord_vector += coord_part

return self._module(vector(self.coeff_ring(), coord_vector))
Expand Down Expand Up @@ -499,7 +499,7 @@ def coordinate_vector(self, v):
ambient_space = self.graded_ring().reduce_type("cusp", degree=(gens[0].weight(), gens[0].ep()))
subspace = ambient_space.subspace(gens)
vector_part_in_subspace = subspace(parts[r])
coord_part = [v for v in vector_part_in_subspace.coordinate_vector()]
coord_part = list(vector_part_in_subspace.coordinate_vector())
coord_vector += coord_part

return self._module(vector(self.coeff_ring(), coord_vector))
Expand Down
2 changes: 1 addition & 1 deletion src/sage/modular/modform_hecketriangle/subspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def __init__(self, ambient_space, basis, check):
Module.__init__(self, base=ambient_space.base_ring())

self._ambient_space = ambient_space
self._basis = [v for v in basis]
self._basis = list(basis)
# self(v) instead would somehow mess up the coercion model
self._gens = [self._element_constructor_(v) for v in basis]
self._module = ambient_space._module.submodule([ambient_space.coordinate_vector(v) for v in basis])
Expand Down
2 changes: 1 addition & 1 deletion src/sage/modular/modsym/ambient.py
Original file line number Diff line number Diff line change
Expand Up @@ -2260,7 +2260,7 @@ def integral_structure(self, algorithm='default'):
# The attribute _mod2term is set by self.compute_presentation().
# It is a list of pairs (n, c), such that the ith element of the list
# is equivalent to c times the n-th basis Manin symbol.
G = set([i for i, _ in self._mod2term])
G = {i for i, _ in self._mod2term}

# Now G is a set of integer i such that these integers gives
# indices of Manin symbols that together generate the integral
Expand Down
Loading

0 comments on commit 9b1e18f

Please sign in to comment.