1 // Univariate Polynomials over the integer numbers.
3 #ifndef _CL_UNIVPOLY_INTEGER_H
4 #define _CL_UNIVPOLY_INTEGER_H
7 #include "cln/univpoly.h"
8 #include "cln/number.h"
9 #include "cln/integer_class.h"
10 #include "cln/integer_ring.h"
14 // Normal univariate polynomials with stricter static typing:
15 // `cl_I' instead of `cl_ring_element'.
19 typedef cl_UP_specialized<cl_I> cl_UP_I;
20 typedef cl_univpoly_specialized_ring<cl_I> cl_univpoly_integer_ring;
21 //typedef cl_heap_univpoly_specialized_ring<cl_I> cl_heap_univpoly_integer_ring;
25 class cl_heap_univpoly_integer_ring;
27 class cl_univpoly_integer_ring : public cl_univpoly_ring {
29 // Default constructor.
30 cl_univpoly_integer_ring () : cl_univpoly_ring () {}
32 cl_univpoly_integer_ring (const cl_univpoly_integer_ring&);
33 // Assignment operator.
34 cl_univpoly_integer_ring& operator= (const cl_univpoly_integer_ring&);
35 // Automatic dereferencing.
36 cl_heap_univpoly_integer_ring* operator-> () const
37 { return (cl_heap_univpoly_integer_ring*)heappointer; }
39 // Copy constructor and assignment operator.
40 CL_DEFINE_COPY_CONSTRUCTOR2(cl_univpoly_integer_ring,cl_univpoly_ring)
41 CL_DEFINE_ASSIGNMENT_OPERATOR(cl_univpoly_integer_ring,cl_univpoly_integer_ring)
43 class cl_UP_I : public cl_UP {
45 const cl_univpoly_integer_ring& ring () const { return The(cl_univpoly_integer_ring)(_ring); }
47 CL_DEFINE_CONVERTER(cl_ring_element)
48 // Destructive modification.
49 void set_coeff (uintL index, const cl_I& y);
52 const cl_I operator() (const cl_I& y) const;
53 public: // Ability to place an object at a given address.
54 void* operator new (size_t size) { return malloc_hook(size); }
55 void* operator new (size_t size, cl_UP_I* ptr) { (void)size; return ptr; }
56 void operator delete (void* ptr) { free_hook(ptr); }
59 class cl_heap_univpoly_integer_ring : public cl_heap_univpoly_ring {
60 SUBCLASS_cl_heap_univpoly_ring()
61 // High-level operations.
62 void fprint (std::ostream& stream, const cl_UP_I& x)
64 cl_heap_univpoly_ring::fprint(stream,x);
66 cl_boolean equal (const cl_UP_I& x, const cl_UP_I& y)
68 return cl_heap_univpoly_ring::equal(x,y);
72 return The2(cl_UP_I)(cl_heap_univpoly_ring::zero());
74 cl_boolean zerop (const cl_UP_I& x)
76 return cl_heap_univpoly_ring::zerop(x);
78 const cl_UP_I plus (const cl_UP_I& x, const cl_UP_I& y)
80 return The2(cl_UP_I)(cl_heap_univpoly_ring::plus(x,y));
82 const cl_UP_I minus (const cl_UP_I& x, const cl_UP_I& y)
84 return The2(cl_UP_I)(cl_heap_univpoly_ring::minus(x,y));
86 const cl_UP_I uminus (const cl_UP_I& x)
88 return The2(cl_UP_I)(cl_heap_univpoly_ring::uminus(x));
92 return The2(cl_UP_I)(cl_heap_univpoly_ring::one());
94 const cl_UP_I canonhom (const cl_I& x)
96 return The2(cl_UP_I)(cl_heap_univpoly_ring::canonhom(x));
98 const cl_UP_I mul (const cl_UP_I& x, const cl_UP_I& y)
100 return The2(cl_UP_I)(cl_heap_univpoly_ring::mul(x,y));
102 const cl_UP_I square (const cl_UP_I& x)
104 return The2(cl_UP_I)(cl_heap_univpoly_ring::square(x));
106 const cl_UP_I expt_pos (const cl_UP_I& x, const cl_I& y)
108 return The2(cl_UP_I)(cl_heap_univpoly_ring::expt_pos(x,y));
110 const cl_UP_I scalmul (const cl_I& x, const cl_UP_I& y)
112 return The2(cl_UP_I)(cl_heap_univpoly_ring::scalmul(cl_ring_element(cl_I_ring,x),y));
114 sintL degree (const cl_UP_I& x)
116 return cl_heap_univpoly_ring::degree(x);
118 const cl_UP_I monomial (const cl_I& x, uintL e)
120 return The2(cl_UP_I)(cl_heap_univpoly_ring::monomial(cl_ring_element(cl_I_ring,x),e));
122 const cl_I coeff (const cl_UP_I& x, uintL index)
124 return The(cl_I)(cl_heap_univpoly_ring::coeff(x,index));
126 const cl_UP_I create (sintL deg)
128 return The2(cl_UP_I)(cl_heap_univpoly_ring::create(deg));
130 void set_coeff (cl_UP_I& x, uintL index, const cl_I& y)
132 cl_heap_univpoly_ring::set_coeff(x,index,cl_ring_element(cl_I_ring,y));
134 void finalize (cl_UP_I& x)
136 cl_heap_univpoly_ring::finalize(x);
138 const cl_I eval (const cl_UP_I& x, const cl_I& y)
140 return The(cl_I)(cl_heap_univpoly_ring::eval(x,cl_ring_element(cl_I_ring,y)));
143 // No need for any constructors.
144 cl_heap_univpoly_integer_ring ();
147 // Lookup of polynomial rings.
148 inline const cl_univpoly_integer_ring find_univpoly_ring (const cl_integer_ring& r)
149 { return The(cl_univpoly_integer_ring) (find_univpoly_ring((const cl_ring&)r)); }
150 inline const cl_univpoly_integer_ring find_univpoly_ring (const cl_integer_ring& r, const cl_symbol& varname)
151 { return The(cl_univpoly_integer_ring) (find_univpoly_ring((const cl_ring&)r,varname)); }
153 // Operations on polynomials.
156 inline const cl_UP_I operator+ (const cl_UP_I& x, const cl_UP_I& y)
157 { return x.ring()->plus(x,y); }
160 inline const cl_UP_I operator- (const cl_UP_I& x)
161 { return x.ring()->uminus(x); }
164 inline const cl_UP_I operator- (const cl_UP_I& x, const cl_UP_I& y)
165 { return x.ring()->minus(x,y); }
168 inline const cl_UP_I operator* (const cl_UP_I& x, const cl_UP_I& y)
169 { return x.ring()->mul(x,y); }
172 inline const cl_UP_I square (const cl_UP_I& x)
173 { return x.ring()->square(x); }
175 // Exponentiation x^y, where y > 0.
176 inline const cl_UP_I expt_pos (const cl_UP_I& x, const cl_I& y)
177 { return x.ring()->expt_pos(x,y); }
179 // Scalar multiplication.
180 #if 0 // less efficient
181 inline const cl_UP_I operator* (const cl_I& x, const cl_UP_I& y)
182 { return y.ring()->mul(y.ring()->canonhom(x),y); }
183 inline const cl_UP_I operator* (const cl_UP_I& x, const cl_I& y)
184 { return x.ring()->mul(x.ring()->canonhom(y),x); }
186 inline const cl_UP_I operator* (const cl_I& x, const cl_UP_I& y)
187 { return y.ring()->scalmul(x,y); }
188 inline const cl_UP_I operator* (const cl_UP_I& x, const cl_I& y)
189 { return x.ring()->scalmul(y,x); }
192 inline const cl_I coeff (const cl_UP_I& x, uintL index)
193 { return x.ring()->coeff(x,index); }
195 // Destructive modification.
196 inline void set_coeff (cl_UP_I& x, uintL index, const cl_I& y)
197 { x.ring()->set_coeff(x,index,y); }
198 inline void finalize (cl_UP_I& x)
199 { x.ring()->finalize(x); }
200 inline void cl_UP_I::set_coeff (uintL index, const cl_I& y)
201 { ring()->set_coeff(*this,index,y); }
202 inline void cl_UP_I::finalize ()
203 { ring()->finalize(*this); }
205 // Evaluation. (No extension of the base ring allowed here for now.)
206 inline const cl_I cl_UP_I::operator() (const cl_I& y) const
208 return ring()->eval(*this,y);
212 inline const cl_UP_I deriv (const cl_UP_I& x)
213 { return The2(cl_UP_I)(deriv((const cl_UP&)x)); }
217 CL_REQUIRE(cl_I_ring)
220 // Returns the n-th Tchebychev polynomial (n >= 0).
221 extern const cl_UP_I tschebychev (sintL n);
223 // Returns the n-th Hermite polynomial (n >= 0).
224 extern const cl_UP_I hermite (sintL n);
226 // Returns the n-th Laguerre polynomial (n >= 0).
227 extern const cl_UP_I laguerre (sintL n);
231 #endif /* _CL_UNIVPOLY_INTEGER_H */