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