Orbiter 2022
Combinatorial Objects
vector_space.cpp
Go to the documentation of this file.
1// vector_space.cpp
2//
3// Anton Betten
4//
5// started: December 2, 2018
6
7
8
9
10#include "foundations.h"
11
12
13using namespace std;
14
15
16namespace orbiter {
17namespace layer1_foundations {
18namespace algebra {
19
20
21static void vector_space_unrank_point_callback(int *v, long int rk, void *data);
22static long int vector_space_rank_point_callback(int *v, void *data);
23
24
26{
27 null();
28}
29
31{
32 freeself();
33}
34
36{
37 dimension = 0;
38 F = NULL;
39
40 rank_point_func = NULL;
41 unrank_point_func = NULL;
42 rank_point_data = NULL;
43 v1 = NULL;
44 base_cols = NULL;
45 base_cols2 = NULL;
46 M1 = NULL;
47 M2 = NULL;
48}
49
51{
52 if (v1) {
53 FREE_int(v1);
54 }
55 if (base_cols) {
57 }
58 if (base_cols2) {
60 }
61 if (M1) {
62 FREE_int(M1);
63 }
64 if (M2) {
65 FREE_int(M2);
66 }
67}
68
70 int verbose_level)
71{
72 int f_v = (verbose_level >= 1);
73
74 if (f_v) {
75 cout << "vector_space::init q=" << F->q
76 << " dimension=" << dimension << endl;
77 }
83 rank_point_func = vector_space_rank_point_callback;
84 unrank_point_func = vector_space_unrank_point_callback;
85 rank_point_data = this;
88 if (f_v) {
89 cout << "vector_space::init done" << endl;
90 }
91}
92
94 long int (*rank_point_func)(int *v, void *data),
95 void (*unrank_point_func)(int *v, long int rk, void *data),
96 void *data,
97 int verbose_level)
98{
99 int f_v = (verbose_level >= 1);
100
101 if (f_v) {
102 cout << "vector_space::init_rank_functions" << endl;
103 }
107 if (f_v) {
108 cout << "vector_space::init_rank_functions done" << endl;
109 }
110}
111
112void vector_space::unrank_basis(int *Mtx, long int *set, int len)
113{
114 int i;
115
116 for (i = 0; i < len; i++) {
117 unrank_point(Mtx + i * dimension, set[i]);
118 }
119}
120
121void vector_space::rank_basis(int *Mtx, long int *set, int len)
122{
123 int i;
124
125 for (i = 0; i < len; i++) {
126 set[i] = rank_point(Mtx + i * dimension);
127 }
128}
129
130void vector_space::unrank_point(int *v, long int rk)
131{
132 if (unrank_point_func) {
133 (*unrank_point_func)(v, rk, rank_point_data);
134 }
135 else {
137 }
138}
139
141{
142 long int rk;
143
144 if (rank_point_func) {
145 rk = (*rank_point_func)(v, rank_point_data);
146 }
147 else {
149 }
150 return rk;
151}
152
153
154int vector_space::RREF_and_rank(int *basis, int k)
155{
156 int rk;
157
159 basis, k, dimension,
160 base_cols, 0 /* verbose_level */);
161 return rk;
162}
163
164int vector_space::is_contained_in_subspace(int *v, int *basis, int k)
165{
166 int ret;
167
169 dimension, basis, base_cols,
170 v, 0 /*verbose_level*/);
171 return ret;
172}
173
175 long int *set1, long int *set2, int k, int verbose_level)
176{
177 int f_v = (verbose_level >= 1);
178 int r, i;
179 int rk1, rk2;
180
181 if (f_v) {
182 cout << "vector_space::compare_subspaces_ranked" << endl;
183 }
184#if 0
185 r = F->compare_subspaces_ranked_with_unrank_function(
186 set1, set2, k,
187 dimension,
190 verbose_level);
191#else
192 if (k > dimension) {
193 cout << "vector_space::compare_subspaces_ranked "
194 "k > dimension" << endl;
195 exit(1);
196 }
197 unrank_basis(M1, set1, k);
198 unrank_basis(M2, set2, k);
199 if (f_v) {
200 cout << "matrix1:" << endl;
203 F->log10_of_q);
204 cout << "matrix2:" << endl;
207 F->log10_of_q);
208 }
209 rk1 = F->Linear_algebra->Gauss_simple(M1, k,
211 0/*int verbose_level*/);
212 rk2 = F->Linear_algebra->Gauss_simple(M2, k,
214 0/*int verbose_level*/);
215 if (f_v) {
216 cout << "vector_space::compare_subspaces_ranked "
217 "after Gauss" << endl;
218 cout << "matrix1:" << endl;
221 F->log10_of_q);
222 cout << "rank1=" << rk1 << endl;
223 cout << "base_cols1: ";
224 Int_vec_print(cout, base_cols, rk1);
225 cout << endl;
226 cout << "matrix2:" << endl;
229 F->log10_of_q);
230 cout << "rank2=" << rk2 << endl;
231 cout << "base_cols2: ";
232 Int_vec_print(cout, base_cols2, rk2);
233 cout << endl;
234 }
235 if (rk1 != rk2) {
236 if (f_v) {
237 cout << "vector_space::compare_subspaces_ranked "
238 "the ranks differ, "
239 "so the subspaces are not equal, "
240 "we return 1" << endl;
241 }
242 r = 1;
243 goto ret;
244 }
245 for (i = 0; i < rk1; i++) {
246 if (base_cols[i] != base_cols2[i]) {
247 if (f_v) {
248 cout << "the base_cols differ in entry " << i
249 << ", so the subspaces are not equal, "
250 "we return 1" << endl;
251 }
252 r = 1;
253 goto ret;
254 }
255 }
256 for (i = 0; i < k * dimension; i++) {
257 if (M1[i] != M2[i]) {
258 if (f_v) {
259 cout << "the matrices differ in entry " << i
260 << ", so the subspaces are not equal, "
261 "we return 1" << endl;
262 }
263 r = 1;
264 goto ret;
265 }
266 }
267 if (f_v) {
268 cout << "the subspaces are equal, we return 0" << endl;
269 }
270 r = 0;
271#endif
272 if (f_v) {
273 cout << "vector_space::compare_subspaces_ranked "
274 "done" << endl;
275 }
276ret:
277 return r;
278}
279
280
281// #############################################################################
282// static functions:
283// #############################################################################
284
285
286static void vector_space_unrank_point_callback(int *v, long int rk, void *data)
287{
288 vector_space *VS = (vector_space *) data;
289
290 VS->F->PG_element_unrank_modified_lint(v, 1, VS->dimension, rk);
291
292}
293
294static long int vector_space_rank_point_callback(int *v, void *data)
295{
296 vector_space *VS = (vector_space *) data;
297 long int rk;
298
299 VS->F->PG_element_rank_modified_lint(v, 1, VS->dimension, rk);
300 return rk;
301
302}
303
304}}}
305
306
307
finite dimensional vector space over a finite field
Definition: algebra.h:688
void init(field_theory::finite_field *F, int dimension, int verbose_level)
int compare_subspaces_ranked(long int *set1, long int *set2, int k, int verbose_level)
void rank_basis(int *Mtx, long int *set, int len)
void unrank_basis(int *Mtx, long int *set, int len)
void(* unrank_point_func)(int *v, long int rk, void *data)
Definition: algebra.h:695
int is_contained_in_subspace(int *v, int *basis, int k)
void init_rank_functions(long int(*rank_point_func)(int *v, void *data), void(*unrank_point_func)(int *v, long int rk, void *data), void *data, int verbose_level)
long int(* rank_point_func)(int *v, void *data)
Definition: algebra.h:694
void PG_element_unrank_modified_lint(int *v, int stride, int len, long int a)
void PG_element_rank_modified_lint(int *v, int stride, int len, long int &a)
int is_contained_in_subspace(int k, int len, int *basis, int *base_cols, int *v, int verbose_level)
int Gauss_simple(int *A, int m, int n, int *base_cols, int verbose_level)
#define FREE_int(p)
Definition: foundations.h:640
#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_vec_print(A, B, C)
Definition: foundations.h:685
the orbiter library for the classification of combinatorial objects