Orbiter 2022
Combinatorial Objects
finite_field_io.cpp
Go to the documentation of this file.
1/*
2 * finit_field_io.cpp
3 *
4 * Created on: Jan 5, 2019
5 * Author: betten
6 */
7
8
9#include "foundations.h"
10
11using namespace std;
12
13
14namespace orbiter {
15namespace layer1_foundations {
16namespace field_theory {
17
18
19void finite_field::report(std::ostream &ost, int verbose_level)
20{
21 ost << "\\small" << endl;
22 ost << "\\arraycolsep=2pt" << endl;
23 ost << "\\parindent=0pt" << endl;
24 ost << "$q = " << q << "$\\\\" << endl;
25 ost << "$p = " << p << "$\\\\" << endl;
26 ost << "$e = " << e << "$\\\\" << endl;
27
28 ost << "\\clearpage" << endl << endl;
29 ost << "\\section{The Finite Field with $" << q << "$ Elements}" << endl;
30 cheat_sheet(ost, verbose_level);
31
32
33}
34
35void finite_field::print_minimum_polynomial(int p, std::string &polynomial)
36{
38
39 GFp.finite_field_init(p, FALSE /* f_without_tables */, 0);
40
43
45 FX.create_object_by_rank_string(n, polynomial, 0);
46 {
47 ring_theory::unipoly_domain Fq(&GFp, m, 0 /* verbose_level */);
48
49 Fq.print_object(n, cout);
50 }
51 //cout << "finite_field::print_minimum_polynomial "
52 //"before delete_object" << endl;
53 FX.delete_object(m);
54 FX.delete_object(n);
55}
56
58{
59 cout << "Finite field of order " << q << endl;
60}
61
62void finite_field::print_detailed(int f_add_mult_table)
63{
64 if (f_is_prime_field) {
66 }
67 else {
68 //char *poly;
69
70 //poly = get_primitive_polynomial(p, e, 0 /* verbose_level */);
71
72 cout << "polynomial = ";
74 cout << endl;
75 //cout << " = " << poly << endl;
76
77 if (!f_has_table) {
78 cout << "finite_field::print_detailed !f_has_table" << endl;
79 exit(1);
80 }
82 }
83 if (f_add_mult_table) {
84 if (!f_has_table) {
85 cout << "finite_field::print_detailed !f_has_table" << endl;
86 exit(1);
87 }
88 T->print_add_mult_tables(cout);
90 }
91}
92
93
94
95
97{
98 int i, a, b, c, l;
99
100
101
102 cout << "i : inverse(i) : frobenius_power(i, 1) : alpha_power(i) : "
103 "log_alpha(i)" << endl;
104 for (i = 0; i < q; i++) {
105 if (i)
106 a = inverse(i);
107 else
108 a = -1;
109 if (i)
110 l = log_alpha(i);
111 else
112 l = -1;
113 b = frobenius_power(i, 1);
114 c = alpha_power(i);
115 cout << setw(4) << i << " : "
116 << setw(4) << a << " : "
117 << setw(4) << b << " : "
118 << setw(4) << c << " : "
119 << setw(4) << l << endl;
120
121 }
122}
123
124
125void finite_field::display_T2(ostream &ost)
126{
127 int i;
128
129 ost << "i & T2(i)" << endl;
130 for (i = 0; i < q; i++) {
131 ost << setw((int) log10_of_q) << i << " & "
132 << setw((int) log10_of_q) << T2(i) << endl;
133 }
134}
135
136void finite_field::display_T3(ostream &ost)
137{
138 int i;
139
140 ost << "i & T3(i)" << endl;
141 for (i = 0; i < q; i++) {
142 ost << setw((int) log10_of_q) << i << " & "
143 << setw((int) log10_of_q) << T3(i) << endl;
144 }
145}
146
147void finite_field::display_N2(ostream &ost)
148{
149 int i;
150
151 ost << "i & N2(i)" << endl;
152 for (i = 0; i < q; i++) {
153 ost << setw((int) log10_of_q) << i << " & "
154 << setw((int) log10_of_q) << N2(i) << endl;
155 }
156}
157
158void finite_field::display_N3(ostream &ost)
159{
160 int i;
161
162 ost << "i & N3(i)" << endl;
163 for (i = 0; i < q; i++) {
164 ost << setw((int) log10_of_q) << i << " & "
165 << setw((int) log10_of_q) << N3(i) << endl;
166 }
167}
168
170 int *p, int m, int n)
171{
172 int i, j, a, h;
173 int w;
175
176 w = (int) NT.int_log10(q);
177 for (i = 0; i < m; i++) {
178 for (j = 0; j < n; j++) {
179 a = p[i * n + j];
180 if (a == 0) {
181 for (h = 0; h < w - 1; h++)
182 ost << " ";
183 ost << ". ";
184 }
185 else {
186 a = log_alpha(a);
187 ost << setw(w) << a << " ";
188 }
189 }
190 ost << endl;
191 }
192}
193
194
195
197 int *components, int *embedding, int *pair_embedding)
198{
199 int Q, q, i, j;
200
201 Q = finite_field::q;
202 q = subfield.q;
203 cout << "embedding:" << endl;
204 for (i = 0; i < q; i++) {
205 cout << setw(4) << i << " : " << setw(4) << embedding[i] << endl;
206 }
207 cout << "components:" << endl;
208 for (i = 0; i < Q; i++) {
209 cout << setw(4) << i << setw(4) << components[i * 2 + 0]
210 << setw(4) << components[i * 2 + 1] << endl;
211 }
212 cout << "pair_embeddings:" << endl;
213 for (i = 0; i < q; i++) {
214 for (j = 0; j < q; j++) {
215 cout << setw(4) << i << setw(4) << j << setw(4)
216 << pair_embedding[i * q + j] << endl;
217 }
218 }
219}
220
222 int *components, int *embedding, int *pair_embedding)
223{
224 int q, i, j, a, b, aa, bb, c;
225
226 //Q = finite_field::q;
227 q = subfield.q;
228
229 for (j = 0; j < q; j++) {
230 cout << " & ";
231 subfield.print_element(cout, j);
232 }
233 cout << "\\\\" << endl;
234 cout << "\\hline" << endl;
235 for (i = 0; i < q; i++) {
236 subfield.print_element(cout, i);
237 if (i == 0) {
238 a = 0;
239 }
240 else {
241 a = subfield.alpha_power(i - 1);
242 }
243 aa = embedding[a];
244 for (j = 0; j < q; j++) {
245 if (j == 0) {
246 b = 0;
247 }
248 else {
249 b = subfield.alpha_power(j - 1);
250 }
251 bb = embedding[b];
252 c = add(aa, mult(bb, p));
253 cout << " & ";
254 print_element(cout, c);
255 }
256 cout << "\\\\" << endl;
257 }
258}
259
261{
262 int l;
263
264 if (p == 2) {
265 cout << "finite_field::print_indicator_square_nonsquare "
266 "the characteristic is two" << endl;
267 exit(1);
268 }
269 if (a == 0) {
270 cout << "0";
271 }
272 else {
273 l = log_alpha(a);
274 if (EVEN(l)) {
275 cout << "+";
276 }
277 else {
278 cout << "-";
279 }
280 }
281}
282
283void finite_field::print_element(ostream &ost, int a)
284{
285 int width;
286
287
288 if (e == 1) {
289 ost << a;
290 }
291 else {
293 width = 10;
294 }
295 else {
296 width = log10_of_q;
297 }
299 width, symbol_for_print);
300 }
301}
302
303void finite_field::print_element_str(stringstream &ost, int a)
304{
305 int width;
306
307
308 if (e == 1) {
309 ost << a;
310 }
311 else {
313 width = 10;
314 }
315 else {
316 width = log10_of_q;
317 }
319 width, symbol_for_print);
320 }
321}
322
324 int a, int f_exponential, int width, std::string &symbol)
325{
326 int b;
327
328 if (f_exponential) {
329#if 0
330 if (symbol == NULL) {
331 cout << "finite_field::print_element_with_symbol "
332 "symbol == NULL" << endl;
333 return;
334 }
335#endif
336 if (a == 0) {
337 //print_repeated_character(ost, ' ', width - 1);
338 ost << "0";
339 }
340 else if (a == 1) {
341 //print_repeated_character(ost, ' ', width - 1);
342 ost << "1";
343 }
344 else {
345 b = log_alpha(a);
346 if (b == q - 1) {
347 b = 0;
348 }
349 ost << symbol;
350 if (b > 1) {
351 ost << "^{" << b << "}";
352 }
353 else {
354 ost << " ";
355 }
356 }
357 }
358 else {
359 ost << setw((int) width) << a;
360 }
361}
362
364 int a, int f_exponential, int width, std::string &symbol)
365{
366 int b;
367
368 if (f_exponential) {
369#if 0
370 if (symbol == NULL) {
371 cout << "finite_field::print_element_with_symbol_str "
372 "symbol == NULL" << endl;
373 return;
374 }
375#endif
376 if (a == 0) {
377 //print_repeated_character(ost, ' ', width - 1);
378 ost << "0";
379 }
380 else if (a == 1) {
381 //print_repeated_character(ost, ' ', width - 1);
382 ost << "1";
383 }
384 else {
385 b = log_alpha(a);
386 if (b == q - 1) {
387 b = 0;
388 }
389 ost << symbol;
390 if (b > 1) {
391 ost << "^{" << b << "}";
392 }
393 else {
394 ost << " ";
395 }
396 }
397 }
398 else {
399 ost << setw((int) width) << a;
400 }
401}
402
403void finite_field::int_vec_print_field_elements(ostream &ost, int *v, int len)
404{
405 int i;
406 ost << "(";
407 for (i = 0; i < len; i++) {
408 print_element(ost, v[i]);
409 if (i < len - 1) {
410 ost << ", ";
411 }
412 }
413 ost << ")";
414}
415
417 int *v, int len, std::string &symbol_for_print)
418{
419 int i;
420 ost << "(";
421 for (i = 0; i < len; i++) {
422 if (v[i] >= q) {
423 cout << "finite_field::int_vec_print_elements_exponential v[i] >= q" << endl;
424 cout << "v[i]=" << v[i] << endl;
425 exit(1);
426 }
428 TRUE /*f_print_as_exponentials*/,
429 10 /*width*/, symbol_for_print);
430 if (i < len - 1) {
431 ost << ", ";
432 }
433 }
434 ost << ")";
435}
436
438{
439 char str[1000];
440
441 sprintf(str, "GF_q%d", q);
442 fname.assign(str);
443 fname.append("_addition_table.csv");
444}
445
447{
448 char str[1000];
449
450 sprintf(str, "GF_q%d", q);
451 fname.assign(str);
452 fname.append("_multiplication_table.csv");
453}
454
456{
457 char str[1000];
458
459 sprintf(str, "GF_q%d", q);
460 fname.assign(str);
461 fname.append("_addition_table_reordered.csv");
462}
463
465{
466 char str[1000];
467
468 sprintf(str, "GF_q%d", q);
469 fname.assign(str);
470 fname.append("_multiplication_table_reordered.csv");
471}
472
474{
475 int f_v = (verbose_level >= 1);
476 int i, j, k;
477 int *M;
479
480 M = NEW_int(q * q);
481 for (i = 0; i < q; i++) {
482 for (j = 0; j < q; j++) {
483 k = add(i, j);
484 M[i * q + j] = k;
485 }
486 }
487 std::string fname;
488
490 Fio.int_matrix_write_csv(fname, M, q, q);
491 if (f_v) {
492 cout << "Written file " << fname << " of size " << Fio.file_size(fname) << endl;
493 }
494 FREE_int(M);
495}
496
498{
499 int f_v = (verbose_level >= 1);
500 int i, j, k;
501 int *M;
503
504 M = NEW_int((q - 1) * (q - 1));
505 for (i = 0; i < q - 1; i++) {
506 for (j = 0; j < q - 1; j++) {
507 k = mult(1 + i, 1 + j);
508 M[i * (q - 1) + j] = k;
509 }
510 }
511 std::string fname;
512
514 Fio.int_matrix_write_csv(fname, M, q - 1, q - 1);
515 if (f_v) {
516 cout << "Written file " << fname << " of size " << Fio.file_size(fname) << endl;
517 }
518 FREE_int(M);
519}
520
522{
523
524 if (!f_has_table) {
525 cout << "finite_field::addition_table_reordered_save_csv !f_has_table" << endl;
526 exit(1);
527 }
528
529 std::string fname;
530
532
533 T->addition_table_reordered_save_csv(fname, verbose_level);
534
535}
536
537
539{
540
541 if (!f_has_table) {
542 cout << "finite_field::multiplication_table_reordered_save_csv !f_has_table" << endl;
543 exit(1);
544 }
545
546 std::string fname;
547
549
550 T->multiplication_table_reordered_save_csv(fname, verbose_level);
551
552}
553
554
556 int f_elements_exponential, std::string &symbol_for_print)
557{
558 int i, j, k;
559
560 //f << "\\arraycolsep=1pt" << endl;
561 f << "\\begin{array}{|r|*{" << q << "}{r}|}" << endl;
562 f << "\\hline" << endl;
563 f << "+ ";
564 for (i = 0; i < q; i++) {
565 f << " &";
566 print_element_with_symbol(f, i, f_elements_exponential,
567 10 /* width */,
568 symbol_for_print);
569 }
570 f << "\\\\" << endl;
571 f << "\\hline" << endl;
572 for (i = 0; i < q; i++) {
573 print_element_with_symbol(f, i, f_elements_exponential,
574 10 /* width */,
575 symbol_for_print);
576 for (j = 0; j < q; j++) {
577 k = add(i, j);
578 f << "&";
579 print_element_with_symbol(f, k, f_elements_exponential,
580 10 /* width */,
581 symbol_for_print);
582 }
583 f << "\\\\" << endl;
584 }
585 f << "\\hline" << endl;
586 f << "\\end{array}" << endl;
587}
588
590 int f_elements_exponential, std::string &symbol_for_print)
591{
592 int i, j, k;
593
594 //f << "\\arraycolsep=1pt" << endl;
595 f << "\\begin{array}{|r|*{" << q - 1 << "}{r}|}" << endl;
596 f << "\\hline" << endl;
597 f << "\\cdot ";
598 for (i = 1; i < q; i++) {
599 f << " &";
600 print_element_with_symbol(f, i, f_elements_exponential,
601 10 /* width */,
602 symbol_for_print);
603 }
604 f << "\\\\" << endl;
605 f << "\\hline" << endl;
606 for (i = 1; i < q; i++) {
607 f << setw(3);
608 print_element_with_symbol(f, i, f_elements_exponential,
609 10 /* width */,
610 symbol_for_print);
611 for (j = 1; j < q; j++) {
612 k = mult(i, j);
613 f << "&" << setw(3);
614 print_element_with_symbol(f, k, f_elements_exponential,
615 10 /* width */,
616 symbol_for_print);
617 }
618 f << "\\\\" << endl;
619 }
620 f << "\\hline" << endl;
621 f << "\\end{array}" << endl;
622}
623
624void finite_field::latex_matrix(ostream &f, int f_elements_exponential,
625 std::string &symbol_for_print, int *M, int m, int n)
626{
627 int i, j;
628
629 f << "\\begin{array}{*{" << n << "}{r}}" << endl;
630 for (i = 0; i < m; i++) {
631 for (j = 0; j < n; j++) {
632 f << setw(3);
633 print_element_with_symbol(f, M[i * n + j],
634 f_elements_exponential, 10 /* width */,
635 symbol_for_print);
636 if (j < n - 1) {
637 f << " & ";
638 }
639 }
640 f << "\\\\" << endl;
641 }
642 f << "\\end{array}" << endl;
643}
644
645
647 int *power_table, int len)
648{
649 int i;
650
651 power_table[0] = 1;
652 for (i = 1; i < len; i++) {
653 power_table[i] = mult(power_table[i - 1], t);
654 }
655}
656
657
658void finite_field::cheat_sheet(ostream &f, int verbose_level)
659{
660 int f_v = (verbose_level >= 1);
661
662 if (f_v) {
663 cout << "finite_field::cheat_sheet" << endl;
664 }
665
666 int f_add_mult_table = TRUE;
667
668 if (f_add_mult_table) {
669
670 if (!f_has_table) {
671 cout << "finite_field::cheat_sheet !f_has_table" << endl;
672 exit(1);
673 }
674 if (f_v) {
675 T->print_add_mult_tables(cout);
676 }
678 }
679
680 cheat_sheet_subfields(f, verbose_level);
681
682 cheat_sheet_table_of_elements(f, verbose_level);
683
684 cheat_sheet_main_table(f, verbose_level);
685
686 cheat_sheet_addition_table(f, verbose_level);
687
688 cheat_sheet_multiplication_table(f, verbose_level);
689
690 cheat_sheet_power_table(f, TRUE /* f_with_polynomials */, verbose_level);
691
692 cheat_sheet_power_table(f, FALSE /* f_with_polynomials */, verbose_level);
693
694 if (f_v) {
695 cout << "finite_field::cheat_sheet done" << endl;
696 }
697
698}
699
700void finite_field::cheat_sheet_subfields(ostream &f, int verbose_level)
701{
702 int f_v = (verbose_level >= 1);
703 //const char *symbol_for_print = "\\alpha";
705
706
707 if (f_v) {
708 cout << "finite_field::cheat_sheet_subfields" << endl;
709 }
710
711 //f << "\\small" << endl;
712 if (!f_is_prime_field) {
713 f << "The polynomial used to define the field is : ";
715 GFp.finite_field_init(p, FALSE /* f_without_tables */, 0);
716
719
720
721 FX.create_object_by_rank_string(m, my_poly, verbose_level - 2);
722 f << "$";
723 FX.print_object(m, f);
724 f << "$ = " << my_poly << "\\\\" << endl;
725 }
726
727 f << "$Z_i = \\log_\\alpha (1 + \\alpha^i)$\\\\" << endl;
728
729 if (!f_is_prime_field && !NT.is_prime(e)) {
730 report_subfields(f, verbose_level);
731 }
732 if (!f_is_prime_field) {
733 report_subfields_detailed(f, verbose_level);
734 }
735
736 if (f_v) {
737 cout << "finite_field::cheat_sheet_subfields done" << endl;
738 }
739}
740
741void finite_field::report_subfields(std::ostream &ost, int verbose_level)
742{
743 int f_v = (verbose_level >= 1);
745 int h;
746
747 if (f_v) {
748 cout << "finite_field::report_subfields" << endl;
749 }
750 ost << "\\subsection*{Subfields}" << endl;
751 ost << "$$" << endl;
752 ost << "\\begin{array}{|r|r|r|}" << endl;
753 ost << "\\hline" << endl;
754 ost << "\\mbox{Subfield} & \\mbox{Polynomial} & \\mbox{Numerical Rank} \\\\"
755 << endl;
756 ost << "\\hline" << endl;
757 for (h = 2; h < e; h++) {
758 if ((e % h) == 0) {
759
760
761 ost << "\\hline" << endl;
762 long int poly;
763
765 NT.i_power_j(p, h),
766 FALSE, cout,
767 verbose_level);
768 {
770 GFp.finite_field_init(p, FALSE /* f_without_tables */, 0);
771
774
776 0/*verbose_level*/);
777 ring_theory::unipoly_domain Fq(&GFp, m, 0 /* verbose_level */);
779
780 FX.create_object_by_rank(elt, poly, __FILE__, __LINE__, verbose_level);
781 ost << "\\bbF_{" << NT.i_power_j(p, h) << "} & ";
782 Fq.print_object(elt, ost);
783 ost << " & " << poly;
784 ost << "\\\\" << endl;
785 Fq.delete_object(elt);
786 }
787
788 }
789 }
790 ost << "\\hline" << endl;
791 ost << "\\end{array}" << endl;
792 ost << "$$" << endl;
793 if (f_v) {
794 cout << "finite_field::report_subfields done" << endl;
795 }
796}
797
798void finite_field::report_subfields_detailed(std::ostream &ost, int verbose_level)
799{
800 int f_v = (verbose_level >= 1);
802 int h;
803
804 if (f_v) {
805 cout << "finite_field::report_subfields_detailed" << endl;
806 }
807 ost << "\\subsection*{Subfields in Detail}" << endl;
808 for (h = 1; h < e; h++) {
809 if (e % h) {
810 continue;
811 }
812
813 long int poly_numeric, q0;
814 finite_field *Fq;
815
817
818 q0 = NT.i_power_j(p, h);
819
820 poly_numeric = compute_subfield_polynomial(q0, TRUE, ost, verbose_level);
821
822
823 char str[1000];
824
825 sprintf(str, "%ld", poly_numeric);
826 string poly_text;
827
828 poly_text.assign(str);
829 Fq->init_override_polynomial(q0, poly_text, FALSE /* f_without_tables */, verbose_level);
830
832
834
835 Sub->init(this /* FQ */, Fq, verbose_level);
836
837
838 if (f_v) {
839 ost << "Subfield ${\\mathbb F}_{" << q0 << "}$ generated by polynomial " << poly_numeric << ":\\\\" << endl;
840 Sub->report(ost);
841 }
842
843 FREE_OBJECT(Sub);
844 FREE_OBJECT(Fq);
845 }
846 if (f_v) {
847 cout << "finite_field::report_subfields_detailed done" << endl;
848 }
849}
850
851
852void finite_field::cheat_sheet_addition_table(ostream &f, int verbose_level)
853{
854 int f_v = (verbose_level >= 1);
855
856
857 if (f_v) {
858 cout << "finite_field::cheat_sheet_addition_table" << endl;
859 }
860
861 if (q <= 64) {
862 f << "$$" << endl;
863 latex_addition_table(f, FALSE /* f_elements_exponential */,
864 symbol_for_print);
865#if 0
866 const char *symbol_for_print = "\\alpha";
867 if (q >= 10) {
868 f << "$$" << endl;
869 f << "$$" << endl;
870 }
871 else {
872 f << "\\qquad" << endl;
873 }
874 latex_addition_table(f, TRUE /* f_elements_exponential */,
875 symbol_for_print);
876#endif
877 f << "$$" << endl;
878 }
879 else {
880 f << "Addition table omitted" << endl;
881 }
882
883
884
885 if (f_v) {
886 cout << "finite_field::cheat_sheet_addition_table done" << endl;
887 }
888}
889
890void finite_field::cheat_sheet_multiplication_table(ostream &f, int verbose_level)
891{
892 int f_v = (verbose_level >= 1);
893
894
895 if (f_v) {
896 cout << "finite_field::cheat_sheet_multiplication_table" << endl;
897 }
898
899 if (q <= 64) {
900 f << "$$" << endl;
901 latex_multiplication_table(f, FALSE /* f_elements_exponential */,
902 symbol_for_print);
903#if 0
904 const char *symbol_for_print = "\\alpha";
905 if (q >= 10) {
906 f << "$$" << endl;
907 f << "$$" << endl;
908 }
909 else {
910 f << "\\qquad" << endl;
911 }
912 latex_multiplication_table(f, TRUE /* f_elements_exponential */,
913 symbol_for_print);
914#endif
915 f << "$$" << endl;
916 }
917 else {
918 f << "Multiplication table omitted" << endl;
919 }
920
921
922
923 if (f_v) {
924 cout << "finite_field::cheat_sheet_multiplication_table done" << endl;
925 }
926}
927
928void finite_field::cheat_sheet_power_table(std::ostream &ost, int f_with_polynomials, int verbose_level)
929{
930 int *Powers;
931 int i, j, t;
932 int len = q;
933 int *v;
935
936 t = primitive_root();
937
938 v = NEW_int(e);
939 Powers = NEW_int(len);
940 power_table(t, Powers, len);
941
942 ost << "\\subsection*{Cyclic structure}" << endl;
943
944
945 ost << "$$" << endl;
946 cheat_sheet_power_table_top(ost, f_with_polynomials, verbose_level);
947
948 for (i = 0; i < len; i++) {
949
950 if (i && (i % 32) == 0) {
951 cheat_sheet_power_table_bottom(ost, f_with_polynomials, verbose_level);
952 ost << "$$" << endl;
953 ost << "$$" << endl;
954 cheat_sheet_power_table_top(ost, f_with_polynomials, verbose_level);
955 }
956
957 Gg.AG_element_unrank(p, v, 1, e, Powers[i]);
958
959 ost << i << " & " << t << "^{" << i << "} & " << Powers[i] << " & ";
960 for (j = e - 1; j >= 0; j--) {
961 ost << v[j];
962 }
963
964 if (f_with_polynomials) {
965 ost << " & ";
966
967 print_element_as_polynomial(ost, v, verbose_level);
968 }
969
970
971 ost << "\\\\" << endl;
972 }
973 cheat_sheet_power_table_bottom(ost, f_with_polynomials, verbose_level);
974 ost << "$$" << endl;
975
976 FREE_int(v);
977 FREE_int(Powers);
978
979}
980
981void finite_field::cheat_sheet_power_table_top(std::ostream &ost, int f_with_polynomials, int verbose_level)
982{
983 ost << "\\begin{array}{|r|r|r|r|";
984 if (f_with_polynomials) {
985 ost << "r|";
986 }
987 ost << "}" << endl;
988 ost << "\\hline" << endl;
989
990
991 ost << "i & \\alpha^i & \\alpha^i & \\mbox{vector}";
992 if (f_with_polynomials) {
993 ost << "& \\mbox{reduced rep.}";
994 }
995 ost << "\\\\" << endl;
996 ost << "\\hline" << endl;
997}
998
999void finite_field::cheat_sheet_power_table_bottom(std::ostream &ost, int f_with_polynomials, int verbose_level)
1000{
1001 ost << "\\hline" << endl;
1002 ost << "\\end{array}" << endl;
1003}
1004
1005void finite_field::cheat_sheet_table_of_elements(std::ostream &ost, int verbose_level)
1006{
1007 int *v;
1008 int i, j;
1009 int f_first;
1010 //std::string my_symbol;
1011
1012 v = NEW_int(e);
1013
1014 //my_symbol.assign("\alpha");
1015
1016 ost << "\\subsection*{Table of Elements of ${\\mathbb F}_{" << q << "}$}" << endl;
1017 ost << "$$" << endl;
1018 ost << "\\begin{array}{|r|r|r|}" << endl;
1019 ost << "\\hline" << endl;
1020
1022
1023 for (i = 0; i < q; i++) {
1024 Gg.AG_element_unrank(p, v, 1, e, i);
1025 ost << setw(3) << i;
1026 ost << " & ";
1027 f_first = TRUE;
1028
1029
1030 for (j = e - 1; j >= 0; j--) {
1031 ost << v[j];
1032 }
1033 ost << " & ";
1034
1035 print_element_as_polynomial(ost, v, verbose_level);
1036
1037 ost << "\\\\" << endl;
1038
1039#if 0
1040 ost << " & ";
1042 TRUE /*f_print_as_exponentials*/,
1043 10 /*width*/, my_symbol);
1044#endif
1045 }
1046 ost << "\\hline" << endl;
1047 ost << "\\end{array}" << endl;
1048 ost << "$$" << endl;
1049
1050 FREE_int(v);
1051
1052}
1053
1054void finite_field::print_element_as_polynomial(std::ostream &ost, int *v, int verbose_level)
1055{
1056 int j;
1057 int f_first = TRUE;
1058
1059 for (j = e - 1; j >= 0; j--) {
1060 if (v[j] == 0) {
1061 continue;
1062 }
1063
1064 if (f_first) {
1065 f_first = FALSE;
1066 }
1067 else {
1068 ost << " + ";
1069 }
1070
1071 if (j == 0 || v[j] > 1) {
1072 ost << setw(3) << v[j];
1073 }
1074 if (j) {
1075 ost << "\\alpha";
1076 }
1077 if (j > 1) {
1078 ost << "^{" << j << "}";
1079 }
1080 }
1081 if (f_first) {
1082 ost << "0";
1083 }
1084}
1085
1086void finite_field::cheat_sheet_main_table(std::ostream &f, int verbose_level)
1087{
1088 int *v;
1089 int i, j, a;
1090 int f_first;
1091
1092 v = NEW_int(e);
1093
1094
1095 int nb_cols = 7;
1096
1097 if (e > 1) {
1098 nb_cols += 3;
1099 }
1100 if ((e % 2) == 0 && e > 2) {
1101 nb_cols += 2;
1102 }
1103 if ((e % 3) == 0 && e > 3) {
1104 nb_cols += 2;
1105 }
1106
1107
1108 cheat_sheet_main_table_top(f, nb_cols);
1109
1111
1112 for (i = 0; i < q; i++) {
1113 Gg.AG_element_unrank(p, v, 1, e, i);
1114 f << setw(3) << i << " & ";
1115 f_first = TRUE;
1116 for (j = e - 1; j >= 0; j--) {
1117 if (v[j] == 0) {
1118 continue;
1119 }
1120
1121 if (f_first) {
1122 f_first = FALSE;
1123 }
1124 else {
1125 f << " + ";
1126 }
1127
1128 if (j == 0 || v[j] > 1) {
1129 f << setw(3) << v[j];
1130 }
1131 if (j) {
1132 f << "\\alpha";
1133 }
1134 if (j > 1) {
1135 f << "^{" << j << "}";
1136 }
1137 }
1138 if (f_first) {
1139 f << "0";
1140 }
1141
1142 f << " = ";
1144 TRUE /*f_print_as_exponentials*/,
1145 10 /*width*/, symbol_for_print);
1146
1147
1148
1149 // - gamma_i:
1150 f << " &" << negate(i);
1151 // gamma_i^{-1}:
1152 if (i == 0) {
1153 f << " & \\mbox{DNE}";
1154 }
1155 else {
1156 f << " &" << inverse(i);
1157 }
1158
1159
1160
1161 // log_alpha:
1162 if (i == 0) {
1163 f << " & \\mbox{DNE}";
1164 }
1165 else {
1166 f << " &" << log_alpha(i);
1167 }
1168 // alpha_power:
1169 f << " &" << alpha_power(i);
1170
1171
1172 // Z_i:
1173 a = add(1, alpha_power(i));
1174 if (a == 0) {
1175 f << " & \\mbox{DNE}";
1176 }
1177 else {
1178 f << " &" << log_alpha(a);
1179 }
1180
1181
1182
1183
1184 // additional columns for extension fields:
1185 if (e > 1) {
1186 f << " &" << frobenius_power(i, 1);
1187 f << " &" << absolute_trace(i);
1188 f << " &" << absolute_norm(i);
1189 }
1190
1191 if ((e % 2) == 0 && e > 2) {
1192 f << " &" << T2(i);
1193 f << " &" << N2(i);
1194 }
1195 if ((e % 3) == 0 && e > 3) {
1196 f << " &" << T3(i);
1197 f << " &" << N3(i);
1198 }
1199
1200
1201 f << "\\\\" << endl;
1202
1203 if ((i % 25) == 0 && i) {
1205 cheat_sheet_main_table_top(f, nb_cols);
1206 }
1207 }
1208
1210
1211 FREE_int(v);
1212
1213}
1214
1215void finite_field::cheat_sheet_main_table_top(std::ostream &f, int nb_cols)
1216{
1217 f << "$$" << endl;
1218 f << "\\begin{array}{|*{" << nb_cols << "}{r|}}" << endl;
1219 f << "\\hline" << endl;
1220 f << "i & \\gamma_i ";
1221 f << "& -\\gamma_i";
1222 f << "& \\gamma_i^{-1}";
1223 f << "& \\log_\\alpha(\\gamma_i)";
1224 f << "& \\alpha^i";
1225 f << "& Z_i";
1226 if (e > 1) {
1227 f << "& \\phi(\\gamma_i) ";
1228 f << "& T(\\gamma_i) ";
1229 f << "& N(\\gamma_i) ";
1230 }
1231 if ((e % 2) == 0 && e > 2) {
1232 f << "& T_2(\\gamma_i) ";
1233 f << "& N_2(\\gamma_i) ";
1234 }
1235 if ((e % 3) == 0 && e > 3) {
1236 f << "& T_3(\\gamma_i) ";
1237 f << "& N_3(\\gamma_i) ";
1238 }
1239 f << "\\\\" << endl;
1240 f << "\\hline" << endl;
1241}
1242
1244{
1245 f << "\\hline" << endl;
1246 f << "\\end{array}" << endl;
1247 f << "$$" << endl;
1248}
1249
1250
1252 std::ostream &ost, long int *Pts, int nb_pts, int len)
1253{
1254
1255 ost << "{\\renewcommand*{\\arraystretch}{1.5}" << endl;
1256 ost << "$$" << endl;
1257
1258 display_table_of_projective_points2(ost, Pts, nb_pts, len);
1259
1260 ost << "$$}%" << endl;
1261}
1262
1264 std::ostream &ost, long int *Pts, int nb_pts, int len)
1265{
1266 int i;
1267 int *coords;
1268
1269 coords = NEW_int(len);
1270 ost << "\\begin{array}{|c|c|c|}" << endl;
1271 ost << "\\hline" << endl;
1272 ost << "i & a_i & P_{a_i}\\\\" << endl;
1273 ost << "\\hline" << endl;
1274 ost << "\\hline" << endl;
1275 for (i = 0; i < nb_pts; i++) {
1276 PG_element_unrank_modified_lint(coords, 1, len, Pts[i]);
1277 ost << i << " & " << Pts[i] << " & ";
1278 Int_vec_print(ost, coords, len);
1279 ost << "\\\\" << endl;
1280 if (((i + 1) % 30) == 0) {
1281 ost << "\\hline" << endl;
1282 ost << "\\end{array}" << endl;
1283 ost << "$$}%" << endl;
1284 ost << "$$" << endl;
1285 ost << "\\begin{array}{|c|c|c|}" << endl;
1286 ost << "\\hline" << endl;
1287 ost << "i & a_i & P_{a_i}\\\\" << endl;
1288 ost << "\\hline" << endl;
1289 ost << "\\hline" << endl;
1290 }
1291 }
1292 ost << "\\hline" << endl;
1293 ost << "\\end{array}" << endl;
1294 FREE_int(coords);
1295}
1296
1298 std::ostream &ost, long int *Pts, int nb_pts, int len)
1299{
1300 int i;
1301 int *coords;
1302
1303 coords = NEW_int(len);
1304 ost << "\\begin{array}{|c|}" << endl;
1305 ost << "\\hline" << endl;
1306 ost << "P_i\\\\" << endl;
1307 ost << "\\hline" << endl;
1308 ost << "\\hline" << endl;
1309 for (i = 0; i < nb_pts; i++) {
1310 PG_element_unrank_modified_lint(coords, 1, len, Pts[i]);
1311 Int_vec_print(ost, coords, len);
1312 ost << "\\\\" << endl;
1313 if (((i + 1) % 30) == 0) {
1314 ost << "\\hline" << endl;
1315 ost << "\\end{array}" << endl;
1316 ost << "$$}%" << endl;
1317 ost << "$$" << endl;
1318 ost << "\\begin{array}{|c|}" << endl;
1319 ost << "\\hline" << endl;
1320 ost << "P_i\\\\" << endl;
1321 ost << "\\hline" << endl;
1322 ost << "\\hline" << endl;
1323 }
1324 }
1325 ost << "\\hline" << endl;
1326 ost << "\\end{array}" << endl;
1327 FREE_int(coords);
1328}
1329
1330
1331void finite_field::export_magma(int d, long int *Pts, int nb_pts, std::string &fname)
1332{
1333 string fname2;
1334 int *v;
1335 int h, i, a, b;
1337
1338 v = NEW_int(d);
1339 fname2.assign(fname);
1340 ST.replace_extension_with(fname2, ".magma");
1341
1342 {
1343 ofstream fp(fname2);
1344
1345 fp << "G,I:=PGammaL(" << d << "," << q
1346 << ");F:=GF(" << q << ");" << endl;
1347 fp << "S:={};" << endl;
1348 fp << "a := F.1;" << endl;
1349 for (h = 0; h < nb_pts; h++) {
1350 PG_element_unrank_modified_lint(v, 1, d, Pts[h]);
1351
1353
1354 fp << "Include(~S,Index(I,[";
1355 for (i = 0; i < d; i++) {
1356 a = v[i];
1357 if (a == 0) {
1358 fp << "0";
1359 }
1360 else if (a == 1) {
1361 fp << "1";
1362 }
1363 else {
1364 b = log_alpha(a);
1365 fp << "a^" << b;
1366 }
1367 if (i < d - 1) {
1368 fp << ",";
1369 }
1370 }
1371 fp << "]));" << endl;
1372 }
1373 fp << "Stab := Stabilizer(G,S);" << endl;
1374 fp << "Size(Stab);" << endl;
1375 fp << endl;
1376 }
1378
1379 cout << "Written file " << fname2 << " of size "
1380 << Fio.file_size(fname2) << endl;
1381
1382 FREE_int(v);
1383}
1384
1385void finite_field::export_gap(int d, long int *Pts, int nb_pts, std::string &fname)
1386{
1387 string fname2;
1388 int *v;
1389 int h, i, a, b;
1391
1392 v = NEW_int(d);
1393 fname2.assign(fname);
1394 ST.replace_extension_with(fname2, ".gap");
1395
1396 {
1397 ofstream fp(fname2);
1398
1399 fp << "LoadPackage(\"fining\");" << endl;
1400 fp << "pg := ProjectiveSpace(" << d - 1 << "," << q << ");" << endl;
1401 fp << "S:=[" << endl;
1402 for (h = 0; h < nb_pts; h++) {
1403 PG_element_unrank_modified_lint(v, 1, d, Pts[h]);
1404
1406
1407 fp << "[";
1408 for (i = 0; i < d; i++) {
1409 a = v[i];
1410 if (a == 0) {
1411 fp << "0*Z(" << q << ")";
1412 }
1413 else if (a == 1) {
1414 fp << "Z(" << q << ")^0";
1415 }
1416 else {
1417 b = log_alpha(a);
1418 fp << "Z(" << q << ")^" << b;
1419 }
1420 if (i < d - 1) {
1421 fp << ",";
1422 }
1423 }
1424 fp << "]";
1425 if (h < nb_pts - 1) {
1426 fp << ",";
1427 }
1428 fp << endl;
1429 }
1430 fp << "];" << endl;
1431 fp << "S := List(S,x -> VectorSpaceToElement(pg,x));" << endl;
1432 fp << "g := CollineationGroup(pg);" << endl;
1433 fp << "stab := Stabilizer(g,Set(S),OnSets);" << endl;
1434 fp << "Size(stab);" << endl;
1435 }
1437
1438 cout << "Written file " << fname2 << " of size "
1439 << Fio.file_size(fname2) << endl;
1440
1441#if 0
1442LoadPackage("fining");
1443pg := ProjectiveSpace(2,4);
1444#points := Points(pg);
1445#pointslist := AsList(points);
1446#Display(pointslist[1]);
1447frame := [[1,0,0],[0,1,0],[0,0,1],[1,1,1]]*Z(2)^0;
1448frame := List(frame,x -> VectorSpaceToElement(pg,x));
1449pairs := Combinations(frame,2);
1450secants := List(pairs,p -> Span(p[1],p[2]));
1451leftover := Filtered(pointslist,t->not ForAny(secants,s->t in s));
1452hyperoval := Union(frame,leftover);
1453g := CollineationGroup(pg);
1454stab := Stabilizer(g,Set(hyperoval),OnSets);
1455StructureDescription(stab);
1456#endif
1457
1458
1459 FREE_int(v);
1460}
1461
1462void finite_field::print_matrix_latex(std::ostream &ost, int *A, int m, int n)
1463{
1464 int i, j, a;
1465
1466 ost << "\\left[" << endl;
1467 ost << "\\begin{array}{*{" << n << "}{r}}" << endl;
1468 for (i = 0; i < m; i++) {
1469 for (j = 0; j < n; j++) {
1470 a = A[i * n + j];
1471
1472#if 0
1473 if (is_prime(GFq->q)) {
1474 ost << setw(w) << a << " ";
1475 }
1476 else {
1477 ost << a;
1478 // GFq->print_element(ost, a);
1479 }
1480#else
1481 print_element(ost, a);
1482#endif
1483
1484 if (j < n - 1)
1485 ost << " & ";
1486 }
1487 ost << "\\\\" << endl;
1488 }
1489 ost << "\\end{array}" << endl;
1490 ost << "\\right]" << endl;
1491
1492}
1493
1494void finite_field::print_matrix_numerical_latex(std::ostream &ost, int *A, int m, int n)
1495{
1496 int i, j, a;
1497
1498 ost << "\\left[" << endl;
1499 ost << "\\begin{array}{*{" << n << "}{r}}" << endl;
1500 for (i = 0; i < m; i++) {
1501 for (j = 0; j < n; j++) {
1502 a = A[i * n + j];
1503
1504
1505 ost << a;
1506 if (j < n - 1)
1507 ost << " & ";
1508 }
1509 ost << "\\\\" << endl;
1510 }
1511 ost << "\\end{array}" << endl;
1512 ost << "\\right]" << endl;
1513
1514}
1515
1516
1517
1518}}}
1519
1520
1521
functions related to strings and character arrays
void replace_extension_with(char *p, const char *new_ext)
void cheat_sheet_power_table_top(std::ostream &ost, int f_with_polynomials, int verbose_level)
void print_element_with_symbol_str(std::stringstream &ost, int a, int f_exponential, int width, std::string &symbol)
void cheat_sheet_main_table(std::ostream &f, int verbose_level)
void export_gap(int d, long int *Pts, int nb_pts, std::string &fname)
void cheat_sheet_power_table(std::ostream &f, int f_with_polynomials, int verbose_level)
void cheat_sheet_addition_table(std::ostream &f, int verbose_level)
void cheat_sheet_table_of_elements(std::ostream &ost, int verbose_level)
void print_minimum_polynomial(int p, std::string &polynomial)
void print_matrix_latex(std::ostream &ost, int *A, int m, int n)
void report_subfields(std::ostream &f, int verbose_level)
void export_magma(int d, long int *Pts, int nb_pts, std::string &fname)
void print_embedding_tex(finite_field &subfield, int *components, int *embedding, int *pair_embedding)
void report_subfields_detailed(std::ostream &ost, int verbose_level)
void cheat_sheet_power_table_bottom(std::ostream &ost, int f_with_polynomials, int verbose_level)
void print_element_with_symbol(std::ostream &ost, int a, int f_exponential, int width, std::string &symbol)
void print_matrix_numerical_latex(std::ostream &ost, int *A, int m, int n)
void cheat_sheet(std::ostream &f, int verbose_level)
void display_table_of_projective_points(std::ostream &ost, long int *Pts, int nb_pts, int len)
void latex_addition_table(std::ostream &f, int f_elements_exponential, std::string &symbol_for_print)
void display_table_of_projective_points_easy(std::ostream &ost, long int *Pts, int nb_pts, int len)
void int_vec_print_elements_exponential(std::ostream &ost, int *v, int len, std::string &symbol_for_print)
void display_table_of_projective_points2(std::ostream &ost, long int *Pts, int nb_pts, int len)
void print_element_str(std::stringstream &ost, int a)
void report(std::ostream &ost, int verbose_level)
void init_override_polynomial(int q, std::string &poly, int f_without_tables, int verbose_level)
void PG_element_unrank_modified_lint(int *v, int stride, int len, long int a)
void int_vec_print_field_elements(std::ostream &ost, int *v, int len)
void cheat_sheet_main_table_top(std::ostream &f, int nb_cols)
void latex_matrix(std::ostream &f, int f_elements_exponential, std::string &symbol_for_print, int *M, int m, int n)
void cheat_sheet_subfields(std::ostream &f, int verbose_level)
void print_embedding(finite_field &subfield, int *components, int *embedding, int *pair_embedding)
void cheat_sheet_multiplication_table(std::ostream &f, int verbose_level)
void latex_multiplication_table(std::ostream &f, int f_elements_exponential, std::string &symbol_for_print)
void print_integer_matrix_zech(std::ostream &ost, int *p, int m, int n)
long int compute_subfield_polynomial(int order_subfield, int f_latex, std::ostream &ost, int verbose_level)
void power_table(int t, int *power_table, int len)
void print_element_as_polynomial(std::ostream &ost, int *v, int verbose_level)
a finite field as a vector space over a subfield
void init(finite_field *FQ, finite_field *Fq, 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)
void int_matrix_write_csv(std::string &fname, int *M, int m, int n)
Definition: file_io.cpp:1300
domain of polynomials in one variable over a finite field
Definition: ring_theory.h:691
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 print_object(unipoly_object p, std::ostream &ost)
#define FREE_int(p)
Definition: foundations.h:640
#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 TRUE
Definition: foundations.h:231
#define FALSE
Definition: foundations.h:234
#define EVEN(x)
Definition: foundations.h:221
#define Int_vec_print(A, B, C)
Definition: foundations.h:685
the orbiter library for the classification of combinatorial objects