CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

Views: 418346
1
/****************************************************************************
2
**
3
*A exponent_auts.c ANUPQ source Eamonn O'Brien
4
**
5
*Y Copyright 1995-2001, Lehrstuhl D fuer Mathematik, RWTH Aachen, Germany
6
*Y Copyright 1995-2001, School of Mathematical Sciences, ANU, Australia
7
**
8
*/
9
10
#include "pq_defs.h"
11
#include "pcp_vars.h"
12
#include "pq_functions.h"
13
14
/* save description of automorphisms used in exponent checking to file */
15
16
void save_auts(FILE *ofp, int *head, int *list, struct pcp_vars *pcp)
17
{
18
register int alpha;
19
register int offset;
20
register int required_offset;
21
register int prev = 0;
22
23
register int m = pcp->m;
24
register int required_ptr, stored_ptr;
25
int required_length, stored_length;
26
register int original, diff;
27
register int j;
28
int list_length;
29
int retain;
30
31
int nmr_items;
32
int *copy_head;
33
34
/* the action on more than lastg generators may be stored in
35
list; if this is the case, establish how many entries from
36
the array list must be stored in order to retain the
37
description of the automorphisms on lastg generators */
38
39
original = head[0];
40
41
if (head[0] > pcp->lastg) {
42
copy_head = allocate_vector(pcp->lastg * m + 1, 0, FALSE);
43
list_length = 0;
44
retain = pcp->lastg;
45
diff = 0;
46
for (alpha = 1; alpha <= m; ++alpha) {
47
offset = (alpha - 1) * original;
48
required_offset = (alpha - 1) * retain;
49
for (j = 1; j <= retain; ++j)
50
copy_head[required_offset + j] = head[offset + j] - diff;
51
52
required_ptr = head[offset + retain];
53
stored_ptr = head[offset + original];
54
stored_length = stored_ptr + list[stored_ptr + 1] + 1 - prev;
55
required_length = required_ptr + list[required_ptr + 1] + 1 - prev;
56
57
diff += stored_length - required_length;
58
59
list_length += required_length;
60
prev += stored_length;
61
}
62
} else {
63
copy_head = head;
64
retain = head[0];
65
list_length = list[0];
66
}
67
68
prev = 0;
69
70
nmr_items = fwrite(&retain, sizeof(int), 1, ofp);
71
verify_read(nmr_items, 1);
72
nmr_items = fwrite(&list_length, sizeof(int), 1, ofp);
73
verify_read(nmr_items, 1);
74
75
for (alpha = 1; alpha <= m; ++alpha) {
76
offset = (alpha - 1) * original;
77
required_offset = (alpha - 1) * retain;
78
nmr_items =
79
fwrite(copy_head + required_offset + 1, sizeof(int), retain, ofp);
80
verify_read(nmr_items, retain);
81
required_ptr = head[offset + retain];
82
stored_ptr = head[offset + original];
83
stored_length = stored_ptr + list[stored_ptr + 1] + 1 - prev;
84
required_length = required_ptr + list[required_ptr + 1] + 1 - prev;
85
nmr_items = fwrite(&required_length, sizeof(int), 1, ofp);
86
verify_read(nmr_items, 1);
87
nmr_items = fwrite(list + prev + 1, sizeof(int), required_length, ofp);
88
verify_read(nmr_items, required_length);
89
prev += stored_length;
90
}
91
92
if (original != retain)
93
free_vector(copy_head, 0);
94
95
RESET(ofp);
96
}
97
98
/* restore automorphisms used in exponent checking from file ifp;
99
nmr_saved = nmr of generators whose images have been saved to file;
100
retain = nmr of generators whose images are to be retained;
101
new_index = index of last used position in array list */
102
103
int restore_auts(FILE *ifp,
104
int offset,
105
int nmr_saved,
106
int retain,
107
int *new_index,
108
int *head,
109
int *list)
110
{
111
int alpha_length; /* length of the automorphism description */
112
int i, add;
113
int nmr_items;
114
115
nmr_items = fread(head + offset + 1, sizeof(int), nmr_saved, ifp);
116
verify_read(nmr_items, nmr_saved);
117
118
add = *new_index - head[offset + 1];
119
for (i = 1; i <= nmr_saved; ++i)
120
head[offset + i] += add;
121
122
nmr_items = fread(&alpha_length, sizeof(int), 1, ifp);
123
verify_read(nmr_items, 1);
124
nmr_items = fread(list + *new_index + 1, sizeof(int), alpha_length, ifp);
125
verify_read(nmr_items, alpha_length);
126
127
*new_index = head[offset + retain] + list[head[offset + retain] + 1] + 1;
128
129
return alpha_length;
130
}
131
132
/* restore automorphisms used in exponent checking from file */
133
134
void
135
restore_automorphisms(FILE *ifp, int **head, int **list, struct pcp_vars *pcp)
136
{
137
int new_index = 0;
138
int offset;
139
register int alpha;
140
int nmr_saved;
141
int list_length;
142
int retain;
143
int nmr_items;
144
145
nmr_items = fread(&nmr_saved, sizeof(int), 1, ifp);
146
verify_read(nmr_items, 1);
147
nmr_items = fread(&list_length, sizeof(int), 1, ifp);
148
verify_read(nmr_items, 1);
149
150
*head = allocate_vector(nmr_saved * pcp->m + 1, 0, FALSE);
151
(*head)[0] = nmr_saved;
152
153
*list = allocate_vector(list_length + 1, 0, FALSE);
154
(*list)[0] = list_length;
155
156
retain = MIN(pcp->lastg, nmr_saved);
157
for (alpha = 1; alpha <= pcp->m; ++alpha) {
158
offset = (alpha - 1) * retain;
159
restore_auts(ifp, offset, nmr_saved, retain, &new_index, *head, *list);
160
}
161
(*head)[0] = retain;
162
163
printf("Automorphisms read from file\n");
164
}
165
166