#include <GF2_Polynomial.h>
List of all members.
Constructor & Destructor Documentation
Default constructor. Makes an empty thus invalid polynomial
Constructs a new polynomial with coefficients in GF(2) with the specified coefficients
- Parameters:
-
size | The number of coefficients |
gfe | Coefficients array in increasing powers of variable. If null it assign all zero values to coefficients |
{
if (gfe != NULL)
{
poly.assign(gfe, gfe + size);
}
else
{
poly.assign(size, 0);
}
}
Copy constructor
- Parameters:
-
polynomial | Reference of the polynomial to copy |
{
poly = polynomial.poly;
}
Constructs a zero degree polynomial with the given element as coefficient.
Constructs the X^n polynomial
{
poly.assign(n+1, 0);
poly.back() = 1;
}
Member Function Documentation
Degree of the polynomial
{
return static_cast<unsigned int>(poly.size() - 1);
}
Gets a constant reference to the coefficients vector
Gets a modifiable reference to the coefficients vector
Tells if the polynomial has no coefficients or a null coefficient
{
return (poly.size() == 0) || ((poly.size() == 1) && (poly[0] == 0));
}
bool rssoft::gf::GF2_Polynomial::operator!= |
( |
const GF2_Polynomial & |
polynomial | ) |
const |
{
return !(*this == polynomial);
}
{
const std::pair<GF2_Polynomial, GF2_Polynomial>& divres = div(*this, divisor);
poly = divres.second.get_poly();
return *this;
}
GF2_Polynomial & rssoft::gf::GF2_Polynomial::operator%= |
( |
const unsigned int & |
power | ) |
|
{
if (poly.size() >= power)
{
for (size_t i = poly.size(); i > power; i--)
{
poly.pop_back();
}
}
simplify(*this);
return *this;
}
{
GF2_Element result = 0;
if (poly.size() > 0)
{
result = poly[poly.size() - 1];
for (std::size_t i = poly.size() - 2; ((int) i) >= 0; i--)
{
result = poly[i] + (result * value);
}
return result;
}
else
{
throw GF_Exception("Cannot evaluate invalid polynomial");
}
}
{
GF2_Element result = 0;
if (poly.size() > 0)
{
result = poly[poly.size() - 1];
for (std::size_t i = poly.size() - 2; ((int) i) >= 0; i--)
{
result = poly[i] + (result * value);
}
return result;
}
else
{
throw GF_Exception("Cannot evaluate invalid polynomial");
}
}
{
GF2_Polynomial product(deg() + polynomial.deg() + 1, 0);
for (unsigned int i = 0; i < poly.size(); i++)
{
for (unsigned int j = 0; j < polynomial.poly.size(); j++)
{
product.poly[i + j] += poly[i] * polynomial.poly[j];
}
}
simplify(product);
poly = product.poly;
return *this;
}
{
if (gfe == 0)
{
poly.clear();
poly.push_back(0);
}
return *this;
}
{
if (poly.size() < polynomial.poly.size())
{
unsigned int j = 0;
for (unsigned int i = 0; i < poly.size(); i++)
{
poly[i] += polynomial.poly[j++];
}
for (; j < polynomial.poly.size(); j++)
{
poly.push_back(polynomial.poly[j]);
}
}
else
{
unsigned int i = 0;
for (unsigned int j = 0; j < polynomial.poly.size(); j++)
{
poly[i++] += polynomial.poly[j];
}
}
simplify(*this);
return *this;
}
{
poly[0] += gfe;
return *this;
}
{
return (*this += polynomial);
}
{
poly[0] -= gfe;
return *this;
}
{
const std::pair<GF2_Polynomial, GF2_Polynomial>& divres = div(*this, divisor);
poly = divres.first.get_poly();
return *this;
}
{
if (gfe == 0)
{
throw GF_Exception("Division by zero");
}
return *this;
}
GF2_Polynomial & rssoft::gf::GF2_Polynomial::operator<<= |
( |
const unsigned int & |
n | ) |
|
{
if (poly.size() > 0)
{
std::size_t initial_size = poly.size();
poly.resize(poly.size() + n, 1);
std::copy(poly.rend() - initial_size, poly.rend(), poly.rbegin());
std::fill(poly.begin(), poly.begin() + n, 0);
}
return *this;
}
{
if (this != &polynomial)
{
poly = polynomial.poly;
}
return *this;
}
{
poly.clear();
poly.push_back(gfe);
return *this;
}
bool rssoft::gf::GF2_Polynomial::operator== |
( |
const GF2_Polynomial & |
polynomial | ) |
const |
{
if (poly.size() != polynomial.poly.size())
return false;
else
{
for (unsigned int i = 0; i < poly.size(); i++)
{
if (poly[i] != polynomial.poly[i])
return false;
}
return true;
}
}
GF2_Polynomial & rssoft::gf::GF2_Polynomial::operator>>= |
( |
const unsigned int & |
n | ) |
|
{
if (n <= poly.size())
{
std::copy(poly.begin() + n, poly.end(), poly.begin());
poly.erase(poly.end() - n, poly.end());
}
else
{
poly.clear();
}
return *this;
}
GF2_Element & rssoft::gf::GF2_Polynomial::operator[] |
( |
unsigned int |
term | ) |
|
{
assert(term < poly.size());
return poly[term];
}
const GF2_Element & rssoft::gf::GF2_Polynomial::operator[] |
( |
unsigned int |
term | ) |
const |
{
assert(term < poly.size());
return poly[term];
}
GF2_Polynomial & rssoft::gf::GF2_Polynomial::operator^= |
( |
const int & |
n | ) |
|
{
GF2_Polynomial result = *this;
for (int i = 0; i < n; i++)
{
result *= *this;
}
*this = result;
return *this;
}
Sets the degree of the polynomial. Truncates or extends with zeros the coefficients vector internally
{
poly.resize(x - 1, 0);
}
Tells if the polynomial has coefficients
{
return (poly.size() > 0);
}
Friends And Related Function Documentation
std::ostream& operator<< |
( |
std::ostream & |
os, |
|
|
const GF2_Polynomial & |
polynomial |
|
) |
| [friend] |
Prints a polynomial to an output stream
{
if (polynomial.deg() >= 0)
{
bool is_null = true;
bool first_coeff = true;
for (unsigned int i = 0; i < polynomial.poly.size(); i++)
{
GF2_Element coeff = polynomial.poly[i];
if (coeff != 0)
{
is_null = false;
os << ((!first_coeff) ? "+ " : "");
if (i == 0)
{
os << "1 ";
}
else if (i==1)
{
os << "x ";
}
else
{
os << "x^" << i << " ";
}
first_coeff = false;
}
}
if (is_null)
{
os << "0";
}
}
return os;
}
Member Data Documentation
The documentation for this class was generated from the following files: