Orbiter 2022
Combinatorial Objects
finite_field_implementation_wo_tables.cpp
Go to the documentation of this file.
1/*
2 * finite_field_implementation_wo_tables.cpp
3 *
4 * Created on: Sep 6, 2021
5 * Author: betten
6 */
7
8
9
10
11
12
13#include "foundations.h"
14
15using namespace std;
16
17
18
19namespace orbiter {
20namespace layer1_foundations {
21namespace field_theory {
22
23
24
26{
27 F = NULL;
28 v1 = v2 = v3 = NULL;
29 GFp = NULL;
30 FX = NULL;
31 m = NULL;
32 factor_polynomial_degree = 0;
33 factor_polynomial_coefficients_negated = NULL;
34 Fq = NULL;
35 Alpha = NULL;
36}
37
39{
40 if (v1) {
41 FREE_int(v1);
42 }
43 if (v2) {
44 FREE_int(v2);
45 }
46 if (v3) {
47 FREE_int(v3);
48 }
49 if (factor_polynomial_coefficients_negated) {
50 FREE_int(factor_polynomial_coefficients_negated);
51 }
52}
53
55{
56 int f_v = (verbose_level >= 1);
57
58 if (f_v) {
59 cout << "finite_field_implementation_wo_tables::init" << endl;
60 }
61
62 finite_field_implementation_wo_tables::F = F;
63
64
65 v1 = NEW_int(F->e);
66 v2 = NEW_int(F->e);
67 v3 = NEW_int(F->e);
68
69
71
72 if (f_v) {
73 cout << "finite_field_implementation_wo_tables::init before GFp->finite_field_init" << endl;
74 }
75 GFp->finite_field_init(F->p, FALSE /* f_without_tables */, 0);
76 if (f_v) {
77 cout << "finite_field_implementation_wo_tables::init after GFp->finite_field_init" << endl;
78 }
79
80
82
83
84 if (f_v) {
85 cout << "finite_field_implementation_wo_tables::init before FX->create_object_by_rank_string" << endl;
86 }
87 FX->create_object_by_rank_string(m, F->my_poly, 0 /*verbose_level - 2*/);
88 if (f_v) {
89 cout << "finite_field_implementation_wo_tables::init m=";
90 FX->print_object(m, cout);
91 cout << endl;
92 }
93
95
96 if (f_v) {
97 cout << "finite_field_implementation_wo_tables::init before Fq->init_factorring" << endl;
98 }
99 Fq->init_factorring(GFp, m, verbose_level - 1);
100 if (f_v) {
101 cout << "finite_field_implementation_wo_tables::init after Fq->init_factorring" << endl;
102 }
103
104 int i;
105
106 factor_polynomial_degree = Fq->degree(m);
107 factor_polynomial_coefficients_negated = NEW_int(factor_polynomial_degree + 1);
108 for (i = 0; i <= factor_polynomial_degree; i++) {
109 factor_polynomial_coefficients_negated[i] = F->negate(Fq->s_i(m, i));
110 }
111
112
113 if (f_v) {
114 cout << "finite_field_implementation_wo_tables::init before Fq->create_object_by_rank" << endl;
115 }
116 Fq->create_object_by_rank(Alpha, F->alpha, __FILE__, __LINE__, 0 /*verbose_level - 2*/);
117 if (f_v) {
118 cout << "finite_field_implementation_wo_tables::init after Fq->create_object_by_rank" << endl;
119 }
120
121
122 if (f_v) {
123 cout << "finite_field_implementation_wo_tables::init done" << endl;
124 }
125}
126
127int finite_field_implementation_wo_tables::mult(int i, int j, int verbose_level)
128{
129 int f_v = (verbose_level >= 1);
130
131 if (f_v) {
132 cout << "finite_field_implementation_wo_tables::mult" << endl;
133 }
134
136 int k;
137
138 Fq->create_object_by_rank(a, i, __FILE__, __LINE__, 0 /*verbose_level - 2*/);
139 Fq->create_object_by_rank(b, j, __FILE__, __LINE__, 0 /*verbose_level - 2*/);
140 Fq->create_object_of_degree_no_test(c, factor_polynomial_degree);
141
142 if (f_v) {
143 cout << "a=" << endl;
144 Fq->print_object(a, cout);
145 cout << endl;
146 cout << "b=" << endl;
147 Fq->print_object(b, cout);
148 cout << endl;
149 cout << "finite_field_implementation_wo_tables::mult before Fq->mult_mod_negated" << endl;
150 }
151
152 Fq->mult_mod_negated(a, b, c,
153 factor_polynomial_degree,
154 factor_polynomial_coefficients_negated,
155 verbose_level);
156
157 if (f_v) {
158 cout << "finite_field_implementation_wo_tables::mult after Fq->mult_mod_negated" << endl;
159 }
160
161 k = Fq->rank(c);
162 if (f_v) {
163 cout << "c=" << endl;
164 Fq->print_object(c, cout);
165 cout << endl;
166 cout << "i=" << i << ", j=" << j << " k=" << k << endl;
167 }
168
169 Fq->delete_object(a);
170 Fq->delete_object(b);
171 Fq->delete_object(c);
172 if (f_v) {
173 cout << "finite_field_implementation_wo_tables::mult done" << endl;
174 }
175 return k;
176}
177
179{
180 int f_v = (verbose_level >= 1);
181
182 if (f_v) {
183 cout << "finite_field_implementation_wo_tables::inverse" << endl;
184 }
185
187 int k;
188
189 Fq->create_object_by_rank(a, i, __FILE__, __LINE__, 0 /*verbose_level - 2*/);
190 Fq->create_object_of_degree_no_test(u, factor_polynomial_degree);
191 Fq->create_object_of_degree_no_test(v, factor_polynomial_degree);
192 Fq->create_object_of_degree_no_test(g, factor_polynomial_degree);
193
194 if (f_v) {
195 cout << "a=" << endl;
196 Fq->print_object(a, cout);
197 cout << endl;
198 cout << "finite_field_implementation_wo_tables::inverse before Fq->extended_gcd" << endl;
199 }
200
201 Fq->extended_gcd(m, a, u, v, g, verbose_level);
202
203 if (f_v) {
204 cout << "finite_field_implementation_wo_tables::inverse after Fq->extended_gcd" << endl;
205 }
206
207 k = Fq->rank(v);
208 if (f_v) {
209 cout << "v=" << endl;
210 Fq->print_object(v, cout);
211 cout << endl;
212 cout << "i=" << i << ", k=" << k << endl;
213 }
214
215 Fq->delete_object(a);
216 Fq->delete_object(u);
217 Fq->delete_object(v);
218 Fq->delete_object(g);
219 if (f_v) {
220 cout << "finite_field_implementation_wo_tables::inverse done" << endl;
221 }
222 return k;
223}
224
226{
227 int f_v = (verbose_level >= 1);
228
229 if (f_v) {
230 cout << "finite_field_implementation_wo_tables::negate" << endl;
231 }
232
234
235 if (i < 0 || i >= F->q) {
236 cout << "finite_field_implementation_wo_tables::negate out of range, i = " << i << endl;
237 exit(1);
238 }
239 long int l, k;
240
241 Gg.AG_element_unrank(F->p, v1, 1, F->e, i);
242 for (l = 0; l < F->e; l++) {
243 v2[l] = (F->p - v1[l]) % F->p;
244 }
245 k = Gg.AG_element_rank(F->p, v2, 1, F->e);
246
247 if (f_v) {
248 cout << "finite_field_implementation_wo_tables::negate done" << endl;
249 }
250 return k;
251}
252
253int finite_field_implementation_wo_tables::add(int i, int j, int verbose_level)
254{
255 int f_v = (verbose_level >= 1);
256
257 if (f_v) {
258 cout << "finite_field_implementation_wo_tables::add" << endl;
259 }
260
262
263 if (i < 0 || i >= F->q) {
264 cout << "finite_field_implementation_wo_tables::add out of range, i = " << i << endl;
265 exit(1);
266 }
267 if (j < 0 || j >= F->q) {
268 cout << "finite_field_implementation_wo_tables::add out of range, j = " << j << endl;
269 exit(1);
270 }
271 long int l, k;
272
273 Gg.AG_element_unrank(F->p, v1, 1, F->e, i);
274 Gg.AG_element_unrank(F->p, v2, 1, F->e, j);
275 for (l = 0; l < F->e; l++) {
276 v3[l] = (v1[l] + v2[l]) % F->p;
277 }
278 k = Gg.AG_element_rank(F->p, v3, 1, F->e);
279
280 if (f_v) {
281 cout << "finite_field_implementation_wo_tables::add done" << endl;
282 }
283 return k;
284}
285
286
287
288}}}
289
290
291
292
void finite_field_init(int q, int f_without_tables, int verbose_level)
various functions related to geometries
Definition: geometry.h:721
void AG_element_unrank(int q, int *v, int stride, int len, long int a)
long int AG_element_rank(int q, int *v, int stride, int len)
domain of polynomials in one variable over a finite field
Definition: ring_theory.h:691
void mult_mod_negated(unipoly_object a, unipoly_object b, unipoly_object &c, int factor_polynomial_degree, int *factor_polynomial_coefficients_negated, int verbose_level)
void extended_gcd(unipoly_object m, unipoly_object n, unipoly_object &u, unipoly_object &v, unipoly_object &g, int verbose_level)
void create_object_by_rank(unipoly_object &p, long int rk, const char *file, int line, int verbose_level)
void create_object_by_rank_string(unipoly_object &p, std::string &rk, int verbose_level)
void create_object_of_degree_no_test(unipoly_object &p, int d)
void print_object(unipoly_object p, std::ostream &ost)
void init_factorring(field_theory::finite_field *F, unipoly_object m, int verbose_level)
#define FREE_int(p)
Definition: foundations.h:640
#define NEW_OBJECT(type)
Definition: foundations.h:638
#define NEW_int(n)
Definition: foundations.h:625
#define FALSE
Definition: foundations.h:234
the orbiter library for the classification of combinatorial objects