Orbiter 2022
Combinatorial Objects
rank_checker.cpp
Go to the documentation of this file.
1// rank_checker.cpp
2//
3// Anton Betten
4//
5// moved here from projective: May 10, 2009
6
7
8
9
10#include "foundations.h"
11
12using namespace std;
13
14
15namespace orbiter {
16namespace layer1_foundations {
17namespace algebra {
18
19
21{
22 GFq = NULL;
23 m = 0;
24 n = 0;
25 d = 0;
26 M1 = NULL;
27 M2 = NULL;
28 base_cols = NULL;
29 set = NULL;
30}
31
33{
34 //cout << "in ~rank_checker()" << endl;
35 if (M1)
36 FREE_int(M1);
37 if (M2)
38 FREE_int(M2);
39 if (base_cols)
41 if (set)
43 //cout << "~rank_checker() finished" << endl;
44}
45
47{
52 M1 = NEW_int(m * n);
53 M2 = NEW_int(m * n);
55 set = NEW_int(n);
56}
57
58int rank_checker::check_rank(int len, long int *S, int verbose_level)
59{
60 int f_v = (verbose_level >= 1);
61 int f_vv = (verbose_level >= 2);
62 int i, j, aj, rk, f_OK = TRUE;
64
65 if (f_v) {
66 cout << "rank_checker::check_rank: checking the set ";
67 Lint_vec_print(cout, S, len);
68 cout << endl;
69 }
70 // M1 will be used as a m x len matrix
71 for (j = 0; j < len; j++) {
73 M1 + j, len /* stride */, m /* len */, S[j]);
74 }
75 if (f_vv) {
76 cout << "\n";
77 //print_integer_matrix(cout, gen.S, 1, len);
79 }
80 if (len <= 1) {
81 return TRUE;
82 }
83 if (d <= 1) {
84 return TRUE;
85 }
86 int d1 = MINIMUM(d - 2, len - 1);
87 if (f_vv) {
88 cout << "d1=" << d1 << endl;
89 }
90
91
92 // M2 will be used as a m x (d1 + 1) matrix
93
94 Combi.first_k_subset(set, len - 1, d1);
95 while (TRUE) {
96
97 // get the subset of columns:
98 if (f_vv) {
99 cout << "subset: ";
100 Int_vec_print(cout, set, d1);
101 cout << endl;
102 }
103
104 for (j = 0; j < d1; j++) {
105 aj = set[j];
106 for (i = 0; i < m; i++) {
107 M2[i * (d1 + 1) + j] = M1[i * len + aj];
108 }
109 }
110 for (i = 0; i < m; i++) {
111 M2[i * (d1 + 1) + d1] = M1[i * len + len - 1];
112 }
113 if (FALSE) {
114 Int_vec_print_integer_matrix(cout, M2, m, d1 + 1);
115 }
116
118 FALSE /* f_special */,
119 FALSE /* f_complete */,
120 base_cols,
121 FALSE /* f_P */, NULL,
122 m /* m */, d1 + 1 /* n */, 0 /* Pn */,
123 0 /* verbose_level */);
124 if (rk <= d1) {
125 f_OK = FALSE;
126 if (f_v) {
127 cout << "not OK; subset: ";
128 Int_vec_print(cout, set, d1);
129 cout << " leads to a rk " << rk << " submatrix" << endl;
130 }
131 break;
132 }
133 if (!Combi.next_k_subset(set, len - 1, d1)) {
134 break;
135 }
136 }
137 if (!f_OK) {
138 return FALSE;
139 }
140 return TRUE;
141}
142
144 int len, long int *S, int dim_S, int verbose_level)
145{
146 int f_v = (verbose_level >= 1);
147 int f_vv = (verbose_level >= 2);
148 int i, j, aj, rk, f_OK = TRUE;
150
151 // S is a m x len matrix
152 if (len <= 1) {
153 return TRUE;
154 }
155 if (d <= 1) {
156 return TRUE;
157 }
158 int d1 = MINIMUM(d - 2, len - 1);
159 if (f_vv) {
160 cout << "d1=" << d1 << endl;
161 }
162
163
164 // M2 will be used as a m x (d1 + 1) matrix
165
166 Combi.first_k_subset(set, len - 1, d1);
167 while (TRUE) {
168
169 // get the subset of columns:
170 if (f_vv) {
171 cout << "subset: ";
172 Int_vec_print(cout, set, d1);
173 cout << endl;
174 }
175
176 for (j = 0; j < d1; j++) {
177 aj = set[j];
178 for (i = 0; i < m; i++) {
179 M2[i * (d1 + 1) + j] = S[i * dim_S + aj];
180 }
181 }
182 for (i = 0; i < m; i++) {
183 M2[i * (d1 + 1) + d1] = S[i * dim_S + len - 1];
184 }
185
187 FALSE /* f_special */,
188 FALSE /* f_complete */,
189 base_cols,
190 FALSE /* f_P */, NULL,
191 m /* m */, d1 + 1 /* n */, 0 /* Pn */,
192 0 /* verbose_level */);
193 if (rk <= d1) {
194 f_OK = FALSE;
195 if (f_v) {
196 cout << "not OK; subset: ";
197 Int_vec_print(cout, set, d1);
198 cout << " leads to a rk " << rk
199 << " submatrix, but we want rank "
200 << d1 + 1 << endl;
201 }
202 break;
203 }
204 if (!Combi.next_k_subset(set, len - 1, d1)) {
205 break;
206 }
207 }
208 if (!f_OK) {
209 return FALSE;
210 }
211 return TRUE;
212}
213
215 int len, long int *S, int verbose_level)
216{
217 int f_v = (verbose_level >= 1);
218 int f_vv = (verbose_level >= 2);
219 int i, j, aj, rk, f_OK = TRUE;
221
222 if (f_v) {
223 cout << "rank_checker::check_rank_last_two_are_fixed: "
224 "checking the set ";
225 Lint_vec_print(cout, S, len);
226 cout << endl;
227 }
228 // M1 will be used as a m x len matrix
229 for (j = 0; j < len; j++) {
231 M1 + j, len /* stride */, m /* len */, S[j]);
232 }
233 if (f_vv) {
234 cout << "\n";
235 //print_integer_matrix(cout, gen.S, 1, len);
236 Int_vec_print_integer_matrix(cout, M1, m, len);
237 }
238 if (len <= 1) {
239 return TRUE;
240 }
241 if (d <= 2) {
242 return TRUE;
243 }
244 int d1 = MINIMUM(d - 3, len - 2);
245 if (f_vv) {
246 cout << "d1=" << d1 << endl;
247 }
248
249
250 // M2 will be used as a m x (d1 + 2) matrix
251
252 Combi.first_k_subset(set, len - 2, d1);
253 while (TRUE) {
254
255 // get the subset of columns:
256 if (f_vv) {
257 cout << "subset: ";
258 Int_vec_print(cout, set, d1);
259 cout << endl;
260 }
261
262 for (j = 0; j < d1; j++) {
263 aj = set[j];
264 for (i = 0; i < m; i++) {
265 M2[i * (d1 + 2) + j] = M1[i * len + aj];
266 }
267 }
268 for (i = 0; i < m; i++) {
269 M2[i * (d1 + 2) + d1] = M1[i * len + len - 2];
270 M2[i * (d1 + 2) + d1 + 1] = M1[i * len + len - 1];
271 }
272 if (FALSE) {
273 Int_vec_print_integer_matrix(cout, M2, m, d1 + 2);
274 }
275
277 FALSE /* f_special */,
278 FALSE /* f_complete */,
279 base_cols,
280 FALSE /* f_P */, NULL,
281 m /* m */, d1 + 2 /* n */, 0 /* Pn */,
282 0 /* verbose_level */);
283 if (rk <= d1 + 1) {
284 f_OK = FALSE;
285 if (f_v) {
286 cout << "not OK; subset: ";
287 Int_vec_print(cout, set, d1);
288 cout << " leads to a rk " << rk << " submatrix" << endl;
289 }
290 break;
291 }
292 if (!Combi.next_k_subset(set, len - 2, d1)) {
293 break;
294 }
295 }
296 if (!f_OK) {
297 return FALSE;
298 }
299 if (f_v) {
300 cout << "is OK" << endl;
301 }
302 return TRUE;
303}
304
306 int len, long int *S, int f_projective, int verbose_level)
307{
308 int f_v = (verbose_level >= 1);
309 int f_vv = (verbose_level >= 2);
310 int j, rk;
312
313 if (f_vv) {
314 cout << "rank_checker::compute_rank_row_vectors set ";
315 Lint_vec_print(cout, S, len);
316 cout << endl;
317 }
318 // M1 will be used as a len x n matrix
319 for (j = 0; j < len; j++) {
320 if (f_projective) {
322 M1 + j * n, 1 /* stride */, n /* len */, S[j]);
323 }
324 else {
325 Gg.AG_element_unrank(GFq->q, M1 + j * n, 1, n, S[j]);
326 }
327 }
328 if (f_v) {
329 cout << "\n";
330 //print_integer_matrix(cout, gen.S, 1, len);
331 Int_vec_print_integer_matrix(cout, M1, len, n);
332 }
333
334
336 FALSE /* f_special */,
337 FALSE /* f_complete */,
338 base_cols,
339 FALSE /* f_P */, NULL,
340 len /* m */, n /* n */, 0 /* Pn */,
341 0 /* verbose_level */);
342
343 return rk;
344}
345
346
347}}}
348
349
int check_rank_matrix_input(int len, long int *S, int dim_S, int verbose_level)
int check_rank_last_two_are_fixed(int len, long int *S, int verbose_level)
int check_rank(int len, long int *S, int verbose_level)
int compute_rank_row_vectors(int len, long int *S, int f_projective, int verbose_level)
void init(field_theory::finite_field *GFq, int m, int n, int d)
void PG_element_unrank_modified(int *v, int stride, int len, int a)
void PG_element_unrank_modified_lint(int *v, int stride, int len, long int a)
various functions related to geometries
Definition: geometry.h:721
void AG_element_unrank(int q, int *v, int stride, int len, long int a)
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)
#define Int_vec_print_integer_matrix(A, B, C, D)
Definition: foundations.h:690
#define MINIMUM(x, y)
Definition: foundations.h:216
#define FREE_int(p)
Definition: foundations.h:640
#define Lint_vec_print(A, B, C)
Definition: foundations.h:686
#define NEW_int(n)
Definition: foundations.h:625
#define TRUE
Definition: foundations.h:231
#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