1 #ifndef _SMALLMMPOLYNOMIAL_H_ 2 #define _SMALLMMPOLYNOMIAL_H_ 4 #include "../Polynomial/BPASMultivarPolynomial.hpp" 5 #include "../FFT/src/modpn.h" 6 #include "../FFT/src/general_routine.h" 7 #include "../FFT/src/basic_routine.h" 8 #include "../FFT/src/DDMP.h" 17 #define SDMPBASESIZE 1024 42 static mpz_class characteristic;
89 for (
int i = 0; i < var; ++i) {
92 acc[i+1] = acc[i] * (degs[i] + 1);
94 n = acc[var-1] * (degs[var-1] + 1);
99 for (
int i = 1; i <= var; ++i) {
100 std::ostringstream convert;
101 convert << var - i + 1;
103 names[i] += convert.str();
122 coefs =
new sfixn[2];
134 std::copy(b.degs, b.degs+var, degs);
136 std::copy(b.acc, b.acc+var, acc);
137 coefs =
new sfixn[n];
138 std::copy(b.coefs, b.coefs+n, coefs);
139 names =
new Symbol[var+1];
140 std::copy(b.names, b.names+var+1, names);
169 std::copy(b.degs, b.degs+var, degs);
171 std::copy(b.acc, b.acc+var, acc);
173 coefs =
new sfixn[n];
174 std::copy(b.coefs, b.coefs+n, coefs);
175 names =
new Symbol[var+1];
176 std::copy(b.names, b.names+var+1, names);
190 return SmallPrimeFieldDistributedDenseMultivariateModularPolynomial::characteristic;
198 for (
int i = 0; i < n; ++i) {
220 for (
int i = 1; i < n; ++i) {
224 return (coefs[0] == 1);
234 for (
int i = 1; i < n; ++i)
244 for (
int i = 1; i < n; ++i) {
248 return (coefs[0] == p - 1);
258 for (
int i = 1; i < n; ++i)
268 for (
int i = 1; i < n; ++i) {
272 if (coefs[0] < (p >> 1)) {
return 1; }
279 mpz_class mpzLead(leadCoef);
280 mpz_class mpzPrime(p);
284 if (!mpz_invert(temp, mpzLead.get_mpz_t(), mpzPrime.get_mpz_t()))
286 sfixn leadInv = mpz_get_si(temp);
305 return variables().size();
322 for (
int i = 0; i < n; ++i)
323 if (coefs[i] != 0) { k++; }
340 std::cerr <<
"SmallPrimeFieldDistributedDenseMultivariateModularPolynomial::degree() NOT YET IMPLEMENTED" << std::endl;
352 for (
int i = 1; i <= var; ++i) {
360 for (
int i = 0; i < n; ++i) {
361 int e = (i / acc[k]) % (degs[k] + 1);
362 if (coefs[i] != 0 && e > d)
375 for (
int i = n-1; i > -1; --i) {
382 inline sfixn trailingCoefficient()
const {
383 for (
int i = 0; i < n; ++i) {
391 inline bool isConstantTermZero()
const {
392 return (coefs[0] == 0);
403 for (
int i = var-1, j = 0; i > -1 && j < v; --i, ++j) {
408 for (
int i = v-var-1; i > -1; --i)
409 if (d[i]) {
return 0; }
413 inline sfixn
coefficient(
const std::vector<int>& v)
const {
426 std::cout <<
"BPAS: error, SFDDMMP(" << var <<
"), but trying to setCoefficient with " << v <<
" variables." << std::endl;
430 for (
int i = var-1, j = 0; i > -1 && j < v; --i, ++j) {
434 std::cout <<
"BPAS: error, the degree of " << names[i+1] <<
" in SFDDMMP is " << degs[i] <<
"." << std::endl;
441 inline void setCoefficient(
const std::vector<int>& v,
const sfixn& val) {
452 if (k >= n || k < 0) {
453 std::cout <<
"BPAS: error, trying to access a non-exist coefficient in SFDDMMP<Field>." << std::endl;
465 std::vector<Symbol> xs;
466 for (
int i = var; i > 0; --i)
467 xs.push_back(names[i]);
479 std::cerr <<
"BPAS ERROR: SDMP shrinking and expanding polynomial ring NOT YET IMPLEMENTED" << std::endl;
483 for (
int i = var, j = 0; i > 0 && j < ns; --i, ++j)
487 inline std::vector<Symbol> variables()
const {
488 std::cerr <<
"BPAS ERROR: SDMP::variables() NOT YET IMPLEMENTED" << std::endl;
564 return !(*
this == b);
702 std::cerr <<
"BPAS ERROR: SmallPrimeFieldDistributedDenseMultivariateModularPolynomial::opeartor^ NOT YET IMPLEMENTED" << std::endl;
717 std::cerr <<
"BPAS ERROR: SmallPrimeFieldDistributedDenseMultivariateModularPolynomial::operator/(sfixn) NOT YET IMPLEMENTED" << std::endl;
725 sfixn content()
const {
726 std::cerr <<
"BPAS ERROR: SmallPrimeFieldDistributedDenseMultivariateModularPolynomial::content NOT YET IMPLEMENTED" << std::endl;
731 std::cerr <<
"BPAS ERROR: SmallPrimeFieldDistributedDenseMultivariateModularPolynomial::primitivePart NOT YET IMPLEMENTED" << std::endl;
735 void print(std::ostream& out)
const;
744 std::cerr <<
"SmallPrimeFieldDistributedDenseMultivariateModularPolynomial::operator/ NOT YET IMPLEMENTED" << std::endl;
750 std::cerr <<
"SmallPrimeFieldDistributedDenseMultivariateModularPolynomial::operator/= NOT YET IMPLEMENTED" << std::endl;
756 std::cerr <<
"SmallPrimeFieldDistributedDenseMultivariateModularPolynomial::gcd NOT YET IMPLEMENTED" << std::endl;
765 std::cerr <<
"SmallPrimeFieldDistributedDenseMultivariateModularPolynomial::squareFree NOT YET IMPLEMENTED" << std::endl;
767 std::vector<SmallPrimeFieldDistributedDenseMultivariateModularPolynomial> ret;
768 ret.push_back(*
this);
SmallPrimeFieldDistributedDenseMultivariateModularPolynomial & operator-=(const SmallPrimeFieldDistributedDenseMultivariateModularPolynomial &b)
Overload operator -=.
Definition: sdmpolynomial.h:617
SmallPrimeFieldDistributedDenseMultivariateModularPolynomial & operator+=(const SmallPrimeFieldDistributedDenseMultivariateModularPolynomial &b)
Overload operator +=.
Definition: sdmpolynomial.h:579
SmallPrimeFieldDistributedDenseMultivariateModularPolynomial derivative(const Symbol &s) const
Compute derivative.
Definition: sdmpolynomial.h:525
SmallPrimeFieldDistributedDenseMultivariateModularPolynomial evaluate(int, const Symbol *syms, const sfixn *xs) const
Evaluate f(x)
Definition: sdmpolynomial.h:535
void print(std::ostream &out) const
Print the Ring element.
A multivariate polynomial with coefficients in a small prime field using a dense representation.
Definition: sdmpolynomial.h:22
An abstract class defining the interface of a GCD domain.
Definition: BPASGCDDomain.hpp:14
bool isOne() const
Is polynomial 1.
Definition: sdmpolynomial.h:219
sfixn coefficient(int v, const int *d) const
Get a coefficient.
Definition: sdmpolynomial.h:401
SmallPrimeFieldDistributedDenseMultivariateModularPolynomial(Symbol x, sfixn m)
Construct with a variable name such that f(x) = x;.
Definition: sdmpolynomial.h:114
SmallPrimeFieldDistributedDenseMultivariateModularPolynomial operator*(const SmallPrimeFieldDistributedDenseMultivariateModularPolynomial &b) const
Overload operator *.
SmallPrimeFieldDistributedDenseMultivariateModularPolynomial(const SmallPrimeFieldDistributedDenseMultivariateModularPolynomial &b)
Copy constructor.
Definition: sdmpolynomial.h:132
SmallPrimeFieldDistributedDenseMultivariateModularPolynomial & operator*=(const SmallPrimeFieldDistributedDenseMultivariateModularPolynomial &b)
Overload operator *=.
Definition: sdmpolynomial.h:669
Factors< SmallPrimeFieldDistributedDenseMultivariateModularPolynomial > squareFree() const
Compute squarefree factorization of *this.
Definition: sdmpolynomial.h:764
An ExpressionTree encompasses various forms of data that can be expressed generically as a binary tre...
Definition: ExpressionTree.hpp:17
void setRingVariables(const std::vector< Symbol > &xs)
Set variable names.
Definition: sdmpolynomial.h:476
~SmallPrimeFieldDistributedDenseMultivariateModularPolynomial()
Deconstructor.
Definition: sdmpolynomial.h:148
SmallPrimeFieldDistributedDenseMultivariateModularPolynomial operator+(const SmallPrimeFieldDistributedDenseMultivariateModularPolynomial &b) const
Overload operator +.
ExpressionTree convertToExpressionTree() const
Convert *this to an expression tree.
void negate()
Negate, f(-x)
SmallPrimeFieldDistributedDenseMultivariateModularPolynomial unitCanonical(SmallPrimeFieldDistributedDenseMultivariateModularPolynomial *u=NULL, SmallPrimeFieldDistributedDenseMultivariateModularPolynomial *v=NULL) const
Obtain the unit normal (a.k.a canonical associate) of an element.
Definition: sdmpolynomial.h:276
int numberOfRingVariables() const
Get the number of variables in this polynomial ring.
Definition: sdmpolynomial.h:311
void zero()
Zero polynomial.
Definition: sdmpolynomial.h:210
void setCoefficient(int v, const int *d, const sfixn &val)
Set a coefficient.
Definition: sdmpolynomial.h:424
SmallPrimeFieldDistributedDenseMultivariateModularPolynomial(int v, int *ds, sfixn m)
Constructor with number of variables and terms.
Definition: sdmpolynomial.h:85
SmallPrimeFieldDistributedDenseMultivariateModularPolynomial derivative(const Symbol &s, int k) const
Return k-th derivative.
Definition: sdmpolynomial.h:515
void differentiate(const Symbol &s)
Convert current object to its derivative.
Definition: sdmpolynomial.h:505
SmallPrimeFieldDistributedDenseMultivariateModularPolynomial & operator=(const SmallPrimeFieldDistributedDenseMultivariateModularPolynomial &b)
Overload operator =.
Definition: sdmpolynomial.h:160
bool operator==(const SmallPrimeFieldDistributedDenseMultivariateModularPolynomial &b) const
Overload operator ==.
void differentiate(const Symbol &s, int k)
Convert current object to its k-th derivative.
Definition: sdmpolynomial.h:498
A simple data structure for encapsulating a collection of Factor elements.
Definition: Factors.hpp:95
SmallPrimeFieldDistributedDenseMultivariateModularPolynomial()
Constructor using a default prime.
Definition: sdmpolynomial.h:50
bool isZero() const
Is a zero polynomial.
Definition: sdmpolynomial.h:197
Integer numberOfTerms() const
Get the number of non-zero terms.
Definition: sdmpolynomial.h:320
sfixn leadingCoefficient() const
Get the leading coefficient.
Definition: sdmpolynomial.h:374
SmallPrimeFieldDistributedDenseMultivariateModularPolynomial evaluate(const std::vector< Symbol > &syms, const std::vector< sfixn > &xs) const
Evaluate f(x)
Definition: sdmpolynomial.h:546
An arbitrary-precision Integer.
Definition: Integer.hpp:22
bool isNegativeOne() const
Is polynomial -1.
Definition: sdmpolynomial.h:243
std::vector< Symbol > ringVariables() const
Get variable names.
Definition: sdmpolynomial.h:464
bool operator!=(const SmallPrimeFieldDistributedDenseMultivariateModularPolynomial &b) const
Overload operator !=.
Definition: sdmpolynomial.h:563
SmallPrimeFieldDistributedDenseMultivariateModularPolynomial(sfixn m)
Constructor with the field.
Definition: sdmpolynomial.h:67
An encapsulation of a mathematical symbol.
Definition: Symbol.hpp:23
void negativeOne()
Set polynomial to -1.
Definition: sdmpolynomial.h:256
SmallPrimeFieldDistributedDenseMultivariateModularPolynomial & operator^=(long long int e)
Overload operator ^ for exponentiation.
Definition: sdmpolynomial.h:711
Integer degree() const
Total degree.
Definition: sdmpolynomial.h:339
int numberOfVariables() const
Get the number of variables.
Definition: sdmpolynomial.h:304
int isConstant() const
Is a constant.
Definition: sdmpolynomial.h:267
void setCoefficient(int k, const sfixn &val)
Set a coefficient.
Definition: sdmpolynomial.h:451
SmallPrimeFieldDistributedDenseMultivariateModularPolynomial operator/(const SmallPrimeFieldDistributedDenseMultivariateModularPolynomial &p) const
Exact division.
Definition: sdmpolynomial.h:743
mpz_class getCharacteristic() const override
The characteristic of this ring class.
Definition: sdmpolynomial.h:189
SmallPrimeFieldDistributedDenseMultivariateModularPolynomial & operator/=(const SmallPrimeFieldDistributedDenseMultivariateModularPolynomial &p)
Exact division assignment.
Definition: sdmpolynomial.h:749
int size() const
Get the size of the polynomial.
Definition: sdmpolynomial.h:332
Integer degree(const Symbol &x) const
Get a partial degree of variable x.
Definition: sdmpolynomial.h:350
SmallPrimeFieldDistributedDenseMultivariateModularPolynomial operator^(long long int e) const
Overload operator ^ for exponentiation.
Definition: sdmpolynomial.h:700
SmallPrimeFieldDistributedDenseMultivariateModularPolynomial operator-() const
Overload operator -, negate.
SmallPrimeFieldDistributedDenseMultivariateModularPolynomial gcd(const SmallPrimeFieldDistributedDenseMultivariateModularPolynomial &p) const
Get GCD of *this and other.
Definition: sdmpolynomial.h:755
void one()
Set polynomial to 1.
Definition: sdmpolynomial.h:232