forked from lbfm-rwth/GaussParallel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_seq_trafo.g
394 lines (371 loc) · 10.8 KB
/
main_seq_trafo.g
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
Chief := function( galoisField,mat,a,b )
## inputs: a finite field, a matrix, natural nr. a,b to treat mat as axb matirx
local nrows,
ncols,
rows,
rank,
tmpC,
tmpR,
tmp,
bs,
A,
B,
C,
D,
E,
K,
M,
R,
X,
v,
w,
i,
j,
k,
k_,
l,
h;
##Preparation: Init and chopping the matrix mat
C := ChopMatrix( galoisField,mat,a,b );
ncols := DimensionsMat( mat )[2];
A := [];
B := [];
D := [];
E := [];
K := [];
M := [];
R := [];
X := [];
nrows := [];
for i in [ 1 .. a ] do
A[i] := [];
E[i] := [];
K[i] := [];
for k in [ 1 .. b ] do
A[i][k] := rec( A:=[],M:=[],K:=[],rho:=[],E:=[],lambda:=[] );
E[i][k] := rec( rho:=[],delta:=[],nr:=0 );
od;
for h in [ 1 .. a ] do
K[i][h] := [];
od;
od;
for i in [ 1 .. b ] do
M[i] := [];
nrows[i] := DimensionsMat(C[1][i])[2];
for k in [ 1 .. a ] do
M[i][k] := [];
od;
od;
for k in [ 1 .. b ] do
D[k] := rec( remnant:=[],bitstring:=[] );
B[k] := [];
R[k] := [];
X[k] := [];
for j in [ 1 .. b ] do
B[k][j] := [];
R[k][j] := [];
X[k][j] := [];;
od;
od;
###############################
###############################
## Step 1 ##
for i in [ 1 .. a ] do
for j in [ 1 .. b ] do
tmp := ClearDown( galoisField,C[i][j],D[j],i );
D[j] := tmp.D;
A[i][j] := tmp.A;
if j=1 then
bs := rec( rho:=[],delta:=[],nr:=0 );
else
bs := E[i][j-1];
fi;
E[i][j] := Extend( A[i][j],bs,j );
for k in [ j+1 .. b ] do
tmp := UpdateRow( galoisField,A[i][j],C[i][k],
B[j][k],i );
C[i][k] := tmp.C;
B[j][k] := tmp.B;
od;
for h in [ 1 .. i ] do
tmp := UpdateRowTrafo( galoisField,A[i][j],K[i][h],
M[j][h],E[h][j],i,h,j );
K[i][h] := tmp.K;
M[j][h] := tmp.M;
od;
od;
od;
## Step 2 ##
for j in [ 1 .. b ] do
for h in [ 1 .. a ] do
M[j][h] := RowLengthen( galoisField,M[j][h],E[h][j],E[h][b] );
od;
od;
## Step3 ##
for k in [ 1 .. b ] do
R[k][k] := D[k].remnant;
od;
for k_ in [ 1 .. b ] do
k := b-k_+1;
for j in [ 1 .. (k - 1) ] do
tmp := CEX( galoisField,D[k].bitstring,B[j][k] );
X := tmp[1];
R[j][k] := tmp[2];
if IsEmpty(X) then continue; fi;
for l in [ k .. b ] do
if not IsEmpty(R[k][l]) then
if IsEmpty(R[j][l]) then
R[j][l] :=X*R[k][l];
else
R[j][l] := R[j][l] + X*R[k][l];
fi;
fi;
od;
for h in [ 1 .. a ] do
if not IsEmpty(M[k][h]) then
if IsEmpty(M[j][h]) then
M[j][h] := X*M[k][h];
else
M[j][h] := M[j][h] + X*M[k][h];
fi;
fi;
od;
od;
od;
Print("3\n");
###############################
###############################
## Write output
# Begin with row-select bitstring named v
v := [];
rank := 0;
w := 0*[1..(DimensionsMat(mat)[1]/a) ];
for i in [ 1 .. a ] do
if IsEmpty(E[i][b].rho) then
tmp := w;
else
tmp := E[i][b].rho;
fi;
v := Concatenation( v,tmp );
rank := rank + Sum( tmp );
od;
#### Glueing the blocks of M
B := NullMat( rank,Length(v),galoisField );
rows := [];
for j in [ 1 .. b ] do
rows[j] := 0;
for i in [ 1 .. a ] do
if not IsEmpty(M[j][i]) then
rows[j] := DimensionsMat(M[j][i])[1];
break;
fi;
od;
od;
tmpR := 1;
for j in [ 1 .. b ] do
if rows[j]=0 then
continue;
fi;
tmpC := 1;
w := DimensionsMat(mat)[1]/a;
for i in [ 1 .. a ] do
if IsEmpty(M[j][i]) then
if IsEmpty(E[i][b].rho) then
tmp := w;
else
tmp := Length( E[i][b].rho );
fi;
tmpC := tmpC + tmp; continue;
#M[j][i] := NullMat( rows[j],tmp,galoisField );
else
M[j][i] := TransposedMat( RRF( galoisField,
NullMat( Length(E[i][b].rho)-
DimensionsMat(M[j][i])[2],
DimensionsMat(M[j][i])[1],galoisField ),
TransposedMat(M[j][i]),E[i][b].rho ) );
fi;
B{[tmpR .. tmpR + DimensionsMat(M[j][i])[1]-1 ]}{[tmpC .. tmpC + DimensionsMat(M[j][i])[2]-1 ]}
:= M[j][i];
tmpC := tmpC + DimensionsMat(M[j][i])[2];
od;
tmpR := tmpR + rows[j];
od;
### Glueing the blocks of R
C := NullMat( rank,ncols-rank,galoisField );
rows := [];
w := [];
for i in [ 1 .. b ] do
rows[i] := 0;
if IsEmpty(D[i].bitstring) then
w := Concatenation( w,0*[1..nrows[i]] );
else
w := Concatenation( w,D[i].bitstring );
fi;
for j in [ 1 .. b ] do
if not IsEmpty(R[i][j]) then
rows[i] := DimensionsMat(R[i][j])[1];
break;
fi;
od;
od;
tmpR := 1;
for i in [ 1 .. b ] do
if rows[i]=0 then
continue;
fi;
tmpC := 1;
for j in [ 1 .. b ] do
if IsEmpty(R[i][j]) then
if not IsEmpty(D[j].bitstring) then
tmpC := tmpC + Sum( 1 - D[j].bitstring );
elif not IsEmpty(R[1][j]) then
tmpC := tmpC + DimensionsMat(R[1][j])[2];
fi;
continue;
fi;
C{[tmpR .. tmpR + DimensionsMat(R[i][j])[1]-1 ]}{[tmpC .. tmpC + DimensionsMat(R[i][j])[2]-1 ]}
:= R[i][j];
tmpC := tmpC + DimensionsMat(R[i][j])[2];
od;
tmpR := tmpR + rows[i];
od;
C := TransposedMat( RRF( galoisField,TransposedMat(C), -IdentityMat( rank,galoisField ),w ) );
## Glueing the blocks of K
D := NullMat( Length(v)-rank,Length(v),galoisField );
X := IdentityMat( Length(v)-rank,galoisField );
rows := [];
for j in [ 1 .. a ] do
rows[j] := 0;
for i in [ 1 .. a ] do
if IsEmpty(K[j][i]) then
rows[j] := Length(E[j][b].rho) - Sum(E[j][b].rho);
else
rows[j] := DimensionsMat(K[j][i])[1];
break;
fi;
od;
od;
tmpR := 1;
for j in [ 1 .. a ] do
if rows[j]=0 then
continue;
fi;
tmpC := 1;
for i in [ 1 .. a ] do
if IsEmpty(K[j][i]) then
if IsEmpty(E[i][b].rho) then
#tmp := b;
tmp := DimensionsMat(mat)[1]/a;
else
tmp := Length( E[i][b].rho );
fi;
tmpC := tmpC + tmp; continue;
#K[j][i] := NullMat( rows[j],tmp,galoisField );
else
K[j][i] := TransposedMat( RRF( galoisField,
NullMat( Length(E[i][b].rho)-
DimensionsMat(K[j][i])[2],
DimensionsMat(K[j][i])[1],galoisField ),
TransposedMat(K[j][i]),E[i][b].rho ) );
fi;
D{[tmpR .. tmpR + DimensionsMat(K[j][i])[1]-1 ]}
{[tmpC .. tmpC + DimensionsMat(K[j][i])[2]-1 ]}
:= K[j][i];
tmpC := tmpC + DimensionsMat(K[j][i])[2];
od;
tmpR := tmpR + rows[j];
od;
D := TransposedMat( RRF( galoisField,X,
TransposedMat( CEX( galoisField,v,D )[1] ),v ) );
return rec( transformation:=B,remnant:=C,relations:=D,
pivotrows:=v,pivotcols:=w,rank:=rank);
end;
Chief_debug := function( galoisField,mat,a,b )
local tmp,
bs,
A,
B,
C,
D,
E,
K,
M,
R,
X,
i,
j,
k,
h;
##Preparation: Init and chopping the matrix mat
C := ChopMatrix( galoisField,mat,a,b );
A := [];
B := [];
D := [];
E := [];
K := [];
M := [];
R := [];
X := [];
for i in [ 1 .. a ] do
A[i] := [];
E[i] := [];
K[i] := [];
for k in [ 1 .. b ] do
A[i][k] := rec( A:=[],M:=[],K:=[],rho:=[],E:=[],lambda:=[] );
E[i][k] := rec( rho:=[],delta:=[],nr:=0 );
od;
for h in [ 1 .. a ] do
K[i][h] := [];
od;
od;
for i in [ 1 .. b ] do
M[i] := [];
for k in [ 1 .. a ] do
M[i][k] := [];
od;
od;
for k in [ 1 .. b ] do
D[k] := rec( remnant:=[],bitstring:=[] );
B[k] := [];
R[k] := [];
X[k] := [];
for j in [ 1 .. b ] do
B[k][j] := [];
R[k][j] := [];
X[k][j] := [];;
od;
od;
###############################
###############################
## Step 1 ##
for i in [ 1 .. a ] do
for j in [ 1 .. b ] do
Error( "BEFORE CLEARDOWN" );
tmp := ClearDown( galoisField,C[i][j],D[j],i );
D[j] := tmp.D;
A[i][j] := tmp.A;
if j=1 then
bs := rec( rho:=[],delta:=[],nr:=0 );
else
bs := E[i][j-1];
fi;
E[i][j] := Extend( A[i][j],bs,j );
Error( "AFTER CLEARDOWN" );
for k in [ j+1 .. b ] do
tmp := UpdateRow( galoisField,A[i][j],C[i][k],
B[j][k],i );
C[i][k] := tmp.C;
B[j][k] := tmp.B;
od;
Error( "AFTER UPDATEROW" );
for h in [ 1 .. i ] do
tmp := UpdateRowTrafo( galoisField,A[i][j],K[i][h],
M[j][h],E[h][j],i,h,j );
K[i][h] := tmp.K;
M[j][h] := tmp.M;
od;
Error( "AFTER UPDATETRAFO" );
od;
od;
return true;
end;