summaryrefslogtreecommitdiffstats
path: root/subgroupladder.g
blob: e1235a15a5d796067feb45a050200d2d23b0c1c4 (plain)
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
FindPos := function(list, x)
	local n, i;
	n := Length(list);
	for i in [1..n] do
		if x in list[i] then
			return i;
		fi;
	od;
end;

id := function(x)
	return x;
end;

Subgroupladder := function(G)
	local
		orb,
		i,
		k,
		n,
		pair,
		ladder,
		directfactors,
		mapping,
		output,
		partition;
		

	if (not IsPermGroup(G)) then
		ErrorNoReturn("the argument must be a permutation group!\n");
	fi;

	n := LargestMovedPoint(G);

	orb := List(Orbits(G), x -> x);
	SortBy(orb, x->-Length(x));

	output := [];

	partition := List(orb, Length);
	mapping := List([1..n], x -> FindPos(orb, x));
	ladder := [[List(partition, id), List(mapping, id)]];


	while (Length(partition) <> 1 or partition[1] < n) do
		if (Length(partition) = 1 and partition[1] < n) then
			mapping[Position(mapping, 0)] := 1;
			partition[1] := partition[1] + 1;
			Add(ladder, [List(partition, id), List(mapping, id)]);
		else 
			if (partition[2] = 1) then
				Remove(partition, 2);
				for i in [1..n] do
					if (mapping[i]) > 1 then
						mapping[i] := mapping[i] - 1;
					fi;
				od;
				partition[1] := partition[1] + 1;
				Add(ladder, [List(partition, id), List(mapping, id)]);
			else 
				mapping[Position(mapping, 2)] := Length(partition)+1;
				partition[2] := partition[2] - 1;
				Add(partition, 1);
				Add(ladder, [List(partition, id), List(mapping, id)]);

				mapping[Position(mapping, Length(partition))] := 1;
				Remove(partition);
				partition[1] := partition[1] + 1;
				Add(ladder, [List(partition, id), List(mapping, id)]);
			fi;
		fi;
	od;

	for pair in ladder do
		k := Length(pair[1]);
		mapping := pair[2];
		directfactors := [];
		for i in [1..k] do
			Add(directfactors, SymmetricGroup(Filtered([1..n], x -> i = mapping[x])));
		od;
		Add(output, DirectProduct(directfactors));
	od;

	return output;
end;