Statistiques
| Révision :

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

Historique | Voir | Annoter | Télécharger (9,15 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_v_autoprint() function.
57
 * Should be called with NULL as the final argument.
58
 */
59
void
60
pobyso_autoprint(sollya_obj_t soObj, ...);
61

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

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

    
71

    
72

    
73
/**
74
 * Parse a string to create a Sollya object.
75
 * A very thin wrapper around the sollya_lib_parse_string() function.
76
 * If the final ";" is forgotten in the expression, it is added by the
77
 * function.
78
 * @return a Sollya expression if successes, a Sollya error if fails.
79
 */
80
pobyso_error_t
81
pobyso_parse(const char* expression);
82

    
83
/**
84
 * A wrapper around the Sollya Remez function.
85
 */
86
/**
87
 * Parse a string to create a Sollya object.
88
 * A very thin wrapper around the sollya_lib_parse_string() function.
89
 * If the final ";" is forgotten in the expression, it is added by the
90
 * function.
91
 * @return a Sollya functional expression if successes, a Sollya error if fails.
92
 */
93
pobyso_error_t
94
pobyso_parse_string(const char* expression);
95

    
96
/**
97
 * A wrapper around the Sollya Remez function with the canonical monomials
98
 * base.
99
 */
100

    
101
pobyso_func_exp_t
102
pobyso_remez_canonical_monomials_base(pobyso_func_exp_t function,
103
                                      long int degree,
104
                                      pobyso_range_t interval,
105
                                      pobyso_func_exp_t weight,
106
                                      double quality,
107
                                      pobyso_range_t bounds);
108

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

    
114
pobyso_func_exp_t
115
pobyso_remez_sparse_monomials_base(pobyso_func_exp_t);
116

    
117
/**
118
 * A wrapper around the Sollya Remez function with the canonical monomials
119
 * base.
120
 */
121

    
122
pobyso_func_exp_t
123
pobyso_remez_arbitrary_base(pobyso_func_exp_t);
124

    
125
/**
126
 * Set the canonical mode.
127
 */
128

    
129
int
130
pobyso_set_canonical_on(void);
131

    
132
/**
133
 * Set the verbosity mode off (level 0).
134
 * The current level of verbosity is returned.
135
 */
136
pobyso_sollya_verbosity_t
137
pobyso_set_verbosity_off(void);
138

    
139
/**
140
 * Set the verbosity level to newVerbosityLevel.
141
 * @param newVerbosityLevel must be a Sollya object corresponding to an
142
 *        integer constant.
143
 */
144
pobyso_sollya_verbosity_t
145
pobyso_set_verbosity_to(pobyso_sollya_verbosity_t newVerbosityLevel);
146

    
147
/**
148
 * Set the verbosity level to intVerbosityLevel.
149
 * @param newVerbosityLevel is an positive or null int.
150
*/
151
pobyso_sollya_verbosity_t
152
pobyso_set_verbosity_to_int(int intVerbosityLevel);
153

    
154
#if 0
155
/**
156
 * Create the canonical (non sparse) base of monomials for a given degree.
157
 */
158
chain*
159
pobyso_create_canonical_monomials_base(const unsigned int degree);
160

161
/**
162
 * Create a chain from an array of int.
163
 */
164
sollya_int_list
165
pobyso_create_int_list_from_int_Array(int* intArray,
166
                                    const unsigned int arrayLength);
167

168
/**
169
 * Create a chain from an array of int.
170
 */
171
sollya_int_list_t
172
pobyso_create_int_list_from_unsigned_int_array(unsigned int* intArray,
173
                                            const unsigned int arrayLength);
174
/**
175
 * Differentiation of a function.
176
 * A slim wrapper around the Sollya differentiate function.
177
 * @param functionNode - the Sollya node to differentiate;
178
 * @return a node representing the function differentiated or NULL, if
179
 *         something goes wrong.
180
 */
181

182
sollya_obj_t
183
pobyso_diff(sollya_obj_t function);
184

185
/**
186
 * A match to the Sollya dirtyinfnorm.
187
 * A slim wrapper around the Sollya function.
188
 * @param infnorm - out parameter to return the result, must be "inited"
189
 *                  and "cleared" by the caller;
190
 * @param functionNode - the Sollya node to compute the infinite norm of;
191
 * @param lowerBound - the lower bound of the interval;
192
 * @param upperBound - the upper bound of the interval;
193
 * @param precision  - the internal precision Sollya must use.
194
 * @return 0 if everything is OK, != 0 if something goes wrong.
195
 */
196
int
197
pobyso_dirty_infnorm(mpfr_t infNorm,
198
                      node *functionNode,
199
                      mpfr_t lowerBound,
200
                      mpfr_t upperBound,
201
                      mp_prec_t precision);
202

203

204
/**
205
 * Faithful evaluation of an expression.
206
 *
207
 * @param faitufulEvaluation - holds the result, must be "inited" by the
208
 *                             caller;
209
 */
210
int
211
pobyso_evaluate_faithful(mpfr_t faithfulEvaluation,
212
                          node *nodeToEvaluate,
213
                          mpfr_t argument,
214
                          mpfr_prec_t precision);
215

216
/**
217
 * Find the zeros of a function on a given interval.
218
 */
219
chain*
220
pobyso_find_zeros(node *function,
221
                  mpfr_t *lowerBound,
222
                  mpfr_t *upperBound);
223
/**
224
 * Free a chain of node.
225
 * All elements of the chain have to be nodes.
226
 */
227
void
228
pobyso_free_chain_of_nodes(chain *theChain);
229

230
/**
231
 * Free a range.
232
 * It involves clearing the mpfr_t elements and deallocating the
233
 * pointers.
234
 */
235
void
236
pobyso_free_range(rangetype range);
237

238
/**
239
 * Computes a good polynomial approximation with fixed-point or floating-point
240
 * coefficients.
241
 */
242
node*
243
pobyso_fp_minimax_canonical_monomials_base(node *function,
244
                                          int degree,
245
                                          chain *formats,
246
                                          chain *points,
247
                                          mpfr_t lowerBound,
248
                                          mpfr_t upperBound,
249
                                          int fpFixedArg,
250
                                          int absRel,
251
                                          node *constPart,
252
                                          node *minimax);
253
/**
254
 * Parses a string to build the node representing the function.
255
 * In fact, does nothing for the moment: the string must be a correct function
256
 * definition. No error correction takes place here.
257
 */
258
node*
259
pobyso_parse_function(char *functionString,
260
                      char *freeVariableNameString);
261

262
/** Compute a polynomial approximation in the canonical monomials basis for
263
 *  a function, for a given precision. The returned polynomial has the minimal
264
 *  degree to achieve the required precision.
265
 */
266
node*
267
pobyso_remez_approx_canonical_monomials_base_for_error(node *functionNode,
268
                                                      unsigned int mode,
269
                                                      mpfr_t lowerBound,
270
                                                      mpfr_t upperBound,
271
                                                      mpfr_t eps);
272

273
/**
274
 * Computes a the remez approximation of a function.
275
 * @param function   - the node holding the function to approximate;
276
 * @param weight     - the node holding the weight function, can be NULL. In
277
 *                     this case a default weight of "1" will be provided and
278
 *                     the approximation is related is with respect to the
279
 *                     absolute error.
280
 * @param degree     - the degree of the approximation polynomial;
281
 * @param lowerBound - the lower bound of the approximation interval;
282
 * @param upperBound - the upper bound of the approximation interval;
283
 * @param quality    - quality = (eps - eps*) / eps*; the search stop when the required
284
 *                     quality is achieved.
285
 *
286
 * @return a node holding the approximation polynomial in Horner form.
287
 */
288
node*
289
pobyso_remez_canonical_monomials_base(node *function,
290
                                       node *weight,
291
                                       unsigned int degree,
292
                                       mpfr_t lowerBound,
293
                                       mpfr_t upperBound,
294
                                       mpfr_t quality);
295
#endif
296
#define POBYSO_h  
297
  
298
#endif
299