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 <getput.h>
3
#include <matrix.h>
4
#include <base.h>
5
#include <longtools.h>
6
#include <presentation.h>
7
8
9
10
/* -------------------------------------------------------------------------- */
11
/* tests if M == Id */
12
/* -------------------------------------------------------------------------- */
13
static boolean equal_id(matrix_TYP *M)
14
{
15
int i, j;
16
17
if (M->rows != M->cols)
18
return(FALSE);
19
20
for (i = 0; i < M->rows; i++){
21
for (j = 0; j < M->cols; j++){
22
if (i == j){
23
if (M->array.SZ[i][j] != 1)
24
return(FALSE);
25
}
26
else{
27
if (M->array.SZ[i][j] != 0)
28
return(FALSE);
29
}
30
}
31
}
32
return(TRUE);
33
}
34
35
36
37
/* -------------------------------------------------------------------------- */
38
/* transform a matrix A to standard form */
39
/* -------------------------------------------------------------------------- */
40
void standard_form(matrix_TYP *A,
41
matrix_TYP *D,
42
int first)
43
{
44
int i, j;
45
46
for (i = 0; i < A->rows; i++){
47
for (j = 0; j < A->cols; j++){
48
A->array.SZ[j][i] %= D->array.SZ[j + first][j + first];
49
if (A->array.SZ[j][i] < 0)
50
A->array.SZ[j][i] += D->array.SZ[j + first][j + first];
51
}
52
}
53
}
54
55
56
57
/* -------------------------------------------------------------------------- */
58
/* invert A : C_a x C_b x ... -> C_a x C_b x ... */
59
/* -------------------------------------------------------------------------- */
60
matrix_TYP *graph_mat_inv(matrix_TYP *A,
61
matrix_TYP *D,
62
int first)
63
{
64
int i;
65
66
matrix_TYP *B, *C;
67
68
C = copy_mat(A);
69
B = init_mat(A->rows, A->cols, "1");
70
71
while (equal_id(C) != TRUE){
72
free_mat(B);
73
B = C;
74
C = NULL;
75
C = mat_mul(B, A);
76
standard_form(C, D, first);
77
}
78
free_mat(C);
79
return(B);
80
}
81
82
83
84
/* -------------------------------------------------------------------------- */
85
/* mapped word for A[i] : C_a x C_b x ... -> C_a x C_b x ... */
86
/* -------------------------------------------------------------------------- */
87
matrix_TYP *graph_mapped_word(int *w,
88
matrix_TYP **A,
89
matrix_TYP **AINV,
90
matrix_TYP *D)
91
{
92
93
int i, first;
94
95
matrix_TYP *M;
96
97
98
for (first = 0; first < D->cols && D->array.SZ[first][first] == 1; first++);
99
100
if (w[0] == 0)
101
return init_mat(A[0]->cols,A[0]->cols,"i1");
102
103
if (w[1] < 0) {
104
if (AINV[-w[1]-1] == NULL)
105
AINV[-w[1]-1] = graph_mat_inv(A[-w[1]-1], D, first);
106
M = copy_mat(AINV[-w[1]-1]);
107
}
108
else{
109
M = copy_mat(A[w[1]-1]);
110
}
111
112
for (i=2;i<=w[0];i++){
113
if (w[i] < 0){
114
if (AINV[-w[i]-1] == NULL)
115
AINV[-w[i]-1] = graph_mat_inv(A[-w[i]-1], D, first);
116
mat_muleq(M,AINV[-w[i]-1]);
117
}
118
else{
119
mat_muleq(M,A[w[i]-1]);
120
}
121
standard_form(M, D, first);
122
}
123
124
return M;
125
126
} /* graph_mapped_word(...) */
127
128
129
130