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

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