SetAutoColumns(false);
SetColumns(100);
ClearVerbose();
SetEchoInput(true);
Attach("twocovdesc.m");

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

///////////////////////////////////////////////////////////////////////////////
//Example 7.1

C:=HyperellipticCurve(2*x^6+x+2);
Hk,AtoHk:=TwoCoverDescent(C);
#Hk;

///////////////////////////////////////////////////////////////////////////////
//Example 7.2

C:=HyperellipticCurve(-x^6+2*x^5+3*x^4-x^3+x^2+x-3);
Hk,AtoHk:=TwoCoverDescent(C);
#Hk;

///////////////////////////////////////////////////////////////////////////////
//Example 8.1

f:=2*x^6+x^4+3*x^2-2;
C:=HyperellipticCurve(f);
Hk,AtoHk:=TwoCoverDescent(C);
A<theta>:=Domain(AtoHk);
deltas:={-1-theta,1-theta};
{AtoHk(d): d in deltas} eq Hk;
L<alpha>:=NumberField(x^2+x+2);
LX<X>:=PolynomialRing(L);
g:=(X^2-1/2)*(X^2-alpha);
h:=2*(X^2+alpha+1);
g*h eq Evaluate(f,X);

LTHETA<THETA>:=quo<LX|g>;
j:=hom<A->LTHETA|THETA>;
{Norm(j(delta)):delta in deltas} eq {1/2*(-alpha + 1)};
E:=HyperellipticCurve( (1-alpha)*(2*X^2-1)*(X^2-alpha));
P1:=ProjectiveSpace(Rationals(),1);
EtoP1:=map<E->P1|[E.1,E.3]>;

P0:=E![1,alpha-1];
Eprime,EtoEprime:=EllipticCurve(E,P0);
Etilde:=EllipticCurve(X^3+(1-alpha)*X^2+(2-9*alpha)*X+(16-2*alpha));
EprimeToEtilde:=Isomorphism(Eprime,Etilde);

EtoEtilde:=EtoEprime*EprimeToEtilde;

EtildeToP1:=Expand(Inverse(EtoEtilde)*EtoP1);

success,MWgrp,MWmap:=PseudoMordellWeilGroup(Etilde);
assert success;
MWgrp;
N,V,R:=Chabauty(MWmap,EtildeToP1,5);
N eq #V;
R;
{EvaluateByPowerSeries(EtildeToP1,MWmap(g)):g in V};
RationalPoints(C,1);
RationalPoints(C,-1);

///////////////////////////////////////////////////////////////////////////////
// Example 9.1

k<alpha>:=NumberField(x^2-2);
kX<X>:=PolynomialRing(k);
E:=EllipticCurve(X^3+(2-2*alpha)*X+(2-9*alpha));
Hk,AtoHk:=TwoCoverDescent(HyperellipticCurve(E));
A<theta>:=Domain(AtoHk);
delta:=theta^2+(8-4*alpha)*theta+13-6*alpha;
two:=MultiplicationByMMap(E,2);
mu,tor:=CasselsMap(two);
Sel2,mp:=SelmerGroup(two);
B:=Domain(mp);
Modulus(A) eq Modulus(B);
AtoB:=hom<A->B|B.1>;
{mp(AtoB(d@@AtoHk)):d in Hk} eq {a: a in Sel2};
D:=Domain(tor(AtoB(delta)));
C:=Quartic(D);
HkC:=TwoCoverDescent(C);
#HkC;


