load "witt_gen.m";
load "etas.m";
load "gt.m";
load "load_js.m";

n:=3;

//for p in [17,19,23] do
for p in [5, 7, 11] do

    t:=Cputime();
    ResetMaximumMemoryUsage();

    print "=====================================================";
    print "                 p = ", p;
    print "=====================================================";

    file:="j3_" cat IntegerToString(p);


    F<j0>:=RationalFunctionField(GF(p));
    P<J3>:=PolynomialRing(F);
    PP<X,Y>:=PolynomialRing(Integers(),2);
    PPP:=PolynomialRing(ResidueClassRing(p^(n+2)),2);

    DefineJs(j0,~j1,~j2,~j3,p);

    vecj:=[P!j0,P!j1,P!j2,P!j3,(P!j0)^p,(P!j1)^p,(P!j2)^p,(P!J3)^p];

    mp:=PP!(PP!ClassicalModularPolynomial(p));

    primr:=GenPrimRoots(p,n+2);

    print "Compute etapols...";
    time pols:=etapols(p,n);
    print "Done!";
    print "";


    mp:=Pol_New_Form(mp,p,n : primr:=primr );

    print "Compute GT...";
    time mp:=GT(mp : pols:=pols, primr:=primr, vvars:=vecj);
    print "Done!";
    print "";

    delete vecj;

    mp3:=mp[4];

    delete mp;

    print "Compute quot..";                                               
    time jj3:=-Coefficient(mp3,0)/Coefficient(mp3,p);                      
    print "Done!";                                                        
    print "";                                                             
                                                                          
    delete mp3;                                                           

    print "Compute InvFrob...";                                           
    time jj3:=pthroot(jj3);                                                 
    print "Done!";                                                        
    print "";     

    // Write(file,j3);

    j3 eq jj3;

    delete j3;

    print "Time (in sec): ", Cputime(t);
    print "Memory Usage (in MB): ", GetMaximumMemoryUsage()/((1024.0)^2);
    print "";

end for;


/*

p=5, n=3 old way:

Total time: 407.089 seconds, Total memory usage: 376.78MB

new way:

Total time: 4.080 seconds, Total memory usage: 42.62MB

=====================================================                     
                 p =  5                                                   
=====================================================                     
Compute etapols...                                                        
Time: 0.010                                                               
Done!                                                                     

Compute GT...
Time: 0.450  
Done!        

Compute quot..
Time: 0.000   
Done!         

Compute InvFrob...
Time: 0.010       
Done!             

true
Time (in sec):  0.480
Memory Usage (in MB):  30.5937500000000000000000000000

=====================================================
                 p =  7                              
=====================================================
Compute etapols...                                   
Time: 0.010                                          
Done!                                                

Compute GT...
Time: 7.040  
Done!        

Compute quot..
Time: 0.020   
Done!         

Compute InvFrob...
Time: 0.020
Done!

true
Time (in sec):  7.100
Memory Usage (in MB):  45.2500000000000000000000000000

=====================================================
                 p =  11
=====================================================
Compute etapols...
Time: 0.190
Done!

Compute GT...
Time: 397.110
Done!

Compute quot..
Time: 0.430
Done!

Compute InvFrob...
Time: 0.210
Done!

true
Time (in sec):  398.020
Memory Usage (in MB):  1014.31250000000000000000000000


*/
