Statistiques
| Révision :

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

Historique | Voir | Annoter | Télécharger (9,26 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
 * Check if a sollya object is a constant expression.
73
 * @return 1 if true and zero otherwise
74
 */
75
int
76
pobyso_is_constant_expression(sollya_obj_t obj_to_text);
77

    
78
/**
79
 * Create a Sollya monomial from a Sollya constant,
80
 * the coefficient, and an integer, the exponent
81
 * @return a Sollya functional expression if successes, or a Sollya error
82
 * if fails.
83
 */
84
sollya_obj_t
85
pobyso_new_monomial(pobyso_func_exp_t coefficient, long degree);
86

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

    
101
/**
102
 * A wrapper around the Sollya Remez function with the canonical monomials
103
 * base.
104
 */
105

    
106
pobyso_func_exp_t
107
pobyso_remez_canonical_monomials_base(pobyso_func_exp_t function,
108
                                      long int degree,
109
                                      pobyso_range_t interval,
110
                                      pobyso_func_exp_t weight,
111
                                      double quality,
112
                                      pobyso_range_t bounds);
113

    
114
/**
115
 * A wrapper around the Sollya Remez function with the a sparse monomials
116
 * base.
117
 */
118

    
119
pobyso_func_exp_t
120
pobyso_remez_sparse_monomials_base(pobyso_func_exp_t);
121

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

    
127
pobyso_func_exp_t
128
pobyso_remez_arbitrary_base(pobyso_func_exp_t);
129

    
130
/**
131
 * Set the canonical mode.
132
 */
133

    
134
int
135
pobyso_set_canonical_on(void);
136

    
137
/**
138
 * Set the verbosity mode off (level 0).
139
 * The current level of verbosity is returned.
140
 */
141
pobyso_sollya_verbosity_t
142
pobyso_set_verbosity_off(void);
143

    
144
/**
145
 * Set the verbosity level to newVerbosityLevel.
146
 * @param newVerbosityLevel must be a Sollya object corresponding to an
147
 *        integer constant.
148
 */
149
pobyso_sollya_verbosity_t
150
pobyso_set_verbosity_to(pobyso_sollya_verbosity_t newVerbosityLevel);
151

    
152
/**
153
 * Set the verbosity level to intVerbosityLevel.
154
 * @param newVerbosityLevel is an positive or null int.
155
*/
156
pobyso_sollya_verbosity_t
157
pobyso_set_verbosity_to_int(int intVerbosityLevel);
158

    
159
#if 0
160
/**
161
 * Create the canonical (non sparse) base of monomials for a given degree.
162
 */
163
chain*
164
pobyso_create_canonical_monomials_base(const unsigned int degree);
165

166
/**
167
 * Create a chain from an array of int.
168
 */
169
sollya_int_list
170
pobyso_create_int_list_from_int_Array(int* intArray,
171
                                    const unsigned int arrayLength);
172

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

187
sollya_obj_t
188
pobyso_diff(sollya_obj_t function);
189

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

208

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

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

235
/**
236
 * Free a range.
237
 * It involves clearing the mpfr_t elements and deallocating the
238
 * pointers.
239
 */
240
void
241
pobyso_free_range(rangetype range);
242

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

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

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