/*

Calculates the Greenberg transform of

  x^3 + (a0,a1,a2)*x^2 + (b0,b1,b2)*x + (c0,c1,c2)

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:=11;
// //////////////////////////////////////////////

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

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

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

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


// p:=5 gives Total time: 0.420 seconds, Total memory usage: 11.53MB

// p:=7 gives Total time: 5.490 seconds, Total memory usage: 94.12MB

// p:=11 gives Total time: 2517.389 seconds, Total memory usage: 8380.22MB

// OLD!!!
// p:=5 gives "Total time: 0.490 seconds, Total memory usage: 13.18MB"

// p:=7 gives "Total time: 9.660 seconds, Total memory usage: 208.88MB"

// p:=11 gives "Total time: 6898.399 seconds, Total memory usage: 15176.38MB"
// over 19 hours and 15GB


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

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

load 'witt2_fun.m';

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


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

a:=[a0,a1,a2];
b:=[b0,b1,b2];
c:=[c0,c1,c2];
x:=[x0,x1,x2];
x2:=WittProd2(x,x);

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


// p:=5 gives Total time: 0.410 seconds, Total memory usage: 11.72MB

// p:=7 gives Total time: 4.150 seconds, Total memory usage: 90.50MB

// p:=11 gives Total time: 987.440 seconds, Total memory usage: 7209.50MB

// OLD!!!!
// p:=5 gives:  Total time: 0.420 seconds, Total memory usage: 13.60MB

// p:=7 gives:  Total time: 8.339 seconds, Total memory usage: 111.32MB

// p:=11 gives  Total time: 3583.969 seconds, Total memory usage: 7947.46MB




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

// THIRD WAY: Use the formulas for GT

load 'witt2_fun.m';

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


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

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

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

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


// p:=5 gives Total time: 0.370 seconds, Total memory usage: 10.62MB

// p:=7 gives Total time: 1.810 seconds, Total memory usage: 44.44MB

// p:=11 gives Total time: 240.849 seconds, Total memory usage: 2110.59MB

// p:=13 gives Total time: 2579.769 seconds, Total memory usage: 10516.19MB


// OLD!!!!
//  TESTED!!!

// p:=5 gives "Total time: 0.460 seconds, Total memory usage: 10.47MB"

// p:=7 gives "Total time: 3.100 seconds, Total memory usage: 47.48MB"

// p:=11 gives "Total time: 606.059 seconds, Total memory usage: 3788.02MB"
// a bit over 10 minutes and almost 4GB


// p:=13 gives "Total time: 8770.979 seconds, Total memory usage: 17180.85MB"


//  FIRST RUN, GETTING THE # OF TERMS!!!!
// p:=13 gives "Total time: 9242.469 seconds, Total memory usage: 19387.71MB"
// (subtract the time taken to count the # of term: 9110.559)
/*

> time #Terms(cc3);
153065983
Time: 131.910
> Cputime();
9242.450
>

Total time: 9242.469 seconds, Total memory usage: 19387.71MB
scrn@boole[~/tex/comp]$ gp
Reading GPRC: /home/dept/finotti/.gprc ...Done.

                                 GP/PARI CALCULATOR Version 2.3.3 (released)
                        amd64 running linux (x86-64/GMP-4.2.1 kernel) 64-bit version
                        compiled: Dec 19 2008, gcc-4.1.2 20070626 (Red Hat 4.1.2-13)
                              (readline v5.2 enabled, extended help available)

                                   Copyright (C) 2000-2006 The PARI Group

PARI/GP is free software, covered by the GNU General Public License, and comes WITHOUT ANY WARRANTY
WHATSOEVER.

Type ? for help, \q to quit.
Type ?12 for how to get moral (and possibly technical) support.

parisize = 8000000, primelimit = 500000
(11:55) gp > 9242.469-131.910
%1 = 9110.5590000000000000000000000000000000



*/
