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

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

/******************************** Create Table 1 ************************************/

low := 10; high := 500;
Listen := SplitMultEllCurves(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 := [ [0,3,1], [0,3,2], [0,5,1], [0,7,1], [0,11,1],
             [1,3,1], [1,3,2], [1,5,1], [1,7,1], [1,11,1],
             [2,3,1], [2,3,2], [2,5,1], [2,7,1], [2,11,1]
           ];
filename := "Table1.out";
/* Starting from the triple [1, 11, 1] we had to use the higher precision 100.
   Probably 60 would have been enough.
   For triples before we used the precision 50.
*/
prec := 100; PrimeBound := 50;

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
            IsExample, ETNCvalid, calU, calE, K := NonPerfectEtnc(E, l, n, p, prec);
            if IsExample then
                if not ETNCvalid then
                     fprintf "Counter example to ETNC E = %o p = %o l = %o n = %o\n",
                             CremonaReference(E), p, l, n;
                     print "Counter example to ETNC";
                     print "\n*********** E = ", E, "l = ", l, "p = ", p, "***********\n";
                     assert not ETNCvalid;
                else
                     fprintf filename, "E = %o r = %o p = %o l = %o n = %o\n", 
                                        CremonaReference(E), r, p, l, n;
                     print "\n*********** E = ", CremonaReference(E), 
                           " p = ", p, " ETNC_l is valid mod calE  ***********\n";
                end if;
            else
                print "\n*********** E = ", CremonaReference(E), 
                      " p = ", p, " Hypothesis not fullfilled ***********\n";
            end if;
        end for;
    end for;
end for;

/* In the case r = 0 we can fully verify the l-part of ETNC (if we trust in rationality).
   It is therefore of interest to also check the p-part for p \ne l with the methods of 
   "Numerical evidence for the equivariant Birch and Swinnerton-Dyer conjecture (Part I)"

*/


/******************************** Create Table 1 ************************************/

low := 10; high := 100;
Listen := SplitMultEllCurves(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 := [ [0,3,1], [0,3,2], [0,5,1], [0,7,1], [0,11,1] ];
filename := "Table2.out";
prec := 50; PrimeBound := 50;

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
            print "?????????? E = ", CremonaReference(E), " p = ", p,  " ????????????????????????";
            IsExample, ETNCvalid, NotChecked := etncII(E, l, n, p, prec);
            if IsExample then
                if not ETNCvalid then
                     fprintf "Counter example to ETNC E = %o p = %o l = %o n = %o\n",
                             CremonaReference(E), p, l, n;
                     print "Counter example to ETNC";
                     print "\n*********** E = ", E, "l = ", l, "p = ", p, "***********\n";
                     assert not ETNCvalid;
                else
                     fprintf filename, "E = %o r = %o p = %o l = %o n = %o Checked outside %o\n",
                                        CremonaReference(E), r, p, l, n, Set(NotChecked);
                     print "\n*********** E = ", CremonaReference(E),
                           " p = ", p, " ETNC_l is valid mod calE  ***********\n";
                end if;
            else
                print "\n*********** E = ", CremonaReference(E),
                      " p = ", p, " Hypothesis not fullfilled ***********\n";
            end if;
        end for;
    end for;
end for;

