]> www.ginac.de Git - cln.git/blob - include/cln/univpoly_complex.h
5de6dac820637551417f0eaf6646f288a61e3bd5
[cln.git] / include / cln / univpoly_complex.h
1 // Univariate Polynomials over the complex numbers.
2
3 #ifndef _CL_UNIVPOLY_COMPLEX_H
4 #define _CL_UNIVPOLY_COMPLEX_H
5
6 #include "cln/ring.h"
7 #include "cln/univpoly.h"
8 #include "cln/number.h"
9 #include "cln/complex_class.h"
10 #include "cln/integer_class.h"
11 #include "cln/complex_ring.h"
12
13 namespace cln {
14
15 // Normal univariate polynomials with stricter static typing:
16 // `cl_N' instead of `cl_ring_element'.
17
18 #ifdef notyet
19
20 typedef cl_UP_specialized<cl_N> cl_UP_N;
21 typedef cl_univpoly_specialized_ring<cl_N> cl_univpoly_complex_ring;
22 //typedef cl_heap_univpoly_specialized_ring<cl_N> cl_heap_univpoly_complex_ring;
23
24 #else
25
26 class cl_heap_univpoly_complex_ring;
27
28 class cl_univpoly_complex_ring : public cl_univpoly_ring {
29 public:
30         // Default constructor.
31         cl_univpoly_complex_ring () : cl_univpoly_ring () {}
32         // Copy constructor.
33         cl_univpoly_complex_ring (const cl_univpoly_complex_ring&);
34         // Assignment operator.
35         cl_univpoly_complex_ring& operator= (const cl_univpoly_complex_ring&);
36         // Automatic dereferencing.
37         cl_heap_univpoly_complex_ring* operator-> () const
38         { return (cl_heap_univpoly_complex_ring*)heappointer; }
39 };
40 // Copy constructor and assignment operator.
41 CL_DEFINE_COPY_CONSTRUCTOR2(cl_univpoly_complex_ring,cl_univpoly_ring)
42 CL_DEFINE_ASSIGNMENT_OPERATOR(cl_univpoly_complex_ring,cl_univpoly_complex_ring)
43
44 class cl_UP_N : public cl_UP {
45 public:
46         const cl_univpoly_complex_ring& ring () const { return The(cl_univpoly_complex_ring)(_ring); }
47         // Conversion.
48         CL_DEFINE_CONVERTER(cl_ring_element)
49         // Destructive modification.
50         void set_coeff (uintL index, const cl_N& y);
51         void finalize();
52         // Evaluation.
53         const cl_N operator() (const cl_N& y) const;
54 public: // Ability to place an object at a given address.
55         void* operator new (size_t size) { return malloc_hook(size); }
56         void* operator new (size_t size, void* ptr) { (void)size; return ptr; }
57         void operator delete (void* ptr) { free_hook(ptr); }
58 };
59
60 class cl_heap_univpoly_complex_ring : public cl_heap_univpoly_ring {
61         SUBCLASS_cl_heap_univpoly_ring()
62         // High-level operations.
63         void fprint (std::ostream& stream, const cl_UP_N& x)
64         {
65                 cl_heap_univpoly_ring::fprint(stream,x);
66         }
67         cl_boolean equal (const cl_UP_N& x, const cl_UP_N& y)
68         {
69                 return cl_heap_univpoly_ring::equal(x,y);
70         }
71         const cl_UP_N zero ()
72         {
73                 return The2(cl_UP_N)(cl_heap_univpoly_ring::zero());
74         }
75         cl_boolean zerop (const cl_UP_N& x)
76         {
77                 return cl_heap_univpoly_ring::zerop(x);
78         }
79         const cl_UP_N plus (const cl_UP_N& x, const cl_UP_N& y)
80         {
81                 return The2(cl_UP_N)(cl_heap_univpoly_ring::plus(x,y));
82         }
83         const cl_UP_N minus (const cl_UP_N& x, const cl_UP_N& y)
84         {
85                 return The2(cl_UP_N)(cl_heap_univpoly_ring::minus(x,y));
86         }
87         const cl_UP_N uminus (const cl_UP_N& x)
88         {
89                 return The2(cl_UP_N)(cl_heap_univpoly_ring::uminus(x));
90         }
91         const cl_UP_N one ()
92         {
93                 return The2(cl_UP_N)(cl_heap_univpoly_ring::one());
94         }
95         const cl_UP_N canonhom (const cl_I& x)
96         {
97                 return The2(cl_UP_N)(cl_heap_univpoly_ring::canonhom(x));
98         }
99         const cl_UP_N mul (const cl_UP_N& x, const cl_UP_N& y)
100         {
101                 return The2(cl_UP_N)(cl_heap_univpoly_ring::mul(x,y));
102         }
103         const cl_UP_N square (const cl_UP_N& x)
104         {
105                 return The2(cl_UP_N)(cl_heap_univpoly_ring::square(x));
106         }
107         const cl_UP_N expt_pos (const cl_UP_N& x, const cl_I& y)
108         {
109                 return The2(cl_UP_N)(cl_heap_univpoly_ring::expt_pos(x,y));
110         }
111         const cl_UP_N scalmul (const cl_N& x, const cl_UP_N& y)
112         {
113                 return The2(cl_UP_N)(cl_heap_univpoly_ring::scalmul(cl_ring_element(cl_C_ring,x),y));
114         }
115         sintL degree (const cl_UP_N& x)
116         {
117                 return cl_heap_univpoly_ring::degree(x);
118         }
119         const cl_UP_N monomial (const cl_N& x, uintL e)
120         {
121                 return The2(cl_UP_N)(cl_heap_univpoly_ring::monomial(cl_ring_element(cl_C_ring,x),e));
122         }
123         const cl_N coeff (const cl_UP_N& x, uintL index)
124         {
125                 return The(cl_N)(cl_heap_univpoly_ring::coeff(x,index));
126         }
127         const cl_UP_N create (sintL deg)
128         {
129                 return The2(cl_UP_N)(cl_heap_univpoly_ring::create(deg));
130         }
131         void set_coeff (cl_UP_N& x, uintL index, const cl_N& y)
132         {
133                 cl_heap_univpoly_ring::set_coeff(x,index,cl_ring_element(cl_C_ring,y));
134         }
135         void finalize (cl_UP_N& x)
136         {
137                 cl_heap_univpoly_ring::finalize(x);
138         }
139         const cl_N eval (const cl_UP_N& x, const cl_N& y)
140         {
141                 return The(cl_N)(cl_heap_univpoly_ring::eval(x,cl_ring_element(cl_C_ring,y)));
142         }
143 private:
144         // No need for any constructors.
145         cl_heap_univpoly_complex_ring ();
146 };
147
148 // Lookup of polynomial rings.
149 inline const cl_univpoly_complex_ring find_univpoly_ring (const cl_complex_ring& r)
150 { return The(cl_univpoly_complex_ring) (find_univpoly_ring((const cl_ring&)r)); }
151 inline const cl_univpoly_complex_ring find_univpoly_ring (const cl_complex_ring& r, const cl_symbol& varname)
152 { return The(cl_univpoly_complex_ring) (find_univpoly_ring((const cl_ring&)r,varname)); }
153
154 // Operations on polynomials.
155
156 // Add.
157 inline const cl_UP_N operator+ (const cl_UP_N& x, const cl_UP_N& y)
158         { return x.ring()->plus(x,y); }
159
160 // Negate.
161 inline const cl_UP_N operator- (const cl_UP_N& x)
162         { return x.ring()->uminus(x); }
163
164 // Subtract.
165 inline const cl_UP_N operator- (const cl_UP_N& x, const cl_UP_N& y)
166         { return x.ring()->minus(x,y); }
167
168 // Multiply.
169 inline const cl_UP_N operator* (const cl_UP_N& x, const cl_UP_N& y)
170         { return x.ring()->mul(x,y); }
171
172 // Squaring.
173 inline const cl_UP_N square (const cl_UP_N& x)
174         { return x.ring()->square(x); }
175
176 // Exponentiation x^y, where y > 0.
177 inline const cl_UP_N expt_pos (const cl_UP_N& x, const cl_I& y)
178         { return x.ring()->expt_pos(x,y); }
179
180 // Scalar multiplication.
181 #if 0 // less efficient
182 inline const cl_UP_N operator* (const cl_I& x, const cl_UP_N& y)
183         { return y.ring()->mul(y.ring()->canonhom(x),y); }
184 inline const cl_UP_N operator* (const cl_UP_N& x, const cl_I& y)
185         { return x.ring()->mul(x.ring()->canonhom(y),x); }
186 #endif
187 inline const cl_UP_N operator* (const cl_I& x, const cl_UP_N& y)
188         { return y.ring()->scalmul(x,y); }
189 inline const cl_UP_N operator* (const cl_UP_N& x, const cl_I& y)
190         { return x.ring()->scalmul(y,x); }
191 inline const cl_UP_N operator* (const cl_N& x, const cl_UP_N& y)
192         { return y.ring()->scalmul(x,y); }
193 inline const cl_UP_N operator* (const cl_UP_N& x, const cl_N& y)
194         { return x.ring()->scalmul(y,x); }
195
196 // Coefficient.
197 inline const cl_N coeff (const cl_UP_N& x, uintL index)
198         { return x.ring()->coeff(x,index); }
199
200 // Destructive modification.
201 inline void set_coeff (cl_UP_N& x, uintL index, const cl_N& y)
202         { x.ring()->set_coeff(x,index,y); }
203 inline void finalize (cl_UP_N& x)
204         { x.ring()->finalize(x); }
205 inline void cl_UP_N::set_coeff (uintL index, const cl_N& y)
206         { ring()->set_coeff(*this,index,y); }
207 inline void cl_UP_N::finalize ()
208         { ring()->finalize(*this); }
209
210 // Evaluation. (No extension of the base ring allowed here for now.)
211 inline const cl_N cl_UP_N::operator() (const cl_N& y) const
212 {
213         return ring()->eval(*this,y);
214 }
215
216 // Derivative.
217 inline const cl_UP_N deriv (const cl_UP_N& x)
218         { return The2(cl_UP_N)(deriv((const cl_UP&)x)); }
219
220 #endif
221
222 CL_REQUIRE(cl_C_ring)
223
224 }  // namespace cln
225
226 #endif /* _CL_UNIVPOLY_COMPLEX_H */