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