/*

Find the average times to compute sums of Witt vectors over
finite fields with two methods:

* precompute the formulas and then evaluate
  (disregard time to compute the formulas)

* use recursion


*/

load 'witt2_fun.m';

p:=101;
time vecS:=WittSum2Pol(p);

n:=20;

 
F:=GF(p^n);
tms1:=[];
tms2:=[];
tms3:=[];

magma_witt:=false;

ntry:=7;
for i in [1..ntry] do

    v1:=[Random(F), Random(F), Random(F)]; v2:=[Random(F), Random(F), Random(F)];
    t1:=Cputime();
    tmp1:=WittSum2(v1,v2);
    print "t1 = ", Cputime(t1);
    Append(~tms1,Cputime(t1));

    t2:=Cputime();
    tmp2:=WittSum22(v1,v2 : vecS:=vecS);
    print "t2 = ", Cputime(t2);
    Append(~tms2,Cputime(t2));

    if tmp1 ne tmp2 then
        print "ERROR";
    end if;

    if magma_witt then
        W:=WittRing(F,3);
        t3:=Cputime();
        tmp3:=W!v1 + W!v2;
        Append(~tms3,Cputime(t3));
    end if;
        
end for;

print tms1;
print tms2;

print "NEW = ", (&+tms1)/ntry;
print "OLD = ", (&+tms2)/ntry;
if magma_witt then
    print "MAGMA = ", (&+tms3)/ntry;
end if;

print "";
print "";


/*

The new values are not as good, since pol_p_power has to test
if we are using a finite field or not (I guess).

31^4 gives:
NEW =  0.280
OLD =  0.083

31^5 gives:
NEW =  0.359
OLD =  5.090

11^15 gives:
NEW =  0.017
OLD =  0.016

13^7 gives:
NEW =  0.037
OLD =  0.114

23^10 gives:
NEW =  0.118
OLD =  0.714

43^4 gives:
NEW =  1.084
OLD =  3.551

53^4 gives:
NEW =  2.802
OLD =  8.747

61^4 gives:
NEW =  5.590
OLD =  16.633

101^10 gives:
NEW =  82.643
OLD =  889.167
Total memory usage: 2241.97MB

101^20 gives:
NEW =  85.779
OLD =  2027.190


*/
