Statistiques
| Révision :

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

Historique | Voir | Annoter | Télécharger (8,78 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
typedef sollya_obj_t pobyso_error_t;
24
typedef sollya_obj_t pobyso_func_exp_t;
25
typedef sollya_obj_t pobyso_precision_t;
26
typedef sollya_obj_t pobyso_range_t;
27

    
28
typedef sollya_obj_t sollya_verbosity_t;
29

    
30
#define POBYSO_ABSOLUTE 1
31
#define POBYSO_RELATIVE 2
32

    
33
/* Mimic the default behavior of interactive Sollya. */
34
#define POBYSO_DEFAULT_POINTS 501
35
#define POBYSO_INF_NORM_NUM_POINTS (POBYSO_DEFAULT_POINTS)
36
#define POBYSO_GUESS_DEGREE_BOUND 1024
37

    
38

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

    
44
static inline int pobyso_is_error(sollya_obj_t errorCandidate)
45
{return(sollya_lib_obj_is_error(errorCandidate));}
46

    
47
static inline int pobyso_is_function(sollya_obj_t functionCandidate)
48
{return(sollya_lib_obj_is_function(functionCandidate));}
49

    
50
/**
51
 * Print object(s) to stdout.
52
 * A very thin wrapper around the lib_sollya_v_autoprint() function.
53
 * Should be called with NULL as the final argument.
54
 */
55
void
56
pobyso_autoprint(sollya_obj_t soObj, ...);
57

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

    
64
void
65
pobyso_autoprint_v(sollya_obj_t soObj, va_list va);
66

    
67
/**
68
 * Parse a string to create a Sollya object.
69
 * A very thin wrapper around the sollya_lib_parse_string() function.
70
 * If the final ";" is forgotten in the expression, it is added by the
71
 * function.
72
 * @return a Sollya expression if successes, a Sollya error if fails.
73
 */
74
pobyso_error_t
75
pobyso_parse(const char* expression);
76

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

    
90
/**
91
 * A wrapper around the Sollya Remez function with the canonical monomials
92
 * base.
93
 */
94

    
95
pobyso_func_exp_t
96
pobyso_remez_canonical_monomials_base(pobyso_func_exp_t function,
97
                                      long int degree,
98
                                      pobyso_range_t interval,
99
                                      pobyso_func_exp_t weight,
100
                                      double quality,
101
                                      pobyso_range_t bounds);
102

    
103
/**
104
 * A wrapper around the Sollya Remez function with the a sparse monomials
105
 * base.
106
 */
107

    
108
pobyso_func_exp_t
109
pobyso_remez_sparse_monomials_base(pobyso_func_exp_t);
110

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

    
116
pobyso_func_exp_t
117
pobyso_remez_arbitrary_base(pobyso_func_exp_t);
118

    
119

    
120

    
121
/**
122
 * Set the verbosity mode off (level 0).
123
 * The current level of vebositiy is returned.
124
 */
125
sollya_verbosity_t
126
pobyso_set_verbosity_off(void);
127

    
128
/**
129
 * Set the verbosity level to newVerbosityLevel.
130
 * @param newVerbosityLevel must be a Sollay object corresponding to an
131
 *        integer constant.
132
 */
133
sollya_verbosity_t
134
pobyso_set_verbosity_to(sollya_obj_t newVerbosityLevel);
135

    
136
#if 0
137
/**
138
 * Create the canonical (non sparse) base of monomials for a given degree.
139
 */
140
chain*
141
pobyso_create_canonical_monomials_base(const unsigned int degree);
142

143
/**
144
 * Create a chain from an array of int.
145
 */
146
sollya_int_list
147
pobyso_create_int_list_from_int_Array(int* intArray,
148
                                    const unsigned int arrayLength);
149

150
/**
151
 * Create a chain from an array of int.
152
 */
153
sollya_int_list_t
154
pobyso_create_int_list_from_unsigned_int_array(unsigned int* intArray,
155
                                            const unsigned int arrayLength);
156
/**
157
 * Differentiation of a function.
158
 * A slim wrapper around the Sollya differentiate function.
159
 * @param functionNode - the Sollya node to differentiate;
160
 * @return a node representing the function differentiated or NULL, if
161
 *         something goes wrong.
162
 */
163

164
sollya_obj_t
165
pobyso_diff(sollya_obj_t function);
166

167
/**
168
 * A match to the Sollya dirtyinfnorm.
169
 * A slim wrapper around the Sollya function.
170
 * @param infnorm - out parameter to return the result, must be "inited"
171
 *                  and "cleared" by the caller;
172
 * @param functionNode - the Sollya node to compute the infinite norm of;
173
 * @param lowerBound - the lower bound of the interval;
174
 * @param upperBound - the upper bound of the interval;
175
 * @param precision  - the internal precision Sollya must use.
176
 * @return 0 if everything is OK, != 0 if something goes wrong.
177
 */
178
int
179
pobyso_dirty_infnorm(mpfr_t infNorm,
180
                      node *functionNode,
181
                      mpfr_t lowerBound,
182
                      mpfr_t upperBound,
183
                      mp_prec_t precision);
184

185

186
/**
187
 * Faithful evaluation of an expression.
188
 *
189
 * @param faitufulEvaluation - holds the result, must be "inited" by the
190
 *                             caller;
191
 */
192
int
193
pobyso_evaluate_faithful(mpfr_t faithfulEvaluation,
194
                          node *nodeToEvaluate,
195
                          mpfr_t argument,
196
                          mpfr_prec_t precision);
197

198
/**
199
 * Find the zeros of a function on a given interval.
200
 */
201
chain*
202
pobyso_find_zeros(node *function,
203
                  mpfr_t *lowerBound,
204
                  mpfr_t *upperBound);
205
/**
206
 * Free a chain of node.
207
 * All elements of the chain have to be nodes.
208
 */
209
void
210
pobyso_free_chain_of_nodes(chain *theChain);
211

212
/**
213
 * Free a range.
214
 * It involves clearing the mpfr_t elements and deallocating the
215
 * pointers.
216
 */
217
void
218
pobyso_free_range(rangetype range);
219

220
/**
221
 * Computes a good polynomial approximation with fixed-point or floating-point
222
 * coefficients.
223
 */
224
node*
225
pobyso_fp_minimax_canonical_monomials_base(node *function,
226
                                          int degree,
227
                                          chain *formats,
228
                                          chain *points,
229
                                          mpfr_t lowerBound,
230
                                          mpfr_t upperBound,
231
                                          int fpFixedArg,
232
                                          int absRel,
233
                                          node *constPart,
234
                                          node *minimax);
235
/**
236
 * Parses a string to build the node representing the function.
237
 * In fact, does nothing for the moment: the string must be a correct function
238
 * definition. No error correction takes place here.
239
 */
240
node*
241
pobyso_parse_function(char *functionString,
242
                      char *freeVariableNameString);
243

244
/** Compute a polynomial approximation in the canonical monomials basis for
245
 *  a function, for a given precision. The returned polynomial has the minimal
246
 *  degree to achieve the required precision.
247
 */
248
node*
249
pobyso_remez_approx_canonical_monomials_base_for_error(node *functionNode,
250
                                                      unsigned int mode,
251
                                                      mpfr_t lowerBound,
252
                                                      mpfr_t upperBound,
253
                                                      mpfr_t eps);
254

255
/**
256
 * Computes a the remez approximation of a function.
257
 * @param function   - the node holding the function to approximate;
258
 * @param weight     - the node holding the weight function, can be NULL. In
259
 *                     this case a default weight of "1" will be provided and
260
 *                     the approximation is related is with respect to the
261
 *                     absolute error.
262
 * @param degree     - the degree of the approximation polynomial;
263
 * @param lowerBound - the lower bound of the approximation interval;
264
 * @param upperBound - the upper bound of the approximation interval;
265
 * @param quality    - quality = (eps - eps*) / eps*; the search stop when the required
266
 *                     quality is achieved.
267
 *
268
 * @return a node holding the approximation polynomial in Horner form.
269
 */
270
node*
271
pobyso_remez_canonical_monomials_base(node *function,
272
                                       node *weight,
273
                                       unsigned int degree,
274
                                       mpfr_t lowerBound,
275
                                       mpfr_t upperBound,
276
                                       mpfr_t quality);
277
#endif
278
#define POBYSO_h  
279
  
280
#endif
281