Orbiter 2022
Combinatorial Objects
domain.cpp
Go to the documentation of this file.
1// domain.cpp
2//
3// Anton Betten
4// 11.06.2000
5// moved from D2 to ORBI Nov 15, 2007
6
8#include "discreta.h"
9
10using namespace std;
11
12
13namespace orbiter {
14namespace layer2_discreta {
15
16#define MAX_DOMAIN_STACK 100
17
19static domain* domain_stack[MAX_DOMAIN_STACK];
20
22{
23 the_type = GFp;
24 the_prime.m_i_i(p);
25 //the_pres = NULL;
26 the_factor_poly = NULL;
27 the_sub_domain = NULL;
28 F = NULL;
29}
30
31
32
34{
35 cout << "domain::domain orbiter finite_field of order " << F->q << endl;
36 domain::F = F;
37 the_type = Orbiter_finite_field;
38 the_prime.m_i_i(F->p);
39 //the_pres = NULL;
40 the_factor_poly = NULL;
41 the_sub_domain = NULL;
42}
43
44domain::domain(unipoly *factor_poly, domain *sub_domain)
45{
46 the_type = GFq;
47 the_factor_poly = factor_poly;
48 the_sub_domain = sub_domain;
49
50 the_prime.m_i_i(0);
51 //the_pres = NULL;
52 F = NULL;
53}
54
55#if 0
56domain::domain(pc_presentation *pres)
57{
58 the_type = PC_GROUP;
59 the_pres = pres;
60
61 the_prime.m_i_i(0);
62 the_factor_poly = NULL;
63 the_sub_domain = NULL;
64}
65#endif
66
68{
69 return the_type;
70}
71
73{
74 return F;
75}
76
78{
80
81 if (the_type == GFp)
82 return the_prime.s_i_i();
83 if (the_type == GFq) {
84 int q = the_sub_domain->order_int();
85 int f = the_factor_poly->degree();
86 int Q = NT.i_power_j(q, f);
87 return Q;
88 }
89 if (the_type == Orbiter_finite_field) {
90 return F->q;
91 }
92 cout << "domain::order_int no finite field domain" << endl;
93 exit(1);
94}
95
97{
98 if (the_type == GFp)
99 return the_prime.s_i_i();
100 if (the_type == GFq) {
101 int q = the_sub_domain->order_int();
102 return q;
103 }
104 if (the_type == Orbiter_finite_field) {
105 return F->p;
106 }
107 cout << "domain::order_subfield_int no finite field domain" << endl;
108 exit(1);
109}
110
112{
113 if (the_type == GFp)
114 return the_prime.s_i_i();
115 if (the_type == GFq) {
116 return the_sub_domain->characteristic();
117 }
118 if (the_type == Orbiter_finite_field) {
119 return F->p;
120 }
121 cout << "domain::characteristic() no finite field domain" << endl;
122 exit(1);
123}
124
126{
127 if (type() == Orbiter_finite_field) {
128 return TRUE;
129 }
130 return FALSE;
131}
132
133#if 0
134pc_presentation *domain::pres()
135{
136 return the_pres;
137}
138#endif
139
141{
142 return the_factor_poly;
143}
144
146{
147 return the_sub_domain;
148}
149
151{
153 cout << "push_domain() overflow in domain stack" << endl;
154 exit(1);
155 }
156 domain_stack[domain_stack_len++] = d;
157}
158
159
161{
162 if (domain_stack_len == 0) {
163 cout << "push_domain() ounderflow in domain stack" << endl;
164 exit(1);
165 }
166 d = domain_stack[--domain_stack_len];
167}
168
169
170
172{
173 if (domain_stack_len > 0)
174 return TRUE;
175 else
176 return FALSE;
177}
178
180{
181 if (domain_stack_len <= 0) {
182 cout << "get_current_domain() domain stack empty" << endl;
183 exit(1);
184 }
185 return domain_stack[domain_stack_len - 1];
186 //return dom;
187}
188
189#if 0
190domain *get_domain_if_pc_group()
191{
192 if (!has_domain())
193 return NULL;
194
195 domain *d = get_current_domain();
196 if (d->type() == PC_GROUP) {
197 return d;
198 }
199 return NULL;
200}
201#endif
202
204{
205 if (!has_domain())
206 return FALSE;
207
208 d = get_current_domain();
209 if (d->type() == GFp) {
210 return TRUE;
211 }
212 d = NULL;
213 return FALSE;
214}
215
217{
218 if (!has_domain())
219 return FALSE;
220
221 d = get_current_domain();
222 if (d->type() == GFq) {
223 return TRUE;
224 }
225 d = NULL;
226 return FALSE;
227}
228
230{
231 if (!has_domain())
232 return FALSE;
233
234 d = get_current_domain();
235 if (d->type() == Orbiter_finite_field) {
236 return TRUE;
237 }
238 d = NULL;
239 return FALSE;
240}
241
243{
244 if (is_GFp_domain(d))
245 return TRUE;
246 if (is_GFq_domain(d))
247 return TRUE;
248 return FALSE;
249}
250
252{
253 if (is_GFp_domain(d)) {
254 return d->order_int();
255 }
256 if (is_GFq_domain(d)) {
257 return d->order_int();
258 }
259 cout << "finite_field_domain_order_int(): error: must be GFp or GFq" << endl;
260 exit(1);
261}
262
264{
265 if (is_GFp_domain(d)) {
266 return d->characteristic();
267 }
268 if (is_GFq_domain(d)) {
269 return d->characteristic();
270 }
271 cout << "finite_field_domain_characteristic(): error: must be GFp or GFq" << endl;
272 exit(1);
273}
274
276{
277 domain *d;
278 int q;
280
281 if (!is_finite_field_domain(d)) {
282 cout << "finite_field_domain_primitive_root() no finite field domain" << endl;
283 exit(1);
284 }
286 if (is_GFp_domain(d)) {
287 return NT.primitive_root(q, FALSE /* f_v */);
288 }
289 else {
290 integer a;
291 int i, o;
292
293 cout << "finite_field_domain_primitive_root():" << endl;
294 for (i = 1; i < q; i++) {
295 a.m_i((int) i);
296 o = a.order();
297 cout << "order of " << i << " is " << o << endl;
298 if (o == q - 1) {
299 return i;
300 }
301 }
302 cout << "finite_field_domain_primitive_root "
303 "couldn't find primitive root!" << endl;
304 exit(1);
305 // int p, f;
306 // factor_prime_power(q, &p, &f);
307
308 // return p;
309 }
310}
311
313{
314 domain *d, *sd;
315 int q, f, a, i;
317
318 if (!is_finite_field_domain(d)) {
319 cout << "finite_field_domain_base_over_subfield "
320 "no finite field domain" << endl;
321 exit(1);
322 }
323 //qq = finite_field_domain_order_int(d);
324 if (is_GFp_domain(d)) {
325 b.m_l(1);
326 b.m_ii(0, 1);
327 return;
328 }
329 else if (is_GFq_domain(d)) {
330 sd = d->sub_domain();
331 unipoly *m = d->factor_poly();
332 f = m->degree();
333 q = sd->order_int();
334 b.m_l(f);
335 for (i = 0; i < f; i++) {
336 a = NT.i_power_j(q, i);
337 b.m_ii(i, a);
338 }
339 }
340}
341
343{
344 if (d == NULL) {
345 cout << "with::with() trying to push NULL pointer domain" << endl;
346 exit(1);
347 }
348 push_domain(d);
349}
350
352{
353 domain *d;
354 pop_domain(d);
355}
356
357#if 1
358// used in a5_in_PSL
359
360typedef struct ff_memory FF_MEMORY;
361
363
364
365struct ff_memory {
366 int q, p, f;
371};
372
373#define MAX_FF_DOMAIN 100
374
375static int nb_ffm = 0;
376static FF_MEMORY *Ffm[MAX_FF_DOMAIN];
377
378domain *allocate_finite_field_domain(int q, int verbose_level)
379{
380 int f_v = (verbose_level >= 1);
381 FF_MEMORY *ffm = new FF_MEMORY;
382 int p, f;
384
385 if (nb_ffm >= MAX_FF_DOMAIN) {
386 cout << "allocate_finite_field_domain() too many finite field domains" << endl;
387 exit(1);
388 }
389 ffm->q = q;
390 NT.factor_prime_power(q, p, f);
391 ffm->p = p;
392 ffm->f = f;
393 if (f_v) {
394 cout << "allocate_finite_field_domain() q=" << q << ", p=" << ffm->p << ", f=" << ffm->f << endl;
395 }
396 ffm->d1 = new domain(ffm->p);
397
398 if (ffm->f > 1) {
399 with w(ffm->d1);
401 ffm->m->Singer(ffm->p, ffm->f, verbose_level - 2);
402 if (f_v ) {
403 cout << "q=" << q << "=" << ffm->p << "^" << ffm->f << ", m=" << *ffm->m << endl;
404 }
405 ffm->d2 = new domain(ffm->m, ffm->d1);
406 ffm->dom = ffm->d2;
407 }
408 else {
409 ffm->dom = ffm->d1;
410 }
411 Ffm[nb_ffm++] = ffm;
412 return ffm->dom;
413}
414
416{
417 int i;
418
419 for (i = 0; i < nb_ffm; i++) {
420 if (Ffm[i]->dom == dom) {
421 if (FALSE) {
422 cout << "deleting ff domain no " << i << endl;
423 }
424 if (Ffm[i]->f > 1) {
425 delete Ffm[i]->d2;
426 freeobject(Ffm[i]->m);
427 delete Ffm[i]->d1;
428 }
429 else {
430 delete Ffm[i]->d1;
431 }
432 delete Ffm[i];
433 for ( ; i < nb_ffm - 1; i++) {
434 Ffm[i] = Ffm[i + 1];
435 }
436 nb_ffm--;
437 return;
438 }
439 }
440 cout << "free_finite_field_domain() error: domain not found" << endl;
441 exit(1);
442}
443#endif
444
445
446
447}}
DISCRETA vector class for vectors of DISCRETA objects.
Definition: discreta.h:797
void m_ii(int i, int a)
Definition: discreta.h:824
DISCRETA class for influencing arithmetic operations.
Definition: discreta.h:1360
layer1_foundations::field_theory::finite_field * get_F()
Definition: domain.cpp:72
DISCRETA integer class.
Definition: discreta.h:667
DISCRETA class for polynomials in one variable.
Definition: discreta.h:1236
void Singer(int p, int f, int verbose_level)
Definition: unipoly.cpp:564
DISCRETA class related to class domain.
Definition: discreta.h:1413
#define MAX_FF_DOMAIN
Definition: domain.cpp:373
#define MAX_DOMAIN_STACK
Definition: domain.cpp:16
#define TRUE
Definition: foundations.h:231
#define FALSE
Definition: foundations.h:234
int is_Orbiter_finite_field_domain(domain *&d)
Definition: domain.cpp:229
domain * allocate_finite_field_domain(int q, int verbose_level)
Definition: domain.cpp:378
void freeobject(discreta_base *p)
Definition: global.cpp:89
discreta_base * callocobject(kind k)
Definition: global.cpp:81
int finite_field_domain_primitive_root()
Definition: domain.cpp:275
domain * get_current_domain()
Definition: domain.cpp:179
int finite_field_domain_characteristic(domain *d)
Definition: domain.cpp:263
int is_finite_field_domain(domain *&d)
Definition: domain.cpp:242
int is_GFq_domain(domain *&d)
Definition: domain.cpp:216
void finite_field_domain_base_over_subfield(Vector &b)
Definition: domain.cpp:312
void free_finite_field_domain(domain *dom)
Definition: domain.cpp:415
void pop_domain(domain *&d)
Definition: domain.cpp:160
int is_GFp_domain(domain *&d)
Definition: domain.cpp:203
int finite_field_domain_order_int(domain *d)
Definition: domain.cpp:251
void push_domain(domain *d)
Definition: domain.cpp:150
struct ff_memory FF_MEMORY
Definition: domain.cpp:360
the orbiter library for the classification of combinatorial objects
DISCRETA auxilliary class for class domain.
Definition: domain.cpp:365