Statistiques
| Révision :

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

Historique | Voir | Annoter | Télécharger (9,34 ko)

1 26 storres
/** @file pobyso.h
2 26 storres
 * Integration of Sollya to C programs
3 26 storres
 * @author S.T.
4 26 storres
 * @date 2011-10-11
5 26 storres
 * Note: pobyso stands for POwered BY SOllya.
6 26 storres
 *                         --      -- --
7 26 storres
 */
8 26 storres
/******************************************************************************/
9 26 storres
10 26 storres
/*
11 26 storres
 * Add below all the headers needed to get this header work.
12 26 storres
 */
13 26 storres
/* <stdio.h> is needed *before* <mpfr.h> for all MPFR input/output functions
14 26 storres
 * prototypes be defined. */
15 127 storres
#include <string.h>
16 26 storres
#include <stdio.h>
17 26 storres
#include <sollya.h>
18 26 storres
#include <mpfr.h>
19 26 storres
20 26 storres
#ifndef POBYSO_h
21 26 storres
22 128 storres
/* Typedefs to make code more readable. */
23 132 storres
24 128 storres
typedef sollya_obj_t pobyso_error_t;
25 130 storres
typedef sollya_obj_t pobyso_func_exp_t;
26 132 storres
typedef sollya_obj_t pobyso_on_off_t;
27 128 storres
typedef sollya_obj_t pobyso_precision_t;
28 128 storres
typedef sollya_obj_t pobyso_range_t;
29 132 storres
typedef sollya_obj_t pobyso_sollya_verbosity_t;
30 128 storres
31 132 storres
#define POBYSO_ABSOLUTE (1)
32 132 storres
#define POBYSO_RELATIVE (2)
33 128 storres
34 132 storres
#define POBYSO_OFF (0)
35 132 storres
#define POBYSO_ON (1)
36 128 storres
37 26 storres
/* Mimic the default behavior of interactive Sollya. */
38 26 storres
#define POBYSO_DEFAULT_POINTS 501
39 26 storres
#define POBYSO_INF_NORM_NUM_POINTS (POBYSO_DEFAULT_POINTS)
40 26 storres
#define POBYSO_GUESS_DEGREE_BOUND 1024
41 26 storres
42 128 storres
43 128 storres
/* Very thin wrappers around a lot of Sollya functions.
44 128 storres
 */
45 128 storres
static inline pobyso_error_t pobyso_error(void)
46 128 storres
{return(sollya_lib_error());}
47 128 storres
48 128 storres
static inline int pobyso_is_error(sollya_obj_t errorCandidate)
49 128 storres
{return(sollya_lib_obj_is_error(errorCandidate));}
50 128 storres
51 128 storres
static inline int pobyso_is_function(sollya_obj_t functionCandidate)
52 128 storres
{return(sollya_lib_obj_is_function(functionCandidate));}
53 128 storres
54 26 storres
/**
55 26 storres
 * Print object(s) to stdout.
56 134 storres
 * A very thin wrapper around the lib_sollya_autoprint() function.
57 26 storres
 */
58 26 storres
void
59 134 storres
pobyso_autoprint(sollya_obj_t soObj);
60 26 storres
61 26 storres
/**
62 26 storres
 * Print object(s) to stdout: the va_list companion function.
63 26 storres
 * A very thin wrapper around the lib_sollya_v_autoprint() function.
64 26 storres
 * The last argument in the va_list should be NULL.
65 26 storres
 */
66 26 storres
67 26 storres
void
68 26 storres
pobyso_autoprint_v(sollya_obj_t soObj, va_list va);
69 26 storres
70 133 storres
/**
71 134 storres
 * Get the current verbosity level.
72 134 storres
 * @return an integer at the current verbosity level.
73 134 storres
 */
74 134 storres
int
75 134 storres
pobyso_get_verbosity();
76 134 storres
77 134 storres
/**
78 133 storres
 * Check if a sollya object is a constant expression.
79 133 storres
 * @return 1 if true and zero otherwise
80 133 storres
 */
81 133 storres
int
82 133 storres
pobyso_is_constant_expression(sollya_obj_t obj_to_text);
83 132 storres
84 26 storres
/**
85 133 storres
 * Create a Sollya monomial from a Sollya constant,
86 134 storres
 * the coefficient, and an integer, the exponent.
87 134 storres
 * @param coefficient must be a non NULL constant expression;
88 134 storres
 * @param degree must be a non negative integer;
89 133 storres
 * @return a Sollya functional expression if successes, or a Sollya error
90 133 storres
 * if fails.
91 26 storres
 */
92 134 storres
pobyso_func_exp_t
93 133 storres
pobyso_new_monomial(pobyso_func_exp_t coefficient, long degree);
94 128 storres
95 128 storres
/**
96 128 storres
 * A wrapper around the Sollya Remez function.
97 128 storres
 */
98 128 storres
/**
99 128 storres
 * Parse a string to create a Sollya object.
100 128 storres
 * A very thin wrapper around the sollya_lib_parse_string() function.
101 128 storres
 * If the final ";" is forgotten in the expression, it is added by the
102 128 storres
 * function.
103 133 storres
 * @return a Sollya functional expression if successes, or a Sollya error
104 133 storres
 * if fails.
105 128 storres
 */
106 134 storres
pobyso_func_exp_t
107 26 storres
pobyso_parse_string(const char* expression);
108 26 storres
109 26 storres
/**
110 128 storres
 * A wrapper around the Sollya Remez function with the canonical monomials
111 128 storres
 * base.
112 128 storres
 */
113 128 storres
114 130 storres
pobyso_func_exp_t
115 130 storres
pobyso_remez_canonical_monomials_base(pobyso_func_exp_t function,
116 128 storres
                                      long int degree,
117 128 storres
                                      pobyso_range_t interval,
118 130 storres
                                      pobyso_func_exp_t weight,
119 128 storres
                                      double quality,
120 128 storres
                                      pobyso_range_t bounds);
121 128 storres
122 128 storres
/**
123 128 storres
 * A wrapper around the Sollya Remez function with the a sparse monomials
124 128 storres
 * base.
125 128 storres
 */
126 128 storres
127 130 storres
pobyso_func_exp_t
128 130 storres
pobyso_remez_sparse_monomials_base(pobyso_func_exp_t);
129 128 storres
130 128 storres
/**
131 128 storres
 * A wrapper around the Sollya Remez function with the canonical monomials
132 128 storres
 * base.
133 128 storres
 */
134 128 storres
135 130 storres
pobyso_func_exp_t
136 130 storres
pobyso_remez_arbitrary_base(pobyso_func_exp_t);
137 128 storres
138 132 storres
/**
139 132 storres
 * Set the canonical mode.
140 132 storres
 */
141 128 storres
142 132 storres
int
143 132 storres
pobyso_set_canonical_on(void);
144 128 storres
145 128 storres
/**
146 26 storres
 * Set the verbosity mode off (level 0).
147 132 storres
 * The current level of verbosity is returned.
148 26 storres
 */
149 134 storres
int
150 128 storres
pobyso_set_verbosity_off(void);
151 26 storres
152 26 storres
/**
153 26 storres
 * Set the verbosity level to newVerbosityLevel.
154 132 storres
 * @param newVerbosityLevel must be a Sollya object corresponding to an
155 26 storres
 *        integer constant.
156 26 storres
 */
157 134 storres
int
158 134 storres
pobyso_set_verbosity_to(int newVerbosityLevel);
159 26 storres
160 132 storres
/**
161 134 storres
 * Wrapper around the sollya_lib_subpoly Sollya function.
162 134 storres
 */
163 132 storres
164 134 storres
pobyso_func_exp_t
165 134 storres
pobyso_subpoly(pobyso_func_exp_t polynomial, long expsNum,...);
166 134 storres
167 26 storres
#if 0
168 26 storres
/**
169 26 storres
 * Create the canonical (non sparse) base of monomials for a given degree.
170 26 storres
 */
171 26 storres
chain*
172 26 storres
pobyso_create_canonical_monomials_base(const unsigned int degree);
173 26 storres

174 26 storres
/**
175 26 storres
 * Create a chain from an array of int.
176 26 storres
 */
177 26 storres
sollya_int_list
178 26 storres
pobyso_create_int_list_from_int_Array(int* intArray,
179 26 storres
                                    const unsigned int arrayLength);
180 26 storres

181 26 storres
/**
182 26 storres
 * Create a chain from an array of int.
183 26 storres
 */
184 26 storres
sollya_int_list_t
185 26 storres
pobyso_create_int_list_from_unsigned_int_array(unsigned int* intArray,
186 26 storres
                                            const unsigned int arrayLength);
187 26 storres
/**
188 26 storres
 * Differentiation of a function.
189 26 storres
 * A slim wrapper around the Sollya differentiate function.
190 26 storres
 * @param functionNode - the Sollya node to differentiate;
191 26 storres
 * @return a node representing the function differentiated or NULL, if
192 26 storres
 *         something goes wrong.
193 26 storres
 */
194 26 storres

195 26 storres
sollya_obj_t
196 26 storres
pobyso_diff(sollya_obj_t function);
197 26 storres

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

216 26 storres

217 26 storres
/**
218 26 storres
 * Faithful evaluation of an expression.
219 26 storres
 *
220 26 storres
 * @param faitufulEvaluation - holds the result, must be "inited" by the
221 26 storres
 *                             caller;
222 26 storres
 */
223 26 storres
int
224 26 storres
pobyso_evaluate_faithful(mpfr_t faithfulEvaluation,
225 26 storres
                          node *nodeToEvaluate,
226 26 storres
                          mpfr_t argument,
227 26 storres
                          mpfr_prec_t precision);
228 26 storres

229 26 storres
/**
230 26 storres
 * Find the zeros of a function on a given interval.
231 26 storres
 */
232 26 storres
chain*
233 26 storres
pobyso_find_zeros(node *function,
234 26 storres
                  mpfr_t *lowerBound,
235 26 storres
                  mpfr_t *upperBound);
236 26 storres
/**
237 26 storres
 * Free a chain of node.
238 26 storres
 * All elements of the chain have to be nodes.
239 26 storres
 */
240 26 storres
void
241 26 storres
pobyso_free_chain_of_nodes(chain *theChain);
242 26 storres

243 26 storres
/**
244 26 storres
 * Free a range.
245 26 storres
 * It involves clearing the mpfr_t elements and deallocating the
246 26 storres
 * pointers.
247 26 storres
 */
248 26 storres
void
249 26 storres
pobyso_free_range(rangetype range);
250 26 storres

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

275 26 storres
/** Compute a polynomial approximation in the canonical monomials basis for
276 26 storres
 *  a function, for a given precision. The returned polynomial has the minimal
277 26 storres
 *  degree to achieve the required precision.
278 26 storres
 */
279 26 storres
node*
280 26 storres
pobyso_remez_approx_canonical_monomials_base_for_error(node *functionNode,
281 26 storres
                                                      unsigned int mode,
282 26 storres
                                                      mpfr_t lowerBound,
283 26 storres
                                                      mpfr_t upperBound,
284 26 storres
                                                      mpfr_t eps);
285 26 storres

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