Orbiter 2022
Combinatorial Objects
projective_space_implementation.cpp
Go to the documentation of this file.
1/*
2 * projective_space_implementation.cpp
3 *
4 * Created on: Nov 2, 2021
5 * Author: betten
6 */
7
8
9#include "foundations.h"
10
11
12using namespace std;
13
14
15#define MAX_NUMBER_OF_LINES_FOR_INCIDENCE_MATRIX 100000
16#define MAX_NUMBER_OF_LINES_FOR_LINE_TABLE 1000000
17#define MAX_NUMBER_OF_POINTS_FOR_POINT_TABLE 1000000
18#define MAX_NB_POINTS_FOR_LINE_THROUGH_TWO_POINTS_TABLE 10000
19#define MAX_NB_POINTS_FOR_LINE_INTERSECTION_TABLE 10000
20
21
22namespace orbiter {
23namespace layer1_foundations {
24namespace geometry {
25
26
28{
29 P = NULL;
30
31 Bitmatrix = NULL;
32
34 Line_intersection = NULL;
35 Lines = NULL;
36 Lines_on_point = NULL;
37
38 v = NULL;
39 w = NULL;
40
41}
42
44{
45 if (Bitmatrix) {
47 }
50 }
53 }
54 if (Lines) {
56 }
57 if (Lines_on_point) {
59 }
60 if (v) {
61 FREE_int(v);
62 }
63 if (w) {
64 FREE_int(w);
65 }
66}
67
69{
70 int f_v = (verbose_level >= 1);
71 int f_vv = FALSE; //(verbose_level >= 2);
72 //int f_vvv = (verbose_level >= 3);
73
74 int i, j, a, b, i1, i2, j1, j2;
75 long int N_points, N_lines;
76 int k, r, n;
77
78 if (f_v) {
79 cout << "projective_space_implementation::init" << endl;
80 }
81
83
84 N_points = P->N_points;
85 N_lines = P->N_lines;
86 k = P->k;
87 r = P->r;
88 n = P->n;
89
90 v = NEW_int(n + 1);
91 w = NEW_int(n + 1);
92
94 if (f_v) {
95 cout << "projective_space_implementation::init "
96 "allocating Incidence (bitvector)" << endl;
97 }
99 Bitmatrix->init(N_points, N_lines, verbose_level);
100 }
101 else {
102 if (f_v) {
103 cout << "projective_space_implementation::init: "
104 "N_lines too big, we do not initialize the "
105 "incidence matrix" << endl;
106 }
107 Bitmatrix = NULL;
108 }
109
110
112 if (f_v) {
113 cout << "projective_space_implementation::init "
114 "allocating Lines" << endl;
115 }
116 Lines = NEW_int(N_lines * k);
117 }
118 else {
119 if (f_v) {
120 cout << "projective_space_implementation::init: "
121 "N_lines too big, we do not initialize "
122 "the line table" << endl;
123 }
124 Lines = NULL;
125 }
126
127
128
129
132 if (f_v) {
133 cout << "projective_space_implementation::init "
134 "allocating Lines_on_point" << endl;
135 cout << "projective_space_implementation::init "
136 "allocating N_points=" << N_points << endl;
137 cout << "projective_space_implementation::init "
138 "allocating r=" << r << endl;
139 }
140 Lines_on_point = NEW_int(N_points * r);
141 }
142 else {
143 if (f_v) {
144 cout << "projective_space_implementation::init: "
145 "N_points too big, we do not initialize the "
146 "Lines_on_point table" << endl;
147 }
148 Lines_on_point = NULL;
149 }
150
151
152
153
154 if ((long int) N_points < MAX_NB_POINTS_FOR_LINE_THROUGH_TWO_POINTS_TABLE) {
155
156 if (f_v) {
157 cout << "projective_space_implementation::init "
158 "allocating Line_through_two_points" << endl;
159 }
160 Line_through_two_points = NEW_int((long int) N_points * (long int) N_points);
161 }
162 else {
163 if (f_v) {
164 cout << "projective_space_implementation::init: "
165 "we do not initialize "
166 "Line_through_two_points" << endl;
167 }
169 }
170
171 if ((long int) N_lines < MAX_NB_POINTS_FOR_LINE_INTERSECTION_TABLE) {
172 if (f_v) {
173 cout << "projective_space_implementation::init "
174 "allocating Line_intersection" << endl;
175 }
176 Line_intersection = NEW_int((long int) N_lines * (long int) N_lines);
177 Int_vec_zero(Line_through_two_points, (long int) N_points * (long int) N_points);
178 for (i = 0; i < (long int) N_lines * (long int) N_lines; i++) {
179 Line_intersection[i] = -1;
180 }
181 }
182 else {
183 if (f_v) {
184 cout << "projective_space_implementation::init: "
185 "we do not initialize "
186 "Line_intersection" << endl;
187 }
188 Line_intersection = NULL;
189 }
190
191
192 if (f_v) {
193 cout << "projective_space_implementation::init "
194 "number of points = " << N_points << endl;
195 }
196 if (FALSE) {
197 for (i = 0; i < N_points; i++) {
198 P->F->PG_element_unrank_modified(v, 1, n + 1, i);
199 cout << "point " << i << " : ";
200 Int_vec_print(cout, v, n + 1);
201 cout << " = ";
202 P->F->int_vec_print_field_elements(cout, v, n + 1);
203
205 cout << " = ";
206 Int_vec_print(cout, v, n + 1);
207
208
209 cout << " = ";
210 P->F->int_vec_print_field_elements(cout, v, n + 1);
211
212
213 cout << endl;
214 }
215 }
216 if (f_v) {
217 cout << "projective_space_implementation::init "
218 "number of lines = " << N_lines << endl;
219 }
220
221
222
223 if (Lines || Bitmatrix || Lines_on_point) {
224
225
226 if (f_v) {
227 cout << "projective_space_implementation::init "
228 "computing lines..." << endl;
229 if (Lines) {
230 cout << "Lines is allocated" << endl;
231 }
232 if (Bitmatrix) {
233 cout << "Bitmatrix is allocated" << endl;
234 }
235 if (Lines_on_point) {
236 cout << "Lines_on_point is allocated" << endl;
237 }
238 }
239
240
241
242 int *R;
243
244 R = NEW_int(N_points);
245 Int_vec_zero(R, N_points);
246
247 for (i = 0; i < N_lines; i++) {
248#if 0
249 if ((i % 1000000) == 0) {
250 cout << "projective_space_implementation::init "
251 "Line " << i << " / " << N_lines << ":" << endl;
252 }
253#endif
254 P->Grass_lines->unrank_lint(i, 0/*verbose_level - 4*/);
255 if (FALSE) {
257 P->Grass_lines->M, 2, n + 1, n + 1,
258 P->F->log10_of_q + 1);
259 }
260
261
262#if 0
263 // testing of grassmann:
264
265 j = Grass_lines->rank_int(0/*verbose_level - 4*/);
266 if (j != i) {
267 cout << "projective_space_implementation::init "
268 "rank yields " << j << " != " << i << endl;
269 exit(1);
270 }
271#endif
272
273
274
275 for (a = 0; a < k; a++) {
276 P->F->PG_element_unrank_modified(v, 1, 2, a);
277 P->F->Linear_algebra->mult_matrix_matrix(v, P->Grass_lines->M, w, 1, 2, n + 1,
278 0 /* verbose_level */);
279 P->F->PG_element_rank_modified(w, 1, n + 1, b);
280 if (Bitmatrix) {
281 Bitmatrix->m_ij(b, i, 1);
282 }
283
284 if (Lines) {
285 Lines[i * k + a] = b;
286 }
287 if (Lines_on_point) {
288 Lines_on_point[b * r + R[b]] = i;
289 }
290 R[b]++;
291 }
292 if (f_vv) {
293 cout << "line " << i << ":" << endl;
295 P->Grass_lines->M, 2, n + 1, n + 1,
296 P->F->log10_of_q + 1);
297
298 if (Lines) {
299 cout << "points on line " << i << " : ";
300 Int_vec_print(cout, Lines + i * k, k);
301 cout << endl;
302 }
303 }
304
305 }
306 for (i = 0; i < N_points; i++) {
307 if (R[i] != r) {
308 cout << "R[i] != r" << endl;
309 exit(1);
310 }
311 }
312
313 FREE_int(R);
314 }
315 else {
316 if (f_v) {
317 cout << "projective_space_implementation::init "
318 "computing lines skipped" << endl;
319 }
320 }
321
322
323
324#if 0
325 if (f_v) {
326 cout << "computing Lines_on_point..." << endl;
327 }
328 for (i = 0; i < N_points; i++) {
329 if ((i % 1000) == 0) {
330 cout << "point " << i << " / " << N_points << ":" << endl;
331 }
332 a = 0;
333 for (j = 0; j < N_lines; j++) {
334 if (is_incident(i, j)) {
335 Lines_on_point[i * r + a] = j;
336 a++;
337 }
338 }
339 if (FALSE /*f_vv */) {
340 cout << "lines on point " << i << " = ";
341 PG_element_unrank_modified(*F, w, 1, n + 1, i);
342 int_vec_print(cout, w, n + 1);
343 cout << " : ";
344 int_vec_print(cout, Lines_on_point + i * r, r);
345 cout << endl;
346 }
347 }
348 if (f_v) {
349 cout << "computing Lines_on_point done" << endl;
350 }
351#endif
352
353 if (FALSE) {
354 //cout << "incidence matrix:" << endl;
355 //print_integer_matrix_width(cout, Incidence, N_points, N_lines, N_lines, 1);
356 cout << "projective_space::init_incidence_structure Lines:" << endl;
357 Int_vec_print_integer_matrix_width(cout, Lines, N_lines, k, k, 3);
358 cout << "projective_space::init_incidence_structure Lines_on_point:" << endl;
359 Int_vec_print_integer_matrix_width(cout, Lines_on_point, N_points, r, r, 3);
360 }
361
362
364 if (f_v) {
365 cout << "projective_space_implementation::init "
366 "computing Line_through_two_points..." << endl;
367 }
368 for (i1 = 0; i1 < N_points; i1++) {
369 for (a = 0; a < r; a++) {
370 j = Lines_on_point[i1 * r + a];
371 for (b = 0; b < k; b++) {
372 i2 = Lines[j * k + b];
373 if (i2 == i1) {
374 continue;
375 }
376 Line_through_two_points[i1 * N_points + i2] = j;
377 Line_through_two_points[i2 * N_points + i1] = j;
378 }
379 }
380 }
381 if (FALSE) {
382 cout << "line through points i,j is" << endl;
383 for (i = 0; i < N_points; i++) {
384 for (j = i + 1; j < N_points; j++) {
385 cout << i << " , " << j << " : "
386 << Line_through_two_points[i * N_points + j] << endl;
387 }
388 }
389 //cout << "Line_through_two_points:" << endl;
390 //print_integer_matrix_width(cout,
391 //Line_through_two_points, N_points, N_points, N_points, 2);
392 }
393 }
394 else {
395 if (f_v) {
396 cout << "projective_space_implementation::init "
397 "computing Line_through_two_points skipped" << endl;
398 }
399 }
400
402 if (f_v) {
403 cout << "projective_space_implementation::init "
404 "computing Line_intersection..." << endl;
405 }
406 for (j1 = 0; j1 < N_lines; j1++) {
407 for (a = 0; a < k; a++) {
408 i = Lines[j1 * k + a];
409 for (b = 0; b < r; b++) {
410 j2 = Lines_on_point[i * r + b];
411 if (j2 == j1) {
412 continue;
413 }
414 Line_intersection[j1 * N_lines + j2] = i;
415 Line_intersection[j2 * N_lines + j1] = i;
416 }
417 }
418 }
419 if (FALSE) {
420 cout << "projective_space_implementation::init "
421 "point of intersection of lines i,j is" << endl;
422 for (i = 0; i < N_lines; i++) {
423 for (j = i + 1; j < N_lines; j++) {
424 cout << i << " , " << j << " : "
425 << Line_intersection[i * N_lines + j] << endl;
426 }
427 }
428 //cout << "Line_intersection:" << endl;
429 //print_integer_matrix_width(cout,
430 // Line_intersection, N_lines, N_lines, N_lines, 2);
431 }
432 }
433 else {
434 if (f_v) {
435 cout << "projective_space_implementation::init "
436 "computing Line_intersection skipped" << endl;
437 }
438 }
439 if (f_v) {
440 cout << "projective_space_implementation::init done" << endl;
441 }
442}
443
444
445}}}
446
447
448
449
matrices over GF(2) stored as bitvectors
void init(int m, int n, int verbose_level)
Definition: bitmatrix.cpp:35
void PG_element_rank_modified(int *v, int stride, int len, int &a)
void PG_element_unrank_modified(int *v, int stride, int len, int a)
void int_vec_print_field_elements(std::ostream &ost, int *v, int len)
void unrank_lint(long int rk, int verbose_level)
Definition: grassmann.cpp:343
projective space PG(n,q) of dimension n over Fq
Definition: geometry.h:1916
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 Int_vec_zero(A, B)
Definition: foundations.h:713
#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 FALSE
Definition: foundations.h:234
#define Int_vec_print(A, B, C)
Definition: foundations.h:685
the orbiter library for the classification of combinatorial objects
#define MAX_NUMBER_OF_POINTS_FOR_POINT_TABLE
#define MAX_NUMBER_OF_LINES_FOR_INCIDENCE_MATRIX
#define MAX_NB_POINTS_FOR_LINE_THROUGH_TWO_POINTS_TABLE
#define MAX_NB_POINTS_FOR_LINE_INTERSECTION_TABLE
#define MAX_NUMBER_OF_LINES_FOR_LINE_TABLE