"Fossies" - the Fresh Open Source Software Archive

Member "pari-2.13.1/src/test/in/mat" (12 Dec 2020, 6899 Bytes) of package /linux/misc/pari-2.13.1.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "mat": 2.13.0_vs_2.13.1.

    1 iferr(Mat([1]) + matrix(0,1),E,E)
    2 iferr(1/matrix(2,2,i,j,Mod(0, 2)),E,E)
    3 test(n)=
    4 {
    5   until(matrank(M)==n,M=matrix(n,n,i,j,random(Mod(1,2))));
    6   if(M^-1*M!=matid(n),error("F2m"));
    7 }
    8 test(200)
    9 test(2)
   10 
   11 matsize(matrix(0, 0) * matrix(0, 2))
   12 
   13 default(realprecision,38);
   14 h=mathilbert(40);
   15 [Q,R] = matqr(h); vecmax(abs(h-Q*R)) < 1e-37
   16 [q,R] = matqr(h,1); vecmax(abs(mathouseholder(q,h)-R)) < 1e-37
   17 matqr([;])
   18 matqr([;],1)
   19 mathouseholder(q, vectorv(40,i,1))
   20 Mat(List())
   21 Mat(List([1]))
   22 Mat([[1,2,3],[2,3,4]]~)
   23 Mat(Qfb(1,2,5))
   24 matdiagonal(matid(2))
   25 iferr(matdiagonal([1,2;3,4]),E,E)
   26 matpascal(4,1/2)
   27 A=[1,2,3;4,5,6];B=[4,6;10,12]
   28 matinverseimage(A,B)
   29 matinverseimage(A*Mod(1,2),B)
   30 matinverseimage(A*Mod(1,7),B)
   31 matinverseimage(A*Mod(1,2^64+13),B)
   32 matinverseimage(A*Mod(1,3037000507),B)
   33 B=[4,10]~;
   34 matinverseimage(A*Mod(1,2),B)
   35 matinverseimage(A*Mod(1,7),B)
   36 matinverseimage(A*Mod(1,2^64+13),B)
   37 matinverseimage(A*Mod(1,3037000507),B)
   38 
   39 test(f)=
   40 {
   41   print(f,":");
   42   print(f(A*Mod(1,2)));
   43   print(f(A*Mod(1,7)));
   44   print(f(A*Mod(1,3037000507)));
   45   print(f(A*Mod(1,2^64+13)));
   46   print(f(A*(1+O(101^3))));
   47 }
   48 testall()=
   49 {
   50   test(matdet);
   51   test(matrank);
   52   test(matadjoint);
   53   test(matimage);
   54   test(matimagecompl);
   55   test(matindexrank);
   56   test(matker);
   57   test(lindep);
   58   test(x->matsolve(x,vectorv(#x,i,i)));
   59   test(x->matsolve(x,matrix(#x,#x,i,j,i+j)));
   60   test(x->x^(-1));
   61   test(x->x^2);
   62   test(x->A*x);
   63 }
   64 A = [1,2,4;2,12,7;2,9,11];
   65 testall();
   66 A = [;]
   67 testall();
   68 
   69 A=[0,1,0;1,0,1;2,0,3];
   70 matdet(A*Mod(1,3037000507))
   71 matdet(A*Mod(1,2^64+13))
   72 matsolve(A*Mod(1,2^64+13),[1,2,3]~)
   73 m=[1,0;0,0;0,1]; b=[1,2;0,0;3,4];
   74 matsolve(m,b)
   75 matsolve(m/2,b)
   76 matsolve(m*Mod(1,2),b)
   77 matsolve(m*Mod(1,3),b)
   78 matsolve(m*Mod(1,2^64+13),b)
   79 matsolve(m*ffgen(2^3)^0,b)
   80 \\ #2261
   81 matsolve([1,1,1/2; 1,0,1/2; 2,1,0], [-1;1;-1])
   82 
   83 matker([1.,I;I,-1.])
   84 matkerint(Mat([1,1]))
   85 
   86 trace(matid(3))
   87 trace([;])
   88 iferr(trace(Mat([1,2])),E,E)
   89 matrixqz([1/3,1/4;1/2,1/3])
   90 matrixqz(matrix(2,2),-1)
   91 m=[1,-4,6,1;-13,14,-8,-3;0,0,0,0;0,0,0,0;7,-9,3,2;-7,9,7,4;0,0,0,0;0,0,0,0;10,-2,-2,0;0,0,-4,-4;0,0,0,0;0,0,0,0;-7,9,-7,-4;-4,-3,7,3;0,0,0,0;0,0,0,0;-5,1,9,4;1,-4,-10,-5;0,0,0,0;0,0,0,0;-13,14,-8,-5;-3,-7,7,4;0,0,0,0;0,0,0,0;-18,15,5,3;8,6,-6,-2;0,0,0,0;0,0,0,0;0,0,0,0;4,3,3,1;0,0,0,0;0,0,0,0;11,-6,4,3;-7,9,7,2;0,0,0,0;0,0,0,0;-5,1,7,4;4,3,1,1;0,0,0,0;0,0,0,0;-6,5,-9,-7;-9,-2,10,7;0,0,0,0;0,0,0,0;-1,4,-4,-1;-20,4,6,4;0,0,0,0;0,0,0,0;0,0,-8,-4;9,2,6,3;0,0,0,0;0,0,0,0;0,0,0,0;0,0,0,0;3,7,1,0;6,-5,-7,-5;0,0,0,0;0,0,0,0;-11,6,8,5;0,0,-6,-4;0,0,0,0;0,0,0,0;-12,10,10,6;0,0,-8,-4;0,0,0,0;0,0,0,0;-5,1,3,2;-6,5,-7,-3;0,0,0,0;0,0,0,0;10,-2,-6,-4;-4,-3,3,1;0,0,0,0;0,0,0,0;0,0,0,0;0,0,0,0;0,0,0,0;0,0,0,0;-2,8,0,-2;2,-8,-4,-2;0,0,0,0;0,0,0,0];
   92 a=matrixqz(m,-2);matdet(a~*a)
   93 matrixqz([2,0;0,2;1,0;0,1],-2)
   94 matrixqz([1,0;0,2/3;1/2,0;0,1/3],-2)
   95 matrixqz([1/2,0;0,0],-1)
   96 matrixqz([1/2;0],-1)
   97 matrixqz([;],-2)
   98 mathnf(matrixqz(matrix(3,3,i,j,1/(i+j)),-2))
   99 mathnf(matrixqz(matrix(4,2,i,j,1/(i+13*j+1))*matrix(2,4,i,j,(i+j)/(i^2+j^2)),-2))
  100 mathnf(matrixqz([2/5,3;0,0;1,1/7],-2))
  101 
  102 A=[1,2,3;4,5,6;7,8,9];
  103 test(lindep)
  104 test(matsupplement)
  105 A=matrix(5,1);
  106 test(matsupplement)
  107 
  108 default(parisize,10^6); \\ need to exercise gerepile in matker+matimage
  109 p=2^64+13;
  110 A=matrix(70,70,i,j, i+j);
  111 Ap=Mod(A,p);
  112 #matker(Ap)
  113 #matimage(Ap)
  114 #matker(A)
  115 matker([3,0,2,2;1,3,3,3])
  116 vecsum([])
  117 vecsum([2])
  118 vecsum(primes(4))
  119 vecprod([])
  120 vecprod([1,2,3])
  121 
  122 content([])
  123 content([;])
  124 content(matrix(0,2))
  125 
  126 vectorsmall(3)
  127 v=vectorsmall(3,i,3*i^2)
  128 content(v)
  129 content(vectorsmall(0))
  130 v=vectorsmall(5,i,(3-i)*i)
  131 content(v)
  132 
  133 m=[1,0;0,0;0,1]; b=[1,2;0,0;3,4];
  134 liftint(Mod(m,2)^(-1))
  135 liftint(Mod(m,3)^(-1))
  136 liftint(Mod(m,2^64+13)^(-1))
  137 liftint(matsolve(Mod(m,2),b))
  138 liftint(matsolve(Mod(m,3),b))
  139 liftint(matsolve(Mod(m,2^64+13),b))
  140 (m*ffgen(2^2)^0)^(-1)
  141 (m*ffgen(3^2)^0)^(-1)
  142 (m*ffgen((2^64+13)^2)^0)^(-1)
  143 
  144 m=[1,2,3;4,5,6];
  145 m[2,]=[1,2,3]
  146 m
  147 m[1,]*=2
  148 m
  149 
  150 test(t) =
  151 {
  152    N = [1, 2; -1, -2]*t^0;
  153    print(matinverseimage(N, N^0));
  154 }
  155 test(Mod(1, 3));
  156 test(Mod(1, nextprime(2^64)));
  157 test(ffgen(2^17));
  158 test(ffgen(2017^3));
  159 test(ffgen(nextprime(2^64)^3));
  160 
  161 p = nextprime(2^63);
  162 q = nextprime(p + 1);
  163 {
  164    forvec(v = vector(8, i, [0, 2]),
  165           matker([p^v[1]*q^v[2], p^v[3]*q^v[4];
  166                   p^v[5]*q^v[6], p^v[7]*q^v[8]], 1));
  167 }
  168 
  169 test(x,u=1) =
  170 {
  171    n = 22; r = 12;
  172    M = matrix(n, n, i, j, random(x)*u);
  173    P = matrix(n, r, i, j, if(2*i >= 3*j + 8, random(x)*u, 0));
  174    N = P*matrix(r, n, i, j, random(x)*u);
  175    S = matsupplement(P);
  176    Q = N[,1..r];
  177    R = mattranspose(P);
  178    X = matsolve(M, N);
  179    K = matker(N);
  180    J = matimage(N);
  181    if (M*X != N, error("M*X == N"));
  182    if (N*K != 0,error("N*K == 0"));
  183    if (N*lindep(N) != 0, error("lindep(N)"));
  184    if (R*lindep(R) != 0, error("lindep(R)"));
  185    if (matimage(J) != J, error("matimage(J)"));
  186    if (matdet(S) == 0, error("matsupplement(S)"));
  187    if (matrank(J) != r, error("matrank(J)"));
  188    if (matrank(K) != n - r, error("matrank(K)"));
  189    if (matrank(N) != r, error("matrank(N)"));
  190    if (J^-1 * J != matid(r), error("J^-1 * J"));
  191    if (matdet(M^-1) != matdet(M)^-1, error("matdet"));
  192    if (P*matinverseimage(P, Q) != Q, error("matinverseimage"));
  193    if(#lindep(J), error("lindep(J)"));
  194    if(#matker(K), error("matker(K)"));
  195    if(#matker(M), error("matker(M)"));
  196    if(#matinverseimage(N, M),error("matinverseimage(N, M)"));
  197    if(#matinverseimage(P, M),error("matinverseimage(P, M)"));
  198    iferr(N^-1, e,, errname(e) == "e_INV");
  199    iferr(matsolve(N, M), e,, errname(e) == "e_INV");
  200 }
  201 p=nextprime(2^65);
  202 test(Mod(1, 8161));
  203 test(Mod(1, p));
  204 default(parisize,16*10^6);
  205 test(ffgen([2017,3]));
  206 test(ffgen([p,2]));
  207 test(x^3*Mod(1,17),Mod(1,ffinit(17,4)));
  208 test(x^2*Mod(1,p),Mod(1,ffinit(p,3)));
  209 
  210 test(x,u=1) =
  211 {
  212   my(R = matrix(5, 5, i, j, random(x)*u));
  213   if(R^2+R!=R*(R+1),error([x,u]));
  214 }
  215 test(10*x^3,Mod(1,x^4+7*x^3+12*x+5));
  216 test(10*x^3,Mod(1,(x^4+7*x^3+12*x+5)/7));
  217 test(10*x^3,Mod(1,5*x^4+7*x^3+12*x+5));
  218 test(10*x^3,Mod(1/11,x^4+7*x^3+12*x+5));
  219 test(10*x^3,Mod(1/11,(x^4+7*x^3+12*x+5)/7));
  220 test(10*x^3,Mod(1/11,5*x^4+7*x^3+12*x+5));
  221 
  222 [0,0;-1,0;1,1]^(-1)
  223 [1,2;3,4;5,6]^-1
  224 
  225 A=[0,0;-10,200;-4,80;0,0;-10,200;-4,80;-50,1000;-80,1600;-28,560];
  226 B=[0,1;0,0;0,0;-3,-2;20,10;25,-10;-8,-6;30,20;25,-15];
  227 matintersect(A,B)
  228 
  229 a = ffgen([65537, 96]);
  230 M = matrix(40, 30, i, j, random(a)) * matrix(30, 40, i, j, random(a));
  231 matrank(M)
  232 
  233 M=matrix(100,200);N=matrix(200,100);
  234 [matsize(M*N), matsize(N*M)]
  235 
  236 A=[x,2;y,4]; B=[x,-2; y,3; 3, 4]; matreduce(matconcat([A,B]~))
  237 matreduce(matrix(0,2))
  238 matreduce([])
  239 matreduce([1,1,2,1,3,1,2])
  240 matreduce([1])
  241 
  242 \\ Errors, keep at end of file
  243 1/Mat([0,0]~)
  244 mathouseholder(1,1)
  245 [q,r]=matqr(matid(2),1); mathouseholder(q,1)
  246 matsolve([1,0;0,0]*Mod(1,2),[1,1]~)
  247 matsolve([1,0;0,0]*Mod(1,3),[1,1]~)
  248 vecsum(1)
  249 1~
  250 vectorsmall(3,i,i^100)
  251 m=[1,2,3;4,5,6];
  252 m[1,]=[1,2]
  253 m[1,]=[1,2,3,4]
  254 m[1,]=[1,2,3]~
  255 [1,2,3;4,5,6]^-1
  256 [1,2,3;4,5,6;7,8,9]^-1
  257 matrixqz(matrix(2,2))
  258 matrixqz([;],-3)
  259 matreduce(1)
  260 matreduce([;])
  261 matreduce([1,x;1,y])