/
curve_enumerator.py
2315 lines (1877 loc) · 82.2 KB
/
curve_enumerator.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
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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
A class to enumerate all elliptic curves over \\QQ up to isomorphism in a given
Weierstrass family, ordered by height.
AUTHORS:
- Simon Spicer (2012-09): First version
"""
#*****************************************************************************
# Copyright (C) 2012 William Stein and Simon Spicer
#
# Distributed under the terms of the GNU General Public License (GPL)
#
# This code is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# The full text of the GPL is available at:
#
# http://www.gnu.org/licenses/
#*****************************************************************************
import time
from copy import deepcopy
from sage.rings.integer_ring import IntegerRing, ZZ
from sage.functions.other import floor,ceil
from sage.combinat.cartesian_product import CartesianProduct
from sage.misc.misc import powerset, srange
from sage.schemes.elliptic_curves.constructor import EllipticCurve
from sage.rings.arith import valuation
from sage.misc.cachefunc import cached_method
class CurveEnumerator_abstract(object):
"""
The CurveEnumerator class will enumerate all elliptic curves
over \\QQ in a specified Weierstrass form ordered by height, where
height is a function of the Weierstrass equation of the curve
as described in each subclass's __init__() method.
"""
def __init__(self):
"""
This should never be called, as CurveEnumerater_abstract
has been designed only to be inherited from its subclasses
"""
raise NameError("Abstract class cannot be instantiated.")
def __repr__(self):
"""
Representation of self. Prints what family of curves is being considered,
the model description and the height function on that family.
EXAMPLES::
sage: C = EllipticCurveEnumerator(family="short_weierstrass"); C
Height iterator for elliptic curves over QQ
Family: Short Weierstrass
Model: Y^2 = X^3 + A*X + B
Coefficients: [A,B]
Height function: H = min{|A|^3,|B|^2}
sage: C = EllipticCurveEnumerator(family="F_2(2)"); C
Height iterator for elliptic curves over QQ
Family: Rank Two + Two Torsion
Model: Y^2 = X^3 + A*X^2 + B, where
A = 1/4*(2*(w0^2+w1^2+w2^2+w3^2) - (w0+w1+w2+w3)^2), and
B = w0*w1*w2*w3
Coefficients: [w0,w1,w2,w3]
Height function: H = min{|w0|,|w1|,|w2|,|w3|}
"""
s = "Height iterator for elliptic curves over QQ\n"
s += "Family: "+self._name+"\n"
s += "Model: "+self._model+"\n"
s += "Coefficients: "+self._coeff_names+"\n"
s += "Height function: "+self._height_function
s += "Height bounds: "+str(self._height_lower_bound)+" to "+str(self._height_upper_bound)
return s
def _height_increment(self,coeffs):
"""
Given a tuple of coefficients of a Weierstrass equation with
a certain height, return the next largest permissable height
and the range of coefficients that achieve that height.
INPUT:
- ``coeffs`` -- A list or tuple of coefficients of the
same length as the number of coeffients in the model.
OUTPUT:
A tuple of three entries consisting of:
1. The smallest permissable height greater than the height
of the input coefficient list;
2. A list of coeffients, some of which attain the above
height;
3. A list of indices of which of the coefficients in the
above list achieve this height. The remaining entries
in the coefficient list indicate the maximum absolute
value that coefficient can attain without affecting the
curve's height.
EXAMPLES::
sage: C = EllipticCurveEnumerator(family="short_weierstrass")
sage: C._height_increment([2,2])
(9, [2, 3], [1])
sage: C._height_increment([3,7])
(64, [4, 8], [0, 1])
"""
I = range(len(coeffs))
height_candidates = [(coeffs[i]+1)**(self._pows[i]) for i in I]
next_height = min(height_candidates)
index = []
new_coeffs = list(coeffs)
for i in I:
if height_candidates[i]==next_height:
new_coeffs[i] += 1
index.append(i)
return (next_height,new_coeffs,index)
def next_height(self, N):
"""
Return the next permissable height greater than or equal to N for
curves in self's family.
WARNING: This function my return a height for which only singular
curves exist. For example, in the short Weierstrass case
height 0 is permissable, as the curve Y^2 = X^3 (uniquely)
has height zero.
INPUT:
- ``N`` -- An integer. Note that N may be negative, even though height
is always non-negative.
OUTPUT:
A tuple consisting of three elements of the form (H, C, I) such that
1. H is the smallest height >= N (so if N<0, H will be 0)
2. C is a list of coefficients for curves of this height
3. I is list of indices indicating which of the above coefficients
achieve this height. The remaining values in C indicate the
max absolute value those coefficients are allowed to obtain
without altering the height.
For example, the tuple (4, [1, 2], [1]) for the short Weierstrass
case denotes set of curves with height 4; these are all of the
form Y^2 = X^3 + A*X + B, where B=2 and A ranges between -1 and 1.
EXAMPLES::
sage: C = EllipticCurveEnumerator(family="short_weierstrass")
sage: C.next_height(4)
(4, [1, 2], [1])
sage: C.next_height(60)
(64, [4, 8], [0, 1])
sage: C.next_height(-100)
(0, [0, 0], [0, 1])
"""
# Negative heights don't exist
if N<0: N=ZZ(0)
coeffs = [ceil(N**(1/n))-1 for n in self._pows]
height = max([coeffs[i]**(self._pows[i]) for i in range(self._num_coeffs)])
return self._height_increment(coeffs)
def heights(self, lowerbound, upperbound):
"""
Return a list of permissable curve heights in the specified range
(bounds inclusive), and for each height the equation coefficients
that produce curves of that height.
WARNING: This function my return heights for which only singular
curves exist. For example, in the short Weierstrass case
height 0 is permissable, as the curve Y^2 = X^3 (uniquely)
has height zero.
INPUT:
- ``lowerbound`` -- Lower bound for the height range;
- ``upperbound`` -- Upper bound for the height range. Heights
returned are up to and including both bounds.
OUTPUT:
A list of tuples, each consisting of three elements of the form
(H, C, I) such that
1. H is the smallest height >= N
2. C is a list of coefficients for curves of this height
3. I is a list of indices indicating which of the above coefficients
achieve this height. The remaining values in C indicate the
max absolute value those coefficients are allowed to obtain
without altering the height.
For example, the tuple (4, [1, 2], [1]) for the short Weierstrass
case denotes set of curves with height 4; these are all of the
form Y^2 = X^3 + A*X + B, where B=2 and A ranges between -1 and 1.
EXAMPLES::
sage: C = EllipticCurveEnumerator(family="short_weierstrass")
sage: C.heights(100,150)
[(100, [4, 10], [1]), (121, [4, 11], [1]), (125, [5, 11], [0]), (144, [5, 12], [1])]
sage: C.heights(150,100)
Traceback (most recent call last):
...
ValueError: Height upper bound must be greater than or equal to lower bound.
sage: C.heights(-100,100)
Traceback (most recent call last):
...
ValueError: Height lower bound must be non-negative.
"""
if lowerbound < 0:
raise ValueError("Height lower bound must be non-negative.")
if upperbound < lowerbound:
raise ValueError("Height upper bound must be greater than or equal to lower bound.")
coeffs = [ceil(lowerbound**(1/n))-1 for n in self._pows]
height = max([coeffs[i]**(self._pows[i]) for i in range(self._num_coeffs)])
L = []
while height <= upperbound:
C = self._height_increment(coeffs)
if C[0] > upperbound:
break
else:
height = C[0]
coeffs = C[1]
L.append(C)
return L
def _is_singular(self, C):
"""
Tests if the a-invariants in 5-tuple C specify a singular
elliptic curve.
INPUT:
- ``C`` -- A 5-tuple/list of a-invariants of a potential
elliptic curve over Q
OUTPUT:
True or False
EXAMPLES::
sage: C = EllipticCurveEnumerator(family="short_weierstrass")
sage: C._is_singular([0,0,0,3,2])
False
sage: EllipticCurve([0,0,0,3,2])
Elliptic Curve defined by y^2 = x^3 + 3*x + 2 over Rational Field
sage: C._is_singular([0,0,0,-3,2])
True
sage: EllipticCurve([0,0,0,-3,2])
Traceback (most recent call last):
...
ArithmeticError: Invariants [0, 0, 0, -3, 2] define a singular curve.
"""
a1 = C[0]
a2 = C[1]
a3 = C[2]
a4 = C[3]
a6 = C[4]
b2 = a1**2 + 4*a2
b4 = 2*a4 + a1*a3
b6 = a3**2 + 4*a6
b8 = (a1**2)*a6 + 4*a2*a6 - a1*a3*a4 + a2*(a3**2) - a4**2
Delta = -(b2**2)*b8 - 8*(b4**3) - 27*(b6**2) + 9*b2*b4*b6
return Delta==0
def _coeffs_from_height(self, height_tuple):
"""
Returns a list of tuples of a-invariants of all curves
described by height_tuple.
INPUT:
- ``height_tuple`` -- A tuple of the form
(H, C, I) such that
H: The smallest height >= N
C: A list of coefficients for curves of this height
I: A list of indices indicating which of the above coefficients
achieve this height. The remaining values in C indicate the
max absolute value those coefficients are allowed to obtain
without altering the height.
For example, the tuple (4, [1, 2], [1]) for the short Weierstrass
case denotes set of curves with height 4; these are all of the
form Y^2 = X^3 + A*X + B, where B=2 and A ranges between -1 and 1.
OUTPUT:
A list of 2-tuples, each consisting of the given height,
followed by a tuple of a-invariants of a curve of that height.
EXAMPLES::
sage: C = EllipticCurveEnumerator(family="short_weierstrass")
sage: B = C.next_height(4); B
(4, [1, 2], [1])
sage: L = C._coeffs_from_height(B)
sage: for ell in L: print ell
(4, [0, 0, 0, -1, -2])
(4, [0, 0, 0, -1, 2])
(4, [0, 0, 0, 0, -2])
(4, [0, 0, 0, 0, 2])
(4, [0, 0, 0, 1, -2])
(4, [0, 0, 0, 1, 2])
"""
height = height_tuple[0]
coeffs = height_tuple[1]
index = height_tuple[2]
# Produce list of all coefficient tuples with given height
L = []
for S in list(powerset(index))[1:]:
B = []
for j in range(len(coeffs)):
if j in S:
B.append([-coeffs[j],coeffs[j]])
elif j in index:
B.append(srange(-coeffs[j]+1,coeffs[j]))
else:
B.append(srange(-coeffs[j],coeffs[j]+1))
C = CartesianProduct(*B).list()
for c in C:
L.append(c)
# Convert coefficient tuples to a-invariants
L2 = []
for c in L:
C = (height, self._coeffs_to_a_invariants(c))
if not self._is_singular(C[1]):
# Some families can produce duplicate sets of coefficients
if self._duplicates==False or not C in L2:
L2.append(C)
return L2
def _coeffs_from_height_list(self, coefficient_list):
"""
Return all height/a-invariant tuples of elliptic curves from a
list of curve height/coefficient/index tuples.
INPUT:
- ``coefficient_list`` -- A list of height/coefficient/index
tuples. See the documentation for _height_increment() for
a description of this format.
OUTPUT:
A list of tuples, each consisting of a height and a tuple of
a-invariants defining an elliptic curve over \\QQ of that height.
The list will be ordered by increasing height.
EXAMPLES::
sage: C = EllipticCurveEnumerator(family="short_weierstrass")
sage: B = C.heights(1,4); B
[(1, [1, 1], [0, 1]), (4, [1, 2], [1])]
sage: L = C._coeffs_from_height_list(B)
sage: for ell in L: print(ell)
(1, [0, 0, 0, -1, 0])
(1, [0, 0, 0, 1, 0])
(1, [0, 0, 0, 0, -1])
(1, [0, 0, 0, 0, 1])
(1, [0, 0, 0, -1, -1])
(1, [0, 0, 0, -1, 1])
(1, [0, 0, 0, 1, -1])
(1, [0, 0, 0, 1, 1])
(4, [0, 0, 0, -1, -2])
(4, [0, 0, 0, -1, 2])
(4, [0, 0, 0, 0, -2])
(4, [0, 0, 0, 0, 2])
(4, [0, 0, 0, 1, -2])
(4, [0, 0, 0, 1, 2])
"""
L2 = []
for C in coefficient_list:
L2 += self._coeffs_from_height(C)
return L2
def coefficients_over_height_range(self, lowerbound, upperbound,\
output_filename=None, return_data=True):
"""
Return all a-invariant tuples of elliptic curves over a given
height range, bounds inclusive.
INPUT:
- ``lowerbound`` -- The lower height bound
- ``upperbound`` -- The upper height bound
- ``output_filename`` -- (Default None): If not None, the string
name of a file to which the output will be saved.
- ``return_data`` -- (Default: True) If False, the computed
data will not be returned.
OUTPUT:
If specified, the output is written to file. Each line specifies
a single curve, and consists of six tab-separated integers in the
format
H a1 a2 a3 a4 a6
H: The height of the curve
a1..a6: The a-invariants of the curve
Curves will be ordered by increasing height.
If return_data==True, the output is returned in the form of a
list of tuples. Each tuple is of the form
(H, [a1,a2,a3,a4,a6])
where H and a1..a6 are as above.
The list will be ordered by increasing height.
EXAMPLES::
sage: C = EllipticCurveEnumerator(family="short_weierstrass")
sage: L = C.coefficients_over_height_range(0,4)
sage: for ell in L: print(ell)
(1, [0, 0, 0, -1, 0])
(1, [0, 0, 0, 1, 0])
(1, [0, 0, 0, 0, -1])
(1, [0, 0, 0, 0, 1])
(1, [0, 0, 0, -1, -1])
(1, [0, 0, 0, -1, 1])
(1, [0, 0, 0, 1, -1])
(1, [0, 0, 0, 1, 1])
(4, [0, 0, 0, -1, -2])
(4, [0, 0, 0, -1, 2])
(4, [0, 0, 0, 0, -2])
(4, [0, 0, 0, 0, 2])
(4, [0, 0, 0, 1, -2])
(4, [0, 0, 0, 1, 2])
"""
H = self.heights(lowerbound,upperbound)
L = self._coeffs_from_height_list(H)
#WAS: open(savefile,'w').write('\n'.join('\t'.join([str(a) for a in C])))
#WAS: maybe leave in, but use consistent naming, e.g., output_filename...
# Save data to file
if output_filename is not None:
out_file = open(output_filename,"w")
# for C in [flatten[C] for C in L]:
# out_file.write("\t".join([str(c) for c in C])+"\n")
for C in L:
out_file.write(str(C[0])+"\t")
for a in C[1]:
out_file.write(str(a)+"\t")
out_file.write("\n")
if return_data:
return L
def rank(self, curves, output_filename=None,problems_filename=None, \
return_data=True, print_timing=True, **rank_opts):
r"""
Compute the algebraic rank for a list of curves ordered by height.
INPUT:
- ``curves`` -- A list of height/a-invariant tuples of
curves, as returned by the coefficients_over_height_range() method
Each tuple is of the form
(H, [a1,a2,a3,a4,a6]) where
H is the height of the curve, and
[a1,...,a6] the curve's a-invariants
- ``output_filename`` -- (Default None): If not None, the string name
of the file to which the output will be saved.
- ``problems_filename`` -- (Default None): If not None, the string name
of the file to which problem curves will be written.
- ``return_data`` -- (Default True): If set to False, the data
is not returned at the end of computation.
- ``print_timing`` -- (Default True): If set to False, wall time
of total computation will not be printed.
Additional arguments are passed to the rank() method of the EllipticCurve
class.
OUTPUT:
If specified, writes computed data to file. Each line of the written file
consists of seven tab separated entries of the form
H a1 a2 a3 a4 a6 d
1. H is the curve's height
2. a1,...,a6 are the curve's a-invariants
3. d is the computed datum for that curve
If specified, writes problem curves to file. Each line of the written file
consists of seven tab separated entries of the form
H a1 a2 a3 a4 a6
1. H is the curve's height
2. a1,...,a6 are the curve's a-invariants
If return_data==True: A list consisting of two lists is returned:
The first is a list of triples of the form
(H, (a1,a2,a3,a4,a6), d)
where the entries are as above.
The second is a list of curve for which the datum could not be provably
computed; each entry of this list is just a pair consisting of height
and a-invariants.
EXAMPLES::
sage: C = EllipticCurveEnumerator(family="short_weierstrass")
sage: L = C.coefficients_over_height_range(0,4)
sage: R,P = C.rank(L,return_data=True,print_timing=False)
sage: P
[]
sage: for r in R: print(r)
(1, [0, 0, 0, -1, 0], 0)
(1, [0, 0, 0, 1, 0], 0)
(1, [0, 0, 0, 0, -1], 0)
(1, [0, 0, 0, 0, 1], 0)
(1, [0, 0, 0, -1, -1], 0)
(1, [0, 0, 0, -1, 1], 1)
(1, [0, 0, 0, 1, -1], 1)
(1, [0, 0, 0, 1, 1], 1)
(4, [0, 0, 0, -1, -2], 1)
(4, [0, 0, 0, -1, 2], 0)
(4, [0, 0, 0, 0, -2], 1)
(4, [0, 0, 0, 0, 2], 1)
(4, [0, 0, 0, 1, -2], 0)
(4, [0, 0, 0, 1, 2], 0)
"""
if print_timing:
t = time.time()
if output_filename is not None:
out_file = open(output_filename,"w")
if problems_filename is not None:
prob_file = open(problems_filename,"w")
if return_data:
output = []
problems = []
for C in curves:
# Attempt to compute rank and write curve+rank to file
try:
E = EllipticCurve(C[1])
d = E.rank(**rank_opts)
if output_filename is not None:
out_file.write(str(C[0])+"\t")
for a in C[1]:
out_file.write(str(a)+"\t")
out_file.write(str(d)+"\n")
out_file.flush()
if return_data:
output.append((C[0],C[1],d))
# Write to problem file or append to problems list if fail
except:
if problems_filename is not None:
prob_file.write(str(C[0])+"\t")
for a in C[1]:
prob_file.write(str(a)+"\t")
prob_file.write("\n")
prob_file.flush()
if return_data:
problems.append(C)
if output_filename is not None:
out_file.close()
if problems_filename is not None:
prob_file.close()
if print_timing:
print(time.time()-t)
if return_data:
return output,problems
def two_selmer(self, curves, rank=True, reduced=False,
output_filename=None, problems_filename=None, \
return_data=True, print_timing=True):
r"""
Compute rank or size of two-Selmer for a list of curves ordered by height.
INPUT:
- ``curves`` -- A list of height/a-invariant tuples of
curves, as returned by the coefficients_over_height_range() method.
Each tuple is of the form
(H, [a1,a2,a3,a4,a6]) where
H is the height of the curve, and
[a1,...,a6] the curve's a-invariants
- ``rank`` -- (Default True) Compute the rank versus size
of the curve's 2-Selmer group. If True, rank is computed; if set to
False size (i.e. 2^rank) is computed instead.
- ``reduced`` -- (Default False) Compute full 2-Selmer or
reduced 2-Selmer. If True, full 2-Selmer is computed; if False, the
reduced group rank/size (i.e. 2-Selmer rank - 2-torsion rank or
2^(2-Selmer rank - 2-torsion rank) as per whether 'rank' is set to
True or False) is computed.
- ``output_filename`` -- (Default None): If not None, the string
name of the file to which the output will be saved.
- ``problems_filename`` -- (Default None): If not None, the string name
of the file to which problem curves will be written.
- ``return_data`` -- (Default True): If set to False, the data
is not returned at the end of computation.
- ``print_timing`` -- (Default True): If set to False, wall time
of total computation will not be printed.
OUTPUT:
Writes data to file. Each line of the written file consists of seven
tab separated entries of the form
H, a1, a2, a3, a4, a6, d
H: The curve's height
a1,...,a6: The curve's a-invariants
d: The computed datum for that curve
(only if return_data==True) A list consisting of two lists:
The first is a list of triples of the form
(H, (a1,a2,a3,a4,a6), d)
where the entries are as above.
The second is a list of curve for which the datum could not be provably
computed; each entry of this list is just a pair consisting of height
and a-invariants.
EXAMPLES::
sage: C = EllipticCurveEnumerator(family="short_weierstrass")
sage: L = C.coefficients_over_height_range(4,4)
sage: R,P = C.two_selmer(L,rank=True,return_data=True,print_timing=False)
sage: P
[]
sage: for r in R: print(r)
(4, [0, 0, 0, -1, -2], 1)
(4, [0, 0, 0, -1, 2], 0)
(4, [0, 0, 0, 0, -2], 1)
(4, [0, 0, 0, 0, 2], 1)
(4, [0, 0, 0, 1, -2], 1)
(4, [0, 0, 0, 1, 2], 1)
sage: R,P = C.two_selmer(L,rank=False,return_data=True,print_timing=False)
sage: for r in R: print(r)
(4, [0, 0, 0, -1, -2], 2)
(4, [0, 0, 0, -1, 2], 1)
(4, [0, 0, 0, 0, -2], 2)
(4, [0, 0, 0, 0, 2], 2)
(4, [0, 0, 0, 1, -2], 2)
(4, [0, 0, 0, 1, 2], 2)
sage: R,P = C.two_selmer(L,reduced=True,print_timing=False)
sage: for r in R: print(r)
(4, [0, 0, 0, -1, -2], 1)
(4, [0, 0, 0, -1, 2], 0)
(4, [0, 0, 0, 0, -2], 1)
(4, [0, 0, 0, 0, 2], 1)
(4, [0, 0, 0, 1, -2], 0)
(4, [0, 0, 0, 1, 2], 0)
sage: R,P = C.two_selmer(L,rank=False,reduced=True,print_timing=False)
sage: for r in R: print(r)
(4, [0, 0, 0, -1, -2], 2)
(4, [0, 0, 0, -1, 2], 1)
(4, [0, 0, 0, 0, -2], 2)
(4, [0, 0, 0, 0, 2], 2)
(4, [0, 0, 0, 1, -2], 1)
(4, [0, 0, 0, 1, 2], 1)
"""
if print_timing:
t = time.time()
if output_filename is not None:
out_file = open(output_filename,"w")
if problems_filename is not None:
prob_file = open(problems_filename,"w")
if return_data:
output = []
problems = []
for C in curves:
# Attempt to compute datum and write curve+datum to file
try:
E = EllipticCurve(C[1])
d = E.selmer_rank()
if reduced:
d -= E.two_torsion_rank()
if not rank:
d = 2**d
if output_filename is not None:
out_file.write(str(C[0])+"\t")
for a in C[1]:
out_file.write(str(a)+"\t")
out_file.write(str(d)+"\n")
out_file.flush()
if return_data:
output.append((C[0],C[1],d))
# Write to problem file if fail
except:
if problems_filename is not None:
prob_file.write(str(C[0])+"\t")
for a in C[1]:
prob_file.write(str(a)+"\t")
prob_file.write("\n")
prob_file.flush()
if return_data:
problems.append(C)
if output_filename is not None:
out_file.close()
if problems_filename is not None:
prob_file.close()
if print_timing:
print(time.time()-t)
if return_data:
return output,problems
def three_selmer(self, curves, rank=True, reduced=False,
output_filename=None, problems_filename=None, \
proof=True, return_data=True, print_timing=True):
r"""
Compute rank or size of two-Selmer for a list of curves ordered by height
using Magma.
WARNING: This function will only work if Magma is installed.
INPUT:
- ``curves`` -- A list of height/a-invariant tuples of
curves, as returned by the coefficients_over_height_range() method.
Each tuple is of the form
(H, [a1,a2,a3,a4,a6]) where
H is the height of the curve, and
[a1,...,a6] the curve's a-invariants
- ``rank`` -- (Default True) Compute the rank versus size
of the curve's 3-Selmer group. If True, rank is computed; if set to
False size (i.e. 3^rank) is computed instead.
- ``reduced`` -- (Default False) Compute full 3-Selmer or
reduced 3-Selmer. If True, full 3-Selmer is computed; if False, the
reduced group rank/size (i.e. 3-Selmer rank - 3-torsion rank or
3^(3-Selmer rank - 3-torsion rank) as per whether 'rank' is set to
True or False) is computed.
- ``output_filename`` -- (Default None): If not None, the string
name of the file to which the output will be saved.
- ``problems_filename`` -- (Default None): If not None, the string name
of the file to which problem curves will be written.
- ``proof`` -- (Default True): If False, the Generalized
Riemann Hypothesis will not be assumed in the computing
of class group bounds in Magma (and thus will be
slower); if True, GRH will be assumed and computation
will be quicker.
- ``return_data`` -- (Default True): If set to False, the data
is not returned at the end of computation.
- ``print_timing`` -- (Default True): If set to False, wall time
of total computation will not be printed.
OUTPUT:
Writes data to file. Each line of the written file consists of seven
tab separated entries of the form
H, a1, a2, a3, a4, a6, d
H: The curve's height
a1,...,a6: The curve's a-invariants
d: The computed datum for that curve
(only if return_data==True) A list consisting of two lists:
The first is a list of triples of the form
(H, (a1,a2,a3,a4,a6), d)
where the entries are as above.
The second is a list of curve for which the datum could not be provably
computed; each entry of this list is just a pair consisting of height
and a-invariants.
EXAMPLES::
"""
from sage.interfaces.all import magma
if print_timing:
t = time.time()
if proof == False:
magma.eval('SetClassGroupBounds("GRH")')
else:
magma.eval('SetClassGroupBounds("PARI")')
if output_filename is not None:
out_file = open(output_filename,"w")
if problems_filename is not None:
prob_file = open(problems_filename,"w")
if return_data:
output = []
problems = []
for C in curves:
# Attempt to compute datum and write curve+datum to file
try:
E = EllipticCurve(C[1])
d = E.three_selmer_rank()
if reduced:
d -= valuation(E.torsion_order(),3)
if not rank:
d = 3**d
if output_filename is not None:
out_file.write(str(C[0])+"\t")
for a in C[1]:
out_file.write(str(a)+"\t")
out_file.write(str(d)+"\n")
out_file.flush()
if return_data:
output.append((C[0],C[1],d))
# Write to problem file if fail
except:
if problems_filename is not None:
prob_file.write(str(C[0])+"\t")
for a in C[1]:
prob_file.write(str(a)+"\t")
prob_file.write("\n")
prob_file.flush()
if return_data:
problems.append(C)
if output_filename is not None:
out_file.close()
if problems_filename is not None:
prob_file.close()
if print_timing:
print(time.time()-t)
if return_data:
return output,problems
def two_torsion(self, curves, rank=True,
output_filename=None, problems_filename=None, \
return_data=True, print_timing=True):
r"""
Compute rank or size of two-torsion groups for a list of curves ordered by height.
INPUT:
- ``curves`` -- A list of (height,a-invariant) tuples of
curves, as returned by the coefficients_over_height_range() method.
Each tuple is of the form
(H, [a1,a2,a3,a4,a6]) where
H is the height of the curve, and
[a1,...,a6] the curve's a-invariants
- ``rank`` -- (Default True) Compute the rank versus size
of the curve's 2-torsion group. If True, rank is computed; if set to
False size (i.e. 2^rank) is computed instead.
- ``output_filename`` -- (Default None): If not None, the string
name of the file to which the output will be saved.
- ``problems_filename`` -- (Default None): If not None, the string name
of the file to which problem curves will be written.
- ``return_data`` -- (Default True): If set to False, the data
is not returned at the end of computation.
- ``print_timing`` -- (Default True): If set to False, wall time
of total computation will not be printed.
OUTPUT:
Writes data to file. Each line of the written file consists of seven
tab separated entries of the form
H, a1, a2, a3, a4, a6, d
H: The curve's height
a1,...,a6: The curve's a-invariants
d: The computed datum for that curve
(only if return_data==True) A list consisting of two lists:
The first is a list of triples of the form
(H, (a1,a2,a3,a4,a6), d)
where the entries are as above.
The second is a list of curve for which the datum could not be provably
computed; each entry of this list is just a pair consisting of height
and a-invariants.
EXAMPLES::
sage: C = EllipticCurveEnumerator(family="short_weierstrass")
sage: L = C.coefficients_over_height_range(4,4)
sage: R,P = C.two_torsion(L,rank=True,return_data=True,print_timing=False)
sage: P
[]
sage: for r in R: print(r)
(4, [0, 0, 0, -1, -2], 0)
(4, [0, 0, 0, -1, 2], 0)
(4, [0, 0, 0, 0, -2], 0)
(4, [0, 0, 0, 0, 2], 0)
(4, [0, 0, 0, 1, -2], 1)
(4, [0, 0, 0, 1, 2], 1)
sage: R,P = C.two_torsion(L,rank=False,return_data=True,print_timing=False)
sage: for r in R: print(r)
(4, [0, 0, 0, -1, -2], 1)
(4, [0, 0, 0, -1, 2], 1)
(4, [0, 0, 0, 0, -2], 1)
(4, [0, 0, 0, 0, 2], 1)
(4, [0, 0, 0, 1, -2], 2)
(4, [0, 0, 0, 1, 2], 2)
"""
if print_timing:
t = time.time()
if output_filename is not None:
out_file = open(output_filename,"w")
if problems_filename is not None:
prob_file = open(problems_filename,"w")
if return_data:
output = []
problems = []
for C in curves:
# Attempt to compute datum and write curve+datum to file
try:
E = EllipticCurve(C[1])
d = E.two_torsion_rank()
if not rank:
d = 2**d
if output_filename is not None:
out_file.write(str(C[0])+"\t")
for a in C[1]:
out_file.write(str(a)+"\t")
out_file.write(str(d)+"\n")
out_file.flush()
if return_data:
output.append((C[0],C[1],d))
# Write to problem file if fail
except:
if problems_filename is not None:
prob_file.write(str(C[0])+"\t")
for a in C[1]:
prob_file.write(str(a)+"\t")
prob_file.write("\n")
prob_file.flush()
if return_data:
problems.append(C)
if output_filename is not None:
out_file.close()
if problems_filename is not None:
prob_file.close()
if print_timing:
print(time.time()-t)
if return_data:
return output,problems