]> www.ginac.de Git - cln.git/blob - include/cln/univpoly_integer.h
Update comment.
[cln.git] / include / cln / univpoly_integer.h
1 // Univariate Polynomials over the integer numbers.
2
3 #ifndef _CL_UNIVPOLY_INTEGER_H
4 #define _CL_UNIVPOLY_INTEGER_H
5
6 #include "cln/ring.h"
7 #include "cln/univpoly.h"
8 #include "cln/number.h"
9 #include "cln/integer_class.h"
10 #include "cln/integer_ring.h"
11
12 namespace cln {
13
14 // Normal univariate polynomials with stricter static typing:
15 // `cl_I' instead of `cl_ring_element'.
16
17 #ifdef notyet
18
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;
22
23 #else
24
25 class cl_heap_univpoly_integer_ring;
26
27 class cl_univpoly_integer_ring : public cl_univpoly_ring {
28 public:
29         // Default constructor.
30         cl_univpoly_integer_ring () : cl_univpoly_ring () {}
31         // Copy constructor.
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; }
38 };
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)
42
43 class cl_UP_I : public cl_UP {
44 public:
45         const cl_univpoly_integer_ring& ring () const { return The(cl_univpoly_integer_ring)(_ring); }
46         // Conversion.
47         CL_DEFINE_CONVERTER(cl_ring_element)
48         // Destructive modification.
49         void set_coeff (uintL index, const cl_I& y);
50         void finalize();
51         // Evaluation.
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); }
57 };
58
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)
63         {
64                 cl_heap_univpoly_ring::fprint(stream,x);
65         }
66         cl_boolean equal (const cl_UP_I& x, const cl_UP_I& y)
67         {
68                 return cl_heap_univpoly_ring::equal(x,y);
69         }
70         const cl_UP_I zero ()
71         {
72                 return The2(cl_UP_I)(cl_heap_univpoly_ring::zero());
73         }
74         cl_boolean zerop (const cl_UP_I& x)
75         {
76                 return cl_heap_univpoly_ring::zerop(x);
77         }
78         const cl_UP_I plus (const cl_UP_I& x, const cl_UP_I& y)
79         {
80                 return The2(cl_UP_I)(cl_heap_univpoly_ring::plus(x,y));
81         }
82         const cl_UP_I minus (const cl_UP_I& x, const cl_UP_I& y)
83         {
84                 return The2(cl_UP_I)(cl_heap_univpoly_ring::minus(x,y));
85         }
86         const cl_UP_I uminus (const cl_UP_I& x)
87         {
88                 return The2(cl_UP_I)(cl_heap_univpoly_ring::uminus(x));
89         }
90         const cl_UP_I one ()
91         {
92                 return The2(cl_UP_I)(cl_heap_univpoly_ring::one());
93         }
94         const cl_UP_I canonhom (const cl_I& x)
95         {
96                 return The2(cl_UP_I)(cl_heap_univpoly_ring::canonhom(x));
97         }
98         const cl_UP_I mul (const cl_UP_I& x, const cl_UP_I& y)
99         {
100                 return The2(cl_UP_I)(cl_heap_univpoly_ring::mul(x,y));
101         }
102         const cl_UP_I square (const cl_UP_I& x)
103         {
104                 return The2(cl_UP_I)(cl_heap_univpoly_ring::square(x));
105         }
106         const cl_UP_I expt_pos (const cl_UP_I& x, const cl_I& y)
107         {
108                 return The2(cl_UP_I)(cl_heap_univpoly_ring::expt_pos(x,y));
109         }
110         const cl_UP_I scalmul (const cl_I& x, const cl_UP_I& y)
111         {
112                 return The2(cl_UP_I)(cl_heap_univpoly_ring::scalmul(cl_ring_element(cl_I_ring,x),y));
113         }
114         sintL degree (const cl_UP_I& x)
115         {
116                 return cl_heap_univpoly_ring::degree(x);
117         }
118         sintL ldegree (const cl_UP_I& x)
119         {
120                 return cl_heap_univpoly_ring::ldegree(x);
121         }
122         const cl_UP_I monomial (const cl_I& x, uintL e)
123         {
124                 return The2(cl_UP_I)(cl_heap_univpoly_ring::monomial(cl_ring_element(cl_I_ring,x),e));
125         }
126         const cl_I coeff (const cl_UP_I& x, uintL index)
127         {
128                 return The(cl_I)(cl_heap_univpoly_ring::coeff(x,index));
129         }
130         const cl_UP_I create (sintL deg)
131         {
132                 return The2(cl_UP_I)(cl_heap_univpoly_ring::create(deg));
133         }
134         void set_coeff (cl_UP_I& x, uintL index, const cl_I& y)
135         {
136                 cl_heap_univpoly_ring::set_coeff(x,index,cl_ring_element(cl_I_ring,y));
137         }
138         void finalize (cl_UP_I& x)
139         {
140                 cl_heap_univpoly_ring::finalize(x);
141         }
142         const cl_I eval (const cl_UP_I& x, const cl_I& y)
143         {
144                 return The(cl_I)(cl_heap_univpoly_ring::eval(x,cl_ring_element(cl_I_ring,y)));
145         }
146 private:
147         // No need for any constructors.
148         cl_heap_univpoly_integer_ring ();
149 };
150
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)); }
156
157 // Operations on polynomials.
158
159 // Add.
160 inline const cl_UP_I operator+ (const cl_UP_I& x, const cl_UP_I& y)
161         { return x.ring()->plus(x,y); }
162
163 // Negate.
164 inline const cl_UP_I operator- (const cl_UP_I& x)
165         { return x.ring()->uminus(x); }
166
167 // Subtract.
168 inline const cl_UP_I operator- (const cl_UP_I& x, const cl_UP_I& y)
169         { return x.ring()->minus(x,y); }
170
171 // Multiply.
172 inline const cl_UP_I operator* (const cl_UP_I& x, const cl_UP_I& y)
173         { return x.ring()->mul(x,y); }
174
175 // Squaring.
176 inline const cl_UP_I square (const cl_UP_I& x)
177         { return x.ring()->square(x); }
178
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); }
182
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); }
189 #endif
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); }
194
195 // Coefficient.
196 inline const cl_I coeff (const cl_UP_I& x, uintL index)
197         { return x.ring()->coeff(x,index); }
198
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); }
208
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
211 {
212         return ring()->eval(*this,y);
213 }
214
215 // Derivative.
216 inline const cl_UP_I deriv (const cl_UP_I& x)
217         { return The2(cl_UP_I)(deriv((const cl_UP&)x)); }
218
219 #endif
220
221 CL_REQUIRE(cl_I_ring)
222
223
224 // Returns the n-th Tchebychev polynomial (n >= 0).
225 extern const cl_UP_I tschebychev (sintL n);
226
227 // Returns the n-th Hermite polynomial (n >= 0).
228 extern const cl_UP_I hermite (sintL n);
229
230 // Returns the n-th Laguerre polynomial (n >= 0).
231 extern const cl_UP_I laguerre (sintL n);
232
233 }  // namespace cln
234
235 #endif /* _CL_UNIVPOLY_INTEGER_H */