-
Notifications
You must be signed in to change notification settings - Fork 3
/
rcyclotomic7integer_infinitensymetries.cpp
450 lines (368 loc) · 16 KB
/
rcyclotomic7integer_infinitensymetries.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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
#include "rcyclotomic7integer_infinitensymetries.h"
RCyclotomic7Integer_InfiniteNSymetries::RCyclotomic7Integer_InfiniteNSymetries(
AlVin *alvin)
: InfiniteNSymetries(alvin) {
unsigned int i, j;
auto aiVectors(alvin->get_aiVectors());
riVectorsProducts = vector<vector<RCyclotomic7Integer>>(
iVectorsCount, vector<RCyclotomic7Integer>(iVectorsCount, 0));
iVectorsNormsFloor = vector<long int>(iVectorsCount, 0);
// -------------------------------------------------
// Quadratic form
for (auto ai : aiQF)
rciQF.push_back(Rational<RCyclotomic7Integer>(
*dynamic_cast<RCyclotomic7Integer *>(ai)));
// -------------------------------------------------
// Vectors
for (i = 0; i < iVectorsCount; i++) {
auto v(vector<Rational<RCyclotomic7Integer>>(0));
Matrix<Rational<RCyclotomic7Integer>, Dynamic, 1> v2;
for (j = 0; j <= iDimension; j++)
v.push_back(Rational<RCyclotomic7Integer>(
*dynamic_cast<RCyclotomic7Integer *>(aiVectors[i][j])));
v2 = Matrix<Rational<RCyclotomic7Integer>, 1, Dynamic>::Map(&v[0], 1,
iDimension + 1);
rciVectorsC.push_back(v2);
}
// -------------------------------------------------
// Products
for (i = 0; i < iVectorsCount; i++) {
AlgebraicInteger *aiNorm(
alvin->aiBilinearProduct(aiVectors[i], aiVectors[i]));
riVectorsProducts[i][i] = *dynamic_cast<RCyclotomic7Integer *>(aiNorm);
mpz_class iT(riVectorsProducts[i][i].floor());
if (!iT.fits_slong_p())
throw(string("RCyclotomic7Integer_InfiniteNSymetries::"
"RCyclotomic7Integer_InfiniteNSymetries: Number too big"));
iVectorsNormsFloor[i] = iT.get_si();
delete aiNorm;
for (j = i + 1; j < iVectorsCount; j++) {
AlgebraicInteger *aiProd(
alvin->aiBilinearProduct(aiVectors[i], aiVectors[j]));
riVectorsProducts[i][j] = riVectorsProducts[j][i] =
*dynamic_cast<RCyclotomic7Integer *>(aiProd);
delete aiProd;
}
}
// -------------------------------------------------
// Weights of dotted lines
qiDottedWeights = vector<vector<Rational<RCyclotomic7Integer>>>(
iVectorsCount, vector<Rational<RCyclotomic7Integer>>(iVectorsCount, 0));
for (i = 0; i < iVectorsCount; i++) {
for (j = i + 1; j < iVectorsCount; j++) {
if (iGraphMatrix[i][j] == 2) // dotted
{
AlgebraicInteger *aiNum(
alvin->aiBilinearProduct(aiVectors[i], aiVectors[j]));
AlgebraicInteger *aiNorm1(
alvin->aiBilinearProduct(aiVectors[i], aiVectors[i]));
AlgebraicInteger *aiNorm2(
alvin->aiBilinearProduct(aiVectors[j], aiVectors[j]));
aiNum->multiplyBy(aiNum);
aiNorm1->multiplyBy(aiNorm2);
qiDottedWeights[i][j] = qiDottedWeights[j][i] =
Rational<RCyclotomic7Integer>(
*dynamic_cast<RCyclotomic7Integer *>(aiNum),
*dynamic_cast<RCyclotomic7Integer *>(aiNorm1));
delete aiNum;
delete aiNorm1;
delete aiNorm2;
}
}
}
}
RCyclotomic7Integer_InfiniteNSymetries::
~RCyclotomic7Integer_InfiniteNSymetries() {}
Rational<RCyclotomic7Integer>
RCyclotomic7Integer_InfiniteNSymetries::rciVectorNorm(
const Matrix<Rational<RCyclotomic7Integer>, -1, 1> &rciV) const {
Rational<RCyclotomic7Integer> rriRes(-rciQF[0] * rciV(0, 0) * rciV(0, 0));
for (unsigned int j(1); j < iVectorSize; j++)
rriRes += rciQF[j] * rciV(j, 0) * rciV(j, 0);
return rriRes;
}
Rational<RCyclotomic7Integer>
RCyclotomic7Integer_InfiniteNSymetries::rciVectorsProduct(
const Matrix<Rational<RCyclotomic7Integer>, Dynamic, 1> &rciV1,
const Matrix<Rational<RCyclotomic7Integer>, Dynamic, 1> &rciV2) const {
Rational<RCyclotomic7Integer> rciRes(-rciQF[0] * rciV1(0, 0) * rciV2(0, 0));
for (unsigned int j(1); j < iVectorSize; j++)
rciRes += rciQF[j] * rciV1(j, 0) * rciV2(j, 0);
return rciRes;
}
vector<GraphInvolution>
RCyclotomic7Integer_InfiniteNSymetries::FindIsomorphismsInSubgraph(
const vector<unsigned int> &iVertices) {
vector<GraphInvolution> iIsomorphisms;
unsigned int iVerticesCount(iVertices.size()), i, j, k;
// -------------------------------------------------------------
// Do the corresponding vectors span the whole space?
Matrix<Rational<RCyclotomic7Integer>, Dynamic, Dynamic> mVectorsVertices_temp;
mVectorsVertices_temp.resize(iVectorSize, iVerticesCount);
for (i = 0; i < iVerticesCount; i++)
mVectorsVertices_temp.col(i) = rciVectorsC[iVertices[i]];
FullPivLU<Matrix<Rational<RCyclotomic7Integer>, Dynamic, Dynamic>>
lu_mVectorsVertices_temp(mVectorsVertices_temp);
if (lu_mVectorsVertices_temp.rank() < iVectorSize)
return iIsomorphisms;
// -------------------------------------------------------------
// We extract a basis of the space, consisting of a subset of vectors
// designated by iVertices
auto iPerm(lu_mVectorsVertices_temp.permutationQ().indices());
vector<unsigned int> iLinearlyIndependantVertices(
iVectorSize,
0); ///< Strictly speaking, the indices i (in iVertices!) such that the
///< set vectors[ iVertices[i] ] is linearly indpendant
std::sort(iPerm.derived().data(), iPerm.derived().data() + iVectorSize);
Matrix<Rational<RCyclotomic7Integer>, Dynamic, Dynamic> mVectorsVerticesBasis;
mVectorsVerticesBasis.resize(iVectorSize, iVectorSize);
for (i = 0; i < iVectorSize; i++) {
iLinearlyIndependantVertices[i] = iPerm[i];
mVectorsVerticesBasis.col(i) = mVectorsVertices_temp.col(iPerm[i]);
}
// -------------------------------------------------------------
// Constructing the graph
igraph_t graph;
igraph_matrix_t adjMat;
igraph_matrix_init(&adjMat, iVerticesCount, iVerticesCount);
// vertices coloring
igraph_vector_int_t verticesColors;
igraph_vector_int_init(&verticesColors, iVerticesCount);
for (i = 0; i < iVerticesCount; i++) {
VECTOR(verticesColors)[i] = iVectorsNormsFloor[iVertices[i]];
for (j = i + 1; j < iVerticesCount; j++)
MATRIX(adjMat, i, j) = iGraphMatrix[iVertices[i]][iVertices[j]];
}
if (igraph_adjacency(&graph, &adjMat, IGRAPH_ADJ_UNDIRECTED) !=
IGRAPH_SUCCESS)
throw(string(
"InfiniteNSymetries::FindInvolutionInSubgraph: Error creating graph"));
// -------------------------------------------------------------
// Finding isomorphisms
igraph_vector_ptr_t maps;
igraph_vector_ptr_init(&maps, 1);
igraph_get_isomorphisms_vf2(&graph, &graph, &verticesColors, &verticesColors,
0, 0, &maps, 0, 0, 0);
long int iIsomorphismsCount(igraph_vector_ptr_size(&maps));
for (int is(1); is < iIsomorphismsCount; is++) // Don't consider the identity
{
bool bIsInvolution(true), bIsIsomorphism(true);
vector<unsigned int> iPermutation(iVerticesCount, -1);
unsigned int iFixedPoints(0);
igraph_vector_t *v((igraph_vector_t *)igraph_vector_ptr_e(&maps, is));
// ---------------------------------------------------
// Checking that it is an involution and getting the permutation
for (k = 0; k < iVerticesCount; k++) {
iPermutation[k] = (unsigned int)VECTOR(*v)[k];
if (iPermutation[k] == k)
iFixedPoints++;
if ((unsigned int)VECTOR(*v)[(unsigned int)VECTOR(*v)[k]] != k) {
bIsInvolution = false;
break;
}
}
igraph_vector_destroy(v);
free(v);
if (!bIsInvolution)
continue;
// ---------------------------------------------------
// Checking that it is an isomorphism
for (i = 0; i < iVerticesCount && bIsIsomorphism; i++) {
for (j = i + 1; j < iVerticesCount; j++) {
// Weight not preserved or dotted and weight of the dotted not preserved
if ((iGraphMatrix[iVertices[i]][iVertices[j]] !=
iGraphMatrix[iVertices[iPermutation[i]]]
[iVertices[iPermutation[j]]]) ||
(iGraphMatrix[iVertices[i]][iVertices[j]] == 2 &&
!bDottedSameWeight(iVertices[i], iVertices[j],
iVertices[iPermutation[i]],
iVertices[iPermutation[j]]))) {
bIsIsomorphism = false;
break;
}
// If does not preserve some angle
if (riVectorsProducts[iVertices[i]][iVertices[j]] !=
riVectorsProducts[iVertices[iPermutation[i]]]
[iVertices[iPermutation[j]]]) {
bIsIsomorphism = false;
break;
}
}
}
if (!bIsIsomorphism) // Does not preserve the dotted
continue;
// ---------------------------------------------------
// Here, we still have to check it preserves the lattice generated by the
// canonical basis
Matrix<Rational<RCyclotomic7Integer>, Dynamic, Dynamic>
iIntegralSymmetry; ///< Permutation matrix wrt to a basis contained in
///< the vectors corresponding to iVertices
Matrix<Rational<RCyclotomic7Integer>, Dynamic, Dynamic>
mVectorsVerticesBasisInv(mVectorsVerticesBasis.inverse());
iIntegralSymmetry.resize(iVectorSize, iVectorSize);
for (i = 0; i < iVectorSize; i++) {
iIntegralSymmetry.col(i) =
mVectorsVerticesBasisInv *
rciVectorsC[iVertices[iPermutation[iLinearlyIndependantVertices[i]]]];
}
Matrix<Rational<RCyclotomic7Integer>, Dynamic, Dynamic> mCanBasis(
mVectorsVerticesBasis * iIntegralSymmetry * mVectorsVerticesBasisInv);
bool bPreservesLattice(true);
for (i = 0; i < iVectorSize && bPreservesLattice; i++) {
for (j = 0; j < iVectorSize; j++) {
if (!mCanBasis(i, j).get_hasDenominatorOne()) {
bPreservesLattice = false;
break;
}
}
}
if (bPreservesLattice)
iIsomorphisms.push_back({iVertices, iPermutation,
iLinearlyIndependantVertices,
(iVerticesCount + iFixedPoints) / 2});
}
// ----------------------------------------
// Freeing memory
igraph_destroy(&graph);
igraph_matrix_destroy(&adjMat);
igraph_vector_destroy(
(igraph_vector_t *)igraph_vector_ptr_e(&maps, 0)); // identity
free((igraph_vector_t *)igraph_vector_ptr_e(&maps, 0)); // identity
igraph_vector_ptr_destroy(&maps);
igraph_vector_int_destroy(&verticesColors);
return iIsomorphisms;
}
bool RCyclotomic7Integer_InfiniteNSymetries::FindIntegralSymmetryFromSubgraph(
const vector<unsigned int> &iVertices) {
unsigned int i, j;
unsigned int iVerticesCount(iVertices.size());
// -------------------------------------------------------------
// Does the corresponding polyhedron have at least one vertex?
vector<vector<unsigned int>> iCox(vector<vector<unsigned int>>(
iVerticesCount, vector<unsigned int>(iVerticesCount, 2)));
for (i = 0; i < iVerticesCount; i++) {
for (j = i + 1; j < iVerticesCount; j++)
iCox[i][j] = iCox[j][i] = iCoxeterMatrix[iVertices[i]][iVertices[j]];
}
CoxIter ci(iCox, iDimension);
ci.exploreGraph();
ci.computeGraphsProducts();
ci.computeEulerCharacteristicFVector();
vector<unsigned int> iFV(ci.get_fVector());
if (!iFV[0])
return bFinished;
// -------------------------------------------------------------
// Finding the isomorphisms
vector<GraphInvolution> iIsomorphisms(FindIsomorphismsInSubgraph(iVertices));
if (!iIsomorphisms.size())
return bFinished;
// -------------------------------------------------------------
// Going through
WorkWithIsomorphisms(iVertices, iIsomorphisms);
return bFinished;
}
bool RCyclotomic7Integer_InfiniteNSymetries::bDottedSameWeight(
const unsigned int &v1, const unsigned int &v2, const unsigned int &w1,
const unsigned int &w2) const {
return (qiDottedWeights[v1][v2] == qiDottedWeights[w1][w2]);
}
void RCyclotomic7Integer_InfiniteNSymetries::WorkWithIsomorphisms(
const vector<unsigned int> &iVertices,
const vector<GraphInvolution> &iIsomorphisms) {
unsigned int i, j, k, iVerticesCount(iVertices.size());
// -------------------------------------------
// Vectors corresponding to the vertices
Matrix<Rational<RCyclotomic7Integer>, Dynamic, Dynamic> m;
m.resize(iVectorSize, iVerticesCount);
for (unsigned int i(0); i < iVerticesCount; i++)
m.col(i) = rciVectorsC[i];
// --------------------------------------------
// For each isomorphism
for (auto iIso : iIsomorphisms) {
// ------------------------------------------------
// The column of m span the space of fixed points
Matrix<Rational<RCyclotomic7Integer>, Dynamic, Dynamic> m;
m.resize(iVectorSize, iIso.iOrbitCount);
j = 0;
for (i = 0; i < iVerticesCount && j < iIso.iOrbitCount; i++) {
if (iIso.iPermutation[i] == i)
m.col(j++) = rciVectorsC[iVertices[i]];
else if (iIso.iPermutation[i] < i)
m.col(j++) = rciVectorsC[iVertices[i]] +
rciVectorsC[iVertices[iIso.iPermutation[i]]];
}
// We get a basis of the space of fixed points
FullPivLU<Matrix<Rational<RCyclotomic7Integer>, Dynamic, Dynamic>> lu(m);
Matrix<Rational<RCyclotomic7Integer>, Dynamic, Dynamic> basisFixedPoints(
lu.image(m));
unsigned int iFixedPointDimTemp(basisFixedPoints.cols());
if (iFixedPointDimTemp == iVectorSize) // Soooo much fixed points
continue;
#pragma omp critical
{
if (!rciBasisFixedPoints.cols()) // These are the first fixed points
{
rciBasisFixedPoints = basisFixedPoints;
iFixedPointsDimension = iFixedPointDimTemp;
usefulInvolutions.push_back(iIso);
} else // We already have fixed points
{
// The goal here is to take the intersection of the previsous fixed
// points space and the new one
Matrix<Rational<RCyclotomic7Integer>, Dynamic, Dynamic> tempVectors(
rciBasisFixedPoints);
tempVectors.conservativeResize(iVectorSize,
tempVectors.cols() + iFixedPointDimTemp);
for (j = 0; j < iFixedPointDimTemp; j++)
tempVectors.col(j + iFixedPointsDimension) = basisFixedPoints.col(j);
FullPivLU<Matrix<Rational<RCyclotomic7Integer>, Dynamic, Dynamic>>
luTemp(tempVectors);
Matrix<Rational<RCyclotomic7Integer>, Dynamic, Dynamic> ker(
luTemp.kernel());
if (luTemp.dimensionOfKernel() == 0) {
bFinished = true;
iFixedPointsDimension = 0;
rciBasisFixedPoints.resize(iVectorSize, 0);
usefulInvolutions.push_back(iIso);
}
if (ker.cols() < iFixedPointsDimension &&
!bFinished) // If we earned something
{
usefulInvolutions.push_back(iIso);
unsigned int iIntersectionDimension(ker.cols());
rciBasisFixedPoints.resize(iVectorSize, iIntersectionDimension);
for (j = 0; j < iIntersectionDimension; j++) {
Matrix<Rational<RCyclotomic7Integer>, Dynamic, 1> v(
ker(0, j) * tempVectors.col(0));
for (k = 1; k < iFixedPointsDimension; k++)
v += ker(k, j) * tempVectors.col(k);
rciBasisFixedPoints.col(j) = v;
}
iFixedPointsDimension = ker.cols();
if (iFixedPointsDimension == 1) {
if (rciVectorNorm(rciBasisFixedPoints.col(0)) >= 0) {
bFinished = true;
}
} else if (iFixedPointsDimension == 2) {
// If the basis has two orthogonal vector of positive norm
if (rciVectorNorm(rciBasisFixedPoints.col(0)) >= 0 &&
rciVectorNorm(rciBasisFixedPoints.col(1)) >= 0 &&
rciVectorsProduct(rciBasisFixedPoints.col(0),
rciBasisFixedPoints.col(1)) == 0)
bFinished = true;
}
}
}
}
if (bFinished)
return;
}
}
void RCyclotomic7Integer_InfiniteNSymetries::print_basisFixedPoints(
const string &strSpacer) const {
for (unsigned int i(0); i < iFixedPointsDimension; i++)
cout << strSpacer
<< Matrix<Rational<RCyclotomic7Integer>, 1, Eigen::Dynamic>(
rciBasisFixedPoints.col(i).transpose())
<< endl;
}