Statistiques
| Révision :

root / pobysoC-4.0 / src / pobyso.h @ 134

Historique | Voir | Annoter | Télécharger (9,34 ko)

1
/** @file pobyso.h
2
 * Integration of Sollya to C programs
3
 * @author S.T.
4
 * @date 2011-10-11
5
 * Note: pobyso stands for POwered BY SOllya.
6
 *                         --      -- --
7
 */
8
/******************************************************************************/
9
 
10
/*
11
 * Add below all the headers needed to get this header work.
12
 */
13
/* <stdio.h> is needed *before* <mpfr.h> for all MPFR input/output functions
14
 * prototypes be defined. */
15
#include <string.h>
16
#include <stdio.h>
17
#include <sollya.h>
18
#include <mpfr.h>
19

    
20
#ifndef POBYSO_h
21

    
22
/* Typedefs to make code more readable. */
23

    
24
typedef sollya_obj_t pobyso_error_t;
25
typedef sollya_obj_t pobyso_func_exp_t;
26
typedef sollya_obj_t pobyso_on_off_t;
27
typedef sollya_obj_t pobyso_precision_t;
28
typedef sollya_obj_t pobyso_range_t;
29
typedef sollya_obj_t pobyso_sollya_verbosity_t;
30

    
31
#define POBYSO_ABSOLUTE (1)
32
#define POBYSO_RELATIVE (2)
33

    
34
#define POBYSO_OFF (0)
35
#define POBYSO_ON (1)
36

    
37
/* Mimic the default behavior of interactive Sollya. */
38
#define POBYSO_DEFAULT_POINTS 501
39
#define POBYSO_INF_NORM_NUM_POINTS (POBYSO_DEFAULT_POINTS)
40
#define POBYSO_GUESS_DEGREE_BOUND 1024
41

    
42

    
43
/* Very thin wrappers around a lot of Sollya functions.
44
 */
45
static inline pobyso_error_t pobyso_error(void)
46
{return(sollya_lib_error());}
47

    
48
static inline int pobyso_is_error(sollya_obj_t errorCandidate)
49
{return(sollya_lib_obj_is_error(errorCandidate));}
50

    
51
static inline int pobyso_is_function(sollya_obj_t functionCandidate)
52
{return(sollya_lib_obj_is_function(functionCandidate));}
53

    
54
/**
55
 * Print object(s) to stdout.
56
 * A very thin wrapper around the lib_sollya_autoprint() function.
57
 */
58
void
59
pobyso_autoprint(sollya_obj_t soObj);
60

    
61
/**
62
 * Print object(s) to stdout: the va_list companion function.
63
 * A very thin wrapper around the lib_sollya_v_autoprint() function.
64
 * The last argument in the va_list should be NULL.
65
 */
66

    
67
void
68
pobyso_autoprint_v(sollya_obj_t soObj, va_list va);
69

    
70
/**
71
 * Get the current verbosity level.
72
 * @return an integer at the current verbosity level.
73
 */
74
int
75
pobyso_get_verbosity();
76

    
77
/**
78
 * Check if a sollya object is a constant expression.
79
 * @return 1 if true and zero otherwise
80
 */
81
int
82
pobyso_is_constant_expression(sollya_obj_t obj_to_text);
83

    
84
/**
85
 * Create a Sollya monomial from a Sollya constant,
86
 * the coefficient, and an integer, the exponent.
87
 * @param coefficient must be a non NULL constant expression;
88
 * @param degree must be a non negative integer;
89
 * @return a Sollya functional expression if successes, or a Sollya error
90
 * if fails.
91
 */
92
pobyso_func_exp_t
93
pobyso_new_monomial(pobyso_func_exp_t coefficient, long degree);
94

    
95
/**
96
 * A wrapper around the Sollya Remez function.
97
 */
98
/**
99
 * Parse a string to create a Sollya object.
100
 * A very thin wrapper around the sollya_lib_parse_string() function.
101
 * If the final ";" is forgotten in the expression, it is added by the
102
 * function.
103
 * @return a Sollya functional expression if successes, or a Sollya error
104
 * if fails.
105
 */
106
pobyso_func_exp_t
107
pobyso_parse_string(const char* expression);
108

    
109
/**
110
 * A wrapper around the Sollya Remez function with the canonical monomials
111
 * base.
112
 */
113

    
114
pobyso_func_exp_t
115
pobyso_remez_canonical_monomials_base(pobyso_func_exp_t function,
116
                                      long int degree,
117
                                      pobyso_range_t interval,
118
                                      pobyso_func_exp_t weight,
119
                                      double quality,
120
                                      pobyso_range_t bounds);
121

    
122
/**
123
 * A wrapper around the Sollya Remez function with the a sparse monomials
124
 * base.
125
 */
126

    
127
pobyso_func_exp_t
128
pobyso_remez_sparse_monomials_base(pobyso_func_exp_t);
129

    
130
/**
131
 * A wrapper around the Sollya Remez function with the canonical monomials
132
 * base.
133
 */
134

    
135
pobyso_func_exp_t
136
pobyso_remez_arbitrary_base(pobyso_func_exp_t);
137

    
138
/**
139
 * Set the canonical mode.
140
 */
141

    
142
int
143
pobyso_set_canonical_on(void);
144

    
145
/**
146
 * Set the verbosity mode off (level 0).
147
 * The current level of verbosity is returned.
148
 */
149
int
150
pobyso_set_verbosity_off(void);
151

    
152
/**
153
 * Set the verbosity level to newVerbosityLevel.
154
 * @param newVerbosityLevel must be a Sollya object corresponding to an
155
 *        integer constant.
156
 */
157
int
158
pobyso_set_verbosity_to(int newVerbosityLevel);
159

    
160
/**
161
 * Wrapper around the sollya_lib_subpoly Sollya function.
162
 */
163

    
164
pobyso_func_exp_t
165
pobyso_subpoly(pobyso_func_exp_t polynomial, long expsNum,...);
166

    
167
#if 0
168
/**
169
 * Create the canonical (non sparse) base of monomials for a given degree.
170
 */
171
chain*
172
pobyso_create_canonical_monomials_base(const unsigned int degree);
173

174
/**
175
 * Create a chain from an array of int.
176
 */
177
sollya_int_list
178
pobyso_create_int_list_from_int_Array(int* intArray,
179
                                    const unsigned int arrayLength);
180

181
/**
182
 * Create a chain from an array of int.
183
 */
184
sollya_int_list_t
185
pobyso_create_int_list_from_unsigned_int_array(unsigned int* intArray,
186
                                            const unsigned int arrayLength);
187
/**
188
 * Differentiation of a function.
189
 * A slim wrapper around the Sollya differentiate function.
190
 * @param functionNode - the Sollya node to differentiate;
191
 * @return a node representing the function differentiated or NULL, if
192
 *         something goes wrong.
193
 */
194

195
sollya_obj_t
196
pobyso_diff(sollya_obj_t function);
197

198
/**
199
 * A match to the Sollya dirtyinfnorm.
200
 * A slim wrapper around the Sollya function.
201
 * @param infnorm - out parameter to return the result, must be "inited"
202
 *                  and "cleared" by the caller;
203
 * @param functionNode - the Sollya node to compute the infinite norm of;
204
 * @param lowerBound - the lower bound of the interval;
205
 * @param upperBound - the upper bound of the interval;
206
 * @param precision  - the internal precision Sollya must use.
207
 * @return 0 if everything is OK, != 0 if something goes wrong.
208
 */
209
int
210
pobyso_dirty_infnorm(mpfr_t infNorm,
211
                      node *functionNode,
212
                      mpfr_t lowerBound,
213
                      mpfr_t upperBound,
214
                      mp_prec_t precision);
215

216

217
/**
218
 * Faithful evaluation of an expression.
219
 *
220
 * @param faitufulEvaluation - holds the result, must be "inited" by the
221
 *                             caller;
222
 */
223
int
224
pobyso_evaluate_faithful(mpfr_t faithfulEvaluation,
225
                          node *nodeToEvaluate,
226
                          mpfr_t argument,
227
                          mpfr_prec_t precision);
228

229
/**
230
 * Find the zeros of a function on a given interval.
231
 */
232
chain*
233
pobyso_find_zeros(node *function,
234
                  mpfr_t *lowerBound,
235
                  mpfr_t *upperBound);
236
/**
237
 * Free a chain of node.
238
 * All elements of the chain have to be nodes.
239
 */
240
void
241
pobyso_free_chain_of_nodes(chain *theChain);
242

243
/**
244
 * Free a range.
245
 * It involves clearing the mpfr_t elements and deallocating the
246
 * pointers.
247
 */
248
void
249
pobyso_free_range(rangetype range);
250

251
/**
252
 * Computes a good polynomial approximation with fixed-point or floating-point
253
 * coefficients.
254
 */
255
node*
256
pobyso_fp_minimax_canonical_monomials_base(node *function,
257
                                          int degree,
258
                                          chain *formats,
259
                                          chain *points,
260
                                          mpfr_t lowerBound,
261
                                          mpfr_t upperBound,
262
                                          int fpFixedArg,
263
                                          int absRel,
264
                                          node *constPart,
265
                                          node *minimax);
266
/**
267
 * Parses a string to build the node representing the function.
268
 * In fact, does nothing for the moment: the string must be a correct function
269
 * definition. No error correction takes place here.
270
 */
271
node*
272
pobyso_parse_function(char *functionString,
273
                      char *freeVariableNameString);
274

275
/** Compute a polynomial approximation in the canonical monomials basis for
276
 *  a function, for a given precision. The returned polynomial has the minimal
277
 *  degree to achieve the required precision.
278
 */
279
node*
280
pobyso_remez_approx_canonical_monomials_base_for_error(node *functionNode,
281
                                                      unsigned int mode,
282
                                                      mpfr_t lowerBound,
283
                                                      mpfr_t upperBound,
284
                                                      mpfr_t eps);
285

286
/**
287
 * Computes a the remez approximation of a function.
288
 * @param function   - the node holding the function to approximate;
289
 * @param weight     - the node holding the weight function, can be NULL. In
290
 *                     this case a default weight of "1" will be provided and
291
 *                     the approximation is related is with respect to the
292
 *                     absolute error.
293
 * @param degree     - the degree of the approximation polynomial;
294
 * @param lowerBound - the lower bound of the approximation interval;
295
 * @param upperBound - the upper bound of the approximation interval;
296
 * @param quality    - quality = (eps - eps*) / eps*; the search stop when the required
297
 *                     quality is achieved.
298
 *
299
 * @return a node holding the approximation polynomial in Horner form.
300
 */
301
node*
302
pobyso_remez_canonical_monomials_base(node *function,
303
                                       node *weight,
304
                                       unsigned int degree,
305
                                       mpfr_t lowerBound,
306
                                       mpfr_t upperBound,
307
                                       mpfr_t quality);
308
#endif
309
#define POBYSO_h  
310
  
311
#endif
312