Orbiter 2022
Combinatorial Objects
coding_theory_domain.cpp
Go to the documentation of this file.
1/*
2 * coding_theory_domain.cpp
3 *
4 * Created on: Apr 21, 2019
5 * Author: betten
6 */
7
8
9#include "foundations.h"
10
11using namespace std;
12
13
14
15namespace orbiter {
16namespace layer1_foundations {
17namespace coding_theory {
18
19
21{
22
23}
24
26{
27
28}
29
30
31
32
33
34
35
37 int n, int k, int q, int verbose_level)
38{
39 int f_v = (verbose_level >= 1);
40 int i, j;
42
43 if (f_v) {
44 cout << "coding_theory_domain::make_mac_williams_equations" << endl;
45 }
46 M = NEW_OBJECTS(ring_theory::longinteger_object, (n + 1) * (n + 1));
47
48 for (i = 0; i <= n; i++) {
49 for (j = 0; j <= n; j++) {
50 Combi.krawtchouk(M[i * (n + 1) + j], n, q, i, j);
51 }
52 }
53
54 {
55 char str[1000];
56 string fname;
57 char title[1000];
58 char author[1000];
59
60 snprintf(str, 1000, "MacWilliams_n%d_k%d_q%d.tex", n, k, q);
61 fname.assign(str);
62 snprintf(title, 1000, "MacWilliams System for a $[%d,%d]_{%d}$ code", n, k, q);
63 //strcpy(author, "");
64 author[0] = 0;
65
66
67 {
68 ofstream ost(fname);
70
71 L.head(ost,
72 FALSE /* f_book*/,
73 TRUE /* f_title */,
74 title, author,
75 FALSE /* f_toc */,
76 FALSE /* f_landscape */,
77 TRUE /* f_12pt */,
78 TRUE /* f_enlarged_page */,
79 TRUE /* f_pagenumbers */,
80 NULL /* extra_praeamble */);
81
82
83 if (f_v) {
84 cout << "coding_theory_domain::make_mac_williams_equations "
85 "before print_longinteger_matrix_tex" << endl;
86 }
87
89
90 ost << "$$" << endl;
91 ost << "\\left[" << endl;
92 Li.print_longinteger_matrix_tex(ost, M, n + 1, n + 1);
93 ost << "\\right]" << endl;
94 ost << "$$" << endl;
95
96 if (f_v) {
97 cout << "coding_theory_domain::make_mac_williams_equations "
98 "after print_longinteger_matrix_tex" << endl;
99 }
100
101
102 L.foot(ost);
103
104 }
106
107 cout << "written file " << fname << " of size "
108 << Fio.file_size(fname) << endl;
109 }
110
111 if (f_v) {
112 cout << "coding_theory_domain::make_mac_williams_equations done" << endl;
113 }
114}
115
117 int n_max, int q, int verbose_level)
118{
119 int f_v = (verbose_level >= 1);
120 int n, k, d_S, d_H, d_P, d_G, d_GV;
121
122 if (f_v) {
123 cout << "coding_theory_domain::make_table_of_bounds" << endl;
124 }
125 vector<vector<long int>> Table;
126
127 for (n = 2; n <= n_max; n++) {
128 for (k = 1; k <= n; k++) {
129 cout << "n=" << n << " k=" << k << " q=" << q << endl;
130 d_S = singleton_bound_for_d(n, k, q, 0 /*verbose_level*/);
131 cout << "d_S=" << d_S << endl;
132 d_H = hamming_bound_for_d(n, k, q, 0 /*verbose_level*/);
133 cout << "d_H=" << d_H << endl;
134 d_P = plotkin_bound_for_d(n, k, q, 0 /*verbose_level*/);
135 cout << "d_P=" << d_P << endl;
136 d_G = griesmer_bound_for_d(n, k, q, 0 /*verbose_level*/);
137 cout << "d_G=" << d_G << endl;
138 d_GV = gilbert_varshamov_lower_bound_for_d(n, k, q, 0 /*verbose_level*/);
139 cout << "d_GV=" << d_GV << endl;
140 vector<long int> entry;
141
142 entry.push_back(n);
143 entry.push_back(k);
144 entry.push_back(q);
145 entry.push_back(d_GV);
146 entry.push_back(d_S);
147 entry.push_back(d_H);
148 entry.push_back(d_P);
149 entry.push_back(d_G);
150 Table.push_back(entry);
151 }
152 }
153 long int *T;
154 int N;
155 int i, j;
156 int nb_cols = 8;
157
158 N = Table.size();
159
160 T = NEW_lint(N * nb_cols);
161 for (i = 0; i < N; i++) {
162 for (j = 0; j < nb_cols; j++) {
163 T[i * nb_cols + j] = Table[i][j];
164 }
165 }
167 std::string fname;
168 char str[1000];
169
170 sprintf(str, "_n%d_q%d", n_max, q);
171
172 fname.assign("table_of_bounds");
173 fname.append(str);
174 fname.append(".csv");
175
176 string *headers;
177
178 headers = new string[8];
179
180 headers[0].assign("n");
181 headers[1].assign("k");
182 headers[2].assign("q");
183 headers[3].assign("GV");
184 headers[4].assign("S");
185 headers[5].assign("H");
186 headers[6].assign("P");
187 headers[7].assign("G");
188
189 Fio.lint_matrix_write_csv_override_headers(fname, headers, T, N, nb_cols);
190 cout << "Written file " << fname << " of size " << Fio.file_size(fname) << endl;
191
192 FREE_lint(T);
193 delete [] headers;
194
195
196 if (f_v) {
197 cout << "coding_theory_domain::make_table_of_bounds done" << endl;
198 }
199}
200
202 int n, int k, int d, int q,
203 geometry::projective_space *P, int verbose_level)
204{
205 int f_v = (verbose_level >= 1);
206
207 if (f_v) {
208 cout << "coding_theory_domain::make_gilbert_varshamov_code" << endl;
209 cout << "coding_theory_domain::make_gilbert_varshamov_code P->N_points = " << P->N_points << endl;
210 }
211 long int *set;
212 int *f_forbidden;
213
214 set = NEW_lint(n);
215 f_forbidden = NEW_int(P->N_points);
216 Int_vec_zero(f_forbidden, P->N_points);
217
218 make_gilbert_varshamov_code_recursion(P, n, d, set, f_forbidden, 0 /*level*/, verbose_level);
219
220
221
222 cout << "coding_theory_domain::make_gilbert_varshamov_code found "
223 "the following parity check matrix as projective set: ";
224 Lint_vec_print(cout, set, n);
225 cout << endl;
226
227 int *genma;
228 int nmk;
229
230
231 nmk = P->n + 1;
232 genma = NEW_int(n * n);
233
235 n, nmk, set,
236 genma,
237 verbose_level);
238
239 cout << "coding_theory_domain::make_gilbert_varshamov_code parity check matrix:" << endl;
240 Int_matrix_print(genma, P->n + 1, n);
241
242 cout << "coding_theory_domain::make_gilbert_varshamov_code parity check matrix:" << endl;
243 Int_vec_print_fully(cout, genma, nmk * n);
244 cout << endl;
245
246 P->F->Linear_algebra->RREF_and_kernel(n, nmk, genma, 0 /* verbose_level */);
247
248 cout << "coding_theory_domain::make_gilbert_varshamov_code generator matrix:" << endl;
249 Int_matrix_print(genma + nmk * n, k, n);
250
251
252 cout << "coding_theory_domain::make_gilbert_varshamov_code generator matrix:" << endl;
253 Int_vec_print_fully(cout, genma + nmk * n, k * n);
254 cout << endl;
255
256
257
258 FREE_int(genma);
259
260
261 FREE_lint(set);
262 FREE_int(f_forbidden);
263 if (f_v) {
264 cout << "coding_theory_domain::make_gilbert_varshamov_code done" << endl;
265 }
266}
267
269 geometry::projective_space *P, int n, int d,
270 long int *set, int *f_forbidden, int level, int verbose_level)
271{
272 int f_v = (verbose_level >= 1);
273
274 if (f_v) {
275 cout << "coding_theory_domain::make_gilbert_varshamov_code level = " << level << endl;
276 cout << "coding_theory_domain::make_gilbert_varshamov_code set = ";
277 Lint_vec_print(cout, set, level);
278 cout << endl;
279 }
280
281 if (level == n) {
282 cout << "done" << endl;
283 return;
284 }
285 int a, b, i;
286
287 for (a = 0; a < P->N_points; a++) {
288
289 if (!f_forbidden[a]) {
290 break;
291 }
292 }
293
294 if (a == P->N_points) {
295 cout << "coding_theory_domain::make_gilbert_varshamov_code_recursion "
296 "failure to construct the code" << endl;
297 exit(1);
298 }
299
300 if (f_v) {
301 cout << "coding_theory_domain::make_gilbert_varshamov_code_recursion "
302 "picking a=" << a << endl;
303 }
304
305
306 vector<int> add_set;
307 int nmk;
309 int cnt;
310
311 nmk = P->n + 1;
312 set[level] = a;
313 if (f_v) {
314 cout << "coding_theory_domain::make_gilbert_varshamov_code nmk = " << nmk << endl;
315 }
316
317 f_forbidden[a] = TRUE;
318 add_set.push_back(a);
319 cnt = 1;
320
321
322 if (level) {
323
324 int *subset;
325 subset = NEW_int(level - 1);
326 int s, N, h, u, c, e, t, f;
327 int *v1;
328 //int *v2;
329 int *v3;
330
331 v1 = NEW_int(nmk);
332 //v2 = NEW_int(nmk);
333 v3 = NEW_int(nmk);
334
335 s = MINIMUM(level, d - 2);
336
337
338 for (i = 1; i <= s; i++) {
339 N = Combi.binomial_lint(level, i);
340 if (f_v) {
341 cout << "coding_theory_domain::make_gilbert_varshamov_code "
342 "N_" << i << " = " << N << endl;
343 cout << "set = ";
344 Lint_vec_print(cout, set, level + 1);
345 cout << endl;
346 cout << "looping over all subsets of size " << i << ":" << endl;
347 }
348 for (h = 0; h < N; h++) {
349 Combi.unrank_k_subset(h, subset, level, i);
350 Int_vec_zero(v3, nmk);
351 for (u = 0; u < i; u++) {
352 c = subset[u];
353 e = set[c];
354 P->unrank_point(v1, e);
355 for (t = 0; t < nmk; t++) {
356 v3[t] = P->F->add(v3[t], v1[t]);
357 }
358 }
359 P->unrank_point(v1, set[level]);
360 for (t = 0; t < nmk; t++) {
361 v3[t] = P->F->add(v3[t], v1[t]);
362 }
363 f = P->rank_point(v3);
364 if (f_v) {
365 cout << "h=" << h << " / " << N << " : ";
366 Int_vec_print(cout, subset, i);
367 cout << " : ";
368 Int_vec_print(cout, v3, nmk);
369 cout << " : " << f;
370 }
371 if (!f_forbidden[f]) {
372 f_forbidden[f] = TRUE;
373 add_set.push_back(f);
374 cnt++;
375 if (f_v) {
376 cout << " : is new forbidden point " << cnt;
377 }
378 }
379 if (f_v) {
380 cout << endl;
381 }
382 }
383 //cout << endl;
384 }
385 FREE_int(subset);
386 FREE_int(v1);
387 //FREE_int(v2);
388 FREE_int(v3);
389 }
390 if (f_v) {
391 cout << "coding_theory_domain::make_gilbert_varshamov_code "
392 "level = " << level << " : cnt = " << cnt << " calling the recursion:" << endl;
393 }
394 make_gilbert_varshamov_code_recursion(P, n, d, set, f_forbidden, level + 1, verbose_level);
395 if (f_v) {
396 cout << "coding_theory_domain::make_gilbert_varshamov_code "
397 "level = " << level << " : cnt = " << cnt << " done with the recursion:" << endl;
398 }
399
400 for (i = 0; i < add_set.size(); i++) {
401 b = add_set[i];
402 f_forbidden[b] = FALSE;
403 }
404
405
406 if (f_v) {
407 cout << "coding_theory_domain::make_gilbert_varshamov_code done" << endl;
408 }
409}
410
411
412
413
414int coding_theory_domain::gilbert_varshamov_lower_bound_for_d(int n, int k, int q, int verbose_level)
415{
416 int f_v = (verbose_level >= 1);
419 int i, d;
420 ring_theory::longinteger_object qnmk, qm1, qm1_power, S, s, a, b;
421
422 if (f_v) {
423 cout << "coding_theory_domain::gilbert_varshamov_lower_bound_for_d" << endl;
424 }
425 qnmk.create(q, __FILE__, __LINE__);
426 qm1.create(q - 1, __FILE__, __LINE__);
427 D.power_int(qnmk, n - k);
428 qm1_power.create(1, __FILE__, __LINE__);
429 S.create(0, __FILE__, __LINE__);
430 //cout << "gilbert_varshamov_lower_bound_for_d: q=" << q << " n=" << n << " k=" << k << " " << q << "^" << n - k << " = " << qnmk << endl;
431 for (i = 0; ; i++) {
432 Combi.binomial(b, n - 1, i, FALSE);
433 D.mult(b, qm1_power, s);
434 D.add(S, s, a);
435 a.assign_to(S);
436 if (D.compare(S, qnmk) >= 0) {
437 d = i + 1;
438 //cout << "S=" << S << " d=" << d << endl;
439 break;
440 }
441 //cout << "i=" << i << " S=" << S << " is OK" << endl;
442 D.mult(qm1_power, qm1, s);
443 s.assign_to(qm1_power);
444 }
445 if (f_v) {
446 cout << "coding_theory_domain::gilbert_varshamov_lower_bound_for_d done" << endl;
447 }
448 return d;
449}
450
451
453 int n, int k, int q, int verbose_level)
454{
455 int f_v = (verbose_level >= 1);
456 int d;
457
458 if (f_v) {
459 cout << "coding_theory_domain::singleton_bound_for_d" << endl;
460 }
461 d = n - k + 1;
462 return d;
463}
464
465
467 int n, int k, int q, int verbose_level)
468{
469 int f_v = (verbose_level >= 1);
470 int f_vv = (verbose_level >= 2);
471 int e, d, t;
472 ring_theory::longinteger_object qnmk, qm1, qm1_power, B, s, a, b;
475
476
477 if (f_v) {
478 cout << "coding_theory_domain::hamming_bound_for_d" << endl;
479 }
480 qnmk.create(q, __FILE__, __LINE__);
481 qm1.create(q - 1, __FILE__, __LINE__);
482 D.power_int(qnmk, n - k);
483 qm1_power.create(1, __FILE__, __LINE__);
484 B.create(0, __FILE__, __LINE__);
485 if (f_vv) {
486 cout << "coding_theory_domain::hamming_bound_for_d: "
487 "q=" << q << " n=" << n << " k=" << k << " "
488 << q << "^" << n - k << " = " << qnmk << endl;
489 }
490 for (e = 0; ; e++) {
491 Combi.binomial(b, n, e, FALSE);
492 D.mult(b, qm1_power, s);
493 D.add(B, s, a);
494 a.assign_to(B);
495 if (D.compare(B, qnmk) == 1) {
496 // now the size of the Ball of radius e is bigger than q^{n-m}
497 t = e - 1;
498 d = 2 * t + 2;
499 if (f_vv) {
500 cout << "B=" << B << " t=" << t << " d=" << d << endl;
501 }
502 break;
503 }
504 if (f_vv) {
505 cout << "e=" << e << " B=" << B << " is OK" << endl;
506 }
507 D.mult(qm1_power, qm1, s);
508 s.assign_to(qm1_power);
509 }
510 if (f_v) {
511 cout << "coding_theory_domain::hamming_bound_for_d done" << endl;
512 }
513 return d;
514}
515
517 int n, int k, int q, int verbose_level)
518{
519 int f_v = (verbose_level >= 1);
520 int f_vv = (verbose_level >= 2);
521 int d;
522 ring_theory::longinteger_object qkm1, qk, qm1, a, b, c, Q, R;
524
525 if (f_v) {
526 cout << "coding_theory_domain::plotkin_bound_for_d" << endl;
527 }
528
529 // d \le \frac{n q^{k-1}}{q^k-1}
530
531 qkm1.create(q, __FILE__, __LINE__);
532 D.power_int(qkm1, k - 1);
533 a.create(n, __FILE__, __LINE__);
534 D.mult(a, qkm1, b);
535 // now b = n q^{k-1}
536
537 a.create(q - 1, __FILE__, __LINE__);
538 D.mult(b, a, c);
539 // now c = n q^{k-1} (q - 1)
540
541
542 a.create(q, __FILE__, __LINE__);
543 D.mult(a, qkm1, qk);
544 // now qk = q^k
545
546 a.create(-1, __FILE__, __LINE__);
547 D.add(qk, a, b);
548 // now b = 2^k - 1
549
550 if (f_vv) {
551 cout << "coding_theory_domain::plotkin_bound_for_d "
552 "q=" << q << " n=" << n << " k=" << k << endl;
553 }
554 D.integral_division(c, b, Q, R, FALSE /* verbose_level */);
555 d = Q.as_int();
556 if (f_vv) {
557 cout << c << " / " << b << " = " << d << endl;
558 }
559 if (f_v) {
560 cout << "coding_theory_domain::plotkin_bound_for_d" << endl;
561 }
562 return d;
563}
564
566 int n, int k, int q, int verbose_level)
567{
568 int f_v = (verbose_level >= 1);
569 int d, n1;
570
571 if (f_v) {
572 cout << "coding_theory_domain::griesmer_bound_for_d" << endl;
573 }
574 for (d = 1; d <= n; d++) {
575 n1 = griesmer_bound_for_n(k, d, q, verbose_level - 2);
576 if (n1 > n) {
577 d--;
578 break;
579 }
580 }
581 if (f_v) {
582 cout << "coding_theory_domain::griesmer_bound_for_d done" << endl;
583 }
584 return d;
585}
586
588 int k, int d, int q, int verbose_level)
589{
590 int f_v = (verbose_level >= 1);
591 int f_vv = (verbose_level >= 2);
592 int i, n;
593 ring_theory::longinteger_object qq, qi, d1, S, Q, R, one, a, b;
595
596 if (f_v) {
597 cout << "coding_theory_domain::griesmer_bound_for_n" << endl;
598 }
599 one.create(1, __FILE__, __LINE__);
600 d1.create(d, __FILE__, __LINE__);
601 qq.create(q, __FILE__, __LINE__);
602 qi.create(1, __FILE__, __LINE__);
603 S.create(0, __FILE__, __LINE__);
604 if (f_vv) {
605 cout << "coding_theory_domain::griesmer_bound_for_n q=" << q
606 << " d=" << d << " k=" << k << endl;
607 }
608 for (i = 0; i < k; i++) {
609 D.integral_division(d1, qi, Q, R, FALSE /* verbose_level */);
610 if (!R.is_zero()) {
611 D.add(Q, one, a);
612 D.add(S, a, b);
613 }
614 else {
615 D.add(S, Q, b);
616 }
617 b.assign_to(S);
618 D.mult(qi, qq, a);
619 a.assign_to(qi);
620 if (f_vv) {
621 cout << "i=" << i << " S=" << S << endl;
622 }
623 }
624 n = S.as_int();
625 if (f_v) {
626 cout << "coding_theory_domain::griesmer_bound_for_n" << endl;
627 }
628 return n;
629}
630
631
633 int q, int n, int k, int verbose_level)
634{
635 int f_v = (verbose_level >= 1);
638 int i, j;
639
640 if (f_v) {
641 cout << "interface_coding_theory::do_make_macwilliams_system" << endl;
642 }
643
644 C.make_mac_williams_equations(M, n, k, q, verbose_level);
645
646 cout << "\\begin{array}{r|*{" << n << "}{r}}" << endl;
647 for (i = 0; i <= n; i++) {
648 for (j = 0; j <= n; j++) {
649 cout << M[i * (n + 1) + j];
650 if (j < n) {
651 cout << " & ";
652 }
653 }
654 cout << "\\\\" << endl;
655 }
656 cout << "\\end{array}" << endl;
657
658 cout << "[";
659 for (i = 0; i <= n; i++) {
660 cout << "[";
661 for (j = 0; j <= n; j++) {
662 cout << M[i * (n + 1) + j];
663 if (j < n) {
664 cout << ",";
665 }
666 }
667 cout << "]";
668 if (i < n) {
669 cout << ",";
670 }
671 }
672 cout << "]" << endl;
673
674
675 if (f_v) {
676 cout << "coding_theory_domain::do_make_macwilliams_system done" << endl;
677 }
678}
679
680
681
683 int f_projective, int verbose_level)
684{
685 int f_v = (verbose_level >= 1);
686
687 int width, height;
688 int *v;
689 int *w;
690 int *Table;
693
694 if (f_v) {
695 cout << "coding_theory_domain::make_Hamming_graph_and_write_file" << endl;
696 }
697
698 v = NEW_int(n);
699 w = NEW_int(n);
700
701 if (f_projective) {
702 width = height = Gg.nb_PG_elements(n - 1, q);
704 F->finite_field_init(q, FALSE /* f_without_tables */, 0 /* verbose_level */);
705 }
706 else {
707 width = height = Gg.nb_AG_elements(n, q);
708 }
709
710#if 0
711 int N;
712 N = width;
713 if (f_graph) {
714 Adj = NEW_int(N * N);
715 int_vec_zero(Adj, N * N);
716 }
717#endif
718
719 cout << "width=" << width << endl;
720
721 int i, j, d, h;
722
723 Table = NEW_int(height * width);
724 for (i = 0; i < height; i++) {
725
726 if (f_projective) {
727 F->PG_element_unrank_modified(v, 1 /*stride*/, n, i);
728 }
729 else {
730 Gg.AG_element_unrank(q, v, 1, n, i);
731 }
732
733 for (j = 0; j < width; j++) {
734
735 if (f_projective) {
736 F->PG_element_unrank_modified(w, 1 /*stride*/, n, j);
737 }
738 else {
739 Gg.AG_element_unrank(q, w, 1, n, j);
740 }
741
742 d = 0;
743 for (h = 0; h < n; h++) {
744 if (v[h] != w[h]) {
745 d++;
746 }
747 }
748
749#if 0
750 if (f_graph && d == 1) {
751 Adj[i * N + j] = 1;
752 }
753#endif
754
755 Table[i * width + j] = d;
756
757 }
758 }
759
760 string fname;
761 char str[1000];
763
764 sprintf(str, "Hamming_n%d_q%d.csv", n, q);
765 fname.assign(str);
766
767 Fio.int_matrix_write_csv(fname, Table, height, width);
768
769 if (f_v) {
770 cout << "Written file " << fname << " of size " << Fio.file_size(fname) << endl;
771 }
772
773 if (f_v) {
774 cout << "coding_theory_domain::make_Hamming_graph_and_write_file" << endl;
775 }
776
777}
778
779
781 ostream &ost, field_theory::finite_field *F, int *M, int n, int k)
782{
783 int i;
784 int *weights;
785
786 weights = NEW_int(n + 1);
788 M, // [k * n]
789 weights, // [n + 1]
790 0 /*verbose_level*/);
791
792
793 ost << "projective weights: " << endl;
794 for (i = 0; i <= n; i++) {
795 if (weights[i] == 0) {
796 continue;
797 }
798 ost << i << " : " << weights[i] << endl;
799 }
800 FREE_int(weights);
801}
802
804 int *code, int verbose_level)
805 // code[k * n]
806{
807 int f_v = (verbose_level >= 1);
808 int *weight_enumerator;
809 int i;
810
811 if (f_v) {
812 cout << "coding_theory_domain::code_minimum_distance" << endl;
813 }
814 weight_enumerator = NEW_int(n + 1);
815 Int_vec_zero(weight_enumerator, n + 1);
816
818 code, // [k * n]
819 weight_enumerator, // [n + 1]
820 verbose_level);
821 for (i = 1; i <= n; i++) {
822 if (weight_enumerator[i]) {
823 break;
824 }
825 }
826 if (i == n + 1) {
827 cout << "coding_theory_domain::code_minimum_distance "
828 "the minimum weight is undefined" << endl;
829 exit(1);
830 }
831 FREE_int(weight_enumerator);
832 return i;
833}
834
836 int *code, // [k * n]
837 int *codewords, // q^k
838 int verbose_level)
839{
840 int f_v = (verbose_level >= 1);
841 long int N, h, rk;
842 int *msg;
843 int *word;
845
846 if (f_v) {
847 cout << "coding_theory_domain::codewords_affine" << endl;
848 }
849 N = Gg.nb_AG_elements(k, F->q);
850 if (f_v) {
851 cout << N << " messages" << endl;
852 }
853 msg = NEW_int(k);
854 word = NEW_int(n);
855
856 for (h = 0; h < N; h++) {
857 Gg.AG_element_unrank(F->q, msg, 1, k, h);
858 F->Linear_algebra->mult_vector_from_the_left(msg, code, word, k, n);
859 rk = Gg.AG_element_rank(F->q, word, 1, n);
860 codewords[h] = rk;
861 }
862 FREE_int(msg);
863 FREE_int(word);
864 if (f_v) {
865 cout << "coding_theory_domain::codewords_affine done" << endl;
866 }
867}
868
870 int n, int k,
871 int *code, // [k * n]
872 int *weight_enumerator, // [n + 1]
873 int verbose_level)
874{
875 int f_v = (verbose_level >= 1);
876 int f_vv = (verbose_level >= 1);
877 int N, h, wt, i;
878 int *msg;
879 int *word;
880 int t0, t1, dt;
883
884 t0 = Os.os_ticks();
885
886 if (f_v) {
887 cout << "coding_theory_domain::code_projective_weight_enumerator" << endl;
888 }
889 N = Gg.nb_AG_elements(k, F->q);
890 if (f_v) {
891 cout << N << " messages" << endl;
892 }
893 msg = NEW_int(k);
894 word = NEW_int(n);
895
896 Int_vec_zero(weight_enumerator, n + 1);
897
898 for (h = 0; h < N; h++) {
899 if (f_v && (h % ONE_MILLION) == 0) {
900 t1 = Os.os_ticks();
901 dt = t1 - t0;
902 cout << setw(10) << h << " / " << setw(10) << N << " : ";
903 Os.time_check_delta(cout, dt);
904 cout << endl;
905 if (f_vv) {
906 cout << "so far, the weight enumerator is:" << endl;
907 for (i = 0; i <= n; i++) {
908 if (weight_enumerator[i] == 0)
909 continue;
910 cout << setw(5) << i << " : " << setw(10)
911 << weight_enumerator[i] << endl;
912 }
913 }
914 }
915 Gg.AG_element_unrank(F->q, msg, 1, k, h);
916 F->Linear_algebra->mult_vector_from_the_left(msg, code, word, k, n);
917 wt = 0;
918 for (i = 0; i < n; i++) {
919 if (word[i]) {
920 wt++;
921 }
922 }
923 weight_enumerator[wt]++;
924 }
925 if (f_v) {
926 cout << "the weight enumerator is:" << endl;
927 for (i = 0; i <= n; i++) {
928 if (weight_enumerator[i] == 0) {
929 continue;
930 }
931 cout << setw(5) << i << " : " << setw(10)
932 << weight_enumerator[i] << endl;
933 }
934 }
935
936
937 FREE_int(msg);
938 FREE_int(word);
939}
940
942 int n, int k,
943 int *code, // [k * n]
944 int *weight_enumerator, // [n + 1]
945 int verbose_level)
946{
947 int f_v = (verbose_level >= 1);
948 int f_vv = (verbose_level >= 1);
949 int N, h, wt, i;
950 int *msg;
951 int *word;
952 int t0, t1, dt;
955
956 t0 = Os.os_ticks();
957
958 if (f_v) {
959 cout << "coding_theory_domain::code_weight_enumerator" << endl;
960 }
961 N = Gg.nb_AG_elements(k, F->q);
962 if (f_v) {
963 cout << N << " messages" << endl;
964 }
965 msg = NEW_int(k);
966 word = NEW_int(n);
967
968 Int_vec_zero(weight_enumerator, n + 1);
969
970 for (h = 0; h < N; h++) {
971 if ((h % ONE_MILLION) == 0) {
972 t1 = Os.os_ticks();
973 dt = t1 - t0;
974 cout << setw(10) << h << " / " << setw(10) << N << " : ";
975 Os.time_check_delta(cout, dt);
976 cout << endl;
977 if (f_vv) {
978 cout << "so far, the weight enumerator is:" << endl;
979 for (i = 0; i <= n; i++) {
980 if (weight_enumerator[i] == 0) {
981 continue;
982 }
983 cout << setw(5) << i << " : " << setw(10)
984 << weight_enumerator[i] << endl;
985 }
986 }
987 }
988 Gg.AG_element_unrank(F->q, msg, 1, k, h);
989 F->Linear_algebra->mult_vector_from_the_left(msg, code, word, k, n);
990 wt = 0;
991 for (i = 0; i < n; i++) {
992 if (word[i]) {
993 wt++;
994 }
995 }
996 weight_enumerator[wt]++;
997 }
998 if (f_v) {
999 cout << "the weight enumerator is:" << endl;
1000 for (i = 0; i <= n; i++) {
1001 if (weight_enumerator[i] == 0) {
1002 continue;
1003 }
1004 cout << setw(5) << i << " : " << setw(10)
1005 << weight_enumerator[i] << endl;
1006 }
1007 }
1008
1009
1010 FREE_int(msg);
1011 FREE_int(word);
1012}
1013
1014
1016 int n, int k,
1017 int *code, // [k * n]
1018 int *weight_enumerator, // [n + 1]
1019 int verbose_level)
1020{
1021 int f_v = (verbose_level >= 1);
1022 int f_vv = (verbose_level >= 2);
1023 int N, h, wt, i;
1024 int *msg;
1025 int *word;
1026 int t0, t1, dt;
1029
1030 t0 = Os.os_ticks();
1031
1032 if (f_v) {
1033 cout << "coding_theory_domain::code_weight_enumerator_fast" << endl;
1034 }
1035 N = Gg.nb_PG_elements(k - 1, F->q);
1036 if (f_v) {
1037 cout << N << " projective messages" << endl;
1038 }
1039 msg = NEW_int(k);
1040 word = NEW_int(n);
1041
1042
1043 Int_vec_zero(weight_enumerator, n + 1);
1044
1045 for (h = 0; h < N; h++) {
1046 if (((h % ONE_MILLION) == 0) && h) {
1047 t1 = Os.os_ticks();
1048 dt = t1 - t0;
1049 cout << setw(10) << h << " / " << setw(10) << N << " : ";
1050 Os.time_check_delta(cout, dt);
1051 cout << endl;
1052 if (f_vv) {
1053 cout << "so far, the weight enumerator is:" << endl;
1054 for (i = 0; i <= n; i++) {
1055 if (weight_enumerator[i] == 0) {
1056 continue;
1057 }
1058 cout << setw(5) << i << " : " << setw(10)
1059 << (F->q - 1) * weight_enumerator[i] << endl;
1060 }
1061 }
1062 }
1063 F->PG_element_unrank_modified(msg, 1, k, h);
1064 //AG_element_unrank(q, msg, 1, k, h);
1065 F->Linear_algebra->mult_vector_from_the_left(msg, code, word, k, n);
1066 wt = 0;
1067 for (i = 0; i < n; i++) {
1068 if (word[i]) {
1069 wt++;
1070 }
1071 }
1072 weight_enumerator[wt]++;
1073 if (f_vv) {
1074 cout << h << " / " << N << " msg: ";
1075 Int_vec_print(cout, msg, k);
1076 cout << " codeword ";
1077 Int_vec_print(cout, word, n);
1078 cout << " weight " << wt << endl;
1079 }
1080 }
1081 weight_enumerator[0] = 1;
1082 for (i = 1; i <= n; i++) {
1083 weight_enumerator[i] *= F->q - 1;
1084 }
1085 if (f_v) {
1086 cout << "the weight enumerator is:" << endl;
1087 for (i = 0; i <= n; i++) {
1088 if (weight_enumerator[i] == 0) {
1089 continue;
1090 }
1091 cout << setw(5) << i << " : " << setw(10)
1092 << weight_enumerator[i] << endl;
1093 }
1094 }
1095
1096
1097 FREE_int(msg);
1098 FREE_int(word);
1099}
1100
1103 int n, int k,
1104 int *code, // [k * n]
1105 int *&weights, // will be allocated [N]
1106 int verbose_level)
1107{
1108 int f_v = (verbose_level >= 1);
1109 //int f_vv = (verbose_level >= 1);
1110 int N, h, wt, i;
1111 int *msg;
1112 int *word;
1113 int t0, t1, dt;
1116
1117 t0 = Os.os_ticks();
1118
1119 if (f_v) {
1120 cout << "coding_theory_domain::code_projective_weights" << endl;
1121 }
1122 N = Gg.nb_PG_elements(k - 1, F->q);
1123 if (f_v) {
1124 cout << N << " projective messages" << endl;
1125 }
1126 weights = NEW_int(N);
1127 msg = NEW_int(k);
1128 word = NEW_int(n);
1129
1130 for (h = 0; h < N; h++) {
1131 if ((h % ONE_MILLION) == 0) {
1132 t1 = Os.os_ticks();
1133 dt = t1 - t0;
1134 cout << setw(10) << h << " / " << setw(10) << N << " : ";
1135 Os.time_check_delta(cout, dt);
1136 cout << endl;
1137 }
1138 F->PG_element_unrank_modified(msg, 1, k, h);
1139 //AG_element_unrank(q, msg, 1, k, h);
1140 F->Linear_algebra->mult_vector_from_the_left(msg, code, word, k, n);
1141 wt = 0;
1142 for (i = 0; i < n; i++) {
1143 if (word[i]) {
1144 wt++;
1145 }
1146 }
1147 weights[h] = wt;
1148 }
1149 if (f_v) {
1150 cout << "coding_theory_domain::code_projective_weights done" << endl;
1151 }
1152
1153
1154 FREE_int(msg);
1155 FREE_int(word);
1156}
1157
1159{
1161 int i, j;
1162
1163 M = NEW_OBJECTS(ring_theory::longinteger_object, (n + 1) * (n + 1));
1164
1165 for (i = 0; i <= n; i++) {
1166 for (j = 0; j <= n; j++) {
1167 D.krawtchouk(M[i * (n + 1) + j], n, q, i, j);
1168 }
1169 }
1170}
1171
1173{
1174 int n = 19, k = 7, q = 2;
1176 ring_theory::longinteger_object *M, *A1, *A2, qk;
1177 int i;
1178
1179 qk.create(q, __FILE__, __LINE__);
1180 D.power_int(qk, k);
1181 cout << q << "^" << k << " = " << qk << endl;
1182
1183 mac_williams_equations(M, n, k, q);
1184
1185 D.matrix_print_tex(cout, M, n + 1, n + 1);
1186
1189 for (i = 0; i <= n; i++) {
1190 A1[i].create(0, __FILE__, __LINE__);
1191 }
1192 A1[0].create(1, __FILE__, __LINE__);
1193 A1[8].create(78, __FILE__, __LINE__);
1194 A1[12].create(48, __FILE__, __LINE__);
1195 A1[16].create(1, __FILE__, __LINE__);
1196 D.matrix_print_tex(cout, A1, n + 1, 1);
1197
1198 D.matrix_product(M, A1, A2, n + 1, n + 1, 1);
1199 D.matrix_print_tex(cout, A2, n + 1, 1);
1200
1201 D.matrix_entries_integral_division_exact(A2, qk, n + 1, 1);
1202
1203 D.matrix_print_tex(cout, A2, n + 1, 1);
1204
1205 FREE_OBJECTS(M);
1206 FREE_OBJECTS(A1);
1207 FREE_OBJECTS(A2);
1208}
1209
1210
1212 int *M, int m, int n,
1213 int f_normalize_from_the_left, int f_normalize_from_the_right,
1214 int verbose_level)
1215{
1216 int f_v = (verbose_level >= 1);
1217 int *A;
1218 int *base_cols;
1219 int *weight_enumerator;
1220 int rk, i;
1222
1223 if (f_v) {
1224 cout << "coding_theory_domain::do_weight_enumerator" << endl;
1225 }
1226
1227 A = NEW_int(n * n);
1228 base_cols = NEW_int(n);
1229 weight_enumerator = NEW_int(n + 1);
1230 Int_vec_copy(M, A, m * n);
1231
1232 if (f_v) {
1233 cout << "coding_theory_domain::do_weight_enumerator input matrix:" << endl;
1234 Int_matrix_print(A, m, n);
1235
1236 cout << "$$" << endl;
1237 cout << "\\left[" << endl;
1238 Li.print_integer_matrix_tex(cout, A, m, n);
1239 cout << "\\right]" << endl;
1240 cout << "$$" << endl;
1241
1242 }
1243
1244 rk = F->Linear_algebra->Gauss_int(A,
1245 FALSE /* f_special */, TRUE /* f_complete */, base_cols,
1246 FALSE /* f_P */, NULL /*P*/, m, n, n,
1247 0 /*verbose_level*/);
1248
1249
1250 if (f_v) {
1251 cout << "coding_theory_domain::do_weight_enumerator after RREF:" << endl;
1252 Int_matrix_print(A, rk, n);
1253 cout << "rk=" << rk << endl;
1254
1255
1256 cout << "$$" << endl;
1257 cout << "\\left[" << endl;
1258 Li.print_integer_matrix_tex(cout, A, rk, n);
1259 cout << "\\right]" << endl;
1260 cout << "$$" << endl;
1261
1262
1263 cout << "coding_theory_domain::do_weight_enumerator coefficients:" << endl;
1264 Int_vec_print(cout, A, rk * n);
1265 cout << endl;
1266 }
1267
1268 code_weight_enumerator(F, n, rk,
1269 A /* code */, // [k * n]
1270 weight_enumerator, // [n + 1]
1271 verbose_level);
1272
1273 if (f_v) {
1274 cout << "coding_theory_domain::do_weight_enumerator The weight enumerator is:" << endl;
1275 for (i = 0; i <= n; i++) {
1276 cout << i << " : " << weight_enumerator[i] << endl;
1277 }
1278
1279 int f_first = TRUE;
1280
1281 for (i = 0; i <= n; i++) {
1282 if (weight_enumerator[i] == 0) {
1283 continue;
1284 }
1285 if (f_first) {
1286 f_first = FALSE;
1287 }
1288 else {
1289 cout << " + ";
1290 }
1291 cout << weight_enumerator[i];
1292 if (i) {
1293 cout << "*";
1294 cout << "x";
1295 if (i > 1) {
1296 cout << "^";
1297 if (i < 10) {
1298 cout << i;
1299 }
1300 else {
1301 cout << "(" << i << ")";
1302 }
1303 }
1304 }
1305 if (n - i) {
1306 cout << "*";
1307 cout << "y";
1308 if (n - i > 1) {
1309 cout << "^";
1310 if (n - i < 10) {
1311 cout << n - i;
1312 }
1313 else {
1314 cout << "(" << n - i << ")";
1315 }
1316 }
1317 }
1318
1319 }
1320 cout << endl;
1321
1322
1323 cout << "coding_theory_domain::do_weight_enumerator The weight enumerator is:" << endl;
1324 for (i = 0; i <= n; i++) {
1325 cout << i << " : " << weight_enumerator[i] << endl;
1326 }
1327
1328 f_first = TRUE;
1329
1330 for (i = 0; i <= n; i++) {
1331 if (weight_enumerator[i] == 0) {
1332 continue;
1333 }
1334 if (f_first) {
1335 f_first = FALSE;
1336 }
1337 else {
1338 cout << " + ";
1339 }
1340 cout << weight_enumerator[i];
1341 if (i) {
1342 //cout << "*";
1343 cout << "x";
1344 if (i > 1) {
1345 cout << "^";
1346 if (i < 10) {
1347 cout << i;
1348 }
1349 else {
1350 cout << "{" << i << "}";
1351 }
1352 }
1353 }
1354 if (n - i) {
1355 //cout << "*";
1356 cout << "y";
1357 if (n - i > 1) {
1358 cout << "^";
1359 if (n - i < 10) {
1360 cout << n - i;
1361 }
1362 else {
1363 cout << "{" << n - i << "}";
1364 }
1365 }
1366 }
1367
1368 }
1369 cout << endl;
1370
1371 cout << "weight enumerator:" << endl;
1372 Int_vec_print_fully(cout, weight_enumerator, n + 1);
1373 cout << endl;
1374
1375 }
1376
1377
1378 if (f_normalize_from_the_left) {
1379 if (f_v) {
1380 cout << "coding_theory_domain::do_weight_enumerator normalizing from the left" << endl;
1381 }
1382 for (i = 0; i < rk; i++) {
1384 A + i * n, 1, n);
1385 }
1386
1387 if (f_v) {
1388 cout << "coding_theory_domain::do_weight_enumerator after normalize from the left:" << endl;
1389 Int_matrix_print(A, rk, n);
1390 cout << "rk=" << rk << endl;
1391 }
1392 }
1393
1394 if (f_normalize_from_the_right) {
1395 if (f_v) {
1396 cout << "coding_theory_domain::do_weight_enumerator normalizing from the right" << endl;
1397 }
1398 for (i = 0; i < rk; i++) {
1400 A + i * n, 1, n);
1401 }
1402
1403 if (f_v) {
1404 cout << "coding_theory_domain::do_weight_enumerator after normalize from the right:" << endl;
1405 Int_matrix_print(A, rk, n);
1406 cout << "coding_theory_domain::do_weight_enumerator rk=" << rk << endl;
1407 }
1408 }
1409
1410
1411 FREE_int(A);
1412 FREE_int(base_cols);
1413 FREE_int(weight_enumerator);
1414
1415 if (f_v) {
1416 cout << "coding_theory_domain::do_weight_enumerator done" << endl;
1417 }
1418}
1419
1420
1421
1423 int n,
1424 long int *basis_set, int k,
1425 int f_embellish,
1426 int verbose_level)
1427{
1428 cout << "coding_theory_domain::linear_code_through_basis:" << endl;
1429
1430 int i;
1431 int *genma;
1432 int *word;
1433 int *code_word;
1434 long int *set;
1435 int sz;
1437
1438 genma = NEW_int(k * n);
1439 word = NEW_int(k);
1440 code_word = NEW_int(n);
1441
1442 for (i = 0; i < k; i++) {
1443
1444 Gg.AG_element_unrank(2, genma + i * n, 1, n, basis_set[i]);
1445 }
1446
1447 cout << "genma:" << endl;
1448 Int_matrix_print(genma, k, n);
1449
1450 sz = 1 << k;
1451 set = NEW_lint(sz);
1452
1454
1456 F->finite_field_init(2, FALSE /* f_without_tables */, 0);
1457
1458 for (i = 0; i < sz; i++) {
1459 Gg.AG_element_unrank(2, word, 1, k, i);
1460 F->Linear_algebra->mult_matrix_matrix(word, genma,
1461 code_word, 1, k, n, 0 /* verbose_level*/);
1462 set[i] = Gg.AG_element_rank(2, code_word, 1, n);
1463
1464 cout << i << " : ";
1465 Int_vec_print(cout, word, k);
1466 cout << " : ";
1467 Int_vec_print(cout, code_word, n);
1468 cout << " : " << set[i] << endl;
1469 }
1470
1471
1472 cout << "Codewords : ";
1473 Lint_vec_print(cout, set, sz);
1474 cout << endl;
1475
1476
1477
1478 {
1479 char fname[1000];
1480 char title[1000];
1481 char author[1000];
1482
1483 snprintf(fname, 1000, "code_n%d_k%d_q%d.tex", n, k, F->q);
1484 snprintf(title, 1000, "Linear $[%d,%d]$ code over GF($%d$)", n, k, F->q);
1485 //sprintf(author, "");
1486 author[0] = 0;
1487
1488
1489 {
1490 ofstream ost(fname);
1491
1492
1494
1495
1496 L.head(ost, FALSE /* f_book*/, TRUE /* f_title */,
1497 title, author, FALSE /* f_toc */, FALSE /* f_landscape */,
1498 TRUE /* f_12pt */,
1499 TRUE /* f_enlarged_page */,
1500 TRUE /* f_pagenumbers */,
1501 NULL /* extra_praeamble */);
1502
1503
1504 ost << "$$" << endl;
1505 ost << "\\left[" << endl;
1506 L.int_matrix_print_tex(ost, genma, k, n);
1507 ost << "\\right]" << endl;
1508 ost << "$$" << endl;
1509 ost << "Codewords: ";
1510 ost << "$";
1511 Lint_vec_print(ost, set, sz);
1512 ost << "$\\\\";
1513 ost << endl;
1514
1515 L.foot(ost);
1516 }
1517
1519
1520 cout << "written file " << fname << " of size " << Fio.file_size(fname) << endl;
1521
1522 }
1523
1524 //investigate_code(set, sz, n, f_embellish, verbose_level);
1525
1526 FREE_OBJECT(F);
1527 FREE_int(genma);
1528 FREE_int(word);
1529 FREE_int(code_word);
1530
1531}
1532
1534 int n, int k, long int *columns_set_of_size_n,
1535 int *genma,
1536 int verbose_level)
1537{
1538 int f_v = (verbose_level >= 1);
1539
1540 if (f_v) {
1541 cout << "coding_theory_domain::matrix_from_projective_set" << endl;
1542 }
1543 int i, j;
1544 int *v;
1545
1546 v = NEW_int(k);
1547 for (j = 0; j < n; j++) {
1548
1549 F->PG_element_unrank_modified(v, 1, k, columns_set_of_size_n[j]);
1550 for (i = 0; i < k; i++) {
1551 genma[i * n + j] = v[i];
1552 }
1553 }
1554 FREE_int(v);
1555
1556 if (f_v) {
1557 cout << "coding_theory_domain::matrix_from_projective_set done" << endl;
1558 }
1559}
1560
1562 int n,
1563 long int *columns_set, int k,
1564 int verbose_level)
1565{
1566 int f_v = (verbose_level >= 1);
1567
1568 if (f_v) {
1569 cout << "coding_theory_domain::do_linear_code_through_columns_of_parity_check_projectively" << endl;
1570 }
1571
1573 int i, j;
1574 int *v;
1575 int *genma;
1576 int *word;
1577 int *code_word;
1579
1581 F->finite_field_init(2, FALSE /* f_without_tables */, 0);
1582 genma = NEW_int(k * n);
1583 v = NEW_int(k);
1584 word = NEW_int(k);
1585 code_word = NEW_int(n);
1586 for (j = 0; j < n; j++) {
1587
1588 F->PG_element_unrank_modified(v, 1, k, columns_set[j]);
1589 for (i = 0; i < k; i++) {
1590 genma[i * n + j] = v[i];
1591 }
1592 }
1593 cout << "genma:" << endl;
1594 Int_matrix_print(genma, k, n);
1595
1596
1598 long int *set;
1599 long int N;
1600
1601 N = NT.i_power_j(2, k);
1602 set = NEW_lint(N);
1603 for (i = 0; i < N; i++) {
1604 Gg.AG_element_unrank(2, word, 1, k, i);
1605 F->Linear_algebra->mult_matrix_matrix(word, genma,
1606 code_word, 1, k, n, 0 /* verbose_level*/);
1607 set[i] = Gg.AG_element_rank(2, code_word, 1, n);
1608
1609 cout << i << " : ";
1610 Int_vec_print(cout, word, k);
1611 cout << " : ";
1612 Int_vec_print(cout, code_word, n);
1613 cout << " : " << set[i] << endl;
1614 }
1615
1616
1617 cout << "Codewords : ";
1618 Lint_vec_print_fully(cout, set, N);
1619 cout << endl;
1620
1621 char str[1000];
1622 string fname_csv;
1624
1625 snprintf(str, 1000, "codewords_n%d_k%d_q%d.csv", n, k, F->q);
1626 fname_csv.assign(str);
1627 Fio.lint_matrix_write_csv(fname_csv, set, 1, N);
1628 cout << "written file " << fname_csv << " of size "
1629 << Fio.file_size(fname_csv) << endl;
1630
1631
1632
1633 {
1634 char fname[1000];
1635 char title[1000];
1636 char author[1000];
1637
1638 snprintf(fname, 1000, "code_n%d_k%d_q%d.tex", n, k, F->q);
1639 snprintf(title, 1000, "Linear $[%d,%d]$ code over GF($%d$)", n, k, F->q);
1640 //sprintf(author, "");
1641 author[0] = 0;
1642
1643
1644 {
1645 ofstream ost(fname);
1646
1647
1649
1650
1651 L.head(ost, FALSE /* f_book*/, TRUE /* f_title */,
1652 title, author, FALSE /* f_toc */, FALSE /* f_landscape */,
1653 TRUE /* f_12pt */,
1654 TRUE /* f_enlarged_page */,
1655 TRUE /* f_pagenumbers */,
1656 NULL /* extra_praeamble */);
1657
1658
1659 ost << "$$" << endl;
1660 ost << "\\left[" << endl;
1661 L.int_matrix_print_tex(ost, genma, k, n);
1662 ost << "\\right]" << endl;
1663 ost << "$$" << endl;
1664#if 0
1665 ost << "Codewords: ";
1666 ost << "$";
1667 lint_vec_print(ost, set, n);
1668 ost << "$\\\\";
1669#endif
1670 ost << endl;
1671
1672 L.foot(ost);
1673 }
1674
1676
1677 cout << "written file " << fname << " of size " << Fio.file_size(fname) << endl;
1678
1679 }
1680
1681
1682
1683 FREE_lint(set);
1684 FREE_int(genma);
1685 FREE_int(v);
1686 FREE_int(word);
1687 FREE_int(code_word);
1688 FREE_OBJECT(F);
1689
1690 if (f_v) {
1691 cout << "coding_theory_domain::do_linear_code_through_columns_of_parity_check_projectively done" << endl;
1692 }
1693}
1694
1696 int n,
1697 long int *columns_set, int k,
1698 int verbose_level)
1699{
1700 int f_v = (verbose_level >= 1);
1701
1702 if (f_v) {
1703 cout << "coding_theory_domain::do_linear_code_through_columns_of_parity_check" << endl;
1704 }
1705
1707 int i, j;
1708 int *v;
1709 int *genma;
1710 int *word;
1711 int *code_word;
1713
1715 F->finite_field_init(2, FALSE /* f_without_tables */, 0);
1716 genma = NEW_int(k * n);
1717 v = NEW_int(k);
1718 word = NEW_int(k);
1719 code_word = NEW_int(n);
1720 for (j = 0; j < n; j++) {
1721
1722 Gg.AG_element_unrank(2, v, 1, k, columns_set[j]);
1723 for (i = 0; i < k; i++) {
1724 genma[i * n + j] = v[i];
1725 }
1726 }
1727 cout << "genma:" << endl;
1728 Int_matrix_print(genma, k, n);
1729
1730
1732 long int *set;
1733 long int N;
1734
1735 N = NT.i_power_j(2, k);
1736 set = NEW_lint(N);
1737 for (i = 0; i < N; i++) {
1738 Gg.AG_element_unrank(2, word, 1, k, i);
1739 F->Linear_algebra->mult_matrix_matrix(word, genma,
1740 code_word, 1, k, n, 0 /* verbose_level*/);
1741 set[i] = Gg.AG_element_rank(2, code_word, 1, n);
1742
1743 cout << i << " : ";
1744 Int_vec_print(cout, word, k);
1745 cout << " : ";
1746 Int_vec_print(cout, code_word, n);
1747 cout << " : " << set[i] << endl;
1748 }
1749
1750
1751 cout << "Codewords : ";
1752 Lint_vec_print_fully(cout, set, N);
1753 cout << endl;
1754
1755 char str[1000];
1756 string fname_csv;
1758
1759 snprintf(str, 1000, "codewords_n%d_k%d_q%d.csv", n, k, F->q);
1760 fname_csv.assign(str);
1761 Fio.lint_matrix_write_csv(fname_csv, set, 1, N);
1762 cout << "written file " << fname_csv << " of size "
1763 << Fio.file_size(fname_csv) << endl;
1764
1765
1766
1767 {
1768 char fname[1000];
1769 char title[1000];
1770 char author[1000];
1771
1772 snprintf(fname, 1000, "code_n%d_k%d_q%d.tex", n, k, F->q);
1773 snprintf(title, 1000, "Linear $[%d,%d]$ code over GF($%d$)", n, k, F->q);
1774 //sprintf(author, "");
1775 author[0] = 0;
1776
1777
1778 {
1779 ofstream ost(fname);
1780
1781
1783
1784
1785 L.head(ost, FALSE /* f_book*/, TRUE /* f_title */,
1786 title, author, FALSE /* f_toc */, FALSE /* f_landscape */,
1787 TRUE /* f_12pt */,
1788 TRUE /* f_enlarged_page */,
1789 TRUE /* f_pagenumbers */,
1790 NULL /* extra_praeamble */);
1791
1792
1793 ost << "$$" << endl;
1794 ost << "\\left[" << endl;
1795 L.int_matrix_print_tex(ost, genma, k, n);
1796 ost << "\\right]" << endl;
1797 ost << "$$" << endl;
1798#if 0
1799 ost << "Codewords: ";
1800 ost << "$";
1801 lint_vec_print(ost, set, n);
1802 ost << "$\\\\";
1803#endif
1804 ost << endl;
1805
1806 L.foot(ost);
1807 }
1808
1810
1811 cout << "written file " << fname << " of size " << Fio.file_size(fname) << endl;
1812
1813 }
1814
1815
1816
1817 FREE_lint(set);
1818 FREE_int(genma);
1819 FREE_int(v);
1820 FREE_int(word);
1821 FREE_int(code_word);
1822 FREE_OBJECT(F);
1823
1824 if (f_v) {
1825 cout << "coding_theory_domain::do_linear_code_through_columns_of_parity_check done" << endl;
1826 }
1827}
1828
1830 int n,
1831 int polynomial_degree,
1832 int polynomial_nb_vars,
1833 std::string &polynomial_text,
1834 int f_embellish,
1835 int verbose_level)
1836{
1837 int f_v = (verbose_level >= 1);
1838
1839 if (f_v) {
1840 cout << "reading polynomial " << polynomial_text << " of degree "
1841 << polynomial_degree << " in "
1842 << polynomial_nb_vars << " variables" << endl;
1843 }
1844
1845 long int *poly_monomials;
1846 int poly_monomials_sz;
1849 int *mon;
1850 int *coeff;
1851 long int a;
1852 int i, j, b, idx;
1853 monomial_ordering_type Monomial_ordering_type = t_PART;
1854
1855 Lint_vec_scan(polynomial_text, poly_monomials, poly_monomials_sz);
1856 cout << "polynomial after scan: ";
1857 Lint_vec_print(cout, poly_monomials, poly_monomials_sz);
1858 cout << endl;
1859
1862
1863 Fq->finite_field_init(2, FALSE /* f_without_tables */, 0 /* verbose_level */);
1864
1865 Poly->init(Fq, polynomial_nb_vars, polynomial_degree,
1866 FALSE /* f_init_incidence_structure */,
1867 Monomial_ordering_type,
1868 0 /* verbose_level */);
1869 mon = NEW_int(polynomial_nb_vars);
1870 coeff = NEW_int(Poly->get_nb_monomials());
1871
1872 Int_vec_zero(coeff, Poly->get_nb_monomials());
1873
1874 for (i = 0; i < poly_monomials_sz; i++) {
1875 Int_vec_zero(mon, polynomial_nb_vars);
1876 a = poly_monomials[i];
1877 j = 0;
1878 while (a) {
1879 b = a % 10;
1880 mon[b]++;
1881 a /= 10;
1882 j++;
1883 }
1884 mon[0] += polynomial_degree - j;
1885 idx = Poly->index_of_monomial(mon);
1886 coeff[idx] = Fq->add(coeff[idx], 1);
1887 }
1888
1889 Poly->print_equation(cout, coeff);
1890 cout << endl;
1891
1892 int *v;
1893 int *f;
1894 int h;
1895 long int *set;
1896 int set_sz = 0;
1899
1900 v = NEW_int(polynomial_nb_vars);
1901 f = NEW_int(Poly->get_P()->N_points);
1902 Poly->polynomial_function(coeff, f, verbose_level);
1903
1904
1905 set = NEW_lint(Poly->get_P()->N_points);
1906
1907 for (h = 0; h < Poly->get_P()->N_points; h++) {
1908 Poly->unrank_point(v, h);
1909 cout << h << " : ";
1910 Int_vec_print(cout, v, polynomial_nb_vars);
1911 cout << " : " << f[h] << endl;
1912 if (f[h] == 1 && v[polynomial_nb_vars - 1] == 1) {
1913 a = Gg.AG_element_rank(2, v, 1, polynomial_nb_vars - 1);
1914 set[set_sz++] = a;
1915 }
1916 }
1917 FREE_int(v);
1918
1919 Sorting.lint_vec_heapsort(set, set_sz);
1920
1921 cout << "We found a set of size " << set_sz << " : " << endl;
1922 Lint_vec_print_fully(cout, set, set_sz);
1923 cout << endl;
1924
1925 investigate_code(set, set_sz, n, f_embellish, verbose_level);
1926
1927 FREE_int(f);
1928
1929}
1930
1932 int f_embellish,
1933 int verbose_level)
1934{
1935 int f_v = (verbose_level >= 1);
1936
1937 if (f_v) {
1938 cout << "coding_theory_domain::do_sylvester_hadamard" << endl;
1939 }
1940 int i;
1941
1942 if (n % 4) {
1943 cout << "for Hadamard matrices, n must be divisible by 4." << endl;
1944 exit(1);
1945 }
1946 int m = n >> 2;
1947 int nb_factors, sz, sz1, j, a;
1948 int *M1;
1949 int *M2;
1950 int H2[4] = {1,1,1,2};
1953
1954 nb_factors = NT.int_log2(m);
1955
1956 cout << "nb_factors = " << nb_factors << endl;
1957
1958 if ((2 << nb_factors) != n) {
1959 cout << "for Sylvester type Hadamard matrices, n must be 4 times a power of two" << endl;
1960 exit(1);
1961 }
1962
1963 M1 = NEW_int(2 * n * n);
1964 M2 = NEW_int(2 * n * n);
1966
1968 F->finite_field_init(3, FALSE /* f_without_tables */, 0);
1969 Int_vec_copy(H2, M1, 4);
1970 sz = 2;
1971 for (i = 0; i < nb_factors; i++) {
1972
1973 cout << "M1=" << endl;
1974 Int_matrix_print(M1, sz, sz);
1975
1977 M1, H2,
1978 sz, 2, M2, sz1,
1979 verbose_level);
1980 Int_vec_copy(M2, M1, sz1 * sz1);
1981
1982 sz = sz1;
1983 }
1984 cout << "Sylvester type Hadamard matrix:" << endl;
1985 Int_matrix_print(M1, sz, sz);
1986 for (i = 0; i < sz; i++) {
1987 for (j = 0; j < sz; j++) {
1988 a = M1[i * sz + j];
1989 M1[(sz + i) * sz + j] = F->negate(a);
1990 }
1991 }
1992
1993 for (i = 0; i < 2 * sz; i++) {
1994 for (j = 0; j < sz; j++) {
1995 a = M1[i * sz + j];
1996 if (a == 2) {
1997 M1[i * sz + j] = 0;
1998 }
1999 }
2000 }
2001 cout << "Sylvester type Hadamard code:" << endl;
2002 Int_matrix_print(M1, 2 * sz, sz);
2003
2004
2005 long int *set;
2006
2007 set = NEW_lint(2 * sz);
2008 for (i = 0; i < 2 * sz; i++) {
2009 set[i] = Gg.AG_element_rank(2, M1 + i * sz, 1, sz);
2010 }
2011
2012 investigate_code(set, 2 * sz, n, f_embellish, verbose_level);
2013
2014 FREE_lint(set);
2015
2016 FREE_int(M1);
2017 FREE_int(M2);
2018 FREE_OBJECT(F);
2019
2020}
2021
2023 std::string &label,
2024 long int *Words,
2025 int nb_words, int n, int f_metric_balls, int radius_of_metric_ball,
2026 int f_enhance, int radius,
2027 int verbose_level)
2028{
2029 int f_v = (verbose_level >= 1);
2030 int nb_rows, nb_cols;
2031 int *v;
2032 int *M;
2033 int *M1;
2034 int *M2;
2035 int *M3; // the holes
2036 int N;
2037 int h, i, j;
2039
2040 if (f_v) {
2041 cout << "coding_theory_domain::code_diagram" << endl;
2042 cout << "n=" << n << endl;
2043 cout << "set:" << endl;
2044 Lint_vec_print(cout, Words, nb_words);
2045 cout << endl;
2046 }
2047
2048 dimensions(n, nb_rows, nb_cols);
2049
2050 if (f_v) {
2051 cout << "coding_theory_domain::code_diagram" << endl;
2052 cout << "nb_rows=" << nb_rows << endl;
2053 cout << "nb_cols=" << nb_cols << endl;
2054 }
2055
2056 v = NEW_int(n);
2057 M1 = NEW_int(nb_rows * nb_cols);
2058 M2 = NEW_int(nb_rows * nb_cols);
2059 M3 = NEW_int(nb_rows * nb_cols);
2060 M = NEW_int(nb_rows * nb_cols);
2061
2062
2063 Int_vec_zero(M1, nb_rows * nb_cols);
2064 Int_vec_zero(M2, nb_rows * nb_cols);
2065 //Orbiter->Int_vec.zero(M3, nb_rows * nb_cols);
2066 for (h = 0; h < nb_rows * nb_cols; h++) {
2067 M3[h] = n + 1;
2068 }
2069
2070 N = 1 << n;
2071
2072 cout << "N=" << N << endl;
2073
2074 cout << "placing codewords" << endl;
2075 for (h = 0; h < N; h++) {
2076 place_binary(h, i, j);
2077 M1[i * nb_cols + j] = h;
2078 //M2[i * nb_cols + j] = 1;
2079 }
2080 cout << "placing position values done" << endl;
2081
2082
2083 cout << "placing codewords" << endl;
2084 Int_vec_zero(M, nb_rows * nb_cols);
2085 for (h = 0; h < nb_words; h++) {
2086 convert_to_binary(n, Words[h], v);
2087 cout << "codeword " << h + 1 << " = " << setw(5) << Words[h];
2088 cout << " : ";
2089 print_binary(n, v);
2090 cout << endl;
2091 place_binary(Words[h], i, j);
2092 M[i * nb_cols + j] = h + 1;
2093 M2[i * nb_cols + j] = 1;
2094 M3[i * nb_cols + j] = 0; // distance is zero
2095
2096 if (f_enhance) {
2097 embellish(M, nb_rows, nb_cols, i, j, h + 1 /* value */, radius);
2098 }
2099 if (f_enhance) {
2100 embellish(M2, nb_rows, nb_cols, i, j, 1 /* value */, radius);
2101 }
2102 }
2103 //int_matrix_print(M, nb_rows, nb_cols);
2104 cout << "placing codewords done" << endl;
2105
2106
2107
2108 if (f_metric_balls) {
2109 int u, t, s, a;
2110 int *set_of_errors;
2111
2112 set_of_errors = NEW_int(radius_of_metric_ball);
2113
2114 for (h = 0; h < nb_words; h++) {
2115 convert_to_binary(n, Words[h], v);
2116 cout << "codeword " << h + 1 << " = " << setw(5) << Words[h];
2117 cout << " : ";
2118 print_binary(n, v);
2119 cout << endl;
2120 place_binary(Words[h], i, j);
2121 for (u = 1; u <= radius_of_metric_ball; u++) {
2123
2124 N = Combi.int_n_choose_k(n, u);
2125 for (t = 0; t < N; t++) {
2126 Combi.unrank_k_subset(t, set_of_errors, n, u);
2127 convert_to_binary(n, Words[h], v);
2128 for (s = 0; s < u; s++) {
2129 a = set_of_errors[s];
2130 v[a] = (v[a] + 1) % 2;
2131 }
2132 place_binary(v, n, i, j);
2133 if (M[i * nb_cols + j]) {
2134 cout << "the metric balls overlap!" << endl;
2135 cout << "h=" << h << endl;
2136 cout << "t=" << t << endl;
2137 cout << "i=" << i << endl;
2138 cout << "j=" << j << endl;
2139 exit(1);
2140 }
2141 M[i * nb_cols + j] = h + 1;
2142 }
2143 }
2144 }
2145 FREE_int(set_of_errors);
2146 }
2147
2148 int *Dist_from_code_enumerator;
2149 int d;
2150 int s, original_value, a;
2151 int *set_of_errors;
2152
2153 set_of_errors = NEW_int(n);
2154
2155 Dist_from_code_enumerator = NEW_int(n + 1);
2156 Int_vec_zero(Dist_from_code_enumerator, n + 1);
2157
2158 for (d = 0; d < n; d++) {
2159 cout << "computing words of distance " << d + 1 << " from the code" << endl;
2160 for (h = 0; h < nb_rows * nb_cols; h++) {
2161 if (M3[h] == d) {
2162 Dist_from_code_enumerator[d]++;
2163 i = h / nb_cols;
2164 j = h % nb_cols;
2165 convert_to_binary(n, h, v);
2166 for (s = 0; s < n; s++) {
2167 original_value = v[s];
2168 v[s] = (v[s] + 1) % 2;
2169 place_binary(v, n, i, j);
2170 a = i * nb_cols + j;
2171 if (M3[a] > d + 1) {
2172 M3[a] = d + 1;
2173 }
2174 v[s] = original_value;
2175 }
2176 }
2177 }
2178 cout << "We found " << Dist_from_code_enumerator[d]
2179 << " words at distance " << d << " from the code" << endl;
2180
2181 if (Dist_from_code_enumerator[d] == 0) {
2182 break;
2183 }
2184 }
2185 cout << "d : # words at distance d from code" << endl;
2186 for (d = 0; d < n; d++) {
2187 cout << d << " : " << Dist_from_code_enumerator[d] << endl;
2188 }
2189 cout << endl;
2190
2191 FREE_int(set_of_errors);
2192
2193 {
2194 char str[1000];
2195
2196 string fname;
2197
2198 fname.assign(label);
2199
2200 sprintf(str, "_%d_%d.tex", n, nb_words);
2201 fname.append(str);
2202
2203 {
2204 ofstream fp(fname);
2206
2207 L.head_easy(fp);
2208 fp << "$$" << endl;
2209 L.print_integer_matrix_tex(fp, M1, nb_rows, nb_cols);
2210 fp << "$$" << endl;
2211
2212
2213
2214 fp << "$$" << endl;
2215 L.print_integer_matrix_tex(fp, M, nb_rows, nb_cols);
2216 fp << "$$" << endl;
2217
2218
2219 L.foot(fp);
2220 }
2221 cout << "Written file " << fname << " of size " << Fio.file_size(fname) << endl;
2222 }
2223
2224 //cout << "M:" << endl;
2225 //int_matrix_print(M, nb_rows, nb_cols);
2226
2227 {
2228 char str[1000];
2229
2230 string fname;
2231
2232 fname.assign(label);
2233
2234 sprintf(str, "_diagram_%d_%d.csv", n, nb_words);
2235 fname.append(str);
2237
2238 Fio.int_matrix_write_csv(fname, M, nb_rows, nb_cols);
2239
2240 cout << "Written file " << fname << " of size " << Fio.file_size(fname) << endl;
2241 }
2242
2243 //cout << "M2:" << endl;
2244 //int_matrix_print(M2, nb_rows, nb_cols);
2245
2246 {
2247 char str[1000];
2248
2249 string fname;
2250
2251 fname.assign(label);
2252
2253 sprintf(str, "_diagram_01_%d_%d.csv", n, nb_words);
2254 fname.append(str);
2256
2257 Fio.int_matrix_write_csv(fname, M2, nb_rows, nb_cols);
2258
2259 cout << "Written file " << fname << " of size " << Fio.file_size(fname) << endl;
2260 }
2261
2262 {
2263 char str[1000];
2264
2265 string fname;
2266
2267 fname.assign(label);
2268
2269 sprintf(str, "_holes_%d_%d.csv", n, nb_words);
2270 fname.append(str);
2272
2273 Fio.int_matrix_write_csv(fname, M3, nb_rows, nb_cols);
2274
2275 cout << "Written file " << fname << " of size " << Fio.file_size(fname) << endl;
2276 }
2277
2278 FREE_int(v);
2279 FREE_int(M1);
2280 FREE_int(M2);
2281 FREE_int(M3);
2282 FREE_int(M);
2283
2284 if (f_v) {
2285 cout << "coding_theory_domain::code_diagram done" << endl;
2286 }
2287}
2288
2290 int nb_words, int n, int f_embellish, int verbose_level)
2291{
2292 int f_v = (verbose_level >= 1);
2293 int nb_rows, nb_cols;
2294 int *v;
2295 int *M;
2296 int *M1;
2297 int *M2;
2298 int N;
2299 //int D, d;
2300 int h, i, j;
2302
2303 if (f_v) {
2304 cout << "coding_theory_domain::investigate_code" << endl;
2305 cout << "n=" << n << endl;
2306 cout << "set:" << endl;
2307 Lint_vec_print(cout, Words, nb_words);
2308 cout << endl;
2309 }
2310
2311 dimensions(n, nb_rows, nb_cols);
2312
2313 if (f_v) {
2314 cout << "coding_theory_domain::investigate_code" << endl;
2315 cout << "nb_rows=" << nb_rows << endl;
2316 cout << "nb_cols=" << nb_cols << endl;
2317 }
2318
2319 v = NEW_int(n);
2320 M1 = NEW_int(nb_rows * nb_cols);
2321 M2 = NEW_int(nb_rows * nb_cols);
2322 M = NEW_int(nb_rows * nb_cols);
2323
2324
2325 Int_vec_zero(M1, nb_rows * nb_cols);
2326 Int_vec_zero(M2, nb_rows * nb_cols);
2327
2328
2329 N = 1 << n;
2330
2331 cout << "N=" << N << endl;
2332
2333 cout << "placing codewords" << endl;
2334 for (h = 0; h < N; h++) {
2335 place_binary(h, i, j);
2336 M1[i * nb_cols + j] = h;
2337 //M2[i * nb_cols + j] = 1;
2338 }
2339 cout << "placing position values done" << endl;
2340
2341
2342#if 0
2343 colored_graph *C;
2344
2345 C = new colored_graph;
2346
2347 C->init_adjacency_no_colors(int nb_points, int *Adj, int verbose_level);
2348#endif
2349
2350
2351 char fname[1000];
2352
2353 sprintf(fname, "code_%d_%d.tex", n, nb_words);
2354
2355 {
2356 ofstream fp(fname);
2358
2359 L.head_easy(fp);
2360 fp << "$$" << endl;
2361 L.print_integer_matrix_tex(fp, M1, nb_rows, nb_cols);
2362 fp << "$$" << endl;
2363
2364
2365
2366 cout << "placing codewords" << endl;
2367 Int_vec_zero(M, nb_rows * nb_cols);
2368 for (h = 0; h < nb_words; h++) {
2369 convert_to_binary(n, Words[h], v);
2370 cout << "codeword " << h + 1 << " = " << setw(5) << Words[h];
2371 cout << " : ";
2372 print_binary(n, v);
2373 cout << endl;
2374 place_binary(Words[h], i, j);
2375 M[i * nb_cols + j] = h + 1;
2376 M2[i * nb_cols + j] = 1;
2377 if (f_embellish) {
2378 embellish(M, nb_rows, nb_cols, i, j, h + 1, 3);
2379 }
2380 }
2381 //int_matrix_print(M, nb_rows, nb_cols);
2382 cout << "placing codewords done" << endl;
2383
2384 fp << "$$" << endl;
2385 L.print_integer_matrix_tex(fp, M, nb_rows, nb_cols);
2386 fp << "$$" << endl;
2387
2388
2389 L.foot(fp);
2390 }
2391 cout << "Written file " << fname << " of size " << Fio.file_size(fname) << endl;
2392
2393 cout << "M2:" << endl;
2394 Int_matrix_print(M2, nb_rows, nb_cols);
2395
2396 {
2397 char str[1000];
2398 string fname;
2400
2401 sprintf(str, "code_matrix_%d_%d.csv", nb_rows, nb_cols);
2402 fname.assign(str);
2403 Fio.int_matrix_write_csv(fname, M2, nb_rows, nb_cols);
2404
2405 }
2406
2407
2408#if 0
2409 {
2410 colored_graph *CG;
2411
2412 CG = NEW_OBJECT(colored_graph);
2413
2414 cout << "before create_Levi_graph_from_incidence_matrix" << endl;
2415 CG->create_Levi_graph_from_incidence_matrix(M, nb_rows, nb_cols,
2416 FALSE /* f_point_labels */, NULL /* *point_labels */,
2417 verbose_level);
2418
2419 cout << "after create_Levi_graph_from_incidence_matrix" << endl;
2420
2421 char fname[1000];
2422
2423
2424 sprintf(fname, "code_%d_%d_Levi_%d_%d.bin",
2425 n, nb_words, nb_rows, nb_cols);
2426 CG->save(fname, verbose_level);
2427 delete CG;
2428 }
2429#endif
2430
2431
2433 int *coeff;
2434 int *f;
2435 int *g;
2436
2438
2439
2440 cout << "before BF->init, n=" << n << endl;
2441 BF->init(n, 0 /*verbose_level*/);
2442
2443 cout << "BF->Poly[n].get_nb_monomials()=" << BF->Poly[n].get_nb_monomials() << endl;
2444 coeff = NEW_int(BF->Poly[n].get_nb_monomials());
2445 f = NEW_int(N);
2446 g = NEW_int(N);
2447
2448 Int_vec_zero(f, N);
2449 for (h = 0; h < nb_words; h++) {
2450 f[Words[h]] = 1;
2451 }
2452
2453 cout << "computing the polynomial representation: " << endl;
2454
2455
2457 f /* func */, coeff, 0 /*verbose_level*/);
2458 //BF->search_for_bent_functions(verbose_level);
2459
2460
2461
2462 cout << "The representation as polynomial is: ";
2463
2464 cout << " : ";
2465 BF->Poly[BF->n].print_equation(cout, coeff);
2466 cout << " : ";
2467 //evaluate_projectively(poly, f_proj);
2468 BF->evaluate(coeff, g);
2469 //int_vec_print(cout, g, BF->Q);
2470 cout << endl;
2471
2472
2473 for (h = 0; h < BF->Q; h++) {
2474 if (f[h] != g[h]) {
2475 cout << "f[h] != g[h], h = " << h << ", an error has occured" << endl;
2476 }
2477 }
2478
2479
2480 FREE_OBJECT(BF);
2481 FREE_OBJECT(coeff);
2482 FREE_OBJECT(f);
2483 FREE_OBJECT(g);
2484
2485
2486#if 0
2487 D = INT_MAX;
2488 for (i = 0; i < nb_words; i++) {
2489 for (j = i + 1; j < nb_words; j++) {
2490 d = distance(n, Words[i], Words[j]);
2491 //cout << "The distance between word " << i << " and word " << j << " is " << d << endl;
2492 D = MINIMUM(D, d);
2493 }
2494 }
2495
2496 cout << "minimum distance d = " << D << endl;
2497 cout << "attained for:" << endl;
2498 for (i = 0; i < nb_words; i++) {
2499 for (j = i + 1; j < nb_words; j++) {
2500 if (distance(n, Words[i], Words[j]) == D) {
2501 cout << i << ", " << j << endl;
2502 }
2503 }
2504 }
2505#endif
2506
2507}
2508
2510 int n,
2511 std::vector<std::string> &long_code_generators_text,
2512 int f_nearest_codeword,
2513 std::string &nearest_codeword_text,
2514 int verbose_level)
2515{
2516 int f_v = (verbose_level >= 1);
2517
2518 if (f_v) {
2519 cout << "coding_theory_domain::do_long_code" << endl;
2520 }
2521
2522 int i, j;
2523 int *genma;
2524 int k;
2525
2526 k = long_code_generators_text.size();
2527 genma = NEW_int(k * n);
2528 Int_vec_zero(genma, k * n);
2529 for (i = 0; i < k; i++) {
2530 long int *set;
2531 int sz;
2532
2533
2534 orbiter_kernel_system::Orbiter->get_lint_vector_from_label(long_code_generators_text[i], set, sz, verbose_level);
2535
2536 for (j = 0; j < sz; j++) {
2537 genma[i * n + set[j]] = 1;
2538 }
2539 FREE_lint(set);
2540 }
2541
2542 cout << "genma:" << endl;
2543 Int_matrix_print(genma, k, n);
2544
2545 {
2546 char str[1000];
2547 string fname;
2549
2550 sprintf(str, "long_code_genma_n%d_k%d.csv", n, k);
2551 fname.assign(str);
2552 Fio.int_matrix_write_csv(fname, genma, k, n);
2553 cout << "Written file " << fname << " of size " << Fio.file_size(fname) << endl;
2554 }
2555
2556 int sz;
2557 int *message;
2558 int *code_word;
2559 int *M;
2560 int nb_rows, nb_cols;
2561 int h, r, c;
2563 int *Wt;
2564 int wt;
2565 //int N;
2566
2567 //N = 1 << n;
2568 dimensions_N(n, nb_rows, nb_cols);
2569
2570 if (f_v) {
2571 cout << "n=" << n << endl;
2572 cout << "nb_rows=" << nb_rows << endl;
2573 cout << "nb_cols=" << nb_cols << endl;
2574 }
2575
2576 sz = 1 << k;
2577 message = NEW_int(k);
2578 code_word = NEW_int(n);
2579 M = NEW_int(nb_rows * nb_cols);
2580
2582
2584 F->finite_field_init(2, FALSE /* f_without_tables */, 0);
2585
2586 Wt = NEW_int(sz);
2587 Int_vec_zero(Wt, sz);
2588
2589 for (i = 0; i < sz; i++) {
2590 Gg.AG_element_unrank(2, message, 1, k, i);
2591 F->Linear_algebra->mult_matrix_matrix(message, genma,
2592 code_word, 1, k, n, 0 /* verbose_level*/);
2593
2594 Int_vec_zero(M, nb_rows * nb_cols);
2595 wt = 0;
2596 for (h = 0; h < n; h++) {
2597 if (code_word[h]) {
2598 wt++;
2599 }
2600 }
2601 Wt[i] = wt;
2602 for (h = 0; h < n; h++) {
2603 if (code_word[h]) {
2604 place_binary(h, r, c);
2605 M[r * nb_cols + c] = 1;
2606 }
2607 }
2608 {
2609 char str[1000];
2610 string fname;
2612
2613 sprintf(str, "long_code_genma_n%d_k%d_codeword_%d.csv", n, k, i);
2614 fname.assign(str);
2615 Fio.int_matrix_write_csv(fname, M, nb_rows, nb_cols);
2616 cout << "Written file " << fname << " of size " << Fio.file_size(fname) << endl;
2617 }
2618 }
2619
2620 {
2621 cout << "Weight distribution:";
2623
2624 C.init(Wt, sz, FALSE, 0);
2625 C.print_first(FALSE /* f_backwards */);
2626 cout << endl;
2627
2628 cout << "i : weight of the i-th codeword" << endl;
2629 for (i = 0; i < sz; i++) {
2630 cout << i << " : " << Wt[i] << endl;
2631 }
2632 }
2633
2634
2636 int *f;
2637 int *g;
2638 int ln;
2639
2641
2642
2643 ln = log2(n);
2644
2645 cout << "before BF->init, ln=" << ln << endl;
2646 BF->init(ln, 0 /*verbose_level*/);
2647
2648 f = NEW_int(n);
2649 g = NEW_int(n);
2650
2651
2652 if (f_nearest_codeword) {
2653
2654 cout << "nearest codeword" << endl;
2655
2656 long int *nearest_codeword_set;
2657 int nearest_codeword_sz;
2658 int *word;
2659
2660
2661 Lint_vec_scan(nearest_codeword_text,
2662 nearest_codeword_set, nearest_codeword_sz);
2663
2664
2665 word = NEW_int(n);
2666 Int_vec_zero(word, n);
2667 for (j = 0; j < nearest_codeword_sz; j++) {
2668 word[nearest_codeword_set[j]] = 1;
2669 }
2670 for (h = 0; h < n; h++) {
2671 if (word[h]) {
2672 f[h] = -1;
2673 }
2674 else {
2675 f[h] = 1;
2676 }
2677 }
2678
2679 BF->apply_Walsh_transform(f, g);
2680 Int_vec_zero(M, nb_rows * nb_cols);
2681 for (h = 0; h < n; h++) {
2682 place_binary(h, r, c);
2683 M[r * nb_cols + c] = g[h];
2684 }
2685 {
2686 char str[1000];
2687 string fname;
2689
2690 sprintf(str, "long_code_genma_n%d_k%d_nearest_codeword_fourier.csv", n, k);
2691 fname.assign(str);
2692 Fio.int_matrix_write_csv(fname, M, nb_rows, nb_cols);
2693 cout << "Written file " << fname << " of size " << Fio.file_size(fname) << endl;
2694 }
2695
2696 Int_vec_zero(M, nb_rows * nb_cols);
2697 for (h = 0; h < n; h++) {
2698 if (word[h]) {
2699 place_binary(h, r, c);
2700 M[r * nb_cols + c] = 1;
2701 }
2702 }
2703 {
2704 char str[1000];
2705 string fname;
2707
2708 sprintf(str, "long_code_genma_n%d_k%d_nearest_codeword.csv", n, k);
2709 fname.assign(str);
2710 Fio.int_matrix_write_csv(fname, M, nb_rows, nb_cols);
2711 cout << "Written file " << fname << " of size " << Fio.file_size(fname) << endl;
2712 }
2713
2714 int d;
2715 int *D;
2716
2717 D = NEW_int(sz);
2718 for (i = 0; i < sz; i++) {
2719 Gg.AG_element_unrank(2, message, 1, k, i);
2720 F->Linear_algebra->mult_matrix_matrix(message, genma,
2721 code_word, 1, k, n, 0 /* verbose_level*/);
2722
2723 d = 0;
2724 for (h = 0; h < n; h++) {
2725 if (word[h] != code_word[h]) {
2726 d++;
2727 }
2728 D[i] = d;
2729 }
2730 }
2731 {
2732 cout << "distance distribution:";
2734
2735 C.init(D, sz, FALSE, 0);
2736 C.print_first(FALSE /* f_backwards */);
2737 cout << endl;
2738
2739 cout << "i : distance from the i-th codeword" << endl;
2740 for (i = 0; i < sz; i++) {
2741 cout << i << " : " << D[i] << endl;
2742 }
2743 }
2744 FREE_int(D);
2745
2746
2747 }
2748 else {
2749 cout << "no nearest codeword option" << endl;
2750 }
2751
2752 FREE_int(message);
2753 FREE_int(code_word);
2754 FREE_int(M);
2755 FREE_OBJECT(F);
2756
2757
2758}
2759
2760void coding_theory_domain::embellish(int *M, int nb_rows, int nb_cols, int i0, int j0, int a, int rad)
2761{
2762 int i, j, u, v;
2763
2764#if 0
2765 int ij[] = {
2766 -1, -1,
2767 -1, 0,
2768 -1, 1,
2769 0, -1,
2770 0, 1,
2771 1, -1,
2772 1, 0,
2773 1, 1,
2774 -2,-2,
2775 -2,-1,
2776 -2,0,
2777 -2,1,
2778 -2,2,
2779 -2,-2,
2780 -2,2,
2781 -1,-2,
2782 -1,2,
2783 0,-2,
2784 0,2,
2785 1,-2,
2786 1,2,
2787 2,-2,
2788 2,-1,
2789 2,0,
2790 2,1,
2791 2,2,s
2792 };
2793#endif
2794 for (u = -rad; u <= rad; u++) {
2795 for (v = -rad; v <= rad; v++) {
2796 i = i0 + u;
2797 j = j0 + v;
2798 place_entry(M, nb_rows, nb_cols, i, j, a);
2799 }
2800 }
2801#if 0
2802 for (h = 0; h < 8 + 18; h++) {
2803 i = i0 + ij[h * 2 + 0];
2804 j = j0 + ij[h * 2 + 1];
2805 place_entry(M, nb_rows, nb_cols, i, j, a);
2806 }
2807#endif
2808}
2809
2810void coding_theory_domain::place_entry(int *M, int nb_rows, int nb_cols, int i, int j, int a)
2811{
2812 if (i < 0) {
2813 return;
2814 }
2815 if (j < 0) {
2816 return;
2817 }
2818 if (i >= nb_rows) {
2819 return;
2820 }
2821 if (j >= nb_cols) {
2822 return;
2823 }
2824 M[i * nb_cols + j] = a;
2825}
2826
2827void coding_theory_domain::do_it(int n, int r, int a, int c, int seed, int verbose_level)
2828{
2829 int N;
2830 int i, j, h, s;
2831 int nb_rows, nb_cols;
2832 int *v;
2833 int *W;
2835
2836 N = 1 << n;
2837
2838 cout << "N=" << N << endl;
2839
2840 for (h = 0; h < N; h++) {
2841 place_binary(h, i, j);
2842 cout << h << " : (" << i << "," << j << ")" << endl;
2843 }
2844
2845 dimensions(n, nb_rows, nb_cols);
2846 int *M;
2847 int D, d;
2848
2849 v = NEW_int(n);
2850 W = NEW_int(r);
2851 M = NEW_int(nb_rows * nb_cols);
2852 Int_vec_zero(M, nb_rows * nb_cols);
2853
2854 s = seed;
2855 for (h = 0; h < r; h++) {
2856 W[h] = s;
2857 convert_to_binary(n, s, v);
2858 cout << "s = " << setw(5) << s;
2859 cout << " : ";
2860 print_binary(n, v);
2861 cout << endl;
2862 place_binary(s, i, j);
2863 M[i * nb_cols + j] = 1;
2864 s = (a * s + c) % N;
2865 }
2866
2867 Int_matrix_print(M, nb_rows, nb_cols);
2868
2869 L.print_integer_matrix_tex(cout, M, nb_rows, nb_cols);
2870
2871 D = INT_MAX;
2872 for (i = 0; i < r; i++) {
2873 for (j = i + 1; j < r; j++) {
2874 d = distance(n, W[i], W[j]);
2875 cout << "The distance between word " << i << " and word " << j << " is " << d << endl;
2876 D = MINIMUM(D, d);
2877 }
2878 }
2879
2880 cout << "minimum distance d = " << D << endl;
2881 cout << "attained for:" << endl;
2882 for (i = 0; i < r; i++) {
2883 for (j = i + 1; j < r; j++) {
2884 if (distance(n, W[i], W[j]) == D) {
2885 cout << i << ", " << j << endl;
2886 }
2887 }
2888 }
2889}
2890
2891void coding_theory_domain::dimensions(int n, int &nb_rows, int &nb_cols)
2892{
2893 int i, j;
2894
2895 place_binary((1 << n) - 1, i, j);
2896 nb_rows = i + 1;
2897 nb_cols = j + 1;
2898}
2899
2900void coding_theory_domain::dimensions_N(int N, int &nb_rows, int &nb_cols)
2901{
2902 int i, j;
2903 long int a, b;
2905
2906 a = NT.int_log2(N);
2907 b = 1 << a;
2908 place_binary(b - 1, i, j);
2909 nb_rows = i + 1;
2910 nb_cols = j + 1;
2911}
2912
2914{
2915 int c;
2916
2917 for (c = n - 1; c >= 0; c--) {
2918 cout << v[c];
2919 }
2920}
2921
2922void coding_theory_domain::convert_to_binary(int n, long int h, int *v)
2923{
2924 int c;
2925
2926 for (c = 0; c < n; c++) {
2927 if (h % 2) {
2928 v[c] = 1;
2929 }
2930 else {
2931 v[c] = 0;
2932 }
2933 h >>= 1;
2934 }
2935}
2936
2937int coding_theory_domain::distance(int n, int a, int b)
2938{
2939 int c, d = 0;
2940
2941 for (c = 0; c < n; c++) {
2942 if (a % 2 != b % 2) {
2943 d++;
2944 }
2945 a >>= 1;
2946 b >>= 1;
2947 }
2948 return d;
2949}
2950
2951void coding_theory_domain::place_binary(long int h, int &i, int &j)
2952{
2953 int o[2];
2954 int c;
2955
2956 o[0] = 1;
2957 o[1] = 0;
2958 i = 0;
2959 j = 0;
2960 for (c = 0; h; c++) {
2961 if (h % 2) {
2962 i += o[0];
2963 j += o[1];
2964 }
2965 h >>= 1;
2966 if (c % 2) {
2967 o[0] = o[1] << 1;
2968 o[1] = 0;
2969 }
2970 else {
2971 o[1] = o[0];
2972 o[0] = 0;
2973 }
2974 }
2975}
2976
2977void coding_theory_domain::place_binary(int *v, int n, int &i, int &j)
2978{
2979 int o[2];
2980 int c;
2981
2982 o[0] = 1;
2983 o[1] = 0;
2984 i = 0;
2985 j = 0;
2986 for (c = 0; c < n; c++) {
2987 if (v[c]) {
2988 i += o[0];
2989 j += o[1];
2990 }
2991 if (c % 2) {
2992 o[0] = o[1] << 1;
2993 o[1] = 0;
2994 }
2995 else {
2996 o[1] = o[0];
2997 o[0] = 0;
2998 }
2999 }
3000}
3001
3002
3003
3004
3007 std::string &label,
3008 int m, int n, std::string &genma_text,
3009 int verbose_level)
3010{
3011 int f_v = (verbose_level >= 1);
3012 int *M;
3013 int sz;
3014 int i;
3015 int *M2;
3016
3017 if (f_v) {
3018 cout << "coding_theory_domain::field_reduction" << endl;
3019 }
3020
3022
3024
3025 Sub->init(FQ, Fq, verbose_level);
3026
3027 if (f_v) {
3028 Sub->print_embedding();
3029 }
3030
3031 //Orbiter->Int_vec.scan(genma_text, M, sz);
3032 Get_int_vector_from_label(genma_text, M, sz, verbose_level);
3033
3034 if (sz != m * n) {
3035 cout << "sz != m * n" << endl;
3036 exit(1);
3037 }
3038
3039 M2 = NEW_int(Sub->s * m * Sub->s * n);
3040
3041 for (i = 0; i < m; i++) {
3042 Sub->field_reduction(M + i * n, n, M2 + (i * Sub->s) * Sub->s * n,
3043 verbose_level);
3044 }
3045
3046
3047 {
3048 char str[1000];
3049 string fname;
3050 char title[1000];
3051 char author[1000];
3052
3053 snprintf(str, 1000, "field_reduction_Q%d_q%d_%d_%d.tex", FQ->q, Fq->q, m, n);
3054 fname.assign(str);
3055 snprintf(title, 1000, "Field Reduction");
3056 //strcpy(author, "");
3057 author[0] = 0;
3058
3059
3060 {
3061 ofstream ost(fname);
3063
3064 L.head(ost,
3065 FALSE /* f_book*/,
3066 TRUE /* f_title */,
3067 title, author,
3068 FALSE /* f_toc */,
3069 FALSE /* f_landscape */,
3070 TRUE /* f_12pt */,
3071 TRUE /* f_enlarged_page */,
3072 TRUE /* f_pagenumbers */,
3073 NULL /* extra_praeamble */);
3074
3075
3076
3077 ost << "$$" << endl;
3078 ost << "\\left[" << endl;
3079 L.int_matrix_print_tex(ost, M2, m * Sub->s, Sub->s * n);
3080 ost << "\\right]" << endl;
3081 ost << "$$" << endl;
3082
3083 Int_vec_print_fully(ost, M2, m * Sub->s * Sub->s * n);
3084 ost << "\\\\" << endl;
3085
3086
3087
3088 L.foot(ost);
3089
3090 }
3092
3093 cout << "coding_theory_domain::field_reduction written "
3094 "file " << fname << " of size "
3095 << Fio.file_size(fname) << endl;
3096
3097 string fname_csv;
3098
3099 fname_csv.assign(label);
3100 fname_csv.append(".csv");
3101
3102 Fio.int_matrix_write_csv(fname_csv, M2, m * Sub->s, Sub->s * n);
3103 }
3104
3105 FREE_int(M2);
3106 FREE_OBJECT(Sub);
3107
3108 if (f_v) {
3109 cout << "coding_theory_domain::field_reduction done" << endl;
3110 }
3111}
3112
3115 std::string &text, std::string &fname,
3116 int verbose_level)
3117{
3118 int f_v = (verbose_level >= 1);
3119
3120 if (f_v) {
3121 cout << "coding_theory_domain::CRC_encode_text e=" << Nth->F->e << endl;
3122 }
3123 int l, i, j, h, a;
3124 char c;
3125 int *encoding;
3126 int len;
3127
3128
3129 l = text.size();
3130 encoding = NEW_int(5 * l);
3131 j = 0;
3132 for (i = 0; i < l; i++) {
3133 c = text[i];
3134 if (c >= 'A' && c <= 'Z') {
3135 a = 3 + c - 'A';
3136 }
3137 else if (c >= 'a' && c <= 'z') {
3138 a = 3 + c - 'a';
3139 }
3140 else if (c == ' ') {
3141 a = 0;
3142 }
3143 else if (c == ',') {
3144 a = 1;
3145 }
3146 else if (c == '.') {
3147 a = 2;
3148 }
3149 else {
3150 //cout << "unknown character " << c << " skipping" << endl;
3151 //exit(1);
3152 continue;
3153 }
3154 for (h = 0; h < 5; h++) {
3155 encoding[j++] = a % 2;
3156 a >>= 1;
3157 }
3158 }
3159
3160 len = j;
3161
3162 int degree;
3163
3164 degree = Nth->FX->degree(CRC_poly);
3165 if (f_v) {
3166 cout << "coding_theory_domain::CRC_encode_text degree=" << degree << endl;
3167 }
3168
3169 int nb_rows;
3170 int nb_cols;
3171 int I, IP, IPq;
3172 int nb_bits;
3173
3174 nb_rows = 80;
3175 nb_cols = 72;
3176
3177 nb_bits = Nth->F->e;
3178
3179 IP = nb_rows * nb_cols + nb_rows + nb_cols;
3180
3181 IPq = IP / nb_bits;
3182
3183
3184
3185 int *v;
3186 int *information;
3187 int *information_and_parity;
3188 int *information_and_parity_Fq;
3189 int *codeword_Fq;
3191
3192 information = NEW_int(nb_rows * nb_cols);
3193 information_and_parity = NEW_int(nb_rows * nb_cols + nb_rows + nb_cols);
3194 information_and_parity_Fq = NEW_int(IPq);
3195 codeword_Fq = NEW_int(IPq + degree);
3196
3197
3198 int *row_parity;
3199 int *col_parity;
3200
3201 row_parity = NEW_int(nb_rows);
3202 col_parity = NEW_int(nb_cols);
3203
3204 v = NEW_int(nb_bits);
3205
3206
3207 for (I = 0; I * nb_rows * nb_cols < len; I++) {
3208
3209 Int_vec_zero(information, nb_rows * nb_cols);
3210
3211 for (j = 0; j < nb_rows * nb_cols; j++) {
3212 h = I * nb_rows * nb_cols + j;
3213 if (h < len) {
3214 information[j] = encoding[h];
3215 }
3216 else {
3217 information[j] = 0;
3218 }
3219 }
3221 string fname_base;
3222 string fname_out;
3224 char str[1000];
3225
3226
3227 fname_base.assign(fname);
3228 String.chop_off_extension(fname_base);
3229
3230 sprintf(str, "_word%d", I);
3231 fname_base.append(str);
3232
3233
3234
3235 fname_out.assign(fname_base);
3236 fname_out.append("_information.csv");
3237
3238
3239 //Fio.int_vec_write_csv(encoding, 5 * l, fname, "encoding");
3240 Fio.int_matrix_write_csv(fname_out, information, nb_rows, nb_cols);
3241 cout << "Written file " << fname_out << " of size " << Fio.file_size(fname_out) << endl;
3242
3243 for (j = 0; j < nb_cols; j++) {
3244 a = 0;
3245 for (i = 0; i < nb_rows; i++) {
3246 a += information[i * nb_cols + j];
3247 a %= 2;
3248 }
3249 col_parity[j] = a;
3250 }
3251
3252
3253 fname_out.assign(fname_base);
3254 fname_out.append("_col_parity.csv");
3255
3256
3257 //Fio.int_vec_write_csv(encoding, 5 * l, fname, "encoding");
3258 Fio.int_matrix_write_csv(fname_out, col_parity, 1, nb_cols);
3259 cout << "Written file " << fname_out << " of size " << Fio.file_size(fname_out) << endl;
3260
3261
3262 for (i = 0; i < nb_rows; i++) {
3263 a = 0;
3264 for (j = 0; j < nb_cols; j++) {
3265 a += information[i * nb_cols + j];
3266 a %= 2;
3267 }
3268 row_parity[i] = a;
3269 }
3270
3271 fname_out.assign(fname_base);
3272 fname_out.append("_row_parity.csv");
3273
3274
3275 //Fio.int_vec_write_csv(encoding, 5 * l, fname, "encoding");
3276 Fio.int_matrix_write_csv(fname_out, row_parity, 1, nb_rows);
3277 cout << "Written file " << fname_out << " of size " << Fio.file_size(fname_out) << endl;
3278
3279 Int_vec_copy(information, information_and_parity, nb_rows * nb_cols);
3280 Int_vec_copy(row_parity, information_and_parity + nb_rows * nb_cols, nb_rows);
3281 Int_vec_copy(col_parity, information_and_parity + nb_rows * nb_cols + nb_rows, nb_cols);
3282
3283
3284 fname_out.assign(fname_base);
3285 fname_out.append("_IP.csv");
3286
3287
3288 //Fio.int_vec_write_csv(encoding, 5 * l, fname, "encoding");
3289 Fio.int_matrix_write_csv(fname_out, information_and_parity, 1, nb_rows * nb_cols + nb_rows + nb_cols);
3290 cout << "Written file " << fname_out << " of size " << Fio.file_size(fname_out) << endl;
3291
3292
3293 for (i = 0; i < IPq; i++) {
3294 for (h = 0; h < nb_bits; h++) {
3295 v[h] = information_and_parity[i * nb_bits + h];
3296 }
3297 a = GG.AG_element_rank(2, v, 1, nb_bits);
3298 information_and_parity_Fq[i] = a;
3299 }
3300
3301 fname_out.assign(fname_base);
3302 fname_out.append("_IPq.csv");
3303
3304 Fio.int_matrix_write_csv(fname_out, information_and_parity_Fq, 1, IPq);
3305 cout << "Written file " << fname_out << " of size " << Fio.file_size(fname_out) << endl;
3306
3308
3309 Nth->FX->create_object_of_degree(P, IPq + degree);
3310 for (i = 0; i < IPq; i++) {
3311 a = information_and_parity_Fq[i];
3312 Nth->FX->s_i(P, i + degree) = a;
3313 }
3314
3315 cout << "P=";
3316 Nth->FX->print_object(P, cout);
3317 cout << endl;
3318
3321
3322 Nth->FX->create_object_of_degree(Q, IPq + degree);
3323 Nth->FX->create_object_of_degree(R, degree);
3324
3325 Nth->FX->division_with_remainder(P, CRC_poly, Q, R, verbose_level);
3326
3327 cout << "R=";
3328 Nth->FX->print_object(R, cout);
3329 cout << endl;
3330
3331 Int_vec_copy(information_and_parity_Fq, codeword_Fq + degree, IPq);
3332 for (i = 0; i < degree; i++) {
3333 a = Nth->FX->s_i(R, i);
3334 codeword_Fq[i] = a;
3335 }
3336
3337 fname_out.assign(fname_base);
3338 fname_out.append("_codeword_Fq.csv");
3339
3340 Fio.int_matrix_write_csv(fname_out, codeword_Fq, 1, IPq + degree);
3341 cout << "Written file " << fname_out << " of size " << Fio.file_size(fname_out) << endl;
3342
3343
3344 }
3345
3346 if (f_v) {
3347 cout << "coding_theory_domain::CRC_encode_text done" << endl;
3348 }
3349}
3350
3352 std::string &fname, int verbose_level)
3353{
3354 int l, i, j, h, a;
3355 char c;
3356 long int *encoding;
3357 int len;
3358
3359
3360 l = text.size();
3361 encoding = NEW_lint(5 * l);
3362 j = 0;
3363 for (i = 0; i < l; i++) {
3364 c = text[i];
3365 if (c >= 'A' && c <= 'Z') {
3366 a = 3 + c - 'A';
3367 }
3368 else if (c >= 'a' && c <= 'z') {
3369 a = 3 + c - 'a';
3370 }
3371 else if (c == ' ') {
3372 a = 0;
3373 }
3374 else if (c == ',') {
3375 a = 1;
3376 }
3377 else if (c == '.') {
3378 a = 2;
3379 }
3380 else {
3381 cout << "unknown character " << c << " skipping" << endl;
3382 //exit(1);
3383 continue;
3384 }
3385 for (h = 0; h < 5; h++) {
3386 encoding[j++] = a % 2;
3387 a >>= 1;
3388 }
3389 }
3390
3391 len = j;
3392
3394
3395 //Fio.int_vec_write_csv(encoding, 5 * l, fname, "encoding");
3396 Fio.lint_matrix_write_csv(fname, encoding, 1, len);
3397 cout << "Written file " << fname << " of size " << Fio.file_size(fname) << endl;
3398}
3399
3400
3401void coding_theory_domain::field_induction(std::string &fname_in,
3402 std::string &fname_out, int nb_bits, int verbose_level)
3403{
3404 int i, h, len, len2;
3405 long int *M;
3406 long int a;
3407 long int *M2;
3408 int *v;
3409 int m, n;
3411
3412
3414
3415 cout << "Reading file " << fname_in << " of size " << Fio.file_size(fname_in) << endl;
3416 Fio.lint_matrix_read_csv(fname_in, M, m, n, verbose_level);
3417 len = m * n;
3418 len2 = (len + nb_bits - 1) / nb_bits;
3419 v = NEW_int(nb_bits);
3420 M2 = NEW_lint(len2);
3421 for (i = 0; i < len2; i++) {
3422 for (h = 0; h < nb_bits; h++) {
3423 v[h] = M[i * nb_bits + h];
3424 }
3425 a = GG.AG_element_rank(2, v, 1, nb_bits);
3426 M2[i] = a;
3427 }
3428 Fio.lint_matrix_write_csv(fname_out, M2, 1, len2);
3429 cout << "Written file " << fname_out << " of size " << Fio.file_size(fname_out) << endl;
3430
3431}
3432
3433int coding_theory_domain::Hamming_distance(int *v1, int *v2, int n)
3434{
3435 int i, d;
3436
3437 d = 0;
3438 for (i = 0; i < n; i++) {
3439 if (v1[i] != v2[i]) {
3440 d++;
3441 }
3442 }
3443 return d;
3444}
3445
3446
3448{
3449 int i, d, u, v;
3450
3451 d = 0;
3452 for (i = 0; i < n; i++) {
3453 u = a % 2;
3454 v = b % 2;
3455 if (u != v) {
3456 d++;
3457 }
3458 a >>= 1;
3459 b >>= 1;
3460 }
3461 return d;
3462}
3463
3464
3467 int n,
3468 std::string &poly_coeffs,
3469 int verbose_level)
3470{
3471 int f_v = (verbose_level >= 1);
3472
3473 if (f_v) {
3474 cout << "coding_theory_domain::generator_matrix_cyclic_code" << endl;
3475 }
3476
3477 int *coeffs;
3478 int sz;
3479 int k;
3480 int d;
3481 int *M;
3482 int *v;
3483 int i, j;
3484 long int rk;
3485 long int *Rk;
3486
3487 Int_vec_scan(poly_coeffs, coeffs, sz);
3488 d = sz - 1;
3489 k = n - d;
3490
3491 M = NEW_int(k * n);
3492 Int_vec_zero(M, k * n);
3493 for (i = 0; i < k; i++) {
3494 Int_vec_copy(coeffs, M + i * n + i, d + 1);
3495 }
3496
3497 cout << "generator matrix:" << endl;
3498 Int_matrix_print(M, k, n);
3499
3500
3501 cout << "generator matrix:" << endl;
3502 Int_vec_print_fully(cout, M, k * n);
3503 cout << endl;
3504
3505 v = NEW_int(k);
3506 Rk = NEW_lint(n);
3507 for (j = 0; j < n; j++) {
3508 for (i = 0; i < k; i++) {
3509 v[i] = M[i * n + j];
3510 }
3512 v, 1, k, rk);
3513 Rk[j] = rk;
3514 }
3515
3516 cout << "generator matrix in projective points:" << endl;
3517 Lint_vec_print_fully(cout, Rk, n);
3518 cout << endl;
3519
3520 if (f_v) {
3521 cout << "coding_theory_domain::generator_matrix_cyclic_code" << endl;
3522 }
3523}
3524
3525
3526/*
3527 * twocoef.cpp
3528 *
3529 * Created on: Oct 22, 2020
3530 * Author: alissabrown
3531 *
3532 * Received a lot of help from Anton and the recursive function in the possibleC function is modeled after code found at
3533 * https://www.geeksforgeeks.org/print-all-combinations-of-given-length/
3534 *
3535 *
3536 */
3537
3540 int t, int da, int dc,
3541 int verbose_level)
3542{
3543 int f_v = (verbose_level >= 1);
3544
3545 if (f_v) {
3546 cout << "coding_theory_domain::find_CRC_polynomials t=" << t
3547 << " info=" << da << " check=" << dc << endl;
3548 }
3549
3550 //int dc = 4; //dc is the number of parity bits & degree of g(x)
3551 //int da = 4; //da is the degree of the information polynomial
3552 int A[da + dc];
3553 // we have da information bits, which we can think of
3554 // as the coefficients of a polynomial.
3555 // After multiplying by x^dc,
3556 // A(x) has degree at most ad + dc - 1.
3557 long int nb_sol = 0;
3558
3559
3560
3561 int C[dc + 1]; //Array C (what we divide by)
3562 // C(x) has the leading coefficient of one included,
3563 // hence we need one more array element
3564
3565 int i = 0;
3566
3567 for (i = 0; i <= dc; i++) {
3568 C[i] = 0;
3569 }
3570
3571
3572 std::vector<std::vector<int>> Solutions;
3573
3574 if (F->q == 2) {
3575 search_for_CRC_polynomials_binary(t, da, A, dc, C, 0,
3576 nb_sol, Solutions, verbose_level - 1);
3577 }
3578 else {
3579 search_for_CRC_polynomials(t, da, A, dc, C, 0, F,
3580 nb_sol, Solutions, verbose_level - 1);
3581 }
3582
3583 cout << "coding_theory_domain::find_CRC_polynomials info=" << da
3584 << " check=" << dc << " nb_sol=" << nb_sol << endl;
3585
3586 for (i = 0; i < Solutions.size(); i++) {
3587 cout << i << " : ";
3588 for (int j = dc; j >= 0; j--) {
3589 cout << Solutions[i][j];
3590 }
3591 cout << endl;
3592 }
3593 cout << "coding_theory_domain::find_CRC_polynomials info=" << da
3594 << " check=" << dc << " nb_sol=" << nb_sol << endl;
3595
3596}
3597
3599 int da, int *A, int dc, int *C,
3601 long int &nb_sol,
3602 std::vector<std::vector<int> > &Solutions,
3603 int verbose_level)
3604{
3605
3606 if (i == dc + 1) {
3607
3608 int ret;
3609
3610 if (t >= 2) {
3611 ret = test_all_two_bit_patterns(da, A, dc, C, F, verbose_level);
3612 if (ret && t >= 3) {
3613 ret = test_all_three_bit_patterns(da, A, dc, C, F, verbose_level);
3614 }
3615 }
3616 else {
3617 cout << "illegal value for t, t=" << t << endl;
3618 exit(1);
3619 }
3620 if (ret) {
3621 cout << "solution " << nb_sol << " is ";
3622 for (int j = dc; j >= 0; j--) {
3623 cout << C[j];
3624 }
3625 cout << endl;
3626
3627 vector<int> sol;
3628
3629 for (int j = 0; j <= dc; j++) {
3630 sol.push_back(C[j]);
3631 }
3632 Solutions.push_back(sol);
3633
3634
3635 nb_sol++;
3636 }
3637
3638 return;
3639 }
3640
3641 if (i == dc) {
3642
3643 // C(x) has a leading coefficient of one:
3644 C[i] = 1;
3645 search_for_CRC_polynomials(t, da, A, dc, C,
3646 i + 1, F, nb_sol, Solutions, verbose_level);
3647
3648
3649 }
3650 else {
3651 int c;
3652
3653 for (c = 0; c < F->q; c++) {
3654
3655 C[i] = c;
3656
3657 search_for_CRC_polynomials(t, da, A, dc, C,
3658 i + 1, F, nb_sol, Solutions, verbose_level);
3659 }
3660 }
3661}
3662
3664 int da, int *A, int dc, int *C, int i,
3665 long int &nb_sol,
3666 std::vector<std::vector<int> > &Solutions,
3667 int verbose_level)
3668{
3669
3670 if (i == dc + 1) {
3671
3672 int ret;
3673
3674 if (t >= 2) {
3675 ret = test_all_two_bit_patterns_binary(da, A, dc, C, verbose_level);
3676 if (ret && t >= 3) {
3677 ret = test_all_three_bit_patterns_binary(da, A, dc, C, verbose_level);
3678 }
3679 }
3680 else {
3681 cout << "illegal value for t, t=" << t << endl;
3682 exit(1);
3683 }
3684 if (ret) {
3685 cout << "solution " << nb_sol << " is ";
3686 for (int j = dc; j >= 0; j--) {
3687 cout << C[j];
3688 }
3689 cout << endl;
3690
3691 vector<int> sol;
3692
3693 for (int j = 0; j <= dc; j++) {
3694 sol.push_back(C[j]);
3695 }
3696 Solutions.push_back(sol);
3697
3698
3699 nb_sol++;
3700 }
3701
3702 return;
3703 }
3704
3705 if (i == dc) {
3706
3707 C[i] = 1;
3708 search_for_CRC_polynomials_binary(t, da, A, dc, C,
3709 i + 1, nb_sol, Solutions, verbose_level);
3710
3711
3712 }
3713 else {
3714 int c;
3715
3716 for (c = 0; c < 2; c++) {
3717
3718 C[i] = c;
3719
3720 search_for_CRC_polynomials_binary(t, da, A, dc, C,
3721 i + 1, nb_sol, Solutions, verbose_level);
3722 }
3723 }
3724}
3725
3726
3728 int dc, int *C,
3730 int verbose_level)
3731// returns true if division by C leaves a nonzero remainder for all two bit error patters
3732{
3733
3734 //cout << "choosetwo" << endl;
3735
3736 int f_v = (verbose_level >= 1);
3737
3738 int i;
3739 int j;
3740 int k;
3741 int ai, aj;
3742 int ret;
3743 int B[da + dc];
3744
3745 if (f_v) {
3746 cout << "testing polynomial: ";
3747 for (k = dc; k >= 0; k--) {
3748 cout << C[k];
3749 }
3750 cout << endl;
3751 }
3752
3753 for (i = 0; i < da; i++) {
3754 A[i] = 0;
3755 }
3756
3757 for (i = 0; i < da; i++) {
3758
3759 for (ai = 1; ai < F->q; ai++) {
3760
3761 A[i] = ai;
3762
3763 for (j = i + 1; j < da; j++) {
3764
3765 for (aj = 1; aj < F->q; aj++) {
3766
3767 A[j] = aj;
3768
3769 for (k = 0; k < dc; k++) {
3770 B[k] = 0;
3771 }
3772 for (k = 0; k < da; k++) {
3773 B[dc + k] = A[k];
3774 }
3775
3776 if (f_v) {
3777 cout << "testing error pattern: ";
3778 for (k = dc + da - 1; k >= 0; k--) {
3779 cout << B[k];
3780 }
3781 }
3782
3783
3784
3785 ret = remainder_is_nonzero (da, B, dc, C, F);
3786
3787 if (f_v) {
3788 cout << " : ";
3789 for (k = dc - 1; k >= 0; k--) {
3790 cout << B[k];
3791 }
3792 cout << endl;
3793 }
3794
3795 if (!ret) {
3796 return false;
3797 }
3798
3799 }
3800 A[j] = 0;
3801 }
3802
3803 }
3804 A[i] = 0;
3805 }
3806 return true;
3807}
3808
3810 int dc, int *C,
3812 int verbose_level)
3813// returns true if division by C leaves a nonzero remainder for all two bit error patters
3814{
3815
3816 //cout << "choosetwo" << endl;
3817
3818 int f_v = (verbose_level >= 1);
3819
3820 int i1, i2, i3;
3821 int k;
3822 int a1, a2, a3;
3823 int ret;
3824 int B[da + dc];
3825
3826 if (f_v) {
3827 cout << "testing polynomial: ";
3828 for (k = dc; k >= 0; k--) {
3829 cout << C[k];
3830 }
3831 cout << endl;
3832 }
3833
3834 for (int h = 0; h < da; h++) {
3835 A[h] = 0;
3836 }
3837
3838 for (i1 = 0; i1 < da; i1++) {
3839
3840 for (a1 = 1; a1 < F->q; a1++) {
3841
3842 A[i1] = a1;
3843
3844 for (i2 = i1 + 1; i2 < da; i2++) {
3845
3846 for (a2 = 1; a2 < F->q; a2++) {
3847
3848 A[i2] = a2;
3849
3850 for (i3 = i2 + 1; i3 < da; i3++) {
3851
3852 for (a3 = 1; a3 < F->q; a3++) {
3853
3854 A[i3] = a3;
3855
3856 for (int h = 0; h < dc; h++) {
3857 B[h] = 0;
3858 }
3859 for (int h = 0; h < da; h++) {
3860 B[dc + h] = A[h];
3861 }
3862
3863 if (f_v) {
3864 cout << "testing error pattern: ";
3865 for (int h = dc + da - 1; h >= 0; h--) {
3866 cout << B[h];
3867 }
3868 }
3869
3870
3871
3872 ret = remainder_is_nonzero (da, B, dc, C, F);
3873
3874 if (f_v) {
3875 cout << " : ";
3876 for (int h = dc - 1; h >= 0; h--) {
3877 cout << B[h];
3878 }
3879 cout << endl;
3880 }
3881
3882 if (!ret) {
3883 return false;
3884 }
3885
3886 }
3887 A[i3] = 0;
3888 }
3889 }
3890 A[i2] = 0;
3891 }
3892 }
3893 A[i1] = 0;
3894 }
3895 return true;
3896}
3897
3899 int dc, int *C,
3900 int verbose_level)
3901// returns true if division by C leaves a nonzero remainder for all two bit error patters
3902{
3903
3904 //cout << "choosetwo" << endl;
3905
3906 int f_v = (verbose_level >= 1);
3907
3908 int i;
3909 int j;
3910 int k;
3911 int ret;
3912 int B[da + dc];
3913
3914 if (f_v) {
3915 cout << "testing polynomial: ";
3916 for (k = dc; k >= 0; k--) {
3917 cout << C[k];
3918 }
3919 cout << endl;
3920 }
3921
3922 for (i = 0; i < da; i++) {
3923 A[i] = 0;
3924 }
3925
3926 for (i = 0; i < da; i++) {
3927
3928
3929 A[i] = 1;
3930
3931 for (j = i + 1; j < da; j++) {
3932
3933
3934 A[j] = 1;
3935
3936 for (k = 0; k < dc; k++) {
3937 B[k] = 0;
3938 }
3939 for (k = 0; k < da; k++) {
3940 B[dc + k] = A[k];
3941 }
3942
3943 if (f_v) {
3944 cout << "testing error pattern: ";
3945 for (k = dc + da - 1; k >= 0; k--) {
3946 cout << B[k];
3947 }
3948 }
3949
3950
3951
3952 ret = remainder_is_nonzero_binary(da, B, dc, C);
3953
3954 if (f_v) {
3955 cout << " : ";
3956 for (k = dc - 1; k >= 0; k--) {
3957 cout << B[k];
3958 }
3959 cout << endl;
3960 }
3961
3962 if (!ret) {
3963 return false;
3964 }
3965
3966 A[j] = 0;
3967 }
3968
3969 A[i] = 0;
3970 }
3971 return true;
3972}
3973
3975 int dc, int *C,
3976 int verbose_level)
3977// returns true if division by C leaves a nonzero remainder for all two bit error patters
3978{
3979
3980 //cout << "choosetwo" << endl;
3981
3982 int f_v = (verbose_level >= 1);
3983
3984 int i1, i2, i3;
3985 int k;
3986 int ret;
3987 int B[da + dc];
3988
3989 if (f_v) {
3990 cout << "testing polynomial: ";
3991 for (k = dc; k >= 0; k--) {
3992 cout << C[k];
3993 }
3994 cout << endl;
3995 }
3996
3997 for (int h = 0; h < da; h++) {
3998 A[h] = 0;
3999 }
4000
4001 for (i1 = 0; i1 < da; i1++) {
4002
4003 A[i1] = 1;
4004
4005 for (i2 = i1 + 1; i2 < da; i2++) {
4006
4007
4008 A[i2] = 1;
4009
4010 for (i3 = i2 + 1; i3 < da; i3++) {
4011
4012
4013 A[i3] = 1;
4014
4015 for (int h = 0; h < dc; h++) {
4016 B[h] = 0;
4017 }
4018 for (int h = 0; h < da; h++) {
4019 B[dc + h] = A[h];
4020 }
4021
4022 if (f_v) {
4023 cout << "testing error pattern: ";
4024 for (int h = dc + da - 1; h >= 0; h--) {
4025 cout << B[h];
4026 }
4027 }
4028
4029
4030
4031 ret = remainder_is_nonzero_binary(da, B, dc, C);
4032
4033 if (f_v) {
4034 cout << " : ";
4035 for (int h = dc - 1; h >= 0; h--) {
4036 cout << B[h];
4037 }
4038 cout << endl;
4039 }
4040
4041 if (!ret) {
4042 return false;
4043 }
4044
4045 A[i3] = 0;
4046 }
4047 A[i2] = 0;
4048 }
4049
4050 A[i1] = 0;
4051 }
4052 return true;
4053}
4054
4055
4057 int db, int *B, field_theory::finite_field *F)
4058// returns true if the remainder of A after division by B is nonzero
4059{
4060
4061 int i, j, k, a, mav;
4062
4063 for (i = da + db - 1; i >= db; i--) {
4064
4065 a = A[i];
4066
4067 if (a) {
4068
4069 mav = F->negate(F->inverse(a));
4070
4071 for (j = db, k = i; j >= 0; j--, k--) {
4072
4073 //A[k] = (A[k] + B[j]) % 2;
4074 A[k] = F->add(A[k], F->mult(mav, B[j]));
4075 //A[k] = subtraction(A[k], B[j], p);
4076 //A[k]=(A[k]+2-B[j])%2;
4077 }
4078 }
4079 }
4080
4081
4082 for (int k = db - 1; k >= 0; k--) {
4083 if (A[k]) {
4084 return true;
4085 }
4086 }
4087 return false;
4088}
4089
4090
4092 int db, int *B)
4093// returns true if the remainder of A after division by B is nonzero
4094{
4095
4096 int i, j, k, a;
4097
4098 for (i = da + db - 1; i >= db; i--) {
4099
4100 a = A[i];
4101
4102 if (a) {
4103
4104 //mav = F->negate(F->inverse(a));
4105
4106 for (j = db, k = i; j >= 0; j--, k--) {
4107
4108 A[k] = (A[k] + B[j]) % 2;
4109 //A[k] = F->add(A[k], F->mult(mav, B[j]));
4110 //A[k] = subtraction(A[k], B[j], p);
4111 //A[k]=(A[k]+2-B[j])%2;
4112 }
4113 }
4114 }
4115
4116
4117 for (int k = db - 1; k >= 0; k--) {
4118 if (A[k]) {
4119 return true;
4120 }
4121 }
4122 return false;
4123}
4124
4125
4126
4127
4128}}}
4129
4130
void do_long_code(int n, std::vector< std::string > &long_code_generators_text, int f_nearest_codeword, std::string &nearest_codeword_text, int verbose_level)
void field_reduction(field_theory::finite_field *FQ, field_theory::finite_field *Fq, std::string &label, int m, int n, std::string &genma_text, int verbose_level)
int gilbert_varshamov_lower_bound_for_d(int n, int k, int q, int verbose_level)
void codewords_affine(field_theory::finite_field *F, int n, int k, int *code, int *codewords, int verbose_level)
void search_for_CRC_polynomials(int t, int da, int *A, int dc, int *C, int i, field_theory::finite_field *F, long int &nb_sol, std::vector< std::vector< int > > &Solutions, int verbose_level)
void encode_text_5bits(std::string &text, std::string &fname, int verbose_level)
int code_minimum_distance(field_theory::finite_field *F, int n, int k, int *code, int verbose_level)
void CRC_encode_text(field_theory::nth_roots *Nth, ring_theory::unipoly_object &CRC_poly, std::string &text, std::string &fname, int verbose_level)
void do_make_macwilliams_system(int q, int n, int k, int verbose_level)
int test_all_two_bit_patterns_binary(int da, int *A, int dc, int *C, int verbose_level)
void matrix_from_projective_set(field_theory::finite_field *F, int n, int k, long int *columns_set_of_size_n, int *genma, int verbose_level)
void embellish(int *M, int nb_rows, int nb_cols, int i0, int j0, int a, int rad)
void search_for_CRC_polynomials_binary(int t, int da, int *A, int dc, int *C, int i, long int &nb_sol, std::vector< std::vector< int > > &Solutions, int verbose_level)
int singleton_bound_for_d(int n, int k, int q, int verbose_level)
void code_projective_weight_enumerator(field_theory::finite_field *F, int n, int k, int *code, int *weight_enumerator, int verbose_level)
void do_linear_code_through_columns_of_parity_check(int n, long int *columns_set, int k, int verbose_level)
void make_gilbert_varshamov_code_recursion(geometry::projective_space *P, int n, int d, long int *set, int *f_forbidden, int level, int verbose_level)
void compute_and_print_projective_weights(std::ostream &ost, field_theory::finite_field *F, int *M, int n, int k)
int test_all_three_bit_patterns_binary(int da, int *A, int dc, int *C, int verbose_level)
void code_weight_enumerator_fast(field_theory::finite_field *F, int n, int k, int *code, int *weight_enumerator, int verbose_level)
void make_Hamming_graph_and_write_file(int n, int q, int f_projective, int verbose_level)
void do_linear_code_through_basis(int n, long int *basis_set, int k, int f_embellish, int verbose_level)
int griesmer_bound_for_d(int n, int k, int q, int verbose_level)
void do_it(int n, int r, int a, int c, int seed, int verbose_level)
int remainder_is_nonzero(int da, int *A, int db, int *B, field_theory::finite_field *F)
int test_all_two_bit_patterns(int da, int *A, int dc, int *C, field_theory::finite_field *F, int verbose_level)
void make_mac_williams_equations(ring_theory::longinteger_object *&M, int n, int k, int q, int verbose_level)
void investigate_code(long int *Words, int nb_words, int n, int f_embellish, int verbose_level)
void do_polynomial(int n, int polynomial_degree, int polynomial_nb_vars, std::string &polynomial_text, int f_embellish, int verbose_level)
void find_CRC_polynomials(field_theory::finite_field *F, int t, int da, int dc, int verbose_level)
void do_linear_code_through_columns_of_parity_check_projectively(int n, long int *columns_set, int k, int verbose_level)
void do_sylvester_hadamard(int n, int f_embellish, int verbose_level)
int test_all_three_bit_patterns(int da, int *A, int dc, int *C, field_theory::finite_field *F, int verbose_level)
void code_weight_enumerator(field_theory::finite_field *F, int n, int k, int *code, int *weight_enumerator, int verbose_level)
void make_gilbert_varshamov_code(int n, int k, int d, int q, geometry::projective_space *P, int verbose_level)
void generator_matrix_cyclic_code(field_theory::finite_field *F, int n, std::string &poly_coeffs, int verbose_level)
void code_diagram(std::string &label, long int *Words, int nb_words, int n, int f_metric_balls, int radius_of_metric_ball, int f_enhance, int radius, int verbose_level)
void code_projective_weights(field_theory::finite_field *F, int n, int k, int *code, int *&weights, int verbose_level)
void field_induction(std::string &fname_in, std::string &fname_out, int nb_bits, int verbose_level)
void do_weight_enumerator(field_theory::finite_field *F, int *M, int m, int n, int f_normalize_from_the_left, int f_normalize_from_the_right, int verbose_level)
void place_entry(int *M, int nb_rows, int nb_cols, int i, int j, int a)
int griesmer_bound_for_n(int k, int d, int q, int verbose_level)
void mac_williams_equations(ring_theory::longinteger_object *&M, int n, int k, int q)
ring_theory::homogeneous_polynomial_domain * Poly
Definition: combinatorics.h:43
void compute_polynomial_representation(int *func, int *coeff, int verbose_level)
void binomial(ring_theory::longinteger_object &a, int n, int k, int verbose_level)
void krawtchouk(ring_theory::longinteger_object &a, int n, int q, int k, int x)
a collection of functions related to sorted vectors
functions related to strings and character arrays
a statistical analysis of data consisting of single integers
void init(int *data, int data_length, int f_second, int verbose_level)
Definition: tally.cpp:72
void PG_element_unrank_modified(int *v, int stride, int len, int a)
void finite_field_init(int q, int f_without_tables, int verbose_level)
void PG_element_rank_modified_lint(int *v, int stride, int len, long int &a)
the nth roots over Fq using an extension field
a finite field as a vector space over a subfield
void init(finite_field *FQ, finite_field *Fq, int verbose_level)
void field_reduction(int *input, int sz, int *output, 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)
projective space PG(n,q) of dimension n over Fq
Definition: geometry.h:1916
void mult_vector_from_the_left(int *v, int *A, int *vA, int m, int n)
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)
void mult_matrix_matrix(int *A, int *B, int *C, int m, int n, int o, int verbose_level)
int RREF_and_kernel(int n, int k, int *A, int verbose_level)
void Kronecker_product_square_but_arbitrary(int *A, int *B, int na, int nb, int *AB, int &N, int verbose_level)
void int_matrix_write_csv(std::string &fname, int *M, int m, int n)
Definition: file_io.cpp:1300
void lint_matrix_write_csv(std::string &fname, long int *M, int m, int n)
Definition: file_io.cpp:1323
void lint_matrix_write_csv_override_headers(std::string &fname, std::string *headers, long int *M, int m, int n)
Definition: file_io.cpp:1346
void lint_matrix_read_csv(std::string &fname, long int *&M, int &m, int &n, int verbose_level)
Definition: file_io.cpp:1558
void int_matrix_print_tex(std::ostream &ost, int *p, int m, int n)
void print_integer_matrix_tex(std::ostream &ost, int *p, int m, int n)
void head(std::ostream &ost, int f_book, int f_title, const char *title, const char *author, int f_toc, int f_landscape, int f_12pt, int f_enlarged_page, int f_pagenumbers, const char *extras_for_preamble)
void print_longinteger_matrix_tex(std::ostream &ost, ring_theory::longinteger_object *p, int m, int n)
void get_lint_vector_from_label(std::string &label, long int *&v, int &sz, int verbose_level)
homogeneous polynomials of a given degree in a given number of variables over a finite field GF(q)
Definition: ring_theory.h:88
void init(field_theory::finite_field *F, int nb_vars, int degree, int f_init_incidence_structure, monomial_ordering_type Monomial_ordering_type, int verbose_level)
domain to compute with objects of type longinteger
Definition: ring_theory.h:240
int compare(longinteger_object &a, longinteger_object &b)
void add(longinteger_object &a, longinteger_object &b, longinteger_object &c)
void mult(longinteger_object &a, longinteger_object &b, longinteger_object &c)
void matrix_entries_integral_division_exact(longinteger_object *A, longinteger_object &b, int Am, int An)
void matrix_product(longinteger_object *A, longinteger_object *B, longinteger_object *&C, int Am, int An, int Bn)
void integral_division(longinteger_object &a, longinteger_object &b, longinteger_object &q, longinteger_object &r, int verbose_level)
void matrix_print_tex(std::ostream &ost, longinteger_object *A, int Am, int An)
a class to represent arbitrary precision integers
Definition: ring_theory.h:366
void create(long int i, const char *file, int line)
void division_with_remainder(unipoly_object a, unipoly_object b, unipoly_object &q, unipoly_object &r, int verbose_level)
void print_object(unipoly_object p, std::ostream &ost)
#define FREE_OBJECTS(p)
Definition: foundations.h:652
#define Get_int_vector_from_label(A, B, C, D)
Definition: foundations.h:719
#define Int_vec_scan(A, B, C)
Definition: foundations.h:716
#define MINIMUM(x, y)
Definition: foundations.h:216
#define FREE_int(p)
Definition: foundations.h:640
#define Int_vec_zero(A, B)
Definition: foundations.h:713
#define Int_vec_print_fully(A, B, C)
Definition: foundations.h:687
#define ONE_MILLION
Definition: foundations.h:226
#define Lint_vec_scan(A, B, C)
Definition: foundations.h:717
#define NEW_OBJECT(type)
Definition: foundations.h:638
#define Lint_vec_print(A, B, C)
Definition: foundations.h:686
#define FREE_OBJECT(p)
Definition: foundations.h:651
#define NEW_int(n)
Definition: foundations.h:625
#define Int_matrix_print(A, B, C)
Definition: foundations.h:707
#define NEW_OBJECTS(type, n)
Definition: foundations.h:639
#define TRUE
Definition: foundations.h:231
#define FALSE
Definition: foundations.h:234
#define Int_vec_copy(A, B, C)
Definition: foundations.h:693
#define FREE_lint(p)
Definition: foundations.h:642
#define NEW_lint(n)
Definition: foundations.h:628
#define Int_vec_print(A, B, C)
Definition: foundations.h:685
#define Lint_vec_print_fully(A, B, C)
Definition: foundations.h:688
orbiter_kernel_system::orbiter_session * Orbiter
global Orbiter session
the orbiter library for the classification of combinatorial objects