-
Notifications
You must be signed in to change notification settings - Fork 0
/
SchreierSims.g
390 lines (349 loc) · 8.14 KB
/
SchreierSims.g
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
#Deterministic Version
Sifting := function(C, g)
local L, beta, delta, r;
L := [];
while C.generators <> [] do
beta := C.orbit[1];
delta := OnPoints(beta, g);
if not IsBound (C.transversal[delta]) then
return fail;
fi;
r := C.transversal[delta];
g := g * r ^ (-1);
Add(L, r);
C := C.zstabiliser;
od;
if g <> () then
return fail;
else
return L;
fi;
end;
SSOrbit := function(C, a)
local O, T, l, Sgens, i, delta, gamma, j, b, s, testlist;
O := C.orbit;
T := C.transversal;
l := Length(O);
Sgens := [];
Add(C.generators, a);
for i in [1 .. l] do
delta := O[i];
gamma := OnPoints(delta, a);
if not gamma in O then
Add(O, gamma);
C.transversal[gamma] := C.transversal[delta] * a;
else
s := T[delta] * a * T[gamma] ^ (-1);
Add(Sgens, s);
fi;
od;
j := l + 1;
while j <= Length(O) do
delta := O[j];
for i in [1 .. Length(C.generators)] do
b := C.generators[i];
gamma := OnPoints(delta, b);
if not gamma in O then
Add(O, gamma);
C.transversal[gamma] := C.transversal[delta] * b;
else
s := T[delta] * b * T[gamma] ^ (-1);
Add(Sgens, s);
fi;
od;
j := j + 1;
od;
if Set(Orbit(Group(C.generators), C.orbit[1])) <> Set(C.orbit) then
Error();
fi;
return Sgens;
end;
Extend := function(C, a)
local beta, delta, s, k, Sgens;
if Sifting(C, a) = fail then
if C.generators = [] then
C.zstabiliser := rec(generators := []);
beta := SmallestMovedPoint(a);
C.orbit := [beta];
C.transversal := [];
C.transversal[beta] := ();
Add(C.generators, a);
delta := OnPoints(beta, a);
s := a;
while delta <> beta do
Add(C.orbit, delta);
C.transversal[delta] := s;
delta := OnPoints(delta, a);
s := s * a;
od;
Extend(C.zstabiliser, s);
else
Sgens := SSOrbit(C, a);
for k in Sgens do
Extend(C.zstabiliser, k);
od;
fi;
fi;
end;
SchreierSims := function(g)
local C, a;
C := rec(generators := []);
for a in g do
Extend(C, a);
od;
return C;
end;
#Computes the order of a group given a stab chain for that group
SSOrder := function(C)
local a, D;
D := C;
a := 1;
while D.generators <> [] do
a := Length(D.orbit) * a;
D := D.zstabiliser;
od;
return a;
end;
#Randomised Version
#Product Replacement Algorithms
NextRandom := function(gens, g)
local N, i, j, e;
if IsGroup(gens) then
gens := ShallowCopy(GeneratorsOfGroup(gens));
fi;
N := Length(gens);
i := Random([1 .. N]);
j := Random(Concatenation([1 .. i - 1], [i + 1 .. N]));
e := Random([-1, 1]);
if Random([0, 1]) = 0 then
gens[i] := gens[i] * (gens[j] ^ (e));
g := g * gens[i];
else
gens[i] := (gens[j] ^ (e)) * gens[i];
g := gens[i] * g;
fi;
return g;
end;
SetupProductReplacement := function(G)
local gens, len, N, i, dummy, a;
if IsGroup(G) then
gens := ShallowCopy(GeneratorsOfGroup(G));
else
gens := ShallowCopy(G);
fi;
len := Maximum(Length(gens), 11); # Has been observed that size of list has to be at least 10 (see Hulpke)
N := Length(gens);
for i in [N + 1 .. len] do
gens[i] := Random(gens);
od;
for dummy in [1 .. 50] do #50 is heuristic (See Hulpke)
a := Random(gens);
NextRandom(gens, a);
od;
return gens;
end;
# Randomised Schreier-Sims stuff
RandSifting := function(C, g)
local beta, delta, r;
while C.generators <> [] do
beta := C.orbit[1];
delta := OnPoints(beta, g);
if not IsBound (C.transversal[delta]) then
return rec(elt := g, C_current := C, missing_point := true);
fi;
r := C.transversal[delta];
g := g * r ^ (-1);
C := C.zstabiliser;
od;
if g <> () then
return rec(elt:= g, C_current := C, missing_point := false);
else
return true;
fi;
end;
RandSSOrbit := function(C, a)
local O, T, l, i, delta, gamma, j, b, s, testlist;
O := C.orbit;
T := C.transversal;
l := Length(O);
Add(C.generators, a);
for i in [1 .. l] do
delta := O[i];
gamma := OnPoints(delta, a);
if not gamma in O then
Add(O, gamma);
C.transversal[gamma] := C.transversal[delta] * a;
fi;
od;
j := l + 1;
while j <= Length(O) do
delta := O[j];
for i in [1 .. Length(C.generators)] do
b := C.generators[i];
gamma := OnPoints(delta, b);
if not gamma in O then
Add(O, gamma);
C.transversal[gamma] := C.transversal[delta] * b;
fi;
od;
j := j + 1;
od;
end;
NewBasePoint := function(C, a, B)
local beta, delta, s, k, i;
while C.generators <> [] do
C := C.zstabiliser;
od;
C.zstabiliser := rec(generators := []);
beta := SmallestMovedPoint(a);
Add(B, beta);
C.orbit := [beta];
C.transversal := [];
C.transversal[beta] := ();
Add(C.generators, a);
delta := OnPoints(beta, a);
s := a;
while delta <> beta do
Add(C.orbit, delta);
C.transversal[delta] := s;
delta := OnPoints(delta, a);
s := s * a;
od;
end;
RandomExtend := function(C, a, sift, B)
local CC, i, L, j, c;
if not sift.missing_point then
Assert(1, sift.elt <> ());
NewBasePoint(C, sift.elt, B);
return;
fi;
CC := sift.C_current;
if CC.generators = [] then
Error();
fi;
while CC.generators <> [] and sift <> true do
RandSSOrbit(C, sift.elt);
C := C.zstabiliser;
sift := RandSifting(CC, sift.elt);
od;
end;
RandomSchreierSims := function(g)
local B, C, a, c, sift, S;
B := [];
if IsGroup(g) then
g := ShallowCopy(GeneratorsOfGroup(g));
else
g := ShallowCopy(g);
fi;
S := SetupProductReplacement(g);
C := rec(generators := []);
a := NextRandom(S, ());
c := 0;
while c < 20 do
sift := RandSifting(C, a);
if sift <> true then
RandomExtend(C, a, sift, B);
else
c := c + 1;
fi;
a := NextRandom(g, a);
od;
return C;
end;
#Debugging Functions
#Finds the depth of a stab chain
MyDepth := function(C)
local n;
n := 0;
while (not IsEmpty(C.generators)) do
n := n + 1;
C := C.zstabiliser;
od;
return n;
end;
# Checks that output of randomised and deterministic versions agree in 10000 iterations
Check := function(gens)
local a, i, R, D;
a := 0;
R := SSOrder(SchreierSims(gens));
D := SSOrder(RandomSchreierSims(gens));
for i in [1 .. 10000] do
if R <> D then
return false;
else
a := a + 1;
fi;
od;
if a = 10000 then
return true;
fi;
end;
#Check that we get a uniform distribution of elts in product replacement
CheckRandom := function(G, trials)
local a, GG, result, pos, i;
a := NextRandom(G, ());
GG := Enumerator(G);
result := [];
for i in [1 .. trials] do
pos := Position(GG, a);
if not IsBound(result[pos]) then
result[pos] := 0;
fi;
result[pos] := result[pos] + 1;
a := NextRandom(G, a);
od;
return result;
end;
# Checks that C is a valid stab chain for G
ValidateStabChain := function(C, G)
local pt, x, names, H;
H := G;
while not IsEmpty(C.generators) do
H := Group(C.generators);
names := Set(NamesOfComponents(C));
if Set(names) <> Set(["generators", "orbit", "zstabiliser", "transversal"]) then
Error("1");
return false;
fi;
if ForAny(C.generators, x -> not x in G) then
Error("2");
return false;
fi;
if not Set(Orbit(H, C.orbit[1])) = Set(C.orbit) then
Error("4");
return false;
fi;
if ForAny(C.orbit, x -> not IsBound(C.transversal[x])) then
Error("3");
return false;
fi;
pt := C.orbit[1];
for x in C.orbit do
if pt ^ C.transversal[x] <> x then
Error("expect ", pt, " ^ ", C.transversal[x], " = ", C.orbit[x]);
return false;
fi;
od;
C := C.zstabiliser;
od;
return true;
end;
#Brute Force Algorithm for finding the order of a group
BruteForce := function(gens)
local G, i, j, a;
if IsGroup(gens) then
gens := ShallowCopy(GeneratorsOfGroup(gens));
fi;
G := [()];
i := 1;
while i <= Length(G) do
for j in gens do
a := G[i] * j;
if not (a in G) then
Add(G, a);
fi;
od;
i := i +1;
od;
return Length(G);
end;