Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

563640 views
1
#include "typedef.h"
2
#include "tools.h"
3
#include "matrix.h"
4
/**************************************************************************\
5
@---------------------------------------------------------------------------
6
@---------------------------------------------------------------------------
7
@ FILE: p_gauss_mat.c
8
@---------------------------------------------------------------------------
9
@---------------------------------------------------------------------------
10
@
11
\**************************************************************************/
12
13
/*{{{}}}*/
14
/*{{{ p_gauss*/
15
16
/**************************************************************************\
17
@---------------------------------------------------------------------------
18
@ int p_gauss (L_mat)
19
@ matrix_TYP *L_mat ;
20
@
21
@ applies a gauss algorithm to the rows of L_mat modulo L_mat->prime.
22
@ The entries of the matrix are changed.
23
@ The return is the rank of L_mat modulo L_mat->prime.
24
@---------------------------------------------------------------------------
25
@
26
\**************************************************************************/
27
int p_gauss (L_mat)
28
matrix_TYP *L_mat ;
29
{
30
int **M, *v, f, help ;
31
int *M_j, *M_act, numax;
32
int *ss, *nuin;
33
int i, j, k, kk, cL, cM, rL, rM, rg, act;
34
35
cM = cL = L_mat->cols;
36
rM = rL = L_mat->rows;
37
38
M = L_mat->array.SZ;
39
nuin= (int *)malloc((1+cM)*sizeof(int));
40
ss = (int *)malloc(cM*sizeof(int));
41
42
rg = 0;
43
/*------------------------------------------------------------*\
44
| Gauss Algorithm |
45
\*------------------------------------------------------------*/
46
for ( i = 0; i < cM; i++ ) {
47
#if 0
48
/*{{{ auskommentiert, printout*/
49
for(pri = 0; pri < rM; pri++) {
50
for(prj = 0; prj < cM; prj++) {
51
if(M[pri][prj] != 0) {
52
printf("%d ",M[pri][prj]);
53
} else {
54
printf(" ");
55
}
56
}
57
printf("\n");
58
}
59
printf(" i = %d \n", i);
60
/* ende der Einfuegung */
61
/*}}} */
62
#endif
63
ss[i] = -1;
64
/*---------------------------------------------------------*\
65
| Find the row with non-zero entry in i-th column |
66
\*---------------------------------------------------------*/
67
for ( j = rg; (j < rM) && (M[j][i] == 0); j++);
68
if ( j == rM ) {
69
continue;
70
}
71
act = j;
72
/*---------------------------------------------------------*\
73
| Normalize act-th row and mark the non-zero entries |
74
\*---------------------------------------------------------*/
75
nuin[0] = 1;
76
f = P(1,-M[j][i]);
77
for ( k = i ; k < cM; k++ ) {
78
if((help = M[act][k])) {
79
M[act][k] = P(help,f);
80
nuin[nuin[0]++] = k;
81
}
82
}
83
/*---------------------------------------------------------*\
84
| Swap act-th row and rg-th row |
85
\*---------------------------------------------------------*/
86
v = M[rg];
87
M[rg] = M[act];
88
M[act] = v;
89
ss[rg] = i;
90
act = rg ++;
91
/*---------------------------------------------------------*\
92
| Clear i-th column downwards |
93
\*---------------------------------------------------------*/
94
M_act = M[act];
95
for ( j = act+1; j < rM; j++) {
96
if ( (f = S(0,-M[j][i])) != 0 ) {
97
M_j = M[j];
98
M_j[i] = 0;
99
numax = nuin[0];
100
if( f == 1) {
101
for(k=2; k < numax; ++k ) {
102
kk = nuin[k];
103
M_j[kk] = S(M_j[kk],M_act[kk]);
104
}
105
} else {
106
for(k=2; k < numax; ++k ) {
107
kk = nuin[k];
108
M_j[kk] = S(M_j[kk],P(M_act[kk],f));
109
}
110
}
111
}
112
}
113
}
114
/*========================================================*\
115
|| clear it upwards ||
116
\*========================================================*/
117
for (i = rg-1; i > 0; i--) {
118
nuin[0] = 2;
119
nuin[1] = ss[i];
120
M_act = M[i];
121
for(j = ss[i]+1; j < cM; j++) {
122
if(M_act[j]) {
123
nuin[nuin[0]++] = j;
124
}
125
}
126
if(nuin[0] == 2) {
127
j = ss[i];
128
for (k = i-1; k > 0; k--) {
129
M[k][j] = 0;
130
}
131
} else {
132
for ( j = i-1; j >= 0; j--) {
133
if ( (f = S(0,-M[j][ss[i]])) != 0 ) {
134
M_j = M[j];
135
M_j[ss[i]] = 0;
136
numax = nuin[0];
137
if( f == 1) {
138
for(k=2; k < numax; ++k ) {
139
kk = nuin[k];
140
M_j[kk] = S(M_j[kk],M_act[kk]);
141
}
142
} else {
143
for(k=2; k < numax; ++k ) {
144
kk = nuin[k];
145
M_j[kk] = S(M_j[kk],P(M_act[kk],f));
146
}
147
}
148
}
149
}
150
}
151
}
152
free (ss);
153
free (nuin);
154
return (rg);
155
}
156
/*}}} */
157
158