Orbiter 2022
Combinatorial Objects
flag.cpp
Go to the documentation of this file.
1// flag.cpp
2//
3// Anton Betten
4// May 19, 2016
5//
6//
7//
8//
9//
10
11#include "foundations.h"
12
13using namespace std;
14
15
16namespace orbiter {
17namespace layer1_foundations {
18namespace geometry {
19
20
22{
23 null();
24}
25
27{
28 freeself();
29}
30
32{
33 Gr = NULL;
34 Flag = NULL;
35 M = NULL;
36 M_Gauss = NULL;
37 transform = NULL;
38 base_cols = NULL;
39 M1 = NULL;
40 M2 = NULL;
41 M3 = NULL;
42}
43
45{
46 if (Gr) {
48 }
49 if (Flag) {
51 }
52 if (M) {
53 FREE_int(M);
54 }
55 if (M_Gauss) {
57 }
58 if (transform) {
60 }
61 if (base_cols) {
63 }
64 if (M1) {
65 FREE_int(M1);
66 }
67 if (M2) {
68 FREE_int(M2);
69 }
70 if (M3) {
71 FREE_int(M3);
72 }
73 null();
74}
75
76void flag::init(int n,
77 int *type, int type_len, field_theory::finite_field *F,
78 int verbose_level)
79{
80 int f_v = (verbose_level >= 1);
81
82 if (f_v) {
83 cout << "flag::init type_len = "
84 << type_len << " idx=" << idx << endl;
85 }
86 init_recursion(n, type, type_len, type_len - 1, F, verbose_level);
87 if (f_v) {
88 cout << "flag::init done" << endl;
89 }
90}
91
93 int *type, int type_len, int idx, field_theory::finite_field *F,
94 int verbose_level)
95{
96 int f_v = (verbose_level >= 1);
97 int i;
99
100 if (f_v) {
101 cout << "flag::init_recursion type_len = "
102 << type_len << " idx=" << idx << endl;
103 }
104 flag::F = F;
105 flag::n = n;
108 flag::idx = idx;
109
111 K = 0;
112 for (i = 0; i < type_len; i++) {
113 K += type[i];
114 }
115 s0 = 0;
116 for (i = 0; i < idx; i++) {
117 s0 += type[i];
118 }
119 k = type[idx];
120 s1 = s0 + k;
121 if (idx < type_len - 1) {
122 s2 = s1 + type[idx + 1];
123 }
124 else {
125 s2 = n;
126 }
127 Gr->init(s2, s1, F, 0 /* verbose_level */);
128 if (f_v) {
129 cout << "flag::init type_len = " << type_len << " s0=" << s0
130 << " s1=" << s1 << " s2=" << s2 << " k=" << k
131 << " K=" << K << endl;
132 }
133 M = NEW_int(K * n);
134 M_Gauss = NEW_int(K * n);
135 transform = NEW_int(K * K);
137 M1 = NEW_int(n * n);
138 M2 = NEW_int(n * n);
139 M3 = NEW_int(n * n);
140
141 if (idx > 0) {
143
144 Flag->init_recursion(n, type, type_len, idx - 1, F, verbose_level);
145 }
146 else {
147 Flag = NULL;
148 }
149 if (idx == 0) {
150 N0 = 1;
151 }
152 else {
153 N0 = Flag->N;
154 }
155 N1 = Combi.generalized_binomial(s2, s1, F->q);
156 N = N0 * N1;
157 if (f_v) {
158 cout << "flag::init_recursion type_len = " << type_len
159 << " N0=" << N0 << " N1=" << N1 << " N=" << N << endl;
160 }
161
162 if (f_v) {
163 cout << "flag::init_recursion type_len = " << type_len
164 << " done" << endl;
165 }
166}
167
168void flag::unrank(long int rk, int *subspace, int verbose_level)
169{
170 int f_v = (verbose_level >= 1);
171 long int a, b;
172
173 if (f_v) {
174 cout << "flag::unrank idx=" << idx << " rk=" << rk << endl;
175 }
176
177 if (idx != type_len - 1) {
178 cout << "flag::unrank idx != type_len - 1" << endl;
179 exit(1);
180 }
181
182 b = rk % N0;
183 a = rk / N0;
184 if (f_v) {
185 cout << "flag::unrank idx=" << idx << " rk=" << rk
186 << " a=" << a << " b=" << b << endl;
187 }
188
189 Gr->unrank_embedded_subspace_lint(a, 0 /*verbose_level*/);
190 Int_vec_copy(Gr->M, M, K * n);
191 if (f_v) {
192 cout << "flag::unrank M=" << endl;
194 }
195 if (Flag) {
196 Flag->unrank_recursion(b, M, verbose_level);
197 }
198 Int_vec_copy(M, subspace, K * n);
199}
200
201void flag::unrank_recursion(long int rk, int *subspace, int verbose_level)
202// subspace is K x n
203{
204 int f_v = (verbose_level >= 1);
205 long int a, b;
206
207 if (f_v) {
208 cout << "flag::unrank_recursion idx=" << idx
209 << " rk=" << rk << endl;
210 }
211 if (f_v) {
212 cout << "flag::unrank_recursion subspace=" << endl;
213 Int_matrix_print(subspace, K, n);
214 }
215
216 b = rk % N0;
217 a = rk / N0;
218
219 if (f_v) {
220 cout << "flag::unrank_recursion idx=" << idx
221 << " rk=" << rk << " a=" << a << " b=" << b << endl;
222 }
223
224 Gr->unrank_embedded_subspace_lint(a, 0 /*verbose_level*/);
225
226 // now Gr->M is s2 x s2
227
228 if (f_v) {
229 cout << "flag::unrank_recursion after unrank "
230 << a << ":" << endl;
232 }
233
234 F->Linear_algebra->mult_matrix_matrix(Gr->M, subspace, M, s2, s2, n,
235 0 /* verbose_level */);
236 Int_vec_copy(subspace + s2 * n, M + s2 * n, (K - s2) * n);
237
238 if (f_v) {
239 cout << "flag::unrank_recursion idx=" << idx
240 << " after mult, subspace=:" << endl;
242 }
243
244
245
246 if (Flag) {
247 Flag->unrank_recursion(b, M, verbose_level);
248 }
249 Int_vec_copy(M, subspace, K * n);
250}
251
252long int flag::rank(int *input_subspace, int verbose_level)
253{
254 int f_v = (verbose_level >= 1);
255 long int a, b, rk;
256
257 if (f_v) {
258 cout << "flag::rank idx=" << idx << endl;
259 }
260
261 if (idx != type_len - 1) {
262 cout << "flag::rank idx != type_len - 1" << endl;
263 exit(1);
264 }
265 if (f_v) {
266 cout << "flag::rank input_subspace:" << endl;
267 Int_matrix_print(input_subspace, K, n);
268 }
269
270 Int_vec_copy(input_subspace, M, K * n);
271 Int_vec_copy(input_subspace, Gr->M, s2 * n);
272 a = Gr->rank_lint(0 /*verbose_level*/);
273 if (f_v) {
274 cout << "flag::rank idx=" << idx << " a=" << a << endl;
275 }
276 Gr->unrank_embedded_subspace_lint(a, 0 /*verbose_level*/);
277 Int_vec_copy(Gr->M, M1, K * n);
278 if (f_v) {
279 cout << "flag::rank after unrank:" << endl;
281 }
282 if (Flag) {
283 b = Flag->rank_recursion(M, M1, verbose_level);
284 }
285 else {
286 b = 0;
287 }
288 rk = a * N0 + b;
289 if (f_v) {
290 cout << "flag::rank idx=" << idx << " rk=" << rk
291 << " a=" << a << " b=" << b << endl;
292 }
293 return rk;
294}
295
296long int flag::rank_recursion(int *input_subspace,
297 int *big_space, int verbose_level)
298{
299 int f_v = (verbose_level >= 1);
300 long int a, b, rk, r, i, j;
302
303 if (f_v) {
304 cout << "flag::rank_recursion idx=" << idx << endl;
305 }
306 if (f_v) {
307 cout << "flag::rank_recursion input_subspace:" << endl;
308 Int_matrix_print(input_subspace, s1, n);
309 }
310 if (f_v) {
311 cout << "flag::rank_recursion big_space:" << endl;
312 Int_matrix_print(big_space, s2, n);
313 }
314 Int_vec_copy(big_space, M, s2 * n);
315 Int_vec_copy(big_space, M_Gauss, s2 * n);
318 FALSE /*f_special*/,
319 TRUE/* f_complete*/, base_cols,
320 TRUE /* f_P */, transform, s2, n,
321 s2 /* Pn */,
322 0/*int verbose_level*/);
323 if (r != s2) {
324 cout << "flag::rank_recursion r != s2" << endl;
325 cout << "r=" << r << endl;
326 cout << "s2=" << s2 << endl;
327 exit(1);
328 }
329 if (f_v) {
330 cout << "flag::rank_recursion transform:" << endl;
332 }
333 for (i = 0; i < s1; i++) {
334 for (j = 0; j < s2; j++) {
335 a = input_subspace[i * n + base_cols[j]];
336 M1[i * s2 + j] = a;
337 }
338 }
339 // now M1 is s1 x s2
340 if (f_v) {
341 cout << "flag::rank_recursion input submatrix M1:" << endl;
343 }
344
346 0 /* verbose_level */);
347
348 // now M2 is s1 x s2
349 // M2 is the coefficient matrix that defines
350 // the given subspace input_subspace
351 // in terms of the big space big_space
352 // this means: M2 * big_space = input_subspace
353 if (f_v) {
354 cout << "flag::rank_recursion coefficient matrix M2:" << endl;
356 }
357
358 for (i = 0; i < s1; i++) {
360 M, M3, s2, n);
361 if (f_v) {
362 cout << "flag::rank_recursion i=" << i << " M3=" << endl;
364 M3, 1, n, n, F->log10_of_q);
365 }
366 if (Sorting.int_vec_compare(input_subspace + i * n, M3, n)) {
367 cout << "flag::rank_recursion fatal: "
368 "the i-th vector is not in the space" << endl;
369 cout << "i=" << i << endl;
370 exit(1);
371 }
372 // add one row to Gr->M:
373 Int_vec_copy(M2 + i * s2, Gr->M + i * s2, s2);
374 }
375
376
377 // now Gr->M is s1 x s2
378
379 if (f_v) {
380 cout << "flag::rank_recursion coefficient matrix:" << endl;
382 Gr->M, s1, s2, s2, F->log10_of_q);
383 }
384 a = Gr->rank_lint(verbose_level);
385 if (f_v) {
386 cout << "a=" << a << endl;
387 }
388 Gr->unrank_embedded_subspace_lint(a, 0 /*verbose_level*/);
389 // now Gr->M is s2 x s2
390 if (f_v) {
391 cout << "after unrank_embedded, coefficient matrix is" << endl;
393 }
394 F->Linear_algebra->mult_matrix_matrix(Gr->M, big_space, M, s2, s2, n,
395 0 /* verbose_level */);
396 Int_vec_copy(big_space + s2 * n, M + s2 * n, (K - s2) * n);
397 //now M is K x n
398 if (f_v) {
399 cout << "after unrank_embedded:" << endl;
401 }
402
403 if (Flag) {
404 b = Flag->rank_recursion(input_subspace, M, verbose_level);
405 }
406 else {
407 b = 0;
408 }
409 rk = a * N0 + b;
410 if (f_v) {
411 cout << "flag::rank_recursion idx=" << idx
412 << " a=" << a << " b=" << b << " rk=" << rk << endl;
413 }
414 return rk;
415}
416
417}}}
418
419
a collection of functions related to sorted vectors
a maximal chain of subspaces
Definition: geometry.h:522
void unrank(long int rk, int *subspace, int verbose_level)
Definition: flag.cpp:168
void unrank_recursion(long int rk, int *subspace, int verbose_level)
Definition: flag.cpp:201
void init_recursion(int n, int *type, int type_len, int idx, field_theory::finite_field *F, int verbose_level)
Definition: flag.cpp:92
void init(int n, int *type, int type_len, field_theory::finite_field *F, int verbose_level)
Definition: flag.cpp:76
field_theory::finite_field * F
Definition: geometry.h:524
long int rank(int *subspace, int verbose_level)
Definition: flag.cpp:252
long int rank_recursion(int *subspace, int *big_space, int verbose_level)
Definition: flag.cpp:296
to rank and unrank subspaces of a fixed dimension in F_q^n
Definition: geometry.h:892
void unrank_embedded_subspace_lint(long int rk, int verbose_level)
Definition: grassmann.cpp:281
void init(int n, int k, field_theory::finite_field *F, int verbose_level)
Definition: grassmann.cpp:70
void mult_vector_from_the_left(int *v, int *A, int *vA, int m, int n)
int Gauss_int(int *A, int f_special, int f_complete, int *base_cols, int f_P, int *P, int m, int n, int Pn, int verbose_level)
void mult_matrix_matrix(int *A, int *B, int *C, int m, int n, int o, int verbose_level)
#define FREE_int(p)
Definition: foundations.h:640
#define NEW_OBJECT(type)
Definition: foundations.h:638
#define FREE_OBJECT(p)
Definition: foundations.h:651
#define NEW_int(n)
Definition: foundations.h:625
#define Int_vec_print_integer_matrix_width(A, B, C, D, E, F)
Definition: foundations.h:691
#define Int_matrix_print(A, B, C)
Definition: foundations.h:707
#define TRUE
Definition: foundations.h:231
#define FALSE
Definition: foundations.h:234
#define Int_vec_copy(A, B, C)
Definition: foundations.h:693
the orbiter library for the classification of combinatorial objects