root / pobysoC-4.0 / src / pobyso.h @ 287
Historique | Voir | Annoter | Télécharger (12,74 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 | 137 | storres | * @note pobyso stands for POwered BY SOllya.
|
6 | 137 | storres | * @todo -- -- --
|
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 | 150 | storres | typedef sollya_obj_t pobyso_constant_t;
|
25 | 128 | storres | typedef sollya_obj_t pobyso_error_t;
|
26 | 130 | storres | typedef sollya_obj_t pobyso_func_exp_t;
|
27 | 132 | storres | typedef sollya_obj_t pobyso_on_off_t;
|
28 | 146 | storres | typedef mpfr_prec_t pobyso_precision_t;
|
29 | 128 | storres | typedef sollya_obj_t pobyso_range_t;
|
30 | 128 | storres | |
31 | 132 | storres | #define POBYSO_ABSOLUTE (1) |
32 | 132 | storres | #define POBYSO_RELATIVE (2) |
33 | 128 | storres | |
34 | 146 | storres | #define POBYSO_UNFAITHFUL (129) |
35 | 139 | storres | #define POBYSO_NAN (130) |
36 | 139 | storres | |
37 | 132 | storres | #define POBYSO_OFF (0) |
38 | 132 | storres | #define POBYSO_ON (1) |
39 | 128 | storres | |
40 | 26 | storres | /* Mimic the default behavior of interactive Sollya. */
|
41 | 26 | storres | #define POBYSO_DEFAULT_POINTS 501 |
42 | 26 | storres | #define POBYSO_INF_NORM_NUM_POINTS (POBYSO_DEFAULT_POINTS)
|
43 | 26 | storres | #define POBYSO_GUESS_DEGREE_BOUND 1024 |
44 | 26 | storres | |
45 | 128 | storres | |
46 | 128 | storres | /* Very thin wrappers around a lot of Sollya functions.
|
47 | 128 | storres | */
|
48 | 128 | storres | static inline pobyso_error_t pobyso_error(void) |
49 | 128 | storres | {return(sollya_lib_error());}
|
50 | 128 | storres | |
51 | 128 | storres | static inline int pobyso_is_error(sollya_obj_t errorCandidate) |
52 | 128 | storres | {return(sollya_lib_obj_is_error(errorCandidate));}
|
53 | 128 | storres | |
54 | 128 | storres | static inline int pobyso_is_function(sollya_obj_t functionCandidate) |
55 | 128 | storres | {return(sollya_lib_obj_is_function(functionCandidate));}
|
56 | 128 | storres | |
57 | 26 | storres | /**
|
58 | 136 | storres | * Print an object to stdout.
|
59 | 134 | storres | * A very thin wrapper around the lib_sollya_autoprint() function.
|
60 | 26 | storres | */
|
61 | 26 | storres | void
|
62 | 137 | storres | pobyso_autoprint(sollya_obj_t objSo); |
63 | 26 | storres | |
64 | 26 | storres | /**
|
65 | 26 | storres | * Print object(s) to stdout: the va_list companion function.
|
66 | 26 | storres | * A very thin wrapper around the lib_sollya_v_autoprint() function.
|
67 | 26 | storres | * The last argument in the va_list should be NULL.
|
68 | 26 | storres | */
|
69 | 26 | storres | |
70 | 26 | storres | void
|
71 | 137 | storres | pobyso_autoprint_v(va_list va); |
72 | 26 | storres | |
73 | 287 | storres | /** A very thin wrapper around the sollya_lib_clear_obj
|
74 | 287 | storres | * function.
|
75 | 287 | storres | * @param objSo: the Sollya object to free.
|
76 | 287 | storres | */
|
77 | 287 | storres | void
|
78 | 287 | storres | pobyso_clear_obj(sollya_obj_t objSo); |
79 | 287 | storres | |
80 | 133 | storres | /**
|
81 | 146 | storres | * A wrapper around the Sollya dirtyfindzeros function.
|
82 | 146 | storres | * Find the numerical values of the zeroes of the funcExpSo expression over
|
83 | 146 | storres | * the [lowerBoundMp, upperBoundMp] interval.
|
84 | 146 | storres | * @param funcExpSo: a Sollya functional expression;
|
85 | 146 | storres | * @param lowerBoundMp: the lower bound as an MPFR number;
|
86 | 146 | storres | * @param upperBoundMp: the upper bound as an MPFR number;
|
87 | 146 | storres | * @param zerosCount: a pointer to the int where the number of zeros will be
|
88 | 146 | storres | * stored;
|
89 | 146 | storres | * @return a (possibly empty) list of the zeroes of the function or NULL if
|
90 | 146 | storres | * something goes wrong or there are no zeroes. *zerosCount should
|
91 | 146 | storres | * always be tested first.
|
92 | 146 | storres | * If *zeroCounts == 0 the function returns NULL. No deallocation is
|
93 | 146 | storres | * needed.
|
94 | 146 | storres | * If *zeroCounts >= 0, the list must be deallocated by the caller
|
95 | 146 | storres | * after each of the elements has been "mpfr_cleared".
|
96 | 146 | storres | * if something goes wrong *zeroCounts < 0.
|
97 | 146 | storres | */
|
98 | 146 | storres | mpfr_t * |
99 | 146 | storres | pobyso_dirty_find_zeros_bounds(pobyso_func_exp_t funcExpSo, |
100 | 146 | storres | mpfr_t lowerBoundMp, |
101 | 146 | storres | mpfr_t upperBoundMp, |
102 | 146 | storres | int* zerosCount);
|
103 | 146 | storres | |
104 | 146 | storres | /**
|
105 | 134 | storres | * Get the current verbosity level.
|
106 | 134 | storres | * @return an integer at the current verbosity level.
|
107 | 134 | storres | */
|
108 | 134 | storres | int
|
109 | 134 | storres | pobyso_get_verbosity(); |
110 | 134 | storres | |
111 | 134 | storres | /**
|
112 | 139 | storres | * Evaluate an expression for a constant.
|
113 | 139 | storres | *
|
114 | 139 | storres | * The result of the evaluation must be "inited" by the caller.
|
115 | 140 | storres | * Its contents is modified only if the evaluation yields some useful
|
116 | 140 | storres | * result. In this case, its precision may change too.
|
117 | 139 | storres | *@param functionSo : the function to evaluate;
|
118 | 139 | storres | *@param argumentMp : the argument used for the evaluation;
|
119 | 149 | storres | *@param evalutionMp: the result of the evaluation.
|
120 | 287 | storres | *@return 0 if 0K, 1 in case of a "generic" error or POBYSO_UNFAITHFULL
|
121 | 287 | storres | * if the result is the mean of the two bound of the range
|
122 | 287 | storres | * encompassing it and POBYSO_NAN if the result of the evaluation
|
123 | 287 | storres | * is not a number.
|
124 | 139 | storres | */
|
125 | 139 | storres | int
|
126 | 139 | storres | pobyso_evaluate_constant(pobyso_func_exp_t functionSo, |
127 | 139 | storres | mpfr_t argumentMp, |
128 | 139 | storres | mpfr_t evaluationMp); |
129 | 139 | storres | /**
|
130 | 133 | storres | * Check if a sollya object is a constant expression.
|
131 | 133 | storres | * @return 1 if true and zero otherwise
|
132 | 133 | storres | */
|
133 | 133 | storres | int
|
134 | 150 | storres | pobyso_is_constant_expression(sollya_obj_t objToTestSo); |
135 | 132 | storres | |
136 | 26 | storres | /**
|
137 | 138 | storres | * Check if an expression is a monomial (the free variable to an integer
|
138 | 138 | storres | * positive or null power.
|
139 | 137 | storres | * @param exprSo: a Sollya functional expression object;
|
140 | 137 | storres | * @return 1 if exprSo is a monomial (as defined above), 0 otherwise.
|
141 | 137 | storres | */
|
142 | 137 | storres | int pobyso_is_monomial(pobyso_func_exp_t exprSo);
|
143 | 137 | storres | |
144 | 137 | storres | /**
|
145 | 138 | storres | * Check if an expression is a polynomial term (monome)
|
146 | 138 | storres | * (a constant * the free variable to an integer positive or null power or
|
147 | 138 | storres | * the free variable to an integer positive or null power * a constant).
|
148 | 138 | storres | * @param exprSo: a Sollya functional expression object;
|
149 | 138 | storres | * @return 1 if exprSo is a polynomial term (as defined above), 0 otherwise.
|
150 | 138 | storres | */
|
151 | 138 | storres | int pobyso_is_polynomial_term(pobyso_func_exp_t exprSo);
|
152 | 138 | storres | |
153 | 138 | storres | /**
|
154 | 137 | storres | * Check if an expression is an integer.
|
155 | 137 | storres | */
|
156 | 137 | storres | int
|
157 | 137 | storres | pobyso_is_int(pobyso_func_exp_t exprSo); |
158 | 137 | storres | |
159 | 137 | storres | /**
|
160 | 133 | storres | * Create a Sollya monomial from a Sollya constant,
|
161 | 134 | storres | * the coefficient, and an integer, the exponent.
|
162 | 134 | storres | * @param coefficient must be a non NULL constant expression;
|
163 | 134 | storres | * @param degree must be a non negative integer;
|
164 | 133 | storres | * @return a Sollya functional expression if successes, or a Sollya error
|
165 | 133 | storres | * if fails.
|
166 | 26 | storres | */
|
167 | 134 | storres | pobyso_func_exp_t |
168 | 133 | storres | pobyso_new_monomial(pobyso_func_exp_t coefficient, long degree);
|
169 | 128 | storres | |
170 | 128 | storres | /**
|
171 | 149 | storres | * Create a Sollya "off" object. */
|
172 | 149 | storres | pobyso_on_off_t |
173 | 149 | storres | pobyso_on(); |
174 | 149 | storres | |
175 | 149 | storres | /**
|
176 | 149 | storres | * Create a Sollya "on" object. */
|
177 | 149 | storres | pobyso_on_off_t |
178 | 149 | storres | pobyso_off(); |
179 | 149 | storres | |
180 | 149 | storres | /**
|
181 | 128 | storres | * A wrapper around the Sollya Remez function.
|
182 | 128 | storres | */
|
183 | 128 | storres | /**
|
184 | 128 | storres | * Parse a string to create a Sollya object.
|
185 | 128 | storres | * A very thin wrapper around the sollya_lib_parse_string() function.
|
186 | 128 | storres | * If the final ";" is forgotten in the expression, it is added by the
|
187 | 128 | storres | * function.
|
188 | 133 | storres | * @return a Sollya functional expression if successes, or a Sollya error
|
189 | 133 | storres | * if fails.
|
190 | 128 | storres | */
|
191 | 134 | storres | pobyso_func_exp_t |
192 | 26 | storres | pobyso_parse_string(const char* expression); |
193 | 26 | storres | |
194 | 150 | storres | /** Disable the console output from Sollya.
|
195 | 150 | storres | * @return a Sollya constant holding the current verbosity level
|
196 | 150 | storres | * when Sollya was silenced or NULL, if something goes wrong.*/
|
197 | 150 | storres | pobyso_constant_t |
198 | 150 | storres | pobyso_quiet(); |
199 | 150 | storres | |
200 | 149 | storres | /** Create a Sollya range from two MPFR bounds.
|
201 | 149 | storres | * A wrapper around sollya_lib_range_from_bounds.
|
202 | 149 | storres | */
|
203 | 149 | storres | pobyso_range_t |
204 | 149 | storres | pobyso_range_from_bounds(mpfr_t lowerBound, mpfr_t upperBound); |
205 | 149 | storres | |
206 | 26 | storres | /**
|
207 | 128 | storres | * A wrapper around the Sollya Remez function with the canonical monomials
|
208 | 128 | storres | * base.
|
209 | 128 | storres | */
|
210 | 128 | storres | |
211 | 130 | storres | pobyso_func_exp_t |
212 | 130 | storres | pobyso_remez_canonical_monomials_base(pobyso_func_exp_t function, |
213 | 128 | storres | long int degree, |
214 | 128 | storres | pobyso_range_t interval, |
215 | 130 | storres | pobyso_func_exp_t weight, |
216 | 128 | storres | double quality,
|
217 | 128 | storres | pobyso_range_t bounds); |
218 | 128 | storres | |
219 | 128 | storres | /**
|
220 | 128 | storres | * A wrapper around the Sollya Remez function with the a sparse monomials
|
221 | 128 | storres | * base.
|
222 | 128 | storres | */
|
223 | 128 | storres | |
224 | 130 | storres | pobyso_func_exp_t |
225 | 130 | storres | pobyso_remez_sparse_monomials_base(pobyso_func_exp_t); |
226 | 128 | storres | |
227 | 128 | storres | /**
|
228 | 128 | storres | * A wrapper around the Sollya Remez function with the canonical monomials
|
229 | 128 | storres | * base.
|
230 | 128 | storres | */
|
231 | 128 | storres | |
232 | 130 | storres | pobyso_func_exp_t |
233 | 130 | storres | pobyso_remez_arbitrary_base(pobyso_func_exp_t); |
234 | 128 | storres | |
235 | 132 | storres | /**
|
236 | 132 | storres | * Set the canonical mode.
|
237 | 132 | storres | */
|
238 | 128 | storres | |
239 | 132 | storres | int
|
240 | 132 | storres | pobyso_set_canonical_on(void);
|
241 | 128 | storres | |
242 | 128 | storres | /**
|
243 | 26 | storres | * Set the verbosity mode off (level 0).
|
244 | 132 | storres | * The current level of verbosity is returned.
|
245 | 26 | storres | */
|
246 | 134 | storres | int
|
247 | 128 | storres | pobyso_set_verbosity_off(void);
|
248 | 26 | storres | |
249 | 26 | storres | /**
|
250 | 26 | storres | * Set the verbosity level to newVerbosityLevel.
|
251 | 132 | storres | * @param newVerbosityLevel must be a Sollya object corresponding to an
|
252 | 26 | storres | * integer constant.
|
253 | 26 | storres | */
|
254 | 134 | storres | int
|
255 | 134 | storres | pobyso_set_verbosity_to(int newVerbosityLevel);
|
256 | 26 | storres | |
257 | 132 | storres | /**
|
258 | 134 | storres | * Wrapper around the sollya_lib_subpoly Sollya function.
|
259 | 134 | storres | */
|
260 | 132 | storres | |
261 | 134 | storres | pobyso_func_exp_t |
262 | 136 | storres | pobyso_subpoly(pobyso_func_exp_t polynomial, long expsNum, long* expsList); |
263 | 134 | storres | |
264 | 26 | storres | #if 0
|
265 | 26 | storres | /**
|
266 | 26 | storres | * Create the canonical (non sparse) base of monomials for a given degree.
|
267 | 26 | storres | */
|
268 | 26 | storres | chain*
|
269 | 26 | storres | pobyso_create_canonical_monomials_base(const unsigned int degree);
|
270 | 26 | storres | |
271 | 26 | storres | /**
|
272 | 26 | storres | * Create a chain from an array of int.
|
273 | 26 | storres | */
|
274 | 26 | storres | sollya_int_list
|
275 | 26 | storres | pobyso_create_int_list_from_int_Array(int* intArray,
|
276 | 26 | storres | const unsigned int arrayLength);
|
277 | 26 | storres | |
278 | 26 | storres | /**
|
279 | 26 | storres | * Create a chain from an array of int.
|
280 | 26 | storres | */
|
281 | 26 | storres | sollya_int_list_t
|
282 | 26 | storres | pobyso_create_int_list_from_unsigned_int_array(unsigned int* intArray,
|
283 | 26 | storres | const unsigned int arrayLength);
|
284 | 26 | storres | /**
|
285 | 26 | storres | * Differentiation of a function.
|
286 | 26 | storres | * A slim wrapper around the Sollya differentiate function.
|
287 | 26 | storres | * @param functionNode - the Sollya node to differentiate;
|
288 | 26 | storres | * @return a node representing the function differentiated or NULL, if
|
289 | 26 | storres | * something goes wrong.
|
290 | 26 | storres | */
|
291 | 26 | storres | |
292 | 26 | storres | sollya_obj_t
|
293 | 26 | storres | pobyso_diff(sollya_obj_t function);
|
294 | 26 | storres | |
295 | 26 | storres | /**
|
296 | 26 | storres | * A match to the Sollya dirtyinfnorm.
|
297 | 26 | storres | * A slim wrapper around the Sollya function.
|
298 | 26 | storres | * @param infnorm - out parameter to return the result, must be "inited"
|
299 | 26 | storres | * and "cleared" by the caller;
|
300 | 26 | storres | * @param functionNode - the Sollya node to compute the infinite norm of;
|
301 | 26 | storres | * @param lowerBound - the lower bound of the interval;
|
302 | 26 | storres | * @param upperBound - the upper bound of the interval;
|
303 | 26 | storres | * @param precision - the internal precision Sollya must use.
|
304 | 26 | storres | * @return 0 if everything is OK, != 0 if something goes wrong.
|
305 | 26 | storres | */
|
306 | 26 | storres | int
|
307 | 26 | storres | pobyso_dirty_infnorm(mpfr_t infNorm,
|
308 | 26 | storres | node *functionNode,
|
309 | 26 | storres | mpfr_t lowerBound,
|
310 | 26 | storres | mpfr_t upperBound,
|
311 | 26 | storres | mp_prec_t precision);
|
312 | 26 | storres | |
313 | 26 | storres | |
314 | 26 | storres | /**
|
315 | 26 | storres | * Faithful evaluation of an expression.
|
316 | 26 | storres | *
|
317 | 287 | storres | * @param faithfulEvaluation - holds the result, must be "inited" by the
|
318 | 26 | storres | * caller;
|
319 | 26 | storres | */
|
320 | 26 | storres | int
|
321 | 26 | storres | pobyso_evaluate_faithful(mpfr_t faithfulEvaluation,
|
322 | 26 | storres | node *nodeToEvaluate,
|
323 | 26 | storres | mpfr_t argument,
|
324 | 26 | storres | mpfr_prec_t precision);
|
325 | 26 | storres | |
326 | 26 | storres | /**
|
327 | 26 | storres | * Find the zeros of a function on a given interval.
|
328 | 26 | storres | */
|
329 | 26 | storres | chain*
|
330 | 26 | storres | pobyso_find_zeros(node *function,
|
331 | 26 | storres | mpfr_t *lowerBound,
|
332 | 26 | storres | mpfr_t *upperBound);
|
333 | 26 | storres | /**
|
334 | 26 | storres | * Free a chain of node.
|
335 | 26 | storres | * All elements of the chain have to be nodes.
|
336 | 26 | storres | */
|
337 | 26 | storres | void
|
338 | 26 | storres | pobyso_free_chain_of_nodes(chain *theChain);
|
339 | 26 | storres | |
340 | 26 | storres | /**
|
341 | 26 | storres | * Free a range.
|
342 | 26 | storres | * It involves clearing the mpfr_t elements and deallocating the
|
343 | 26 | storres | * pointers.
|
344 | 26 | storres | */
|
345 | 26 | storres | void
|
346 | 26 | storres | pobyso_free_range(rangetype range);
|
347 | 26 | storres | |
348 | 26 | storres | /**
|
349 | 26 | storres | * Computes a good polynomial approximation with fixed-point or floating-point
|
350 | 26 | storres | * coefficients.
|
351 | 26 | storres | */
|
352 | 26 | storres | node*
|
353 | 26 | storres | pobyso_fp_minimax_canonical_monomials_base(node *function,
|
354 | 26 | storres | int degree,
|
355 | 26 | storres | chain *formats,
|
356 | 26 | storres | chain *points,
|
357 | 26 | storres | mpfr_t lowerBound,
|
358 | 26 | storres | mpfr_t upperBound,
|
359 | 26 | storres | int fpFixedArg,
|
360 | 26 | storres | int absRel,
|
361 | 26 | storres | node *constPart,
|
362 | 26 | storres | node *minimax);
|
363 | 26 | storres | /**
|
364 | 26 | storres | * Parses a string to build the node representing the function.
|
365 | 26 | storres | * In fact, does nothing for the moment: the string must be a correct function
|
366 | 26 | storres | * definition. No error correction takes place here.
|
367 | 26 | storres | */
|
368 | 26 | storres | node*
|
369 | 26 | storres | pobyso_parse_function(char *functionString,
|
370 | 26 | storres | char *freeVariableNameString);
|
371 | 26 | storres | |
372 | 26 | storres | /** Compute a polynomial approximation in the canonical monomials basis for
|
373 | 26 | storres | * a function, for a given precision. The returned polynomial has the minimal
|
374 | 26 | storres | * degree to achieve the required precision.
|
375 | 26 | storres | */
|
376 | 26 | storres | node*
|
377 | 26 | storres | pobyso_remez_approx_canonical_monomials_base_for_error(node *functionNode,
|
378 | 26 | storres | unsigned int mode,
|
379 | 26 | storres | mpfr_t lowerBound,
|
380 | 26 | storres | mpfr_t upperBound,
|
381 | 26 | storres | mpfr_t eps);
|
382 | 26 | storres | |
383 | 26 | storres | /**
|
384 | 26 | storres | * Computes a the remez approximation of a function.
|
385 | 26 | storres | * @param function - the node holding the function to approximate;
|
386 | 26 | storres | * @param weight - the node holding the weight function, can be NULL. In
|
387 | 26 | storres | * this case a default weight of "1" will be provided and
|
388 | 26 | storres | * the approximation is related is with respect to the
|
389 | 26 | storres | * absolute error.
|
390 | 26 | storres | * @param degree - the degree of the approximation polynomial;
|
391 | 26 | storres | * @param lowerBound - the lower bound of the approximation interval;
|
392 | 26 | storres | * @param upperBound - the upper bound of the approximation interval;
|
393 | 26 | storres | * @param quality - quality = (eps - eps*) / eps*; the search stop when the required
|
394 | 26 | storres | * quality is achieved.
|
395 | 26 | storres | *
|
396 | 26 | storres | * @return a node holding the approximation polynomial in Horner form.
|
397 | 26 | storres | */
|
398 | 26 | storres | node*
|
399 | 26 | storres | pobyso_remez_canonical_monomials_base(node *function,
|
400 | 26 | storres | node *weight,
|
401 | 26 | storres | unsigned int degree,
|
402 | 26 | storres | mpfr_t lowerBound,
|
403 | 26 | storres | mpfr_t upperBound,
|
404 | 26 | storres | mpfr_t quality);
|
405 | 26 | storres | #endif
|
406 | 26 | storres | #define POBYSO_h
|
407 | 26 | storres | |
408 | 26 | storres | #endif
|