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