This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
ell_generic.py
2947 lines (2315 loc) · 100 KB
/
ell_generic.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
r"""
Elliptic curves over a general ring
Sage defines an elliptic curve over a ring `R` as a 'Weierstrass Model' with
five coefficients `[a_1,a_2,a_3,a_4,a_6]` in `R` given by
`y^2 + a_1 xy + a_3 y = x^3 +a_2 x^2 +a_4 x +a_6`.
Note that the (usual) scheme-theoretic definition of an elliptic curve over `R` would require the discriminant to be a unit in `R`, Sage only imposes that the discriminant is non-zero. Also, in Magma, 'Weierstrass Model' means a model with `a1=a2=a3=0`, which is called 'Short Weierstrass Model' in Sage; these do not always exist in characteristics 2 and 3.
EXAMPLES:
We construct an elliptic curve over an elaborate base ring::
sage: p = 97; a=1; b=3
sage: R.<u> = GF(p)[]
sage: S.<v> = R[]
sage: T = S.fraction_field()
sage: E = EllipticCurve(T, [a, b]); E
Elliptic Curve defined by y^2 = x^3 + x + 3 over Fraction Field of Univariate Polynomial Ring in v over Univariate Polynomial Ring in u over Finite Field of size 97
sage: latex(E)
y^2 = x^{3} + x + 3
AUTHORS:
- William Stein (2005): Initial version
- Robert Bradshaw et al....
- John Cremona (2008-01): isomorphisms, automorphisms and twists in all characteristics
- Julian Rueth (2014-04-11): improved caching
"""
#*****************************************************************************
# Copyright (C) 2005 William Stein <wstein@gmail.com>
# Copyright (C) 2014 Julian Rueth <julian.rueth@fsfe.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
import math
from sage.rings.all import PolynomialRing
from sage.rings.polynomial.polynomial_ring import polygen, polygens
import sage.groups.additive_abelian.additive_abelian_group as groups
import sage.groups.generic as generic
import sage.plot.all as plot
from sage.plot.plot import generate_plot_points
from sage.arith.all import lcm
import sage.rings.all as rings
from sage.rings.number_field.number_field_base import is_NumberField
from sage.misc.all import prod as mul
from sage.misc.cachefunc import cached_method, cached_function
from sage.misc.fast_methods import WithEqualityById
# Schemes
import sage.schemes.projective.projective_space as projective_space
from sage.schemes.projective.projective_homset import SchemeHomset_points_abelian_variety_field
import ell_point
import ell_torsion
import constructor
import formal_group
import weierstrass_morphism as wm
sqrt = math.sqrt
exp = math.exp
oo = rings.infinity # infinity
O = rings.O # big oh
import sage.schemes.curves.projective_curve as plane_curve
def is_EllipticCurve(x):
r"""
Utility function to test if ``x`` is an instance of an Elliptic Curve class.
EXAMPLES::
sage: from sage.schemes.elliptic_curves.ell_generic import is_EllipticCurve
sage: E = EllipticCurve([1,2,3/4,7,19])
sage: is_EllipticCurve(E)
True
sage: is_EllipticCurve(0)
False
"""
return isinstance(x, EllipticCurve_generic)
class EllipticCurve_generic(WithEqualityById, plane_curve.ProjectivePlaneCurve):
r"""
Elliptic curve over a generic base ring.
EXAMPLES::
sage: E = EllipticCurve([1,2,3/4,7,19]); E
Elliptic Curve defined by y^2 + x*y + 3/4*y = x^3 + 2*x^2 + 7*x + 19 over Rational Field
sage: loads(E.dumps()) == E
True
sage: E = EllipticCurve([1,3])
sage: P = E([-1,1,1])
sage: -5*P
(179051/80089 : -91814227/22665187 : 1)
"""
def __init__(self, K, ainvs):
r"""
Construct an elliptic curve from Weierstrass `a`-coefficients.
INPUT:
- ``K`` -- a ring
- ``ainvs`` -- a list or tuple `[a_1, a_2, a_3, a_4, a_6]` of
Weierstrass coefficients.
.. NOTE::
This class should not be called directly; use
:class:`sage.constructor.EllipticCurve` to construct
elliptic curves.
EXAMPLES::
sage: E = EllipticCurve([1,2,3,4,5]); E
Elliptic Curve defined by y^2 + x*y + 3*y = x^3 + 2*x^2 + 4*x + 5 over Rational Field
sage: E = EllipticCurve(GF(7),[1,2,3,4,5]); E
Elliptic Curve defined by y^2 + x*y + 3*y = x^3 + 2*x^2 + 4*x + 5 over Finite Field of size 7
Constructor from `[a_4,a_6]` sets `a_1=a_2=a_3=0`::
sage: EllipticCurve([4,5]).ainvs()
(0, 0, 0, 4, 5)
The base ring need not be a field::
sage: EllipticCurve(IntegerModRing(91),[1,2,3,4,5])
Elliptic Curve defined by y^2 + x*y + 3*y = x^3 + 2*x^2 + 4*x + 5 over Ring of integers modulo 91
"""
self.__base_ring = K
self.__ainvs = tuple(K(a) for a in ainvs)
if self.discriminant() == 0:
raise ArithmeticError("invariants " + str(ainvs) + " define a singular curve")
PP = projective_space.ProjectiveSpace(2, K, names='xyz');
x, y, z = PP.coordinate_ring().gens()
a1, a2, a3, a4, a6 = ainvs
f = y**2*z + (a1*x + a3*z)*y*z \
- (x**3 + a2*x**2*z + a4*x*z**2 + a6*z**3)
plane_curve.ProjectivePlaneCurve.__init__(self, PP, f)
# See #1975: we deliberately set the class to
# EllipticCurvePoint_finite_field for finite rings, so that we
# can do some arithmetic on points over Z/NZ, for teaching
# purposes.
from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing
if is_IntegerModRing(K):
self._point = ell_point.EllipticCurvePoint_finite_field
_point = ell_point.EllipticCurvePoint
def _defining_params_(self):
r"""
Internal function. Returns a tuple of the base ring of this
elliptic curve and its `a`-invariants, from which it can be
reconstructed.
EXAMPLES::
sage: E=EllipticCurve(QQ,[1,1])
sage: E._defining_params_()
(Rational Field, [0, 0, 0, 1, 1])
sage: EllipticCurve(*E._defining_params_()) == E
True
"""
return (self.__base_ring, list(self.__ainvs))
def _repr_(self):
"""
String representation of elliptic curve.
EXAMPLES::
sage: E=EllipticCurve([1,2,3,4,5]); E._repr_()
'Elliptic Curve defined by y^2 + x*y + 3*y = x^3 + 2*x^2 + 4*x + 5 over Rational Field'
::
sage: R.<x> = QQ['x']
sage: K.<a> = NumberField(x^3-17)
sage: EllipticCurve([a^2-3, -2/3*a + 3])
Elliptic Curve defined by y^2 = x^3 + (a^2-3)*x + (-2/3*a+3) over Number Field in a
with defining polynomial x^3 - 17
"""
#return "Elliptic Curve with a-invariants %s over %s"%(self.ainvs(), self.base_ring())
b = self.ainvs()
#return "y^2 + %s*x*y + %s*y = x^3 + %s*x^2 + %s*x + %s"%\
# (a[0], a[2], a[1], a[3], a[4])
a = [z._coeff_repr() for z in b]
s = "Elliptic Curve defined by "
s += "y^2 "
if a[0] == "-1":
s += "- x*y "
elif a[0] == '1':
s += "+ x*y "
elif b[0]:
s += "+ %s*x*y "%a[0]
if a[2] == "-1":
s += "- y "
elif a[2] == '1':
s += "+ y "
elif b[2]:
s += "+ %s*y "%a[2]
s += "= x^3 "
if a[1] == "-1":
s += "- x^2 "
elif a[1] == '1':
s += "+ x^2 "
elif b[1]:
s += "+ %s*x^2 "%a[1]
if a[3] == "-1":
s += "- x "
elif a[3] == '1':
s += "+ x "
elif b[3]:
s += "+ %s*x "%a[3]
if a[4] == '-1':
s += "- 1 "
elif a[4] == '1':
s += "+ 1 "
elif b[4]:
s += "+ %s "%a[4]
s = s.replace("+ -","- ")
s += "over %s"%self.base_ring()
return s
def _latex_(self):
"""
Internal function. Returns a latex string for this elliptic curve.
Users will normally use latex() instead.
EXAMPLES::
sage: E = EllipticCurve(QQ, [1,1])
sage: E._latex_()
'y^2 = x^{3} + x + 1 '
sage: E = EllipticCurve(QQ, [1,2,3,4,5])
sage: E._latex_()
'y^2 + x y + 3 y = x^{3} + 2 x^{2} + 4 x + 5 '
Check that :trac:`12524` is solved::
sage: K.<phi> = NumberField(x^2-x-1)
sage: E = EllipticCurve([0,0,phi,27*phi-43,-80*phi+128])
sage: E._latex_()
'y^2 + \\phi y = x^{3} + \\left(27 \\phi - 43\\right) x - 80 \\phi + 128 '
"""
from sage.rings.polynomial.polynomial_ring import polygen
a = self.ainvs()
x, y = polygen(self.base_ring(), 'x, y')
s = "y^2"
if a[0] or a[2]:
s += " + " + (a[0]*x*y + a[2]*y)._latex_()
s += " = "
s += (x**3 + a[1]*x**2 + a[3]*x + a[4])._latex_()
s += " "
s = s.replace("+ -","- ")
return s
def _pari_init_(self):
"""
Internal function. Returns a string to initialize this elliptic
curve in the PARI system.
EXAMPLES::
sage: E=EllipticCurve(QQ,[1,1])
sage: E._pari_init_()
'ellinit([0/1,0/1,0/1,1/1,1/1])'
"""
return 'ellinit([%s])'%(','.join([x._pari_init_() for x in self.ainvs()]))
def _magma_init_(self, magma):
"""
Internal function. Returns a string to initialize this elliptic
curve in the Magma subsystem.
EXAMPLES::
sage: E = EllipticCurve(QQ,[1,1])
sage: E._magma_init_(magma) # optional - magma
'EllipticCurve([_sage_ref...|0/1,0/1,0/1,1/1,1/1])'
sage: E = EllipticCurve(GF(41),[2,5]) # optional - magma
sage: E._magma_init_(magma) # optional - magma
'EllipticCurve([_sage_ref...|GF(41)!0,GF(41)!0,GF(41)!0,GF(41)!2,GF(41)!5])'
sage: E = EllipticCurve(GF(25,'a'), [0,0,1,4,0])
sage: magma(E) # optional - magma
Elliptic Curve defined by y^2 + y = x^3 + 4*x over GF(5^2)
sage: magma(EllipticCurve([1/2,2/3,-4/5,6/7,8/9])) # optional - magma
Elliptic Curve defined by y^2 + 1/2*x*y - 4/5*y = x^3 + 2/3*x^2 + 6/7*x + 8/9 over Rational Field
sage: R.<x> = Frac(QQ['x'])
sage: magma(EllipticCurve([x,1+x])) # optional - magma
Elliptic Curve defined by y^2 = x^3 + x*x + (x + 1) over Univariate rational function field over Rational Field
"""
kmn = magma(self.base_ring())._ref()
return 'EllipticCurve([%s|%s])'%(kmn,','.join([x._magma_init_(magma) for x in self.ainvs()]))
def _symbolic_(self, SR):
r"""
Many elliptic curves can be converted into a symbolic expression
using the ``symbolic_expression`` command.
EXAMPLES: We find a torsion point on 11a.
::
sage: E = EllipticCurve('11a')
sage: E._symbolic_(SR)
y^2 + y == x^3 - x^2 - 10*x - 20
sage: E.torsion_subgroup().gens()
((5 : 5 : 1),)
We find the corresponding symbolic equality::
sage: eqn = symbolic_expression(E); eqn
y^2 + y == x^3 - x^2 - 10*x - 20
We verify that the given point is on the curve::
sage: eqn(x=5,y=5)
30 == 30
sage: bool(eqn(x=5,y=5))
True
We create a single expression::
sage: F = eqn.lhs() - eqn.rhs(); F
-x^3 + x^2 + y^2 + 10*x + y + 20
sage: y = var('y')
sage: F.solve(y)
[y == -1/2*sqrt(4*x^3 - 4*x^2 - 40*x - 79) - 1/2,
y == 1/2*sqrt(4*x^3 - 4*x^2 - 40*x - 79) - 1/2]
You can also solve for x in terms of y, but the result is
horrendous. Continuing with the above example, we can explicitly
find points over random fields by substituting in values for x::
sage: v = F.solve(y)[0].rhs(); v
-1/2*sqrt(4*x^3 - 4*x^2 - 40*x - 79) - 1/2
sage: v = v.function(x)
sage: v(3)
-1/2*sqrt(-127) - 1/2
sage: v(7)
-1/2*sqrt(817) - 1/2
sage: v(-7)
-1/2*sqrt(-1367) - 1/2
sage: v(sqrt(2))
-1/2*sqrt(-32*sqrt(2) - 87) - 1/2
We can even do arithmetic with them, as follows::
sage: E2 = E.change_ring(SR); E2
Elliptic Curve defined by y^2 + y = x^3 + (-1)*x^2 + (-10)*x + (-20) over Symbolic Ring
sage: P = E2.point((3, v(3), 1), check=False) # the check=False option doesn't verify that y^2 = f(x)
sage: P
(3 : -1/2*sqrt(-127) - 1/2 : 1)
sage: P + P
(-756/127 : 41143/32258*sqrt(-127) - 1/2 : 1)
We can even throw in a transcendental::
sage: w = E2.point((pi,v(pi),1), check=False); w
(pi : -1/2*sqrt(-40*pi + 4*pi^3 - 4*pi^2 - 79) - 1/2 : 1)
sage: x, y, z = w; ((y^2 + y) - (x^3 - x^2 - 10*x - 20)).expand()
0
sage: 2*w
(-2*pi + (2*pi - 3*pi^2 + 10)^2/(-40*pi + 4*pi^3 - 4*pi^2 - 79) + 1 : (3*pi - (2*pi - 3*pi^2 + 10)^2/(-40*pi + 4*pi^3 - 4*pi^2 - 79) - 1)*(2*pi - 3*pi^2 + 10)/sqrt(-40*pi + 4*pi^3 - 4*pi^2 - 79) + 1/2*sqrt(-40*pi + 4*pi^3 - 4*pi^2 - 79) - 1/2 : 1)
sage: x, y, z = 2*w; temp = ((y^2 + y) - (x^3 - x^2 - 10*x - 20))
This is a point on the curve::
sage: bool(temp == 0)
True
"""
a = [SR(x) for x in self.a_invariants()]
x, y = SR.var('x, y')
return y**2 + a[0]*x*y + a[2]*y == x**3 + a[1]*x**2 + a[3]*x + a[4]
def __contains__(self, P):
"""
Returns True if and only if P is a point on the elliptic curve. P
just has to be something that can be coerced to a point.
EXAMPLES::
sage: E = EllipticCurve([0, 0, 1, -1, 0])
sage: (0,0) in E
True
sage: (1,3) in E
False
sage: E = EllipticCurve([GF(7)(0), 1])
sage: [0,0] in E
False
sage: [0,8] in E
True
sage: P = E(0,8)
sage: P
(0 : 1 : 1)
sage: P in E
True
"""
if not isinstance(P, ell_point.EllipticCurvePoint):
try:
P = self(P)
except TypeError:
return False
if P.curve() == self:
return True
x, y, a = P[0], P[1], self.ainvs()
return y**2 + a[0]*x*y + a[2]*y == x**3 + a[1]*x**2 + a[3]*x + a[4]
def __call__(self, *args, **kwds):
r"""
EXAMPLES::
sage: E = EllipticCurve([0, 0, 1, -1, 0])
The point at infinity, which is the 0 element of the group::
sage: E(0)
(0 : 1 : 0)
The origin is a point on our curve::
sage: P = E([0,0])
sage: P
(0 : 0 : 1)
The curve associated to a point::
sage: P.curve()
Elliptic Curve defined by y^2 + y = x^3 - x over Rational Field
Points can be specified by given a 2-tuple or 3-tuple::
sage: E([0,0])
(0 : 0 : 1)
sage: E([0,1,0])
(0 : 1 : 0)
Over a field, points are normalized so the 3rd entry (if non-zero)
is 1::
sage: E(105, -69, 125)
(21/25 : -69/125 : 1)
We create points on an elliptic curve over a prime finite field::
sage: E = EllipticCurve([GF(7)(0), 1])
sage: E([2,3])
(2 : 3 : 1)
sage: E([0,0])
Traceback (most recent call last):
...
TypeError: Coordinates [0, 0, 1] do not define a point on Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field of size 7
We create a point on an elliptic curve over a number field::
sage: x = polygen(RationalField())
sage: K = NumberField(x**3 + x + 1, 'a'); a = K.gen()
sage: E = EllipticCurve([a,a])
sage: E
Elliptic Curve defined by y^2 = x^3 + a*x + a over Number Field in a with defining polynomial x^3 + x + 1
sage: E = EllipticCurve([K(1),1])
sage: E
Elliptic Curve defined by y^2 = x^3 + x + 1 over Number Field in a with defining polynomial x^3 + x + 1
sage: P = E([a,0,1])
sage: P
(a : 0 : 1)
sage: P+P
(0 : 1 : 0)
Another example involving p-adics::
sage: E = EllipticCurve('37a1')
sage: P = E([0,0]); P
(0 : 0 : 1)
sage: R = pAdicField(3,20)
sage: Ep = E.base_extend(R); Ep
Elliptic Curve defined by y^2 + (1+O(3^20))*y = x^3 + (2+2*3+2*3^2+2*3^3+2*3^4+2*3^5+2*3^6+2*3^7+2*3^8+2*3^9+2*3^10+2*3^11+2*3^12+2*3^13+2*3^14+2*3^15+2*3^16+2*3^17+2*3^18+2*3^19+O(3^20))*x over 3-adic Field with capped relative precision 20
sage: Ep(P)
(0 : 0 : 1 + O(3^20))
Constructing points from the torsion subgroup (which is an abstract
abelian group)::
sage: E = EllipticCurve('14a1')
sage: T = E.torsion_subgroup()
sage: [E(t) for t in T]
[(0 : 1 : 0),
(9 : 23 : 1),
(2 : 2 : 1),
(1 : -1 : 1),
(2 : -5 : 1),
(9 : -33 : 1)]
::
sage: E = EllipticCurve([0,0,0,-49,0])
sage: T = E.torsion_subgroup()
sage: [E(t) for t in T]
[(0 : 1 : 0), (-7 : 0 : 1), (0 : 0 : 1), (7 : 0 : 1)]
::
sage: E = EllipticCurve('37a1')
sage: T = E.torsion_subgroup()
sage: [E(t) for t in T]
[(0 : 1 : 0)]
"""
if len(args) == 1 and args[0] == 0:
R = self.base_ring()
return self.point([R(0),R(1),R(0)], check=False)
P = args[0]
if isinstance(P, groups.AdditiveAbelianGroupElement) and isinstance(P.parent(),ell_torsion.EllipticCurveTorsionSubgroup):
return self(P.element())
if isinstance(args[0],
(ell_point.EllipticCurvePoint_field, \
ell_point.EllipticCurvePoint_number_field, \
ell_point.EllipticCurvePoint)):
# check if denominator of the point contains a factor of the
# characteristic of the base ring. if so, coerce the point to
# infinity.
characteristic = self.base_ring().characteristic()
if characteristic != 0 and isinstance(args[0][0], rings.Rational) and isinstance(args[0][1], rings.Rational):
if rings.mod(args[0][0].denominator(),characteristic) == 0 or rings.mod(args[0][1].denominator(),characteristic) == 0:
return self._reduce_point(args[0], characteristic)
args = tuple(args[0])
return plane_curve.ProjectivePlaneCurve.__call__(self, *args, **kwds)
def _reduce_point(self, R, p):
r"""
Reduces a point R on an elliptic curve to the corresponding point on
the elliptic curve reduced modulo p.
Used to coerce points between
curves when p is a factor of the denominator of one of the
coordinates.
This functionality is used internally in the ``call`` method for
elliptic curves.
INPUT:
- R -- a point on an elliptic curve
- p -- a prime
OUTPUT:
S -- the corresponding point of the elliptic curve containing
R, but reduced modulo p
EXAMPLES:
Suppose we have a point with large height on a rational elliptic curve
whose denominator contains a factor of 11::
sage: E = EllipticCurve([1,-1,0,94,9])
sage: R = E([0,3]) + 5*E([8,31])
sage: factor(R.xy()[0].denominator())
2^2 * 11^2 * 1457253032371^2
Since 11 is a factor of the denominator, this point corresponds to the
point at infinity on the same curve but reduced modulo 11. The reduce
function tells us this::
sage: E11 = E.change_ring(GF(11))
sage: S = E11._reduce_point(R, 11)
sage: E11(S)
(0 : 1 : 0)
The 0 point reduces as expected::
sage: E11._reduce_point(E(0), 11)
(0 : 1 : 0)
Note that one need not explicitly call
\code{EllipticCurve._reduce_point}
"""
if R.is_zero():
return R.curve().change_ring(rings.GF(p))(0)
x, y = R.xy()
d = lcm(x.denominator(), y.denominator())
return R.curve().change_ring(rings.GF(p))([x*d, y*d, d])
def is_x_coord(self, x):
r"""
Returns True if ``x`` is the `x`-coordinate of a point on this curve.
.. note::
See also ``lift_x()`` to find the point(s) with a given
`x`-coordinate. This function may be useful in cases where
testing an element of the base field for being a square is
faster than finding its square root.
EXAMPLES::
sage: E = EllipticCurve('37a'); E
Elliptic Curve defined by y^2 + y = x^3 - x over Rational Field
sage: E.is_x_coord(1)
True
sage: E.is_x_coord(2)
True
There are no rational points with x-coordinate 3::
sage: E.is_x_coord(3)
False
However, there are such points in `E(\RR)`::
sage: E.change_ring(RR).is_x_coord(3)
True
And of course it always works in `E(\CC)`::
sage: E.change_ring(RR).is_x_coord(-3)
False
sage: E.change_ring(CC).is_x_coord(-3)
True
AUTHORS:
- John Cremona (2008-08-07): adapted from lift_x()
TEST::
sage: E=EllipticCurve('5077a1')
sage: [x for x in srange(-10,10) if E.is_x_coord (x)]
[-3, -2, -1, 0, 1, 2, 3, 4, 8]
::
sage: F=GF(32,'a')
sage: E=EllipticCurve(F,[1,0,0,0,1])
sage: set([P[0] for P in E.points() if P!=E(0)]) == set([x for x in F if E.is_x_coord(x)])
True
"""
K = self.base_ring()
try:
x = K(x)
except TypeError:
raise TypeError('x must be coercible into the base ring of the curve')
a1, a2, a3, a4, a6 = self.ainvs()
fx = ((x + a2) * x + a4) * x + a6
if a1.is_zero() and a3.is_zero():
return fx.is_square()
b = (a1*x + a3)
if K.characteristic() == 2:
R = PolynomialRing(K, 'y')
F = R([-fx,b,1])
return len(F.roots())>0
D = b*b + 4*fx
return D.is_square()
def lift_x(self, x, all=False):
r"""
Returns one or all points with given `x`-coordinate.
INPUT:
- ``x`` -- an element of the base ring of the curve.
- ``all`` (bool, default False) -- if True, return a (possibly
empty) list of all points; if False, return just one point,
or raise a ValueError if there are none.
.. note::
See also ``is_x_coord()``.
EXAMPLES::
sage: E = EllipticCurve('37a'); E
Elliptic Curve defined by y^2 + y = x^3 - x over Rational Field
sage: E.lift_x(1)
(1 : 0 : 1)
sage: E.lift_x(2)
(2 : 2 : 1)
sage: E.lift_x(1/4, all=True)
[(1/4 : -3/8 : 1), (1/4 : -5/8 : 1)]
There are no rational points with `x`-coordinate 3::
sage: E.lift_x(3)
Traceback (most recent call last):
...
ValueError: No point with x-coordinate 3 on Elliptic Curve defined by y^2 + y = x^3 - x over Rational Field
However, there are two such points in `E(\RR)`::
sage: E.change_ring(RR).lift_x(3, all=True)
[(3.00000000000000 : 4.42442890089805 : 1.00000000000000), (3.00000000000000 : -5.42442890089805 : 1.00000000000000)]
And of course it always works in `E(\CC)`::
sage: E.change_ring(RR).lift_x(.5, all=True)
[]
sage: E.change_ring(CC).lift_x(.5)
(0.500000000000000 : -0.500000000000000 + 0.353553390593274*I : 1.00000000000000)
We can perform these operations over finite fields too::
sage: E = E.change_ring(GF(17)); E
Elliptic Curve defined by y^2 + y = x^3 + 16*x over Finite Field of size 17
sage: E.lift_x(7)
(7 : 11 : 1)
sage: E.lift_x(3)
Traceback (most recent call last):
...
ValueError: No point with x-coordinate 3 on Elliptic Curve defined by y^2 + y = x^3 + 16*x over Finite Field of size 17
Note that there is only one lift with `x`-coordinate 10 in
`E(\GF{17})`::
sage: E.lift_x(10, all=True)
[(10 : 8 : 1)]
We can lift over more exotic rings too::
sage: E = EllipticCurve('37a');
sage: E.lift_x(pAdicField(17, 5)(6))
(6 + O(17^5) : 2 + 16*17 + 16*17^2 + 16*17^3 + 16*17^4 + O(17^5) : 1 + O(17^5))
sage: K.<t> = PowerSeriesRing(QQ, 't', 5)
sage: E.lift_x(1+t)
(1 + t : 2*t - t^2 + 5*t^3 - 21*t^4 + O(t^5) : 1)
sage: K.<a> = GF(16)
sage: E = E.change_ring(K)
sage: E.lift_x(a^3)
(a^3 : a^3 + a : 1)
AUTHOR:
- Robert Bradshaw (2007-04-24)
TEST::
sage: E = EllipticCurve('37a').short_weierstrass_model().change_ring(GF(17))
sage: E.lift_x(3, all=True)
[]
sage: E.lift_x(7, all=True)
[(7 : 3 : 1), (7 : 14 : 1)]
"""
a1, a2, a3, a4, a6 = self.ainvs()
f = ((x + a2) * x + a4) * x + a6
K = self.base_ring()
x += K(0)
one = x.parent()(1)
if a1.is_zero() and a3.is_zero():
if f.is_square():
if all:
ys = f.sqrt(all=True)
return [self.point([x, y, one], check=False) for y in ys]
else:
return self.point([x, f.sqrt(), one], check=False)
else:
b = (a1*x + a3)
D = b*b + 4*f
if K.characteristic() == 2:
R = PolynomialRing(K, 'y')
F = R([-f,b,1])
ys = F.roots(multiplicities=False)
if all:
return [self.point([x, y, one], check=False) for y in ys]
elif len(ys) > 0:
return self.point([x, ys[0], one], check=False)
elif D.is_square():
if all:
return [self.point([x, (-b+d)/2, one], check=False) for d in D.sqrt(all=True)]
else:
return self.point([x, (-b+D.sqrt())/2, one], check=False)
if all:
return []
else:
raise ValueError("No point with x-coordinate %s on %s"%(x, self))
def _point_homset(self, *args, **kwds):
r"""
Internal function. Returns the (abstract) group of points on this
elliptic curve over a ring.
EXAMPLES::
sage: E=EllipticCurve(GF(5),[1,1])
sage: E._point_homset(Spec(GF(5^10,'a'),GF(5)), E)
Abelian group of points on Elliptic Curve defined
by y^2 = x^3 + x + 1 over Finite Field in a of size 5^10
Point sets of elliptic curves are unique (see :trac:`17008`)::
sage: E = EllipticCurve([2, 3])
sage: E.point_homset() is E.point_homset(QQ)
True
sage: @fork
....: def compute_E():
....: E = EllipticCurve([2, 3])
....: p = E(3, 6, 1)
....: return p
....:
sage: p = compute_E()
sage: 2*p
(-23/144 : 2827/1728 : 1)
"""
return SchemeHomset_points_abelian_variety_field(*args, **kwds)
def __getitem__(self, n):
r"""
Placeholder for standard indexing function.
EXAMPLES::
sage: E=EllipticCurve(QQ,[1,1])
sage: E[2]
Traceback (most recent call last):
...
NotImplementedError: not implemented.
"""
raise NotImplementedError("not implemented.")
def __is_over_RationalField(self):
r"""
Internal function. Returns true iff the base ring of this elliptic
curve is the field of rational numbers.
EXAMPLES::
sage: E=EllipticCurve(QQ,[1,1])
sage: E._EllipticCurve_generic__is_over_RationalField()
True
sage: E=EllipticCurve(GF(5),[1,1])
sage: E._EllipticCurve_generic__is_over_RationalField()
False
"""
return isinstance(self.base_ring(), rings.RationalField)
def is_on_curve(self, x, y):
r"""
Returns True if `(x,y)` is an affine point on this curve.
INPUT:
- ``x``, ``y`` - elements of the base ring of the curve.
EXAMPLES::
sage: E=EllipticCurve(QQ,[1,1])
sage: E.is_on_curve(0,1)
True
sage: E.is_on_curve(1,1)
False
"""
a = self.ainvs()
return y**2 +a[0]*x*y + a[2]*y == x**3 + a[1]*x**2 + a[3]*x + a[4]
def a_invariants(self):
r"""
The `a`-invariants of this elliptic curve, as a tuple.
OUTPUT:
(tuple) - a 5-tuple of the `a`-invariants of this elliptic curve.
EXAMPLES::
sage: E = EllipticCurve([1,2,3,4,5])
sage: E.a_invariants()
(1, 2, 3, 4, 5)
sage: E = EllipticCurve([0,1])
sage: E
Elliptic Curve defined by y^2 = x^3 + 1 over Rational Field
sage: E.a_invariants()
(0, 0, 0, 0, 1)
sage: E = EllipticCurve([GF(7)(3),5])
sage: E.a_invariants()
(0, 0, 0, 3, 5)
::
sage: E = EllipticCurve([1,0,0,0,1])
sage: E.a_invariants()[0] = 100000000
Traceback (most recent call last):
...
TypeError: 'tuple' object does not support item assignment
"""
return self.__ainvs
ainvs = a_invariants
def a1(self):
r"""
Returns the `a_1` invariant of this elliptic curve.
EXAMPLES::
sage: E = EllipticCurve([1,2,3,4,6])
sage: E.a1()
1
"""
return self.__ainvs[0]
def a2(self):
r"""
Returns the `a_2` invariant of this elliptic curve.
EXAMPLES::
sage: E = EllipticCurve([1,2,3,4,6])
sage: E.a2()
2
"""
return self.__ainvs[1]
def a3(self):
r"""
Returns the `a_3` invariant of this elliptic curve.
EXAMPLES::
sage: E = EllipticCurve([1,2,3,4,6])
sage: E.a3()
3
"""
return self.__ainvs[2]
def a4(self):
r"""
Returns the `a_4` invariant of this elliptic curve.
EXAMPLES::
sage: E = EllipticCurve([1,2,3,4,6])
sage: E.a4()
4
"""
return self.__ainvs[3]
def a6(self):
r"""
Returns the `a_6` invariant of this elliptic curve.
EXAMPLES::
sage: E = EllipticCurve([1,2,3,4,6])
sage: E.a6()
6
"""
return self.__ainvs[4]
def b_invariants(self):
r"""
Returns the `b`-invariants of this elliptic curve, as a tuple.
OUTPUT:
(tuple) - a 4-tuple of the `b`-invariants of this elliptic curve.
EXAMPLES::
sage: E = EllipticCurve([0, -1, 1, -10, -20])
sage: E.b_invariants()
(-4, -20, -79, -21)
sage: E = EllipticCurve([-4,0])
sage: E.b_invariants()
(0, -8, 0, -16)
::
sage: E = EllipticCurve([1,2,3,4,5])
sage: E.b_invariants()
(9, 11, 29, 35)
sage: E.b2()
9
sage: E.b4()
11
sage: E.b6()