/**********************************************************
 * 
 * This is a benchmark for local_square_classes.m
 * 
 * It compares the times the new algorithm versus
 * the built-in one on the fields with the generating
 * polys (x - 1)^d + 2. Such field are always totally 
 * ramified.
 * 
 *********************************************************/

SetDebugOnError(true);

// initial numbers of tests
N := 1;     // Magma's built-in method
M := 256;  // our function

QQ := Rationals();
ZZ := Integers();
RR := RealField(8);
Qx<x> := PolynomialRing(QQ);

// the degrees will be powers of 2 ith exponents from MIN_EXP to MAX_EXP
MIN_EXP := 7;
MAX_EXP := 12;
// generating polynomials
polys := [ (x - 1)^(2^k) + 2 : k in [ MIN_EXP..MAX_EXP ] ];

///////////////////////////////////////////////////////////
// perform the tests in Magma
//

// set the path to the package
import "path.m" : PATH_TO_LSC;
Attach(PATH_TO_LSC);

// file to store the results
I := POpen("date", "r");
date := Read(I);
date := Split(date, ", ");
filename := "totally_ramified_big_" cat date[4] cat "_" cat date[3] cat "_" cat date[2] cat ".dat";
F := Open(filename, "a");
fprintf F, "deg\tt\tN\tu\tM\n"; 

// run the tests
for f in polys do
    printf ".";
    P := [* *];
    // prepare input data
    for j in [1..N] do
        K := NumberField(f);
        fct := PrimeFactorization(K, 2);
        assert IsOne(#fct);
        p := fct[1][1];
        Append(~P, p);
    end for;
    Q := [* p : j in [1..M] *];
    
    // run the tests
    // built-in method
   t := Cputime();
    for p in P do
        G, mG := LocalMultiplicativeGroupModSquares(p);
    end for;
    t :=  Cputime(t); 
    // our function
    u := Cputime();
    for p in Q do
        H, mH := LocalGroupOfSquaresClasses(p);
    end for;
    u :=  Cputime(u);

    fprintf F, "%o\t%o\t%o\t%o\t%o\n", Degree(f), "nan", N, (RR!u)/M, M;

    // adjust number of tests
    if u gt 4 then M := Isqrt(M); end if;
end for;

delete F;

quit;
