This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
manin_symbol.pyx
471 lines (379 loc) · 14.6 KB
/
manin_symbol.pyx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
# -*- coding: utf-8 -*-
"""
Manin symbols
This module defines the class ManinSymbol. A Manin symbol of
weight `k`, level `N` has the form `[P(X,Y),(u:v)]` where
`P(X,Y)\in\mathbb{Z}[X,Y]` is homogeneous of weight `k-2` and
`(u:v)\in\mathbb{P}^1(\mathbb{Z}/N\mathbb{Z}).` The ManinSymbol class
holds a "monomial Manin symbol" of the simpler form
`[X^iY^{k-2-i},(u:v)]`, which is stored as a triple `(i,u,v)`; the
weight and level are obtained from the parent structure, which is a
:class:`sage.modular.modsym.manin_symbol_list.ManinSymbolList`.
Integer matrices `[a,b;c,d]` act on Manin symbols on the right,
sending `[P(X,Y),(u,v)]` to `[P(aX+bY,cX+dY),(u,v)g]`. Diagonal
matrices (with `b=c=0`, such as `I=[-1,0;0,1]` and `J=[-1,0;0,-1]`)
and anti-diagonal matrices (with `a=d=0`, such as `S=[0,-1;1,0]`) map
monomial Manin symbols to monomial Manin symbols, up to a scalar
factor. For general matrices (such as `T=[0,1,-1,-1]` and
`T^2=[-1,-1;0,1]`) the image of a monomial Manin symbol is expressed
as a formal sum of monomial Manin symbols, with integer coefficients.
"""
from sage.modular.cusps import Cusp
from sage.rings.all import Infinity, ZZ
from sage.rings.integer cimport Integer
from sage.structure.element cimport Element
from sage.structure.sage_object import register_unpickle_override
def is_ManinSymbol(x):
"""
Return ``True`` if ``x`` is a :class:`ManinSymbol`.
EXAMPLES::
sage: from sage.modular.modsym.manin_symbol import ManinSymbol, is_ManinSymbol
sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_gamma0
sage: m = ManinSymbolList_gamma0(6, 4)
sage: s = ManinSymbol(m, m.symbol_list()[3])
sage: s
[Y^2,(1,2)]
sage: is_ManinSymbol(s)
True
sage: is_ManinSymbol(m[3])
True
"""
return isinstance(x, ManinSymbol)
cdef class ManinSymbol(Element):
r"""
A Manin symbol `[X^i Y^{k-2-i}, (u, v)]`.
INPUT:
- ``parent`` -- :class:`~sage.modular.modsym.manin_symbol_list.ManinSymbolList`
- ``t`` -- a triple `(i, u, v)` of integers
EXAMPLES::
sage: from sage.modular.modsym.manin_symbol import ManinSymbol
sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_gamma0
sage: m = ManinSymbolList_gamma0(5,2)
sage: s = ManinSymbol(m,(2,2,3)); s
(2,3)
sage: s == loads(dumps(s))
True
::
sage: m = ManinSymbolList_gamma0(5,8)
sage: s = ManinSymbol(m,(2,2,3)); s
[X^2*Y^4,(2,3)]
::
sage: from sage.modular.modsym.manin_symbol import ManinSymbol
sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_gamma0
sage: m = ManinSymbolList_gamma0(5,8)
sage: s = ManinSymbol(m,(2,2,3))
sage: s.parent()
Manin Symbol List of weight 8 for Gamma0(5)
"""
def __init__(self, parent, t):
r"""
Create a Manin symbol `[X^i Y^{k-2-i}, (u, v)]`, where
`k` is the weight.
INPUT:
- ``parent`` -- :class:`~sage.modular.modsym.manin_symbol_list.ManinSymbolList`
- ``t`` -- a triple `(i, u, v)` of integers
EXAMPLES::
sage: from sage.modular.modsym.manin_symbol import ManinSymbol
sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_gamma0
sage: m = ManinSymbolList_gamma0(5,2)
sage: s = ManinSymbol(m,(2,2,3)); s
(2,3)
::
sage: m = ManinSymbolList_gamma0(5,8)
sage: s = ManinSymbol(m,(2,2,3)); s
[X^2*Y^4,(2,3)]
"""
Element.__init__(self, parent)
(i, u, v) = t
self.i = Integer(i)
self.u = Integer(u)
self.v = Integer(v)
def __reduce__(self):
"""
For pickling.
TESTS::
sage: from sage.modular.modsym.manin_symbol import ManinSymbol
sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_gamma1
sage: m = ManinSymbolList_gamma1(3, 2)
sage: s = ManinSymbol(m, (2, 2, 3))
sage: loads(dumps(s))
(2,3)
"""
return ManinSymbol, (self.parent(), self.tuple())
def __setstate__(self, state):
"""
Needed to unpickle old :class:`ManinSymbol` objects.
TESTS::
sage: from sage.modular.modsym.manin_symbol import ManinSymbol
sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_gamma0
sage: m = ManinSymbolList_gamma0(5,2)
sage: s = ManinSymbol(m,(2,2,3))
sage: loads(dumps(s))
(2,3)
"""
self._parent = state['_ManinSymbol__parent']
(self.i, self.u, self.v) = state['_ManinSymbol__t']
def tuple(self):
r"""
Return the 3-tuple `(i,u,v)` of this Manin symbol.
EXAMPLES::
sage: from sage.modular.modsym.manin_symbol import ManinSymbol
sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_gamma0
sage: m = ManinSymbolList_gamma0(5,8)
sage: s = ManinSymbol(m,(2,2,3))
sage: s.tuple()
(2, 2, 3)
"""
return (self.i, self.u, self.v)
def _repr_(self):
"""
Return a string representation of this Manin symbol.
EXAMPLES::
sage: from sage.modular.modsym.manin_symbol import ManinSymbol
sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_gamma0
sage: m = ManinSymbolList_gamma0(5,8)
sage: s = ManinSymbol(m,(2,2,3))
sage: str(s) # indirect doctest
'[X^2*Y^4,(2,3)]'
"""
if self.weight() > 2:
polypart = _print_polypart(self.i, self.weight()-2-self.i)
return "[%s,(%s,%s)]"%\
(polypart, self.u, self.v)
return "(%s,%s)"%(self.u, self.v)
def _latex_(self):
"""
Return a LaTeX representation of this Manin symbol.
EXAMPLES::
sage: from sage.modular.modsym.manin_symbol import ManinSymbol
sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_gamma0
sage: m = ManinSymbolList_gamma0(5,8)
sage: s = ManinSymbol(m,(2,2,3))
sage: latex(s) # indirect doctest
[X^2*Y^4,(2,3)]
"""
return self._repr_()
cpdef int _cmp_(self, Element right) except -2:
"""
Comparison function for ManinSymbols.
EXAMPLES::
sage: from sage.modular.modsym.manin_symbol import ManinSymbol
sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_gamma0
sage: m = ManinSymbolList_gamma0(5,8)
sage: slist = m.manin_symbol_list()
sage: slist[10] <= slist[20]
True
sage: slist[20] <= slist[10]
False
sage: cmp(slist[10],slist[20])
-1
sage: cmp(slist[20],slist[10])
1
sage: cmp(slist[20],slist[20])
0
"""
cdef ManinSymbol other = <ManinSymbol>right
# Compare tuples (i,u,v)
return cmp(self.i, other.i) or cmp(self.u, other.u) or cmp(self.v, other.v)
def __mul__(self, matrix):
"""
Return the result of applying a matrix to this Manin symbol.
EXAMPLES::
sage: from sage.modular.modsym.manin_symbol import ManinSymbol
sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_gamma0
sage: m = ManinSymbolList_gamma0(5,2)
sage: s = ManinSymbol(m,(0,2,3))
sage: s*[1,2,0,1]
(2,7)
::
sage: m = ManinSymbolList_gamma0(5,8)
sage: s = ManinSymbol(m,(2,2,3))
sage: s*[1,2,0,1]
Traceback (most recent call last):
...
NotImplementedError: ModSym * Matrix only implemented in weight 2
"""
if self.weight() > 2:
raise NotImplementedError("ModSym * Matrix only implemented "
"in weight 2")
from sage.matrix.matrix import is_Matrix
if is_Matrix(matrix):
if (not matrix.nrows() == 2) or (not matrix.ncols() == 2):
raise ValueError("matrix(=%s) must be 2x2" % matrix)
matrix = matrix.list()
return type(self)(self.parent(),
(self.i,
matrix[0]*self.u + matrix[2]*self.v,
matrix[1]*self.u + matrix[3]*self.v))
def apply(self, a,b,c,d):
"""
Return the image of self under the matrix `[a,b;c,d]`.
Not implemented for raw ManinSymbol objects, only for members
of ManinSymbolLists.
EXAMPLE::
sage: from sage.modular.modsym.manin_symbol import ManinSymbol
sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_gamma0
sage: m = ManinSymbolList_gamma0(5,2)
sage: m.apply(10,[1,0,0,1]) # not implemented for base class
"""
raise NotImplementedError
def __copy__(self):
"""
Return a copy of this Manin symbol.
EXAMPLES::
sage: from sage.modular.modsym.manin_symbol import ManinSymbol
sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_gamma0
sage: m = ManinSymbolList_gamma0(5,8)
sage: s = ManinSymbol(m,(2,2,3))
sage: s2 = copy(s)
sage: s2
[X^2*Y^4,(2,3)]
"""
return type(self)(self.parent(), (self.i, self.u, self.v))
def lift_to_sl2z(self, N=None):
r"""
Return a lift of this Manin symbol to `SL_2(\mathbb{Z})`.
If this Manin symbol is `(c,d)` and `N` is its level, this
function returns a list `[a,b, c',d']` that defines a 2x2
matrix with determinant 1 and integer entries, such that
`c=c'` (mod `N`) and `d=d'` (mod `N`).
EXAMPLES::
sage: from sage.modular.modsym.manin_symbol import ManinSymbol
sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_gamma0
sage: m = ManinSymbolList_gamma0(5,8)
sage: s = ManinSymbol(m,(2,2,3))
sage: s
[X^2*Y^4,(2,3)]
sage: s.lift_to_sl2z()
[1, 1, 2, 3]
"""
if N is None:
N = self.level()
if N == 1:
return [ZZ.one(), ZZ.zero(), ZZ.zero(), ZZ.one()]
c = Integer(self.u)
d = Integer(self.v)
g, z1, z2 = c.xgcd(d)
# We're lucky: z1*c + z2*d = 1.
if g==1:
return [z2, -z1, c, d]
# Have to try harder.
if c == 0:
c += N
if d == 0:
d += N
m = c
# compute prime-to-d part of m.
while True:
g = m.gcd(d)
if g == 1:
break
m //= g
# compute prime-to-N part of m.
while True:
g = m.gcd(N)
if g == 1:
break
m //= g
d += N*m
g, z1, z2 = c.xgcd(d)
assert g==1
return [z2, -z1, c, d]
def endpoints(self, N=None):
r"""
Return cusps `alpha`, `beta` such that this Manin symbol, viewed as a
symbol for level `N`, is `X^i*Y^{k-2-i} \{alpha, beta\}`.
EXAMPLES::
sage: from sage.modular.modsym.manin_symbol import ManinSymbol
sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_gamma0
sage: m = ManinSymbolList_gamma0(5,8)
sage: s = ManinSymbol(m,(2,2,3)); s
[X^2*Y^4,(2,3)]
sage: s.endpoints()
(1/3, 1/2)
"""
if N is None:
N = self.parent().level()
else:
N=int(N)
if N < 1:
raise ArithmeticError("N must be positive")
a,b,c,d = self.lift_to_sl2z()
return Cusp(b, d), Cusp(a, c)
def weight(self):
"""
Return the weight of this Manin symbol.
EXAMPLES::
sage: from sage.modular.modsym.manin_symbol import ManinSymbol
sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_gamma0
sage: m = ManinSymbolList_gamma0(5,8)
sage: s = ManinSymbol(m,(2,2,3))
sage: s.weight()
8
"""
return self.parent().weight()
def level(self):
"""
Return the level of this Manin symbol.
EXAMPLES::
sage: from sage.modular.modsym.manin_symbol import ManinSymbol
sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_gamma0
sage: m = ManinSymbolList_gamma0(5,8)
sage: s = ManinSymbol(m,(2,2,3))
sage: s.level()
5
"""
return self.parent().level()
def modular_symbol_rep(self):
"""
Return a representation of ``self`` as a formal sum of modular
symbols.
The result is not cached.
EXAMPLES::
sage: from sage.modular.modsym.manin_symbol import ManinSymbol
sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_gamma0
sage: m = ManinSymbolList_gamma0(5,8)
sage: s = ManinSymbol(m,(2,2,3))
sage: s.modular_symbol_rep()
144*X^6*{1/3, 1/2} - 384*X^5*Y*{1/3, 1/2} + 424*X^4*Y^2*{1/3, 1/2} - 248*X^3*Y^3*{1/3, 1/2} + 81*X^2*Y^4*{1/3, 1/2} - 14*X*Y^5*{1/3, 1/2} + Y^6*{1/3, 1/2}
"""
# TODO: It would likely be much better to do this slightly more directly
from sage.modular.modsym.modular_symbols import ModularSymbol
x = ModularSymbol(self.parent(), self.i, 0, Infinity)
a,b,c,d = self.lift_to_sl2z()
return x.apply([a,b,c,d])
def _print_polypart(i, j):
r"""
Helper function for printing the polynomial part `X^iY^j` of a ManinSymbol.
EXAMPLES::
sage: from sage.modular.modsym.manin_symbol import _print_polypart
sage: _print_polypart(2,3)
'X^2*Y^3'
sage: _print_polypart(2,0)
'X^2'
sage: _print_polypart(0,1)
'Y'
"""
if i > 1:
xpart = "X^%s"%i
elif i == 1:
xpart = "X"
else:
xpart = ""
if j > 1:
ypart = "Y^%s"%j
elif j == 1:
ypart = "Y"
else:
ypart = ""
if len(xpart) > 0 and len(ypart) > 0:
times = "*"
else:
times = ""
if len(xpart + ypart) > 0:
polypart = "%s%s%s"%(xpart, times, ypart)
else:
polypart = ""
return polypart
register_unpickle_override('sage.modular.modsym.manin_symbols',
'ManinSymbol', ManinSymbol)