
/******************* Beispiele fuer das Paper mit Daniel Macias Casillo *****************************************************/
Attach("RelAlgKTheory.m");
Attach("INB.m");
Attach("etnc.m");

Attach("DoEtncIVExamples.m");

filename := "ExamplesForEtncIV.out";

/* A WuthrichType example is such that E(K) \simeq \Zl^{m_0} \oplus \ZlG, where K/Q is cyclic of order l.
   We did not include these examples in the paper because the results are implied by BSD for K and Q.
*/

fprintf filename, "\n************************** WuthrichType examples ****************************************\n\n";

/* Examples with rk(E(Q)) = 4 */
E := EllipticCurve([1, -1, 0, -79, 289]); /* Not split multiplicative, but where do we use this ? It is semistable! */
p := 7; l := 3; n := 1; prec := 20; Bound := 6; CheckSaturation := true;
data := [* E, p, l ,n, prec, Bound, CheckSaturation *];
DoWuthrichTypeExample(filename, data);

E := EllipticCurve([1, -1, 0, -79, 289]);
p :=  11; l :=  5;  n :=  1; prec := 20; Bound := 6; CheckSaturation := false;
data := [* E, p, l ,n, prec, Bound, CheckSaturation *];
DoWuthrichTypeExample(filename, data);

/* Examples with rk(E(Q)) = 3 */
E := EllipticCurve("5077A");   /* Not split multiplicative, but where do we use this ? It is semistable! */
p := 43; l := 3; n := 1; prec := 20;  Bound := 10;  CheckSaturation := true;
data := [* E, p, l ,n, prec, Bound, CheckSaturation *];
DoWuthrichTypeExample(E, data);

E := EllipticCurve("5077A"); 
p :=  11;    l :=  5;  n :=  1; prec := 20; Bound := 6;  CheckSaturation := false;
data := [* E, p, l ,n, prec, Bound, CheckSaturation *];
DoWuthrichTypeExample(filename, data);


/* Examples with rk(E(Q)) = 2 */
E := EllipticCurve("563A1");
p := 43; l := 3; n := 1; prec := 20; Bound := 20;  CheckSaturation := true;
data := [* E, p, l ,n, prec, Bound, CheckSaturation *];
DoWuthrichTypeExample(filename, data);

E := EllipticCurve("563A1");
p := 11; l := 5; n := 1; prec := 20; Bound := 20;  CheckSaturation := false;
data := [* E, p, l ,n, prec, Bound, CheckSaturation *];
DoWuthrichTypeExample(filename, data);


/************************************ lSquared examples **************************************************/

/* These examples are of the type as considered in Section 5.2. We did not include examples with sig = (0,1,0)
   in the paper because here h=1 and calL is essentially the Mazur-Tate element so that part (i) of Cor. 2.11 or
   Theorem 2.12 follows from BSD.
*/

fprintf filename, "\n************************** lSquared examples ****************************************\n\n";

/* Examples with sig = (0, 1, 0) */
E := EllipticCurve([1,1,0,-2,0]);
p := 19; l := 3; n := 2; prec := 20; Bound := 20; CheckSaturation := true;
data := [* E, p, l ,n, prec, Bound , CheckSaturation *];
DolSquaredExample(filename, data);

E := EllipticCurve([1,1,0,8,10]);
p := 19; l := 3; n := 2; prec := 20; Bound := 20; CheckSaturation := true;
data := [* E, p, l ,n, prec, Bound , CheckSaturation *];
DolSquaredExample(filename, data);

E := EllipticCurve([1,0,1,2,0]);
p := 19; l := 3; n := 2; prec := 20; Bound := 20; CheckSaturation := true;
data := [* E, p, l ,n, prec, Bound , CheckSaturation *];
DolSquaredExample(filename, data);

E := EllipticCurve([1,0,1,-15,22]);
p := 19; l := 3; n := 2; prec := 20;  Bound := 20; CheckSaturation := true;
data := [* E, p, l ,n, prec, Bound , CheckSaturation *];
DolSquaredExample(filename, data);
/* Diese Beispiel ist besonders zu analysieren, da hier ETNC nicht gilt !?!?!?????? 
   In diesem Beispiel ist der 3-Anteil von Sha von der Ordnung 9.*/

/* Two examples with sig = (1,1,0). These are the examples inf the paper, Sec. 5.2 Type (i). */
E := EllipticCurve([0,-1,1,0,2]); /* Rank (2,1,0) */
p := 19; l := 3; n := 2; prec := 20; Bound := 20; CheckSaturation := true;
data := [* E, p, l ,n, prec, Bound , CheckSaturation *];
DolSquaredExample(filename, data);

E := EllipticCurve([1,-1,0,-10,16]); /* Rank (2,1,0) */
p := 19; l := 3; n := 2; prec := 20; Bound := 20; CheckSaturation := true;
data := [* E, p, l ,n, prec, Bound , CheckSaturation *];
DolSquaredExample(filename, data);


/* A perfect example is such that E(K) \simeq \ZlG^{m_n}, where in all of our examples m_n = 1.
   We first search for examples, store them in a list and then work through this list.
*/

PrimeBound := 50;
low := 10; high := 200;
low := 130; high := 130;

Listen := SemistableEllCurves(low, high);

/* Listen[r+1] is a list of elliptic curves with semistable reduction
   of algebraic rank r with low \le N_E \le high */


prec := 20;

triples := [ [1,3,1], [1,5,1], [1,7,1] ];

examples := [* *];

for rln in triples do 
    r := rln[1]; l := rln[2]; n := rln[3];
    Es := Listen[r+1];
    ps := [p : p in PrimesUpTo(PrimeBound) | p mod l^n eq 1];

    for x in Es do
        E := x[2];
        print "-------------------------------------------------------------------------------------E = ", CremonaReference(E);
        for p in ps do
            print "*************************************************************************************";
            IsExample, ETNCvalid, E, K := PerfectEtnc(E, l, n, p, prec);
            if IsExample then
                Append(~examples, [* E, K *] );
            end if;
        end for;
    end for;
end for;

fprintf filename, "\n************************** Perfect examples ****************************************\n\n";

NrOfExample := 1;
for ex in examples do
    E := ex[1];
    l := Degree(ex[2]);
    p := Factorization(Discriminant(MaximalOrder(ex[2])))[1,1];
    prec := 20;
    if l eq 3 then Bound := 50; end if;
    if l eq 5 then Bound := 10; end if;
    if l eq 7 then Bound :=  5; end if; 
    if l eq 3 then
         CheckSaturation := true;
    else 
         CheckSaturation := false;
    end if;
    data := [* E, p, l ,n, prec, Bound , CheckSaturation *];
    computable, ETNCvalid := DoPerfectExample(filename, data);
    if not ETNCvalid and computable then
        fprintf filename, "SUSPICIOUS: study in detail !!!!!\n";
    end if;
    if computable then
        fprintf filename, "***************************** Example %o done **********************************\n\n", NrOfExample;
        NrOfExample := NrOfExample + 1;
    end if;
end for;

/* These are the examples in Sec. 5.2 of type (ii) */

/* Listen[r+1] is a list of elliptic curves with split multiplicative reduction
   of algebraic rank r with low \le N_E \le high */

low := 10; high := 750;
Listen := SemistableEllCurves(low, high);
/* Listen[r+1] is a list of elliptic curves with semistable reduction
   of algebraic rank r with low \le N_E \le high */

triples := [
             [2,3,2]
           ];

prec := 50; PrimeBound := 50;

fprintf filename, "\n************************** NonPerfectAnnihilator examples ****************************************\n\n";

NrOfExample := 1;
for rln in triples do
    r := rln[1]; l := rln[2]; n := rln[3];
    Es := Listen[r+1];
    ps := [p : p in PrimesUpTo(PrimeBound) | p mod l^n eq 1];

    for x in Es do
        E := x[2];
        for p in ps do
            data := [* E, p, l, n, prec, 20, true *];
            computable, ETNCvalid := DoNonPerfectAnnihilator(filename, data);
            if not ETNCvalid and computable then
                fprintf filename, "SUSPICIOUS: study in detail !!!!!\n";
            end if;
            if computable then
                fprintf filename, "***************************** Example %o done **********************************\n\n", NrOfExample;
                NrOfExample := NrOfExample + 1;
            end if;
        end for;
    end for;
end for;
