]> www.ginac.de Git - cln.git/blob - include/cln/univpoly_integer.h
* include/cln/object.h (cl_combine): define additional signatures, if
[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, cl_UP_I* 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 (cl_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         const cl_UP_I monomial (const cl_I& x, uintL e)
119         {
120                 return The2(cl_UP_I)(cl_heap_univpoly_ring::monomial(cl_ring_element(cl_I_ring,x),e));
121         }
122         const cl_I coeff (const cl_UP_I& x, uintL index)
123         {
124                 return The(cl_I)(cl_heap_univpoly_ring::coeff(x,index));
125         }
126         const cl_UP_I create (sintL deg)
127         {
128                 return The2(cl_UP_I)(cl_heap_univpoly_ring::create(deg));
129         }
130         void set_coeff (cl_UP_I& x, uintL index, const cl_I& y)
131         {
132                 cl_heap_univpoly_ring::set_coeff(x,index,cl_ring_element(cl_I_ring,y));
133         }
134         void finalize (cl_UP_I& x)
135         {
136                 cl_heap_univpoly_ring::finalize(x);
137         }
138         const cl_I eval (const cl_UP_I& x, const cl_I& y)
139         {
140                 return The(cl_I)(cl_heap_univpoly_ring::eval(x,cl_ring_element(cl_I_ring,y)));
141         }
142 private:
143         // No need for any constructors.
144         cl_heap_univpoly_integer_ring ();
145 };
146
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)); }
152
153 // Operations on polynomials.
154
155 // Add.
156 inline const cl_UP_I operator+ (const cl_UP_I& x, const cl_UP_I& y)
157         { return x.ring()->plus(x,y); }
158
159 // Negate.
160 inline const cl_UP_I operator- (const cl_UP_I& x)
161         { return x.ring()->uminus(x); }
162
163 // Subtract.
164 inline const cl_UP_I operator- (const cl_UP_I& x, const cl_UP_I& y)
165         { return x.ring()->minus(x,y); }
166
167 // Multiply.
168 inline const cl_UP_I operator* (const cl_UP_I& x, const cl_UP_I& y)
169         { return x.ring()->mul(x,y); }
170
171 // Squaring.
172 inline const cl_UP_I square (const cl_UP_I& x)
173         { return x.ring()->square(x); }
174
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); }
178
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); }
185 #endif
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); }
190
191 // Coefficient.
192 inline const cl_I coeff (const cl_UP_I& x, uintL index)
193         { return x.ring()->coeff(x,index); }
194
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); }
204
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
207 {
208         return ring()->eval(*this,y);
209 }
210
211 // Derivative.
212 inline const cl_UP_I deriv (const cl_UP_I& x)
213         { return The2(cl_UP_I)(deriv((const cl_UP&)x)); }
214
215 #endif
216
217 CL_REQUIRE(cl_I_ring)
218
219
220 // Returns the n-th Tchebychev polynomial (n >= 0).
221 extern const cl_UP_I tschebychev (sintL n);
222
223 // Returns the n-th Hermite polynomial (n >= 0).
224 extern const cl_UP_I hermite (sintL n);
225
226 // Returns the n-th Laguerre polynomial (n >= 0).
227 extern const cl_UP_I laguerre (sintL n);
228
229 }  // namespace cln
230
231 #endif /* _CL_UNIVPOLY_INTEGER_H */