39 Array<Array<int> > GF::alphapow;
40 Array<Array<int> > GF::logalpha;
41 ivec GF::q =
"1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536";
46 m =
static_cast<char>(
round_i(::
log2(static_cast<double>(qvalue))));
47 it_assert((1 << m) == qvalue,
"GF::setsize : q is not a power of 2");
48 it_assert((m > 0) && (m <= 16),
"GF::setsize : q must be positive and " 49 "less than or equal to 2^16");
55 const int reducetable[] = {3, 3, 3, 5, 3, 9, 29, 17, 9, 5, 83, 27, 43, 3, 4107};
57 if (alphapow.size() < (m + 1)) {
58 alphapow.set_size(m + 1,
true);
59 logalpha.set_size(m + 1,
true);
62 if (alphapow(m).
size() == 0) {
63 alphapow(m).set_size(qvalue);
64 logalpha(m).set_size(qvalue);
73 reduce = reducetable[m-2];
75 for (n = 1; n < (1 << m) - 1; n++) {
76 temp = alphapow(m)(n - 1);
79 alphapow(m)(n) = (temp & ~(1 << m)) ^ reduce;
81 alphapow(m)(n) = temp;
87 for (n = 0;n < (1 << m) - 1;n++)
88 logalpha(m)(alphapow(m)(n)) = n;
96 static const std::string prefix(
"alpha^");
100 std::string::const_iterator pr_it = prefix.begin(); pr_it++;
101 for(; pr_it < prefix.end(); ++pr_it) {
104 is.setstate(std::ios_base::failbit);
118 is.setstate(std::ios_base::failbit);
127 if (ingf.value == -1)
130 os <<
"alpha^" << ingf.value;
138 for (
int i = 0; i < ingfx.degree + 1; i++) {
139 if (ingfx.coeffs(i) !=
GF(ingfx.q, -1)) {
140 if (terms != 0) os <<
" + ";
142 if (ingfx.coeffs(i) ==
GF(ingfx.q, 0)) {
146 os << ingfx.coeffs(i) <<
"*x^" << i;
150 if (terms == 0) os <<
"0";
163 int degreedif = tempdegree - gdegree;
164 if (degreedif < 0)
return GFX(q, 0);
165 GFX m(q, degreedif), divisor(q);
168 m[degreedif] = temp[tempdegree] / g[gdegree];
171 divisor[degreedif] = m[degreedif];
174 degreedif = tempdegree - gdegree;
190 if (degreedif < 0)
return temp;
191 GFX m(q, degreedif), divisor(q);
194 m[degreedif] = temp[tempdegree] / b[bdegree];
197 divisor[degreedif] = m[degreedif];
Definitions of Galois Field algebra classes and functions.
ITPP_EXPORT int round_i(double x)
Round to nearest integer.
void set_size(int qvalue)
set q=2^mvalue
void clear()
Set all coefficients to zero.
std::ostream & operator<<(std::ostream &output, const bin &inbin)
Output stream of bin.
#define it_assert(t, s)
Abort if t is not true.
Logarithmic and exponenential functions - header file.
int get_true_degree() const
Return true degree of GF(q)[x].
vec log2(const vec &x)
log-2 of the elements
int get_size() const
Return q.
int size(const Vec< T > &v)
Length of vector.
void set(int qvalue, int inexp)
GF(q) equals alpha ^ inexp.
IT++ compatibility types and functions.
GFX modgfx(const GFX &a, const GFX &b)
Modulo function of two GFX (local help function)
Polynomials over GF(q)[x], where q=2^m, m=1,...,16.
GFX divgfx(const GFX &c, const GFX &g)
Division of two GFX (local help function)
int get_degree() const
Return degree of GF(q)[x].
std::istream & operator>>(std::istream &input, bin &outbin)
Input stream of bin.
void set_degree(int indegree, bool copy=false)
Resize the polynomial to the given indegree. If copy is set to true, the old polynomial's coefficient...
int get_size() const
Return q.