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)) 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);
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;
402 coeffs.set_size(degree + 1,
false);
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); }
526 Array<GF> tempcoeffs = coeffs;
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 Mat< Num_T > operator/(const Mat< Num_T > &m, Num_T t)
Element-wise division by a scalar.
void operator+=(const GF &ingf)
sum of two GF(q)
void operator=(const GF &ingf)
GF(q) equals ingf.
void clear()
Set all coefficients to zero.
void operator=(const GFX &ingfx)
Copy.
void operator+=(const GFX &ingfx)
sum of two GF(q)[x]
GFX operator+(const GFX &ingfx) const
sum of two GF(q)[x]
std::ostream & operator<<(std::ostream &output, const bin &inbin)
Output stream of bin.
GF(int qvalue)
Constructor.
GFX operator-(const GFX &ingfx) const
Difference of two GF(q), same as sum for q=2^m.
int operator==(const GF &ingf) const
Equality check.
#define it_assert(t, s)
Abort if t is not true.
#define it_assert_debug(t, s)
Abort if t is not true and NDEBUG is not defined.
int get_true_degree() const
Return true degree of GF(q)[x].
Definition of Array class (container)
GF operator-(const GF &ingf) const
Difference of two GF(q), same as sum for q=2^m.
bvec get_vectorspace() const
Returns the vector space representation of GF(q).
Definitions of converters between different vector and matrix types.
GFX operator*(const GFX &ingfx) const
product of two GF(q)[x]
Mat< Num_T > operator-(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Subtraction of two matrices.
void operator*=(const GF &ingf)
product of two GF(q)
GF operator+(const GF &ingf) const
sum of two GF(q)
Import/Export definitions for some templates defined in base folder.
void operator-=(const GFX &ingfx)
Difference of two GF(q), same as sum for q=2^m.
GF2mat operator+(const GF2mat &X, const GF2mat &Y)
GF(2) matrix addition.
GF operator/(const GF &ingf) const
product of two GF(q)
void operator-=(const GF &ingf)
Difference of two GF(q), same as sum for q=2^m.
int get_size() const
Return q.
int operator!=(const GF &ingf) const
Not-equality check.
GF operator[](int index) const
Acces to individual element in the GF(q)[x] polynomial.
GF2mat operator*(const GF2mat &X, const GF2mat &Y)
GF(2) matrix multiplication.
void set(int qvalue, int inexp)
GF(q) equals alpha ^ inexp.
ITPP_EXPORT bvec dec2bin(int length, int index)
Convert a decimal int index to bvec using length bits in the representation.
GF operator*(const GF &ingf) const
product of two GF(q)
GF & operator[](int index)
Acces to individual element in the GF(q)[x] polynomial.
GF(int qvalue, int inexp)
Constructor.
GFX modgfx(const GFX &a, const GFX &b)
Modulo function of two GFX (local help function)
GF(const GF &ingf)
Copy constructor.
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_value() const
Returns the alpha exponent.
GF operator()(const GF &ingf)
Evaluate polynom at alpha^inexp.
int get_degree() const
Return degree of GF(q)[x].
std::istream & operator>>(std::istream &input, bin &outbin)
Input stream of bin.
void operator/=(const GF &ingf)
division of two GF(q)
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...
ITPP_EXPORT int bin2dec(const bvec &inbvec, bool msb_first=true)
Convert a bvec to decimal int with the first bit as MSB if msb_first == true.
void set(int qvalue, const char *invalues)
Set the GF(q)[x] polynomial.
int get_size() const
Return q.
Templated Vector Class Definitions.
void operator*=(const GFX &ingfx)
product of two GF(q)[x]