1 #ifndef _UNIPOLYNOMIAL_H_ 2 #define _UNIPOLYNOMIAL_H_ 5 #include "../Polynomial/BPASUnivarPolynomial.hpp" 6 #include "../DyadicRationalNumber/globals.h" 7 #include "../DyadicRationalNumber/Multiplication/multiplication.h" 8 #include "../Interval/interval.h" 11 void ts_modulo (lfixz*, lfixz, lfixz,
int);
24 for (
int i = 0; i < n; ++i)
29 void taylorShiftCVL();
33 void taylorShiftDnC(
int,
int);
37 void taylorShiftDnC(
int);
38 void binomials(lfixz*,
int);
39 void taylorShiftBasePower2(lfixz*,
int);
42 void taylorShiftIncrementalCilkFor(lfixq*,
int,
int);
43 void tableauBase(lfixq*,
int);
44 void polygonBase(lfixq*,
int,
int,
int);
45 void taylorShiftBase(lfixq*,
int);
46 void taylorShift3RegularCilkFor(lfixq*,
int,
int);
49 void taylorShiftTableau(
int);
50 void taylorShiftBase(lfixq*, lfixq*,
int);
51 void tableauBaseInplace(lfixq*, lfixq*,
int,
int);
52 void tableauConstruction(lfixq*, lfixq*,
int,
int,
int);
53 void taylorShiftGeneral(lfixq*, lfixq*,
int,
int);
56 lfixz positiveRootBound();
57 lfixz cauchyRootBound();
58 lfixz complexRootBound();
62 long taylorConstant(
int, lfixz,
int, lfixz);
100 if (s < 1) { s = 1; }
116 coef[0] = mpq_class(e.get_mpz());
121 coef[0] = mpq_class(e.get_mpq());
132 std::copy(b.coef, b.coef+n, coef);
163 for (
size_t i = 0; i <= curd; ++i) {
171 inline Integer numberOfTerms()
const {
173 for (
size_t i = 0; i <= curd; ++i) {
189 std::cout <<
"BPAS: warning, try to access a non-exist coefficient " << k <<
" from DUQP(" << n <<
")." << std::endl;
212 if (k >= n || k < 0) {
213 std::cout <<
"BPAS: error, DUQP(" << n <<
") but trying to access " << k <<
"." << std::endl;
216 coef[k] = value.get_mpq();
217 if (k > curd && value != 0)
244 inline DenseUnivariateRationalPolynomial unitCanonical(DenseUnivariateRationalPolynomial* u = NULL, DenseUnivariateRationalPolynomial* v = NULL)
const {
247 DenseUnivariateRationalPolynomial ret = *
this * leadInv;
262 inline DenseUnivariateRationalPolynomial&
operator= (
const DenseUnivariateRationalPolynomial& b) {
264 if (n) {
delete [] coef; n = 0; }
269 std::copy(b.coef, b.coef+n, coef);
284 inline bool operator!= (
const DenseUnivariateRationalPolynomial& b)
const {
285 return !(isEqual(b));
293 inline bool operator== (
const DenseUnivariateRationalPolynomial& b)
const {
304 return (coef[0] == 0);
326 return (coef[0] == 1);
338 for (
int i = 1; i < n; ++i)
349 return (coef[0] == -1);
361 for (
int i = 1; i < n; ++i)
371 if (curd) {
return 0; }
372 else if (coef[0] >= 0) {
return 1; }
385 inline DenseUnivariateRationalPolynomial primitivePart()
const {
387 std::cerr <<
"BPAS ERROR: DUQP::primitivePart NOT YET IMPLEMENTED" << std::endl;
397 DenseUnivariateRationalPolynomial
operator^ (
long long int e)
const;
405 inline DenseUnivariateRationalPolynomial&
operator^= (
long long int e) {
416 DenseUnivariateRationalPolynomial
operator<< (
int k)
const;
436 DenseUnivariateRationalPolynomial
operator>> (
int k)
const;
455 DenseUnivariateRationalPolynomial
operator+ (
const DenseUnivariateRationalPolynomial& b)
const;
462 inline DenseUnivariateRationalPolynomial&
operator+= (
const DenseUnivariateRationalPolynomial& b) {
475 void add(
const DenseUnivariateRationalPolynomial& b);
483 DenseUnivariateRationalPolynomial r (*
this);
487 inline DenseUnivariateRationalPolynomial
operator+ (
const mpq_class& c)
const {
488 DenseUnivariateRationalPolynomial r (*
this);
498 coef[0] += lfixq(c.get_mpq());
502 inline DenseUnivariateRationalPolynomial&
operator+= (
const mpq_class& c) {
507 inline friend DenseUnivariateRationalPolynomial
operator+ (
const mpq_class& c,
const DenseUnivariateRationalPolynomial& p) {
516 DenseUnivariateRationalPolynomial
operator- (
const DenseUnivariateRationalPolynomial& b)
const;
523 inline DenseUnivariateRationalPolynomial&
operator-= (
const DenseUnivariateRationalPolynomial& b) {
536 DenseUnivariateRationalPolynomial
operator- ()
const;
543 void subtract(
const DenseUnivariateRationalPolynomial& b);
551 DenseUnivariateRationalPolynomial r (*
this);
555 inline DenseUnivariateRationalPolynomial
operator- (
const mpq_class& c)
const {
556 DenseUnivariateRationalPolynomial r (*
this);
566 coef[0] -= lfixq(c.get_mpq());
570 inline DenseUnivariateRationalPolynomial&
operator-= (
const mpq_class& c) {
575 inline friend DenseUnivariateRationalPolynomial
operator- (
const mpq_class& c,
const DenseUnivariateRationalPolynomial& p) {
584 DenseUnivariateRationalPolynomial
operator* (
const DenseUnivariateRationalPolynomial& b)
const;
591 inline DenseUnivariateRationalPolynomial&
operator*= (
const DenseUnivariateRationalPolynomial& b) {
602 DenseUnivariateRationalPolynomial r (*
this);
606 inline DenseUnivariateRationalPolynomial
operator* (
const mpq_class& e)
const {
607 DenseUnivariateRationalPolynomial r (*
this);
611 inline DenseUnivariateRationalPolynomial
operator* (
const sfixn& e)
const {
612 DenseUnivariateRationalPolynomial r (*
this);
623 DenseUnivariateRationalPolynomial&
operator*= (
const mpq_class& e);
630 DenseUnivariateRationalPolynomial&
operator*= (
const sfixn& e);
632 inline friend DenseUnivariateRationalPolynomial
operator* (
const mpq_class& c,
const DenseUnivariateRationalPolynomial& p) {
636 inline friend DenseUnivariateRationalPolynomial
operator* (
const sfixn& c,
const DenseUnivariateRationalPolynomial& p) {
646 inline DenseUnivariateRationalPolynomial
operator/ (
const DenseUnivariateRationalPolynomial& b)
const{
647 DenseUnivariateRationalPolynomial rem(*
this);
657 DenseUnivariateRationalPolynomial&
operator/= (
const DenseUnivariateRationalPolynomial& b);
659 inline DenseUnivariateRationalPolynomial operator% (
const DenseUnivariateRationalPolynomial& b)
const {
660 DenseUnivariateRationalPolynomial ret(*
this);
665 inline DenseUnivariateRationalPolynomial& operator%= (
const DenseUnivariateRationalPolynomial& b) {
666 *
this = this->remainder(b);
676 DenseUnivariateRationalPolynomial r (*
this);
680 inline DenseUnivariateRationalPolynomial
operator/ (
const mpq_class& e)
const {
681 DenseUnivariateRationalPolynomial r (*
this);
692 DenseUnivariateRationalPolynomial&
operator/= (
const mpq_class& e);
694 friend DenseUnivariateRationalPolynomial
operator/ (
const mpq_class& c,
const DenseUnivariateRationalPolynomial& p);
702 DenseUnivariateRationalPolynomial
monicDivide(
const DenseUnivariateRationalPolynomial& b);
711 DenseUnivariateRationalPolynomial
monicDivide(
const DenseUnivariateRationalPolynomial& b, DenseUnivariateRationalPolynomial* rem)
const;
755 DenseUnivariateRationalPolynomial
pseudoDivide (
const DenseUnivariateRationalPolynomial& b, DenseUnivariateRationalPolynomial* rem,
RationalNumber* d)
const;
763 DenseUnivariateRationalPolynomial
halfExtendedEuclidean (
const DenseUnivariateRationalPolynomial& b, DenseUnivariateRationalPolynomial* g)
const;
773 void diophantinEquationSolve(
const DenseUnivariateRationalPolynomial& a,
const DenseUnivariateRationalPolynomial& b, DenseUnivariateRationalPolynomial* s, DenseUnivariateRationalPolynomial* t)
const;
795 inline DenseUnivariateRationalPolynomial
derivative(
int k)
const {
796 DenseUnivariateRationalPolynomial a(*
this);
805 inline DenseUnivariateRationalPolynomial
derivative()
const {
827 inline DenseUnivariateRationalPolynomial
integral()
const {
828 DenseUnivariateRationalPolynomial a(*
this);
853 template <
class LargerRing>
858 LargerRing px = (LargerRing)coef[curd];
859 for (
int i = curd-1; i > -1; --i){
860 a = (LargerRing)coef[i];
865 return (LargerRing)coef[0];
880 DenseUnivariateRationalPolynomial
gcd (
const DenseUnivariateRationalPolynomial& q,
int type)
const;
882 inline DenseUnivariateRationalPolynomial
gcd(
const DenseUnivariateRationalPolynomial& q)
const {
967 univariatePositiveRealRootIsolation(&pIs,
this, width, ts);
968 std::vector<Symbol> xs;
990 univariatePositiveRealRootIsolation(&pIs,
this, width, ts);
991 std::vector<Symbol> xs;
1005 univariateRealRootIsolation(&pIs,
this, width, ts);
1016 refineUnivariateInterval(a, a->right+1,
this, width);
1027 refineUnivariateIntervals(&b, &a,
this, width);
1037 void print(std::ostream &out)
const;
1050 inline DenseUnivariateRationalPolynomial euclideanDivision(
const DenseUnivariateRationalPolynomial& b, DenseUnivariateRationalPolynomial* q = NULL)
const {
1052 DenseUnivariateRationalPolynomial monicb = b * lc.
inverse();
1054 DenseUnivariateRationalPolynomial rem;
1059 DenseUnivariateRationalPolynomial rem = *
this;
1064 inline DenseUnivariateRationalPolynomial extendedEuclidean(
const DenseUnivariateRationalPolynomial& b,
1065 DenseUnivariateRationalPolynomial* s = NULL,
1066 DenseUnivariateRationalPolynomial* t = NULL)
const {
1067 DenseUnivariateRationalPolynomial g = this->
gcd(b);
1072 inline DenseUnivariateRationalPolynomial quotient(
const DenseUnivariateRationalPolynomial& b)
const {
1073 DenseUnivariateRationalPolynomial q;
1074 this->euclideanDivision(b, &q);
1078 inline DenseUnivariateRationalPolynomial remainder(
const DenseUnivariateRationalPolynomial& b)
const {
1079 return this->euclideanDivision(b);
DenseUnivariateRationalPolynomial(const DenseUnivariateRationalPolynomial &b)
Copy constructor.
Definition: urpolynomial.h:129
DenseUnivariateRationalPolynomial halfExtendedEuclidean(const DenseUnivariateRationalPolynomial &b, DenseUnivariateRationalPolynomial *g) const
s * a g (mod b), where g = gcd(a, b)
DenseUnivariateRationalPolynomial pseudoDivide(const DenseUnivariateRationalPolynomial &b, RationalNumber *d=NULL)
Pseudo dividsion Return the quotient and itself becomes remainder.
bool isConstantTermZero() const
Is the least signficant coefficient zero.
mpq_class * coefficients(int k=0) const
Get coefficients of the polynomial, given start offset.
Definition: urpolynomial.h:186
void setVariableNames(const std::vector< Symbol > &xs)
Set variable names.
Definition: interval.h:191
DenseUnivariateRationalPolynomial operator-() const
Overload operator -, negate.
DenseUnivariateRationalPolynomial operator^(long long int e) const
Overload operator ^ replace xor operation by exponentiation.
Integer euclideanSize() const
BPASEuclideanDomain methods.
Definition: urpolynomial.h:1045
DenseUnivariateRationalPolynomial & operator>>=(int k)
Overload operator >>= replace by dividing x^k, and return the quotient.
Definition: urpolynomial.h:445
void zero()
Zero polynomial.
Definition: urpolynomial.h:313
LargerRing evaluate(const LargerRing &x) const
Evaluate f(x)
Definition: urpolynomial.h:854
void diophantinEquationSolve(const DenseUnivariateRationalPolynomial &a, const DenseUnivariateRationalPolynomial &b, DenseUnivariateRationalPolynomial *s, DenseUnivariateRationalPolynomial *t) const
s*a + t*b = c, where c in the ideal (a,b)
bool operator==(const DenseUnivariateRationalPolynomial &b) const
Overload operator ==.
Definition: urpolynomial.h:293
void setVariableName(const Symbol &x)
Set variable's name.
Definition: urpolynomial.h:240
DenseUnivariateRationalPolynomial operator*(const DenseUnivariateRationalPolynomial &b) const
Multiply to another polynomial.
DenseUnivariateRationalPolynomial & operator<<=(int k)
Overload operator <<= replace by muplitying x^k.
Definition: urpolynomial.h:424
void negate()
Compute -f(x)
Intervals realRootIsolate(mpq_class width, int ts=-1)
Real root isolation for square-free polynomials.
Definition: urpolynomial.h:1003
bool isOne() const
Is polynomial a constatn 1.
Definition: urpolynomial.h:324
void one()
Set polynomial to 1.
Definition: urpolynomial.h:335
void differentiate(int k)
Convert current object to its k-th derivative.
RationalNumber coefficient(int k) const
Get a coefficient of the polynomial.
Definition: urpolynomial.h:199
void differentiate()
Convert current object to its derivative.
Definition: urpolynomial.h:786
An ExpressionTree encompasses various forms of data that can be expressed generically as a binary tre...
Definition: ExpressionTree.hpp:17
DenseUnivariateRationalPolynomial & operator-=(const DenseUnivariateRationalPolynomial &b)
Overload operator -=.
Definition: urpolynomial.h:523
DenseUnivariateRationalPolynomial(const Integer &e)
Construct a polynomial with a coefficient.
Definition: urpolynomial.h:114
void integrate()
Compute the integral with constant of integration 0.
DenseUnivariateRationalPolynomial lazyPseudoDivide(const DenseUnivariateRationalPolynomial &b, RationalNumber *c, RationalNumber *d=NULL)
Lazy pseudo dividsion Return the quotient and itself becomes remainder e is the exact number of divis...
Data Structure for interval [a, b].
Definition: interval.h:11
Integer degree() const
Get degree of the polynomial.
Definition: urpolynomial.h:149
void refineRoot(Interval *a, mpq_class width)
Refine a root.
Definition: urpolynomial.h:1015
bool isZero() const
Is zero polynomial.
Definition: urpolynomial.h:302
DenseUnivariateRationalPolynomial & operator*=(const DenseUnivariateRationalPolynomial &b)
Overload operator *=.
Definition: urpolynomial.h:591
bool isNegativeOne() const
Is polynomial a constatn -1.
Definition: urpolynomial.h:347
DenseUnivariateRationalPolynomial operator>>(int k) const
Overload operator >> replace by dividing x^k, and return the quotient.
Factors< DenseUnivariateRationalPolynomial > squareFree() const
Square free.
A univariate polynomial with RationalNumber coefficients represented densely.
Definition: urpolynomial.h:16
DenseUnivariateRationalPolynomial & operator=(const DenseUnivariateRationalPolynomial &b)
Overload operator =.
Definition: urpolynomial.h:262
void homothetic(int k=1)
Homothetic operation.
void taylorShift(int ts=-1)
Taylor Shift operation by 1.
DenseUnivariateRationalPolynomial derivative() const
Compute derivative.
Definition: urpolynomial.h:805
DenseUnivariateRationalPolynomial()
Construct a polynomial.
Definition: urpolynomial.h:89
void negativeOne()
Set polynomial to -1.
Definition: urpolynomial.h:358
Intervals refineRoots(Intervals &a, mpq_class width)
Refine the roots.
Definition: urpolynomial.h:1025
DenseUnivariateRationalPolynomial integral() const
Compute integral with constant of integration 0.
Definition: urpolynomial.h:827
A simple data structure for encapsulating a collection of Factor elements.
Definition: Factors.hpp:95
bool divideByVariableIfCan()
Divide by variable if it is zero.
DenseUnivariateRationalPolynomial derivative(int k) const
Return k-th derivative.
Definition: urpolynomial.h:795
An arbitrary-precision Integer.
Definition: Integer.hpp:22
void negativeVariable()
Compute f(-x)
An abstract class defining the interface of a univariate polynomial over an arbitrary BPASRing...
Definition: BPASUnivarPolynomial.hpp:22
RationalNumber evaluate(const RationalNumber &x) const
Evaluate f(x)
void print(std::ostream &out) const
Overload stream operator <<.
mpz_class rootBound()
Return an integer k such that any positive root alpha of the polynomial satisfies alpha < 2^k...
void scaleTransform(int k)
Scale transform operation.
bool operator!=(const DenseUnivariateRationalPolynomial &b) const
Overload operator !=.
Definition: urpolynomial.h:284
DenseUnivariateRationalPolynomial & operator/=(const DenseUnivariateRationalPolynomial &b)
Overload operator /= ExactDivision.
Intervals positiveRealRootIsolate(mpq_class width, int ts=-1)
Positive real root isolation for square-free polynomials.
Definition: urpolynomial.h:965
int isConstant() const
Is a constant.
Definition: urpolynomial.h:370
void setCoefficient(int k, const RationalNumber &value)
Set a coefficient of the polynomial.
Definition: urpolynomial.h:211
An encapsulation of a mathematical symbol.
Definition: Symbol.hpp:23
An arbitrary-precision rational number.
Definition: RationalNumber.hpp:24
DenseUnivariateRationalPolynomial(int s)
Construct a polynomial with degree.
Definition: urpolynomial.h:99
DenseUnivariateRationalPolynomial operator/(const DenseUnivariateRationalPolynomial &b) const
Overload operator / ExactDivision.
Definition: urpolynomial.h:646
RationalNumber leadingCoefficient() const
Get the leading coefficient.
Definition: urpolynomial.h:158
DenseUnivariateRationalPolynomial monicDivide(const DenseUnivariateRationalPolynomial &b)
Monic division Return quotient and itself become the remainder.
int numberOfSignChanges()
Number of coefficient sign variation.
RationalNumber inverse() const
Get the inverse of *this.
Definition: RationalNumber.hpp:388
DenseUnivariateRationalPolynomial & operator^=(long long int e)
Overload operator ^= replace xor operation by exponentiation.
Definition: urpolynomial.h:405
DenseUnivariateRationalPolynomial gcd(const DenseUnivariateRationalPolynomial &q, int type) const
GCD(p, q)
~DenseUnivariateRationalPolynomial()
Destroy the polynomial.
Definition: urpolynomial.h:140
Symbol variable() const
Get variable's name.
Definition: urpolynomial.h:231
Interval lists for real roots of multivariate polynomials.
Definition: interval.h:35
RationalNumber content() const
Content of the polynomial.
Definition: urpolynomial.h:381
DenseUnivariateRationalPolynomial & operator+=(const DenseUnivariateRationalPolynomial &b)
Overload Operator +=.
Definition: urpolynomial.h:462
DenseUnivariateRationalPolynomial operator+(const DenseUnivariateRationalPolynomial &b) const
Overload operator +.
DenseUnivariateRationalPolynomial operator<<(int k) const
Overload operator << replace by muplitying x^k.
void add(const DenseUnivariateRationalPolynomial &b)
Add another polynomial to itself.
void subtract(const DenseUnivariateRationalPolynomial &b)
Subtract another polynomial from itself.
void reciprocal()
Revert coefficients.