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, void* 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 bool 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 bool 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 sintL ldegree (const cl_UP_I& x)
120 return cl_heap_univpoly_ring::ldegree(x);
122 const cl_UP_I monomial (const cl_I& x, uintL e)
124 return The2(cl_UP_I)(cl_heap_univpoly_ring::monomial(cl_ring_element(cl_I_ring,x),e));
126 const cl_I coeff (const cl_UP_I& x, uintL index)
128 return The(cl_I)(cl_heap_univpoly_ring::coeff(x,index));
130 const cl_UP_I create (sintL deg)
132 return The2(cl_UP_I)(cl_heap_univpoly_ring::create(deg));
134 void set_coeff (cl_UP_I& x, uintL index, const cl_I& y)
136 cl_heap_univpoly_ring::set_coeff(x,index,cl_ring_element(cl_I_ring,y));
138 void finalize (cl_UP_I& x)
140 cl_heap_univpoly_ring::finalize(x);
142 const cl_I eval (const cl_UP_I& x, const cl_I& y)
144 return The(cl_I)(cl_heap_univpoly_ring::eval(x,cl_ring_element(cl_I_ring,y)));
147 // No need for any constructors.
148 cl_heap_univpoly_integer_ring ();
151 // Lookup of polynomial rings.
152 inline const cl_univpoly_integer_ring find_univpoly_ring (const cl_integer_ring& r)
153 { return The(cl_univpoly_integer_ring) (find_univpoly_ring((const cl_ring&)r)); }
154 inline const cl_univpoly_integer_ring find_univpoly_ring (const cl_integer_ring& r, const cl_symbol& varname)
155 { return The(cl_univpoly_integer_ring) (find_univpoly_ring((const cl_ring&)r,varname)); }
157 // Operations on polynomials.
160 inline const cl_UP_I operator+ (const cl_UP_I& x, const cl_UP_I& y)
161 { return x.ring()->plus(x,y); }
164 inline const cl_UP_I operator- (const cl_UP_I& x)
165 { return x.ring()->uminus(x); }
168 inline const cl_UP_I operator- (const cl_UP_I& x, const cl_UP_I& y)
169 { return x.ring()->minus(x,y); }
172 inline const cl_UP_I operator* (const cl_UP_I& x, const cl_UP_I& y)
173 { return x.ring()->mul(x,y); }
176 inline const cl_UP_I square (const cl_UP_I& x)
177 { return x.ring()->square(x); }
179 // Exponentiation x^y, where y > 0.
180 inline const cl_UP_I expt_pos (const cl_UP_I& x, const cl_I& y)
181 { return x.ring()->expt_pos(x,y); }
183 // Scalar multiplication.
184 #if 0 // less efficient
185 inline const cl_UP_I operator* (const cl_I& x, const cl_UP_I& y)
186 { return y.ring()->mul(y.ring()->canonhom(x),y); }
187 inline const cl_UP_I operator* (const cl_UP_I& x, const cl_I& y)
188 { return x.ring()->mul(x.ring()->canonhom(y),x); }
190 inline const cl_UP_I operator* (const cl_I& x, const cl_UP_I& y)
191 { return y.ring()->scalmul(x,y); }
192 inline const cl_UP_I operator* (const cl_UP_I& x, const cl_I& y)
193 { return x.ring()->scalmul(y,x); }
196 inline const cl_I coeff (const cl_UP_I& x, uintL index)
197 { return x.ring()->coeff(x,index); }
199 // Destructive modification.
200 inline void set_coeff (cl_UP_I& x, uintL index, const cl_I& y)
201 { x.ring()->set_coeff(x,index,y); }
202 inline void finalize (cl_UP_I& x)
203 { x.ring()->finalize(x); }
204 inline void cl_UP_I::set_coeff (uintL index, const cl_I& y)
205 { ring()->set_coeff(*this,index,y); }
206 inline void cl_UP_I::finalize ()
207 { ring()->finalize(*this); }
209 // Evaluation. (No extension of the base ring allowed here for now.)
210 inline const cl_I cl_UP_I::operator() (const cl_I& y) const
212 return ring()->eval(*this,y);
216 inline const cl_UP_I deriv (const cl_UP_I& x)
217 { return The2(cl_UP_I)(deriv((const cl_UP&)x)); }
222 // Returns the n-th Tchebychev polynomial (n >= 0).
223 extern const cl_UP_I tschebychev (sintL n);
225 // Returns the n-th Hermite polynomial (n >= 0).
226 extern const cl_UP_I hermite (sintL n);
228 // Returns the n-th Laguerre polynomial (n >= 0).
229 extern const cl_UP_I laguerre (sintL n);
233 #endif /* _CL_UNIVPOLY_INTEGER_H */