]> www.ginac.de Git - cln.git/blob - include/cl_univpoly.h
- Added lots of @cindex to produce an index.
[cln.git] / include / cl_univpoly.h
1 // Univariate Polynomials.
2
3 #ifndef _CL_UNIVPOLY_H
4 #define _CL_UNIVPOLY_H
5
6 #include "cl_object.h"
7 #include "cl_ring.h"
8 #include "cl_malloc.h"
9 #include "cl_proplist.h"
10 #include "cl_symbol.h"
11 #include "cl_V.h"
12 #include "cl_io.h"
13
14 // To protect against mixing elements of different polynomial rings, every
15 // polynomial carries its ring in itself.
16
17 class cl_heap_univpoly_ring;
18
19 class cl_univpoly_ring : public cl_ring {
20 public:
21         // Default constructor.
22         cl_univpoly_ring ();
23         // Constructor. Takes a cl_heap_univpoly_ring*, increments its refcount.
24         cl_univpoly_ring (cl_heap_univpoly_ring* r);
25         // Private constructor. Doesn't increment the refcount.
26         cl_univpoly_ring (cl_private_thing);
27         // Copy constructor.
28         cl_univpoly_ring (const cl_univpoly_ring&);
29         // Assignment operator.
30         cl_univpoly_ring& operator= (const cl_univpoly_ring&);
31         // Automatic dereferencing.
32         cl_heap_univpoly_ring* operator-> () const
33         { return (cl_heap_univpoly_ring*)heappointer; }
34 };
35 // Copy constructor and assignment operator.
36 CL_DEFINE_COPY_CONSTRUCTOR2(cl_univpoly_ring,cl_ring)
37 CL_DEFINE_ASSIGNMENT_OPERATOR(cl_univpoly_ring,cl_univpoly_ring)
38
39 // Normal constructor for `cl_univpoly_ring'.
40 inline cl_univpoly_ring::cl_univpoly_ring (cl_heap_univpoly_ring* r)
41         : cl_ring ((cl_private_thing) (cl_inc_pointer_refcount((cl_heap*)r), r)) {}
42 // Private constructor for `cl_univpoly_ring'.
43 inline cl_univpoly_ring::cl_univpoly_ring (cl_private_thing p)
44         : cl_ring (p) {}
45
46 // Operations on univariate polynomial rings.
47
48 inline bool operator== (const cl_univpoly_ring& R1, const cl_univpoly_ring& R2)
49 { return (R1.pointer == R2.pointer); }
50 inline bool operator!= (const cl_univpoly_ring& R1, const cl_univpoly_ring& R2)
51 { return (R1.pointer != R2.pointer); }
52 inline bool operator== (const cl_univpoly_ring& R1, cl_heap_univpoly_ring* R2)
53 { return (R1.pointer == R2); }
54 inline bool operator!= (const cl_univpoly_ring& R1, cl_heap_univpoly_ring* R2)
55 { return (R1.pointer != R2); }
56
57 // Representation of a univariate polynomial.
58
59 class _cl_UP /* cf. _cl_ring_element */ {
60 public:
61         cl_gcpointer rep; // vector of coefficients, a cl_V_any
62         // Default constructor.
63         _cl_UP ();
64 public: /* ugh */
65         // Constructor.
66         _cl_UP (const cl_heap_univpoly_ring* R, const cl_V_any& r) : rep (as_cl_private_thing(r)) { (void)R; }
67         _cl_UP (const cl_univpoly_ring& R, const cl_V_any& r) : rep (as_cl_private_thing(r)) { (void)R; }
68 public:
69         // Conversion.
70         CL_DEFINE_CONVERTER(_cl_ring_element)
71 public: // Ability to place an object at a given address.
72         void* operator new (size_t size) { return cl_malloc_hook(size); }
73         void* operator new (size_t size, _cl_UP* ptr) { (void)size; return ptr; }
74         void operator delete (void* ptr) { cl_free_hook(ptr); }
75 };
76
77 class cl_UP /* cf. cl_ring_element */ : public _cl_UP {
78 protected:
79         cl_univpoly_ring _ring; // polynomial ring (references the base ring)
80 public:
81         const cl_univpoly_ring& ring () const { return _ring; }
82 private:
83         // Default constructor.
84         cl_UP ();
85 public: /* ugh */
86         // Constructor.
87         cl_UP (const cl_univpoly_ring& R, const cl_V_any& r)
88                 : _cl_UP (R,r), _ring (R) {}
89         cl_UP (const cl_univpoly_ring& R, const _cl_UP& r)
90                 : _cl_UP (r), _ring (R) {}
91 public:
92         // Conversion.
93         CL_DEFINE_CONVERTER(cl_ring_element)
94         // Destructive modification.
95         void set_coeff (uintL index, const cl_ring_element& y);
96         void finalize();
97         // Evaluation.
98         const cl_ring_element operator() (const cl_ring_element& y) const;
99         // Debugging output.
100         void debug_print () const;
101 public: // Ability to place an object at a given address.
102         void* operator new (size_t size) { return cl_malloc_hook(size); }
103         void* operator new (size_t size, cl_UP* ptr) { (void)size; return ptr; }
104         void operator delete (void* ptr) { cl_free_hook(ptr); }
105 };
106
107
108 // Ring operations.
109
110 struct _cl_univpoly_setops /* cf. _cl_ring_setops */ {
111         // print
112         void (* fprint) (cl_heap_univpoly_ring* R, cl_ostream stream, const _cl_UP& x);
113         // equality
114         // (Be careful: This is not well-defined for polynomials with
115         // floating-point coefficients.)
116         cl_boolean (* equal) (cl_heap_univpoly_ring* R, const _cl_UP& x, const _cl_UP& y);
117 };
118 struct _cl_univpoly_addops /* cf. _cl_ring_addops */ {
119         // 0
120         const _cl_UP (* zero) (cl_heap_univpoly_ring* R);
121         cl_boolean (* zerop) (cl_heap_univpoly_ring* R, const _cl_UP& x);
122         // x+y
123         const _cl_UP (* plus) (cl_heap_univpoly_ring* R, const _cl_UP& x, const _cl_UP& y);
124         // x-y
125         const _cl_UP (* minus) (cl_heap_univpoly_ring* R, const _cl_UP& x, const _cl_UP& y);
126         // -x
127         const _cl_UP (* uminus) (cl_heap_univpoly_ring* R, const _cl_UP& x);
128 };
129 struct _cl_univpoly_mulops /* cf. _cl_ring_mulops */ {
130         // 1
131         const _cl_UP (* one) (cl_heap_univpoly_ring* R);
132         // canonical homomorphism
133         const _cl_UP (* canonhom) (cl_heap_univpoly_ring* R, const cl_I& x);
134         // x*y
135         const _cl_UP (* mul) (cl_heap_univpoly_ring* R, const _cl_UP& x, const _cl_UP& y);
136         // x^2
137         const _cl_UP (* square) (cl_heap_univpoly_ring* R, const _cl_UP& x);
138         // x^y, y Integer >0
139         const _cl_UP (* expt_pos) (cl_heap_univpoly_ring* R, const _cl_UP& x, const cl_I& y);
140 };
141 struct _cl_univpoly_modulops {
142         // scalar multiplication x*y
143         const _cl_UP (* scalmul) (cl_heap_univpoly_ring* R, const cl_ring_element& x, const _cl_UP& y);
144 };
145 struct _cl_univpoly_polyops {
146         // degree
147         sintL (* degree) (cl_heap_univpoly_ring* R, const _cl_UP& x);
148         // monomial
149         const _cl_UP (* monomial) (cl_heap_univpoly_ring* R, const cl_ring_element& x, uintL e);
150         // coefficient (0 if index>degree)
151         const cl_ring_element (* coeff) (cl_heap_univpoly_ring* R, const _cl_UP& x, uintL index);
152         // create new polynomial, bounded degree
153         const _cl_UP (* create) (cl_heap_univpoly_ring* R, sintL deg);
154         // set coefficient in new polynomial
155         void (* set_coeff) (cl_heap_univpoly_ring* R, _cl_UP& x, uintL index, const cl_ring_element& y);
156         // finalize polynomial
157         void (* finalize) (cl_heap_univpoly_ring* R, _cl_UP& x);
158         // evaluate, substitute an element of R
159         const cl_ring_element (* eval) (cl_heap_univpoly_ring* R, const _cl_UP& x, const cl_ring_element& y);
160 };
161 #if defined(__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ < 8) // workaround two g++-2.7.0 bugs
162   #define cl_univpoly_setops  _cl_univpoly_setops
163   #define cl_univpoly_addops  _cl_univpoly_addops
164   #define cl_univpoly_mulops  _cl_univpoly_mulops
165   #define cl_univpoly_modulops  _cl_univpoly_modulops
166   #define cl_univpoly_polyops  _cl_univpoly_polyops
167 #else
168   typedef const _cl_univpoly_setops  cl_univpoly_setops;
169   typedef const _cl_univpoly_addops  cl_univpoly_addops;
170   typedef const _cl_univpoly_mulops  cl_univpoly_mulops;
171   typedef const _cl_univpoly_modulops  cl_univpoly_modulops;
172   typedef const _cl_univpoly_polyops  cl_univpoly_polyops;
173 #endif
174
175 // Representation of a univariate polynomial ring.
176
177 class cl_heap_univpoly_ring /* cf. cl_heap_ring */ : public cl_heap {
178         SUBCLASS_cl_heap_ring()
179 private:
180         cl_property_list properties;
181 protected:
182         cl_univpoly_setops* setops;
183         cl_univpoly_addops* addops;
184         cl_univpoly_mulops* mulops;
185         cl_univpoly_modulops* modulops;
186         cl_univpoly_polyops* polyops;
187 protected:
188         cl_ring _basering;      // the coefficients are elements of this ring
189 public:
190         const cl_ring& basering () const { return _basering; }
191 public:
192         // Low-level operations.
193         void _fprint (cl_ostream stream, const _cl_UP& x)
194                 { setops->fprint(this,stream,x); }
195         cl_boolean _equal (const _cl_UP& x, const _cl_UP& y)
196                 { return setops->equal(this,x,y); }
197         const _cl_UP _zero ()
198                 { return addops->zero(this); }
199         cl_boolean _zerop (const _cl_UP& x)
200                 { return addops->zerop(this,x); }
201         const _cl_UP _plus (const _cl_UP& x, const _cl_UP& y)
202                 { return addops->plus(this,x,y); }
203         const _cl_UP _minus (const _cl_UP& x, const _cl_UP& y)
204                 { return addops->minus(this,x,y); }
205         const _cl_UP _uminus (const _cl_UP& x)
206                 { return addops->uminus(this,x); }
207         const _cl_UP _one ()
208                 { return mulops->one(this); }
209         const _cl_UP _canonhom (const cl_I& x)
210                 { return mulops->canonhom(this,x); }
211         const _cl_UP _mul (const _cl_UP& x, const _cl_UP& y)
212                 { return mulops->mul(this,x,y); }
213         const _cl_UP _square (const _cl_UP& x)
214                 { return mulops->square(this,x); }
215         const _cl_UP _expt_pos (const _cl_UP& x, const cl_I& y)
216                 { return mulops->expt_pos(this,x,y); }
217         const _cl_UP _scalmul (const cl_ring_element& x, const _cl_UP& y)
218                 { return modulops->scalmul(this,x,y); }
219         sintL _degree (const _cl_UP& x)
220                 { return polyops->degree(this,x); }
221         const _cl_UP _monomial (const cl_ring_element& x, uintL e)
222                 { return polyops->monomial(this,x,e); }
223         const cl_ring_element _coeff (const _cl_UP& x, uintL index)
224                 { return polyops->coeff(this,x,index); }
225         const _cl_UP _create (sintL deg)
226                 { return polyops->create(this,deg); }
227         void _set_coeff (_cl_UP& x, uintL index, const cl_ring_element& y)
228                 { polyops->set_coeff(this,x,index,y); }
229         void _finalize (_cl_UP& x)
230                 { polyops->finalize(this,x); }
231         const cl_ring_element _eval (const _cl_UP& x, const cl_ring_element& y)
232                 { return polyops->eval(this,x,y); }
233         // High-level operations.
234         void fprint (cl_ostream stream, const cl_UP& x)
235         {
236                 if (!(x.ring() == this)) cl_abort();
237                 _fprint(stream,x);
238         }
239         cl_boolean equal (const cl_UP& x, const cl_UP& y)
240         {
241                 if (!(x.ring() == this)) cl_abort();
242                 if (!(y.ring() == this)) cl_abort();
243                 return _equal(x,y);
244         }
245         const cl_UP zero ()
246         {
247                 return cl_UP(this,_zero());
248         }
249         cl_boolean zerop (const cl_UP& x)
250         {
251                 if (!(x.ring() == this)) cl_abort();
252                 return _zerop(x);
253         }
254         const cl_UP plus (const cl_UP& x, const cl_UP& y)
255         {
256                 if (!(x.ring() == this)) cl_abort();
257                 if (!(y.ring() == this)) cl_abort();
258                 return cl_UP(this,_plus(x,y));
259         }
260         const cl_UP minus (const cl_UP& x, const cl_UP& y)
261         {
262                 if (!(x.ring() == this)) cl_abort();
263                 if (!(y.ring() == this)) cl_abort();
264                 return cl_UP(this,_minus(x,y));
265         }
266         const cl_UP uminus (const cl_UP& x)
267         {
268                 if (!(x.ring() == this)) cl_abort();
269                 return cl_UP(this,_uminus(x));
270         }
271         const cl_UP one ()
272         {
273                 return cl_UP(this,_one());
274         }
275         const cl_UP canonhom (const cl_I& x)
276         {
277                 return cl_UP(this,_canonhom(x));
278         }
279         const cl_UP mul (const cl_UP& x, const cl_UP& y)
280         {
281                 if (!(x.ring() == this)) cl_abort();
282                 if (!(y.ring() == this)) cl_abort();
283                 return cl_UP(this,_mul(x,y));
284         }
285         const cl_UP square (const cl_UP& x)
286         {
287                 if (!(x.ring() == this)) cl_abort();
288                 return cl_UP(this,_square(x));
289         }
290         const cl_UP expt_pos (const cl_UP& x, const cl_I& y)
291         {
292                 if (!(x.ring() == this)) cl_abort();
293                 return cl_UP(this,_expt_pos(x,y));
294         }
295         const cl_UP scalmul (const cl_ring_element& x, const cl_UP& y)
296         {
297                 if (!(y.ring() == this)) cl_abort();
298                 return cl_UP(this,_scalmul(x,y));
299         }
300         sintL degree (const cl_UP& x)
301         {
302                 if (!(x.ring() == this)) cl_abort();
303                 return _degree(x);
304         }
305         const cl_UP monomial (const cl_ring_element& x, uintL e)
306         {
307                 return cl_UP(this,_monomial(x,e));
308         }
309         const cl_ring_element coeff (const cl_UP& x, uintL index)
310         {
311                 if (!(x.ring() == this)) cl_abort();
312                 return _coeff(x,index);
313         }
314         const cl_UP create (sintL deg)
315         {
316                 return cl_UP(this,_create(deg));
317         }
318         void set_coeff (cl_UP& x, uintL index, const cl_ring_element& y)
319         {
320                 if (!(x.ring() == this)) cl_abort();
321                 _set_coeff(x,index,y);
322         }
323         void finalize (cl_UP& x)
324         {
325                 if (!(x.ring() == this)) cl_abort();
326                 _finalize(x);
327         }
328         const cl_ring_element eval (const cl_UP& x, const cl_ring_element& y)
329         {
330                 if (!(x.ring() == this)) cl_abort();
331                 return _eval(x,y);
332         }
333         // Property operations.
334         cl_property* get_property (const cl_symbol& key)
335                 { return properties.get_property(key); }
336         void add_property (cl_property* new_property)
337                 { properties.add_property(new_property); }
338 // Constructor.
339         cl_heap_univpoly_ring (const cl_ring& r, cl_univpoly_setops*, cl_univpoly_addops*, cl_univpoly_mulops*, cl_univpoly_modulops*, cl_univpoly_polyops*);
340 // This class is intented to be subclassable, hence needs a virtual destructor.
341         virtual ~cl_heap_univpoly_ring () {}
342 private:
343         virtual void dummy ();
344 };
345 #define SUBCLASS_cl_heap_univpoly_ring() \
346   SUBCLASS_cl_heap_ring()
347
348
349 // Lookup or create the "standard" univariate polynomial ring over a ring r.
350 extern const cl_univpoly_ring cl_find_univpoly_ring (const cl_ring& r);
351 //CL_REQUIRE(cl_UP_unnamed)
352
353 // Lookup or create a univariate polynomial ring with a named variable over r.
354 extern const cl_univpoly_ring cl_find_univpoly_ring (const cl_ring& r, const cl_symbol& varname);
355 //CL_REQUIRE(cl_UP_named)
356
357 CL_REQUIRE(cl_UP)
358
359 // Runtime typing support.
360 extern cl_class cl_class_univpoly_ring;
361
362
363 // Operations on polynomials.
364
365 // Output.
366 inline void fprint (cl_ostream stream, const cl_UP& x)
367         { x.ring()->fprint(stream,x); }
368 CL_DEFINE_PRINT_OPERATOR(cl_UP)
369
370 // Add.
371 inline const cl_UP operator+ (const cl_UP& x, const cl_UP& y)
372         { return x.ring()->plus(x,y); }
373
374 // Negate.
375 inline const cl_UP operator- (const cl_UP& x)
376         { return x.ring()->uminus(x); }
377
378 // Subtract.
379 inline const cl_UP operator- (const cl_UP& x, const cl_UP& y)
380         { return x.ring()->minus(x,y); }
381
382 // Equality.
383 inline bool operator== (const cl_UP& x, const cl_UP& y)
384         { return x.ring()->equal(x,y); }
385 inline bool operator!= (const cl_UP& x, const cl_UP& y)
386         { return !x.ring()->equal(x,y); }
387
388 // Compare against 0.
389 inline cl_boolean zerop (const cl_UP& x)
390         { return x.ring()->zerop(x); }
391
392 // Multiply.
393 inline const cl_UP operator* (const cl_UP& x, const cl_UP& y)
394         { return x.ring()->mul(x,y); }
395
396 // Squaring.
397 inline const cl_UP square (const cl_UP& x)
398         { return x.ring()->square(x); }
399
400 // Exponentiation x^y, where y > 0.
401 inline const cl_UP expt_pos (const cl_UP& x, const cl_I& y)
402         { return x.ring()->expt_pos(x,y); }
403
404 // Scalar multiplication.
405 #if 0 // less efficient
406 inline const cl_UP operator* (const cl_I& x, const cl_UP& y)
407         { return y.ring()->mul(y.ring()->canonhom(x),y); }
408 inline const cl_UP operator* (const cl_UP& x, const cl_I& y)
409         { return x.ring()->mul(x.ring()->canonhom(y),x); }
410 #endif
411 inline const cl_UP operator* (const cl_I& x, const cl_UP& y)
412         { return y.ring()->scalmul(y.ring()->basering()->canonhom(x),y); }
413 inline const cl_UP operator* (const cl_UP& x, const cl_I& y)
414         { return x.ring()->scalmul(x.ring()->basering()->canonhom(y),x); }
415 inline const cl_UP operator* (const cl_ring_element& x, const cl_UP& y)
416         { return y.ring()->scalmul(x,y); }
417 inline const cl_UP operator* (const cl_UP& x, const cl_ring_element& y)
418         { return x.ring()->scalmul(y,x); }
419
420 // Degree.
421 inline sintL degree (const cl_UP& x)
422         { return x.ring()->degree(x); }
423
424 // Coefficient.
425 inline const cl_ring_element coeff (const cl_UP& x, uintL index)
426         { return x.ring()->coeff(x,index); }
427
428 // Destructive modification.
429 inline void set_coeff (cl_UP& x, uintL index, const cl_ring_element& y)
430         { x.ring()->set_coeff(x,index,y); }
431 inline void finalize (cl_UP& x)
432         { x.ring()->finalize(x); }
433 inline void cl_UP::set_coeff (uintL index, const cl_ring_element& y)
434         { ring()->set_coeff(*this,index,y); }
435 inline void cl_UP::finalize ()
436         { ring()->finalize(*this); }
437
438 // Evaluation. (No extension of the base ring allowed here for now.)
439 inline const cl_ring_element cl_UP::operator() (const cl_ring_element& y) const
440 {
441         return ring()->eval(*this,y);
442 }
443
444 // Derivative.
445 extern const cl_UP deriv (const cl_UP& x);
446
447
448 // Ring of uninitialized elements.
449 // Any operation results in a run-time error.
450
451 extern const cl_univpoly_ring cl_no_univpoly_ring;
452 extern cl_class cl_class_no_univpoly_ring;
453 CL_REQUIRE(cl_UP_no_ring)
454
455 inline cl_univpoly_ring::cl_univpoly_ring ()
456         : cl_ring (as_cl_private_thing(cl_no_univpoly_ring)) {}
457 inline _cl_UP::_cl_UP ()
458         : rep ((cl_private_thing) cl_combine(cl_FN_tag,0)) {}
459 inline cl_UP::cl_UP ()
460         : _cl_UP (), _ring () {}
461
462
463 // Debugging support.
464 #ifdef CL_DEBUG
465 extern int cl_UP_debug_module;
466 static void* const cl_UP_debug_dummy[] = { &cl_UP_debug_dummy,
467         &cl_UP_debug_module
468 };
469 #endif
470
471
472 #endif /* _CL_UNIVPOLY_H */
473
474
475 // Templates for univariate polynomials of complex/real/rational/integers.
476
477 #ifdef notyet
478 // Unfortunately, this is not usable now, because of gcc-2.7 bugs:
479 // - A template inline function is not inline in the first function that
480 //   uses it.
481 // - Argument matching bug: User-defined conversions are not tried (or
482 //   tried with too low priority) for template functions w.r.t. normal
483 //   functions. For example, a call expt_pos(cl_UP_specialized<cl_N>,int)
484 //   is compiled as expt_pos(const cl_UP&, const cl_I&) instead of
485 //   expt_pos(const cl_UP_specialized<cl_N>&, const cl_I&).
486 // It will, however, be usable when gcc-2.8 is released.
487
488 #if defined(_CL_UNIVPOLY_COMPLEX_H) || defined(_CL_UNIVPOLY_REAL_H) || defined(_CL_UNIVPOLY_RATIONAL_H) || defined(_CL_UNIVPOLY_INTEGER_H)
489 #ifndef _CL_UNIVPOLY_AUX_H
490
491 // Normal univariate polynomials with stricter static typing:
492 // `class T' instead of `cl_ring_element'.
493
494 template <class T> class cl_univpoly_specialized_ring;
495 template <class T> class cl_UP_specialized;
496 template <class T> class cl_heap_univpoly_specialized_ring;
497
498 template <class T>
499 class cl_univpoly_specialized_ring : public cl_univpoly_ring {
500 public:
501         // Default constructor.
502         cl_univpoly_specialized_ring () : cl_univpoly_ring () {}
503         // Copy constructor.
504         cl_univpoly_specialized_ring (const cl_univpoly_specialized_ring&);
505         // Assignment operator.
506         cl_univpoly_specialized_ring& operator= (const cl_univpoly_specialized_ring&);
507         // Automatic dereferencing.
508         cl_heap_univpoly_specialized_ring<T>* operator-> () const
509         { return (cl_heap_univpoly_specialized_ring<T>*)heappointer; }
510 };
511 // Copy constructor and assignment operator.
512 template <class T>
513 _CL_DEFINE_COPY_CONSTRUCTOR2(cl_univpoly_specialized_ring<T>,cl_univpoly_specialized_ring,cl_univpoly_ring)
514 template <class T>
515 CL_DEFINE_ASSIGNMENT_OPERATOR(cl_univpoly_specialized_ring<T>,cl_univpoly_specialized_ring<T>)
516
517 template <class T>
518 class cl_UP_specialized : public cl_UP {
519 public:
520         const cl_univpoly_specialized_ring<T>& ring () const { return The(cl_univpoly_specialized_ring<T>)(_ring); }
521         // Conversion.
522         CL_DEFINE_CONVERTER(cl_ring_element)
523         // Destructive modification.
524         void set_coeff (uintL index, const T& y);
525         void finalize();
526         // Evaluation.
527         const T operator() (const T& y) const;
528 public: // Ability to place an object at a given address.
529         void* operator new (size_t size) { return cl_malloc_hook(size); }
530         void* operator new (size_t size, cl_UP_specialized<T>* ptr) { (void)size; return ptr; }
531         void operator delete (void* ptr) { cl_free_hook(ptr); }
532 };
533
534 template <class T>
535 class cl_heap_univpoly_specialized_ring : public cl_heap_univpoly_ring {
536         SUBCLASS_cl_heap_univpoly_ring()
537         // High-level operations.
538         void fprint (cl_ostream stream, const cl_UP_specialized<T>& x)
539         {
540                 cl_heap_univpoly_ring::fprint(stream,x);
541         }
542         cl_boolean equal (const cl_UP_specialized<T>& x, const cl_UP_specialized<T>& y)
543         {
544                 return cl_heap_univpoly_ring::equal(x,y);
545         }
546         const cl_UP_specialized<T> zero ()
547         {
548                 return The2(cl_UP_specialized<T>)(cl_heap_univpoly_ring::zero());
549         }
550         cl_boolean zerop (const cl_UP_specialized<T>& x)
551         {
552                 return cl_heap_univpoly_ring::zerop(x);
553         }
554         const cl_UP_specialized<T> plus (const cl_UP_specialized<T>& x, const cl_UP_specialized<T>& y)
555         {
556                 return The2(cl_UP_specialized<T>)(cl_heap_univpoly_ring::plus(x,y));
557         }
558         const cl_UP_specialized<T> minus (const cl_UP_specialized<T>& x, const cl_UP_specialized<T>& y)
559         {
560                 return The2(cl_UP_specialized<T>)(cl_heap_univpoly_ring::minus(x,y));
561         }
562         const cl_UP_specialized<T> uminus (const cl_UP_specialized<T>& x)
563         {
564                 return The2(cl_UP_specialized<T>)(cl_heap_univpoly_ring::uminus(x));
565         }
566         const cl_UP_specialized<T> one ()
567         {
568                 return The2(cl_UP_specialized<T>)(cl_heap_univpoly_ring::one());
569         }
570         const cl_UP_specialized<T> canonhom (const cl_I& x)
571         {
572                 return The2(cl_UP_specialized<T>)(cl_heap_univpoly_ring::canonhom(x));
573         }
574         const cl_UP_specialized<T> mul (const cl_UP_specialized<T>& x, const cl_UP_specialized<T>& y)
575         {
576                 return The2(cl_UP_specialized<T>)(cl_heap_univpoly_ring::mul(x,y));
577         }
578         const cl_UP_specialized<T> square (const cl_UP_specialized<T>& x)
579         {
580                 return The2(cl_UP_specialized<T>)(cl_heap_univpoly_ring::square(x));
581         }
582         const cl_UP_specialized<T> expt_pos (const cl_UP_specialized<T>& x, const cl_I& y)
583         {
584                 return The2(cl_UP_specialized<T>)(cl_heap_univpoly_ring::expt_pos(x,y));
585         }
586         const cl_UP_specialized<T> scalmul (const T& x, const cl_UP_specialized<T>& y)
587         {
588                 return The2(cl_UP_specialized<T>)(cl_heap_univpoly_ring::scalmul(x,y));
589         }
590         sintL degree (const cl_UP_specialized<T>& x)
591         {
592                 return cl_heap_univpoly_ring::degree(x);
593         }
594         const cl_UP_specialized<T> monomial (const T& x, uintL e)
595         {
596                 return The2(cl_UP_specialized<T>)(cl_heap_univpoly_ring::monomial(cl_ring_element(cl_C_ring??,x),e));
597         }
598         const T coeff (const cl_UP_specialized<T>& x, uintL index)
599         {
600                 return The(T)(cl_heap_univpoly_ring::coeff(x,index));
601         }
602         const cl_UP_specialized<T> create (sintL deg)
603         {
604                 return The2(cl_UP_specialized<T>)(cl_heap_univpoly_ring::create(deg));
605         }
606         void set_coeff (cl_UP_specialized<T>& x, uintL index, const T& y)
607         {
608                 cl_heap_univpoly_ring::set_coeff(x,index,cl_ring_element(cl_C_ring??,y));
609         }
610         void finalize (cl_UP_specialized<T>& x)
611         {
612                 cl_heap_univpoly_ring::finalize(x);
613         }
614         const T eval (const cl_UP_specialized<T>& x, const T& y)
615         {
616                 return The(T)(cl_heap_univpoly_ring::eval(x,cl_ring_element(cl_C_ring??,y)));
617         }
618 private:
619         // No need for any constructors.
620         cl_heap_univpoly_specialized_ring ();
621 };
622
623 // Lookup of polynomial rings.
624 template <class T>
625 inline const cl_univpoly_specialized_ring<T> cl_find_univpoly_ring (const cl_specialized_number_ring<T>& r)
626 { return The(cl_univpoly_specialized_ring<T>) (cl_find_univpoly_ring((const cl_ring&)r)); }
627 template <class T>
628 inline const cl_univpoly_specialized_ring<T> cl_find_univpoly_ring (const cl_specialized_number_ring<T>& r, const cl_symbol& varname)
629 { return The(cl_univpoly_specialized_ring<T>) (cl_find_univpoly_ring((const cl_ring&)r,varname)); }
630
631 // Operations on polynomials.
632
633 // Add.
634 template <class T>
635 inline const cl_UP_specialized<T> operator+ (const cl_UP_specialized<T>& x, const cl_UP_specialized<T>& y)
636         { return x.ring()->plus(x,y); }
637
638 // Negate.
639 template <class T>
640 inline const cl_UP_specialized<T> operator- (const cl_UP_specialized<T>& x)
641         { return x.ring()->uminus(x); }
642
643 // Subtract.
644 template <class T>
645 inline const cl_UP_specialized<T> operator- (const cl_UP_specialized<T>& x, const cl_UP_specialized<T>& y)
646         { return x.ring()->minus(x,y); }
647
648 // Multiply.
649 template <class T>
650 inline const cl_UP_specialized<T> operator* (const cl_UP_specialized<T>& x, const cl_UP_specialized<T>& y)
651         { return x.ring()->mul(x,y); }
652
653 // Squaring.
654 template <class T>
655 inline const cl_UP_specialized<T> square (const cl_UP_specialized<T>& x)
656         { return x.ring()->square(x); }
657
658 // Exponentiation x^y, where y > 0.
659 template <class T>
660 inline const cl_UP_specialized<T> expt_pos (const cl_UP_specialized<T>& x, const cl_I& y)
661         { return x.ring()->expt_pos(x,y); }
662
663 // Scalar multiplication.
664 // Need more discrimination on T ??
665 template <class T>
666 inline const cl_UP_specialized<T> operator* (const cl_I& x, const cl_UP_specialized<T>& y)
667         { return y.ring()->mul(y.ring()->canonhom(x),y); }
668 template <class T>
669 inline const cl_UP_specialized<T> operator* (const cl_UP_specialized<T>& x, const cl_I& y)
670         { return x.ring()->mul(x.ring()->canonhom(y),x); }
671 template <class T>
672 inline const cl_UP_specialized<T> operator* (const T& x, const cl_UP_specialized<T>& y)
673         { return y.ring()->scalmul(x,y); }
674 template <class T>
675 inline const cl_UP_specialized<T> operator* (const cl_UP_specialized<T>& x, const T& y)
676         { return x.ring()->scalmul(y,x); }
677
678 // Coefficient.
679 template <class T>
680 inline const T coeff (const cl_UP_specialized<T>& x, uintL index)
681         { return x.ring()->coeff(x,index); }
682
683 // Destructive modification.
684 template <class T>
685 inline void set_coeff (cl_UP_specialized<T>& x, uintL index, const T& y)
686         { x.ring()->set_coeff(x,index,y); }
687 template <class T>
688 inline void finalize (cl_UP_specialized<T>& x)
689         { x.ring()->finalize(x); }
690 template <class T>
691 inline void cl_UP_specialized<T>::set_coeff (uintL index, const T& y)
692         { ring()->set_coeff(*this,index,y); }
693 template <class T>
694 inline void cl_UP_specialized<T>::finalize ()
695         { ring()->finalize(*this); }
696
697 // Evaluation. (No extension of the base ring allowed here for now.)
698 template <class T>
699 inline const T cl_UP_specialized<T>::operator() (const T& y) const
700 {
701         return ring()->eval(*this,y);
702 }
703
704 // Derivative.
705 template <class T>
706 inline const cl_UP_specialized<T> deriv (const cl_UP_specialized<T>& x)
707         { return The(cl_UP_specialized<T>)(deriv((const cl_UP&)x)); }
708
709
710 #endif /* _CL_UNIVPOLY_AUX_H */
711 #endif
712
713 #endif