MPSolve 3.2.1
Loading...
Searching...
No Matches
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
18extern "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
37typedef mps_boolean (*mps_polynomial_feval_t)(mps_context * ctx, mps_polynomial * p, cplx_t x, cplx_t value, double * error);
38
42typedef mps_boolean (*mps_polynomial_deval_t)(mps_context * ctx, mps_polynomial * p, cdpe_t x, cdpe_t value, rdpe_t error);
43
48typedef mps_boolean (*mps_polynomial_meval_t)(mps_context * ctx, mps_polynomial * p, mpc_t x, mpc_t value, rdpe_t error);
49
53typedef void (*mps_polynomial_free_t)(mps_context * ctx, mps_polynomial *p);
54
59typedef long int (*mps_polynomial_raise_data_t)(mps_context * ctx, mps_polynomial * p, long int wp);
60
66typedef void (*mps_polynomial_fstart_t)(mps_context * ctx, mps_polynomial * p, mps_approximation ** approximations);
67
73typedef void (*mps_polynomial_dstart_t)(mps_context * ctx, mps_polynomial * p, mps_approximation ** approximations);
74
80typedef void (*mps_polynomial_mstart_t)(mps_context * ctx, mps_polynomial * p, mps_approximation ** approximations);
81
85typedef void (*mps_polynomial_fnewton_t)(mps_context * ctx, mps_polynomial * p,
86 mps_approximation * root, cplx_t x);
90typedef void (*mps_polynomial_dnewton_t)(mps_context * ctx, mps_polynomial * p,
91 mps_approximation * root, cdpe_t corr);
92
96typedef void (*mps_polynomial_mnewton_t)(mps_context * ctx, mps_polynomial * p,
97 mps_approximation * root, mpc_t corr, long int wp);
98
104typedef void (*mps_polynomial_get_leading_coefficient_t)(mps_context * ctx, mps_polynomial * p, mpc_t lc);
105
117 const char * type_name;
118
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
216void mps_polynomial_init (mps_context * ctx, mps_polynomial * p);
217
218mps_polynomial * mps_polynomial_new (mps_context * ctx);
219
220mps_boolean mps_polynomial_check_type (mps_polynomial * p, const char * type_name);
221
222mps_polynomial * mps_polynomial_cast (const char *type_name, mps_polynomial *p);
223
224mps_boolean mps_polynomial_feval (mps_context * ctx, mps_polynomial * p, cplx_t x, cplx_t value, double * error);
225
226mps_boolean mps_polynomial_deval (mps_context * ctx, mps_polynomial * p, cdpe_t x, cdpe_t value, rdpe_t error);
227
228mps_boolean mps_polynomial_meval (mps_context * ctx, mps_polynomial * p, mpc_t x, mpc_t value, rdpe_t error);
229
230void mps_polynomial_fstart (mps_context * ctx, mps_polynomial * p, mps_approximation ** approximations);
231
232void mps_polynomial_dstart (mps_context * ctx, mps_polynomial * p, mps_approximation ** approximations);
233
234void mps_polynomial_mstart (mps_context * ctx, mps_polynomial * p, mps_approximation ** approximations);
235
236void mps_polynomial_free (mps_context * ctx, mps_polynomial * p);
237
238void mps_polynomial_fnewton (mps_context * ctx, mps_polynomial *p,
239 mps_approximation * root, cplx_t corr);
240
241void mps_polynomial_dnewton (mps_context * ctx, mps_polynomial *p,
242 mps_approximation * root, cdpe_t corr);
243
244void mps_polynomial_mnewton (mps_context * ctx, mps_polynomial *p,
245 mps_approximation * root, mpc_t corr, long int wp);
246
247void mps_polynomial_get_leading_coefficient (mps_context * ctx, mps_polynomial * p, mpc_t lc);
248
249long int mps_polynomial_raise_data (mps_context * ctx, mps_polynomial * p, long int wp);
250
251void mps_polynomial_set_input_prec (mps_context * ctx, mps_polynomial * p, long int prec);
252
253/* functions in general-starting.c */
254void mps_general_fstart (mps_context * ctx, mps_polynomial * p, mps_approximation ** approximations);
255void mps_general_dstart (mps_context * ctx, mps_polynomial * p, mps_approximation ** approximations);
256void 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
273namespace mps {
274 class Polynomial : public mps_polynomial {
275public:
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
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
362public:
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
Definition: polynomial.h:274
virtual bool eval(mps_context *ctx, cplx_t x, cplx_t value, double *error)=0
Evaluate the polynomial at a point.
virtual bool eval(mps_context *ctx, mpc_t x, mpc_t value, rdpe_t error)=0
Evaluate the polynomial at a point.
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
int get_degree()
Public accessor to the degree of the Polynomial.
Definition: polynomial.h:293
virtual bool eval(mps_context *ctx, cdpe_t x, cdpe_t value, rdpe_t error)=0
Evaluate the polynomial at a point.
static Polynomial * fromString(mps_context *ctx, const char *inputString)
Parse a polynomial from a C-style string.
Definition: polynomialxx.cpp:48
Header file for libmps.
Definition: approximation.h:24
this struct holds the state of the mps computation
Definition: context.h:55
Struct that represents an abstract polynomial. All the other real polynomial implementations (such as...
Definition: polynomial.h:111
mps_polynomial_dstart_t dstart
Method that collocate initial starting points.
Definition: polynomial.h:176
mps_polynomial_dnewton_t dnewton
Function used to compute the Newton correction in a point.
Definition: polynomial.h:202
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
mps_polynomial_mnewton_t mnewton
Function used to compute the Newton correction in a point.
Definition: polynomial.h:207
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_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_mstart_t mstart
Method that collocate initial starting points.
Definition: polynomial.h:181
mps_polynomial_fnewton_t fnewton
Function used to compute the Newton correction in a point.
Definition: polynomial.h:197
mps_polynomial_deval_t deval
Method that evaluates the polynomial.
Definition: polynomial.h:161
mps_polynomial_free_t free
Function used to release polynomial resources.
Definition: polynomial.h:186
mps_polynomial_feval_t feval
Method that evaluates the polynomial.
Definition: polynomial.h:156
mps_polynomial_get_leading_coefficient_t get_leading_coefficient
Function used to retrieve the leading coefficient of the polynomial.
Definition: polynomial.h:213
int degree
The degree of the polynomial.
Definition: polynomial.h:122
mps_polynomial_fstart_t fstart
Method that collocate initial starting points.
Definition: polynomial.h:171
mps_structure structure
Structure of the polynomial, i.e., the algebraic (or non-algebraic) structure where the coefficients ...
Definition: polynomial.h:137
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
long int prec
Bits of precision of the coefficients.
Definition: polynomial.h:130
mps_polynomial_meval_t meval
Method that evaluates the polynomial.
Definition: polynomial.h:166