-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.g
174 lines (152 loc) · 3.9 KB
/
util.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
# Library of utility functions to aid in Magma code translation
# two list-type functions tha are used in the translation of rep{
# list of first elt satisfying condition or empty list
BindGlobal("FilFirst",function(l,cond)
local x;
for x in l do
if cond(x) then
return [x];
fi;
od;
return [];
end);
# first for which func does not return empty list
BindGlobal("FRes",function(l,func)
local x,a;
for x in l do
a:=func(x);
if Length(a)>0 then
return a;
fi;
od;
return fail;
end);
# generic subgroup generator, use in place of `SubStructure' if it is
# groups. Should be improved to use more `closure'.
SubgroupContaining:=function(arg)
local P,gens,i;
P:=arg[1];
gens:=[];
for i in [2..Length(arg)] do
if IsGroup(arg[i]) then
Append(gens,GeneratorsOfGroup(arg[i]));
elif IsIdenticalObj(FamilyObj(arg[i]),FamilyObj(One(P))) then
Add(gens,arg[i]);
elif IsList(arg[i]) then
Append(gens,arg[i]);
else
Error("don't know what to do with object");
fi;
od;
return SubgroupNC(P,gens);
end;
DeclareGlobalFunction("Submatrix");
InstallGlobalFunction(Submatrix,function(m,a,b,c,d)
return m{[a..c]}{[b..d]};
end);
# hom is homomorphism defined on fp group
# l is words given by numbers
DeclareGlobalFunction("WordlistSubgroup");
InstallGlobalFunction(WordlistSubgroup,function(G,l,hom,arg)
local fp,fam;
fp:=Source(hom);
fam:=FamilyObj(One(FreeGroupOfFpGroup(fp)));
l:=List(l,x->AssocWordByLetterRep(fam,x));
fam:=FamilyObj(One(fp));
l:=List(l,x->ElementOfFpGroup(fam,x));
l:=List(l,x->ImagesRepresentative(hom,x));
l:=SubgroupNC(G,l);
if Length(arg)>0 then
SetSize(l,arg[1]);
fi;
return l;
end);
DeclareGlobalFunction("MatrixByEntries");
InstallGlobalFunction(MatrixByEntries,function(f,nr,nc,entries)
local i,m,o;
o:=One(f);
if ForAll(entries,x->IsList(x) and Length(x)=3) then
m:=NullMat(nr,nc,f);
for i in entries do
m[i[1]][i[2]]:=i[3]*o;
od;
else
if nr*nc<>Length(entries) then
Error("format?");
fi;
m:=List([1..nr],x->entries{[1+nc*(x-1)..nc*x]}*o);
fi;
if IsFFECollection(f) then
m:=ImmutableMatrix(f,m);
fi;
return m;
end);
DeclareGlobalFunction("SparseMatrix");
InstallGlobalFunction(SparseMatrix,function(arg)
local R,m,n,l,one,i,a;
if Length(arg)=3 then
R:=Cyclotomics;
m:=arg[1];
n:=arg[2];
l:=arg[3];
else
R:=arg[1];
m:=arg[2];
n:=arg[3];
l:=arg[4];
fi;
a:=NullMat(m,n,R);
one:=One(R);
if not IsList(l[1]) then
m:=1;
n:=1;
while n<>Length(l) do
n:=n+1;
for i in [1..l[n-1]] do
a[m][l[n]]:=one*l[n+1];
n:=n+2;
od;
m:=m+1;
od;
else
Error("similar format as by entries");
fi;
if IsFFECollection(R) then
a:=ImmutableMatrix(R,a);
fi;
return a;
end);
DeclareGlobalFunction("ScalarMat");
InstallGlobalFunction(ScalarMat,function(dim,s)
return s*IdentityMat(dim,s);
end);
# GO, SO etc in magma are defined with different generators than in GAP and
# it is not clear that the forms are the same -- in the end a
# base-change might be required to get the same group, which is the reason for not simply
# replacing the code
GOPlus:=function(d,q)
return GO(1,d,q);
end;
SOPlus:=function(d,q)
return SO(1,d,q);
end;
GOMinus:=function(d,q)
return GO(-1,d,q);
end;
SOMinus:=function(d,q)
return SO(-1,d,q);
end;
# homomorphism from free group (possibly on given generators), pre-images
# are made as SLP elements so they will multiply by SLP rules.
DeclareGlobalFunction("EpimorphismFromSLPGroup");
InstallGlobalFunction(EpimorphismFromSLPGroup,function(arg)
local G,epi,fgens;
G:=arg[1];
if Length(arg)>1 and arg[2]<>GeneratorsOfGroup(G) then
G:=SubgroupNC(G,arg[2]);
fi;
epi:=EpimorphismFromFreeGroup(G);
fgens:=GeneratorsOfGroup(Source(epi));
fgens:=StraightLineProgGens(fgens);
return GroupHomomorphismByImagesNC(Source(epi),G,fgens,GeneratorsOfGroup(G));
end);