Basic Polynomial Algebra Subprograms (BPAS)  v. 1.791
BPASRing.hpp
1 #ifndef _BPAS_RING_H_
2 #define _BPAS_RING_H_
3 
4 #include <gmpxx.h>
5 #include <vector>
6 #include "../ExpressionTree/ExpressionTree.hpp"
7 #include <sstream>
8 
9 
10 
11 /**
12  * An abstract class defining the interface of a commutative ring.
13  *
14  * The template Derived is a concrete class derived from (implemeneting the
15  * interface of) BPASRing. This is the "curiously recurring template pattern" (CTRP).
16  * This pattern is used among all sub-classes of BPASRing.
17  */
18 template <class Derived>
19 class BPASRing : public virtual ExpressionTreeConvert {
20 public:
21 
22 
23  /**
24  * The characteristic of this ring class.
25  */
26  virtual mpz_class getCharacteristic() const {
27  return 0;
28  }
29 
30  /**
31  * Determine if *this ring element is zero, that is the additive identity.
32  *
33  * returns true iff *this is zero.
34  */
35  virtual bool isZero() const = 0;
36 
37  /**
38  * Make *this ring element zero.
39  */
40  virtual void zero() = 0;
41 
42  /**
43  * Determine if *this ring element is one, that is the multiplication identity.
44  *
45  * returns true iff *this is one.
46  */
47  virtual bool isOne() const = 0;
48 
49  /**
50  * Make *this ring element one.
51  */
52  virtual void one() = 0;
53 
54  /**
55  * Obtain the unit normal (a.k.a canonical associate) of an element.
56  * If either parameters u, v, are non-NULL then the units are returned such that
57  * b = ua, v = u^-1. Where b is the unit normal of a, and is the returned value.
58  */
59  virtual Derived unitCanonical(Derived* u = NULL, Derived* v = NULL) const = 0;
60 
61  /**
62  * Copy assignment.
63  */
64  virtual Derived& operator= (const Derived&) = 0;
65 
66  /**
67  * Addition.
68  */
69  virtual Derived operator+ (const Derived&) const = 0;
70 
71  /**
72  * Addition assignment.
73  */
74  virtual Derived& operator+= (const Derived&) =0;
75 
76  /**
77  * Subtraction.
78  */
79  virtual Derived operator- (const Derived&) const = 0;
80 
81  /**
82  * Subtraction assignment.
83  */
84  virtual Derived& operator-= (const Derived&) = 0;
85 
86  /**
87  * Negation.
88  */
89  virtual Derived operator- () const = 0;
90 
91  /**
92  * Multiplication.
93  */
94  virtual Derived operator* (const Derived&) const = 0;
95 
96  /**
97  * Multiplication assignment.
98  */
99  virtual Derived& operator*= (const Derived&) = 0;
100 
101  /**
102  * Exponentiation.
103  */
104  virtual Derived operator^ (long long int e) const = 0;
105 
106  /**
107  * Exponentiation assignment.
108  */
109  virtual Derived& operator^= (long long int e) = 0;
110 
111  /**
112  * Equality test,
113  *
114  * returns true iff equal
115  */
116  virtual bool operator== (const Derived&) const = 0;
117 
118  /**
119  * Inequality test,
120  *
121  * returns true iff not equal.
122  */
123  virtual bool operator!= (const Derived&) const = 0;
124 
125  /**
126  * Print the Ring element.
127  *
128  * Derived classes may override this to get custom printing that may
129  * be more expressive (and prettier) than expression tree printing.
130  */
131  virtual void print(std::ostream& ostream) const {
132  ostream << convertToExpressionTree().toString();
133  }
134 
135  /**
136  * Convert the Ring element to a string.
137  *
138  * Simple delegation of printing to a stringstream to obtain a string.
139  * Overriding the print method is sufficient for sub-classes
140  * to make use of this method.
141  *
142  * returns the string representation of the Ring element.
143  */
144  virtual std::string toString() const {
145  std::stringstream ss;
146  print(ss);
147  return ss.str();
148  }
149 
150  /**
151  * Output operator.
152  *
153  * Defines a to string conversion.
154  */
155  friend std::ostream& operator<< (std::ostream& ostream, const Derived& d) {
156  d.print(ostream);
157  return ostream;
158  }
159 
160  friend std::ostream& operator<< (std::ostream& ostream, Derived&& d) {
161  d.print(ostream);
162  return ostream;
163  }
164 
165  // virtual bool isNegativeOne() = 0;
166  // virtual void negativeOne() = 0;
167  // virtual int isConstant() = 0;
168  // static bool isPrimeField;
169  // static bool isSmallPrimeField;
170  // static bool isComplexField;
171 };
172 
173 #endif
An abstract class defining the interface of a commutative ring.
Definition: BPASRing.hpp:19
virtual bool operator==(const Derived &) const =0
Equality test,.
virtual bool operator!=(const Derived &) const =0
Inequality test,.
virtual Derived & operator-=(const Derived &)=0
Subtraction assignment.
virtual std::string toString() const
Convert the Ring element to a string.
Definition: BPASRing.hpp:144
virtual void zero()=0
Make *this ring element zero.
friend std::ostream & operator<<(std::ostream &ostream, const Derived &d)
Output operator.
Definition: BPASRing.hpp:155
std::string toString() const
Convert *this to a generic string representation.
virtual Derived & operator=(const Derived &)=0
Copy assignment.
virtual Derived operator^(long long int e) const =0
Exponentiation.
virtual ExpressionTree convertToExpressionTree() const =0
Convert this to an expression tree.
virtual void one()=0
Make *this ring element one.
virtual Derived & operator^=(long long int e)=0
Exponentiation assignment.
virtual Derived & operator+=(const Derived &)=0
Addition assignment.
virtual Derived operator*(const Derived &) const =0
Multiplication.
virtual mpz_class getCharacteristic() const
The characteristic of this ring class.
Definition: BPASRing.hpp:26
virtual Derived & operator*=(const Derived &)=0
Multiplication assignment.
virtual Derived unitCanonical(Derived *u=NULL, Derived *v=NULL) const =0
Obtain the unit normal (a.k.a canonical associate) of an element.
virtual Derived operator-() const =0
Negation.
virtual bool isOne() const =0
Determine if *this ring element is one, that is the multiplication identity.
An interface defining conversion of a class to an ExpressionTree.
Definition: ExpressionTree.hpp:195
virtual bool isZero() const =0
Determine if *this ring element is zero, that is the additive identity.
virtual Derived operator+(const Derived &) const =0
Addition.
virtual void print(std::ostream &ostream) const
Print the Ring element.
Definition: BPASRing.hpp:131