36 #include <itpp/itexports.h>
84 else set_size(qvalue);
87 GF(
int qvalue,
int inexp) { m = 0;
set(qvalue, inexp); }
89 GF(
const GF &ingf) { m = ingf.m; value = ingf.value; }
92 void set(
int qvalue,
int inexp) {
94 it_assert_debug(inexp >= -1 && inexp < qvalue - 1,
"GF::set, out of range");
102 void set(
int qvalue,
const bvec &vectorspace);
104 void set_size(
int qvalue);
106 int get_size()
const {
return ((m != 0) ? q[m] : 0); }
112 bvec get_vectorspace()
const;
114 int get_value()
const;
116 int operator==(
const GF &ingf)
const;
118 int operator!=(
const GF &ingf)
const;
121 void operator=(
const GF &ingf);
123 void operator=(
const int inexp);
125 void operator+=(
const GF &ingf);
129 void operator-=(
const GF &ingf);
133 void operator*=(
const GF &ingf);
137 void operator/=(
const GF &ingf);
141 ITPP_EXPORT
friend std::ostream &
operator<<(std::ostream &os,
const GF &ingf);
143 ITPP_EXPORT
friend std::istream &
operator>>(std::istream &is,
GF &ingf);
155 #if (defined(_MSC_VER) && defined (ITPP_SHARED_LIB))
157 template class ITPP_EXPORT Array<GF>;
165 ITPP_EXPORT GFX
operator*(
const GF &ingf,
const GFX &ingfx);
167 ITPP_EXPORT GFX
operator*(
const GFX &ingfx,
const GF &ingf);
169 ITPP_EXPORT GFX
operator/(
const GFX &ingfx,
const GF &ingf);
171 ITPP_EXPORT std::ostream &
operator<<(std::ostream &os,
const GFX &ingfx);
183 GFX(
int qvalue,
int indegree);
185 GFX(
int qvalue,
const ivec &invalues);
187 GFX(
int qvalue,
char *invalues);
189 GFX(
int qvalue, std::string invalues);
193 int get_size()
const;
195 int get_degree()
const;
199 void set_degree(
int indegree,
bool copy =
false);
201 int get_true_degree()
const;
203 void set(
int qvalue,
const char *invalues);
205 void set(
int qvalue,
const std::string invalues);
207 void set(
int qvalue,
const ivec &invalues);
213 return coeffs(index);
218 return coeffs(index);
221 void operator=(
const GFX &ingfx);
223 void operator+=(
const GFX &ingfx);
227 void operator-=(
const GFX &ingfx);
231 void operator*=(
const GFX &ingfx);
235 GF operator()(
const GF &ingf);
243 ITPP_EXPORT
friend std::ostream &
operator<<(std::ostream &os,
const GFX &ingfx);
257 ITPP_EXPORT GFX
divgfx(
const GFX &c,
const GFX &g);
263 ITPP_EXPORT GFX
modgfx(
const GFX &a,
const GFX &b);
269 inline void GF::set(
int qvalue,
const bvec &vectorspace)
273 value = logalpha(m)(
bin2dec(vectorspace));
282 temp =
dec2bin(m, alphapow(m)(value));
293 if (value == -1 && ingf.value == -1)
295 if (m == ingf.m && value == ingf.value)
304 return !(tmp == ingf);
315 it_assert_debug(m > 0 && inexp >= -1 && inexp < (q[m] - 1),
"GF::op=, out of range");
325 else if (ingf.value != -1) {
327 value = logalpha(m)(alphapow(m)(value) ^ alphapow(m)(ingf.value));
352 if (value == -1 || ingf.value == -1)
356 value = (value + ingf.value) % (q[m] - 1);
369 it_assert(ingf.value != -1,
"GF::operator/: division by zero element");
374 value = (value - ingf.value + q[m] - 1) % (q[m] - 1);
398 inline void GFX::set(
int qvalue,
const ivec &invalues)
401 degree = invalues.size() - 1;
403 for (
int i = 0;i < degree + 1;i++)
404 coeffs(i).set(qvalue, invalues(i));
408 inline void GFX::set(
int qvalue,
const char *invalues)
410 set(qvalue, ivec(invalues));
413 inline void GFX::set(
int qvalue,
const std::string invalues)
415 set(qvalue, invalues.c_str());
420 it_assert_debug(qvalue > 0 && indegree >= 0,
"GFX::GFX, out of range");
422 coeffs.
set_size(indegree + 1,
false);
424 for (
int i = 0;i < degree + 1;i++)
425 coeffs(i).set(q, -1);
429 set(qvalue, invalues);
434 set(qvalue, invalues);
439 set(qvalue, invalues.c_str());
444 degree = ingfx.degree;
445 coeffs = ingfx.coeffs;
462 coeffs.
set_size(indegree + 1, copy);
469 while (coeffs(i).get_value() == -1) {
480 for (
int i = 0;i < degree + 1;i++)
481 coeffs(i).set(q, -1);
486 degree = ingfx.degree;
487 coeffs = ingfx.coeffs;
494 if (ingfx.degree > degree) {
495 coeffs.
set_size(ingfx.degree + 1,
true);
497 for (
int j = degree + 1; j < coeffs.
size(); j++) { coeffs(j).set(q, -1); }
498 degree = ingfx.degree;
500 for (
int i = 0;i < ingfx.degree + 1;i++) { coeffs(i) += ingfx.coeffs(i); }
527 coeffs.
set_size(degree + ingfx.degree + 1,
false);
528 for (j = 0; j < coeffs.
size(); j++)
529 coeffs(j).set(q, -1);
530 for (i = 0;i < degree + 1;i++)
531 for (j = 0;j < ingfx.degree + 1;j++)
532 coeffs(i + j) += tempcoeffs(i) * ingfx.coeffs(j);
533 degree = coeffs.
size() - 1;
547 for (
int i = 0;i < ingfx.degree + 1;i++)
548 temp.coeffs(i) *= ingf;
561 for (
int i = 0;i < ingfx.degree + 1;i++)
562 temp.coeffs(i) /= ingf;
569 GF temp(coeffs(0)), ingfpower(ingf);
570 for (
int i = 1; i < degree + 1; i++) {
571 temp += coeffs(i) * ingfpower;
579 #endif // #ifndef GALOIS_H