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

563641 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
@ FILE: long_solve_mat.c
10
@---------------------------------------------------------------------------
11
@---------------------------------------------------------------------------
12
@
13
\**************************************************************************/
14
15
/************************************************************************\
16
@-------------------------------------------------------------------------
17
@ matrix_TYP **long_solve_mat(A, B)
18
@ matrix_TYP *A, *B;
19
@
20
@ long_solve_mat(A,B) calculates Matrix X[0] with AX[0] = B, and
21
@ a matrix X[1] with MX[1] = 0, such that
22
@ the cols of X[1] are a Z-basis of the solution space.
23
@-------------------------------------------------------------------------
24
\************************************************************************/
25
matrix_TYP **long_solve_mat(A, B)
26
matrix_TYP *A, *B;
27
{
28
MP_INT ***E, **MA, **MB;
29
MP_INT Ekgv;
30
int Ecols, i,j;
31
matrix_TYP **erg;
32
matrix_TYP *et;
33
int Bcols;
34
35
extern MP_INT **matrix_to_MP_mat();
36
extern MP_INT ***MP_solve_mat();
37
extern matrix_TYP *MP_mat_to_matrix();
38
39
MA = matrix_to_MP_mat(A);
40
if(B != NULL)
41
{
42
MB = matrix_to_MP_mat(B);
43
Bcols = B->cols;
44
}
45
else
46
{
47
MB = NULL; Bcols = 0;
48
}
49
mpz_init(&Ekgv);
50
E = MP_solve_mat(MA, A->rows, A->cols, MB, Bcols, &Ecols, &Ekgv);
51
for(i=0;i<A->rows;i++)
52
{
53
for(j=0;j<A->cols;j++)
54
mpz_clear(&MA[i][j]);
55
free(MA[i]);
56
}
57
free(MA);
58
if(B != NULL)
59
{
60
/* changed tilman on 21/2/97 from:
61
for(i=0;i<A->rows;i++)
62
to: */
63
for(i=0;i<B->rows;i++)
64
{
65
for(j=0;j<Bcols;j++)
66
mpz_clear(&MB[i][j]);
67
free(MB[i]);
68
}
69
free(MB);
70
}
71
72
73
if((erg = (matrix_TYP **)malloc(2 *sizeof(matrix_TYP **))) == NULL)
74
{
75
printf("malloc of 'erg' in 'long_solve_mat' failed\n");
76
exit(2);
77
}
78
if(E[0] != NULL)
79
{
80
erg[0] = MP_mat_to_matrix(E[0], A->cols, Bcols);
81
erg[0]->flags.Integral = FALSE;
82
if(abs(Ekgv._mp_size) > 1)
83
{
84
printf("Error: Integer overflow in 'MP_mat_to_matrix'\n");
85
exit(3);
86
}
87
erg[0]->kgv = mpz_get_si(&Ekgv);
88
if(A->kgv != 1)
89
{
90
for(i=0;i<A->cols;i++)
91
for(j=0;j<B->cols;j++)
92
erg[0]->array.SZ[i][j] *= A->kgv;
93
}
94
if(B->kgv != 1)
95
erg[0]->kgv *= B->kgv;
96
Check_mat(erg[0]);
97
for(i=0;i<A->cols;i++)
98
{
99
for(j=0;j<B->cols;j++)
100
mpz_clear(&E[0][i][j]);
101
free(E[0][i]);
102
}
103
free(E[0]);
104
}
105
else
106
erg[0] = NULL;
107
if(E[1] != NULL)
108
{
109
et = MP_mat_to_matrix(E[1], Ecols, A->cols);
110
for(i=0;i<Ecols;i++)
111
{
112
for(j=0;j<A->cols;j++)
113
mpz_clear(&E[1][i][j]);
114
free(E[1][i]);
115
}
116
free(E[1]);
117
erg[1] = tr_pose(et);
118
free_mat(et);
119
}
120
else
121
erg[1] = NULL;
122
free(E);
123
mpz_clear(&Ekgv);
124
return(erg);
125
}
126
127