1 // Univariate Polynomials over the integer numbers.
3 #ifndef _CL_UNIVPOLY_INTEGER_H
4 #define _CL_UNIVPOLY_INTEGER_H
7 #include "cl_univpoly.h"
9 #include "cl_integer_class.h"
10 #include "cl_integer_ring.h"
12 // Normal univariate polynomials with stricter static typing:
13 // `cl_I' instead of `cl_ring_element'.
17 typedef cl_UP_specialized<cl_I> cl_UP_I;
18 typedef cl_univpoly_specialized_ring<cl_I> cl_univpoly_integer_ring;
19 //typedef cl_heap_univpoly_specialized_ring<cl_I> cl_heap_univpoly_integer_ring;
23 class cl_heap_univpoly_integer_ring;
25 class cl_univpoly_integer_ring : public cl_univpoly_ring {
27 // Default constructor.
28 cl_univpoly_integer_ring () : cl_univpoly_ring () {}
30 cl_univpoly_integer_ring (const cl_univpoly_integer_ring&);
31 // Assignment operator.
32 cl_univpoly_integer_ring& operator= (const cl_univpoly_integer_ring&);
33 // Automatic dereferencing.
34 cl_heap_univpoly_integer_ring* operator-> () const
35 { return (cl_heap_univpoly_integer_ring*)heappointer; }
37 // Copy constructor and assignment operator.
38 CL_DEFINE_COPY_CONSTRUCTOR2(cl_univpoly_integer_ring,cl_univpoly_ring)
39 CL_DEFINE_ASSIGNMENT_OPERATOR(cl_univpoly_integer_ring,cl_univpoly_integer_ring)
41 class cl_UP_I : public cl_UP {
43 const cl_univpoly_integer_ring& ring () const { return The(cl_univpoly_integer_ring)(_ring); }
45 CL_DEFINE_CONVERTER(cl_ring_element)
46 // Destructive modification.
47 void set_coeff (uintL index, const cl_I& y);
50 const cl_I operator() (const cl_I& y) const;
51 public: // Ability to place an object at a given address.
52 void* operator new (size_t size) { return cl_malloc_hook(size); }
53 void* operator new (size_t size, cl_UP_I* ptr) { (void)size; return ptr; }
54 void operator delete (void* ptr) { cl_free_hook(ptr); }
57 class cl_heap_univpoly_integer_ring : public cl_heap_univpoly_ring {
58 SUBCLASS_cl_heap_univpoly_ring()
59 // High-level operations.
60 void fprint (cl_ostream stream, const cl_UP_I& x)
62 cl_heap_univpoly_ring::fprint(stream,x);
64 cl_boolean equal (const cl_UP_I& x, const cl_UP_I& y)
66 return cl_heap_univpoly_ring::equal(x,y);
70 return The2(cl_UP_I)(cl_heap_univpoly_ring::zero());
72 cl_boolean zerop (const cl_UP_I& x)
74 return cl_heap_univpoly_ring::zerop(x);
76 const cl_UP_I plus (const cl_UP_I& x, const cl_UP_I& y)
78 return The2(cl_UP_I)(cl_heap_univpoly_ring::plus(x,y));
80 const cl_UP_I minus (const cl_UP_I& x, const cl_UP_I& y)
82 return The2(cl_UP_I)(cl_heap_univpoly_ring::minus(x,y));
84 const cl_UP_I uminus (const cl_UP_I& x)
86 return The2(cl_UP_I)(cl_heap_univpoly_ring::uminus(x));
90 return The2(cl_UP_I)(cl_heap_univpoly_ring::one());
92 const cl_UP_I canonhom (const cl_I& x)
94 return The2(cl_UP_I)(cl_heap_univpoly_ring::canonhom(x));
96 const cl_UP_I mul (const cl_UP_I& x, const cl_UP_I& y)
98 return The2(cl_UP_I)(cl_heap_univpoly_ring::mul(x,y));
100 const cl_UP_I square (const cl_UP_I& x)
102 return The2(cl_UP_I)(cl_heap_univpoly_ring::square(x));
104 const cl_UP_I expt_pos (const cl_UP_I& x, const cl_I& y)
106 return The2(cl_UP_I)(cl_heap_univpoly_ring::expt_pos(x,y));
108 const cl_UP_I scalmul (const cl_I& x, const cl_UP_I& y)
110 return The2(cl_UP_I)(cl_heap_univpoly_ring::scalmul(cl_ring_element(cl_I_ring,x),y));
112 sintL degree (const cl_UP_I& x)
114 return cl_heap_univpoly_ring::degree(x);
116 const cl_UP_I monomial (const cl_I& x, uintL e)
118 return The2(cl_UP_I)(cl_heap_univpoly_ring::monomial(cl_ring_element(cl_I_ring,x),e));
120 const cl_I coeff (const cl_UP_I& x, uintL index)
122 return The(cl_I)(cl_heap_univpoly_ring::coeff(x,index));
124 const cl_UP_I create (sintL deg)
126 return The2(cl_UP_I)(cl_heap_univpoly_ring::create(deg));
128 void set_coeff (cl_UP_I& x, uintL index, const cl_I& y)
130 cl_heap_univpoly_ring::set_coeff(x,index,cl_ring_element(cl_I_ring,y));
132 void finalize (cl_UP_I& x)
134 cl_heap_univpoly_ring::finalize(x);
136 const cl_I eval (const cl_UP_I& x, const cl_I& y)
138 return The(cl_I)(cl_heap_univpoly_ring::eval(x,cl_ring_element(cl_I_ring,y)));
141 // No need for any constructors.
142 cl_heap_univpoly_integer_ring ();
145 // Lookup of polynomial rings.
146 inline const cl_univpoly_integer_ring cl_find_univpoly_ring (const cl_integer_ring& r)
147 { return The(cl_univpoly_integer_ring) (cl_find_univpoly_ring((const cl_ring&)r)); }
148 inline const cl_univpoly_integer_ring cl_find_univpoly_ring (const cl_integer_ring& r, const cl_symbol& varname)
149 { return The(cl_univpoly_integer_ring) (cl_find_univpoly_ring((const cl_ring&)r,varname)); }
151 // Operations on polynomials.
154 inline const cl_UP_I operator+ (const cl_UP_I& x, const cl_UP_I& y)
155 { return x.ring()->plus(x,y); }
158 inline const cl_UP_I operator- (const cl_UP_I& x)
159 { return x.ring()->uminus(x); }
162 inline const cl_UP_I operator- (const cl_UP_I& x, const cl_UP_I& y)
163 { return x.ring()->minus(x,y); }
166 inline const cl_UP_I operator* (const cl_UP_I& x, const cl_UP_I& y)
167 { return x.ring()->mul(x,y); }
170 inline const cl_UP_I square (const cl_UP_I& x)
171 { return x.ring()->square(x); }
173 // Exponentiation x^y, where y > 0.
174 inline const cl_UP_I expt_pos (const cl_UP_I& x, const cl_I& y)
175 { return x.ring()->expt_pos(x,y); }
177 // Scalar multiplication.
178 #if 0 // less efficient
179 inline const cl_UP_I operator* (const cl_I& x, const cl_UP_I& y)
180 { return y.ring()->mul(y.ring()->canonhom(x),y); }
181 inline const cl_UP_I operator* (const cl_UP_I& x, const cl_I& y)
182 { return x.ring()->mul(x.ring()->canonhom(y),x); }
184 inline const cl_UP_I operator* (const cl_I& x, const cl_UP_I& y)
185 { return y.ring()->scalmul(x,y); }
186 inline const cl_UP_I operator* (const cl_UP_I& x, const cl_I& y)
187 { return x.ring()->scalmul(y,x); }
190 inline const cl_I coeff (const cl_UP_I& x, uintL index)
191 { return x.ring()->coeff(x,index); }
193 // Destructive modification.
194 inline void set_coeff (cl_UP_I& x, uintL index, const cl_I& y)
195 { x.ring()->set_coeff(x,index,y); }
196 inline void finalize (cl_UP_I& x)
197 { x.ring()->finalize(x); }
198 inline void cl_UP_I::set_coeff (uintL index, const cl_I& y)
199 { ring()->set_coeff(*this,index,y); }
200 inline void cl_UP_I::finalize ()
201 { ring()->finalize(*this); }
203 // Evaluation. (No extension of the base ring allowed here for now.)
204 inline const cl_I cl_UP_I::operator() (const cl_I& y) const
206 return ring()->eval(*this,y);
210 inline const cl_UP_I deriv (const cl_UP_I& x)
211 { return The2(cl_UP_I)(deriv((const cl_UP&)x)); }
215 CL_REQUIRE(cl_I_ring)
218 // Returns the n-th Tchebychev polynomial (n >= 0).
219 extern const cl_UP_I cl_tschebychev (sintL n);
221 // Returns the n-th Hermite polynomial (n >= 0).
222 extern const cl_UP_I cl_hermite (sintL n);
224 // Returns the n-th Laguerre polynomial (n >= 0).
225 extern const cl_UP_I cl_laguerre (sintL n);
227 #endif /* _CL_UNIVPOLY_INTEGER_H */