Basic Polynomial Algebra Subprograms (BPAS)  v. 1.652
polynomial.h
1 #ifndef _BPAS_POLYNOMIAL_H_
2 #define _BPAS_POLYNOMIAL_H_
3 
4 /**
5  * Abstract Polynomial Classes
6  **/
7 
8 #include "ring.h"
9 #include "Ring/BPASGCDDomain.hpp"
10 #include "Symbol/Symbol.hpp"
11 #include <vector>
12 #include "Utils/TemplateHelpers.hpp"
13 
14 /**
15  * An abstract class defining the interface of a polynomial over an arbitrary BPASRing.
16  * This calss is
17  * Polynomials themselves form a ring, BPASRing<Derived> as well as the base
18  * ring, Ring, is also a valid ring.
19  **/
20 template <class Ring, class Derived>
21 class BPASBasePolynomial : public virtual BPASRing<Derived>
22  // ,
23  // private Derived_from<Ring, BPASRing<Ring>>
24 {
25  public:
26 
27  /**
28  * In addition to the ring arithmetic for Derived defined by BPASRing
29  * polynomials must do arithmetic with their base ring.
30  **/
31  virtual Derived& operator= (const Ring&) = 0;
32  virtual Derived operator+ (const Ring&) const = 0;
33  virtual Derived& operator+= (const Ring&) = 0;
34  virtual Derived operator- (const Ring&) const = 0;
35  virtual Derived operator- () const = 0;
36  virtual Derived& operator-= (const Ring&) = 0;
37  virtual Derived operator* (const Ring&) const = 0;
38  virtual Derived& operator*= (const Ring&) = 0;
39 
40  virtual Integer degree() const = 0; // total degree
41  virtual Ring leadingCoefficient() const = 0;
42  virtual Ring trailingCoefficient() const = 0;
43  virtual bool isConstantTermZero() const = 0;
44  virtual Integer numberOfTerms() const = 0;
45 };
46 
47 /**
48  * An abstract class defining the interface of a polynomial over an arbitrary BPASIntegralDomain.
49  */
50 template <class Ring, class Derived>
51 class BPASIntegralPolynomial : public virtual BPASBasePolynomial<Ring, Derived>,
52  public virtual BPASIntegralDomain<Derived>,
53  private Derived_from<Ring, BPASIntegralDomain<Ring>> {
54  // virtual std::vector<Derived> squareFree() const = 0; //TODO
55 };
56 
57 /**
58  * An abstract class defining the interface of a polynomial over an arbitrary BPASGCDDomain.
59  */
60 template <class Ring, class Derived>
61 class BPASGCDPolynomial : public virtual BPASIntegralPolynomial<Ring, Derived>,
62  public virtual BPASGCDDomain<Derived>,
63  private Derived_from<Ring, BPASGCDDomain<Ring>> {
64  virtual Ring content() const = 0;
65  virtual Derived primitivePart() const = 0;
66 };
67 
68 /**
69  * Used by BPASPolynomial for compile-time template introspection.
70  */
71 template <class Ring, class Derived>
72 class BPASIntegralPolynomialTester : public std::conditional<std::is_base_of<BPASIntegralDomain<Ring>, Ring>::value, BPASIntegralPolynomial<Ring, Derived>, BPASBasePolynomial<Ring, Derived>>::type {};
73 
74 /**
75  * An abstract class defining the interface of a polynomial over an arbitrary BPASRing.
76  * Users should inherit from this class rather than BPASBasePolynomial, BPASIntegralPolynomial, or BPASGCDPolynomial.
77  * Inherirance of proper classes and exporting of proper functions is done automatically
78  * at compile type through introspection of the template parameter.
79  */
80 template <class Ring, class Derived>
81 class BPASPolynomial : public std::conditional<std::is_base_of<BPASGCDDomain<Ring>, Ring>::value,
82 BPASGCDPolynomial<Ring, Derived>, BPASIntegralPolynomialTester<Ring, Derived> >::type {};
83 
84 /**
85  * An abstract class defining the interface of a univariate polynomial over an arbitrary BPASRing.
86  */
87 template <class Ring, class Derived>
88 class BPASUnivariatePolynomial : public virtual BPASPolynomial<Ring, Derived>
89 
90 {
91  public:
92  virtual void differentiate() = 0; // p = dp/dx
93  virtual void differentiate(int) = 0;
94  virtual Derived derivative() const = 0; // q = dp/dx
95  virtual Derived derivative(int) const = 0;
96  virtual Ring evaluate(const Ring& r) const = 0;
97  virtual Derived monicDivide(const Derived&) = 0;
98  virtual Derived monicDivide(const Derived&, Derived*) const = 0;
99  virtual Derived lazyPseudoDivide(const Derived&, Ring*, Ring*) = 0;
100  virtual Derived lazyPseudoDivide(const Derived&, Derived*, Ring*, Ring*) const = 0;
101  virtual Derived pseudoDivide(const Derived&, Ring*) = 0;
102  virtual Derived pseudoDivide(const Derived&, Derived*, Ring*) const = 0;
103  virtual Ring coefficient(int) const = 0;
104  virtual void setCoefficient(int, const Ring&) = 0;
105  virtual void setVariableName (const Symbol&) = 0;
106  virtual Symbol variable() const = 0;
107  virtual Derived operator<< (int i) const = 0; // q = p * (x^i);
108  virtual Derived& operator<<= (int) = 0; // p = p *(x^i)
109  virtual Derived operator>> (int) const = 0; // q = p / (x^i);
110  virtual Derived& operator>>= (int) = 0;
111 };
112 
113 /**
114  * An abstract class defining the interface of a multivariate polynomial over an arbitrary BPASRing.
115  */
116 template <class Ring, class Derived>
117 class BPASMultivariatePolynomial : public virtual BPASPolynomial<Ring, Derived>
118 {
119  // Monomials are the abelian free monoid generated by Symbols
120  public:
121  // virtual void setPolynomialRing(const std::vector<Symbol>& v) = 0;
122  // virtual std::vector<Symbol> polynomialRing() = 0;
123 
124  virtual void differentiate(const Symbol&) = 0;
125  virtual void differentiate(const Symbol&, int) = 0;
126  virtual Derived derivative(const Symbol&) const = 0;
127  virtual Derived derivative(const Symbol&, int) const = 0;
128 
129  // TODO
130  // virtual void integrate(const Symbol&) = 0;
131  // virtual void integrate(const Symbol&, int) = 0;
132  // virtual Derived integral(const Symbol&) const = 0;
133  // virtual Derived integral(const Symbol&, int) const = 0;
134 
135  virtual Derived evaluate(int, const Symbol*, const Ring*) const = 0;
136  virtual Derived evaluate(const std::vector<Symbol>&, const std::vector<Ring>&) const = 0;
137 
138  virtual int numberOfVariables() const = 0;
139  virtual int numberOfRingVariables() const = 0;
140  virtual Integer degree(const Symbol& v) const = 0;
141  // virtual unsigned int degree(const Symbol& v) const = 0;
142  virtual Ring coefficient(int, const int*) const = 0;
143  virtual Ring coefficient(const std::vector<int>& v) const = 0;
144  virtual void setCoefficient(int, const int*, const Ring& r) = 0;
145  virtual void setCoefficient(const std::vector<int>& v, const Ring& r) = 0;
146 
147  //set variables in the ring.
148  virtual void setRingVariables (const std::vector<Symbol>& xs) = 0;
149  //get all variables in the polynomial ring.
150  virtual std::vector<Symbol> ringVariables() const = 0;
151 
152  //non-zero variables
153  virtual std::vector<Symbol> variables() const = 0;
154 
155  // virtual Derived content(const std::vector<Symbol>& v) const = 0;
156  // virtual Derived primitivePart(const std::vector<Symbol>& v) const = 0;
157  // virtual Derived primitivePart(const std::vector<Symbol>& v, Derived& content) const = 0;
158 };
159 
160 
161 /**
162  * An abstract class defining the interface of a multivariate polynomial that can be viewed recursively.
163  * That is, it can be viewed as a univariate polynomial with multivariate polynomial coefficients.
164  */
165 template <class Ring, class Derived>
167 {
168  public:
169  virtual Derived initial() const = 0;
170  virtual Symbol mainVariable() const = 0;
171  virtual int mainDegree() const = 0;
172  virtual Derived rank() const = 0;
173  virtual Derived tail() const = 0;
174  virtual Derived head() const = 0;
175  virtual Derived separant() const = 0;
176  // virtual SparseUnivariatePolynomial<Derived> convertToSUP() const = 0;
177 
178 };
179 
180 
181 /**
182  * An abstract class defining the interface of a rational function. Domain
183  * should be BPASGCDDomain.
184  */
185 template <class Domain, class Derived>
186 class BPASRationalFunction : public virtual BPASFieldOfFractions<Domain, Derived> {
187 
188 };
189 
190 /**
191  * An abstract class defining the interface of a triangular set.
192  * A BPASTriangularSet is templated by a BPASRecursivelyViewedPolynomial with coefficients
193  * in a BPASField.
194  */
195 template <class Field, class RecursiveFieldPoly>
197  private Derived_from<Field, BPASField<Field>>,
198  private Derived_from<RecursiveFieldPoly, BPASRecursivelyViewedPolynomial<Field,RecursiveFieldPoly>>
199 {
200  public:
201 
204 // virtual void copy(const BPASTriangularSet<Field,RecursiveFieldPoly>&) = 0;
205  virtual int numberOfVariables() const = 0;
206  virtual std::vector<Symbol> variables() const = 0;
207 
208  virtual RecursiveFieldPoly select(const Symbol&) const = 0;
209  virtual void lower(const Symbol&, BPASTriangularSet<Field,RecursiveFieldPoly>&) const = 0;
210  virtual void upper(const Symbol&, BPASTriangularSet<Field,RecursiveFieldPoly>&) const = 0;
211  virtual RecursiveFieldPoly pseudoDivide (const RecursiveFieldPoly&, std::vector<RecursiveFieldPoly>*, RecursiveFieldPoly*) const = 0;
212  virtual RecursiveFieldPoly normalForm (const RecursiveFieldPoly&, std::vector<RecursiveFieldPoly>*) const = 0;
213 };
214 
215 /**
216  * An abstract class defining the interface of a regular chain.
217  * See also BPASTriangularSet.
218  */
219 template <class Field, class RecursiveFieldPoly>
220 class BPASRegularChain : public virtual BPASTriangularSet<Field,RecursiveFieldPoly>
221 {
222  public:
223 
226 // virtual RecursiveFieldPoly normalize (const RecursiveFieldPoly&) = 0;
227 };
228 
229 /**
230  * An abstract class defining the interface of a zero-dimensional regular chain.
231  */
232 template <class Field, class RecursiveFieldPoly>
233 class BPASZeroDimensionalRegularChain : public virtual BPASRegularChain<Field,RecursiveFieldPoly>
234 {
235  public:
236 
239 };
240 
241 #endif
An abstract class defining the interface of a commutative ring.
Definition: BPASRing.hpp:76
An abstract class defining the interface of a field of fractions.
Definition: BPASFieldOfFractions.hpp:16
An abstract class defining the interface of a GCD domain.
Definition: BPASGCDDomain.hpp:14
An abstract class defining the interface of a zero-dimensional regular chain.
Definition: polynomial.h:233
virtual Derived & operator=(const Ring &)=0
In addition to the ring arithmetic for Derived defined by BPASRing polynomials must do arithmetic wit...
An abstract class defining the interface of a rational function.
Definition: polynomial.h:186
friend std::ostream & operator<<(std::ostream &ostream, const Derived &d)
Output operator.
Definition: BPASRing.hpp:201
An abstract class defining the interface of a polynomial over an arbitrary BPASRing.
Definition: polynomial.h:81
virtual Derived operator-() const =0
Negation.
An abstract class defining the interface of a multivariate polynomial over an arbitrary BPASRing...
Definition: polynomial.h:117
Used by BPASPolynomial for compile-time template introspection.
Definition: polynomial.h:72
An arbitrary-precision Integer.
Definition: Integer.hpp:22
Abstract Polynomial Classes.
Definition: polynomial.h:21
An abstract class defining the interface of a univariate polynomial over an arbitrary BPASRing...
Definition: polynomial.h:88
An abstract class defining the interface of a triangular set.
Definition: polynomial.h:196
An encapsulation of a mathematical symbol.
Definition: Symbol.hpp:23
An abstract class defining the interface of a polynomial over an arbitrary BPASGCDDomain.
Definition: polynomial.h:61
An abstract class defining the interface of a regular chain.
Definition: polynomial.h:220
An abstract class defining the interface of a polynomial over an arbitrary BPASIntegralDomain.
Definition: polynomial.h:51
An abstract class defining the interface of an integral domain.
Definition: BPASIntegralDomain.hpp:14
An abstract class defining the interface of a multivariate polynomial that can be viewed recursively...
Definition: polynomial.h:166