1 | /****************************************************************** |
---|
2 | * |
---|
3 | * File: GP.h |
---|
4 | * Purpose: Main Header file for abstract poly classes |
---|
5 | * Author: Olaf Bachmann (obachman@mathematik.uni-kl.de) |
---|
6 | * Created: 11/96 |
---|
7 | * |
---|
8 | ******************************************************************/ |
---|
9 | |
---|
10 | #ifndef _GP_H_ |
---|
11 | #define _GP_H_ |
---|
12 | |
---|
13 | /*************************************************************** |
---|
14 | * |
---|
15 | * some general definitions |
---|
16 | * |
---|
17 | ***************************************************************/ |
---|
18 | |
---|
19 | #ifndef NULL |
---|
20 | #define NULL (0) |
---|
21 | #endif |
---|
22 | |
---|
23 | enum GP_Property_t |
---|
24 | { |
---|
25 | GP_IsUnknownProperty, |
---|
26 | GP_IsTrueProperty, |
---|
27 | GP_IsFalseProperty |
---|
28 | }; |
---|
29 | |
---|
30 | /****************************************************************** |
---|
31 | * |
---|
32 | * Forward declaration of pointers |
---|
33 | * |
---|
34 | ******************************************************************/ |
---|
35 | typedef class GP_t * GP_pt; |
---|
36 | typedef class GP_Atom_t * GP_Atom_pt; |
---|
37 | typedef class GP_Comp_t * GP_Comp_pt; |
---|
38 | typedef class GP_Poly_t * GP_Poly_pt; |
---|
39 | typedef class GP_UvPoly_t * GP_UvPoly_pt; |
---|
40 | typedef class GP_MvPoly_t * GP_MvPoly_pt; |
---|
41 | typedef class GP_DistMvPoly_t * GP_DistMvPoly_pt; |
---|
42 | typedef class GP_RecMvPoly_t * GP_RecMvPoly_pt; |
---|
43 | typedef class GP_Ordering_t * GP_Ordering_pt; |
---|
44 | |
---|
45 | /****************************************************************** |
---|
46 | * |
---|
47 | * Top-level classes: GP, Object, and Iterator |
---|
48 | * |
---|
49 | ******************************************************************/ |
---|
50 | |
---|
51 | enum GP_Type_t |
---|
52 | { |
---|
53 | GP_UnknownType, |
---|
54 | GP_AtomType, |
---|
55 | GP_PolyType, |
---|
56 | GP_CompType |
---|
57 | }; |
---|
58 | |
---|
59 | class GP_t |
---|
60 | { |
---|
61 | public: |
---|
62 | // has to say what kind of specification it is |
---|
63 | virtual GP_Type_t Type() = 0; |
---|
64 | virtual GP_Atom_pt Atom() = 0; |
---|
65 | virtual GP_Comp_pt Comp() = 0; |
---|
66 | virtual GP_Poly_pt Poly() = 0; |
---|
67 | |
---|
68 | // traverses through the spec tree and checks everything for |
---|
69 | // semantic correctness |
---|
70 | bool IsSpecOk(); |
---|
71 | bool IsDataOk(const void* data); |
---|
72 | bool IsOk(const void* data) {return IsSpecOk() && IsDataOk(data);} |
---|
73 | bool Equals(GP_pt other) {return false;} |
---|
74 | }; |
---|
75 | |
---|
76 | typedef class GP_Object_t |
---|
77 | { |
---|
78 | public: |
---|
79 | |
---|
80 | } * GP_Object_pt; |
---|
81 | |
---|
82 | typedef class GP_Iterator_t |
---|
83 | { |
---|
84 | public: |
---|
85 | virtual long N() = 0; |
---|
86 | virtual void* Next() = 0; |
---|
87 | virtual void Reset(const void* data) = 0; |
---|
88 | virtual ~GP_Iterator_t() {} |
---|
89 | |
---|
90 | |
---|
91 | } * GP_Iterator_pt; |
---|
92 | |
---|
93 | |
---|
94 | /****************************************************************** |
---|
95 | * |
---|
96 | * Second-level derived classes: Atom, Composite, Polynomial |
---|
97 | * |
---|
98 | ******************************************************************/ |
---|
99 | ////////////////////////////////////////////////////////// |
---|
100 | // Atoms |
---|
101 | // |
---|
102 | typedef enum |
---|
103 | { |
---|
104 | GP_UnknownAtomType, |
---|
105 | GP_IntegerAtomType, // Integers |
---|
106 | GP_RealAtomType, // Real |
---|
107 | GP_CharPAtomType, // Mod p numbers, where p is a prime number |
---|
108 | GP_ModuloAtomType // and, Mod m numbers, where m is an integer > 0. |
---|
109 | } GP_AtomType_t; |
---|
110 | |
---|
111 | typedef enum |
---|
112 | { |
---|
113 | GP_UnknownAtomEncoding, |
---|
114 | GP_DynamicAtomEncoding, |
---|
115 | GP_UlongAtomEncoding, |
---|
116 | GP_SlongAtomEncoding, |
---|
117 | GP_FloatAtomEncoding, |
---|
118 | GP_DoubleAtomEncoding, |
---|
119 | GP_IncrApIntAtomEncoding, |
---|
120 | GP_DecrApIntAtomEncoding, |
---|
121 | GP_GmpApIntAtomEncoding, |
---|
122 | GP_PariApIntAtomEncoding, |
---|
123 | GP_ApRealAtomEncoding |
---|
124 | } GP_AtomEncoding_t; |
---|
125 | |
---|
126 | class GP_Atom_t : virtual public GP_t |
---|
127 | { |
---|
128 | public: |
---|
129 | GP_Type_t Type() {return GP_AtomType;} |
---|
130 | bool IsAtomSpecOk(); |
---|
131 | bool IsAtomDataOk(const void* data); |
---|
132 | |
---|
133 | // the following need to be implemented by a child of GP_Atom_t |
---|
134 | virtual GP_AtomType_t AtomType() = 0; |
---|
135 | // GP_UnknownAtomEncoding: means can only be determined from the atom itself |
---|
136 | virtual GP_AtomEncoding_t AtomEncoding() = 0; |
---|
137 | // for GP_CharPAtomType and GP_ModuloAtomType |
---|
138 | // this returns the modulus, otherwise, this returns 0 |
---|
139 | // Encoding of return is equivalent to that of AtomEncoding() |
---|
140 | virtual void* GP_AtomModulus() {return NULL;} |
---|
141 | |
---|
142 | // the actual encoding for Atom whose AtomEncoding() is |
---|
143 | // GP_DynamicAtomEncoding |
---|
144 | virtual GP_AtomEncoding_t AtomEncoding(const void* data) |
---|
145 | {return AtomEncoding();} |
---|
146 | |
---|
147 | // getting the value of Atoms |
---|
148 | virtual unsigned long AtomUlong(const void* data) {return 0;} |
---|
149 | virtual signed long AtomSlong(const void* data) {return 0;} |
---|
150 | virtual float AtomFloat(const void* data) {return 0.0;} |
---|
151 | virtual double AtomDouble(const void* data){return 0.0;} |
---|
152 | |
---|
153 | virtual unsigned long AtomApIntLength(const void* data) {return 0;} |
---|
154 | virtual signed long AtomApIntSign(const void* data) {return 0;} |
---|
155 | virtual void AtomApInt(const void* data, unsigned long* apint) {} |
---|
156 | virtual const unsigned long* AtomApInt(const void* data) {return NULL;} |
---|
157 | virtual const void* AtomGmpApInt(const void* data) {return NULL;} |
---|
158 | virtual const void* AtomPariApInt(const void* data) {return NULL;} |
---|
159 | }; |
---|
160 | |
---|
161 | |
---|
162 | |
---|
163 | ////////////////////////////////////////////////////////// |
---|
164 | // Composites |
---|
165 | // |
---|
166 | typedef enum |
---|
167 | { |
---|
168 | GP_UnknownCompType, |
---|
169 | GP_RationalCompType, |
---|
170 | GP_ComplexCompType, |
---|
171 | GP_IdealCompType, |
---|
172 | GP_ModuleCompType, |
---|
173 | GP_QuotientCompType, |
---|
174 | GP_VectorCompType, |
---|
175 | GP_MatrixCompType, |
---|
176 | GP_FreeModuleCompType |
---|
177 | } GP_CompType_t; |
---|
178 | |
---|
179 | class GP_Comp_t : virtual public GP_t |
---|
180 | { |
---|
181 | public: |
---|
182 | GP_Type_t Type() {return GP_CompType;} |
---|
183 | bool IsCompSpecOk(); |
---|
184 | bool IsCompDataOk(const void* data); |
---|
185 | |
---|
186 | virtual GP_CompType_t CompType() = 0; |
---|
187 | // Spec of the elements |
---|
188 | virtual GP_pt Elements() = 0; |
---|
189 | // Iterator over Elmenets |
---|
190 | virtual GP_Iterator_pt ElementDataIterator(const void* data) = 0; |
---|
191 | |
---|
192 | // only relevant for matricies |
---|
193 | virtual void MatrixDimension(long &dx, long &dy) |
---|
194 | {dx = -1; dy = -1;} |
---|
195 | |
---|
196 | // only relevant fro Free modules |
---|
197 | virtual long FreeModuleComponent(void* data) {return -1;} |
---|
198 | virtual void* FreeModuleElement(void* data) {return NULL;} |
---|
199 | }; |
---|
200 | |
---|
201 | |
---|
202 | //////////////////////////////////////////////////////////////////// |
---|
203 | // Last, but not least, polynomials: |
---|
204 | // We distinguish further in |
---|
205 | // |
---|
206 | typedef enum |
---|
207 | { |
---|
208 | GP_UnknownPolyType, |
---|
209 | GP_UvPolyType, // univariate polynomials |
---|
210 | GP_MvPolyType // and, multivariate polynomials |
---|
211 | } GP_PolyType_t; |
---|
212 | |
---|
213 | class GP_Poly_t : virtual public GP_t |
---|
214 | { |
---|
215 | public: |
---|
216 | GP_Type_t Type() {return GP_PolyType;} |
---|
217 | bool IsPolySpecOk(); |
---|
218 | bool IsPolyDataOk(const void* data); |
---|
219 | |
---|
220 | virtual GP_PolyType_t PolyType() = 0; |
---|
221 | virtual GP_UvPoly_pt UvPoly() = 0; |
---|
222 | virtual GP_MvPoly_pt MvPoly() = 0; |
---|
223 | |
---|
224 | virtual GP_pt Coeffs() = 0; |
---|
225 | |
---|
226 | virtual void* MinPoly() {return NULL;} |
---|
227 | virtual GP_Property_t IsIrreducible() {return GP_IsUnknownProperty;} |
---|
228 | // a specification whether the first variable of the poly is to be |
---|
229 | // interpreted as index of a free vector generator -- i.e. whether |
---|
230 | // poly is actually a vector over a free module |
---|
231 | virtual bool IsFreeModuleVector() {return false;} |
---|
232 | }; |
---|
233 | |
---|
234 | |
---|
235 | //////////////////////////////////////// |
---|
236 | // Univariate Polys |
---|
237 | // |
---|
238 | enum GP_UvPolyType_t |
---|
239 | { |
---|
240 | GP_UnknownUvPolyType, |
---|
241 | GP_DenseUvPolyType, // dense univariate polys |
---|
242 | GP_SparseUvPolyType, // sparse univariate polys |
---|
243 | }; |
---|
244 | |
---|
245 | class GP_UvPoly_t : virtual public GP_Poly_t |
---|
246 | { |
---|
247 | public: |
---|
248 | GP_PolyType_t PolyType() {return GP_UvPolyType;} |
---|
249 | bool IsUvPolySpecOk(); |
---|
250 | bool IsUvPolyDataOk(const void* data); |
---|
251 | |
---|
252 | virtual GP_UvPolyType_t UvPolyType() = 0; |
---|
253 | |
---|
254 | // NULL means varname is "unknown" |
---|
255 | virtual char* VarName() {return NULL;} |
---|
256 | |
---|
257 | // For DenseUvPoly, a term is simple a coeff |
---|
258 | // For SparseUvPoly, a term is a tuple of (coeff, exponent) |
---|
259 | virtual GP_Iterator_pt TermIterator(const void* data) = 0; |
---|
260 | |
---|
261 | // The next two functions are only relevant for Sparse Univariate polys |
---|
262 | virtual void* ExpCoeff(const void* term) {return NULL;} |
---|
263 | virtual long ExpValue(const void* term) {return -1;} |
---|
264 | }; |
---|
265 | |
---|
266 | |
---|
267 | //////////////////////////////////////// |
---|
268 | // Multivariate Polys |
---|
269 | // |
---|
270 | typedef enum |
---|
271 | { |
---|
272 | GP_UnknownMvPolyType, |
---|
273 | GP_DistMvPolyType, |
---|
274 | GP_RecMvPolyType |
---|
275 | } GP_MvPolyType_t; |
---|
276 | |
---|
277 | class GP_MvPoly_t : virtual public GP_Poly_t |
---|
278 | { |
---|
279 | public: |
---|
280 | GP_PolyType_t PolyType() {return GP_MvPolyType;} |
---|
281 | bool IsMvPolySpecOk(); |
---|
282 | bool IsMvPolyDataOk(const void* data); |
---|
283 | |
---|
284 | virtual GP_MvPolyType_t MvPolyType() = 0; |
---|
285 | virtual GP_DistMvPoly_pt DistMvPoly() = 0; |
---|
286 | virtual GP_RecMvPoly_pt RecMvPoly() = 0; |
---|
287 | |
---|
288 | // the number of variables of the poly |
---|
289 | virtual long NumberOfVars() = 0; |
---|
290 | // iterator for variable names |
---|
291 | virtual GP_Iterator_pt VarNamesIterator() {return NULL;} |
---|
292 | }; |
---|
293 | |
---|
294 | //////////////////////////////////////// |
---|
295 | // Distributed Multivariate Polys |
---|
296 | // |
---|
297 | typedef enum |
---|
298 | { |
---|
299 | GP_UnknownDistMvPolyType, |
---|
300 | GP_DenseDistMvPolyType, |
---|
301 | GP_SparseDistMvPolyType, |
---|
302 | } GP_DistMvPolyType_t; |
---|
303 | |
---|
304 | |
---|
305 | class GP_DistMvPoly_t : virtual public GP_MvPoly_t |
---|
306 | { |
---|
307 | public: |
---|
308 | GP_MvPolyType_t MvPolyType() {return GP_DistMvPolyType;} |
---|
309 | bool IsDistMvPolySpecOk(); |
---|
310 | bool IsDistMvPolyDataOk(const void* data); |
---|
311 | |
---|
312 | virtual GP_DistMvPolyType_t DistMvPolyType() = 0; |
---|
313 | |
---|
314 | virtual GP_Ordering_pt HasOrdering() {return NULL;} |
---|
315 | virtual GP_Ordering_pt ShouldHaveOrdering() {return NULL;} |
---|
316 | |
---|
317 | virtual GP_Iterator_pt MonomIterator(const void* data) = 0; |
---|
318 | |
---|
319 | // extracting Coeff from a monom |
---|
320 | virtual void* Coeff(const void* monom) = 0; |
---|
321 | |
---|
322 | // for DenseDistPoly, we simply let the Exp Vector be filled |
---|
323 | virtual void ExpVector(const void* monom, long* &expvector) {} |
---|
324 | |
---|
325 | // for SparseDistPolys, we need another iterator |
---|
326 | virtual GP_Iterator_pt ExpVectorIterator(const void* monom) {return NULL;} |
---|
327 | // from which we can extract the (number, value) tuple |
---|
328 | virtual long ExpValue(void* exp) {return -1;} |
---|
329 | virtual long ExpNumber(void* exp) {return -1;} |
---|
330 | }; |
---|
331 | |
---|
332 | |
---|
333 | class GP_RecMvPoly_t : virtual public GP_MvPoly_t |
---|
334 | { |
---|
335 | public: |
---|
336 | GP_MvPolyType_t MvPolyType() {return GP_RecMvPolyType;} |
---|
337 | bool IsRecMvPolySpecOk(); |
---|
338 | bool IsRecMvPolyDataOk(const void* data); |
---|
339 | |
---|
340 | // A RecMvPoly is either |
---|
341 | // NULL -- i.e. the zero polynom, or |
---|
342 | // a Coefficient |
---|
343 | virtual bool IsNull(const void* data) {return data == NULL;} |
---|
344 | virtual bool IsCoeff(const void* data) = 0; |
---|
345 | virtual void* Coeff(const void* data) = 0; |
---|
346 | // or a term of the form v^e*MutlSubPoly() + AddSubPoly() |
---|
347 | // index of variable v ( in range 0 to VarNumber()-1) |
---|
348 | virtual long Variable(const void* data) = 0; |
---|
349 | // exponent e of v |
---|
350 | virtual long Exponent(const void* data) = 0; |
---|
351 | // multiplicative subpoly of v |
---|
352 | virtual void* MultSubPoly(const void* data) = 0; |
---|
353 | // additive submonom of v |
---|
354 | virtual void* AddSubPoly(const void* data) = 0; |
---|
355 | }; |
---|
356 | |
---|
357 | |
---|
358 | /****************************************************************** |
---|
359 | * |
---|
360 | * Let's come to monomial orderings |
---|
361 | * |
---|
362 | ******************************************************************/ |
---|
363 | |
---|
364 | typedef enum |
---|
365 | { |
---|
366 | GP_UnknownOrdering, |
---|
367 | |
---|
368 | // either simple orderings like global orderings (which are complete) |
---|
369 | GP_LexOrdering, |
---|
370 | GP_RevLexOrdering, |
---|
371 | GP_DegLexOrdering, |
---|
372 | GP_DegRevLexOrdering, |
---|
373 | |
---|
374 | // local orderings (are complete) |
---|
375 | GP_NegLexOrdering, |
---|
376 | GP_NegRevLexOrdering, |
---|
377 | GP_NegDegLexOrdering, |
---|
378 | GP_NegDegRevLexOrdering, |
---|
379 | |
---|
380 | // matrix ordering (is complete) |
---|
381 | GP_MatrixOrdering, |
---|
382 | |
---|
383 | // module orderings (are incomplete) |
---|
384 | GP_IncrCompOrdering, |
---|
385 | GP_DecrCompOrdering, |
---|
386 | |
---|
387 | // and, product orderings, which are "compositions" of blocks of |
---|
388 | // simple orderings |
---|
389 | GP_ProductOrdering |
---|
390 | } GP_OrderingType_t; |
---|
391 | |
---|
392 | class GP_Ordering_t |
---|
393 | { |
---|
394 | public: |
---|
395 | bool IsOk(const long nvars); |
---|
396 | |
---|
397 | // type |
---|
398 | virtual GP_OrderingType_t OrderingType() = 0; |
---|
399 | GP_OrderingType_t OrderingType(const void* block) |
---|
400 | {return GP_UnknownOrdering;} |
---|
401 | |
---|
402 | // weights (and number of weights), for weighted orderings |
---|
403 | virtual GP_Iterator_pt WeightsIterator() {return NULL;} |
---|
404 | virtual GP_Iterator_pt WeightsIterator(const void* block) {return NULL;} |
---|
405 | |
---|
406 | // blocks of orderings and number of blocks for product orderings |
---|
407 | virtual GP_Iterator_pt BlockOrderingIterator() {return NULL;} |
---|
408 | |
---|
409 | virtual long BlockLength(const void* block) |
---|
410 | {return -1;} |
---|
411 | |
---|
412 | private: |
---|
413 | bool IsBlockOrderingOk(const void* block_ordering); |
---|
414 | }; |
---|
415 | |
---|
416 | #endif // _GP_H_ |
---|
417 | |
---|