GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
#include "typedef.h"1#include "matrix.h"23/**************************************************************************\4@---------------------------------------------------------------------------5@---------------------------------------------------------------------------6@ FILE: comp_mat.c7@---------------------------------------------------------------------------8@---------------------------------------------------------------------------9@10\**************************************************************************/1112/**************************************************************************\13@---------------------------------------------------------------------------14@15int cmp_mat(A, B)16matrix_TYP *A, *B;17@ compares the matrices A and B18@ if the first nonzero entry of A-B is positive (A>B) the result is 119@ if the first nonzero entry of A-B is negative (A<B) the result is -120@ if A == B the result is 0.21@22@ (the entries are assumed to be ordered in the following way:23@ (i,j)< (k,l) iff i<k or i==k and j<l24@---------------------------------------------------------------------------25@26\**************************************************************************/2728int cmp_mat(A, B)29matrix_TYP *A, *B;30{31int i,j;32matrix_TYP *tmpA = NULL, *tmpB = NULL;3334if(A->cols != B->cols || A->rows != B->rows) {35printf("matrices have incompatible dimensions\n");36exit(3);37}38/*39* Check_mat() is expensive, but our matrices are small40*/41Check_mat( A );42Check_mat( B );43if ( A->array.N != NULL ) {44if ( B->array.N == NULL ) {45tmpB = copy_mat( B );46kgv2rat( tmpB );47tmpA = B; B = tmpB; tmpB = tmpA; tmpA = NULL;48}49} else {50if ( B->array.N != NULL ) {51tmpA = copy_mat( A );52kgv2rat( tmpA );53tmpB = A; A = tmpA; tmpA = tmpB; tmpB = NULL;54}55}56if ( A->array.N == NULL ) {57/*{{{}}}*/58/*{{{ */59if( A->kgv == B->kgv ) {60for(i=0; i<A->rows; i++) {61for(j=0; j<A->cols; j++) {62if(A->array.SZ[i][j] != B->array.SZ[i][j]) {63if(A->array.SZ[i][j] < B->array.SZ[i][j]) {64return -1;65} else {66return 1;67}68}69}70}71} else {72for(i=0; i<A->rows; i++)73for(j=0; j<A->cols; j++)74if((A->array.SZ[i][j] * B->kgv) != (B->array.SZ[i][j] * A->kgv)) {75if(A->array.SZ[i][j] < B->array.SZ[i][j]) {76return -1;77} else {78return 1;79}80}81}82/*}}} */83} else {84/*{{{ */85for(i=0; i<A->rows; i++)86for(j=0; j<A->cols; j++)87if( (A->array.SZ[i][j] != B->array.SZ[i][j] )88|| (A->array.N [i][j] != B->array.N [i][j] )89) {90if ( A->array.SZ[i][j] == B->array.SZ[i][j] ) {91if(A->array.N[i][j] > B->array.N[i][j]) {92if ( tmpA ) {93free_mat( A );94}95if ( tmpB ) {96free_mat( B );97}98return -1;99} else {100if ( tmpA ) {101free_mat( A );102}103if ( tmpB ) {104free_mat( B );105}106return 1;107}108} else if( A->array.N[i][j] == B->array.N[i][j] ) {109if(A->array.SZ[i][j] < B->array.SZ[i][j]) {110if ( tmpA ) {111free_mat( A );112}113if ( tmpB ) {114free_mat( B );115}116return -1;117} else {118if ( tmpA ) {119free_mat( A );120}121if ( tmpB ) {122free_mat( B );123}124return 1;125}126} else { /* beware of overflow ! */127if ( (A->array.SZ[i][j] * B->array.N[i][j])128< (B->array.SZ[i][j] * A->array.N[i][j])129) {130if ( tmpA ) {131free_mat( A );132}133if ( tmpB ) {134free_mat( B );135}136return -1;137} else {138if ( tmpA ) {139free_mat( A );140}141if ( tmpB ) {142free_mat( B );143}144return 1;145}146}147}148/*}}} */149}150return 0;151}152153154