////////////////////////////////////////////////////////////////////////////////////////////////
//
//     Torsion over Q for CM elliptic curves
//
// 		Enrique González-Jiménez
//
///////////////////////////////////////////////////////////////////////////
// Magma 2.24
//////////////////////////////////////////////////////////////////////////
load "CM_aux.m";
// OLSON: Phi^CM(1)={C1,C2,C3,C4,C6,C2xC2}
////////////////////////////////////////////////////////////////////////////////////////////////
// 
// Torsion over Q for CM and D ne -3.-4
// i.e. only quadratic twists
//
// 		Enrique González-Jiménez
//
////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////
// Trivial Torsion over Q for D in [-11,-19,-43,-67,-163] 
 boo:=&and[&and[#Roots(DivisionPolynomial(CM_EllipticCurve(D,1),p)) eq 0 : p in [2,3]] : D in [-11,-19,-43,-67,-163]];
 assert boo;
 
 ///////////////////////////////////////////////
 // Torsion Z/2Z over Q for D in [-7,-28,-8] 

 boo1:=&and[&and[#Roots(PrimitiveDivisionPolynomial(CM_EllipticCurve(D,1),p)) eq 0 : p in [4,3]] : D in [-7,-28,-8]];
 boo2:=&and[#Roots(PrimitiveDivisionPolynomial(CM_EllipticCurve(D,1),2)) eq 1 : D in [-7,-28,-8]];
 assert boo1 and boo2; 
 
///////////////////////////////////////////////
//D:=-16;
 D:=-16;
 E,AB:=CM_EllipticCurve(D,1);
 // One point of order 2 over Q
 boo2:=#Roots(DivisionPolynomial(E,2)) eq 1;
 // No points of order 3 over Q
 boo3:=#Roots(DivisionPolynomial(E,3)) eq 0;
 assert boo2 and boo3;
 // Study of points of order 4 over Q
 R4:=[r[1] : r in Roots(PrimitiveDivisionPolynomial(E,4))];
 // Torsion Z/4Z over Q for D=-16 and quadratic twist d=1,2 
 // and Torsion Z/2Z over Q for D=-16 and quadratic twist d\ne 1,2
 assert [1,2] eq [Squarefree(Integers()!(r^3+AB[1]*r+AB[2])) : r in R4];

///////////////////////////////////////////////
//D:=-27;
 D:=-27;
 E,AB:=CM_EllipticCurve(D,1);
 // No points of order 2 over Q
 boo2:=#Roots(DivisionPolynomial(E,2)) eq 0;
 assert boo2;
 // Study of points of order 3 over Q
 R3:=[r[1] : r in Roots(PrimitiveDivisionPolynomial(E,3))];
 // Torsion Z/3Z over Q for D=-27 and quadratic twist d=1 
 // and Trivial Torsion over Q for D=-27 and quadratic twist d\ne 1
 assert [1] eq [Squarefree(Integers()!(r^3+AB[1]*r+AB[2])) : r in R3];

///////////////////////////////////////////////
//D:=-12;
 D:=-12;
 E,AB:=CM_EllipticCurve(D,1);
 // One point of order 2 over Q
 boo2:=#Roots(DivisionPolynomial(E,2)) eq 1;
 assert boo2;
 // Study of points of order 3 over Q
 R3:=[r[1] : r in Roots(PrimitiveDivisionPolynomial(E,3))];
 // Torsion Z/6Z over Q for D=-12 and quadratic twist d=1 
 // and Torsion Z/2Zover Q for D=-12 and quadratic twist d\ne 1
 assert [1] eq [Squarefree(Integers()!(r^3+AB[1]*r+AB[2])) : r in R3];
 R4:=[r[1] : r in Roots(PrimitiveDivisionPolynomial(E,4))];
 assert #R4 eq 0;
///////////////////////////////////////////////
//D:=-4;
R<d>:=RationalFunctionField(Rationals());
E:=EllipticCurve([d,0]);
_<x>:=PolynomialRing(R);
// Study points of order 2
P2:=PrimitiveDivisionPolynomial(E,2);
PP2:=Factorization(P2);
r:=Roots(P2);
assert #r eq 1;
r0:=r[1,1];
assert 0 eq r0^3+d*r0;
// (0,0) is always a point of order 2 in the curve y^2=x^3+d*x
f:=PP2[2][1];
assert f eq x^2 + d;
// Torsion C2xC2 if and only if d=-r^2
// Conclusion: Torsion over Q is C2xC2 if and only if d=-r^2

// Study points of order 4
P4:=PrimitiveDivisionPolynomial(E,4);
PP4:=Factorization(P4);
assert [x^2 - d, x^4 + 6*d*x^2 + d^2] eq [f[1] : f in PP4];
/* BY HAND
--> x^4 + 6*d*x^2 + d^2=0 --> z=x^2, z^2+6*d*z+d^2=0 --> z=(-3\pm\sqrt{2}=*d\ne x^2 for any x,d\in Q
--> x^2-d=0 --> d=s^2 (s squareree) and x=\pm s --> y^2=x^3+d*x=\pm 2*s^3
-------> y^2=\pm 2*s^3 --> s =\pm 2 --> d=4 
*/
// Conclusion: Torsion over Q is C4 if and only if d=4

// Study points of order 3
P3:=PrimitiveDivisionPolynomial(E,3);
assert P3 eq 3*x^4 + 6*d*x^2 - d^2
/* BY HAND
--> 3*x^4 + 6*d*x^2 - d^2=0 --> z=x^2, 3*z^2+6*d*z-d^2=0 
-----> z=-1/3(3\pm 2\sqrt{3})*d\ne x^2 for any x,d\in Q
*/
// Conclusion: No pints of order 3 over Q
// FINAL CONCLUSION: Torsion over Q is 
// C4 if and only if d=4
// C2xC2 if and only if d=-r^2
// C2 otherwise

///////////////////////////////////////////////
//D:=-3;
R<d>:=RationalFunctionField(Rationals());
E:=EllipticCurve([0,d]);
_<x>:=PolynomialRing(R);
// Study points of order 2
P2:=PrimitiveDivisionPolynomial(E,2);
assert P2 eq 4*(x^3 + d);
/* BY HAND:
--> x^3 + d=0 --> d=r^3 
*/
//Conclusion: Point of order 2 if and only if d=r^3
// No C2xC2 since x^3+r^3=(x-r)*(x^2+r*x+r^2) and x^2+r*x+r^2 irreducible for any r.

// Study points of order 3
P3:=PrimitiveDivisionPolynomial(E,3);
assert P3 eq 3*x*(x^3 + 4*d);
/* BY HAND:
--> x=0 --> y^2=d --> d=r^2
--> x^3 + 4*d =0 --> d=\pm 2*r^3 (r squarefree) and x= -\pm 2*r --> y^2=x^3+d*x=\pm 6r^3
-----> r=\pm 6 --> d=-432
*/
// Conclusion: Point of order 3 if d=r^2 or d=-432

// Point of order 6 if and only if d=r^3 and (d=s^2 or d=-432) 
// ---> since -432 is not cube we have d=r^3=s^2 with r squarefree and s cubefree
// -----> d=1
// Conclusion: Order 6 if and only if d=1
// FINAL CONCLUSION: Torsion over Q is 
// C6 if and only if d=1
// C3 if and only if d=r^2\ne 1 or d=-432
// C2 if and only if d=r^3\ne 1
// C1 otherwise