Skip to content

Commit 74c3977

Browse files
committed
some cleanup in overconvergent and quaternion
1 parent 439065e commit 74c3977

File tree

2 files changed

+61
-73
lines changed

2 files changed

+61
-73
lines changed

src/sage/algebras/quatalg/quaternion_algebra.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def ngens(self):
332332
sage: Q.ngens()
333333
3
334334
sage: Q.gens()
335-
[i, j, k]
335+
(i, j, k)
336336
"""
337337
return 3
338338

@@ -681,7 +681,7 @@ def __init__(self, base_ring, a, b, names='i,j,k'):
681681
else:
682682
self.Element = QuaternionAlgebraElement_generic
683683
self._populate_coercion_lists_(coerce_list=[base_ring])
684-
self._gens = [self([0, 1, 0, 0]), self([0, 0, 1, 0]), self([0, 0, 0, 1])]
684+
self._gens = (self([0, 1, 0, 0]), self([0, 0, 1, 0]), self([0, 0, 0, 1]))
685685

686686
@cached_method
687687
def maximal_order(self, take_shortcuts=True):
@@ -808,7 +808,7 @@ def maximal_order(self, take_shortcuts=True):
808808

809809
# The following code should always work (over QQ)
810810
# Start with <1,i,j,k>
811-
R = self.quaternion_order([1] + self.gens())
811+
R = self.quaternion_order((1,) + self.gens())
812812
d_R = R.discriminant()
813813

814814
e_new_gens = []
@@ -978,7 +978,7 @@ def gen(self, i=0):
978978
sage: Q.gen(2)
979979
kk
980980
sage: Q.gens()
981-
[ii, jj, kk]
981+
(ii, jj, kk)
982982
"""
983983
return self._gens[i]
984984

@@ -1496,7 +1496,7 @@ def one(self):
14961496

14971497
def gens(self):
14981498
"""
1499-
Return generators for self.
1499+
Return generators for ``self``.
15001500
15011501
EXAMPLES::
15021502

src/sage/modular/overconvergent/genus0.py

Lines changed: 56 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,11 @@
194194
from sage.rings.rational_field import QQ
195195
from sage.structure.element import Vector, ModuleElement
196196
from sage.structure.richcmp import richcmp
197+
from .weightspace import WeightSpace_constructor as WeightSpace, WeightCharacter
197198

198199
lazy_import('sage.modular.modform.j_invariant', 'j_invariant_qexp')
199200
lazy_import('sage.rings.padics.factory', 'Qp', as_='pAdicField')
200201

201-
from .weightspace import WeightSpace_constructor as WeightSpace, WeightCharacter
202-
203202

204203
__ocmfdict = {}
205204

@@ -268,6 +267,7 @@ def OverconvergentModularForms(prime, weight, radius, base_ring=QQ, prec=20, cha
268267
__ocmfdict[key] = weakref.ref(M)
269268
return M
270269

270+
271271
#########################
272272
# Main class definition #
273273
#########################
@@ -298,19 +298,21 @@ class OverconvergentModularFormsSpace(Module):
298298
def __init__(self, prime, weight, radius, base_ring, prec, char):
299299
r"""
300300
Create a space of overconvergent `p`-adic modular forms of level
301-
`\Gamma_0(p)`, over the given base ring. The base ring need not be a
301+
`\Gamma_0(p)`, over the given base ring.
302+
303+
The base ring need not be a
302304
`p`-adic ring (the spaces we compute with typically have bases over
303305
`\QQ`).
304306
305307
EXAMPLES::
306308
307-
sage: OverconvergentModularForms(3, 0, 1/2)
309+
sage: M = OverconvergentModularForms(3, 0, 1/2); M
308310
Space of 3-adic 1/2-overconvergent modular forms of weight-character 0 over Rational Field
311+
sage: TestSuite(M).run()
309312
"""
310-
311313
self._p = prime
312314

313-
if not ( base_ring == QQ or isinstance(base_ring, sage.rings.abc.pAdicField) ):
315+
if not (base_ring == QQ or isinstance(base_ring, sage.rings.abc.pAdicField)):
314316
raise TypeError("Base ring must be QQ or a p-adic field")
315317

316318
if base_ring != QQ and base_ring.prime() != self._p:
@@ -328,13 +330,13 @@ def __init__(self, prime, weight, radius, base_ring, prec, char):
328330

329331
self._prec = prec
330332

331-
self._qsr = PowerSeriesRing(base_ring, 'q', prec) # q-series ring
332-
self._gsr = PowerSeriesRing(base_ring, 'g', prec) # g-adic expansions, g = c*f
333+
self._qsr = PowerSeriesRing(base_ring, 'q', prec) # q-series ring
334+
self._gsr = PowerSeriesRing(base_ring, 'g', prec) # g-adic expansions, g = c*f
333335

334336
self._cached_recurrence_matrix = None
335337
self._set_radius(radius)
336338
self._basis_cache = [self._wtchar.pAdicEisensteinSeries(self._qsr, self.prec())]
337-
self._uniformiser = self._qsr(EtaProduct(prime, {prime: 24/ZZ(prime-1), ZZ(1):-24/ZZ(prime-1)}).qexp(self.prec()))
339+
self._uniformiser = self._qsr(EtaProduct(prime, {prime: 24/ZZ(prime-1), ZZ(1): -24/ZZ(prime-1)}).qexp(self.prec()))
338340

339341
for i in range(1, self.prec()):
340342
self._basis_cache.append(self._basis_cache[-1] * self._uniformiser * self._const)
@@ -374,7 +376,7 @@ def _set_radius(self, radius):
374376
p = ZZ(self.prime())
375377

376378
if (radius < 0 or radius > p/(p+1)):
377-
raise ValueError("radius (=%s) must be between 0 and p/(p+1)" % radius)
379+
raise ValueError("radius (=%s) must be between 0 and p/(p+1)" % radius)
378380
d = 12/(p-1)*radius
379381
if d.is_integral():
380382
self._const = p ** ZZ(d)
@@ -383,7 +385,7 @@ def _set_radius(self, radius):
383385
try:
384386
pi = self.base_ring().uniformiser()
385387
e = d / pi.normalized_valuation()
386-
except AttributeError: # base ring isn't a p-adic ring
388+
except AttributeError: # base ring isn't a p-adic ring
387389
pi = p
388390
e = d
389391
if not e.is_integral():
@@ -452,7 +454,7 @@ def _an_element_(self):
452454
sage: OverconvergentModularForms(3, 2, 1/3, prec=4).an_element() # indirect doctest
453455
3-adic overconvergent modular form of weight-character 2 with q-expansion 9*q + 216*q^2 + 2430*q^3 + O(q^4)
454456
"""
455-
return OverconvergentModularFormElement(self, self._gsr.an_element())
457+
return self.element_class(self, self._gsr.an_element())
456458

457459
def character(self):
458460
r"""
@@ -757,15 +759,15 @@ def _element_constructor_(self, input):
757759
return self._coerce_from_ocmf(input)
758760

759761
elif isinstance(input, ModularFormElement):
760-
if ( (input.level() == 1 or input.level().prime_factors() == [self.prime()])
761-
and input.weight() == self.weight().k()
762-
and input.character().primitive_character() == self.weight().chi().primitive_character()):
763-
p = ZZ(self.prime())
764-
nu = (input.level() == 1 and p/(p+1)) or (1 / (p + 1) * p**(2 - input.level().valuation(p)))
765-
if self.radius() > nu:
766-
raise ValueError("Form is not overconvergent enough (form is only %s-overconvergent)" % nu)
767-
else:
768-
return self(self._qsr(input.q_expansion(self.prec())))
762+
if ((input.level() == 1 or input.level().prime_factors() == [self.prime()])
763+
and input.weight() == self.weight().k()
764+
and input.character().primitive_character() == self.weight().chi().primitive_character()):
765+
p = ZZ(self.prime())
766+
nu = (input.level() == 1 and p/(p+1)) or (1 / (p + 1) * p**(2 - input.level().valuation(p)))
767+
if self.radius() > nu:
768+
raise ValueError("Form is not overconvergent enough (form is only %s-overconvergent)" % nu)
769+
else:
770+
return self(self._qsr(input.q_expansion(self.prec())))
769771
else:
770772
raise TypeError("Cannot create an element of '%s' from element of incompatible space '%s'" % (self, input.parent()))
771773

@@ -836,10 +838,9 @@ def _coerce_map_from_(self, other):
836838
3-adic overconvergent modular form of weight-character 0 with q-expansion 1 + O(q^20)
837839
"""
838840
if (isinstance(other, OverconvergentModularFormsSpace) and
839-
self.base_ring().has_coerce_map_from(other.base_ring())):
841+
self.base_ring().has_coerce_map_from(other.base_ring())):
840842
return True
841-
else:
842-
return self.base_ring().has_coerce_map_from(other)
843+
return self.base_ring().has_coerce_map_from(other)
843844

844845
def coordinate_vector(self, x):
845846
r"""
@@ -882,23 +883,6 @@ def ngens(self):
882883
"""
883884
return Infinity
884885

885-
def gens_dict(self):
886-
r"""
887-
Return a dictionary mapping the names of generators of this space to
888-
their values. (Required by parent class definition.) As this does not
889-
make any sense here, this raises a TypeError.
890-
891-
EXAMPLES::
892-
893-
sage: M = OverconvergentModularForms(2, 4, 1/6)
894-
sage: M.gens_dict()
895-
Traceback (most recent call last):
896-
...
897-
TypeError: gens_dict does not make sense as number of generators is infinite
898-
"""
899-
900-
raise TypeError("gens_dict does not make sense as number of generators is infinite")
901-
902886
#####################################
903887
# Routines with some actual content #
904888
#####################################
@@ -999,15 +983,15 @@ def hecke_matrix(self, m, n, use_recurrence=False, exact_arith=False):
999983
l = self._convert_to_basis(self.hecke_operator(self._basis_cache[j], m))
1000984
for i in range(n):
1001985
try:
1002-
mat[i,j] = l[i]
986+
mat[i, j] = l[i]
1003987
except IndexError:
1004988
if not self.weight().is_zero():
1005989
raise ValueError("n is too large for current precision")
1006990
else:
1007991
if i <= self.prime() * j:
1008-
raise ValueError("n is too large computing initial conds: can't work out u[%s, %s]" % (i,j))
992+
raise ValueError("n is too large computing initial conds: can't work out u[%s, %s]" % (i, j))
1009993
else:
1010-
mat[i,j] = 0 # computations are exact for weight 0, and we know these terms are zero
994+
mat[i, j] = 0 # computations are exact for weight 0, and we know these terms are zero
1011995
if use_recurrence:
1012996
if m != self.prime():
1013997
raise ValueError("Recurrence method not valid when m != p")
@@ -1019,17 +1003,17 @@ def hecke_matrix(self, m, n, use_recurrence=False, exact_arith=False):
10191003
raise ValueError("n is too large for current precision")
10201004
else:
10211005
if j <= self.prime() * i:
1022-
raise ValueError("n is too large computing initial conds: can't work out u[%s,%s]" % (i,j))
1023-
mat[i,j] = 0
1006+
raise ValueError("n is too large computing initial conds: can't work out u[%s,%s]" % (i, j))
1007+
mat[i, j] = 0
10241008

10251009
else:
10261010
l = self._convert_to_basis(self.hecke_operator(self._basis_cache[j], m))
10271011
for i in range(self.prime()):
1028-
mat[i,j] = l[i]
1012+
mat[i, j] = l[i]
10291013
for i in range(self.prime(), n):
10301014
for u in range(self.prime()):
10311015
for v in range(self.prime()):
1032-
mat[i,j] = mat[i,j] + mat[i-u-1, j-v-1]*self.recurrence_matrix()[u,v]
1016+
mat[i, j] = mat[i, j] + mat[i-u-1, j-v-1]*self.recurrence_matrix()[u, v]
10331017

10341018
else:
10351019
if n * self.prime() > self.prec():
@@ -1098,8 +1082,8 @@ def eigenfunctions(self, n, F=None, exact_arith=True):
10981082
F = self.base_ring()
10991083

11001084
if F.is_exact():
1101-
#raise TypeError, "cannot calculate eigenfunctions over exact base fields"
1102-
F = pAdicField(self.prime(), 100)
1085+
# raise TypeError, "cannot calculate eigenfunctions over exact base fields"
1086+
F = pAdicField(self.prime(), 100) # noqa:F821
11031087

11041088
m = self.hecke_matrix(self.prime(), n, use_recurrence=True, exact_arith=exact_arith)
11051089
cp = m.charpoly()
@@ -1144,7 +1128,7 @@ def eigenfunctions(self, n, F=None, exact_arith=True):
11441128

11451129
gexp = self._gsr(0)
11461130
for i in range(v.nrows()):
1147-
gexp += self._gsr.gen()**i * F(v[i,0])
1131+
gexp += self._gsr.gen()**i * F(v[i, 0])
11481132
gexp = gexp + O(self._gsr.gen()**int(v.nrows()))
11491133

11501134
if gexp[0] != 0:
@@ -1166,8 +1150,8 @@ def eigenfunctions(self, n, F=None, exact_arith=True):
11661150
# up with garbage. I don't know why. XXX FIX THIS XXX
11671151
eigenfunctions.append((r.valuation(), efunc))
11681152

1169-
eigenfunctions.sort() # sort by slope
1170-
return [f for _,f in eigenfunctions]
1153+
eigenfunctions.sort() # sort by slope
1154+
return [f for _, f in eigenfunctions]
11711155

11721156
def recurrence_matrix(self, use_smithline=True):
11731157
r"""
@@ -1232,13 +1216,13 @@ def _discover_recurrence_matrix(self, use_smithline=True):
12321216

12331217
if use_smithline:
12341218
# Compute Smithline's polynomial H_p
1235-
jq = self._qsr(j_invariant_qexp(1+self.prime()).shift(1).power_series())
1219+
jq = self._qsr(j_invariant_qexp(1 + self.prime()).shift(1).power_series()) # noqa:F821
12361220

12371221
# avoid dividing by q so as not to instantiate a Laurent series
12381222
h = self._uniformiser.shift(-1) * jq
12391223
fi = self._qsr(1)
12401224
coeffs = []
1241-
for i in range(self.prime()+2):
1225+
for i in range(self.prime() + 2):
12421226
if not h.valuation() >= i:
12431227
raise ValueError("Something strange is happening here")
12441228

@@ -1247,15 +1231,15 @@ def _discover_recurrence_matrix(self, use_smithline=True):
12471231
fi = fi*self._uniformiser
12481232
SmiH = f_ring(coeffs)
12491233
assert SmiH.degree() == self.prime() + 1
1250-
xyring = PolynomialRing(self.base_ring(), ["x","y"], 2)
1251-
x,y = xyring.gens()
1234+
xyring = PolynomialRing(self.base_ring(), ["x", "y"], 2)
1235+
x, y = xyring.gens()
12521236
cc = self.prime() ** (-12/(self.prime() - 1))
12531237
bigI = x*SmiH(y*cc) - y*cc*SmiH(x)
12541238
smallI = xyring(bigI / (x - cc*y))
12551239
r = matrix(ZZ, self.prime(), self.prime())
12561240
for i in range(self.prime()):
12571241
for j in range(self.prime()):
1258-
r[i,j] = -smallI[i+1, j+1]
1242+
r[i, j] = -smallI[i+1, j+1]
12591243
return r
12601244
else:
12611245
# compute from U(f^j) for small j via Newton's identities
@@ -1296,6 +1280,7 @@ def cps_u(self, n, use_recurrence=False):
12961280

12971281
return g
12981282

1283+
12991284
class OverconvergentModularFormElement(ModuleElement):
13001285
r"""
13011286
A class representing an element of a space of overconvergent modular forms.
@@ -1318,18 +1303,17 @@ def __init__(self, parent, gexp=None, qexp=None):
13181303
sage: OverconvergentModularForms(3, 2, 1/6,prec=5).an_element() # indirect doctest
13191304
3-adic overconvergent modular form of weight-character 2 with q-expansion 3*q + 72*q^2 + 810*q^3 + 6096*q^4 + O(q^5)
13201305
"""
1321-
13221306
ModuleElement.__init__(self, parent)
13231307

13241308
self._p = self.parent().prime()
1325-
#self.weight = self.parent().weight
1309+
# self.weight = self.parent().weight
13261310
if (gexp is None and qexp is None) or (gexp is not None and qexp is not None):
13271311
raise ValueError("Must supply exactly one of a q-expansion and a g-expansion")
13281312
if gexp is not None:
13291313
self._gexp = gexp.add_bigoh(self.parent().prec())
13301314
self._qexp = sum([self.parent()._basis_cache[i] * gexp[i] for i in range(min(gexp.prec(), self.parent().prec()))])
13311315
self._qexp = self._qexp.add_bigoh(self._gexp.prec())
1332-
else: # qexp is not None
1316+
else: # qexp is not None
13331317
self._qexp = qexp.add_bigoh(self.parent().prec())
13341318
self._gexp = self.parent()._convert_to_basis(self._qexp)
13351319

@@ -1433,7 +1417,9 @@ def slope(self):
14331417

14341418
def eigenvalue(self):
14351419
r"""
1436-
Return the `U_p`-eigenvalue of this eigenform. Raises an error unless
1420+
Return the `U_p`-eigenvalue of this eigenform.
1421+
1422+
This raises an error unless
14371423
this element was explicitly flagged as an eigenform, using the
14381424
_notify_eigen function.
14391425
@@ -1547,13 +1533,12 @@ def is_integral(self):
15471533
sage: M(q - q^2/2 + 6*q^7 + O(q^9)).is_integral()
15481534
False
15491535
"""
1550-
15511536
for co in self.q_expansion().list():
1552-
if (co * (1 + O(self.prime()))).valuation() < 0: # have to force it into ZZ_p
1537+
if (co * (1 + O(self.prime()))).valuation() < 0: # have to force it into ZZ_p
15531538
return False
15541539
return True
15551540

1556-
def _repr_(self):
1541+
def _repr_(self) -> str:
15571542
r"""
15581543
String representation of ``self``.
15591544
@@ -1598,10 +1583,10 @@ def r_ord(self, r):
15981583

15991584
F = self.parent().base_ring()
16001585
if not isinstance(F, sage.rings.abc.pAdicField):
1601-
F = pAdicField(p)
1586+
F = pAdicField(p) # noqa:F821
16021587

16031588
for i in range(self.prec()):
1604-
ord = max( ord, 12/ZZ(p - 1)*i*(r - s) - F(self.gexp()[i]).normalized_valuation())
1589+
ord = max(ord, 12/ZZ(p - 1)*i*(r - s) - F(self.gexp()[i]).normalized_valuation())
16051590

16061591
return ord
16071592

@@ -1638,7 +1623,7 @@ def governing_term(self, r):
16381623
p = self.prime()
16391624
F = self.parent().base_ring()
16401625
if not isinstance(F, sage.rings.abc.pAdicField):
1641-
F = pAdicField(p)
1626+
F = pAdicField(p) # noqa:F821
16421627
s = self.parent().radius()
16431628
p = self.prime()
16441629

@@ -1729,3 +1714,6 @@ def __pari__(self):
17291714
(3^3 + O(3^23))*q + (3^4 + 3^5 + O(3^24))*q^2 + (3^5 + 3^7 + O(3^25))*q^3 + (3^3 + 3^4 + 2*3^5 + 2*3^8 + O(3^23))*q^4 + (2*3^4 + 3^5 + 3^6 + 2*3^7 + 3^10 + O(3^24))*q^5 + (3^6 + 3^7 + 3^8 + 3^9 + 3^10 + 3^11 + O(3^26))*q^6 + (2*3^3 + 3^4 + 2*3^6 + 2*3^7 + 2*3^8 + 3^9 + 3^10 + 2*3^11 + 3^12 + O(3^23))*q^7 + (2*3^4 + 3^5 + 3^8 + 2*3^9 + 2*3^10 + 2*3^13 + O(3^24))*q^8 + (3^7 + 2*3^9 + 2*3^12 + 2*3^14 + O(3^27))*q^9 + (2*3^5 + 3^8 + 3^9 + 2*3^10 + 2*3^13 + 2*3^15 + O(3^25))*q^10 + (3^4 + 2*3^5 + 2*3^6 + 3^8 + 2*3^9 + 3^12 + 3^14 + 2*3^16 + O(3^24))*q^11 + (3^5 + 3^6 + 2*3^8 + 2*3^9 + 2*3^10 + 2*3^12 + 3^14 + 2*3^15 + 2*3^16 + 3^17 + O(3^25))*q^12 + (2*3^3 + 2*3^4 + 2*3^5 + 3^8 + 2*3^9 + 2*3^11 + 3^13 + 2*3^14 + 2*3^17 + 3^18 + O(3^23))*q^13 + (2*3^4 + 2*3^6 + 2*3^7 + 3^8 + 2*3^9 + 3^10 + 3^12 + 3^14 + 2*3^15 + 2*3^16 + 3^18 + 3^19 + O(3^24))*q^14 + (2*3^6 + 3^7 + 3^9 + 3^10 + 3^11 + 2*3^14 + 3^15 + 2*3^16 + 3^17 + 3^18 + 3^20 + O(3^26))*q^15 + (3^3 + 2*3^4 + 2*3^7 + 2*3^8 + 3^9 + 3^10 + 2*3^11 + 3^12 + 2*3^14 + 2*3^15 + 3^17 + 3^18 + 2*3^19 + 2*3^20 + O(3^23))*q^16 + (2*3^5 + 2*3^7 + 2*3^8 + 3^10 + 3^11 + 2*3^12 + 2*3^13 + 3^14 + 3^15 + 3^17 + 2*3^18 + 3^19 + 2*3^21 + O(3^25))*q^17 + (3^8 + 3^9 + 2*3^10 + 2*3^11 + 3^12 + 3^14 + 3^15 + 3^16 + 3^17 + 2*3^21 + 3^22 + O(3^28))*q^18 + (2*3^3 + 3^5 + 2*3^6 + 2*3^8 + 2*3^9 + 3^11 + 2*3^12 + 3^13 + 3^14 + 2*3^15 + 3^16 + 3^17 + 2*3^18 + 3^19 + 2*3^21 + O(3^23))*q^19 + O(q^20)
17301715
"""
17311716
return self.q_expansion().__pari__()
1717+
1718+
1719+
OverconvergentModularFormsSpace.Element = OverconvergentModularFormElement

0 commit comments

Comments
 (0)