Basic Polynomial Algebra Subprograms (BPAS)  v. 1.652
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 
8 /**
9  * An enumeration which describes the properties that a particular ring has.
10  * This operates as a bit-wise mask such that, given an unsigned int representing
11  * a particular ring's properties, one can do :
12  * if (ringProp & (PRIME_FIELD | FINITE_FILE))
13  * to test if a Ring is a (in this instance) a prime field or a finite field.
14  */
15 typedef enum RingProperty {
16  COMMUTATIVE_RING = 0x001,
17  INTEGRAL_DOMAIN = 0x003,
18  GCD_DOMAIN = 0x007,
19  UNIQUE_FACTORIZATION_DOMAIN = 0x00f,
20  PRINICPAL_IDEAL_DOMAIN = 0x01f,
21  EUCLIDEAN_DOMAIN = 0x03f,
22  FIELD = 0x07f,
23  PRIME_FIELD = 0x0ff,
24  FINITE_FIELD = 0x1ff,
25  SMALL_PRIME_FIELD = 0x3ff,
26  COMPLEX_FIELD = 0x47f
27 } RingProperty;
28 
29 /**
30  * Class enapsulates a set of RingProperty(s) that the Ring may have.
31  */
32 class RingProperties {
33 private:
34  unsigned int prop;
35  // int n;
36 
37 public:
38 
39  /**
40  * Default constructor which specifies no properties.
41  */
42  RingProperties();
43 
44  /**
45  * Construct a RingProperties from a RingProperty enum element.
46  */
47  RingProperties(RingProperty p);
48 
49  /**
50  * Construct a RingProperties from a collection of RingProperty elements.
51  */
52  RingProperties(std::vector<RingProperty> v);
53 
54  /**
55  * Determine if *this RingProperties has a RingProperty.
56  */
57  inline bool has(RingProperty p);
58 
59  /**
60  * Determine if *this RingProperties has all properties defined
61  * by the other RingProperties p.
62  */
63  inline bool has(const RingProperties& p);
64 };
65 
66 
67 
68 /**
69  * An abstract class defining the interface of a commutative ring.
70  *
71  * The template Derived is a concrete class derived from (implemeneting the
72  * interface of) BPASRing. This is the "curiously recurring template pattern" (CTRP).
73  * This pattern is used among all sub-classes of BPASRing.
74  */
75 template <class Derived>
76 class BPASRing : public virtual ExpressionTreeConvert {
77 public:
78 
79  /**
80  * Static element describing the properties of this ring class.
81  */
82  static RingProperties properties;
83 
84  /**
85  * The characteristic of this ring class.
86  */
87  virtual mpz_class characteristic() {
88  return 0;
89  }
90 
91  /**
92  * Determine if *this ring element is zero, that is the additive identity.
93  *
94  * returns true iff *this is zero.
95  */
96  virtual bool isZero() const = 0;
97 
98  /**
99  * Make *this ring element zero.
100  */
101  virtual void zero() = 0;
102 
103  /**
104  * Determine if *this ring element is one, that is the multiplication identity.
105  *
106  * returns true iff *this is one.
107  */
108  virtual bool isOne() const = 0;
109 
110  /**
111  * Make *this ring element one.
112  */
113  virtual void one() = 0;
114 
115  /**
116  * Obtain the unit normal (a.k.a canonical associate) of an element.
117  * If either parameters u, v, are non-NULL then the units are returned such that
118  * b = ua, v = u^-1. Where b is the unit normal of a, and is the returned value.
119  */
120  virtual Derived unitCanonical(Derived* u = NULL, Derived* v = NULL) const = 0;
121 
122  /**
123  * Copy assignment.
124  */
125  virtual Derived& operator= (const Derived&) = 0;
126 
127  /**
128  * Addition.
129  */
130  virtual Derived operator+ (const Derived&) const = 0;
131 
132  /**
133  * Addition assignment.
134  */
135  virtual Derived& operator+= (const Derived&) =0;
136 
137  /**
138  * Subtraction.
139  */
140  virtual Derived operator- (const Derived&) const = 0;
141 
142  /**
143  * Subtraction assignment.
144  */
145  virtual Derived& operator-= (const Derived&) = 0;
146 
147  /**
148  * Negation.
149  */
150  virtual Derived operator- () const = 0;
151 
152  /**
153  * Multiplication.
154  */
155  virtual Derived operator* (const Derived&) const = 0;
156 
157  /**
158  * Multiplication assignment.
159  */
160  virtual Derived& operator*= (const Derived&) = 0;
161 
162  /**
163  * Exponentiation.
164  */
165  virtual Derived operator^ (long long int e) const = 0;
166 
167  /**
168  * Exponentiation assignment.
169  */
170  virtual Derived& operator^= (long long int e) = 0;
171 
172  /**
173  * Equality test,
174  *
175  * returns true iff equal
176  */
177  virtual bool operator== (const Derived&) const = 0;
178 
179  /**
180  * Inequality test,
181  *
182  * returns true iff not equal.
183  */
184  virtual bool operator!= (const Derived&) const = 0;
185 
186  /**
187  * Print the Ring element.
188  *
189  * Derived classes may override this to get custom printing that may
190  * be more expressive (and prettier) than expression tree printing.
191  */
192  virtual void print(std::ostream& ostream) const {
193  ostream << convertToExpressionTree().toString();
194  }
195 
196  /**
197  * Output operator.
198  *
199  * Defines a to string conversion.
200  */
201  friend std::ostream& operator<< (std::ostream& ostream, const Derived& d) {
202  d.print(ostream);
203  return ostream;
204  }
205 
206  friend std::ostream& operator<< (std::ostream& ostream, Derived&& d) {
207  d.print(ostream);
208  return ostream;
209  }
210 
211  // virtual bool isNegativeOne() = 0;
212  // virtual void negativeOne() = 0;
213  // virtual int isConstant() = 0;
214  // static bool isPrimeField;
215  // static bool isSmallPrimeField;
216  // static bool isComplexField;
217 };
218 
219 #endif
An abstract class defining the interface of a commutative ring.
Definition: BPASRing.hpp:76
static RingProperties properties
Static element describing the properties of this ring class.
Definition: BPASRing.hpp:82
virtual mpz_class characteristic()
The characteristic of this ring class.
Definition: BPASRing.hpp:87
An interface defining conversion of a class to an ExpressionTree.
Definition: ExpressionTree.hpp:195
virtual void print(std::ostream &ostream) const
Print the Ring element.
Definition: BPASRing.hpp:192