GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
#include"typedef.h"1/**************************************************************************\2@---------------------------------------------------------------------------3@---------------------------------------------------------------------------4@ FILE: compare.c5@---------------------------------------------------------------------------6@---------------------------------------------------------------------------7@8\**************************************************************************/9/*******************************************************************\10@ This file conatain functions that compare matrices or pointer11@ to integer with respect to different lexikographic orders.12@ The functions return -1 if the first arument is smaller with13@ respect to the lexicographic order,14@ 0 if tboth arguments are equal15@ 1 if the first argument is bigger16@17@ If the arguments are 1-dimensional arrays, then the first18@ entry in which they differ decides.19@ For two dimensional arrays v < w if and only if20@ v[i][j] < w[i][j] and21@ v[k][j] == w[k][j] for all k < i and 0<=j<= dim22@ v[i][k] == w[i][k] for all k < j23@ For two dimensional symmetric arrays v < w if and only if24@ v[i][j] < w[i][j] and25@ v[k][j] == w[k][j] for all k < i and j<= i and26@ v[i][k] == w[i][k] for all k < j27@28@ for functions that compare first cols v < w if v^{tr} < w^{tr}29@ in the above sense.30\*******************************************************************/31323334/**************************************************************************\35@---------------------------------------------------------------------------36@ int mat_comp(m1, m2)37@ matrix_TYP *m1, *m2;38@39@ compares m1->array.SZ and m2->array.SZ40@---------------------------------------------------------------------------41@42\**************************************************************************/43int mat_comp(m1, m2)44matrix_TYP *m1, *m2;45{46int i,47j,48*m1SZ,49*m2SZ;5051if(m1->cols != m2->cols || m1->rows != m2->rows)52{53printf("cannot compare %dx%d with %dx%d-matrix\n", m1->rows, m1->cols, m2->rows, m2->cols);54exit(3);55}5657for(i=0;i<m1->rows;i++){58m1SZ = m1->array.SZ[i];59m2SZ = m2->array.SZ[i];60for(j=0; j<m1->cols;j++,m1SZ++,m2SZ++){61if(*m1SZ > *m2SZ)62return(1);63if(*m1SZ != *m2SZ)64return(-1);65}66}6768return(0);69}70717273/**************************************************************************\74@---------------------------------------------------------------------------75@ int mat_col_comp(m1, m2)76@ matrix_TYP *m1, *m2;77@78@ compares m1->array.Sz and m2->array.SZ by going to the columns79@---------------------------------------------------------------------------80@81\**************************************************************************/82int mat_col_comp(m1, m2)83matrix_TYP *m1, *m2;84{85int i,j;86if(m1->cols != m2->cols || m1->rows != m2->rows)87{88printf("cannot compare %dx%d with %dx%d-matrix\n", m1->rows, m1->cols, m2->rows, m2->cols);89exit(3);90}91for(i=0;i<m1->cols;i++)92for(j=0; j<m1->rows;j++)93{94if(m1->array.SZ[j][i] != m2->array.SZ[j][i])95{96if(m1->array.SZ[j][i] > m2->array.SZ[j][i])97return(1);98return(-1);99}100}101return(0);102}103104105106/**************************************************************************\107@---------------------------------------------------------------------------108@ int lower_triangular_mat_comp(m1,m2)109@ matrix_TYP *m1, *m2;110@111@ compares the symmetric arrays m1->array.SZ and m2->array.SZ112@---------------------------------------------------------------------------113@114\**************************************************************************/115int lower_triangular_mat_comp(m1,m2)116matrix_TYP *m1, *m2;117{118int i,j;119if(m1->cols != m2->cols || m1->rows != m2->rows)120{121printf("cannot compare %dx%d with %dx%d-matrix\n", m1->rows, m1->cols, m2->rows, m2->cols);122exit(3);123}124for(i=0;i<m1->rows;i++)125for(j=0; j<=i;j++)126{127if(m1->array.SZ[i][j] != m2->array.SZ[i][j])128{129if(m1->array.SZ[i][j] > m2->array.SZ[i][j])130return(1);131return(-1);132}133}134return(0);135}136137138139/**************************************************************************\140@---------------------------------------------------------------------------141@ int vec_comp(v1, v2, dim)142@ int *v1, *v2, dim;143@144@ compares the 1-dimensional arrays v1 and v2 of length dim145@---------------------------------------------------------------------------146@147\**************************************************************************/148int vec_comp(v1, v2, dim)149int *v1, *v2, dim;150{151int i;152for(i=0;i<dim;i++)153{154if(v1[i] != v2[i])155{156if(v1[i] > v2[i])157return(1);158return(-1);159}160}161return(0);162}163164165166167/**************************************************************************\168@---------------------------------------------------------------------------169@ int pointer_mat_comp(m1, m2, rows, cols)170@ int **m1, **m2, rows, cols;171@172@ compares the araays m1 and m2 of size rows x cols173@---------------------------------------------------------------------------174@175\**************************************************************************/176int pointer_mat_comp(m1, m2, rows, cols)177int **m1, **m2, rows, cols;178{179int i,j;180for(i=0;i<rows;i++)181for(j=0; j<cols;j++)182{183if(m1[i][j] != m2[i][j])184{185if(m1[i][j] > m2[i][j])186return(1);187return(-1);188}189}190return(0);191}192193194195/**************************************************************************\196@---------------------------------------------------------------------------197@ int pointer_lower_triangular_mat_comp(m1,m2, n, m)198@ int **m1, **m2, n, m;199@200@ compares the symmetric arrays m1 and m2 of size n x m201@---------------------------------------------------------------------------202@203\**************************************************************************/204int pointer_lower_triangular_mat_comp(m1,m2, n, m)205int **m1, **m2, n, m;206{207int i,j;208for(i=0;i<n;i++)209for(j=0; j<=i;j++)210{211if(m1[i][j] != m2[i][j])212{213if(m1[i][j] > m2[i][j])214return(1);215return(-1);216}217}218return(0);219}220221222