Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/databases/stein_watkins.py
6915 views
1
r"""
2
The Stein-Watkins table of elliptic curves
3
4
Sage gives access to the Stein-Watkins table of elliptic curves,
5
via an optional package that you must install. This is a huge
6
database of elliptic curves. You can download the database as a
7
2.6GB Sage package from http://modular.ucsd.edu/sagedb/, which you
8
install with the command
9
10
::
11
12
sage -i stein-watkins-ecdb.spkg
13
14
You can also download a small version, without having to explicitly
15
download anything from a website, using the command
16
17
::
18
19
sage -i stein-watkins-ecdb-mini
20
21
This database covers a wide range of conductors, but unlike
22
CremonaDatabase(), this database need not list all curves of a
23
given conductor. It lists the curves whose coefficients aren't "too
24
large" (see [Stein-Watkins, Ants 5]).
25
26
27
- The command ``SteinWatkinsAllData(n)`` returns an
28
iterator over the curves in the `n^{th}` Stein-Watkins table,
29
which contains elliptic curves of conductor between `n10^5`
30
and `(n+1)10^5`. Here `n` can be between
31
`0` and `999`, inclusive.
32
33
- The command ``SteinWatkinsPrimeData(n)`` returns an
34
iterator over the curves in the `n^{th}` Stein-Watkins table,
35
which contains prime conductor elliptic curves of conductor between
36
`n10^6` and `(n+1)10^6`. Here `n` varies
37
between `0` and `99`, inclusive.
38
39
40
EXAMPLES: We obtain the first table of elliptic curves.
41
42
::
43
44
sage: d = SteinWatkinsAllData(0)
45
sage: d
46
Stein-Watkins Database a.0 Iterator
47
48
We type ``d.next()`` to get each isogeny class of
49
curves from ``d``::
50
51
sage: C = d.next() # optional - database_stein_watkins
52
sage: C # optional - database_stein_watkins
53
Stein-Watkins isogeny class of conductor 11
54
sage: d.next() # optional - database_stein_watkins
55
Stein-Watkins isogeny class of conductor 14
56
sage: d.next() # optional - database_stein_watkins
57
Stein-Watkins isogeny class of conductor 15
58
59
An isogeny class has a number of attributes that give data about
60
the isogeny class, such as the rank, equations of curves,
61
conductor, leading coefficient of `L`-function, etc.
62
63
::
64
65
sage: C.data # optional - database_stein_watkins
66
['11', '[11]', '0', '0.253842', '25', '+*1']
67
sage: C.curves # optional - database_stein_watkins
68
[[[0, -1, 1, 0, 0], '(1)', '1', '5'],
69
[[0, -1, 1, -10, -20], '(5)', '1', '5'],
70
[[0, -1, 1, -7820, -263580], '(1)', '1', '1']]
71
sage: C.conductor # optional - database_stein_watkins
72
11
73
sage: C.leading_coefficient # optional - database_stein_watkins
74
'0.253842'
75
sage: C.modular_degree # optional - database_stein_watkins
76
'+*1'
77
sage: C.rank # optional - database_stein_watkins
78
0
79
sage: C.isogeny_number # optional - database_stein_watkins
80
'25'
81
82
If we were to continue typing ``d.next()`` we would
83
iterate over all curves in the Stein-Watkins database up to
84
conductor `10^5`. We could also type ``for C in d:
85
...``
86
87
To access the data file starting at `10^5` do the
88
following::
89
90
sage: d = SteinWatkinsAllData(1) # optional - database_stein_watkins
91
sage: C = d.next() # optional - database_stein_watkins
92
sage: C # optional - database_stein_watkins
93
Stein-Watkins isogeny class of conductor 100002
94
sage: C.curves # optional - database_stein_watkins
95
[[[1, 1, 0, 112, 0], '(8,1,2,1)', 'X', '2'],
96
[[1, 1, 0, -448, -560], '[4,2,1,2]', 'X', '2']]
97
98
Next we access the prime-conductor data::
99
100
sage: d = SteinWatkinsPrimeData(0) # optional - database_stein_watkins
101
sage: C = d.next() # optional - database_stein_watkins
102
sage: C # optional - database_stein_watkins
103
Stein-Watkins isogeny class of conductor 11
104
105
Each call ``d.next()`` gives another elliptic curve of
106
prime conductor::
107
108
sage: C = d.next() # optional - database_stein_watkins
109
sage: C # optional - database_stein_watkins
110
Stein-Watkins isogeny class of conductor 17
111
sage: C.curves # optional - database_stein_watkins
112
[[[1, -1, 1, -1, 0], '[1]', '1', '4'],
113
[[1, -1, 1, -6, -4], '[2]', '1', '2x'],
114
[[1, -1, 1, -1, -14], '(4)', '1', '4'],
115
[[1, -1, 1, -91, -310], '[1]', '1', '2']]
116
sage: C = d.next() # optional - database_stein_watkins
117
sage: C # optional - database_stein_watkins
118
Stein-Watkins isogeny class of conductor 19
119
"""
120
121
#*****************************************************************************
122
#
123
# Sage: Copyright (C) 2005 William Stein <[email protected]>
124
#
125
# Distributed under the terms of the GNU General Public License (GPL)
126
#
127
# This code is distributed in the hope that it will be useful,
128
# but WITHOUT ANY WARRANTY; without even the implied warranty of
129
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
130
# General Public License for more details.
131
#
132
# The full text of the GPL is available at:
133
#
134
# http://www.gnu.org/licenses/
135
#*****************************************************************************
136
137
import bz2, os
138
139
import sage.databases.db # very important that this be fully qualified
140
141
class SteinWatkinsIsogenyClass:
142
def __init__(self, conductor):
143
self.conductor = conductor
144
145
def __repr__(self):
146
return "Stein-Watkins isogeny class of conductor %s"%self.conductor
147
148
def __len__(self):
149
try:
150
return len(self.curves)
151
except AttributeError:
152
return 0
153
154
def __iter__(self):
155
try:
156
for E in self.curves:
157
yield E
158
except AttributeError:
159
return
160
161
162
def _lines(s):
163
while True:
164
i = s.find("\n")
165
if i == -1:
166
yield ""
167
return
168
line = s[:i]
169
s = s[i+1:]
170
yield line
171
172
173
class SteinWatkinsAllData:
174
"""
175
Class for iterating through one of the Stein-Watkins database files
176
for all conductors.
177
"""
178
def __init__(self, num):
179
num = int(num)
180
self.num = num
181
if num < 0:
182
raise RuntimeError, "num (=%s) must be a nonnegative integer"%num
183
name = str(num)
184
name = '0'*(3-len(name)) + name
185
self._file = "%s/data/stein-watkins-ecdb/a.%s.bz2"%(os.environ["SAGE_ROOT"],name)
186
self._iter = self.__iter__()
187
188
def __repr__(self):
189
return "Stein-Watkins Database a.%s Iterator"%self.num
190
191
def __iter__(self):
192
try:
193
file = bz2.BZ2File(self._file, 'r')
194
except IOError:
195
raise IOError, "The Stein-Watkins data file %s must be installed."%self._file
196
C = None
197
for L in file:
198
if len(L) == 0:
199
continue
200
if L[0] != '[': # new curve
201
if C != None:
202
yield C
203
x = L.split()
204
N = int(x[0])
205
C = SteinWatkinsIsogenyClass(N)
206
C.rank = int(x[2])
207
C.leading_coefficient = x[3]
208
C.isogeny_number = x[4]
209
C.modular_degree = x[5]
210
C.curves = []
211
C.data = x
212
else:
213
w = L.split()
214
C.curves.append([eval(w[0]), w[1], w[2], w[3]])
215
yield C
216
217
def next(self):
218
return self._iter.next()
219
220
def __getitem__(self, N):
221
"""
222
Return the curves of conductor N in this table. (Very slow!)
223
Return all data about curves between the given levels in this
224
database file.
225
"""
226
X = []
227
if isinstance(N, slice):
228
min_level, max_level, step = N.indices(len(list(self)))
229
for C in self:
230
M = C.conductor
231
if M >= min_level and M <= max_level:
232
X.append(C)
233
elif M > max_level:
234
return X
235
else:
236
for C in self:
237
M = C.conductor
238
if M == N:
239
X.append(C)
240
elif M > N:
241
return X
242
return X
243
244
def iter_levels(self):
245
"""
246
Iterate through the curve classes, but grouped into lists by
247
level.
248
"""
249
iter = self.__iter__()
250
C = []
251
N = 0
252
while True:
253
try:
254
E = iter.next()
255
except StopIteration:
256
if C != []:
257
yield C
258
raise StopIteration
259
if E.conductor != N:
260
if C != []:
261
yield C
262
C = [E]
263
N = E.conductor
264
else:
265
C.append(E)
266
yield C
267
268
269
class SteinWatkinsPrimeData(SteinWatkinsAllData):
270
def __init__(self, num):
271
num = int(num)
272
self.num = num
273
if num < 0:
274
raise RuntimeError, "num (=%s) must be a nonnegative integer"%num
275
name = str(num)
276
name = '0'*(2-len(name)) + name
277
self._file = "%s/data/stein-watkins-ecdb/p.%s.bz2"%(os.environ["SAGE_ROOT"], name)
278
self._iter = self.__iter__()
279
280
def __repr__(self):
281
return "Stein-Watkins Prime Conductor Database p.%s Iterator"%self.num
282
283
284
def ecdb_num_curves(max_level=200000):
285
i = 0
286
N = 1
287
d = SteinWatkinsAllData(i)
288
v = [int(0) for _ in xrange(max_level+1)]
289
while True:
290
try:
291
C = d.next()
292
except StopIteration:
293
i += 1
294
d = SteinWatkinsAllData(i)
295
continue
296
N = C.conductor
297
if N > max_level:
298
break
299
v[N] += len(C.curves)
300
return v
301
302
303
304