/
elliptic cuves.py
337 lines (238 loc) · 9.02 KB
/
elliptic cuves.py
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
def eroots(E):
r'''
INPUT:
- ``E`` : an elliptic curve
OUTPUT:
The three roots of the 2 - division polynomial of ``E``
EXAMPLES::
sage : E = EllipticCurve([0,0,0,-1,0])
sage : eroots(E)
(1, 0, -1)
'''
f = E.division_polynomial(2)
L = f.splitting_field('a')
e1, e2, e3 = f.roots(L)
return e1[0], e2[0], e3[0]
def lambda_invariants(E):
r'''
INPUT:
- ``E`` : an elliptic curve
OUTPUT:
A list with all lambda invariants of E.
EXAMPLES::
sage : E = EllipticCurve([0,0,0,-1,0])
sage : lambda_invariants(E)
[1/2, 2, 1/2, -1, 2, -1]
'''
e1, e2, e3 = eroots(E)
l = (e1 - e2) / (e1 - e3)
return [l,1/l,1-l,1-1/l,1/(1-l),l/(l-1)]
def j_invariant(l):
r"""
INPUT:
- ``l`` : the lambda invariant of an elliptic curve `E`
OUTPUT:
The associate to ``l`` `j`-invariant of `E`
"""
return (2**8 *(l**2 - l + 1)**3)/(l**2 * (1-l)**2)
def has_good_reduction_outside_S_over_K(E,S):
r"""
INPUT:
- ``E`` : an elliptic curve
- ``S`` : a set of primes of the field of definition of ``E``
OUTPUT:
True, if ``E`` has good reduction outside ``S``, otherwise False. We use Lemma 3.1 of the reference
REFERENCE:
J. E. Cremona and M. P. Lingham. Finding All Elliptic Curves with Good Reduction Outside a Given Set of Primes.
Experimental Mathematics, 16(3):303-312, 2007.
"""
K = E.base_ring()
D = E.discriminant()
d = D.absolute_norm()
SQ = []
for P in S:
p = P.absolute_norm().factor()[0][0]
if p not in SQ:
SQ.append(p)
d = d.prime_to_S_part(SQ)
for p in K.primes_above(d):
if not E.has_good_reduction(p) and p not in S:
return False
return True
def egros_from_0_over_K(K,S):
r"""
INPUT:
- ``K`` : a number field
- ``S`` : a list of primes of ``K``
OUTPUT:
A list with all elliptic curves over ``K`` with good reduction outside ``S`` and `j`-invariant equal to 0.
REFERENCE:
J. E. Cremona and M. P. Lingham. Finding All Elliptic Curves with Good Reduction Outside a Given Set of Primes.
Experimental Mathematics, 16(3):303-312, 2007.
EXAMPLE::
sage:
"""
if K == QQ:
from sage.schemes.elliptic_curves.ell_egros import egros_from_j_0
return egros_from_j_0(S)
#S contains a prime above 3 such that its order at 3 is odd
for p in K.primes_above(3):
if (K(3)).valuation(p) %2 == 1 and p not in S:
return []
Sprime = copy(S)
#we add suitable primes above 2
for p in K.primes_above(2):
if (K(2)).valuation(p)%3 == 1 or (K(2)).valuation(p)%3 == -1 and p not in Sprime:
Sprime.append(p)
#we add suitable primes above 3
for p in K.primes_above(3):
if (K(2)).valuation(p)%4 == 2 and p not in Sprime:
Sprime.append(p)
SprimenotS_2 = [p for p in Sprime if p not in S and (K(2)).valuation(p) != 0]
SprimenotS_3 = [p for p in Sprime if p not in S and (K(3)).valuation(p) != 0]
import time
selmergens,orders = K.selmer_group(Sprime,6,orders=True)
curves = []
if len(SprimenotS_2) + len(SprimenotS_3) == 0:
for v in cartesian_product_iterator([xrange(b) for b in orders]):
w = prod([g**i for g,i in zip(selmergens,v)])
E = EllipticCurve([0,w])
if has_good_reduction_outside_S_over_K(E,S):
curves.append(E)
return curves
for v in cartesian_product_iterator([xrange(b) for b in orders]):
w = prod([g**i for g,i in zip(selmergens,v)])
if len([1 for p in SprimenotS_3 if w.valuation(p)%6 == 3 and (K(3)).valuation(p)%4 == 2]) == len(SprimenotS_3):
n1 = len([1 for p in SprimenotS_2 if w.valuation(p)%6 == 4 and (K(2)).valuation(p)%3 == 1])
n2 = len([1 for p in SprimenotS_2 if w.valuation(p)%6 == 2 and (K(2)).valuation(p)%3 == 2])
if n1+n2 == len(SprimenotS_2):
E = EllipticCurve([0,w])
start = time.time()
if has_good_reduction_outside_S_over_K(E,S):
curves.append(E)
return curves
def egros_from_1728_over_K(K,S):
r"""
INPUT:
- ``K`` : a number field
- ``S`` : a list of primes of ``K``
OUTPUT:
A list with all elliptic curves over ``K`` with good reduction outside ``S`` and `j`-invariant equal to 1728.
REFERENCE:
J. E. Cremona and M. P. Lingham. Finding All Elliptic Curves with Good Reduction Outside a Given Set of Primes.
Experimental Mathematics, 16(3):303-312, 2007.
EXAMPLE::
sage:
"""
if K == QQ:
from sage.schemes.elliptic_curves.ell_egros import egros_from_j_1728
return egros_from_j_1728(S)
Sprime = copy(S)
#we add suitable primes above 2
for p in K.primes_above(2):
if (K(2)).valuation(p)%2 == 1 and p not in Sprime:
Sprime.append(p)
SprimenotS = [p for p in Sprime if p not in S]
selmergens,orders = K.selmer_group(Sprime,4,orders=True)
curves = []
if len(SprimenotS) == 0:
for v in cartesian_product_iterator([xrange(b) for b in orders]):
w = prod([g**i for g,i in zip(selmergens,v)])
E = EllipticCurve([w,0])
if has_good_reduction_outside_S_over_K(E,S):
curves.append(E)
return curves
for v in cartesian_product_iterator([xrange(b) for b in orders]):
w = prod([g**i for g,i in zip(selmergens,v)])
if len([1 for p in SprimenotS if w.valuation(p)%4 == 2]) == len(SprimenotS):
E = EllipticCurve([w,0])
if has_good_reduction_outside_S_over_K(E,S):
curves.append(E)
return curves
def egros_from_j_over_K(j,K,S):
r"""
INPUT:
- ``K`` : a number field
- ``S`` : a list of primes of ``K``
OUTPUT:
A list with all elliptic curves over ``K`` with good reduction outside ``S`` and `j`-invariant equal to
``j``.
REFERENCE:
J. E. Cremona and M. P. Lingham. Finding All Elliptic Curves with Good Reduction Outside a Given Set of Primes.
Experimental Mathematics, 16(3):303-312, 2007.
EXAMPLE::
sage:
"""
import time
if K == QQ:
from sage.schemes.elliptic_curves.ell_egros import egros_from_j
return egros_from_j(j,S)
if j == K(0):
return egros_from_0_over_K(K,S)
if j == K(1728):
return egros_from_1728_over_K(K,S)
w = j**2 * (j - 1728)**3
#the case w not in K(S,6)
if not in_KSn(w,S,6):
return []
#the case w in K(S,4)_2
J = brace_map(w,S,2)[1]
power_n, W0 = in_nCKSmn(J,S,2,2)
principal, u = is_S_principal(J/W0**2,S)
#we choose t as in the reference
curves = []
u /= 3
if power_n:
if principal:
if K.class_number() == 1:
E = EllipticCurve([-3*u**2*j*(j-1728),-2*u**3*j*(j-1728)**2]).global_minimal_model()
else:
E = EllipticCurve([-3*u**2*j*(j-1728),-2*u**3*j*(j-1728)**2]).global_minimal_model(semi_global=True)
Sel2 = K.selmer_group(S,2)
for v in cartesian_product_iterator([xrange(2)]*len(Sel2)):
t = prod([g**e for g,e in zip(Sel2,v)])
start = time.time()
Et = E.quadratic_twist(t).integral_model()
# return Et
if has_good_reduction_outside_S_over_K(Et,S):
curves.append(Et)
end = time.time()
# print 't1',end-start
return curves
def egros_from_jlist_over_K(J,K,S):
r"""
INPUT:
- ``J`` : a list of `j`-invariants
- ``K`` : a number field `K`
- ``S``: a finite set of primes of ``K``
OUTPUT:
A list of all elliptic curves over ``K`` with good reduction outside ``S`` with `j`-invariant in ``J``
EXAMPLE::
sage:
"""
return sum([egros_from_j_over_K(j,K,S) for j in J],[])
def j_invariant_of_2_isogenous(j):
r"""
INPUT:
- ``j`` : the `j`-invariant of an elliptic curve with exactly one rational point of order 2.
OUTPUT:
The `j`-invariant of its 2-isogenous curve.
"""
if j == 0:
return []
if j == 1728:
return [EllipticCurve([-4,0]).j_invariant()]
E = EllipticCurve([1,0,0,-36/(j-1728),-1/(j-1728)]).short_weierstrass_model()
roots = E.two_division_polynomial().roots()
if len(roots) == 1:
r = roots[0][0]
a1,a2,a3,a4,a6 = E.change_weierstrass_model(1,r,0,0).a_invariants()
return [EllipticCurve([0,-2*a2,0,a2**2-4*a4,0]).j_invariant()]
elif len(roots) == 3:
J = []
for r in roots:
a1,a2,a3,a4,a6 = E.change_weierstrass_model(1,r[0],0,0).a_invariants()
j = EllipticCurve([0,-2*a2,0,a2**2-4*a4,0]).j_invariant()
if j not in J:
J.append(j)
return J