File: testlinalg.g

package info (click to toggle)
gap 4r4p12-2
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 29,584 kB
  • ctags: 7,113
  • sloc: ansic: 98,786; sh: 3,299; perl: 2,263; makefile: 498; asm: 63; awk: 6
file content (72 lines) | stat: -rw-r--r-- 1,222 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
TestLinAlg := function()
local p,e,q,f,a,b,c,m,n,x,y,i,j,k;
  p:=Random([1..400]);
  p:=NextPrimeInt(p);
  e:=Random([1..LogInt(65536,p)]);
  q:=p^e;
  f:=GF(q);
  a:=Random([1..200]);
  b:=Random([1..200]);
  c:=Random([1..200]);

  Print(">",a," ",b," ",c,":",f,"\n");
  m:=RandomMat(a,b,f);
  n:=RandomMat(b,c,f);
  x:=m*n;

  if Length(x)<>a then
    Error("rows of product");
  fi;

  if ForAny(x,i->Length(i)<>c) then
    Error("columns of product");
  fi;

  # now compute the product the hard way
  y:=[];
  for i in [1..a] do
    y[i]:=[];
    for j in [1..c] do
      y[i][j]:=Zero(f);
      for k in [1..b] do
        y[i][j]:=y[i][j]+m[i][k]*n[k][j];
      od;
    od;
  od;

  if x<>y then
    Error("arith error",i," ",j);
  fi;

  for i in [1..b] do
    x:=m[1][i]*n[i];
    y:=n[i]*m[1][i];
    if x<>y then
      Error("scalmul1");
    fi;
    for k in [1..c] do
      if x[k]<>m[1][i]*n[i][k] then
	Error("scalmul2");
      fi;
    od;

    x:=m[1][i]+n[i];
    y:=n[i]+m[1][i];
    if x<>y then
      Error("scaladd1");
    fi;
    for k in [1..c] do
      if x[k]<>m[1][i]+n[i][k] then
	Error("scaladd2");
      fi;
    od;

  od;

end;

DWIM:=function()
  repeat
    TestLinAlg();
  until false;
end;