Peter Bruin on Mon, 27 Jan 2014 15:23:55 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: new FFM_mul (and FlxqM_mul, FqM_mul, ...)


Hi Bill,

There was a bug in my recent patch implementing FFM_mul et al.  I should
have been more suspicious (and actually have run/written some tests)
when I wrote

>> The matrix * matrix functions are covered by the current test suite,
>> but the matrix * column vector functions are not.

In fact, FFM_FFC_mul did not work at all!  The attached patch fixes the
problem and adds a test for the matrix * column vector functions.

Cheers,

Peter


diff --git a/src/basemath/FF.c b/src/basemath/FF.c
index c5116b6..1dfb9aa 100644
--- a/src/basemath/FF.c
+++ b/src/basemath/FF.c
@@ -1754,7 +1754,7 @@ FFM_FFC_mul(GEN M, GEN C, GEN ff)
   case t_FF_F2xq: P = F2xqM_F2xqC_mul(M, C, T); break;
   default: P = FlxqM_FlxqC_mul(M, C, T, pp); break;
   }
-  return gerepilecopy(av, raw_to_FFM(P, ff));
+  return gerepilecopy(av, raw_to_FFC(P, ff));
 }
 
 GEN
diff --git a/src/test/32/ff b/src/test/32/ff
index 2d11fe6..d6333d6 100644
--- a/src/test/32/ff
+++ b/src/test/32/ff
@@ -240,19 +240,21 @@ t^2 + Mod(1, 5)*t + Mod(3, 5))*x^3 + Mod(Mod(0, 5), Mod(1, 5)*t^4 + Mod(1, 5
 od(4, 5)*t, Mod(1, 5)*t^4 + Mod(1, 5)*t^3 + Mod(2, 5)*t^2 + Mod(1, 5)*t + Mo
 d(3, 5)) 1]
 
-? test(q)=my(t=ffgen(q,'t),m=[t,t^2,1+t^3;1+t,1+t^2,1+t^3]);print(matker(m));print(matimage(m));print(matrank(m));my(M=[t,2*t^0,3*t^0;t,t^2,1+t^3;1+t,1+t^2,1+t^3]);print(matdet(M));print(M^(-1)*M);
+? test(q)=my(t=ffgen(q,'t),m=[t,t^2,1+t^3;1+t,1+t^2,1+t^3]);print(matker(m));print(matimage(m));print(matrank(m));my(M=[t,2*t^0,3*t^0;t,t^2,1+t^3;1+t,1+t^2,1+t^3]);print(matdet(M));print(M^(-1)*M);my(v=[t^0,t^1,t^2]~);print(M*v);
 ? test(2^5)
 [t^4 + t^3; t^4 + t^3; 1]
 [t, t^2; t + 1, t^2 + 1]
 2
 t^4 + t^2
 [1, 0, 0; 0, 1, 0; 0, 0, 1]
+[t^2 + t, t^4 + t^3 + 1, t^4 + t^3 + t]~
 ? test(7^5)
 [3*t^4 + 5*t^3 + 6*t^2 + 2*t; 4*t^4 + 2*t^3 + t^2 + 5*t; 1]
 [t, t^2; t + 1, t^2 + 1]
 2
 6*t^4 + 2*t^3 + 4*t^2 + 2*t + 2
 [1, 0, 0; 0, 1, 0; 0, 0, 1]
+[3*t^2 + 3*t, 6*t^4 + 5*t^3 + 4*t^2 + 5*t + 6, 6*t^4 + 5*t^3 + 4*t^2 + 6*t]~
 ? test((2^64+13)^5)
 [3*t^4 + 5*t^3 + 18446744073709551621*t^2 + 18446744073709551617*t; 18446744
 073709551626*t^4 + 18446744073709551624*t^3 + 8*t^2 + 12*t; 1]
@@ -260,6 +262,9 @@ t^4 + t^2
 2
 18446744073709551628*t^4 + 2*t^3 + 18446744073709551626*t^2 + 2*t + 2
 [1, 0, 0; 0, 1, 0; 0, 0, 1]
+[3*t^2 + 3*t, 18446744073709551628*t^4 + 5*t^3 + 4*t^2 + 1844674407370955162
+7*t + 18446744073709551628, 18446744073709551628*t^4 + 5*t^3 + 4*t^2 + 18446
+744073709551628*t]~
 ? p=2^64+13;g=ffprimroot(ffgen(p^2),&o);a=2*g^0;
 ? v=[I,-1,Mat(1),matid(2)/2];
 ? for(i=1,#v,print(iferr(fflog(a,g,v[i]),E,E)));
diff --git a/src/test/64/ff b/src/test/64/ff
index 4400fce..2b163ca 100644
--- a/src/test/64/ff
+++ b/src/test/64/ff
@@ -243,19 +243,21 @@ t^2 + Mod(1, 5)*t + Mod(3, 5))*x^3 + Mod(Mod(0, 5), Mod(1, 5)*t^4 + Mod(1, 5
 od(4, 5)*t, Mod(1, 5)*t^4 + Mod(1, 5)*t^3 + Mod(2, 5)*t^2 + Mod(1, 5)*t + Mo
 d(3, 5)) 1]
 
-? test(q)=my(t=ffgen(q,'t),m=[t,t^2,1+t^3;1+t,1+t^2,1+t^3]);print(matker(m));print(matimage(m));print(matrank(m));my(M=[t,2*t^0,3*t^0;t,t^2,1+t^3;1+t,1+t^2,1+t^3]);print(matdet(M));print(M^(-1)*M);
+? test(q)=my(t=ffgen(q,'t),m=[t,t^2,1+t^3;1+t,1+t^2,1+t^3]);print(matker(m));print(matimage(m));print(matrank(m));my(M=[t,2*t^0,3*t^0;t,t^2,1+t^3;1+t,1+t^2,1+t^3]);print(matdet(M));print(M^(-1)*M);my(v=[t^0,t^1,t^2]~);print(M*v);
 ? test(2^5)
 [t^4 + t^3; t^4 + t^3; 1]
 [t, t^2; t + 1, t^2 + 1]
 2
 t^4 + t^2
 [1, 0, 0; 0, 1, 0; 0, 0, 1]
+[t^2 + t, t^4 + t^3 + 1, t^4 + t^3 + t]~
 ? test(7^5)
 [3*t^4 + 5*t^3 + 6*t^2 + 2*t; 4*t^4 + 2*t^3 + t^2 + 5*t; 1]
 [t, t^2; t + 1, t^2 + 1]
 2
 6*t^4 + 2*t^3 + 4*t^2 + 2*t + 2
 [1, 0, 0; 0, 1, 0; 0, 0, 1]
+[3*t^2 + 3*t, 6*t^4 + 5*t^3 + 4*t^2 + 5*t + 6, 6*t^4 + 5*t^3 + 4*t^2 + 6*t]~
 ? test((2^64+13)^5)
 [3*t^4 + 5*t^3 + 18446744073709551621*t^2 + 18446744073709551617*t; 18446744
 073709551626*t^4 + 18446744073709551624*t^3 + 8*t^2 + 12*t; 1]
@@ -263,6 +265,9 @@ t^4 + t^2
 2
 18446744073709551628*t^4 + 2*t^3 + 18446744073709551626*t^2 + 2*t + 2
 [1, 0, 0; 0, 1, 0; 0, 0, 1]
+[3*t^2 + 3*t, 18446744073709551628*t^4 + 5*t^3 + 4*t^2 + 1844674407370955162
+7*t + 18446744073709551628, 18446744073709551628*t^4 + 5*t^3 + 4*t^2 + 18446
+744073709551628*t]~
 ? p=2^64+13;g=ffprimroot(ffgen(p^2),&o);a=2*g^0;
 ? v=[I,-1,Mat(1),matid(2)/2];
 ? for(i=1,#v,print(iferr(fflog(a,g,v[i]),E,E)));
diff --git a/src/test/in/ff b/src/test/in/ff
index 499bd9a..6404029 100644
--- a/src/test/in/ff
+++ b/src/test/in/ff
@@ -95,6 +95,8 @@ test(q)=
   my(M = [t,2*t^0,3*t^0; t,t^2,1+t^3; 1+t,1+t^2,1+t^3]);
   print(matdet(M));
   print(M^(-1)*M);
+  my(v = [t^0, t^1, t^2]~);
+  print(M*v);
 }
 test(2^5)
 test(7^5)