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
/**************************************************************************\
3
@---------------------------------------------------------------------------
4
@---------------------------------------------------------------------------
5
@ FILE: compare.c
6
@---------------------------------------------------------------------------
7
@---------------------------------------------------------------------------
8
@
9
\**************************************************************************/
10
/*******************************************************************\
11
@ This file conatain functions that compare matrices or pointer
12
@ to integer with respect to different lexikographic orders.
13
@ The functions return -1 if the first arument is smaller with
14
@ respect to the lexicographic order,
15
@ 0 if tboth arguments are equal
16
@ 1 if the first argument is bigger
17
@
18
@ If the arguments are 1-dimensional arrays, then the first
19
@ entry in which they differ decides.
20
@ For two dimensional arrays v < w if and only if
21
@ v[i][j] < w[i][j] and
22
@ v[k][j] == w[k][j] for all k < i and 0<=j<= dim
23
@ v[i][k] == w[i][k] for all k < j
24
@ For two dimensional symmetric arrays v < w if and only if
25
@ v[i][j] < w[i][j] and
26
@ v[k][j] == w[k][j] for all k < i and j<= i and
27
@ v[i][k] == w[i][k] for all k < j
28
@
29
@ for functions that compare first cols v < w if v^{tr} < w^{tr}
30
@ in the above sense.
31
\*******************************************************************/
32
33
34
35
/**************************************************************************\
36
@---------------------------------------------------------------------------
37
@ int mat_comp(m1, m2)
38
@ matrix_TYP *m1, *m2;
39
@
40
@ compares m1->array.SZ and m2->array.SZ
41
@---------------------------------------------------------------------------
42
@
43
\**************************************************************************/
44
int mat_comp(m1, m2)
45
matrix_TYP *m1, *m2;
46
{
47
int i,
48
j,
49
*m1SZ,
50
*m2SZ;
51
52
if(m1->cols != m2->cols || m1->rows != m2->rows)
53
{
54
printf("cannot compare %dx%d with %dx%d-matrix\n", m1->rows, m1->cols, m2->rows, m2->cols);
55
exit(3);
56
}
57
58
for(i=0;i<m1->rows;i++){
59
m1SZ = m1->array.SZ[i];
60
m2SZ = m2->array.SZ[i];
61
for(j=0; j<m1->cols;j++,m1SZ++,m2SZ++){
62
if(*m1SZ > *m2SZ)
63
return(1);
64
if(*m1SZ != *m2SZ)
65
return(-1);
66
}
67
}
68
69
return(0);
70
}
71
72
73
74
/**************************************************************************\
75
@---------------------------------------------------------------------------
76
@ int mat_col_comp(m1, m2)
77
@ matrix_TYP *m1, *m2;
78
@
79
@ compares m1->array.Sz and m2->array.SZ by going to the columns
80
@---------------------------------------------------------------------------
81
@
82
\**************************************************************************/
83
int mat_col_comp(m1, m2)
84
matrix_TYP *m1, *m2;
85
{
86
int i,j;
87
if(m1->cols != m2->cols || m1->rows != m2->rows)
88
{
89
printf("cannot compare %dx%d with %dx%d-matrix\n", m1->rows, m1->cols, m2->rows, m2->cols);
90
exit(3);
91
}
92
for(i=0;i<m1->cols;i++)
93
for(j=0; j<m1->rows;j++)
94
{
95
if(m1->array.SZ[j][i] != m2->array.SZ[j][i])
96
{
97
if(m1->array.SZ[j][i] > m2->array.SZ[j][i])
98
return(1);
99
return(-1);
100
}
101
}
102
return(0);
103
}
104
105
106
107
/**************************************************************************\
108
@---------------------------------------------------------------------------
109
@ int lower_triangular_mat_comp(m1,m2)
110
@ matrix_TYP *m1, *m2;
111
@
112
@ compares the symmetric arrays m1->array.SZ and m2->array.SZ
113
@---------------------------------------------------------------------------
114
@
115
\**************************************************************************/
116
int lower_triangular_mat_comp(m1,m2)
117
matrix_TYP *m1, *m2;
118
{
119
int i,j;
120
if(m1->cols != m2->cols || m1->rows != m2->rows)
121
{
122
printf("cannot compare %dx%d with %dx%d-matrix\n", m1->rows, m1->cols, m2->rows, m2->cols);
123
exit(3);
124
}
125
for(i=0;i<m1->rows;i++)
126
for(j=0; j<=i;j++)
127
{
128
if(m1->array.SZ[i][j] != m2->array.SZ[i][j])
129
{
130
if(m1->array.SZ[i][j] > m2->array.SZ[i][j])
131
return(1);
132
return(-1);
133
}
134
}
135
return(0);
136
}
137
138
139
140
/**************************************************************************\
141
@---------------------------------------------------------------------------
142
@ int vec_comp(v1, v2, dim)
143
@ int *v1, *v2, dim;
144
@
145
@ compares the 1-dimensional arrays v1 and v2 of length dim
146
@---------------------------------------------------------------------------
147
@
148
\**************************************************************************/
149
int vec_comp(v1, v2, dim)
150
int *v1, *v2, dim;
151
{
152
int i;
153
for(i=0;i<dim;i++)
154
{
155
if(v1[i] != v2[i])
156
{
157
if(v1[i] > v2[i])
158
return(1);
159
return(-1);
160
}
161
}
162
return(0);
163
}
164
165
166
167
168
/**************************************************************************\
169
@---------------------------------------------------------------------------
170
@ int pointer_mat_comp(m1, m2, rows, cols)
171
@ int **m1, **m2, rows, cols;
172
@
173
@ compares the araays m1 and m2 of size rows x cols
174
@---------------------------------------------------------------------------
175
@
176
\**************************************************************************/
177
int pointer_mat_comp(m1, m2, rows, cols)
178
int **m1, **m2, rows, cols;
179
{
180
int i,j;
181
for(i=0;i<rows;i++)
182
for(j=0; j<cols;j++)
183
{
184
if(m1[i][j] != m2[i][j])
185
{
186
if(m1[i][j] > m2[i][j])
187
return(1);
188
return(-1);
189
}
190
}
191
return(0);
192
}
193
194
195
196
/**************************************************************************\
197
@---------------------------------------------------------------------------
198
@ int pointer_lower_triangular_mat_comp(m1,m2, n, m)
199
@ int **m1, **m2, n, m;
200
@
201
@ compares the symmetric arrays m1 and m2 of size n x m
202
@---------------------------------------------------------------------------
203
@
204
\**************************************************************************/
205
int pointer_lower_triangular_mat_comp(m1,m2, n, m)
206
int **m1, **m2, n, m;
207
{
208
int i,j;
209
for(i=0;i<n;i++)
210
for(j=0; j<=i;j++)
211
{
212
if(m1[i][j] != m2[i][j])
213
{
214
if(m1[i][j] > m2[i][j])
215
return(1);
216
return(-1);
217
}
218
}
219
return(0);
220
}
221
222