Statistiques
| Révision :

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

Historique | Voir | Annoter | Télécharger (9,76 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
 * @todo                        --      -- --
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 objSo);
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(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
int
84
pobyso_is_free_var_posze_int_power(sollya_obj_t objToTestSo);
85

    
86
/**
87
 * Check if an expression is a monomial (made of a constant expression
88
 * and the free variable to an integer positive or null power.
89
 * @param exprSo: a Sollya functional expression object;
90
 * @return 1 if exprSo is a monomial (as defined above), 0 otherwise.
91
 */
92
int pobyso_is_monomial(pobyso_func_exp_t exprSo);
93

    
94
/**
95
 * Check if an expression is an integer.
96
 */
97
int
98
pobyso_is_int(pobyso_func_exp_t exprSo);
99

    
100
/**
101
 * Create a Sollya monomial from a Sollya constant,
102
 * the coefficient, and an integer, the exponent.
103
 * @param coefficient must be a non NULL constant expression;
104
 * @param degree must be a non negative integer;
105
 * @return a Sollya functional expression if successes, or a Sollya error
106
 * if fails.
107
 */
108
pobyso_func_exp_t
109
pobyso_new_monomial(pobyso_func_exp_t coefficient, long degree);
110

    
111
/**
112
 * A wrapper around the Sollya Remez function.
113
 */
114
/**
115
 * Parse a string to create a Sollya object.
116
 * A very thin wrapper around the sollya_lib_parse_string() function.
117
 * If the final ";" is forgotten in the expression, it is added by the
118
 * function.
119
 * @return a Sollya functional expression if successes, or a Sollya error
120
 * if fails.
121
 */
122
pobyso_func_exp_t
123
pobyso_parse_string(const char* expression);
124

    
125
/**
126
 * A wrapper around the Sollya Remez function with the canonical monomials
127
 * base.
128
 */
129

    
130
pobyso_func_exp_t
131
pobyso_remez_canonical_monomials_base(pobyso_func_exp_t function,
132
                                      long int degree,
133
                                      pobyso_range_t interval,
134
                                      pobyso_func_exp_t weight,
135
                                      double quality,
136
                                      pobyso_range_t bounds);
137

    
138
/**
139
 * A wrapper around the Sollya Remez function with the a sparse monomials
140
 * base.
141
 */
142

    
143
pobyso_func_exp_t
144
pobyso_remez_sparse_monomials_base(pobyso_func_exp_t);
145

    
146
/**
147
 * A wrapper around the Sollya Remez function with the canonical monomials
148
 * base.
149
 */
150

    
151
pobyso_func_exp_t
152
pobyso_remez_arbitrary_base(pobyso_func_exp_t);
153

    
154
/**
155
 * Set the canonical mode.
156
 */
157

    
158
int
159
pobyso_set_canonical_on(void);
160

    
161
/**
162
 * Set the verbosity mode off (level 0).
163
 * The current level of verbosity is returned.
164
 */
165
int
166
pobyso_set_verbosity_off(void);
167

    
168
/**
169
 * Set the verbosity level to newVerbosityLevel.
170
 * @param newVerbosityLevel must be a Sollya object corresponding to an
171
 *        integer constant.
172
 */
173
int
174
pobyso_set_verbosity_to(int newVerbosityLevel);
175

    
176
/**
177
 * Wrapper around the sollya_lib_subpoly Sollya function.
178
 */
179

    
180
pobyso_func_exp_t
181
pobyso_subpoly(pobyso_func_exp_t polynomial, long expsNum, long* expsList);
182

    
183
#if 0
184
/**
185
 * Create the canonical (non sparse) base of monomials for a given degree.
186
 */
187
chain*
188
pobyso_create_canonical_monomials_base(const unsigned int degree);
189

190
/**
191
 * Create a chain from an array of int.
192
 */
193
sollya_int_list
194
pobyso_create_int_list_from_int_Array(int* intArray,
195
                                    const unsigned int arrayLength);
196

197
/**
198
 * Create a chain from an array of int.
199
 */
200
sollya_int_list_t
201
pobyso_create_int_list_from_unsigned_int_array(unsigned int* intArray,
202
                                            const unsigned int arrayLength);
203
/**
204
 * Differentiation of a function.
205
 * A slim wrapper around the Sollya differentiate function.
206
 * @param functionNode - the Sollya node to differentiate;
207
 * @return a node representing the function differentiated or NULL, if
208
 *         something goes wrong.
209
 */
210

211
sollya_obj_t
212
pobyso_diff(sollya_obj_t function);
213

214
/**
215
 * A match to the Sollya dirtyinfnorm.
216
 * A slim wrapper around the Sollya function.
217
 * @param infnorm - out parameter to return the result, must be "inited"
218
 *                  and "cleared" by the caller;
219
 * @param functionNode - the Sollya node to compute the infinite norm of;
220
 * @param lowerBound - the lower bound of the interval;
221
 * @param upperBound - the upper bound of the interval;
222
 * @param precision  - the internal precision Sollya must use.
223
 * @return 0 if everything is OK, != 0 if something goes wrong.
224
 */
225
int
226
pobyso_dirty_infnorm(mpfr_t infNorm,
227
                      node *functionNode,
228
                      mpfr_t lowerBound,
229
                      mpfr_t upperBound,
230
                      mp_prec_t precision);
231

232

233
/**
234
 * Faithful evaluation of an expression.
235
 *
236
 * @param faitufulEvaluation - holds the result, must be "inited" by the
237
 *                             caller;
238
 */
239
int
240
pobyso_evaluate_faithful(mpfr_t faithfulEvaluation,
241
                          node *nodeToEvaluate,
242
                          mpfr_t argument,
243
                          mpfr_prec_t precision);
244

245
/**
246
 * Find the zeros of a function on a given interval.
247
 */
248
chain*
249
pobyso_find_zeros(node *function,
250
                  mpfr_t *lowerBound,
251
                  mpfr_t *upperBound);
252
/**
253
 * Free a chain of node.
254
 * All elements of the chain have to be nodes.
255
 */
256
void
257
pobyso_free_chain_of_nodes(chain *theChain);
258

259
/**
260
 * Free a range.
261
 * It involves clearing the mpfr_t elements and deallocating the
262
 * pointers.
263
 */
264
void
265
pobyso_free_range(rangetype range);
266

267
/**
268
 * Computes a good polynomial approximation with fixed-point or floating-point
269
 * coefficients.
270
 */
271
node*
272
pobyso_fp_minimax_canonical_monomials_base(node *function,
273
                                          int degree,
274
                                          chain *formats,
275
                                          chain *points,
276
                                          mpfr_t lowerBound,
277
                                          mpfr_t upperBound,
278
                                          int fpFixedArg,
279
                                          int absRel,
280
                                          node *constPart,
281
                                          node *minimax);
282
/**
283
 * Parses a string to build the node representing the function.
284
 * In fact, does nothing for the moment: the string must be a correct function
285
 * definition. No error correction takes place here.
286
 */
287
node*
288
pobyso_parse_function(char *functionString,
289
                      char *freeVariableNameString);
290

291
/** Compute a polynomial approximation in the canonical monomials basis for
292
 *  a function, for a given precision. The returned polynomial has the minimal
293
 *  degree to achieve the required precision.
294
 */
295
node*
296
pobyso_remez_approx_canonical_monomials_base_for_error(node *functionNode,
297
                                                      unsigned int mode,
298
                                                      mpfr_t lowerBound,
299
                                                      mpfr_t upperBound,
300
                                                      mpfr_t eps);
301

302
/**
303
 * Computes a the remez approximation of a function.
304
 * @param function   - the node holding the function to approximate;
305
 * @param weight     - the node holding the weight function, can be NULL. In
306
 *                     this case a default weight of "1" will be provided and
307
 *                     the approximation is related is with respect to the
308
 *                     absolute error.
309
 * @param degree     - the degree of the approximation polynomial;
310
 * @param lowerBound - the lower bound of the approximation interval;
311
 * @param upperBound - the upper bound of the approximation interval;
312
 * @param quality    - quality = (eps - eps*) / eps*; the search stop when the required
313
 *                     quality is achieved.
314
 *
315
 * @return a node holding the approximation polynomial in Horner form.
316
 */
317
node*
318
pobyso_remez_canonical_monomials_base(node *function,
319
                                       node *weight,
320
                                       unsigned int degree,
321
                                       mpfr_t lowerBound,
322
                                       mpfr_t upperBound,
323
                                       mpfr_t quality);
324
#endif
325
#define POBYSO_h  
326
  
327
#endif
328