English | 中文
POLY.H is a library that supports diverse polynomial calculation including linear computation, multiplication, inversion, square root, logarithm and exponent. Also, it supports polynomial with arbitrary modulus.
POLY.H is implemented in C++. You only need to download the header file poly.h.
There are two classes in POLY.H: poly
and m_poly
, both inside namespace fstdlib
. You can call them by fstdlib::poly
and fstdlib::m_poly
, or simply use using namespace fstdlib
.
poly
is a polynomial class with fixed modulus fstdlib::mod
, whose value is VARIABLE_MODULO
in advance and ensure that:
- The new modulus can be used for NTT. In other words, it has to be a prime and can be represented by
$k \cdot 2^r + 1$ where$k$ and$r$ are integers and$2^r$ is big enough. - Twice this modulus is within the range of 32b signed integer.
Besides, if fstdlib::grt
to a primitive root of your modulus.
m_poly
is a polynomial class with arbitrary modulus mod
, which is a 32b signed integer member of each single instance. You should ensure:
- Twice your modulus is within the range of 32b signed integer.
- Any instances that are calculated together have the same modulus.
- If the modulus is not a prime, no calculation except for linear computation and multiplication is applied.
Method | Intro |
---|---|
poly(std::size_t n) |
Create a polynomial of length |
poly(std::vector<int> a) |
Create a polynomial by a vector. |
m_poly(std::size_t n, int p) |
Create a polynomial of arbitrary modulus |
m_poly(std::vector<int> a, int p) |
Create a polynomial of arbitrary modulus |
Method | Intro | Time Complexity |
---|---|---|
poly operator*(const poly &, const poly &) |
Convolution of two polynomials. | |
poly &operator*=(poly &, const poly &) |
Convolution of two polynomials. | |
poly operator*(const poly &, const int & |
Convolution of a polynomial and a monomial. | |
poly &operator*=(poly &, const int &) |
Convolution of a polynomial and a monomial. | |
poly operator*(const int &, const poly &) |
Convolution of a polynomial and a monomial. | |
poly operator>>(const poly &, const int &) |
Right shift of a polynomial. | |
poly &operator>>=(poly &, const int &) |
Right shift of a polynomial. | |
poly operator<<(const poly &, const int &) |
Left shift of a polynomial. | |
poly &operator<<=(poly &, const int &) |
Left shift of a polynomial. | |
poly operator+(const poly &, const poly &) |
Sum of two polynomials. | |
poly &operator+=(poly &, const poly &) |
Sum of two polynomials. | |
poly operator+(const poly &, const int & |
Sum of a polynomial and a monomial. | |
poly &operator+=(poly &, const int &) |
Sum of a polynomial and a monomial. | |
poly operator+(const int &, const poly &) |
Sum of a monomial and a polynomial. | |
poly operator-(const poly &, const poly &) |
Substraction of two polynomials. | |
poly &operator-=(poly &, const poly &) |
Substraction of two polynomials. | |
poly operator-(const poly &, const int & |
Substraction of a polynomial and a monomial. | |
poly &operator-=(poly &, const int &) |
Substraction of a polynomial and a monomial. | |
poly operator-(const int &, const poly &) |
Substraction of a monomial and a polynomial. | |
poly operator/(const poly &, const int &) |
Division of a polynomial and a monomial. | |
poly operator/=(const poly &, const int &) |
Division of a polynomial and a monomial. |
Method | Intro | Time Complexity |
---|---|---|
poly poly::inv(void)const |
Inversoin of a polynomial. | |
poly poly::inv(std::size_t)const |
Inversion of a polynomial of a specified length. | |
poly poly::prefix(std::size_t)const |
Prefix of a polynomial. The parameter can be greater than the polynomial's length. |
Method | Intro | Time Complexity |
---|---|---|
poly sqrt(const poly &) |
Square root of a polynomial. | |
poly log(const poly &) |
Exponent of a polynomial. | |
poly exp(const poly &) |
Logarithm of a polynomial. |
- The constant term of the polynomial
sqrt
applied to must be$1$ . - The constant term of the polynomial
log
applied to must be$1$ . - The constant term of the polynomial
exp
applied to must be$0$ .