Statistiques
| Révision :

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

Historique | Voir | Annoter | Télécharger (10,06 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
/**
84
 * Check if an expression is a monomial (the free variable to an integer
85
 * positive or null power.
86
 * @param exprSo: a Sollya functional expression object;
87
 * @return 1 if exprSo is a monomial (as defined above), 0 otherwise.
88
 */
89
int pobyso_is_monomial(pobyso_func_exp_t exprSo);
90

    
91
/**
92
 * Check if an expression is a polynomial term (monome)
93
 * (a constant * the free variable to an integer positive or null power or
94
 *  the free variable to an integer positive or null power * a constant).
95
 * @param exprSo: a Sollya functional expression object;
96
 * @return 1 if exprSo is a polynomial term (as defined above), 0 otherwise.
97
 */
98
int pobyso_is_polynomial_term(pobyso_func_exp_t exprSo);
99

    
100
/**
101
 * Check if an expression is an integer.
102
 */
103
int
104
pobyso_is_int(pobyso_func_exp_t exprSo);
105

    
106
/**
107
 * Create a Sollya monomial from a Sollya constant,
108
 * the coefficient, and an integer, the exponent.
109
 * @param coefficient must be a non NULL constant expression;
110
 * @param degree must be a non negative integer;
111
 * @return a Sollya functional expression if successes, or a Sollya error
112
 * if fails.
113
 */
114
pobyso_func_exp_t
115
pobyso_new_monomial(pobyso_func_exp_t coefficient, long degree);
116

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

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

    
136
pobyso_func_exp_t
137
pobyso_remez_canonical_monomials_base(pobyso_func_exp_t function,
138
                                      long int degree,
139
                                      pobyso_range_t interval,
140
                                      pobyso_func_exp_t weight,
141
                                      double quality,
142
                                      pobyso_range_t bounds);
143

    
144
/**
145
 * A wrapper around the Sollya Remez function with the a sparse monomials
146
 * base.
147
 */
148

    
149
pobyso_func_exp_t
150
pobyso_remez_sparse_monomials_base(pobyso_func_exp_t);
151

    
152
/**
153
 * A wrapper around the Sollya Remez function with the canonical monomials
154
 * base.
155
 */
156

    
157
pobyso_func_exp_t
158
pobyso_remez_arbitrary_base(pobyso_func_exp_t);
159

    
160
/**
161
 * Set the canonical mode.
162
 */
163

    
164
int
165
pobyso_set_canonical_on(void);
166

    
167
/**
168
 * Set the verbosity mode off (level 0).
169
 * The current level of verbosity is returned.
170
 */
171
int
172
pobyso_set_verbosity_off(void);
173

    
174
/**
175
 * Set the verbosity level to newVerbosityLevel.
176
 * @param newVerbosityLevel must be a Sollya object corresponding to an
177
 *        integer constant.
178
 */
179
int
180
pobyso_set_verbosity_to(int newVerbosityLevel);
181

    
182
/**
183
 * Wrapper around the sollya_lib_subpoly Sollya function.
184
 */
185

    
186
pobyso_func_exp_t
187
pobyso_subpoly(pobyso_func_exp_t polynomial, long expsNum, long* expsList);
188

    
189
#if 0
190
/**
191
 * Create the canonical (non sparse) base of monomials for a given degree.
192
 */
193
chain*
194
pobyso_create_canonical_monomials_base(const unsigned int degree);
195

196
/**
197
 * Create a chain from an array of int.
198
 */
199
sollya_int_list
200
pobyso_create_int_list_from_int_Array(int* intArray,
201
                                    const unsigned int arrayLength);
202

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

217
sollya_obj_t
218
pobyso_diff(sollya_obj_t function);
219

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

238

239
/**
240
 * Faithful evaluation of an expression.
241
 *
242
 * @param faitufulEvaluation - holds the result, must be "inited" by the
243
 *                             caller;
244
 */
245
int
246
pobyso_evaluate_faithful(mpfr_t faithfulEvaluation,
247
                          node *nodeToEvaluate,
248
                          mpfr_t argument,
249
                          mpfr_prec_t precision);
250

251
/**
252
 * Find the zeros of a function on a given interval.
253
 */
254
chain*
255
pobyso_find_zeros(node *function,
256
                  mpfr_t *lowerBound,
257
                  mpfr_t *upperBound);
258
/**
259
 * Free a chain of node.
260
 * All elements of the chain have to be nodes.
261
 */
262
void
263
pobyso_free_chain_of_nodes(chain *theChain);
264

265
/**
266
 * Free a range.
267
 * It involves clearing the mpfr_t elements and deallocating the
268
 * pointers.
269
 */
270
void
271
pobyso_free_range(rangetype range);
272

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

297
/** Compute a polynomial approximation in the canonical monomials basis for
298
 *  a function, for a given precision. The returned polynomial has the minimal
299
 *  degree to achieve the required precision.
300
 */
301
node*
302
pobyso_remez_approx_canonical_monomials_base_for_error(node *functionNode,
303
                                                      unsigned int mode,
304
                                                      mpfr_t lowerBound,
305
                                                      mpfr_t upperBound,
306
                                                      mpfr_t eps);
307

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