]> www.ginac.de Git - cln.git/blob - include/cl_univpoly_integer.h
Make @exec_prefix@ usable in shell scripts.
[cln.git] / include / cl_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 "cl_ring.h"
7 #include "cl_univpoly.h"
8 #include "cl_number.h"
9 #include "cl_integer_class.h"
10 #include "cl_integer_ring.h"
11
12 // Normal univariate polynomials with stricter static typing:
13 // `cl_I' instead of `cl_ring_element'.
14
15 #ifdef notyet
16
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;
20
21 #else
22
23 class cl_heap_univpoly_integer_ring;
24
25 class cl_univpoly_integer_ring : public cl_univpoly_ring {
26 public:
27         // Default constructor.
28         cl_univpoly_integer_ring () : cl_univpoly_ring () {}
29         // Copy constructor.
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; }
36 };
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)
40
41 class cl_UP_I : public cl_UP {
42 public:
43         const cl_univpoly_integer_ring& ring () const { return The(cl_univpoly_integer_ring)(_ring); }
44         // Conversion.
45         CL_DEFINE_CONVERTER(cl_ring_element)
46         // Destructive modification.
47         void set_coeff (uintL index, const cl_I& y);
48         void finalize();
49         // Evaluation.
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); }
55 };
56
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)
61         {
62                 cl_heap_univpoly_ring::fprint(stream,x);
63         }
64         cl_boolean equal (const cl_UP_I& x, const cl_UP_I& y)
65         {
66                 return cl_heap_univpoly_ring::equal(x,y);
67         }
68         const cl_UP_I zero ()
69         {
70                 return The2(cl_UP_I)(cl_heap_univpoly_ring::zero());
71         }
72         cl_boolean zerop (const cl_UP_I& x)
73         {
74                 return cl_heap_univpoly_ring::zerop(x);
75         }
76         const cl_UP_I plus (const cl_UP_I& x, const cl_UP_I& y)
77         {
78                 return The2(cl_UP_I)(cl_heap_univpoly_ring::plus(x,y));
79         }
80         const cl_UP_I minus (const cl_UP_I& x, const cl_UP_I& y)
81         {
82                 return The2(cl_UP_I)(cl_heap_univpoly_ring::minus(x,y));
83         }
84         const cl_UP_I uminus (const cl_UP_I& x)
85         {
86                 return The2(cl_UP_I)(cl_heap_univpoly_ring::uminus(x));
87         }
88         const cl_UP_I one ()
89         {
90                 return The2(cl_UP_I)(cl_heap_univpoly_ring::one());
91         }
92         const cl_UP_I canonhom (const cl_I& x)
93         {
94                 return The2(cl_UP_I)(cl_heap_univpoly_ring::canonhom(x));
95         }
96         const cl_UP_I mul (const cl_UP_I& x, const cl_UP_I& y)
97         {
98                 return The2(cl_UP_I)(cl_heap_univpoly_ring::mul(x,y));
99         }
100         const cl_UP_I square (const cl_UP_I& x)
101         {
102                 return The2(cl_UP_I)(cl_heap_univpoly_ring::square(x));
103         }
104         const cl_UP_I expt_pos (const cl_UP_I& x, const cl_I& y)
105         {
106                 return The2(cl_UP_I)(cl_heap_univpoly_ring::expt_pos(x,y));
107         }
108         const cl_UP_I scalmul (const cl_I& x, const cl_UP_I& y)
109         {
110                 return The2(cl_UP_I)(cl_heap_univpoly_ring::scalmul(cl_ring_element(cl_I_ring,x),y));
111         }
112         sintL degree (const cl_UP_I& x)
113         {
114                 return cl_heap_univpoly_ring::degree(x);
115         }
116         const cl_UP_I monomial (const cl_I& x, uintL e)
117         {
118                 return The2(cl_UP_I)(cl_heap_univpoly_ring::monomial(cl_ring_element(cl_I_ring,x),e));
119         }
120         const cl_I coeff (const cl_UP_I& x, uintL index)
121         {
122                 return The(cl_I)(cl_heap_univpoly_ring::coeff(x,index));
123         }
124         const cl_UP_I create (sintL deg)
125         {
126                 return The2(cl_UP_I)(cl_heap_univpoly_ring::create(deg));
127         }
128         void set_coeff (cl_UP_I& x, uintL index, const cl_I& y)
129         {
130                 cl_heap_univpoly_ring::set_coeff(x,index,cl_ring_element(cl_I_ring,y));
131         }
132         void finalize (cl_UP_I& x)
133         {
134                 cl_heap_univpoly_ring::finalize(x);
135         }
136         const cl_I eval (const cl_UP_I& x, const cl_I& y)
137         {
138                 return The(cl_I)(cl_heap_univpoly_ring::eval(x,cl_ring_element(cl_I_ring,y)));
139         }
140 private:
141         // No need for any constructors.
142         cl_heap_univpoly_integer_ring ();
143 };
144
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)); }
150
151 // Operations on polynomials.
152
153 // Add.
154 inline const cl_UP_I operator+ (const cl_UP_I& x, const cl_UP_I& y)
155         { return x.ring()->plus(x,y); }
156
157 // Negate.
158 inline const cl_UP_I operator- (const cl_UP_I& x)
159         { return x.ring()->uminus(x); }
160
161 // Subtract.
162 inline const cl_UP_I operator- (const cl_UP_I& x, const cl_UP_I& y)
163         { return x.ring()->minus(x,y); }
164
165 // Multiply.
166 inline const cl_UP_I operator* (const cl_UP_I& x, const cl_UP_I& y)
167         { return x.ring()->mul(x,y); }
168
169 // Squaring.
170 inline const cl_UP_I square (const cl_UP_I& x)
171         { return x.ring()->square(x); }
172
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); }
176
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); }
183 #endif
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); }
188
189 // Coefficient.
190 inline const cl_I coeff (const cl_UP_I& x, uintL index)
191         { return x.ring()->coeff(x,index); }
192
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); }
202
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
205 {
206         return ring()->eval(*this,y);
207 }
208
209 // Derivative.
210 inline const cl_UP_I deriv (const cl_UP_I& x)
211         { return The2(cl_UP_I)(deriv((const cl_UP&)x)); }
212
213 #endif
214
215 CL_REQUIRE(cl_I_ring)
216
217
218 // Returns the n-th Tchebychev polynomial (n >= 0).
219 extern const cl_UP_I cl_tschebychev (sintL n);
220
221 // Returns the n-th Hermite polynomial (n >= 0).
222 extern const cl_UP_I cl_hermite (sintL n);
223
224 // Returns the n-th Laguerre polynomial (n >= 0).
225 extern const cl_UP_I cl_laguerre (sintL n);
226
227 #endif /* _CL_UNIVPOLY_INTEGER_H */