diff --git a/src/sage/modular/btquotients/btquotient.py b/src/sage/modular/btquotients/btquotient.py index ff9701f3d33..ce37fcc86b5 100644 --- a/src/sage/modular/btquotients/btquotient.py +++ b/src/sage/modular/btquotients/btquotient.py @@ -57,7 +57,6 @@ from sage.modular.arithgroup.all import Gamma0 from sage.modular.arithgroup.congroup_gammaH import GammaH_constructor from sage.modular.dirichlet import DirichletGroup -lazy_import("sage.plot.colors", "rainbow") from sage.quadratic_forms.quadratic_form import QuadraticForm from sage.rings.finite_rings.finite_field_constructor import GF from sage.rings.finite_rings.integer_mod_ring import Zmod @@ -69,6 +68,7 @@ from sage.rings.rational_field import QQ from sage.structure.sage_object import SageObject from sage.structure.unique_representation import UniqueRepresentation +lazy_import("sage.plot.colors", "rainbow") class DoubleCosetReduction(SageObject): @@ -1435,7 +1435,8 @@ def __classcall__(cls, p, Nminus, Nplus=1, character=None, True """ return super().__classcall__(cls, p, Nminus, Nplus, - character, use_magma, seed, magma_session) + character, use_magma, + seed, magma_session) def __init__(self, p, Nminus, Nplus=1, character=None, use_magma=False, seed=None, magma_session=None): diff --git a/src/sage/modular/btquotients/pautomorphicform.py b/src/sage/modular/btquotients/pautomorphicform.py index a0d7e1294f9..b068af0cd15 100644 --- a/src/sage/modular/btquotients/pautomorphicform.py +++ b/src/sage/modular/btquotients/pautomorphicform.py @@ -1913,16 +1913,14 @@ def integrate(self, f, center=1, level=0, method='moments'): if method == 'riemann_sum': for e in E: ii += 1 - #print(ii,"/",len(E)) exp = ((R1([e[1, 1], e[1, 0]])) ** (self.parent()._U.weight()) * e.determinant() ** (-(self.parent()._U.weight()) / 2)) * f(R1([e[0, 1], e[0, 0]]) / R1([e[1, 1], e[1, 0]])) - #exp = R2([tmp[jj] for jj in range(self.parent()._k-1)]) + # exp = R2([tmp[jj] for jj in range(self.parent()._k-1)]) new = eval_dist_at_powseries(self.evaluate(e), exp.truncate(self.parent()._U.weight() + 1)) value += new elif method == 'moments': n = self.parent()._U.weight() for e in E: ii += 1 - #print(ii,"/",len(E)) a, b, c, d = e.list() delta = e.determinant() verbose('%s' % (R2([e[0, 1], e[0, 0]]) @@ -2272,7 +2270,7 @@ def __init__(self, domain, U, prec=None, t=None, R=None, self._R = Qp(domain._p, prec) else: self._R = R - #U is a CoefficientModuleSpace + # U is a CoefficientModuleSpace if isinstance(U, Integer): if t is None: if overconvergent: @@ -2281,11 +2279,11 @@ def __init__(self, domain, U, prec=None, t=None, R=None, t = 0 if overconvergent: self._U = OverconvergentDistributions(U - 2, base=self._R, - prec_cap=U - 1 + t, - act_on_left=True, - adjuster=_btquot_adjuster(), - dettwist=-ZZ((U - 2) // 2), - act_padic=True) + prec_cap=U - 1 + t, + act_on_left=True, + adjuster=_btquot_adjuster(), + dettwist=-ZZ((U - 2) // 2), + act_padic=True) else: self._U = Symk(U - 2, base=self._R, act_on_left=True, adjuster=_btquot_adjuster(), @@ -2485,13 +2483,14 @@ def _element_constructor_(self, data): F = [] Uold = data.parent()._U for ii in range(len(data._F)): - newtmp = data.parent()._Sigma0(E[ii].rep.inverse(), check=False) * Uold(data._F[ii],normalize=False) + newtmp = data.parent()._Sigma0(E[ii].rep.inverse(), check=False) * Uold(data._F[ii], + normalize=False) tmp.append(newtmp) F.append(newtmp) - A = data.parent()._Sigma0(Matrix(QQ,2,2,[0,1/self.prime(),1,0]),check=False) + A = data.parent()._Sigma0(Matrix(QQ, 2, 2, [0, ~self.prime(), 1, 0]), check=False) for ii in range(len(data._F)): F.append(-(A * tmp[ii])) - vals = self._make_invariant([self._U(o,normalize=False) for o in F]) + vals = self._make_invariant([self._U(o, normalize=False) for o in F]) return self.element_class(self, vals) if data == 0: return self.zero() @@ -2605,11 +2604,12 @@ def _make_invariant(self, F): m = M[ii] for v in Si: s += 1 - g = self._Sigma0(m.adjugate() * self._source.embed_quaternion(v[0], prec=self._prec).adjugate() * m,check=False) + g = self._Sigma0(m.adjugate() * self._source.embed_quaternion(v[0], prec=self._prec).adjugate() * m, + check=False) newFi += g * x newF.append((QQ(1) / s) * newFi) else: - newF.append(self._U(x,normalize=False)) + newF.append(self._U(x, normalize=False)) return newF def _apply_Up_operator(self, f, scale=False, original_moments=None): @@ -2650,7 +2650,8 @@ def _apply_Up_operator(self, f, scale=False, original_moments=None): for gg, edge_list in HeckeData: u = edge_list[jj] tprec = 2 * (prec_cap + u.power) + 1 - r = S0(self._p ** -u.power * (u.t(tprec) * gg).adjugate(),check=False) + r = S0(self._p ** -u.power * (u.t(tprec) * gg).adjugate(), + check=False) tmp += r * f._value[u.label] tmp *= factor for ii in range(self._n + 1): diff --git a/src/sage/modular/modsym/ambient.py b/src/sage/modular/modsym/ambient.py index 5e4edab0658..9c1876493f1 100644 --- a/src/sage/modular/modsym/ambient.py +++ b/src/sage/modular/modsym/ambient.py @@ -25,8 +25,6 @@ class ``ModularSymbolsAmbient``, derived from - ``ModularSymbolsAmbient_wtk_eps``, for modular symbols of general weight `k` and character `\epsilon`. - - EXAMPLES: We compute a space of modular symbols modulo 2. The dimension is @@ -81,7 +79,6 @@ class ``ModularSymbolsAmbient``, derived from from sage.misc.latex import latex from sage.misc.verbose import verbose from sage.modular.arithgroup.arithgroup_element import M2Z -from sage.modular.arithgroup.congroup_generic import is_CongruenceSubgroup from sage.modular.dirichlet import TrivialCharacter, is_DirichletCharacter from sage.modular.hecke.ambient_module import AmbientHeckeModule from sage.modular.cusps import Cusp @@ -166,7 +163,7 @@ def __init__(self, group, weight, sign, base_ring, """ weight = int(weight) if weight <= 1: - raise ValueError("Weight (=%s) Modular symbols of weight <= 1 not defined."%weight) + raise ValueError("Weight (=%s) Modular symbols of weight <= 1 not defined." % weight) if not arithgroup.is_CongruenceSubgroup(group): raise TypeError("group must be a congruence subgroup") @@ -178,8 +175,8 @@ def __init__(self, group, weight, sign, base_ring, character = TrivialCharacter(group.level(), base_ring) ModularSymbolsSpace.__init__(self, group, weight, - character, sign, base_ring, - category=category) + character, sign, base_ring, + category=category) if custom_init is not None: custom_init(self) @@ -192,9 +189,9 @@ def __init__(self, group, weight, sign, base_ring, rank = self.rank() if formula is not None: assert rank == formula, \ - "Computed dimension (=%s) of ambient space \"%s\" doesn't match dimension formula (=%s)!\n"%(rank, self, formula) + \ - "ModularSymbolsAmbient: group = %s, weight = %s, sign = %s, base_ring = %s, character = %s"%( - group, weight, sign, base_ring, character) + "Computed dimension (=%s) of ambient space \"%s\" doesn't match dimension formula (=%s)!\n" % (rank, self, formula) + \ + "ModularSymbolsAmbient: group = %s, weight = %s, sign = %s, base_ring = %s, character = %s" % ( + group, weight, sign, base_ring, character) AmbientHeckeModule.__init__(self, base_ring, rank, group.level(), weight, category=category) @@ -312,8 +309,8 @@ def compute_presentation(self): """ B, basis, mod = relation_matrix.compute_presentation( - self.manin_symbols(), self.sign(), - self.base_ring()) + self.manin_symbols(), self.sign(), + self.base_ring()) self._manin_generators = self.manin_symbols().manin_symbol_list() self._manin_basis = basis self._manin_gens_to_basis = B @@ -444,17 +441,12 @@ def _element_constructor_(self, x, computed_with_hecke=False): (1,35) sage: M([Cusp(1/2),Cusp(0)]) (1,35) - - """ if isinstance(x, FreeModuleElement): if x.degree() != self.dimension(): - raise TypeError("Incompatible degrees: x has degree %s\ - but modular symbols space has dimension %s"%( - x.degree(), self.dimension())) - #if x.parent().base_ring() != self.base_ring(): - # raise TypeError, "Vector x is over %s, but modular symbols space is over %s."%( - # x.parent().base_ring(), self.base_ring()) + raise TypeError("Incompatible degrees: x has degree " + f"{x.degree()} but modular symbols space has " + f"dimension {self.dimension()}") return self.element_class(self, x) elif isinstance(x, (ManinSymbol, element.ModularSymbolsElement)): @@ -463,14 +455,14 @@ def _element_constructor_(self, x, computed_with_hecke=False): elif isinstance(x, modular_symbols.ModularSymbol): return self(x.manin_symbol_rep()) - elif isinstance(x, (int, Integer)) and x==0: + elif isinstance(x, (int, Integer)) and x == 0: return self.element_class(self, self.free_module()(0)) elif isinstance(x, tuple): return self.manin_symbol(x) elif isinstance(x, FormalSum): - return sum([c*self(y) for c, y in x], self(0)) + return sum([c * self(y) for c, y in x], self(0)) elif isinstance(x, list): if len(x) == 3 and isinstance(x[0], MPolynomial): @@ -538,7 +530,6 @@ def _action_on_modular_symbols(self, g): [0 0 0 1] [0 1 0 0] [0 1 0 0] - """ if not isinstance(g, list): raise TypeError("g must be a list") @@ -571,19 +562,19 @@ def manin_symbol(self, x, check=True): """ if check: if len(x) == 2: - x = (0,x[0],x[1]) + x = (0, x[0], x[1]) if len(x) == 3: # Manin symbol of the form (i, u, v), which corresponds to [X^i*Y^(k-2-i), (u,v)]. - if x[0] < 0 or x[0] > self.weight()-2: + if x[0] < 0 or x[0] > self.weight() - 2: raise ValueError("The first entry of the tuple (=%s)\ - must be an integer between 0 and k-2 (=%s)."%( - x, self.weight()-2)) + must be an integer between 0 and k-2 (=%s)." % ( + x, self.weight() - 2)) else: - raise ValueError("x (=%s) must be of length 2 or 3"%x) + raise ValueError("x (=%s) must be of length 2 or 3" % x) # end check N = self.level() - x = (x[0], x[1]%N, x[2]%N) + x = (x[0], x[1] % N, x[2] % N) try: return self.__manin_symbol[x] except AttributeError: @@ -603,7 +594,7 @@ def _modular_symbol_0_to_alpha(self, alpha, i=0): - ``alpha`` (rational or Infinity) -- a cusp - - ``i`` (int, default 0) -- the degree of the symbol. + - ``i`` (int, default 0) -- the degree of the symbol OUTPUT: @@ -622,11 +613,11 @@ def _modular_symbol_0_to_alpha(self, alpha, i=0): 0 """ if alpha.is_infinity(): - return self.manin_symbol((i,0,1), check=False) + return self.manin_symbol((i, 0, 1), check=False) # v, c = arith.continued_fraction_list(alpha._rational_(), partial_convergents=True) cf = alpha._rational_().continued_fraction() v = list(cf) - c = [(cf.p(k),cf.q(k)) for k in range(len(cf))] + c = [(cf.p(k), cf.q(k)) for k in range(len(cf))] a = self(0) one = ZZ.one() two = ZZ(2) @@ -637,8 +628,8 @@ def _modular_symbol_0_to_alpha(self, alpha, i=0): # zero in this case. we do the first here, and the # second in the k=0 case below, so as to avoid code # duplication - a += self.manin_symbol((i,0,1), check=False) - for k in range(0,len(c)): + a += self.manin_symbol((i, 0, 1), check=False) + for k in range(len(c)): # matrix entries associated to this partial sum if k == 0: x = c[0][0] @@ -650,7 +641,7 @@ def _modular_symbol_0_to_alpha(self, alpha, i=0): y = c[k-1][0] z = c[k][1] w = c[k-1][1] - if k%2 == 0: + if k % 2 == 0: y = -y w = -w @@ -663,7 +654,7 @@ def _modular_symbol_0_to_alpha(self, alpha, i=0): # method 1: write out solution. this is currently # incorrect, because it ends up doing 0^0 in the sum, # so I'll fix it and do timings soon. -# for s in range(0,self.weight()-two+1): +# for s in range(self.weight()-two+1): # coeff = sum([ binomial(i,t)*binomial(self.weight()-two-i,s-t)* # x**t * y**(i-t) * z**(s-t) * # w**(self.weight()-two-i-s+t) for t in range(0,s) ]) @@ -678,10 +669,10 @@ def _modular_symbol_0_to_alpha(self, alpha, i=0): if (self.weight()-2-i == 0): p2 = R(one) poly = (p1**i) * (p2**(self.weight()-2-i)) - for s in range(0,self.weight()-1): # k-2+1 = k-1 - a += poly[s] * self.manin_symbol((s,z,w), check=False) + for s in range(self.weight()-1): # k-2+1 = k-1 + a += poly[s] * self.manin_symbol((s, z, w), check=False) else: - for k in range(1,len(c)): + for k in range(1, len(c)): u = c[k][1] v = c[k-1][1] if k % 2 == 0: @@ -752,17 +743,16 @@ def modular_symbol(self, x, check=True): sage: set_modsym_print_mode() # return to default. """ - if check: if len(x) == 2: - x = [0,x[0],x[1]] + x = [0, x[0], x[1]] elif len(x) == 3: if x[0] < 0 or x[0] > self.weight()-2: raise ValueError("The first entry of the tuple (=%s)\ - must be an integer between 0 and k-2 (=%s)."%( + must be an integer between 0 and k-2 (=%s)." % ( x, self.weight()-2)) else: - raise ValueError("x (=%s) must be of length 2 or 3"%x) + raise ValueError("x (=%s) must be of length 2 or 3" % x) i = Integer(x[0]) alpha = Cusp(x[1]) beta = Cusp(x[2]) @@ -804,15 +794,15 @@ def modular_symbol_sum(self, x, check=True): """ if check: if len(x) != 3: - raise ValueError("%s must have length 3"%x) + raise ValueError("%s must have length 3" % x) f = x[0] - R = self.base_ring()['X','Y'] + R = self.base_ring()['X', 'Y'] X = R.gen(0) try: f = R(f) except TypeError: raise ValueError("f must be coercible to a polynomial \ - over %s"%self.base_ring()) + over %s" % self.base_ring()) if (not f.is_homogeneous()) or (f.degree() != self.weight()-2): raise ValueError("f must be a homogeneous polynomial of degree k-2") alpha = Cusp(x[1]) @@ -1000,23 +990,23 @@ def _compute_hecke_matrix_prime(self, p, rows=None): j = 0 for i in B: for h in H: - entries = syms.apply(i,h) + entries = syms.apply(i, h) for k, x in entries: f, s = mod2term[k] if s: # W[j,f] = W[j,f] + s*K(x) W.add_to_entry(j, f, s * K(x)) j += 1 - tm = verbose("start matrix multiply",tm) + tm = verbose("start matrix multiply", tm) if hasattr(W, '_matrix_times_matrix_dense'): Tp = W._matrix_times_matrix_dense(R) - verbose("done matrix multiply and computing Hecke operator",tm) + verbose("done matrix multiply and computing Hecke operator", tm) else: Tp = W * R - tm = verbose("done matrix multiply",tm) + tm = verbose("done matrix multiply", tm) Tp = Tp.dense_matrix() - verbose("done making Hecke operator matrix dense",tm) - self._hecke_matrices[(p,rows)] = Tp + verbose("done making Hecke operator matrix dense", tm) + self._hecke_matrices[(p, rows)] = Tp return Tp def __heilbronn_operator(self, M, H, t=1): @@ -1072,7 +1062,7 @@ def __heilbronn_operator(self, M, H, t=1): hom = self.Hom(M) if self.dimension() == 0 or M.dimension() == 0: A = MS(0) - phi = hom(A, "Heilbronn operator(%s,%s)"%(H,t)) + phi = hom(A, "Heilbronn operator(%s,%s)" % (H, t)) return phi rows = [] @@ -1086,17 +1076,17 @@ def __heilbronn_operator(self, M, H, t=1): # Manin symbol [X^i*Y^(k-2-i), (u,v)] for h in H: # Apply h to the polynomial part - (a,b,c,d) = tuple(h) + a, b, c, d = tuple(h) # P gives the ordered coefficients of (a*X+b*Y)^i*(c*X+d*Y)^(j-i) - P = apply_to_monomial(i, k-2, a,b,c,d) + P = apply_to_monomial(i, k-2, a, b, c, d) # Apply h to the (u,v) part of the Manin symbol - (uu,vv) = (u*a+v*c, u*b+v*d) + (uu, vv) = (u*a+v*c, u*b+v*d) # For the generalized Heilbronn operator, we through away any # symbols for which the (u,v) part of the symbol doesn't have # both entries divisible by t. if t != 1: - if uu%t != 0 or vv%t != 0: + if uu % t != 0 or vv % t != 0: continue uu = uu//t vv = vv//t @@ -1108,13 +1098,13 @@ def __heilbronn_operator(self, M, H, t=1): # into the image space M and add that to z. # Note that we coerce in Manin symbols as tuples. for m in range(len(P)): - x = M((m,uu,vv)) + x = M((m, uu, vv)) z += x*P[m] rows.append(z.element()) A = MS(rows) - return hom(A, "Heilbronn operator(%s,%s)"%(H,t)) + return hom(A, "Heilbronn operator(%s,%s)" % (H, t)) def _repr_(self): r""" @@ -1126,8 +1116,8 @@ def _repr_(self): sage: m # indirect doctest Modular Symbols space of dimension 3 for Gamma_0(1) of weight 12 with sign 0 over Rational Field """ - return "Modular Symbols space of dimension %s and weight %s for %s with sign %s and character %s over %s"%( - self.dimension(), self.weight(), self.group(), self.sign(), self.character()._repr_short_(), self.base_ring()) + return "Modular Symbols space of dimension %s and weight %s for %s with sign %s and character %s over %s" % ( + self.dimension(), self.weight(), self.group(), self.sign(), self.character()._repr_short_(), self.base_ring()) def _latex_(self): r""" @@ -1143,12 +1133,11 @@ def _latex_(self): sage: m = ModularSymbols(chi) sage: latex(m) \mathrm{ModSym}_{2}(\Gamma_1(7),\left[\zeta_{6}\right];\Bold{Q}(\zeta_{6})) - """ - return "\\mathrm{ModSym}_{%s}(%s,%s;%s)"%(self.weight(), - latex(self.group()), - latex(list(self.character().values_on_gens())), - latex(self.base_ring())) + return "\\mathrm{ModSym}_{%s}(%s,%s;%s)" % (self.weight(), + latex(self.group()), + latex(list(self.character().values_on_gens())), + latex(self.base_ring())) def _matrix_of_operator_on_modular_symbols(self, codomain, R): r""" @@ -1333,9 +1322,9 @@ def boundary_map(self): E = [x.element() for x in I] zero = self.base_ring()(0) n = int(B.dimension()) - E = sum([ list(x) + [zero]*(n - len(x)) for x in E ], []) + E = sum([list(x) + [zero]*(n - len(x)) for x in E], []) - A = W( E ) + A = W(E) H = Hom(self, B) self.__boundary_map = H(A, "boundary map") return self.__boundary_map @@ -1414,7 +1403,7 @@ def cuspidal_submodule(self): if self.base_ring().characteristic() == 0: d = self._cuspidal_submodule_dimension_formula() if d is not None: - assert d == S.dimension(), "According to dimension formulas the cuspidal subspace of \"%s\" has dimension %s; however, computing it using modular symbols we obtained %s, so there is a bug (please report!)."%(self, d, S.dimension()) + assert d == S.dimension(), "According to dimension formulas the cuspidal subspace of \"%s\" has dimension %s; however, computing it using modular symbols we obtained %s, so there is a bug (please report!)." % (self, d, S.dimension()) self.__cuspidal_submodule = S return self.__cuspidal_submodule @@ -1521,7 +1510,7 @@ def _degeneracy_lowering_matrix(self, M, t): # Use Proposition 2.6.15 in Merel's 1585 paper (or Prop 15 in # electronic version of that paper). H = heilbronn.HeilbronnMerel(t) - return self.__heilbronn_operator(M,H,t).matrix() + return self.__heilbronn_operator(M, H, t).matrix() def rank(self): """ @@ -1602,7 +1591,7 @@ def element(self, x): if isinstance(x, ManinSymbol): if not x.parent().weight() == self.weight(): raise ArithmeticError("incompatible weights: Manin symbol\ - has weight %s, but modular symbols space has weight %s"%( + has weight %s, but modular symbols space has weight %s" % ( x.parent().weight(), self.weight())) t = self.manin_symbols().index(x.tuple()) if isinstance(t, tuple): @@ -1616,11 +1605,11 @@ def element(self, x): M = x.parent() if M.ambient_hecke_module() != self: # TODO -- sometimes do something more sophisticated here. - raise TypeError("Modular symbol (%s) does not lie in this space."%x) + raise TypeError("Modular symbol (%s) does not lie in this space." % x) return self(x.element()) else: - raise ValueError("Cannot create element of %s from %s."%(x,self)) + raise ValueError("Cannot create element of %s from %s." % (x, self)) def dual_star_involution_matrix(self): """ @@ -1773,7 +1762,7 @@ def factorization(self): # We only run through spaces of level a multiple of the conductor of the character, which # we compute below, or set to 1 in case of Gamma_H or Gamma_1 chi = self.character() - cond = 1 if chi is None else chi.conductor() + cond = 1 if chi is None else chi.conductor() # Now actually run through the divisor levels, taking only the ones with that are # a multiple of the conductor. for d in reversed(divisors(self.level())): @@ -1786,18 +1775,18 @@ def factorization(self): if self.sign() == 0: V = A.plus_submodule() V._is_simple = True - D.append((V,n)) + D.append((V, n)) if skip_minus: continue V = A.minus_submodule() V._is_simple = True - D.append((V,n)) + D.append((V, n)) else: A._is_simple = True - D.append((A,n)) + D.append((A, n)) # The eisenstein part for E in self.eisenstein_submodule().decomposition(anemic=True): - D.append((E,1)) + D.append((E, 1)) r = self.dimension() s = sum(A.rank() * mult for A, mult in D) @@ -1852,7 +1841,7 @@ def is_eisenstein(self): return self.__is_eisenstein except AttributeError: S = self.ambient_hecke_module().eisenstein_submodule() - self.__is_eisenstein = self.dimension()==S.dimension() + self.__is_eisenstein = self.dimension() == S.dimension() return self.__is_eisenstein def manin_symbols_basis(self): @@ -2096,7 +2085,7 @@ def _compute_diamond_matrix(self, d): sage: ModularSymbols(Gamma1(13), 5).diamond_bracket_operator(6).charpoly().factor() (x^2 + 1)^8 * (x^4 - x^2 + 1)^10 """ - return self.__heilbronn_operator(self, [[d,0, 0,d]], 1).matrix() * d**(2 - self.weight()) + return self.__heilbronn_operator(self, [[d, 0, 0, d]], 1).matrix() * d**(2 - self.weight()) def submodule(self, M, dual_free_module=None, check=True): r""" @@ -2146,7 +2135,7 @@ def submodule(self, M, dual_free_module=None, check=True): if check: if not is_FreeModule(M): V = self.free_module() - if not isinstance(M, (list,tuple)): + if not isinstance(M, (list, tuple)): M = M.gens() M = V.span([V(x.element()) for x in M]) return subspace.ModularSymbolsSubspace(self, M, dual_free_module=dual_free_module, check=check) @@ -2299,7 +2288,7 @@ def integral_structure(self, algorithm='default'): elif algorithm == 'padic': B = B.echelon_form(algorithm='padic', include_zero_rows=False) else: - raise ValueError("unknown algorithm '%s'"%algorithm) + raise ValueError("unknown algorithm '%s'" % algorithm) W = B.row_module() if d != 1: W = W.scale(1/d) @@ -2376,7 +2365,7 @@ class of cuspidal newforms in this ambient space. B = [A.dual_free_module().basis_matrix().transpose() for A in D] # Normalize the names strings. - names = ['%s%s'%(names,i) for i in range(len(B))] + names = ['%s%s' % (names, i) for i in range(len(B))] # Find an integer i such that the i-th columns of the basis for the # dual modules corresponding to the factors in D are all nonzero. @@ -2647,7 +2636,7 @@ def _repr_(self): Modular Symbols space of dimension 32 for Gamma_0(37) of weight 6 with sign 0 over Rational Field """ return ("Modular Symbols space of dimension %s for Gamma_0(%s) of weight %s with sign %s " + - "over %s") % (self.dimension(), self.level(),self.weight(), self.sign(), + "over %s") % (self.dimension(), self.level(), self.weight(), self.sign(), self.base_ring()) def _cuspidal_submodule_dimension_formula(self): @@ -2727,7 +2716,7 @@ def _degeneracy_raising_matrix_1(self, M): # We apply each matrix in H according to the above formula for h in H: hg = h*g - z += M((i, hg[1,0], hg[1,1])) + z += M((i, hg[1, 0], hg[1, 1])) rows.append(z.element()) A = MS(rows) @@ -2838,7 +2827,7 @@ def _hecke_images(self, i, v): # the kernel of the dual space corresponding to self. c = self.manin_generators()[self.manin_basis()[i]] N = self.level() - return heilbronn.hecke_images_gamma0_weight_k(c.u,c.v, c.i, N, self.weight(), + return heilbronn.hecke_images_gamma0_weight_k(c.u, c.v, c.i, N, self.weight(), v, self.manin_gens_to_basis()) @cached_method @@ -3011,8 +3000,8 @@ def _compute_hecke_matrix_prime(self, p, rows=None): tm = verbose("Matrix non-reduced", tm) for i in B: # The following step is where most of the time is spent. - c,d = P1[i] - v = H.apply(c,d, N) + c, d = P1[i] + v = H.apply(c, d, N) # v is now a list of pairs ((c,d),m), where m is the # number of times that (c,d) appears in the image of x @@ -3025,25 +3014,25 @@ def _compute_hecke_matrix_prime(self, p, rows=None): # s, and the image of x under T_p is the product # of s with the matrix R defined above. for z, m in v: - k = P1.index_of_normalized_pair(z[0],z[1]) + k = P1.index_of_normalized_pair(z[0], z[1]) if k != -1: f, s = mod2term[k] if s != 0: - W[j,f] = W[j,f] + s*m + W[j, f] = W[j, f] + s*m j += 1 - tm = verbose("done making non-reduced matrix",tm) - verbose("start matrix-matrix (%s x %s) times (%s x %s) multiply to get Tp"%(W.nrows(), W.ncols(), - R.nrows(), R.ncols())) + tm = verbose("done making non-reduced matrix", tm) + verbose("start matrix-matrix (%s x %s) times (%s x %s) multiply to get Tp" % (W.nrows(), W.ncols(), + R.nrows(), R.ncols())) if hasattr(W, '_matrix_times_matrix_dense'): Tp = W._matrix_times_matrix_dense(R) - verbose("done matrix multiply and computing Hecke operator",tm) + verbose("done matrix multiply and computing Hecke operator", tm) else: Tp = W * R - tm = verbose("done multiplying",tm) + tm = verbose("done multiplying", tm) Tp = Tp.dense_matrix() verbose("done making Hecke operator dense", tm) if rows is None: - self._hecke_matrices[(p,rows)] = Tp + self._hecke_matrices[(p, rows)] = Tp return Tp def boundary_space(self): @@ -3091,7 +3080,8 @@ def _hecke_image_of_ith_basis_vector(self, n, i): """ c = self.manin_generators()[self.manin_basis()[i]] N = self.level() - I = heilbronn.hecke_images_gamma0_weight2(c.u,c.v,N,[n], self.manin_gens_to_basis()) + I = heilbronn.hecke_images_gamma0_weight2(c.u, c.v, N, [n], + self.manin_gens_to_basis()) return self(I[0]) def _hecke_images(self, i, v): @@ -3131,7 +3121,8 @@ def _hecke_images(self, i, v): # the kernel of the dual space corresponding to self. c = self.manin_generators()[self.manin_basis()[i]] N = self.level() - return heilbronn.hecke_images_gamma0_weight2(c.u,c.v,N, v, self.manin_gens_to_basis()) + return heilbronn.hecke_images_gamma0_weight2(c.u, c.v, N, v, + self.manin_gens_to_basis()) class ModularSymbolsAmbient_wtk_g1(ModularSymbolsAmbient): @@ -3333,7 +3324,7 @@ def _degeneracy_raising_matrix_1(self, M): # We apply each matrix in H according to the above formula for h in H: hg = h*g - z += M((i, hg[1,0], hg[1,1])) + z += M((i, hg[1, 0], hg[1, 1])) rows.append(z.element()) A = MS(rows) @@ -3737,8 +3728,10 @@ def _degeneracy_raising_matrix_1(self, M): syms = self.manin_symbols() G = MatrixSpace(ZZ, 2) H = [G(h) for h in H] - eps = self.character() # note: in my thesis I twisted by eps^(-1), which is definitely a mistake - # since twisting by eps gives the right answer and by eps^(-1) does not. + eps = self.character() + # note: in my thesis I twisted by eps^(-1), which is definitely a mistake + # since twisting by eps gives the right answer and by eps^(-1) does not. + for n in B: z = M(0) s = syms.manin_symbol(n) @@ -3746,8 +3739,8 @@ def _degeneracy_raising_matrix_1(self, M): i = s.i # We apply each matrix in H according to the above formula for h in H: - hg = h*g - z += eps(h[0,0])*M((i, hg[1,0], hg[1,1])) + hg = h * g + z += eps(h[0, 0]) * M((i, hg[1, 0], hg[1, 1])) rows.append(z.element()) A = MS(rows) return A @@ -3833,7 +3826,7 @@ def modular_symbols_of_level(self, N): elif N % self.level() == 0: eps = self.character().extend(N) else: - raise ValueError("The level N (=%s) must be a divisor or multiple of the modulus of the character (=%s)"%(N, self.level())) + raise ValueError("The level N (=%s) must be a divisor or multiple of the modulus of the character (=%s)" % (N, self.level())) return modsym.ModularSymbols(eps, self.weight(), self.sign(), self.base_ring()) def modular_symbols_of_sign(self, sign): @@ -3923,16 +3916,14 @@ def _hecke_images(self, i, v): [ 0 1 1 -1 -1 0 -1 1 1 0 1 2 0 -2 2] """ if self.weight() != 2: - raise NotImplementedError("hecke images only implemented when the weight is 2") + raise NotImplementedError("Hecke images only implemented when the weight is 2") chi = self.character() # Find basis vector for ambient space such that it is not in # the kernel of the dual space corresponding to self. c = self.manin_generators()[self.manin_basis()[i]] N = self.level() if chi.order() > 2: - return heilbronn.hecke_images_nonquad_character_weight2(c.u,c.v,N, - v, chi, self.manin_gens_to_basis()) - else: - return heilbronn.hecke_images_quad_character_weight2(c.u,c.v,N, - v, chi, self.manin_gens_to_basis()) - raise NotImplementedError + return heilbronn.hecke_images_nonquad_character_weight2(c.u, c.v, N, + v, chi, self.manin_gens_to_basis()) + return heilbronn.hecke_images_quad_character_weight2(c.u, c.v, N, + v, chi, self.manin_gens_to_basis()) diff --git a/src/sage/modular/modsym/boundary.py b/src/sage/modular/modsym/boundary.py index f29c363cf8b..81f2dcedb3e 100644 --- a/src/sage/modular/modsym/boundary.py +++ b/src/sage/modular/modsym/boundary.py @@ -237,7 +237,7 @@ def _rmul_(self, other): """ x = {} for i, c in self.__x.items(): - x[i] = c*other + x[i] = c * other return BoundarySpaceElement(self.parent(), x) def _lmul_(self, other): @@ -258,7 +258,7 @@ def _lmul_(self, other): """ x = {} for i, c in self.__x.items(): - x[i] = other*c + x[i] = other * c return BoundarySpaceElement(self.parent(), x) def __neg__(self): @@ -324,8 +324,8 @@ def __init__(self, if character is None and arithgroup.is_Gamma0(group): character = dirichlet.TrivialCharacter(group.level(), base_ring) (self.__group, self.__weight, self.__character, - self.__sign, self.__base_ring) = (group, weight, - character, sign, base_ring) + self.__sign, self.__base_ring) = (group, weight, + character, sign, base_ring) self._known_gens = [] self._zero_cusps = [] hecke.HeckeModule_generic.__init__(self, base_ring, group.level()) @@ -443,7 +443,7 @@ def gen(self, i=0): """ if i >= len(self._known_gens) or i < 0: raise ValueError("only %s generators known for %s" % (len(self._known_gens), self)) - return BoundarySpaceElement(self, {i:1}) + return BoundarySpaceElement(self, {i: 1}) def free_module(self): """ @@ -558,7 +558,7 @@ def __call__(self, x): if not isinstance(M, ModularSymbolsAmbient): raise TypeError("x (=%s) must be an element of a space of modular symbols of type ModularSymbolsAmbient" % x) if M.level() != self.level(): - raise TypeError("x (=%s) must have level %s but has level %s"%( + raise TypeError("x (=%s) must have level %s but has level %s" % ( x, self.level(), M.level())) S = x.manin_symbol_rep() if len(S) == 0: @@ -697,7 +697,7 @@ def _coerce_cusp(self, c): if i != -1: if i == -2: return self(0) - return BoundarySpaceElement(self, {i:1}) + return BoundarySpaceElement(self, {i: 1}) # see if we've already found -c sign = self.sign() @@ -707,7 +707,7 @@ def _coerce_cusp(self, c): if i2 == -2: return self(0) else: - return BoundarySpaceElement(self, {i2:sign}) + return BoundarySpaceElement(self, {i2: sign}) # found a new cusp class g = self._known_gens @@ -743,7 +743,7 @@ def _coerce_cusp(self, c): del self._known_gens[-1] return self(0) - return BoundarySpaceElement(self, {(len(g)-1):1}) + return BoundarySpaceElement(self, {(len(g) - 1): 1}) def _is_equiv(self, c1, c2): """ @@ -904,7 +904,7 @@ def _coerce_cusp(self, c): if i == -2: return self(0) else: - return BoundarySpaceElement(self, {i : eps**k}) + return BoundarySpaceElement(self, {i: eps**k}) if sign != 0: i2, eps = self._cusp_index(-c) @@ -912,7 +912,7 @@ def _coerce_cusp(self, c): if i2 == -2: return self(0) else: - return BoundarySpaceElement(self, {i2:sign*(eps**k)}) + return BoundarySpaceElement(self, {i2: sign * (eps**k)}) # found a new cusp class g = self._known_gens @@ -922,7 +922,7 @@ def _coerce_cusp(self, c): # this occurs if and only if N = 4 and c is equivalent to 1/2. if N == 4 and k % 2: - if self._is_equiv(c, (1,2))[0]: + if self._is_equiv(c, (1, 2))[0]: self._zero_cusps.append(c) del self._known_gens[-1] return self(0) @@ -946,10 +946,10 @@ def _coerce_cusp(self, c): # if sign: if (c.is_infinity() and sign != (-1)**self.weight()) or \ - (c.is_zero() and sign == -1): - self._zero_cusps.append(c) - del self._known_gens[-1] - return self(0) + (c.is_zero() and sign == -1): + self._zero_cusps.append(c) + del self._known_gens[-1] + return self(0) elif (not c.is_infinity() and not c.is_zero()): t, eps = self._is_equiv(c, -c) if t and ((eps == 1 and sign == -1) or @@ -958,7 +958,7 @@ def _coerce_cusp(self, c): del self._known_gens[-1] return self(0) - return BoundarySpaceElement(self, {(len(g)-1): 1}) + return BoundarySpaceElement(self, {(len(g) - 1): 1}) class BoundarySpace_wtk_gamma_h(BoundarySpace): @@ -1153,7 +1153,7 @@ def _coerce_cusp(self, c): if i == -2: return self(0) else: - return BoundarySpaceElement(self, {i : eps**k}) + return BoundarySpaceElement(self, {i: eps**k}) if sign != 0: i2, eps = self._cusp_index(-c) @@ -1161,7 +1161,7 @@ def _coerce_cusp(self, c): if i2 == -2: return self(0) else: - return BoundarySpaceElement(self, {i2:sign*(eps**k)}) + return BoundarySpaceElement(self, {i2: sign * (eps**k)}) # found a new cusp class g = self._known_gens @@ -1211,7 +1211,7 @@ def _coerce_cusp(self, c): del self._known_gens[-1] return self(0) - return BoundarySpaceElement(self, {(len(g)-1): 1}) + return BoundarySpaceElement(self, {(len(g) - 1): 1}) class BoundarySpace_wtk_eps(BoundarySpace): @@ -1392,7 +1392,7 @@ def _coerce_cusp(self, c): # Does cusp vanish because of stabiliser? s = arithgroup.Gamma0(self.level()).cusp_data(c)[0] - if self.__eps(s[1,1]) != 1: + if self.__eps(s[1, 1]) != 1: self._zero_cusps.append(c) del self._known_gens[-1] return self(0) @@ -1430,4 +1430,4 @@ def _coerce_cusp(self, c): del self._known_gens[-1] return self(0) - return BoundarySpaceElement(self, {(len(g)-1):1}) + return BoundarySpaceElement(self, {(len(g) - 1): 1}) diff --git a/src/sage/modular/modsym/element.py b/src/sage/modular/modsym/element.py index cc81faad50d..df08763459d 100644 --- a/src/sage/modular/modsym/element.py +++ b/src/sage/modular/modsym/element.py @@ -1,8 +1,7 @@ """ A single element of an ambient space of modular symbols """ - -#***************************************************************************** +# **************************************************************************** # Sage: Open Source Mathematical Software # # Copyright (C) 2005 William Stein @@ -16,9 +15,8 @@ # # The full text of the GPL is available at: # -# http://www.gnu.org/licenses/ -#***************************************************************************** - +# https://www.gnu.org/licenses/ +# **************************************************************************** import sage.modules.free_module_element from sage.misc.repr import repr_lincomb @@ -26,9 +24,11 @@ import sage.modular.hecke.all as hecke import sage.misc.latex as latex + _print_mode = "manin" -def is_ModularSymbolsElement(x): + +def is_ModularSymbolsElement(x) -> bool: r""" Return True if x is an element of a modular symbols space. @@ -80,6 +80,7 @@ def set_modsym_print_mode(mode="manin"): global _print_mode _print_mode = mode + class ModularSymbolsElement(hecke.HeckeModuleElement): """ An element of a space of modular symbols. @@ -117,7 +118,7 @@ def __init__(self, parent, x, check=True): if not isinstance(x, sage.modules.free_module_element.FreeModuleElement): raise TypeError("x must be a free module element.") if x.degree() != parent.degree(): - raise TypeError("x (of degree %s) must be of degree the same as the degree of the parent (of degree %s)."%(x.degree(), parent.degree())) + raise TypeError("x (of degree %s) must be of degree the same as the degree of the parent (of degree %s)." % (x.degree(), parent.degree())) hecke.HeckeModuleElement.__init__(self, parent, x) def _repr_(self): @@ -143,7 +144,7 @@ def _repr_(self): m = self.manin_symbol_rep() elif _print_mode == "modular": m = self.modular_symbol_rep() - return repr_lincomb([(t,c) for c,t in m]) + return repr_lincomb([(t, c) for c, t in m]) def _latex_(self): r""" @@ -204,7 +205,8 @@ def _rmul_(self, other): ... TypeError: unsupported operand parent(s) for *: 'Modular Symbols space of dimension 8 for Gamma_0(3) of weight 12 with sign 0 over Rational Field' and 'Ring of integers modulo 17' """ - return ModularSymbolsElement(self.parent(), self.element()*other, check=False) + return ModularSymbolsElement(self.parent(), self.element() * other, + check=False) def _lmul_(self, left): r""" @@ -222,7 +224,8 @@ def _lmul_(self, left): ... TypeError: unsupported operand parent(s) for *: 'Ring of integers modulo 17' and 'Modular Symbols space of dimension 8 for Gamma_0(3) of weight 12 with sign 0 over Rational Field' """ - return ModularSymbolsElement(self.parent(), left*self.element(), check=False) + return ModularSymbolsElement(self.parent(), left * self.element(), + check=False) def _neg_(self): r""" diff --git a/src/sage/modular/modsym/g1list.py b/src/sage/modular/modsym/g1list.py index 87e86e94814..4485a52814a 100644 --- a/src/sage/modular/modsym/g1list.py +++ b/src/sage/modular/modsym/g1list.py @@ -2,7 +2,7 @@ List of coset representatives for `\Gamma_1(N)` in `\SL_2(\ZZ)` """ -#***************************************************************************** +# **************************************************************************** # Sage: Open Source Mathematical Software # # Copyright (C) 2005 William Stein @@ -16,8 +16,8 @@ # # The full text of the GPL is available at: # -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# **************************************************************************** from sage.arith.misc import GCD from sage.structure.richcmp import richcmp_method, richcmp @@ -96,12 +96,13 @@ def __repr__(self): sage: L = sage.modular.modsym.g1list.G1list(3); L.__repr__() 'List of coset representatives for Gamma_1(3) in SL_2(Z)' """ - return "List of coset representatives for Gamma_1(%s) in SL_2(Z)"%self.__N + return f"List of coset representatives for Gamma_1({self.__N}) in SL_2(Z)" def list(self): r""" - Return a list of vectors representing the cosets. Do not change the - returned list! + Return a list of vectors representing the cosets. + + Do not change the returned list! EXAMPLES:: @@ -169,7 +170,8 @@ def __setstate__(self, state): # We don't really want this class, but we want to handle new # pickles without creating a new class self.__class__ = G1list - self.__dict__ = state # Default pickling is ``state = self.__dict__`` + self.__dict__ = state # Default pickling is ``state = self.__dict__`` + register_unpickle_override('sage.modular.modsym.g1list', 'G1list', _G1list_old_pickle) diff --git a/src/sage/modular/modsym/ghlist.py b/src/sage/modular/modsym/ghlist.py index 38cdc8ff2b4..bd15cc505b5 100644 --- a/src/sage/modular/modsym/ghlist.py +++ b/src/sage/modular/modsym/ghlist.py @@ -173,7 +173,8 @@ def __setstate__(self, state): # We don't really want this class, but we want to handle new # pickles without creating a new class self.__class__ = GHlist - self.__dict__ = state # Default pickling is ``state = self.__dict__`` + self.__dict__ = state # Default pickling is ``state = self.__dict__`` + register_unpickle_override('sage.modular.modsym.ghlist', 'GHlist', _GHlist_old_pickle) diff --git a/src/sage/modular/modsym/manin_symbol_list.py b/src/sage/modular/modsym/manin_symbol_list.py index 182a35ffe32..858fa4a9feb 100644 --- a/src/sage/modular/modsym/manin_symbol_list.py +++ b/src/sage/modular/modsym/manin_symbol_list.py @@ -133,7 +133,7 @@ def symbol_list(self): sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList sage: m = ManinSymbolList(6, P1List(11)) """ - return list(self._symbol_list) # This makes a shallow copy + return list(self._symbol_list) # This makes a shallow copy def __len__(self): """ @@ -162,11 +162,10 @@ def apply(self, j, X): Traceback (most recent call last): ... NotImplementedError: Only implemented in derived classes - """ raise NotImplementedError("Only implemented in derived classes") - def _apply_S_only_0pm1(self): + def _apply_S_only_0pm1(self) -> bool: """ Return True if the coefficient when applying the S relation is always 0, 1, or -1. This is useful for optimizing code in @@ -183,7 +182,7 @@ def _apply_S_only_0pm1(self): sage: ManinSymbolList_character(eps,2)._apply_S_only_0pm1() False """ - return False # derived classes could overload and put True + return False # derived classes could overload and put True def apply_S(self, j): """ @@ -498,11 +497,8 @@ def apply_S(self, j): (2, 1)] """ i, u, v = self._symbol_list[j] - k = self.index((self._weight-2-i, v, -u)) - if i%2 == 0: - return k, 1 - else: - return k, -1 + k = self.index((self._weight - 2 - i, v, -u)) + return k, -1 if i % 2 else 1 def _apply_S_only_0pm1(self): """ @@ -552,7 +548,7 @@ def apply_I(self, j): """ i, u, v = self._symbol_list[j] k = self.index((i, -u, v)) - if i%2 == 0: + if i % 2 == 0: return k, 1 else: return k, -1 @@ -761,10 +757,9 @@ def __repr__(self): sage: M11 = ManinSymbolList_gamma0(11,2) sage: str(M11) 'Manin Symbol List of weight 2 for Gamma0(11)' - """ - return "Manin Symbol List of weight %s for Gamma0(%s)"%( - self.weight(), self.level()) + return "Manin Symbol List of weight %s for Gamma0(%s)" % ( + self.weight(), self.level()) class ManinSymbolList_gamma1(ManinSymbolList_group): @@ -820,8 +815,8 @@ def __repr__(self): sage: str(M11) 'Manin Symbol List of weight 4 for Gamma1(11)' """ - return "Manin Symbol List of weight %s for Gamma1(%s)"%( - self.weight(), self.level()) + return "Manin Symbol List of weight %s for Gamma1(%s)" % ( + self.weight(), self.level()) class ManinSymbolList_gamma_h(ManinSymbolList_group): @@ -890,8 +885,8 @@ def __repr__(self): sage: ModularSymbols(GammaH(12, [5]), 2).manin_symbols().__repr__() 'Manin Symbol List of weight 2 for Congruence Subgroup Gamma_H(12) with H generated by [5]' """ - return "Manin Symbol List of weight %s for %s"%( - self.weight(), self.group()) + return "Manin Symbol List of weight %s for %s" % ( + self.weight(), self.group()) class ManinSymbolList_character(ManinSymbolList): @@ -967,8 +962,8 @@ def __repr__(self): sage: str(m) # indirect doctest 'Manin Symbol List of weight 2 for Gamma1(4) with character [-1]' """ - return "Manin Symbol List of weight %s for Gamma1(%s) with character %s"%( - self.weight(), self.level(), self.character()._repr_short_()) + return "Manin Symbol List of weight %s for Gamma1(%s) with character %s" % ( + self.weight(), self.level(), self.character()._repr_short_()) def level(self): """ @@ -1028,7 +1023,7 @@ def apply(self, j, m): return [] r = len(self.__P1) return [(m + r*k, s*P[k]) for k in range(self._weight-2+1) - if P[k] != 0] + if P[k] != 0] def apply_S(self, j): """ @@ -1056,8 +1051,8 @@ def apply_S(self, j): [(1, 1), (0, -1), (4, 1), (5, -1), (2, -1), (3, 1)] """ i, u, v = self._symbol_list[j] - k, s = self.index((self._weight-2-i, v, -u)) - if i%2 == 0: + k, s = self.index((self._weight - 2 - i, v, -u)) + if i % 2 == 0: return k, s else: return k, -s @@ -1106,7 +1101,7 @@ def apply_I(self, j): """ i, u, v = self._symbol_list[j] k, s = self.index((i, -u, v)) - if i%2 == 0: + if i % 2 == 0: return k, s else: return k, -s diff --git a/src/sage/modular/modsym/modsym.py b/src/sage/modular/modsym/modsym.py index 0a87eece1d7..d6aea48b548 100644 --- a/src/sage/modular/modsym/modsym.py +++ b/src/sage/modular/modsym/modsym.py @@ -71,7 +71,7 @@ Modular Symbols space of dimension 20460 and level 184137, weight 2, character [2, 2], sign 1, over Finite Field of size 3 """ -#***************************************************************************** +# **************************************************************************** # Sage: Open Source Mathematical Software # # Copyright (C) 2005 William Stein @@ -85,8 +85,8 @@ # # The full text of the GPL is available at: # -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# **************************************************************************** import weakref @@ -115,7 +115,7 @@ def canonical_parameters(group, weight, sign, base_ring): """ sign = rings.Integer(sign) - if not (sign in [-1,0,1]): + if sign not in [-1, 0, 1]: raise ValueError("sign must be -1, 0, or 1") weight = rings.Integer(weight) @@ -137,15 +137,17 @@ def canonical_parameters(group, weight, sign, base_ring): base_ring = rational_field.RationalField() if not isinstance(base_ring, rings.CommutativeRing): - raise TypeError("base_ring (=%s) must be a commutative ring"%base_ring) + raise TypeError(f"base_ring (={base_ring}) must be a commutative ring") if not base_ring.is_field(): - raise TypeError("(currently) base_ring (=%s) must be a field"%base_ring) + raise TypeError(f"(currently) base_ring (={base_ring}) must be a field") return group, weight, sign, base_ring + _cache = {} + def ModularSymbols_clear_cache(): """ Clear the global cache of modular symbols spaces. @@ -348,16 +350,16 @@ def ModularSymbols(group=1, if M is not None: return M - (group, weight, sign, base_ring) = key + group, weight, sign, base_ring = key M = None if arithgroup.is_Gamma0(group): - if weight == 2: - M = ambient.ModularSymbolsAmbient_wt2_g0( - group.level(),sign, base_ring, custom_init=custom_init) - else: - M = ambient.ModularSymbolsAmbient_wtk_g0( - group.level(), weight, sign, base_ring, custom_init=custom_init) + if weight == 2: + M = ambient.ModularSymbolsAmbient_wt2_g0( + group.level(), sign, base_ring, custom_init=custom_init) + else: + M = ambient.ModularSymbolsAmbient_wtk_g0( + group.level(), weight, sign, base_ring, custom_init=custom_init) elif arithgroup.is_Gamma1(group): diff --git a/src/sage/modular/modsym/modular_symbols.py b/src/sage/modular/modsym/modular_symbols.py index 504af3a4096..e76694d54e2 100644 --- a/src/sage/modular/modsym/modular_symbols.py +++ b/src/sage/modular/modsym/modular_symbols.py @@ -95,7 +95,7 @@ def _repr_(self): polypart = '' else: polypart = str(self.polynomial_part()) + '*' - return "%s{%s, %s}"%(polypart, self.__alpha, self.__beta) + return "%s{%s, %s}" % (polypart, self.__alpha, self.__beta) def __getitem__(self, j): r""" @@ -132,8 +132,9 @@ def _latex_(self): polypart = '' else: polypart = latex(self.polynomial_part()) - return "%s\\left\\{%s, %s\\right\\}"%(polypart, - latex(self.__alpha), latex(self.__beta)) + return "%s\\left\\{%s, %s\\right\\}" % (polypart, + latex(self.__alpha), + latex(self.__beta)) def __richcmp__(self, other, op): """ diff --git a/src/sage/modular/modsym/p1list_nf.py b/src/sage/modular/modsym/p1list_nf.py index 493e0e827b5..69986c1b8c8 100644 --- a/src/sage/modular/modsym/p1list_nf.py +++ b/src/sage/modular/modsym/p1list_nf.py @@ -76,19 +76,20 @@ sage: P.lift_to_sl2_Ok(3) [0, -1, 1, -2*a] """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2009, Maite Aranes # # Distributed under the terms of the GNU General Public License (GPL) -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# **************************************************************************** from sage.structure.richcmp import richcmp_method, richcmp from sage.structure.sage_object import SageObject from sage.misc.search import search -_level_cache = {} # The info stored here is used in the normalization of MSymbols. +_level_cache = {} # The info stored here is used in the normalization of MSymbols. + def P1NFList_clear_level_cache(): """ @@ -201,16 +202,16 @@ def __init__(self, N, c, d=None, check=True): c1 = R(c[0]) d1 = R(c[1]) except (ValueError, TypeError): - raise TypeError("Unable to create a Manin symbol from %s"%c) + raise TypeError("Unable to create a Manin symbol from %s" % c) else: try: c1 = R(c) d1 = R(d) except (ValueError, TypeError): - raise TypeError("Unable to create a Manin symbol from (%s, %s)"%(c, d)) + raise TypeError("Unable to create a Manin symbol from (%s, %s)" % (c, d)) if check: if (c1.is_zero() and d1.is_zero()) or not N.is_coprime(k.ideal(c1, d1)): - raise ValueError("(%s, %s) is not an element of P1(R/N)."%(c1, d1)) + raise ValueError("(%s, %s) is not an element of P1(R/N)." % (c1, d1)) self.__c, self.__d = (c1, d1) def __repr__(self): @@ -225,7 +226,7 @@ def __repr__(self): sage: MSymbol(N, 3, a) M-symbol (3: a) of level Fractional ideal (3, 1/2*a - 1/2) """ - return "M-symbol (%s: %s) of level %s"%(self.__c, self.__d, self.__N) + return "M-symbol (%s: %s) of level %s" % (self.__c, self.__d, self.__N) def _latex_(self): r""" @@ -468,9 +469,9 @@ def normalize(self, with_scalar=False): return MSymbol(N, c, d) -#************************************************************************** -#* P1NFList class * -#************************************************************************** +# ************************************************************************ +# P1NFList class * +# ************************************************************************ @richcmp_method @@ -588,9 +589,8 @@ def __repr__(self): sage: N = k.ideal(5, a+1) sage: P = P1NFList(N); P The projective line over the ring of integers modulo the Fractional ideal (5, a + 1) - """ - return "The projective line over the ring of integers modulo the %s"%self.__N + return "The projective line over the ring of integers modulo the %s" % self.__N def list(self): """ @@ -659,8 +659,8 @@ def normalize(self, c, d=None, with_scalar=False): """ if d is None: try: - c = MSymbol(self.__N, c) # check that c is an MSymbol - except ValueError: # catch special case of wrong level + c = MSymbol(self.__N, c) # check that c is an MSymbol + except ValueError: # catch special case of wrong level raise ValueError("The MSymbol is of a different level") return c.normalize(with_scalar) return MSymbol(self.N(), c, d).normalize(with_scalar) @@ -744,8 +744,8 @@ def index(self, c, d=None, with_scalar=False): """ if d is None: try: - c = MSymbol(self.__N, c) # check that c is an MSymbol - except ValueError: # catch special case of wrong level + c = MSymbol(self.__N, c) # check that c is an MSymbol + except ValueError: # catch special case of wrong level raise ValueError("The MSymbol is of a different level") if with_scalar: u, norm_c = c.normalize(with_scalar=True) @@ -996,13 +996,13 @@ def apply_J_epsilon(self, i, e1, e2=1): return j -#************************************************************************** +# ************************************************************************* # Global functions: # - p1NFList --compute list of M-symbols # - lift_to_sl2_Ok # - make_coprime -- need it for ``lift_to_sl2_Ok`` # - psi -- useful to check cardinality of the M-symbols list -#************************************************************************** +# ************************************************************************* def p1NFlist(N): """ @@ -1024,14 +1024,14 @@ def p1NFlist(N): """ k = N.number_field() - L = [MSymbol(N, k(0),k(1), check=False)] - #N.residues() = iterator through the residues mod N - L = L+[MSymbol(N, k(1), r, check=False) for r in N.residues()] + L = [MSymbol(N, k(0), k(1), check=False)] + # N.residues() = iterator through the residues mod N + L = L + [MSymbol(N, k(1), r, check=False) for r in N.residues()] from sage.arith.misc import divisors for D in divisors(N): - if not D.is_trivial() and D!=N: - #we find Dp ideal coprime to N, in inverse class to D + if not D.is_trivial() and D != N: + # we find Dp ideal coprime to N, in inverse class to D if D.is_principal(): Dp = k.ideal(1) c = D.gens_reduced()[0] @@ -1041,7 +1041,7 @@ def p1NFlist(N): while not Dp.is_coprime(N) or not (Dp*D).is_principal(): Dp = next(it) c = (D*Dp).gens_reduced()[0] - #now we find all the (c,d)'s which have associated divisor D + # now we find all the (c,d)'s which have associated divisor D I = D + N/D for d in (N/D).residues(): if I.is_coprime(d): @@ -1051,6 +1051,7 @@ def p1NFlist(N): L.append(MSymbol(N, c, d1, check=False).normalize()) return L + def lift_to_sl2_Ok(N, c, d): """ Lift a pair (c, d) to an element of `SL(2, O_k)`, where `O_k` is the ring @@ -1123,17 +1124,17 @@ def lift_to_sl2_Ok(N, c, d): ValueError: <0> + <7> and the Fractional ideal (7, a) are not coprime. """ k = N.number_field() - #check the input + # check the input if c.is_zero() and d.is_zero(): - raise ValueError("Cannot lift (%s, %s) to an element of Sl2(Ok)."%(c, d)) + raise ValueError("Cannot lift (%s, %s) to an element of Sl2(Ok)." % (c, d)) if not N.is_coprime(k.ideal(c, d)): - raise ValueError("<%s> + <%s> and the %s are not coprime."%(c, d, N)) - #a few special cases + raise ValueError("<%s> + <%s> and the %s are not coprime." % (c, d, N)) + # a few special cases if c - 1 in N: return [k(0), k(-1), 1, d] if d - 1 in N: return [k(1), k(0), c, 1] - if c.is_zero(): # and d!=1, so won't happen for normalized M-symbols (c: d) + if c.is_zero(): # and d!=1, so won't happen for normalized M-symbols (c: d) it = k.primes_of_degree_one_iter() q = k.ideal(1) while not (q.is_coprime(d) and (q*N).is_principal()): @@ -1141,7 +1142,7 @@ def lift_to_sl2_Ok(N, c, d): m = (q*N).gens_reduced()[0] B = k.ideal(m).element_1_mod(k.ideal(d)) return [(1-B)/d, -B/m, m, d] - if d.is_zero(): # and c!=1, so won't happen for normalized M-symbols (c: d) + if d.is_zero(): # and c!=1, so won't happen for normalized M-symbols (c: d) it = k.primes_of_degree_one_iter() q = k.ideal(1) while not (q.is_coprime(c) and (q*N).is_principal()): diff --git a/src/sage/modular/modsym/subspace.py b/src/sage/modular/modsym/subspace.py index 3c496534955..d1d2a393127 100644 --- a/src/sage/modular/modsym/subspace.py +++ b/src/sage/modular/modsym/subspace.py @@ -81,8 +81,8 @@ def _repr_(self): sage: ModularSymbols(24,4).cuspidal_subspace()._repr_() 'Modular Symbols subspace of dimension 16 of Modular Symbols space of dimension 24 for Gamma_0(24) of weight 4 with sign 0 over Rational Field' """ - return "Modular Symbols subspace of dimension %s of %s"%( - self.rank(), self.ambient_module()) + return "Modular Symbols subspace of dimension %s of %s" % ( + self.rank(), self.ambient_module()) ################################ # Public functions @@ -279,17 +279,17 @@ def factorization(self): if A.is_cuspidal(): V = A.plus_submodule() V._is_simple = True - D.append((V,1)) + D.append((V, 1)) V = A.minus_submodule() V._is_simple = True - D.append((V,1)) + D.append((V, 1)) else: A._is_simple = True D.append((A, 1)) else: for A in N: A._is_simple = True - D.append((A,1)) + D.append((A, 1)) else: # Compute factorization of the ambient space, then compute multiplicity # of each factor in this space. @@ -297,19 +297,19 @@ def factorization(self): for S in self.ambient_hecke_module().simple_factors(): n = self.multiplicity(S, check_simple=False) if n > 0: - D.append((S,n)) + D.append((S, n)) # endif # check that dimensions add up r = self.dimension() - s = sum([A.rank()*mult for A, mult in D]) + s = sum([A.rank() * mult for A, mult in D]) if r != s: - raise NotImplementedError("modular symbols factorization not fully implemented yet -- self has dimension %s, but sum of dimensions of factors is %s"%( - r, s)) + raise NotImplementedError("modular symbols factorization not fully implemented yet " + "-- self has dimension %s, but sum of dimensions of factors is %s" % (r, s)) self._factorization = sage.structure.factorization.Factorization(D, cr=True) return self._factorization - def is_cuspidal(self): + def is_cuspidal(self) -> bool: """ Return True if self is cuspidal. diff --git a/src/sage/modular/modsym/tests.py b/src/sage/modular/modsym/tests.py index 48a45be55ed..737bb66ba62 100644 --- a/src/sage/modular/modsym/tests.py +++ b/src/sage/modular/modsym/tests.py @@ -111,7 +111,7 @@ def _modular_symbols_space(self): elif self.onlychar: which = 2 else: - which = random.randrange(0,3) + which = random.randrange(0, 3) if which == 0: print("gamma0") M = self._modular_symbols_space_gamma0() @@ -251,9 +251,9 @@ def test(self, name, seconds=0): total = cputime() n = 1 while seconds == 0 or cputime(total) < seconds: - s = "** test_dimension: number %s"%n + s = "** test_dimension: number %s" % n if seconds > 0: - s += " (will stop after about %s seconds)"%seconds + s += " (will stop after about %s seconds)" % seconds t = cputime() self._do(name) print("\ttime=%s\telapsed=%s" % (cputime(t), cputime(total))) @@ -292,7 +292,7 @@ def test_csnew_dimension(self): d = V.dimension() d2 = M._cuspidal_new_submodule_dimension_formula() assert d == d2, \ - "Test failed for M=\"%s\", where computed dimension is %s but formula dimension is %s."%(M, d, d2) + "Test failed for M=\"%s\", where computed dimension is %s but formula dimension is %s." % (M, d, d2) def test_csns_nscs(self): """