annotate main/comm/src/cyclpoly.cc @ 9666:67d4cfc5eeb3 octave-forge

comm: update license to GPLv3+
author carandraug
date Tue, 13 Mar 2012 04:31:21 +0000
parents 51da4a61963f
children 44545240fca5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9666
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 8090
diff changeset
1 //Copyright (C) 2003 David Bateman
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 8090
diff changeset
2 //
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 8090
diff changeset
3 // This program is free software; you can redistribute it and/or modify it under
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 8090
diff changeset
4 // the terms of the GNU General Public License as published by the Free Software
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 8090
diff changeset
5 // Foundation; either version 3 of the License, or (at your option) any later
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 8090
diff changeset
6 // version.
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 8090
diff changeset
7 //
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 8090
diff changeset
8 // This program is distributed in the hope that it will be useful, but WITHOUT
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 8090
diff changeset
9 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 8090
diff changeset
10 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 8090
diff changeset
11 // details.
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 8090
diff changeset
12 //
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 8090
diff changeset
13 // You should have received a copy of the GNU General Public License along with
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 8090
diff changeset
14 // this program; if not, see <http://www.gnu.org/licenses/>.
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 8090
diff changeset
15 //
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 8090
diff changeset
16 // In addition to the terms of the GPL, you are permitted to link
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 8090
diff changeset
17 // this program with any Open Source program, as defined by the
67d4cfc5eeb3 comm: update license to GPLv3+
carandraug
parents: 8090
diff changeset
18 // Open Source Initiative (www.opensource.org)
2382
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
19
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
20 #include <iostream>
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
21 #include <iomanip>
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
22 #include <sstream>
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
23 #include <octave/oct.h>
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
24 #include <octave/pager.h>
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
25
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
26 enum cyclic_poly_type
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
27 {
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
28 CYCLIC_POLY_MIN=0,
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
29 CYCLIC_POLY_MAX,
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
30 CYCLIC_POLY_ALL,
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
31 CYCLIC_POLY_L
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
32 };
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
33
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
34 // A simplified version of the filter function for specific lengths of a and b
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
35 // in the Galois field GF(2)
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
36 Array<int> filter_gf2 (const Array<int>& b, const Array<int>& a,
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
37 const Array<int>& x, const int& n) {
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
38
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
39 int x_len = x.length ();
8090
51da4a61963f Update galois field C++ code in the communications package for Octave 3.4
adb014
parents: 4404
diff changeset
40 Array<int> si (dim_vector (n, 1), 0);
51da4a61963f Update galois field C++ code in the communications package for Octave 3.4
adb014
parents: 4404
diff changeset
41 Array<int> y (dim_vector (x_len, 1), 0);
2382
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
42
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
43 for (int i=0; i < x_len; i++) {
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
44 y(i) = si(0);
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
45 if (b(0) && x(i))
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
46 y(i) ^= 1;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
47
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
48 for (int j = 0; j < n - 1; j++) {
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
49 si(j) = si(j+1);
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
50 if (a(j+1) && y(i))
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
51 si(j) ^= 1;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
52 if (b(j+1) && x(i))
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
53 si(j) ^= 1;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
54 }
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
55 si(n-1) = 0;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
56 if (a(n) && y(i))
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
57 si(n-1) ^= 1;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
58 if (b(n) && x(i))
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
59 si(n-1) ^= 1;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
60 }
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
61
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
62 return y;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
63 }
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
64
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
65 // Cyclic polynomial is irreducible. I.E. it divides into x^n-1 without remainder
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
66 // There must surely be an easier way of doing this as the polynomials are over
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
67 // GF(2).
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
68 static bool
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
69 do_is_cyclic_polynomial (const unsigned long long& a1, const int& n, const int& m)
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
70 {
8090
51da4a61963f Update galois field C++ code in the communications package for Octave 3.4
adb014
parents: 4404
diff changeset
71 Array<int> a (dim_vector (n+1, 1),0);
51da4a61963f Update galois field C++ code in the communications package for Octave 3.4
adb014
parents: 4404
diff changeset
72 Array<int> y (dim_vector (n+1, 1), 0);
51da4a61963f Update galois field C++ code in the communications package for Octave 3.4
adb014
parents: 4404
diff changeset
73 Array<int> x (dim_vector (n-m+2, 1), 0);
2382
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
74 y(0) = 1;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
75 y(n) = 1;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
76 x(0) = 1;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
77 for (int i=0; i < m+1; i++)
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
78 a(i) = (a1 & (1UL << i) ? 1 : 0);
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
79
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
80 Array<int> b = filter_gf2 (y, a, x, n);
8090
51da4a61963f Update galois field C++ code in the communications package for Octave 3.4
adb014
parents: 4404
diff changeset
81 b.resize(dim_vector (n+1, 1), 0);
51da4a61963f Update galois field C++ code in the communications package for Octave 3.4
adb014
parents: 4404
diff changeset
82 Array<int> p (dim_vector (m+1, 1), 0);
2382
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
83 p(0) = 1;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
84 Array<int> q = filter_gf2 (a, p, b, m);
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
85
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
86 for (int i=0; i < n+1; i++)
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
87 if (y(i) ^ q(i))
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
88 return false;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
89
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
90 return true;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
91 }
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
92
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
93 DEFUN_DLD (cyclpoly, args, nargout,
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
94 "-*- texinfo -*-\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
95 "@deftypefn {Loadable Function} {@var{y} =} cyclpoly (@var{n},@var{k})\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
96 "@deftypefnx {Loadable Function} {@var{y} =} cyclpoly (@var{n},@var{k},@var{opt})\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
97 "@deftypefnx {Loadable Function} {@var{y} =} cyclpoly (@var{n},@var{k},@var{opt},@var{rep})\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
98 "\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
99 "This function returns the cyclic generator polynomials of the code\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
100 "[@var{n},@var{k}]. By default the the polynomial with the smallest\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
101 "weight is returned. However this behavior can be overridden with the\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
102 "@var{opt} flag. Valid values of @var{opt} are:\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
103 "\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
104 "@table @asis\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
105 "@item 'all'\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
106 "Returns all of the polynomials of the code [@var{n},@var{k}]\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
107 "@item 'min'\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
108 "Returns the polynomial of minimum weight of the code [@var{n},@var{k}]\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
109 "@item 'max'\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
110 "Returns the polynomial of the maximum weight of the code [@var{n},@var{k}]\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
111 "@item @var{l}\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
112 "Returns the polynomials having exactly the weight @var{l}\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
113 "@end table\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
114 "\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
115 "The polynomials are returns as row-vectors in the variable @var{y}. Each\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
116 "row of @var{y} represents a polynomial with the least-significant term\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
117 "first. The polynomials can be returned with an integer representation\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
118 "if @var{rep} is 'integer'. The default behaviour is given if @var{rep}\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
119 "is 'polynomial'.\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
120 "@end deftypefn\n"
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
121 "@seealso{gf,isprimitive}")
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
122 {
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
123 octave_value retval;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
124 int nargin = args.length ();
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
125 bool polyrep = true;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
126 enum cyclic_poly_type type = CYCLIC_POLY_MIN;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
127 RowVector cyclic_polys;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
128 int l=0;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
129
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
130 if ((nargin < 2) || (nargin > 4)) {
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
131 error("cyclpoly: incorrect number of arguments");
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
132 return retval;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
133 }
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
134
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
135 int n = args(0).int_value();
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
136 int k = args(1).int_value();;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
137
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
138 if (n < 1) {
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
139 error("cyclpoly: n must be 1 or greater");
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
140 return retval;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
141 }
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
142
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
143 if (n <= k) {
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
144 error("cyclpoly: k must be less than n");
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
145 return retval;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
146 }
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
147
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
148 for (int i = 2; i < nargin; i++) {
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
149 if (args(i).is_scalar_type ()) {
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
150 l = args(i).int_value();
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
151 type = CYCLIC_POLY_L;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
152 } else if (args(i).is_string ()) {
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
153 std::string s_arg = args(i).string_value ();
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
154
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
155 if (s_arg == "integer")
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
156 polyrep = false;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
157 else if (s_arg == "polynomial")
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
158 polyrep = true;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
159 else if (s_arg == "min")
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
160 type = CYCLIC_POLY_MIN;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
161 else if (s_arg == "max")
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
162 type = CYCLIC_POLY_MAX;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
163 else if (s_arg == "all")
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
164 type = CYCLIC_POLY_ALL;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
165 else {
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
166 error ("cyclpoly: invalid argument");
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
167 return retval;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
168 }
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
169 } else {
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
170 error ("cyclpoly: incorrect argument type");
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
171 return retval;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
172 }
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
173 }
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
174
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
175 int m = n - k;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
176
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
177 // Matlab code seems to think that 1+x+x^3 is of larger weight than
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
178 // 1+x^2+x^3. So for matlab compatiability the list of polynomials
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
179 // should be reversed by replacing "i+=2" with "i-=2" and visa-versa.
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
180 // Thats not going to happen!!!
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
181
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
182 switch (type) {
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
183 case CYCLIC_POLY_MIN:
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
184 cyclic_polys.resize(1);
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
185 for (unsigned long long i = (1UL<<m)+1; i < (1UL<<(1+m)); i+=2)
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
186 if (do_is_cyclic_polynomial(i, n, m)) {
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
187 cyclic_polys(0) = (double)i;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
188 break;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
189 }
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
190 break;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
191 case CYCLIC_POLY_MAX:
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
192 cyclic_polys.resize(1);
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
193 for (unsigned long long i = (1UL<<(m+1))-1; i > (1UL<<m); i-=2)
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
194 if (do_is_cyclic_polynomial(i, n, m)) {
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
195 cyclic_polys(0) = (double)i;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
196 break;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
197 }
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
198 break;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
199 case CYCLIC_POLY_ALL:
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
200 for (unsigned long long i = (1UL<<m)+1; i < (1UL<<(1+m)); i+=2)
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
201 if (do_is_cyclic_polynomial(i, n, m)) {
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
202 cyclic_polys.resize(cyclic_polys.length()+1);
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
203 cyclic_polys(cyclic_polys.length()-1) = (double)i;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
204 }
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
205 break;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
206 case CYCLIC_POLY_L:
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
207 for (unsigned long long i = ((unsigned long long)1<<m)+1; i < ((unsigned long long)1<<(1+m)); i+=2) {
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
208 int li = 0;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
209 for (int j=0; j < m+1; j++)
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
210 if (i & ((unsigned long long)1 << j))
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
211 li++;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
212 if (li == l) {
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
213 if (do_is_cyclic_polynomial(i, n, m)) {
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
214 cyclic_polys.resize(cyclic_polys.length()+1);
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
215 cyclic_polys(cyclic_polys.length()-1) = (double)i;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
216 }
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
217 }
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
218 }
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
219 break;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
220 default:
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
221 error("cyclpoly: impossible");
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
222 break;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
223 }
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
224
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
225 if (cyclic_polys.length() == 0) {
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
226 octave_stdout <<
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
227 "cyclpoly: no generator polynomial statifies constraints" << std::endl;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
228 retval = octave_value(Matrix(0,0));
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
229 } else {
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
230 if (polyrep) {
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
231 Matrix polys(cyclic_polys.length(),m+1, 0);
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
232 for (int i = 0 ; i < cyclic_polys.length(); i++)
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
233 for (int j = 0; j < m+1; j++)
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
234 if ((unsigned long long)cyclic_polys(i) & (1<<j))
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
235 polys(i,j) = 1;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
236 retval = octave_value (polys);
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
237 } else
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
238 retval = octave_value (cyclic_polys);
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
239 }
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
240
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
241 return retval;
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
242 }
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
243
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
244 /*
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
245 ;;; Local Variables: ***
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
246 ;;; mode: C++ ***
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
247 ;;; End: ***
5056d2d5eb72 Changed the directory structure of comm to match the package system
hauberg
parents:
diff changeset
248 */