-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgrouprepresentation.cpp
369 lines (294 loc) · 12.1 KB
/
grouprepresentation.cpp
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
#include "grouprepresentation.h"
#include "topologicalsurface.h"
#include "fundamentaldomaingenerator.h"
template<typename T> GroupRepresentation<T>::GroupRepresentation()
{
}
template<typename T> GroupRepresentation<T>::GroupRepresentation(const DiscreteGroup &Gamma) : Gamma(Gamma)
{
}
template<typename T> GroupRepresentation<T>::GroupRepresentation(const DiscreteGroup &Gamma, std::vector<T> listOfMatrices) :
Gamma(Gamma), generatorImages(listOfMatrices)
{
if(listOfMatrices.size() != (Gamma.getGenerators()).size())
{
throw(QString("Error in GroupRepresentation<T>::GroupRepresentation : The list of matrices doesn't match the list of generators"));
}
}
template <typename T> DiscreteGroup GroupRepresentation<T>::getDiscreteGroup() const
{
return Gamma;
}
template<typename T> bool GroupRepresentation<T>::checkRelations() const
{
bool res = true;
std::vector<Word> relations = Gamma.getRelations();
T identity;
identity.setIdentity();
uint i = 0;
for (const auto &r : relations)
{
T test = evaluateRepresentation(r);
if(!T::almostEqual(test, identity))
{
std::stringstream message;
message << "WARNING in GroupRepresentation<T>::checkRelations(): failed";
message << "In relation #" << i << "( " << Gamma.getWordAsString(r) << "), error: " << test.error();
qDebug() << QString::fromStdString(message.str());
res = false;
}
++i;
}
return res;
}
template <typename T> std::vector<T> GroupRepresentation<T>::getGeneratorImages() const
{
return generatorImages;
}
template <typename T> bool GroupRepresentation<T>::getGeneratorImage(const generatorName &a, T &output) const
{
std::vector<generatorName> generators = Gamma.getGenerators();
uint i=0;
for (const auto &g : generators)
{
if (g == a)
{
output = generatorImages[i];
return true;
}
++i;
}
std::stringstream errorMessage;
errorMessage << "Error in GroupRepresentation<T>::getGeneratorImage: could not find generator name " << a << " in " << *this << std::endl;
throw(QString::fromStdString(errorMessage.str()));
return false;
}
template<typename T> T GroupRepresentation<T>::evaluateRepresentation(const Word & w) const
{
T res = T(1);
Word wc = Word::contract(w);
std::vector<letter> letters = wc.getLetters();
for (const auto &l : letters)
{
if(l.second >= 0)
{
res = res*Tools::exponentiation(generatorImages[l.first], l.second);
}
else
{
res = res*Tools::exponentiation(generatorImages[l.first], -l.second).inverse();
}
}
return res;
}
template<typename T> std::vector<T> GroupRepresentation<T>::evaluateRepresentation(const std::vector<Word> & listOfWords) const
{
std::vector<T> output;
output.reserve(listOfWords.size());
for(const auto & word : listOfWords)
{
output.push_back(evaluateRepresentation(word));
}
return output;
}
template<typename T> GroupRepresentation<T> GroupRepresentation<T>::conjugate(const T &conjugator) const
{
std::vector<T> list;
list.reserve(generatorImages.size());
for (const auto &genim : generatorImages)
{
list.push_back(conjugator*genim*conjugator.inverse());
}
return GroupRepresentation<T>(Gamma,list);
}
template<typename T> void GroupRepresentation<T>::rotateGenerators(int shift)
{
Gamma.rotateGenerators(shift);
int antishift = generatorImages.size() - shift;
rotate(generatorImages.begin(), generatorImages.begin()+ antishift, generatorImages.end());
}
template<> GroupRepresentation<SL2CMatrix> GroupRepresentation<SL2CMatrix>::bar() const
{
std::vector<SL2CMatrix> list(generatorImages.size());
for (uint i=0; i!=generatorImages.size(); ++i)
{
list[i] = generatorImages[i].bar();
}
GroupRepresentation<SL2CMatrix> r(Gamma,list);
return r;
}
template <> DiscreteGroup GroupRepresentation<H2Isometry>::getDiscreteGroup() const
{
return Gamma;
}
template <> std::vector<H2Isometry> GroupRepresentation<H2Isometry>::getSidePairings() const
{
return evaluateRepresentation(Gamma.getSidePairings());
}
template <> std::vector<H2Isometry> GroupRepresentation<H2Isometry>::getPairingsFromVertex() const
{
return evaluateRepresentation(Gamma.getPairingsFromVertex());
}
template <> std::vector<H2Isometry> GroupRepresentation<H2Isometry>::getPairingsAroundVertex() const
{
return evaluateRepresentation(Gamma.getPairingsAroundVertex());
}
template <> std::vector<H2Isometry> GroupRepresentation<H2Isometry>::getPairingsAroundVertices() const
{
return evaluateRepresentation(Gamma.getPairingsAroundVertices());
}
template <> H2Polygon GroupRepresentation<H2Isometry>::getFundamentalDomain(const H2Point &firstVertex) const
{
std::vector<H2Isometry> pairingsFromVertex = getPairingsFromVertex();
std::vector<H2Point> vertices;
vertices.reserve(pairingsFromVertex.size());
for (const auto &pairing : pairingsFromVertex)
{
vertices.push_back(pairing*firstVertex);
}
return H2Polygon(vertices);
}
template <> H2Polygon GroupRepresentation<H2Isometry>::getOptimalFundamentalDomain() const
{
return FundamentalDomainGenerator(*this).getOptimalFundamentalDomain();
}
template <> void GroupRepresentation<H2Isometry>::setNormalizedPairOfPantsRepresentation(generatorName c1, generatorName c2, generatorName c3,
double C1, double C2, double C3,
double S1, double S2, double S3,
generatorName normalized)
{
if (S1<0 || S2 < 0 || S3 < 0)
{
throw(QString("ERROR in GroupRepresentation<H2Isometry>::setNormalizedPairOfPantsRepresentation: you gave me a negative length (seriously?)"));
}
if (normalized == c3)
{
Gamma.setPairOfPants(c1, c2, c3);
generatorImages.clear();
H2Isometry f;
Complex W, Z, A, U;
Z = Complex(-C1*S3 , -C3*C1 - C2*C3*C3 + S2*S3*S3);
W = Complex(-C3*S2*S3 + S3*C1 + S3*C2*C3 , -C1*C3 - C2);
U = Z/conj(Z);
A = W/Z;
f.setDiskCoordinates(U, A);
generatorImages.push_back(f);
Z = Complex(-C2*S3 , -C1-C2*C3);
W = Complex(-S2*S3 , -C2*C3-C1);
U = Z/conj(Z);
A = W/Z;
f.setDiskCoordinates(U, A);
generatorImages.push_back(f);
U = 1.0;
A = Complex(0.0, -S3/C3);
f.setDiskCoordinates(U, A);
generatorImages.push_back(f);
}
else if (normalized == c1)
{
setNormalizedPairOfPantsRepresentation(c2, c3, c1, C2, C3, C1, S2, S3, S1, c1);
rotateGenerators(1);
}
else if (normalized == c2)
{
setNormalizedPairOfPantsRepresentation(c3, c1, c2, C3, C1, C2, S3, S1, S2, c2);
rotateGenerators(2);
}
else
{
throw(QString("ERROR in GroupRepresentation<H2Isometry>::setNormalizedPairOfPantsRepresentation: Normalizer has to be one of the generators!"));
}
}
template <> void GroupRepresentation<H2Isometry>::setNormalizedPairOfPantsRepresentation(generatorName c1, generatorName c2, generatorName c3,
double length1, double length2, double length3,
generatorName normalized)
{
setNormalizedPairOfPantsRepresentation(c1, c2, c3, cosh(length1/2), cosh(length2/2), cosh(length3/2), sinh(length1/2), sinh(length2/2), sinh(length3/2), normalized);
}
template <> void GroupRepresentation<H2Isometry>::setNiceRepresentation()
{
Gamma = DiscreteGroup(TopologicalSurface(2, 0));
H2Isometry A1, B1, A2, B2, a1, b1, a2, b2;
H2Point p1, p2;
H2Geodesic L1, L2;
Complex I(0.0, 1.0);
Complex z1 = 1.0/sqrt(sqrt(2.0));
Complex u = Complex(1.0,1.0)/sqrt(2.0);
p1.setDiskCoordinate(z1);
p2.setDiskCoordinate(u*z1);
L1.setPassingThroughTwoPoints(p1, p2);
p1.setDiskCoordinate(I*u*z1);
p2.setDiskCoordinate(I*z1);
L2.setPassingThroughTwoPoints(p1, p2);
A1.setByMappingGeodesic(L1, L2);
p1.setDiskCoordinate(u*z1);
p2.setDiskCoordinate(I*z1);
L1.setPassingThroughTwoPoints(p1, p2);
p1.setDiskCoordinate(-z1);
p2.setDiskCoordinate(u*I*z1);
L2.setPassingThroughTwoPoints(p1, p2);
B1.setByMappingGeodesic(L1, L2);
p1.setDiskCoordinate(-z1);
p2.setDiskCoordinate(-u*z1);
L1.setPassingThroughTwoPoints(p1, p2);
p1.setDiskCoordinate(-I*u*z1);
p2.setDiskCoordinate(-I*z1);
L2.setPassingThroughTwoPoints(p1, p2);
A2.setByMappingGeodesic(L1, L2);
p1.setDiskCoordinate(-u*z1);
p2.setDiskCoordinate(-I*z1);
L1.setPassingThroughTwoPoints(p1, p2);
p1.setDiskCoordinate(z1);
p2.setDiskCoordinate(-I*u*z1);
L2.setPassingThroughTwoPoints(p1, p2);
B2.setByMappingGeodesic(L1, L2);
a1 = A1.inverse()*B1.inverse()*A1;
b1 = A1.inverse()*B1*A1*B1.inverse()*A1;
b2 = A2*B1*A1.inverse()*B1.inverse()*A1;
a2 = b2.inverse()*B2.inverse()*b2;
p1.setDiskCoordinate(-z1);
generatorImages = {a1, b1, a2, b2};
}
template <> bool GroupRepresentation<H2Isometry>::checkCompatibilityOfFNcoordinates(const std::vector<double> & lengths,
const std::vector<double> & twists)
{
uint N = lengths.size();
if (twists.size() != N)
{
throw(QString("ERROR in GroupRepresentation<H2Isometry>::setFenchelNielsenCoordinatesUnnormalized: number of lengths and twists don't match!"));
return false;
}
else if (N%3 != 0)
{
throw(QString("ERROR in GroupRepresentation<H2Isometry>::setFenchelNielsenCoordinatesUnnormalized: number of lengths and twists has to be a multiple of 3!"));
}
else if (N<3)
{
throw(QString("ERROR in GroupRepresentation<H2Isometry>::setFenchelNielsenCoordinatesUnnormalized: at least 3 lengths and twists are needed!"));
return false;
}
return true;
}
template <> GroupRepresentation<H2Isometry> GroupRepresentation<H2Isometry>::amalgamateOverInverse(const GroupRepresentation<H2Isometry> & rho1, const generatorName &a1,
const GroupRepresentation<H2Isometry> & rho2,
const generatorName &a1inverse)
{
std::vector<H2Isometry> generatorImages1 = rho1.getGeneratorImages();
std::vector<H2Isometry> generatorImages2 = rho2.getGeneratorImages();
generatorImages1.insert(generatorImages1.end(), generatorImages2.begin(), generatorImages2.end());
return GroupRepresentation<H2Isometry>(DiscreteGroup::amalgamateOverInverse(rho1.Gamma, a1, rho2.Gamma, a1inverse), generatorImages1);
}
template <> GroupRepresentation<H2Isometry> GroupRepresentation<H2Isometry>::HNNextensionOverInverse(const GroupRepresentation<H2Isometry> &rho,
const generatorName &a,
const generatorName &ainverse,
const generatorName &newGeneratorName,
const H2Isometry & conjugator)
{
std::vector<H2Isometry> outputGeneratorImages = rho.getGeneratorImages();
outputGeneratorImages.push_back(conjugator);
return GroupRepresentation<H2Isometry>(DiscreteGroup::HNNextensionOverInverse(rho.Gamma, a, ainverse, newGeneratorName), outputGeneratorImages);
}
template class GroupRepresentation<H2Isometry>;
template class GroupRepresentation<H3Isometry>;
template class GroupRepresentation<SL2RMatrix>;
template class GroupRepresentation<SL2CMatrix>;