Statistiques
| Révision :

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

Historique | Voir | Annoter | Télécharger (9,3 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

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

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

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

    
41

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

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

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

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

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

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

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

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

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

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

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

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

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

    
126
pobyso_func_exp_t
127
pobyso_remez_sparse_monomials_base(pobyso_func_exp_t);
128

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

    
134
pobyso_func_exp_t
135
pobyso_remez_arbitrary_base(pobyso_func_exp_t);
136

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

    
141
int
142
pobyso_set_canonical_on(void);
143

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

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

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

    
163
pobyso_func_exp_t
164
pobyso_subpoly(pobyso_func_exp_t polynomial, long expsNum, long* expsList);
165

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

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

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

194
sollya_obj_t
195
pobyso_diff(sollya_obj_t function);
196

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

215

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

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

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

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

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

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