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

563604 views
1
#include "typedef.h"
2
#include "gmp.h"
3
/* #include "gmp-impl.h" */
4
#include "longtools.h"
5
#include "matrix.h"
6
7
/**************************************************************************\
8
@---------------------------------------------------------------------------
9
@---------------------------------------------------------------------------
10
@ FILE: long_gauss.c
11
@---------------------------------------------------------------------------
12
@---------------------------------------------------------------------------
13
@
14
\**************************************************************************/
15
16
17
/**************************************************************************\
18
@---------------------------------------------------------------------------
19
@ int long_row_gauss(Mat)
20
@ matrix_TYP *Mat;
21
@
22
@ applies an integral gaussian algorithm to the rows of mat.
23
@ the rank is returned
24
@ the function uses GNU MP to avoid overflow
25
@---------------------------------------------------------------------------
26
@
27
\**************************************************************************/
28
int long_row_gauss(Mat)
29
matrix_TYP *Mat;
30
{
31
int rang;
32
MP_INT **M;
33
34
M = matrix_to_MP_mat(Mat);
35
rang = MP_row_gauss(M, Mat->rows, Mat->cols);
36
write_MP_mat_to_matrix(Mat, M);
37
free_MP_mat(M, Mat->rows, Mat->cols);
38
free(M);
39
return(rang);
40
}
41
42
/************************************************************************
43
@
44
@------------------------------------------------------------------------
45
@
46
@ int long_row_basis(Mat,int flag)
47
@
48
@ returns the rank of the INTEGRAL matrix Mat.
49
@ The matrix Mat is changed in such a way that the first rank rows
50
@ of it form an integral basis of the Lattices spanned by the rows
51
@ of the matrix Mat.
52
@
53
@------------------------------------------------------------------------
54
@
55
*************************************************************************/
56
int long_row_basis(Mat,flag)
57
matrix_TYP *Mat;
58
int flag;
59
{
60
int rang,
61
cols = Mat->cols,
62
i,
63
j,
64
k;
65
66
MP_INT merk,
67
**M,
68
**M3,
69
**M4,
70
**T1;
71
72
73
M = matrix_to_MP_mat(Mat);
74
rang = MP_row_gauss(M, Mat->rows, Mat->cols);
75
76
/* write this matrix back and check if it fits into int's */
77
k = FALSE;
78
for (i=0;i<Mat->rows;i++)
79
for (j=0;j<Mat->cols;j++)
80
if (abs(M[i][j]._mp_size)>1)
81
k = TRUE;
82
else
83
Mat->array.SZ[i][j] = mpz_get_si(&M[i][j]);
84
85
if (k || flag){
86
/***************************************************************\
87
| make a pair_reduction to the rows of M if needed
88
\***************************************************************/
89
mpz_init_set_ui(&merk,0);
90
M3 = init_MP_mat(rang, rang);
91
for(i=0;i<rang;i++)
92
for(j=0;j<=i;j++)
93
{
94
for(k=0;k<cols;k++)
95
{
96
mpz_mul(&merk, &M[i][k], &M[j][k]);
97
mpz_add(&M3[i][j], &merk, &M3[i][j]);
98
}
99
}
100
for(i=0;i<rang;i++)
101
for(j=0;j<i;j++)
102
mpz_set(&M3[j][i], &M3[i][j]);
103
104
/* output for debugging purposes
105
dump_MP_mat(M3,rows,rows,"M3"); */
106
107
T1 = init_MP_mat(rang, rang);
108
for(i=0;i<rang;i++)
109
mpz_set_si(&T1[i][i], 1);
110
MP_pair_red(M3, T1, rang);
111
112
/* output for debugging purposes
113
dump_MP_mat(T1,rows,rows,"T1"); */
114
115
M4 = init_MP_mat(Mat->rows, cols);
116
for(i=0;i<rang;i++)
117
for(j=0;j<cols;j++)
118
for(k=0;k<rang;k++)
119
{
120
mpz_mul(&merk, &T1[i][k], &M[k][j]);
121
mpz_add(&M4[i][j], &M4[i][j], &merk);
122
}
123
124
/* output for debugging purposes
125
dump_MP_mat(M4,rows,rows,"M4"); */
126
127
write_MP_mat_to_matrix(Mat, M4);
128
129
free_MP_mat(M, Mat->rows, Mat->cols);
130
free(M);
131
free_MP_mat(M3,rang,rang);
132
free(M3);
133
free_MP_mat(M4,Mat->rows,cols);
134
free(M4);
135
free_MP_mat(T1, rang,rang);
136
free(T1);
137
mpz_clear(&merk);
138
}
139
else{
140
free_MP_mat(M, Mat->rows, Mat->cols);
141
free(M);
142
}
143
144
return(rang);
145
}
146
147
/**************************************************************************\
148
@---------------------------------------------------------------------------
149
@ int long_row_trf_gauss(Mat,T)
150
@ matrix_TYP *Mat, *T;
151
@
152
@ applies an integral gaussian algorithm to the rows of mat.
153
@ the rank is returned
154
@ the function uses GNU MP to avoid overflow.
155
@ The tranformation is written to the matrix T.
156
@---------------------------------------------------------------------------
157
@
158
\**************************************************************************/
159
int long_row_trf_gauss(M, T)
160
matrix_TYP *M, *T;
161
{
162
int rang;
163
MP_INT **N, **S;
164
165
N = matrix_to_MP_mat(M);
166
S = init_MP_mat(M->rows, M->rows);
167
rang = MP_trf_gauss(N, S, M->rows, M->cols);
168
write_MP_mat_to_matrix(M, N);
169
write_MP_mat_to_matrix(T, S);
170
free_MP_mat(N, M->rows, M->cols); free_MP_mat(S,M->rows, M->rows);
171
free(N); free(S);
172
return(rang);
173
}
174
175
176
177
/**************************************************************************\
178
@---------------------------------------------------------------------------
179
@ int long_row_gauss_simultaneous(A, B)
180
@ matrix_TYP *A, *B;
181
@
182
@ Applies an integral gaussian algorithm to the rows of mat.
183
@ The rank is returned
184
@ The function uses GNU MP to avoid overflow.
185
@ The tranformations are applied simultaneously to the matrix B.
186
@---------------------------------------------------------------------------
187
@
188
\**************************************************************************/
189
int long_row_gauss_simultaneous(A, B)
190
matrix_TYP *A, *B;
191
{
192
int rang;
193
MP_INT **MA, **MB;
194
195
MA = matrix_to_MP_mat(A);
196
MB = matrix_to_MP_mat(B);
197
rang = MP_row_gauss_simultaneous(MA, A->rows, A->cols, MB, B->cols);
198
write_MP_mat_to_matrix(A, MA);
199
write_MP_mat_to_matrix(B, MB);
200
free_MP_mat(MA, A->rows, A->cols); free_MP_mat(MB, B->rows, B->cols);
201
free(MA); free(MB);
202
return(rang);
203
}
204
205