Attach("RelAlgKTheory.m");
Attach("INB.m");
Attach("etnc.m");

ZX<x> := PolynomialRing( Integers() );
DB := CremonaDatabase();
prec := 20;
SetDefaultRealFieldPrecision(prec);

/************************************************************************************
*                      Navilarekallus D_3-Beispiel                                            *
************************************************************************************/

E := EllipticCurves(DB, "11A")[1];
ZX<x> := PolynomialRing(Rationals());
pol := x^3 - 4*x + 1;
K := SplittingField(NumberField(pol));
pol := MinimalPolynomial(K.1);
L := NumberField(pol);
A := ArtinRepresentations(L);
K :=L`artinrepdata`K;


/* Compute an integral normal basis element. */
X, isfree := INB(K);
K := X[1]; theta := X[2]; Atheta := X[3]; AssOrd := X[4]; nb := X[5]; h := X[6]; QG := X[7];
OK := MaximalOrder(K);
G := Domain(h);
lambda := QG ! ElementToSequence(nb);
delta := QGAction(lambda, theta, h);   /* delta generates an integral normal basis */



/* Compute general information */
EK := BaseChange(E, K);
Factorization(229*OK);

P := Factorization(11*OK)[1,1];
NrOfNsPoints(E, OK, P);

P := Factorization(229*OK)[1,1];
#Reduction(EK, P);

TorsionSubgroup(E);
TorsionSubgroup(EK);

TamagawaNumbers(E, OK);


QG := InitGroupAlgebra(G);

/* Compute the resolvents of the integral normal basis element delta */
R := Resolvents(QG, h, delta);

/* Compute the real and purely imaginary period of E/Q */
Ovals := CompOvals(QG, E, OK, h);
    
/* Compute the leading terms of the L-series and the order of vanishing */
SetVerbose("LSeries", 1);
Lvec := InitLSeries(QG, E, K, prec);
Lvals,orders := Evaluate(Lvec);
E`Lvals := Lvals; E`orders := orders; E`OK := OK; E`h := h;
print "The analytic rank conjecturally is ", orders;
print "Lvals = ", Lvals;

/* The Mordell-Weil group is torsion, so the regulator is trivial */
Rvals := [ [ComplexField()!1 : i in [1..#z]] : z in Lvals];

/* Compute the ratios of L-values, periods and resolvents and check rationality */
Z := ComputeZ(QG, E, Lvals, R, Ovals, Rvals);
print "Z = ", Z;
readi d, "Input a denominator";
5
TateShafarevicGroup(E, QG, Lvals, Rvals, OK);RatZ, err := MakeRational(Z, QG, d, Round(4));
print "u = ", RatZ;
print "Maximal rounding error: ", err;

E`Rvals := Rvals; E`K := NumberField(E`OK); E`RatZ := RatZ; E`EK := BaseChange(E, E`K);

/* Compute a conjectural order for the Tate-Shafarevic group */
E`ts := TateShafarevicGroup(E, QG, Lvals, Rvals, OK);
625

S := ComputeS(E, OK); /* the set S of bad primes; those where the representation is ramified */
HP := S join HardPrimes(E, QG, Lvals, Rvals, OK);
print "S = ", S;
print "HP = ", HP;

P := Factorization(2*OK)[1,1];
#Reduction(EK, P);
P := Factorization(3*OK)[1,1];
#Reduction(EK, P);
P := Factorization(5*OK)[1,1];
#Reduction(EK, P);
P := Factorization(11*OK)[1,1];
NrOfNsPoints(E, OK, P);
P := Factorization(229*OK)[1,1];
#Reduction(EK, P);


/* Check primes which are not in HP */
CheckEasyPrimes(RatZ, HP);

l := 3;
CheckHardPrime(QG, E, S, l);

l := 11;
CheckHardPrime(QG, E, S, l);

l := 229;
CheckHardPrime(QG, E, S, l);

for l in HP do
    CheckHardPrime(QG, E, S, l);
    print "*********************************************************************";
end for;
