MPSolve  3.2.1
polynomial.h
1 /*
2  * This file is part of MPSolve 3.2.1
3  *
4  * Copyright (C) 2001-2020, Dipartimento di Matematica "L. Tonelli", Pisa.
5  * License: http://www.gnu.org/licenses/gpl.html GPL version 3 or higher
6  *
7  * Authors:
8  * Dario Andrea Bini <bini@dm.unipi.it>
9  * Giuseppe Fiorentino <fiorent@dm.unipi.it>
10  * Leonardo Robol <leonardo.robol@unipi.it>
11  */
12 
13 #ifndef MPS_POLYNOMIAL_H_
14 #define MPS_POLYNOMIAL_H_
15 
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #include <mps/mps.h>
22 
23 /* Macro that can be used to enforce a sort of type-safe casting between
24  * mps_polynomial "subclasses". Please note that this does not guarantee
25  * type-safeness at all if you cast other types. */
26 #define MPS_POLYNOMIAL_CAST(typename, t) ((typename*)(mps_polynomial_cast (# typename, (mps_polynomial*)t)))
27 
28 /* Macro to ease casting of polynomials subclasses */
29 #define MPS_POLYNOMIAL(t) (MPS_POLYNOMIAL_CAST (mps_polynomial, t))
30 
31 /* A polynomial is completely determined by the functions that allow to operate on it.
32  * The types of these functions is defined in the following. */
33 
37 typedef mps_boolean (*mps_polynomial_feval_t)(mps_context * ctx, mps_polynomial * p, cplx_t x, cplx_t value, double * error);
38 
42 typedef mps_boolean (*mps_polynomial_deval_t)(mps_context * ctx, mps_polynomial * p, cdpe_t x, cdpe_t value, rdpe_t error);
43 
48 typedef mps_boolean (*mps_polynomial_meval_t)(mps_context * ctx, mps_polynomial * p, mpc_t x, mpc_t value, rdpe_t error);
49 
53 typedef void (*mps_polynomial_free_t)(mps_context * ctx, mps_polynomial *p);
54 
59 typedef long int (*mps_polynomial_raise_data_t)(mps_context * ctx, mps_polynomial * p, long int wp);
60 
66 typedef void (*mps_polynomial_fstart_t)(mps_context * ctx, mps_polynomial * p, mps_approximation ** approximations);
67 
73 typedef void (*mps_polynomial_dstart_t)(mps_context * ctx, mps_polynomial * p, mps_approximation ** approximations);
74 
80 typedef void (*mps_polynomial_mstart_t)(mps_context * ctx, mps_polynomial * p, mps_approximation ** approximations);
81 
85 typedef void (*mps_polynomial_fnewton_t)(mps_context * ctx, mps_polynomial * p,
86  mps_approximation * root, cplx_t x);
90 typedef void (*mps_polynomial_dnewton_t)(mps_context * ctx, mps_polynomial * p,
91  mps_approximation * root, cdpe_t corr);
92 
96 typedef void (*mps_polynomial_mnewton_t)(mps_context * ctx, mps_polynomial * p,
97  mps_approximation * root, mpc_t corr, long int wp);
98 
104 typedef void (*mps_polynomial_get_leading_coefficient_t)(mps_context * ctx, mps_polynomial * p, mpc_t lc);
105 
117  const char * type_name;
118 
122  int degree;
123 
130  long int prec;
131 
137  mps_structure structure;
138 
144  mps_density density;
145 
151  mps_boolean thread_safe;
152 
156  mps_polynomial_feval_t feval;
157 
161  mps_polynomial_deval_t deval;
162 
166  mps_polynomial_meval_t meval;
167 
171  mps_polynomial_fstart_t fstart;
172 
176  mps_polynomial_dstart_t dstart;
177 
181  mps_polynomial_mstart_t mstart;
182 
186  mps_polynomial_free_t free;
187 
192  mps_polynomial_raise_data_t raise_data;
193 
197  mps_polynomial_fnewton_t fnewton;
198 
202  mps_polynomial_dnewton_t dnewton;
203 
207  mps_polynomial_mnewton_t mnewton;
208 
213  mps_polynomial_get_leading_coefficient_t get_leading_coefficient;
214 };
215 
216 void mps_polynomial_init (mps_context * ctx, mps_polynomial * p);
217 
218 mps_polynomial * mps_polynomial_new (mps_context * ctx);
219 
220 mps_boolean mps_polynomial_check_type (mps_polynomial * p, const char * type_name);
221 
222 mps_polynomial * mps_polynomial_cast (const char *type_name, mps_polynomial *p);
223 
224 mps_boolean mps_polynomial_feval (mps_context * ctx, mps_polynomial * p, cplx_t x, cplx_t value, double * error);
225 
226 mps_boolean mps_polynomial_deval (mps_context * ctx, mps_polynomial * p, cdpe_t x, cdpe_t value, rdpe_t error);
227 
228 mps_boolean mps_polynomial_meval (mps_context * ctx, mps_polynomial * p, mpc_t x, mpc_t value, rdpe_t error);
229 
230 void mps_polynomial_fstart (mps_context * ctx, mps_polynomial * p, mps_approximation ** approximations);
231 
232 void mps_polynomial_dstart (mps_context * ctx, mps_polynomial * p, mps_approximation ** approximations);
233 
234 void mps_polynomial_mstart (mps_context * ctx, mps_polynomial * p, mps_approximation ** approximations);
235 
236 void mps_polynomial_free (mps_context * ctx, mps_polynomial * p);
237 
238 void mps_polynomial_fnewton (mps_context * ctx, mps_polynomial *p,
239  mps_approximation * root, cplx_t corr);
240 
241 void mps_polynomial_dnewton (mps_context * ctx, mps_polynomial *p,
242  mps_approximation * root, cdpe_t corr);
243 
244 void mps_polynomial_mnewton (mps_context * ctx, mps_polynomial *p,
245  mps_approximation * root, mpc_t corr, long int wp);
246 
247 void mps_polynomial_get_leading_coefficient (mps_context * ctx, mps_polynomial * p, mpc_t lc);
248 
249 long int mps_polynomial_raise_data (mps_context * ctx, mps_polynomial * p, long int wp);
250 
251 void mps_polynomial_set_input_prec (mps_context * ctx, mps_polynomial * p, long int prec);
252 
253 /* functions in general-starting.c */
254 void mps_general_fstart (mps_context * ctx, mps_polynomial * p, mps_approximation ** approximations);
255 void mps_general_dstart (mps_context * ctx, mps_polynomial * p, mps_approximation ** approximations);
256 void mps_general_mstart (mps_context * ctx, mps_polynomial * p, mps_approximation ** approximations);
257 
258 #ifdef _MPS_PRIVATE
259 /* Private implementation details */
260 #endif
261 
262 #ifdef __cplusplus
263 }
264 #endif
265 
266 
267 /*
268  * C++ wrapper around mps_polynomial.
269  */
270 
271 #ifdef __cplusplus
272 
273 namespace mps {
274  class Polynomial : public mps_polynomial {
275 public:
281  explicit Polynomial (mps_context * ctx, const char * type_name = "mps_polynomial");
282 
286  static Polynomial * fromString (mps_context * ctx, const char * inputString);
287 
288  virtual ~Polynomial ();
289 
293  int get_degree ()
294  {
295  return degree;
296  }
297 
311  virtual bool eval (mps_context * ctx, cplx_t x, cplx_t value, double * error) = 0;
312 
326  virtual bool eval (mps_context * ctx, cdpe_t x, cdpe_t value, rdpe_t error) = 0;
327 
341  virtual bool eval (mps_context * ctx, mpc_t x, mpc_t value, rdpe_t error) = 0;
342 
350  virtual long int raise_data_wp (mps_context * ctx, long int wp);
351 
352  virtual void start_fp (mps_context * ctx, mps_approximation ** approximations);
353  virtual void start_dpe (mps_context * ctx, mps_approximation ** approximations);
354  virtual void start_mp (mps_context * ctx, mps_approximation ** approximations);
355 
356  virtual void get_leading_coefficient (mps_context * ctx, mpc_t lc);
357 
358  virtual void newton (mps_context * ctx, mps_approximation * a, cplx_t x) = 0;
359  virtual void newton (mps_context * ctx, mps_approximation * a, cdpe_t x) = 0;
360  virtual void newton (mps_context * ctx, mps_approximation * a, mpc_t x, long int wp) = 0;
361 
362 public:
363  static mps_boolean feval_wrapper (mps_context * ctx, mps_polynomial *p,
364  cplx_t x, cplx_t value, double * error);
365 
366  static mps_boolean deval_wrapper (mps_context * ctx, mps_polynomial *p,
367  cdpe_t x, cdpe_t value, rdpe_t error);
368 
369  static mps_boolean meval_wrapper (mps_context * ctx, mps_polynomial *p,
370  mpc_t x, mpc_t value, rdpe_t error);
371 
372  static void free_wrapper (mps_context * ctx, mps_polynomial * p);
373 
374  static long int raise_data_wrapper (mps_context * ctx, mps_polynomial * p,
375  long int wp);
376 
377  static void fstart_wrapper (mps_context * ctx, mps_polynomial * p, mps_approximation ** approximations);
378  static void dstart_wrapper (mps_context * ctx, mps_polynomial * p, mps_approximation ** approximations);
379  static void mstart_wrapper (mps_context * ctx, mps_polynomial * p, mps_approximation ** approximations);
380 
381  static void fnewton_wrapper (mps_context * ctx, mps_polynomial * p,
382  mps_approximation * a, cplx_t x);
383  static void dnewton_wrapper (mps_context * ctx, mps_polynomial * p,
384  mps_approximation * a, cdpe_t x);
385  static void mnewton_wrapper (mps_context * ctx, mps_polynomial * p,
386  mps_approximation * a, mpc_t x,
387  long int wp);
388 
389  static void get_leading_coefficient_wrapper (mps_context * ctx, mps_polynomial * p,
390  mpc_t leading_coefficient);
391  };
392 }
393 
394 #endif /* __cplusplus */
395 
396 #endif
mps.h
Header file for libmps.
mps::Polynomial::raise_data_wp
virtual long int raise_data_wp(mps_context *ctx, long int wp)
Raise the working precision of this polynomial to the specified value.
Definition: polynomialxx.cpp:63
mps_polynomial::fstart
mps_polynomial_fstart_t fstart
Method that collocate initial starting points.
Definition: polynomial.h:171
mps_polynomial::mnewton
mps_polynomial_mnewton_t mnewton
Function used to compute the Newton correction in a point.
Definition: polynomial.h:207
mps::Polynomial::eval
virtual bool eval(mps_context *ctx, cplx_t x, cplx_t value, double *error)=0
Evaluate the polynomial at a point.
mps_polynomial::density
mps_density density
Density of the coefficients, or MPS_DENSITY_USER if the coefficients (or the newton fraction) is prov...
Definition: polynomial.h:144
mps_context
this struct holds the state of the mps computation
Definition: context.h:55
mps_polynomial::meval
mps_polynomial_meval_t meval
Method that evaluates the polynomial.
Definition: polynomial.h:166
mps_polynomial::structure
mps_structure structure
Structure of the polynomial, i.e., the algebraic (or non-algebraic) structure where the coefficients ...
Definition: polynomial.h:137
mps_polynomial::free
mps_polynomial_free_t free
Function used to release polynomial resources.
Definition: polynomial.h:186
mps_polynomial::raise_data
mps_polynomial_raise_data_t raise_data
Function used to raise precision of the coefficients of the representation of the polynomial.
Definition: polynomial.h:192
mps_polynomial::type_name
const char * type_name
Name of the type. This must be a global static string that can be used to check if a mps_polynomial i...
Definition: polynomial.h:117
mps_polynomial::dnewton
mps_polynomial_dnewton_t dnewton
Function used to compute the Newton correction in a point.
Definition: polynomial.h:202
mps_polynomial
Struct that represents an abstract polynomial. All the other real polynomial implementations (such as...
Definition: polynomial.h:111
mps::Polynomial
Definition: polynomial.h:274
mps_polynomial::prec
long int prec
Bits of precision of the coefficients.
Definition: polynomial.h:130
mps_polynomial::deval
mps_polynomial_deval_t deval
Method that evaluates the polynomial.
Definition: polynomial.h:161
mps::Polynomial::eval
virtual bool eval(mps_context *ctx, cdpe_t x, cdpe_t value, rdpe_t error)=0
Evaluate the polynomial at a point.
mps::Polynomial::fromString
static Polynomial * fromString(mps_context *ctx, const char *inputString)
Parse a polynomial from a C-style string.
Definition: polynomialxx.cpp:48
mps::Polynomial::get_degree
int get_degree()
Public accessor to the degree of the Polynomial.
Definition: polynomial.h:293
mps_polynomial::degree
int degree
The degree of the polynomial.
Definition: polynomial.h:122
mps_polynomial::mstart
mps_polynomial_mstart_t mstart
Method that collocate initial starting points.
Definition: polynomial.h:181
mps_polynomial::dstart
mps_polynomial_dstart_t dstart
Method that collocate initial starting points.
Definition: polynomial.h:176
mps_approximation
Definition: approximation.h:24
mps::Polynomial::eval
virtual bool eval(mps_context *ctx, mpc_t x, mpc_t value, rdpe_t error)=0
Evaluate the polynomial at a point.
mps::Polynomial::Polynomial
Polynomial(mps_context *ctx, const char *type_name="mps_polynomial")
This constructor has the main role of adjusting the fake vtable in the C struct to reflect the actual...
Definition: polynomialxx.cpp:55
mps_polynomial::feval
mps_polynomial_feval_t feval
Method that evaluates the polynomial.
Definition: polynomial.h:156
mps_polynomial::fnewton
mps_polynomial_fnewton_t fnewton
Function used to compute the Newton correction in a point.
Definition: polynomial.h:197
mps_polynomial::get_leading_coefficient
mps_polynomial_get_leading_coefficient_t get_leading_coefficient
Function used to retrieve the leading coefficient of the polynomial.
Definition: polynomial.h:213
mps_polynomial::thread_safe
mps_boolean thread_safe
This is true if the polynomial has thread-safe methods. Note that this is the default assumption set ...
Definition: polynomial.h:151