1 #ifndef _UZPOLYNOMIAL_H_ 2 #define _UZPOLYNOMIAL_H_ 5 #include "../Polynomial/BPASUnivarPolynomial.hpp" 22 for (
int i = 0; i < n; ++i)
35 static mpz_class characteristic;
45 coef =
new mpz_class[1];
56 coef =
new mpz_class[n];
68 coef =
new mpz_class[1];
69 coef[0] = e.get_mpz();
72 if (e.get_den() == 1) {
73 coef =
new mpz_class[1];
74 coef[0] = e.get_num().get_mpz();
77 std::cout <<
"BPAS error, try to construct a rational number in DUZP." << std::endl;
88 coef =
new mpz_class[n];
89 std::copy(b.coef, b.coef+n, coef);
118 inline Integer trailingCoefficient()
const {
119 for(
int i = 0; i <= curd; ++i) {
127 inline Integer numberOfTerms()
const {
129 for (
size_t i = 0; i <= curd; ++i) {
143 std::cout <<
"BPAS: warning, try to access a non-exist coefficient " << k <<
" from DUZP(" << n <<
")." << std::endl;
153 if (k < 0 || k >= n) {
166 if (k >= n || k < 0) {
167 std::cout <<
"BPAS: error, DUZP(" << n <<
") but trying to access " << k <<
"." << std::endl;
171 if (k > curd && value != 0)
214 if (n) {
delete [] coef; n = 0; }
218 coef =
new mpz_class[n];
219 std::copy(b.coef, b.coef+n, coef);
235 return !(isEqual(b));
254 return (coef[0] == 0);
275 return (coef[0] == 1);
287 for (
int i = 1; i < n; ++i)
298 return (coef[0] == -1);
310 for (
int i = 1; i < n; ++i)
320 if (curd) {
return 0; }
321 else if (coef[0] >= 0) {
return 1; }
363 mpz_class c = coef[0];
364 for (
int i = 1; i <= curd; ++i) {
366 mpz_gcd(c.get_mpz_t(), c.get_mpz_t(), coef[i].get_mpz_t());
376 std::cerr <<
"BPAS ERROR: DUZP::primitivePart NOT YET IMPLEMENTED" << std::endl;
386 return (coef[0] == 0);
501 coef[0] += c.get_mpz();
556 for (
int i = 0; i <= curd; ++i) {
594 coef[0] -= c.get_mpz();
659 mpz_class c = e.get_mpz();
665 if (e != 0 && e != 1) {
666 for (
int i = 0; i <= curd; ++i)
669 else if (e == 0) {
zero(); }
679 if (e != 0 && e != 1) {
680 for (
int i = 0; i <= curd; ++i)
683 else if (e == 0) {
zero(); }
740 mpz_class c = e.get_mpz();
747 return (*
this /= mpz_class(e));
886 // THIS FUNCTION IS DEPRECATED
887 // mpz_class evaluate(const mpz_class& x) const;
894 Integer evaluate(const Integer& x) const;
901 Factors<DenseUnivariateIntegerPolynomial> squareFree() const;
909 void print(std::ostream &out) const;
914 ExpressionTree convertToExpressionTree() const;
DenseUnivariateIntegerPolynomial gcd(const DenseUnivariateIntegerPolynomial &q, int type) const
GCD(p, q)
DenseUnivariateIntegerPolynomial & operator+=(const DenseUnivariateIntegerPolynomial &b)
Overload Operator +=.
Definition: uzpolynomial.h:460
DenseUnivariateIntegerPolynomial operator*(const DenseUnivariateIntegerPolynomial &b) const
Multiply to another polynomial.
DenseUnivariateIntegerPolynomial(const Integer &e)
Construct a polynomial with a coeffient.
Definition: uzpolynomial.h:67
void integrate()
Convert current object to its integral with constant of integration 0.
DenseUnivariateIntegerPolynomial & operator=(const DenseUnivariateIntegerPolynomial &b)
Overload operator =.
Definition: uzpolynomial.h:212
DenseUnivariateIntegerPolynomial & operator>>=(int k)
Overload operator >>= replace by dividing x^k, and return the quotient.
Definition: uzpolynomial.h:443
DenseUnivariateIntegerPolynomial operator^(long long int e) const
Overload operator ^ replace xor operation by exponentiation.
DenseUnivariateIntegerPolynomial & operator*=(const DenseUnivariateIntegerPolynomial &b)
Overload operator *=.
Definition: uzpolynomial.h:628
DenseUnivariateIntegerPolynomial & operator^=(long long int e)
Overload operator ^= replace xor operation by exponentiation.
Definition: uzpolynomial.h:403
DenseUnivariateIntegerPolynomial unitCanonical(DenseUnivariateIntegerPolynomial *u=NULL, DenseUnivariateIntegerPolynomial *v=NULL) const
Obtain the unit normal (a.k.a canonical associate) of an element.
Definition: uzpolynomial.h:330
mpz_class * coefficients(int k=0) const
Get coefficients of the polynomial, given start offset.
Definition: uzpolynomial.h:140
void differentiate()
Convert current object to its derivative.
Definition: uzpolynomial.h:841
DenseUnivariateIntegerPolynomial operator+(const DenseUnivariateIntegerPolynomial &b) const
Overload operator +.
DenseUnivariateIntegerPolynomial()
Construct a polynomial.
Definition: uzpolynomial.h:44
DenseUnivariateIntegerPolynomial(int s)
Construct a polynomial with degree.
Definition: uzpolynomial.h:53
Integer unitCanonical(Integer *u=NULL, Integer *v=NULL) const
Obtain the unit normal (a.k.a canonical associate) of an element.
DenseUnivariateIntegerPolynomial monicDivide(const DenseUnivariateIntegerPolynomial &b, DenseUnivariateIntegerPolynomial *rem) const
Monic division Return quotient.
Definition: uzpolynomial.h:767
DenseUnivariateIntegerPolynomial lazyPseudoDivide(const DenseUnivariateIntegerPolynomial &b, DenseUnivariateIntegerPolynomial *rem, Integer *c, Integer *d) const
Lazy pseudo dividsion Return the quotient e is the exact number of division steps.
Definition: uzpolynomial.h:793
A univariate polynomial with Integer coefficients using a dense representation.
Definition: uzpolynomial.h:14
Symbol variable() const
Get variable's name.
Definition: uzpolynomial.h:196
void setCoefficient(int k, const mpz_class value)
Set a coefficient of the polynomial.
Definition: uzpolynomial.h:165
Integer leadingCoefficient() const
Get the leading coefficient.
Definition: uzpolynomial.h:114
void one()
Set polynomial to 1.
Definition: uzpolynomial.h:284
DenseUnivariateIntegerPolynomial lazyPseudoDivide(const DenseUnivariateIntegerPolynomial &b, Integer *c, Integer *d=NULL)
Lazy pseudo dividsion Return the quotient and itself becomes remainder e is the exact number of divis...
DenseUnivariateIntegerPolynomial derivative() const
Compute derivative.
Definition: uzpolynomial.h:860
Integer coefficient(int k) const
Get a coefficient of the polynomial.
Definition: uzpolynomial.h:152
Integer content() const
Content of the polynomial.
Definition: uzpolynomial.h:362
DenseUnivariateIntegerPolynomial derivative(int k) const
Return k-th derivative.
Definition: uzpolynomial.h:850
bool isConstantTermZero() const
Is the least signficant coefficient zero.
Definition: uzpolynomial.h:385
int isConstant() const
Is a constant.
Definition: uzpolynomial.h:319
void zero()
Zero polynomial.
Definition: uzpolynomial.h:263
DenseUnivariateIntegerPolynomial & operator<<=(int k)
Overload operator << replace by muplitying x^k.
Definition: uzpolynomial.h:422
void subtract(const DenseUnivariateIntegerPolynomial &b)
Subtract another polynomial from itself.
DenseUnivariateIntegerPolynomial integral()
Compute integral with constant of integration 0.
Definition: uzpolynomial.h:874
void negate()
Compute -f(x)
Definition: uzpolynomial.h:555
DenseUnivariateIntegerPolynomial(const DenseUnivariateIntegerPolynomial &b)
Copy constructor.
Definition: uzpolynomial.h:86
An arbitrary-precision Integer.
Definition: Integer.hpp:22
An abstract class defining the interface of a univariate polynomial over an arbitrary BPASRing...
Definition: BPASUnivarPolynomial.hpp:22
void differentiate(int k)
Convert current object to its k-th derivative.
DenseUnivariateIntegerPolynomial & operator-=(const DenseUnivariateIntegerPolynomial &b)
Overload operator -=.
Definition: uzpolynomial.h:535
bool operator==(const DenseUnivariateIntegerPolynomial &b) const
Overload operator ==.
Definition: uzpolynomial.h:243
void add(const DenseUnivariateIntegerPolynomial &b)
Add another polynomial to itself.
bool isZero() const
Is zero polynomial.
Definition: uzpolynomial.h:252
bool operator!=(const DenseUnivariateIntegerPolynomial &b) const
Overload operator !=.
Definition: uzpolynomial.h:234
bool isOne() const
Is polynomial a constatn 1.
Definition: uzpolynomial.h:273
DenseUnivariateIntegerPolynomial operator>>(int k) const
Overload operator >> replace by dividing x^k, and return the quotient.
An encapsulation of a mathematical symbol.
Definition: Symbol.hpp:23
bool isNegativeOne() const
Is polynomial a constatn -1.
Definition: uzpolynomial.h:296
An arbitrary-precision rational number.
Definition: RationalNumber.hpp:24
DenseUnivariateIntegerPolynomial & operator/=(const DenseUnivariateIntegerPolynomial &b)
Overload operator /= ExactDivision.
DenseUnivariateIntegerPolynomial operator-() const
Overload operator -, negate.
DenseUnivariateIntegerPolynomial operator/(const DenseUnivariateIntegerPolynomial &b) const
Overload operator / ExactDivision.
Definition: uzpolynomial.h:701
DenseUnivariateIntegerPolynomial pseudoDivide(const DenseUnivariateIntegerPolynomial &b, Integer *d=NULL)
Pseudo dividsion Return the quotient and itself becomes remainder.
void negativeOne()
Set polynomial to -1.
Definition: uzpolynomial.h:307
DenseUnivariateIntegerPolynomial monicDivide(const DenseUnivariateIntegerPolynomial &b)
Monic division Return quotient and itself become the remainder.
void setCoefficient(int k, const Integer &value)
Set the coefficient of the monomial with degree d to be the Ring element r.
Definition: uzpolynomial.h:175
DenseUnivariateIntegerPolynomial operator<<(int k) const
Overload operator << replace by muplitying x^k.
Integer degree() const
Get degree of the polynomial.
Definition: uzpolynomial.h:105
~DenseUnivariateIntegerPolynomial()
Destroy the polynomial.
Definition: uzpolynomial.h:96
void setVariableName(const Symbol &x)
Set variable's name.
Definition: uzpolynomial.h:204