
// We write down a model for X=X(d7)
// and the associated j: X(d7) -> X(1).
// We also verify that these are consistent
// with the model and j-map computed by Elkies
// and given in the paper:
// Andrew Sutherland, "A local-global principle
// for rational isogenies of prime degree",
// JTNB vol 24, 2012, 475--485.

// X(d7) is the modular curve associated to the subgroup H_1 (say) of
// GL_2(\F_7) generated by the two matrices
//  [3  0]              [0  2]
//  [0  5]              [2  0]

load "gl.m";
G:=GL(2,7); // GL_2(\F_7)

H1:=sub<G | [G![3,0,0,5], G![0,2,2,0]]>; 
assert isSurjective(H1); // From gl.m
			// Thus X(d7) is defined over \Q

H:=H1 meet SL(2,7);
assert G![-1,0,0,-1] in H;


// Following Ligozat
// "Courbes Modulaires de Niveau 11", Antwerp V
// page 191
muH:=Index(SL(2,7),H);  // This gives us the degree of X-->X(1)
assert muH eq 56;

assert IsDivisibleBy(Order(H),7) eq false;
// 7 does not divide the order of H.
// In this case H/{\pm I} acts freely on the cusps.

einfH:=muH div 7; // The number of cusps=8

e2H:=(7+1)*#{h : h in H | Trace(h) eq 0}/Order(H);
// The number of elliptic points of order 2.
assert e2H in Integers();
e2H:=Integers()!e2H;

assert e2H eq 0;


e3H:=(7-1)*#{h : h in H | Trace(h) eq -1}/Order(H);
// The number of elliptic points of order 3.
assert e3H in Integers();
e3H:=Integers()!e3H;

assert e3H eq 2;
gen:=1+(muH/12)-(e2H/4)-(e3H/3)-(einfH/2);

assert gen eq 1;

// Therefore X(d7) has genus 1.
// From the above we deduce the following ramification data for
// X(d7)--> X(1) :
// (a) Above 0 there are two (=e3H) points with ramification index 1
//     and (56-2)/3=18 points with ramification index 3
// (b) Above 1728 there zero (=e2H) points with ramification index 1
//     and 56/2=28 points with ramification index 2
// (c) Above \infty there are 8 points of ramification index 7

_,C:=splitCartan(7);  // from gl.m
			// C is the normalizer of the split Cartan subgroup.

assert isContained(H1,C);
assert #(C meet SL(2,7))/#H eq 2;

// Thus X(d7) is a double cover of X(s7). 


Qx<x>:=PolynomialRing(Rationals());

// Following Imin Chen's thesis, page 68:
// X(s7) has genus 0
// x is a Hauptmodul for X(s7)
// j=num/den is the map X(s7) -> X(1):
num:= (x^2-5*x+8)^3*(x^2-5*x+1)^3*(x^4-5*x^3+8*x^2-7*x+7)^3*(x+1)^3*x;
den:=(x^3-4*x^2+3*x+1)^7;

assert Degree(num) eq 28;
assert Degree(den) eq 21; // Thus \infty is a pole for j of order 7.

// Note that X(s7) -> X(1) has degree 28=56/2 as expected.

assert num-1728*den eq 
    (x^4 - 10*x^3 + 27*x^2 - 10*x - 27)*
    (x^4 - 10*x^3 + 34*x^2 - 38*x + 1)^2*
    (x^4 - 3*x^3 - x^2 + 4*x + 8)^2*
    (x^4 - 3*x^3 + 6*x^2 - 3*x + 1)^2;

// The factorisation of num-1728*den tells us about the 
// ramification above 1728, just as the factorisations
// of num and den tell us about the ramification above 0 and \infty.
// We deduce the following ramification data for X(s7) -> X(1):

// (A) Above 0 there are nine points of ramification index 3 and 
//     one of ramification index 1
// (B) Above 1728 there are 12 points of ramification index 2
//     four of ramification index 1
// (C) Above \infty there are four points of ramification index 7.

// Comparing (a) with (A), (b) with (B), and (c) with (C),
// we see that all places of X(s7) above 0, 1728 and \infty split
// in X(d7) -> X(s7) except for the four points above 1728
// with ramification index 1, these ramify in X(d7) -> X(s7).
// The four points correspond to the roots of the factor
// x^4 - 10*x^3 + 27*x^2 - 10*x - 27 of num-1728*den;
// Hence an equation for X(d7) has the form
// y^2=c(x^4 - 10*x^3 + 27*x^2 - 10*x - 27)
// for some squarefree integer c.
// X(d7) has a model of \Z[1/7]. We will use this fact to narrow
// down the possibilities for c.

Qc<c>:=PolynomialRing(Rationals());
Qcx<x>:=PolynomialRing(Qc);
Dc:=HyperellipticCurve(c*(x^4 - 10*x^3 + 27*x^2 - 10*x - 27));
delta:=Discriminant(Jacobian(GenusOneModel(Dc))); // The discriminant
						// of the Jacobian elliptic
						// curve of Dc
assert delta eq -2^12*7^3*c^6;
// If p \mid c, and p \ne 7 then it is clear (from the discriminant)
// that the minimal model of the Jacobian elliptic curve of Dc 
// has bad reduction at p. Hence c=\pm 1, \pm 7.

Qx<x>:=Parent(num);

// Try c=-1
c:=-1;
Dc:=HyperellipticCurve(c*(x^4 - 10*x^3 + 27*x^2 - 10*x - 27));
delta:=Discriminant(MinimalModel(Jacobian(GenusOneModel(Dc))));

assert Valuation(delta,2) eq 12; // Minimal model of Jacobian
				// has bad reduction at 2.
// Thus c \ne -1.

// Try c=7
c:=7;
Dc:=HyperellipticCurve(c*(x^4 - 10*x^3 + 27*x^2 - 10*x - 27));
delta:=Discriminant(MinimalModel(Jacobian(GenusOneModel(Dc))));

assert Valuation(delta,2) eq 12; // Minimal model of Jacobian
				// has bad reduction at 2.

// Thus c \ne 7.

// We are left with the cases c=1 and c=-7.
// Thus X(d7)=Dc where c=1 or c=-7 but we don't know
// which yet. We will use the rational points on these
// curves to distinguish between them.


c:=1;
D1:=HyperellipticCurve(c*(x^4 - 10*x^3 + 27*x^2 - 10*x - 27));

E:=MinimalModel(EllipticCurve(D1));

assert CremonaReference(E) eq "49a1"; // Has good reduction away from 7.
assert Rank(E) eq 0;
assert #TorsionSubgroup(E) eq 2;

// Thus the only rational points on D1 are the two points at infinity.
// If X(d7)=D_1, then the rational points have x-coordinate infinity,
// and so j-invariant=num(x)/den(x)=\infty (since num has degree 28
// and den has degree 21). In other words the only rational points
// would be cusps.

c:=-7;
Dm7:=HyperellipticCurve(c*(x^4 - 10*x^3 + 27*x^2 - 10*x - 27));
pt1:=Dm7![5/2,7/4];
pt2:=Dm7![5/2,-7/4];

E:=MinimalModel(EllipticCurve(Dm7,pt1));

assert CremonaReference(E) eq "49a3"; // Has good reduction away from 7.
assert Rank(E) eq 0;
assert #TorsionSubgroup(E) eq 2;


// Thus the only rational points on Dm7 are the points pt1, pt2.
// If X(d7)=Dm7, then the only rational points have x-coordinate
// 5/2, and so j-invariant=num(5/2)/den(5/2)

j:=Evaluate(num,5/2)/Evaluate(den,5/2);

assert j eq 2268945/128;  // This the j-invariant appearing
// in Andrew Sutherland's paper. 

E:=EllipticCurve([ 0, 0, 0, -1715, 25970 ]);
assert jInvariant(E) eq j;

// We will show that the image of \overline{rho}_{E,7}
// is contained in H_1. Thus X(d7) must have a
// non-cuspidal rational point with j-invariant 2268945/128.
// This shows that X(d7)=Dm7 !!

// The image of \overline{\rho}_{E,7} is the Galois
// group of \Q(E[7])/\Q. Computing this Galois group
// is currently too much for MAGMA. So we will narrow
// down the possibilities for the image by computing
// the projective image.

F7:=x^8 + 28*x^7 + 322*x^6 + 1904*x^5 + 5915*x^4 + 8624*x^3 + 4018*x^2 + 748*x + 49;  // This is the Fricke polynomial for l=7
// The Galois group of F7(x)-j*x is the 
// PROJECTIVE image of \overline{\rho}_{E,7}
// (see Barinder Banwait's thesis, Section 4.3.3).

assert IsIsomorphic(GaloisGroup(F7-j*x),DihedralGroup(3));
// Thus the projective image of \overline{\rho}_{E,7}
// agrees with the image of H_1 in \PGL_2(\F_7):

assert IsIsomorphic(imPGL(H1),DihedralGroup(3)); 
// See gl.m for the command imPGL.


// We now write down all subgroups of GL_2(\F_7)
// whose image in PGL_2(\F_7) is isomorphic to D_3
G:=GL(2,7);
subs:=Subgroups(G);
subs:=[ K`subgroup : K in subs];
subs:=[ K : K in subs | IsIsomorphic(imPGL(K),DihedralGroup(3)) ];
// Thus the image of \overline{\rho}_{E,7} belongs to subs; 

// Since E is defined over \Q, we know the image
// is odd and has surjective determinant:
subs:=[ K : K in subs | isSurjective(K) and isOdd(K)];
assert #subs eq 2;
// We are left with two possibilities for the image.

assert &and[isContained(K,H1) : K in subs];

// Both are contained in H_1 (up to conjugation). 
// Thus E gives rise to an non-cuspidal rational
// point on X(d7) with j-invariant 2668945/128.
// This completes our proof that X(d7)=Dm7.

// Finally we compare our result for X(d7)->X(1)
// with that of Elkies quoted in Sutherland's paper.

_<u1,v1>:=FunctionField(Dm7);
j1:=Evaluate(num,u1)/Evaluate(den,u1);
// j as an element of the function field of our model for X(d7)

D2:=HyperellipticCurve(-7*(x^4+2*x^3-9*x^2-10*x-3)); // The model given
							// by Elkies.

num2:=-(x-3)^3*(x-2)*(x^2+x-5)^3*(x^2+x+2)^3*(x^4-3*x^3+2*x^2+3*x+1)^3;
den2:=(x^3-2*x^2-x+1)^7;   // The j-map given by Elkies is num2/den2

_<u2,v2>:=FunctionField(D2);
j2:=Evaluate(num2,u2)/Evaluate(den2,u2);

phi:=iso<Dm7 -> D2 | [-u1+2,v1,1], [-u2+2,v2,1]>;

// The two models are isomorphic.
// phi : Dm7 -> D2 is now isomorphism

assert Pullback(phi,j2) eq j1; // Which commutes with the j-maps.
				// Thus our model is equivalent to
				// the one given by Elkies.
