/*

Calculates the Greenberg transform of

  x^2 + (a0,a1,a2)*x + (b0,b1,b2)

in 3 different ways:

* Precompute polynomials for Witt Sum and Prod. (in the most efficient way),
  then use them to perform sums and prod.

* Perform sums and prods using recursion.

* Use the formulas for the GT.


Best to cut and paste....

We include the times obtained (in boole) as comments.


  ***  TESTED!!!  -- compared the results and they all match!  ***


*/
// /////////////////////////////////////////////////////////////// //

// FIRST WAY: Precompute polynomials for Witt Sum and Prod.

load 'witt2_fun.m';

// //////////////////////////////////////////////
// choose char.
p:=7;
// //////////////////////////////////////////////

vecS:=WittSum2Pol(p);
vecP:=WittProd2Pol(p);

PR<a0,a1,a2,b0,b1,b2,x0,x1,x2>:=PolynomialRing(GF(p),9);

a:=[a0,a1,a2];
b:=[b0,b1,b2];
x:=[x0,x1,x2];

GT:=WittSum22(b,WittProd22(a,x : vecP:=vecP) : vecS:=vecS);
GT:=WittSum22(GT,WittProd22(x,x : vecP:=vecP) : vecS:=vecS);


// p:=5 gives  Total time: 0.300 seconds, Total memory usage: 9.03MB

// p:=7 gives  Total time: 0.420 seconds, Total memory usage: 11.75MB

// p:=11 gives  Total time: 6.730 seconds, Total memory usage: 130.62MB

// p:=13 gives  Total time: 39.929 seconds, Total memory usage: 520.12MB

// p:=17 gives  Total time: 758.480 seconds, Total memory usage: 4647.69MB


// /////////////////////////////////////////////////////////////// //

// SECOND WAY: Perform sums and prods using recursion.

load 'witt2_fun.m';

// //////////////////////////////////////////////
// choose char.
p:=5;
// //////////////////////////////////////////////


PR<a0,a1,a2,b0,b1,b2,x0,x1,x2>:=PolynomialRing(GF(p),12);

a:=[a0,a1,a2];
b:=[b0,b1,b2];
x:=[x0,x1,x2];

GT2:=WittSum2(b,WittProd2(a,x));
GT2:=WittSum2(GT2,WittProd2(x,x));


// p:=5 gives Total time: 0.300 seconds, Total memory usage: 9.03MB

// p:=7 gives Total time: 0.410 seconds, Total memory usage: 11.28MB

// p:=11 gives Total time: 4.570 seconds, Total memory usage: 107.69MB

// p:=13 gives Total time: 20.800 seconds, Total memory usage: 383.88MB

// p:=17 gives Total time: 262.910 seconds, Total memory usage: 3032.72MB

// p:=19 gives Total time: 988.269 seconds, Total memory usage: 7208.94MB

// /////////////////////////////////////////////////////////////// //

// THIRD WAY: Use the formulas for GT

load 'witt2_fun.m';

// //////////////////////////////////////////////
// choose char.
p:=23;
// //////////////////////////////////////////////


PR<a0,a1,a2,b0,b1,b2,x0,x1,x2>:=PolynomialRing(GF(p),9);


f:=b0+a0*x0+x0^2;
cc2:=Derivative(f,7)^p*x1+ b1+a1*x0^p+SpcFct(f);

cc3:=Derivative(f,7)^(p^2)*x2
    +(-NextCoord(2,p)*x0^p+a1)^p*x1^p
    +x1^(2*p)+(b2+a2*x0^(p^2))
    +SpcFct(Derivative(f,7)^p*x1+ b1+a1*x0^p)
    +fSpcFct(Derivative(f,7)^p*x1+ b1+a1*x0^p,SpcFct(f))
    +Spc4Fct(f);

// GT3:=[f,cc2,cc3];



// 

// p:=5 gives Total time: 0.300 seconds, Total memory usage: 9.03MB

// p:=7 gives Total time: 0.360 seconds, Total memory usage: 10.31MB

// p:=11 gives Total time: 1.909 seconds, Total memory usage: 36.38MB

// p:=13 gives Total time: 7.730 seconds, Total memory usage: 94.28MB

// p:=17 gives Total time: 74.620 seconds, Total memory usage: 529.75MB

// p:=19 gives Total time: 187.659 seconds, Total memory usage: 1124.44MB

// p:=23 gives Total time: 1086.250 seconds, Total memory usage: 4185.97MB




// OLD: p:=23 gives  Total time: 4902.340 seconds, Total memory usage: 7474.36MB
 
// # of terms for p=23. -- Need to subtract 39.710 to obtain the correct time...

/*

> time #Terms(cc3);
65553940
Time: 39.710
>

(12:22) gp > 4902.340-39.710
%1 = 4862.6300000000000000000000000000000000


*/
