Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/sage/libs/cremona/newforms.pyx
8817 views
1
from sage.rings.rational import Rational
2
from sage.rings.integer cimport Integer
3
from sage.schemes import elliptic_curves
4
from sage.modular.all import Cusp
5
6
#*****************************************************************************
7
# Copyright (C) 2008 Tom Boothby <[email protected]>
8
#
9
# Distributed under the terms of the GNU General Public License (GPL)
10
# as published by the Free Software Foundation; either version 2 of
11
# the License, or (at your option) any later version.
12
# http://www.gnu.org/licenses/
13
#*****************************************************************************
14
15
16
cdef class ECModularSymbol:
17
"""
18
Modular symbol associated with an elliptic curve,
19
using John Cremona's newforms class.
20
21
EXAMPLES::
22
23
sage: from sage.libs.cremona.newforms import ECModularSymbol
24
sage: E = EllipticCurve('11a')
25
sage: M = ECModularSymbol(E,1); M
26
Modular symbol with sign 1 over Rational Field attached to Elliptic Curve defined by y^2 + y = x^3 - x^2 - 10*x - 20 over Rational Field
27
sage: [M(1/i) for i in range(1,11)]
28
[0, 2, 1, -1, -2, -2, -1, 1, 2, 0]
29
30
"""
31
def __init__(self, E, sign=1):
32
"""
33
Construct the modular symbol.
34
35
EXAMPLES::
36
37
sage: from sage.libs.cremona.newforms import ECModularSymbol
38
sage: E = EllipticCurve('11a')
39
sage: M = ECModularSymbol(E)
40
sage: E = EllipticCurve('37a')
41
sage: M = ECModularSymbol(E)
42
sage: E = EllipticCurve('389a')
43
sage: M = ECModularSymbol(E)
44
45
TESTS:
46
47
This one is from :trac: `8042` (note that Cremona's code is more limited
48
when run on a 32-bit platform, but works fine on 64-bit in this
49
case; see :trac: `8114`).
50
51
::
52
sage: from sage.libs.cremona.newforms import ECModularSymbol
53
sage: E = EllipticCurve('858k2')
54
sage: ECModularSymbol(E)
55
Traceback (most recent call last): # 32-bit
56
... # 32-bit
57
OverflowError: Python int too large to convert to C long # 32-bit
58
Modular symbol with sign 1 over Rational Field attached to Elliptic Curve defined by y^2 + x*y = x^3 + 16353089*x - 335543012233 over Rational Field # 64-bit
59
"""
60
cdef ZZ_c a1, a2, a3, a4, a6, N
61
cdef Curve *C
62
cdef Curvedata *CD
63
cdef CurveRed *CR
64
cdef int n, t
65
66
a1 = new_bigint(int(E.a1()))
67
a2 = new_bigint(int(E.a2()))
68
a3 = new_bigint(int(E.a3()))
69
a4 = new_bigint(int(E.a4()))
70
a6 = new_bigint(int(E.a6()))
71
72
sig_on()
73
C = new_Curve(a1,a2,a3,a4,a6)
74
CD = new_Curvedata(C[0],0)
75
CR = new_CurveRed(CD[0])
76
N = getconductor(CR[0])
77
n = I2int(N)
78
self.n = n
79
self.sign = sign
80
81
self.nfs = new_newforms(n,0)
82
self.nfs.createfromcurve(sign,CR[0])
83
self._E = E
84
sig_off()
85
86
def __repr__(self):
87
"""
88
TESTS::
89
90
sage: from sage.libs.cremona.newforms import ECModularSymbol
91
sage: E = EllipticCurve('11a')
92
sage: M = ECModularSymbol(E); M
93
Modular symbol with sign 1 over Rational Field attached to Elliptic Curve defined by y^2 + y = x^3 - x^2 - 10*x - 20 over Rational Field
94
sage: E = EllipticCurve('37a')
95
sage: M = ECModularSymbol(E); M
96
Modular symbol with sign 1 over Rational Field attached to Elliptic Curve defined by y^2 + y = x^3 - x over Rational Field
97
sage: E = EllipticCurve('389a')
98
sage: M = ECModularSymbol(E); M
99
Modular symbol with sign 1 over Rational Field attached to Elliptic Curve defined by y^2 + y = x^3 + x^2 - 2*x over Rational Field
100
"""
101
return "Modular symbol with sign %s over Rational Field attached to %s"%(self.sign, self._E)
102
103
def __call__(self, r):
104
"""
105
Computes the (rational) value of self at a rational number r.
106
107
EXAMPLES::
108
109
sage: from sage.libs.cremona.newforms import ECModularSymbol
110
sage: E = EllipticCurve('11a')
111
sage: M = ECModularSymbol(E)
112
sage: [M(1/i) for i in range(1,10)]
113
[0, 2, 1, -1, -2, -2, -1, 1, 2]
114
sage: E = EllipticCurve('37a')
115
sage: M = ECModularSymbol(E)
116
sage: [M(1/i) for i in range(1,10)]
117
[0, 0, 0, 0, 1, 0, 1, 1, 0]
118
sage: E = EllipticCurve('389a')
119
sage: M = ECModularSymbol(E)
120
sage: [M(1/i) for i in range(1,10)]
121
[0, 0, 0, 0, 4, 0, 2, 0, -2]
122
123
TESTS (see :trac: `11211`)::
124
125
sage: from sage.libs.cremona.newforms import ECModularSymbol
126
sage: E = EllipticCurve('11a')
127
sage: M = ECModularSymbol(E)
128
sage: M(oo)
129
2/5
130
sage: M(7/5)
131
3
132
sage: M("garbage")
133
Traceback (most recent call last):
134
...
135
TypeError: Unable to convert garbage to a Cusp
136
sage: M(7/5)
137
3
138
"""
139
cdef rational _r
140
cdef rational _s
141
cdef mpz_t *z_n, *z_d
142
cdef ZZ_c *Z_n, *Z_d
143
cdef long n, d
144
145
r = Cusp(r)
146
d = r.denominator()
147
n = r.numerator()
148
if d != 0:
149
n = n % d
150
sig_on()
151
_r = new_rational(n,d)
152
_s = self.nfs.plus_modular_symbol(_r)
153
sig_off()
154
return Rational((rational_num(_s), rational_den(_s)))
155
156