1 // Univariate Polynomials.
6 #include "cln/object.h"
8 #include "cln/malloc.h"
9 #include "cln/proplist.h"
10 #include "cln/symbol.h"
16 // To protect against mixing elements of different polynomial rings, every
17 // polynomial carries its ring in itself.
19 class cl_heap_univpoly_ring;
21 class cl_univpoly_ring : public cl_ring {
23 // Default constructor.
25 // Constructor. Takes a cl_heap_univpoly_ring*, increments its refcount.
26 cl_univpoly_ring (cl_heap_univpoly_ring* r);
27 // Private constructor. Doesn't increment the refcount.
28 cl_univpoly_ring (cl_private_thing);
30 cl_univpoly_ring (const cl_univpoly_ring&);
31 // Assignment operator.
32 cl_univpoly_ring& operator= (const cl_univpoly_ring&);
33 // Automatic dereferencing.
34 cl_heap_univpoly_ring* operator-> () const
35 { return (cl_heap_univpoly_ring*)heappointer; }
37 // Copy constructor and assignment operator.
38 CL_DEFINE_COPY_CONSTRUCTOR2(cl_univpoly_ring,cl_ring)
39 CL_DEFINE_ASSIGNMENT_OPERATOR(cl_univpoly_ring,cl_univpoly_ring)
41 // Normal constructor for `cl_univpoly_ring'.
42 inline cl_univpoly_ring::cl_univpoly_ring (cl_heap_univpoly_ring* r)
43 : cl_ring ((cl_private_thing) (cl_inc_pointer_refcount((cl_heap*)r), r)) {}
44 // Private constructor for `cl_univpoly_ring'.
45 inline cl_univpoly_ring::cl_univpoly_ring (cl_private_thing p)
48 // Operations on univariate polynomial rings.
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, const cl_univpoly_ring& R2)
53 { return (R1.pointer != R2.pointer); }
54 inline bool operator== (const cl_univpoly_ring& R1, cl_heap_univpoly_ring* R2)
55 { return (R1.pointer == R2); }
56 inline bool operator!= (const cl_univpoly_ring& R1, cl_heap_univpoly_ring* R2)
57 { return (R1.pointer != R2); }
59 // Representation of a univariate polynomial.
61 class _cl_UP /* cf. _cl_ring_element */ {
63 cl_gcpointer rep; // vector of coefficients, a cl_V_any
64 // Default constructor.
68 _cl_UP (const cl_heap_univpoly_ring* R, const cl_V_any& r) : rep (as_cl_private_thing(r)) { (void)R; }
69 _cl_UP (const cl_univpoly_ring& R, const cl_V_any& r) : rep (as_cl_private_thing(r)) { (void)R; }
72 CL_DEFINE_CONVERTER(_cl_ring_element)
73 public: // Ability to place an object at a given address.
74 void* operator new (size_t size) { return malloc_hook(size); }
75 void* operator new (size_t size, void* ptr) { (void)size; return ptr; }
76 void operator delete (void* ptr) { free_hook(ptr); }
79 class cl_UP /* cf. cl_ring_element */ : public _cl_UP {
81 cl_univpoly_ring _ring; // polynomial ring (references the base ring)
83 const cl_univpoly_ring& ring () const { return _ring; }
85 // Default constructor.
89 cl_UP (const cl_univpoly_ring& R, const cl_V_any& r)
90 : _cl_UP (R,r), _ring (R) {}
91 cl_UP (const cl_univpoly_ring& R, const _cl_UP& r)
92 : _cl_UP (r), _ring (R) {}
95 CL_DEFINE_CONVERTER(cl_ring_element)
96 // Destructive modification.
97 void set_coeff (uintL index, const cl_ring_element& y);
100 const cl_ring_element operator() (const cl_ring_element& y) const;
102 void debug_print () const;
103 public: // Ability to place an object at a given address.
104 void* operator new (size_t size) { return malloc_hook(size); }
105 void* operator new (size_t size, void* ptr) { (void)size; return ptr; }
106 void operator delete (void* ptr) { free_hook(ptr); }
112 struct _cl_univpoly_setops /* cf. _cl_ring_setops */ {
114 void (* fprint) (cl_heap_univpoly_ring* R, std::ostream& stream, const _cl_UP& x);
116 // (Be careful: This is not well-defined for polynomials with
117 // floating-point coefficients.)
118 bool (* equal) (cl_heap_univpoly_ring* R, const _cl_UP& x, const _cl_UP& y);
120 struct _cl_univpoly_addops /* cf. _cl_ring_addops */ {
122 const _cl_UP (* zero) (cl_heap_univpoly_ring* R);
123 bool (* zerop) (cl_heap_univpoly_ring* R, const _cl_UP& x);
125 const _cl_UP (* plus) (cl_heap_univpoly_ring* R, const _cl_UP& x, const _cl_UP& y);
127 const _cl_UP (* minus) (cl_heap_univpoly_ring* R, const _cl_UP& x, const _cl_UP& y);
129 const _cl_UP (* uminus) (cl_heap_univpoly_ring* R, const _cl_UP& x);
131 struct _cl_univpoly_mulops /* cf. _cl_ring_mulops */ {
133 const _cl_UP (* one) (cl_heap_univpoly_ring* R);
134 // canonical homomorphism
135 const _cl_UP (* canonhom) (cl_heap_univpoly_ring* R, const cl_I& x);
137 const _cl_UP (* mul) (cl_heap_univpoly_ring* R, const _cl_UP& x, const _cl_UP& y);
139 const _cl_UP (* square) (cl_heap_univpoly_ring* R, const _cl_UP& x);
141 const _cl_UP (* expt_pos) (cl_heap_univpoly_ring* R, const _cl_UP& x, const cl_I& y);
143 struct _cl_univpoly_modulops {
144 // scalar multiplication x*y
145 const _cl_UP (* scalmul) (cl_heap_univpoly_ring* R, const cl_ring_element& x, const _cl_UP& y);
147 struct _cl_univpoly_polyops {
149 sintL (* degree) (cl_heap_univpoly_ring* R, const _cl_UP& x);
151 sintL (* ldegree) (cl_heap_univpoly_ring* R, const _cl_UP& x);
153 const _cl_UP (* monomial) (cl_heap_univpoly_ring* R, const cl_ring_element& x, uintL e);
154 // coefficient (0 if index>degree)
155 const cl_ring_element (* coeff) (cl_heap_univpoly_ring* R, const _cl_UP& x, uintL index);
156 // create new polynomial, bounded degree
157 const _cl_UP (* create) (cl_heap_univpoly_ring* R, sintL deg);
158 // set coefficient in new polynomial
159 void (* set_coeff) (cl_heap_univpoly_ring* R, _cl_UP& x, uintL index, const cl_ring_element& y);
160 // finalize polynomial
161 void (* finalize) (cl_heap_univpoly_ring* R, _cl_UP& x);
162 // evaluate, substitute an element of R
163 const cl_ring_element (* eval) (cl_heap_univpoly_ring* R, const _cl_UP& x, const cl_ring_element& y);
165 typedef const _cl_univpoly_setops cl_univpoly_setops;
166 typedef const _cl_univpoly_addops cl_univpoly_addops;
167 typedef const _cl_univpoly_mulops cl_univpoly_mulops;
168 typedef const _cl_univpoly_modulops cl_univpoly_modulops;
169 typedef const _cl_univpoly_polyops cl_univpoly_polyops;
171 // Representation of a univariate polynomial ring.
173 class cl_heap_univpoly_ring /* cf. cl_heap_ring */ : public cl_heap {
174 SUBCLASS_cl_heap_ring()
176 cl_property_list properties;
178 cl_univpoly_setops* setops;
179 cl_univpoly_addops* addops;
180 cl_univpoly_mulops* mulops;
181 cl_univpoly_modulops* modulops;
182 cl_univpoly_polyops* polyops;
184 cl_ring _basering; // the coefficients are elements of this ring
186 const cl_ring& basering () const { return _basering; }
188 // Low-level operations.
189 void _fprint (std::ostream& stream, const _cl_UP& x)
190 { setops->fprint(this,stream,x); }
191 bool _equal (const _cl_UP& x, const _cl_UP& y)
192 { return setops->equal(this,x,y); }
193 const _cl_UP _zero ()
194 { return addops->zero(this); }
195 bool _zerop (const _cl_UP& x)
196 { return addops->zerop(this,x); }
197 const _cl_UP _plus (const _cl_UP& x, const _cl_UP& y)
198 { return addops->plus(this,x,y); }
199 const _cl_UP _minus (const _cl_UP& x, const _cl_UP& y)
200 { return addops->minus(this,x,y); }
201 const _cl_UP _uminus (const _cl_UP& x)
202 { return addops->uminus(this,x); }
204 { return mulops->one(this); }
205 const _cl_UP _canonhom (const cl_I& x)
206 { return mulops->canonhom(this,x); }
207 const _cl_UP _mul (const _cl_UP& x, const _cl_UP& y)
208 { return mulops->mul(this,x,y); }
209 const _cl_UP _square (const _cl_UP& x)
210 { return mulops->square(this,x); }
211 const _cl_UP _expt_pos (const _cl_UP& x, const cl_I& y)
212 { return mulops->expt_pos(this,x,y); }
213 const _cl_UP _scalmul (const cl_ring_element& x, const _cl_UP& y)
214 { return modulops->scalmul(this,x,y); }
215 sintL _degree (const _cl_UP& x)
216 { return polyops->degree(this,x); }
217 sintL _ldegree (const _cl_UP& x)
218 { return polyops->ldegree(this,x); }
219 const _cl_UP _monomial (const cl_ring_element& x, uintL e)
220 { return polyops->monomial(this,x,e); }
221 const cl_ring_element _coeff (const _cl_UP& x, uintL index)
222 { return polyops->coeff(this,x,index); }
223 const _cl_UP _create (sintL deg)
224 { return polyops->create(this,deg); }
225 void _set_coeff (_cl_UP& x, uintL index, const cl_ring_element& y)
226 { polyops->set_coeff(this,x,index,y); }
227 void _finalize (_cl_UP& x)
228 { polyops->finalize(this,x); }
229 const cl_ring_element _eval (const _cl_UP& x, const cl_ring_element& y)
230 { return polyops->eval(this,x,y); }
231 // High-level operations.
232 void fprint (std::ostream& stream, const cl_UP& x)
234 if (!(x.ring() == this)) throw runtime_exception();
237 bool equal (const cl_UP& x, const cl_UP& y)
239 if (!(x.ring() == this)) throw runtime_exception();
240 if (!(y.ring() == this)) throw runtime_exception();
245 return cl_UP(this,_zero());
247 bool zerop (const cl_UP& x)
249 if (!(x.ring() == this)) throw runtime_exception();
252 const cl_UP plus (const cl_UP& x, const cl_UP& y)
254 if (!(x.ring() == this)) throw runtime_exception();
255 if (!(y.ring() == this)) throw runtime_exception();
256 return cl_UP(this,_plus(x,y));
258 const cl_UP minus (const cl_UP& x, const cl_UP& y)
260 if (!(x.ring() == this)) throw runtime_exception();
261 if (!(y.ring() == this)) throw runtime_exception();
262 return cl_UP(this,_minus(x,y));
264 const cl_UP uminus (const cl_UP& x)
266 if (!(x.ring() == this)) throw runtime_exception();
267 return cl_UP(this,_uminus(x));
271 return cl_UP(this,_one());
273 const cl_UP canonhom (const cl_I& x)
275 return cl_UP(this,_canonhom(x));
277 const cl_UP mul (const cl_UP& x, const cl_UP& y)
279 if (!(x.ring() == this)) throw runtime_exception();
280 if (!(y.ring() == this)) throw runtime_exception();
281 return cl_UP(this,_mul(x,y));
283 const cl_UP square (const cl_UP& x)
285 if (!(x.ring() == this)) throw runtime_exception();
286 return cl_UP(this,_square(x));
288 const cl_UP expt_pos (const cl_UP& x, const cl_I& y)
290 if (!(x.ring() == this)) throw runtime_exception();
291 return cl_UP(this,_expt_pos(x,y));
293 const cl_UP scalmul (const cl_ring_element& x, const cl_UP& y)
295 if (!(y.ring() == this)) throw runtime_exception();
296 return cl_UP(this,_scalmul(x,y));
298 sintL degree (const cl_UP& x)
300 if (!(x.ring() == this)) throw runtime_exception();
303 sintL ldegree (const cl_UP& x)
305 if (!(x.ring() == this)) throw runtime_exception();
308 const cl_UP monomial (const cl_ring_element& x, uintL e)
310 return cl_UP(this,_monomial(x,e));
312 const cl_ring_element coeff (const cl_UP& x, uintL index)
314 if (!(x.ring() == this)) throw runtime_exception();
315 return _coeff(x,index);
317 const cl_UP create (sintL deg)
319 return cl_UP(this,_create(deg));
321 void set_coeff (cl_UP& x, uintL index, const cl_ring_element& y)
323 if (!(x.ring() == this)) throw runtime_exception();
324 _set_coeff(x,index,y);
326 void finalize (cl_UP& x)
328 if (!(x.ring() == this)) throw runtime_exception();
331 const cl_ring_element eval (const cl_UP& x, const cl_ring_element& y)
333 if (!(x.ring() == this)) throw runtime_exception();
336 // Property operations.
337 cl_property* get_property (const cl_symbol& key)
338 { return properties.get_property(key); }
339 void add_property (cl_property* new_property)
340 { properties.add_property(new_property); }
342 cl_heap_univpoly_ring (const cl_ring& r, cl_univpoly_setops*, cl_univpoly_addops*, cl_univpoly_mulops*, cl_univpoly_modulops*, cl_univpoly_polyops*);
343 ~cl_heap_univpoly_ring () {}
345 #define SUBCLASS_cl_heap_univpoly_ring() \
346 SUBCLASS_cl_heap_ring()
349 // Lookup or create the "standard" univariate polynomial ring over a ring r.
350 extern const cl_univpoly_ring find_univpoly_ring (const cl_ring& r);
352 // Lookup or create a univariate polynomial ring with a named variable over r.
353 extern const cl_univpoly_ring find_univpoly_ring (const cl_ring& r, const cl_symbol& varname);
358 // Operations on polynomials.
361 inline void fprint (std::ostream& stream, const cl_UP& x)
362 { x.ring()->fprint(stream,x); }
363 CL_DEFINE_PRINT_OPERATOR(cl_UP)
366 inline const cl_UP operator+ (const cl_UP& x, const cl_UP& y)
367 { return x.ring()->plus(x,y); }
370 inline const cl_UP operator- (const cl_UP& x)
371 { return x.ring()->uminus(x); }
374 inline const cl_UP operator- (const cl_UP& x, const cl_UP& y)
375 { return x.ring()->minus(x,y); }
378 inline bool operator== (const cl_UP& x, const cl_UP& y)
379 { return x.ring()->equal(x,y); }
380 inline bool operator!= (const cl_UP& x, const cl_UP& y)
381 { return !x.ring()->equal(x,y); }
383 // Compare against 0.
384 inline bool zerop (const cl_UP& x)
385 { return x.ring()->zerop(x); }
388 inline const cl_UP operator* (const cl_UP& x, const cl_UP& y)
389 { return x.ring()->mul(x,y); }
392 inline const cl_UP square (const cl_UP& x)
393 { return x.ring()->square(x); }
395 // Exponentiation x^y, where y > 0.
396 inline const cl_UP expt_pos (const cl_UP& x, const cl_I& y)
397 { return x.ring()->expt_pos(x,y); }
399 // Scalar multiplication.
400 #if 0 // less efficient
401 inline const cl_UP operator* (const cl_I& x, const cl_UP& y)
402 { return y.ring()->mul(y.ring()->canonhom(x),y); }
403 inline const cl_UP operator* (const cl_UP& x, const cl_I& y)
404 { return x.ring()->mul(x.ring()->canonhom(y),x); }
406 inline const cl_UP operator* (const cl_I& x, const cl_UP& y)
407 { return y.ring()->scalmul(y.ring()->basering()->canonhom(x),y); }
408 inline const cl_UP operator* (const cl_UP& x, const cl_I& y)
409 { return x.ring()->scalmul(x.ring()->basering()->canonhom(y),x); }
410 inline const cl_UP operator* (const cl_ring_element& x, const cl_UP& y)
411 { return y.ring()->scalmul(x,y); }
412 inline const cl_UP operator* (const cl_UP& x, const cl_ring_element& y)
413 { return x.ring()->scalmul(y,x); }
416 inline sintL degree (const cl_UP& x)
417 { return x.ring()->degree(x); }
420 inline sintL ldegree (const cl_UP& x)
421 { return x.ring()->ldegree(x); }
424 inline const cl_ring_element coeff (const cl_UP& x, uintL index)
425 { return x.ring()->coeff(x,index); }
427 // Destructive modification.
428 inline void set_coeff (cl_UP& x, uintL index, const cl_ring_element& y)
429 { x.ring()->set_coeff(x,index,y); }
430 inline void finalize (cl_UP& x)
431 { x.ring()->finalize(x); }
432 inline void cl_UP::set_coeff (uintL index, const cl_ring_element& y)
433 { ring()->set_coeff(*this,index,y); }
434 inline void cl_UP::finalize ()
435 { ring()->finalize(*this); }
437 // Evaluation. (No extension of the base ring allowed here for now.)
438 inline const cl_ring_element cl_UP::operator() (const cl_ring_element& y) const
440 return ring()->eval(*this,y);
444 extern const cl_UP deriv (const cl_UP& x);
447 // Ring of uninitialized elements.
448 // Any operation results in a run-time error.
450 extern const cl_univpoly_ring cl_no_univpoly_ring;
451 extern cl_class cl_class_no_univpoly_ring;
453 class cl_UP_no_ring_init_helper
457 cl_UP_no_ring_init_helper();
458 ~cl_UP_no_ring_init_helper();
460 static cl_UP_no_ring_init_helper cl_UP_no_ring_init_helper_instance;
462 inline cl_univpoly_ring::cl_univpoly_ring ()
463 : cl_ring (as_cl_private_thing(cl_no_univpoly_ring)) {}
464 inline _cl_UP::_cl_UP ()
465 : rep ((cl_private_thing) cl_combine(cl_FN_tag,0)) {}
466 inline cl_UP::cl_UP ()
467 : _cl_UP (), _ring () {}
470 // Debugging support.
472 extern int cl_UP_debug_module;
473 CL_FORCE_LINK(cl_UP_debug_dummy, cl_UP_debug_module)
478 #endif /* _CL_UNIVPOLY_H */
482 // Templates for univariate polynomials of complex/real/rational/integers.
485 // Unfortunately, this is not usable now, because of gcc-2.7 bugs:
486 // - A template inline function is not inline in the first function that
488 // - Argument matching bug: User-defined conversions are not tried (or
489 // tried with too low priority) for template functions w.r.t. normal
490 // functions. For example, a call expt_pos(cl_UP_specialized<cl_N>,int)
491 // is compiled as expt_pos(const cl_UP&, const cl_I&) instead of
492 // expt_pos(const cl_UP_specialized<cl_N>&, const cl_I&).
493 // It will, however, be usable when gcc-2.8 is released.
495 #if defined(_CL_UNIVPOLY_COMPLEX_H) || defined(_CL_UNIVPOLY_REAL_H) || defined(_CL_UNIVPOLY_RATIONAL_H) || defined(_CL_UNIVPOLY_INTEGER_H)
496 #ifndef _CL_UNIVPOLY_AUX_H
498 // Normal univariate polynomials with stricter static typing:
499 // `class T' instead of `cl_ring_element'.
501 template <class T> class cl_univpoly_specialized_ring;
502 template <class T> class cl_UP_specialized;
503 template <class T> class cl_heap_univpoly_specialized_ring;
506 class cl_univpoly_specialized_ring : public cl_univpoly_ring {
508 // Default constructor.
509 cl_univpoly_specialized_ring () : cl_univpoly_ring () {}
511 cl_univpoly_specialized_ring (const cl_univpoly_specialized_ring&);
512 // Assignment operator.
513 cl_univpoly_specialized_ring& operator= (const cl_univpoly_specialized_ring&);
514 // Automatic dereferencing.
515 cl_heap_univpoly_specialized_ring<T>* operator-> () const
516 { return (cl_heap_univpoly_specialized_ring<T>*)heappointer; }
518 // Copy constructor and assignment operator.
520 _CL_DEFINE_COPY_CONSTRUCTOR2(cl_univpoly_specialized_ring<T>,cl_univpoly_specialized_ring,cl_univpoly_ring)
522 CL_DEFINE_ASSIGNMENT_OPERATOR(cl_univpoly_specialized_ring<T>,cl_univpoly_specialized_ring<T>)
525 class cl_UP_specialized : public cl_UP {
527 const cl_univpoly_specialized_ring<T>& ring () const { return The(cl_univpoly_specialized_ring<T>)(_ring); }
529 CL_DEFINE_CONVERTER(cl_ring_element)
530 // Destructive modification.
531 void set_coeff (uintL index, const T& y);
534 const T operator() (const T& y) const;
535 public: // Ability to place an object at a given address.
536 void* operator new (size_t size) { return malloc_hook(size); }
537 void* operator new (size_t size, void* ptr) { (void)size; return ptr; }
538 void operator delete (void* ptr) { free_hook(ptr); }
542 class cl_heap_univpoly_specialized_ring : public cl_heap_univpoly_ring {
543 SUBCLASS_cl_heap_univpoly_ring()
544 // High-level operations.
545 void fprint (std::ostream& stream, const cl_UP_specialized<T>& x)
547 cl_heap_univpoly_ring::fprint(stream,x);
549 bool equal (const cl_UP_specialized<T>& x, const cl_UP_specialized<T>& y)
551 return cl_heap_univpoly_ring::equal(x,y);
553 const cl_UP_specialized<T> zero ()
555 return The2(cl_UP_specialized<T>)(cl_heap_univpoly_ring::zero());
557 bool zerop (const cl_UP_specialized<T>& x)
559 return cl_heap_univpoly_ring::zerop(x);
561 const cl_UP_specialized<T> plus (const cl_UP_specialized<T>& x, const cl_UP_specialized<T>& y)
563 return The2(cl_UP_specialized<T>)(cl_heap_univpoly_ring::plus(x,y));
565 const cl_UP_specialized<T> minus (const cl_UP_specialized<T>& x, const cl_UP_specialized<T>& y)
567 return The2(cl_UP_specialized<T>)(cl_heap_univpoly_ring::minus(x,y));
569 const cl_UP_specialized<T> uminus (const cl_UP_specialized<T>& x)
571 return The2(cl_UP_specialized<T>)(cl_heap_univpoly_ring::uminus(x));
573 const cl_UP_specialized<T> one ()
575 return The2(cl_UP_specialized<T>)(cl_heap_univpoly_ring::one());
577 const cl_UP_specialized<T> canonhom (const cl_I& x)
579 return The2(cl_UP_specialized<T>)(cl_heap_univpoly_ring::canonhom(x));
581 const cl_UP_specialized<T> mul (const cl_UP_specialized<T>& x, const cl_UP_specialized<T>& y)
583 return The2(cl_UP_specialized<T>)(cl_heap_univpoly_ring::mul(x,y));
585 const cl_UP_specialized<T> square (const cl_UP_specialized<T>& x)
587 return The2(cl_UP_specialized<T>)(cl_heap_univpoly_ring::square(x));
589 const cl_UP_specialized<T> expt_pos (const cl_UP_specialized<T>& x, const cl_I& y)
591 return The2(cl_UP_specialized<T>)(cl_heap_univpoly_ring::expt_pos(x,y));
593 const cl_UP_specialized<T> scalmul (const T& x, const cl_UP_specialized<T>& y)
595 return The2(cl_UP_specialized<T>)(cl_heap_univpoly_ring::scalmul(x,y));
597 sintL degree (const cl_UP_specialized<T>& x)
599 return cl_heap_univpoly_ring::degree(x);
601 sintL ldegree (const cl_UP_specialized<T>& x)
603 return cl_heap_univpoly_ring::ldegree(x);
605 const cl_UP_specialized<T> monomial (const T& x, uintL e)
607 return The2(cl_UP_specialized<T>)(cl_heap_univpoly_ring::monomial(cl_ring_element(cl_C_ring??,x),e));
609 const T coeff (const cl_UP_specialized<T>& x, uintL index)
611 return The(T)(cl_heap_univpoly_ring::coeff(x,index));
613 const cl_UP_specialized<T> create (sintL deg)
615 return The2(cl_UP_specialized<T>)(cl_heap_univpoly_ring::create(deg));
617 void set_coeff (cl_UP_specialized<T>& x, uintL index, const T& y)
619 cl_heap_univpoly_ring::set_coeff(x,index,cl_ring_element(cl_C_ring??,y));
621 void finalize (cl_UP_specialized<T>& x)
623 cl_heap_univpoly_ring::finalize(x);
625 const T eval (const cl_UP_specialized<T>& x, const T& y)
627 return The(T)(cl_heap_univpoly_ring::eval(x,cl_ring_element(cl_C_ring??,y)));
630 // No need for any constructors.
631 cl_heap_univpoly_specialized_ring ();
634 // Lookup of polynomial rings.
636 inline const cl_univpoly_specialized_ring<T> find_univpoly_ring (const cl_specialized_number_ring<T>& r)
637 { return The(cl_univpoly_specialized_ring<T>) (find_univpoly_ring((const cl_ring&)r)); }
639 inline const cl_univpoly_specialized_ring<T> find_univpoly_ring (const cl_specialized_number_ring<T>& r, const cl_symbol& varname)
640 { return The(cl_univpoly_specialized_ring<T>) (find_univpoly_ring((const cl_ring&)r,varname)); }
642 // Operations on polynomials.
646 inline const cl_UP_specialized<T> operator+ (const cl_UP_specialized<T>& x, const cl_UP_specialized<T>& y)
647 { return x.ring()->plus(x,y); }
651 inline const cl_UP_specialized<T> operator- (const cl_UP_specialized<T>& x)
652 { return x.ring()->uminus(x); }
656 inline const cl_UP_specialized<T> operator- (const cl_UP_specialized<T>& x, const cl_UP_specialized<T>& y)
657 { return x.ring()->minus(x,y); }
661 inline const cl_UP_specialized<T> operator* (const cl_UP_specialized<T>& x, const cl_UP_specialized<T>& y)
662 { return x.ring()->mul(x,y); }
666 inline const cl_UP_specialized<T> square (const cl_UP_specialized<T>& x)
667 { return x.ring()->square(x); }
669 // Exponentiation x^y, where y > 0.
671 inline const cl_UP_specialized<T> expt_pos (const cl_UP_specialized<T>& x, const cl_I& y)
672 { return x.ring()->expt_pos(x,y); }
674 // Scalar multiplication.
675 // Need more discrimination on T ??
677 inline const cl_UP_specialized<T> operator* (const cl_I& x, const cl_UP_specialized<T>& y)
678 { return y.ring()->mul(y.ring()->canonhom(x),y); }
680 inline const cl_UP_specialized<T> operator* (const cl_UP_specialized<T>& x, const cl_I& y)
681 { return x.ring()->mul(x.ring()->canonhom(y),x); }
683 inline const cl_UP_specialized<T> operator* (const T& x, const cl_UP_specialized<T>& y)
684 { return y.ring()->scalmul(x,y); }
686 inline const cl_UP_specialized<T> operator* (const cl_UP_specialized<T>& x, const T& y)
687 { return x.ring()->scalmul(y,x); }
691 inline const T coeff (const cl_UP_specialized<T>& x, uintL index)
692 { return x.ring()->coeff(x,index); }
694 // Destructive modification.
696 inline void set_coeff (cl_UP_specialized<T>& x, uintL index, const T& y)
697 { x.ring()->set_coeff(x,index,y); }
699 inline void finalize (cl_UP_specialized<T>& x)
700 { x.ring()->finalize(x); }
702 inline void cl_UP_specialized<T>::set_coeff (uintL index, const T& y)
703 { ring()->set_coeff(*this,index,y); }
705 inline void cl_UP_specialized<T>::finalize ()
706 { ring()->finalize(*this); }
708 // Evaluation. (No extension of the base ring allowed here for now.)
710 inline const T cl_UP_specialized<T>::operator() (const T& y) const
712 return ring()->eval(*this,y);
717 inline const cl_UP_specialized<T> deriv (const cl_UP_specialized<T>& x)
718 { return The(cl_UP_specialized<T>)(deriv((const cl_UP&)x)); }
721 #endif /* _CL_UNIVPOLY_AUX_H */