root / pobysoC-4.0 / src / pobyso.h @ 138
Historique | Voir | Annoter | Télécharger (10,06 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 | 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 | 128 | storres | |
30 | 132 | storres | #define POBYSO_ABSOLUTE (1) |
31 | 132 | storres | #define POBYSO_RELATIVE (2) |
32 | 128 | storres | |
33 | 132 | storres | #define POBYSO_OFF (0) |
34 | 132 | storres | #define POBYSO_ON (1) |
35 | 128 | storres | |
36 | 26 | storres | /* Mimic the default behavior of interactive Sollya. */
|
37 | 26 | storres | #define POBYSO_DEFAULT_POINTS 501 |
38 | 26 | storres | #define POBYSO_INF_NORM_NUM_POINTS (POBYSO_DEFAULT_POINTS)
|
39 | 26 | storres | #define POBYSO_GUESS_DEGREE_BOUND 1024 |
40 | 26 | storres | |
41 | 128 | storres | |
42 | 128 | storres | /* Very thin wrappers around a lot of Sollya functions.
|
43 | 128 | storres | */
|
44 | 128 | storres | static inline pobyso_error_t pobyso_error(void) |
45 | 128 | storres | {return(sollya_lib_error());}
|
46 | 128 | storres | |
47 | 128 | storres | static inline int pobyso_is_error(sollya_obj_t errorCandidate) |
48 | 128 | storres | {return(sollya_lib_obj_is_error(errorCandidate));}
|
49 | 128 | storres | |
50 | 128 | storres | static inline int pobyso_is_function(sollya_obj_t functionCandidate) |
51 | 128 | storres | {return(sollya_lib_obj_is_function(functionCandidate));}
|
52 | 128 | storres | |
53 | 26 | storres | /**
|
54 | 136 | storres | * Print an object to stdout.
|
55 | 134 | storres | * A very thin wrapper around the lib_sollya_autoprint() function.
|
56 | 26 | storres | */
|
57 | 26 | storres | void
|
58 | 137 | storres | pobyso_autoprint(sollya_obj_t objSo); |
59 | 26 | storres | |
60 | 26 | storres | /**
|
61 | 26 | storres | * Print object(s) to stdout: the va_list companion function.
|
62 | 26 | storres | * A very thin wrapper around the lib_sollya_v_autoprint() function.
|
63 | 26 | storres | * The last argument in the va_list should be NULL.
|
64 | 26 | storres | */
|
65 | 26 | storres | |
66 | 26 | storres | void
|
67 | 137 | storres | pobyso_autoprint_v(va_list va); |
68 | 26 | storres | |
69 | 133 | storres | /**
|
70 | 134 | storres | * Get the current verbosity level.
|
71 | 134 | storres | * @return an integer at the current verbosity level.
|
72 | 134 | storres | */
|
73 | 134 | storres | int
|
74 | 134 | storres | pobyso_get_verbosity(); |
75 | 134 | storres | |
76 | 134 | storres | /**
|
77 | 133 | storres | * Check if a sollya object is a constant expression.
|
78 | 133 | storres | * @return 1 if true and zero otherwise
|
79 | 133 | storres | */
|
80 | 133 | storres | int
|
81 | 133 | storres | pobyso_is_constant_expression(sollya_obj_t obj_to_text); |
82 | 132 | storres | |
83 | 26 | storres | /**
|
84 | 138 | storres | * Check if an expression is a monomial (the free variable to an integer
|
85 | 138 | storres | * positive or null power.
|
86 | 137 | storres | * @param exprSo: a Sollya functional expression object;
|
87 | 137 | storres | * @return 1 if exprSo is a monomial (as defined above), 0 otherwise.
|
88 | 137 | storres | */
|
89 | 137 | storres | int pobyso_is_monomial(pobyso_func_exp_t exprSo);
|
90 | 137 | storres | |
91 | 137 | storres | /**
|
92 | 138 | storres | * Check if an expression is a polynomial term (monome)
|
93 | 138 | storres | * (a constant * the free variable to an integer positive or null power or
|
94 | 138 | storres | * the free variable to an integer positive or null power * a constant).
|
95 | 138 | storres | * @param exprSo: a Sollya functional expression object;
|
96 | 138 | storres | * @return 1 if exprSo is a polynomial term (as defined above), 0 otherwise.
|
97 | 138 | storres | */
|
98 | 138 | storres | int pobyso_is_polynomial_term(pobyso_func_exp_t exprSo);
|
99 | 138 | storres | |
100 | 138 | storres | /**
|
101 | 137 | storres | * Check if an expression is an integer.
|
102 | 137 | storres | */
|
103 | 137 | storres | int
|
104 | 137 | storres | pobyso_is_int(pobyso_func_exp_t exprSo); |
105 | 137 | storres | |
106 | 137 | storres | /**
|
107 | 133 | storres | * Create a Sollya monomial from a Sollya constant,
|
108 | 134 | storres | * the coefficient, and an integer, the exponent.
|
109 | 134 | storres | * @param coefficient must be a non NULL constant expression;
|
110 | 134 | storres | * @param degree must be a non negative integer;
|
111 | 133 | storres | * @return a Sollya functional expression if successes, or a Sollya error
|
112 | 133 | storres | * if fails.
|
113 | 26 | storres | */
|
114 | 134 | storres | pobyso_func_exp_t |
115 | 133 | storres | pobyso_new_monomial(pobyso_func_exp_t coefficient, long degree);
|
116 | 128 | storres | |
117 | 128 | storres | /**
|
118 | 128 | storres | * A wrapper around the Sollya Remez function.
|
119 | 128 | storres | */
|
120 | 128 | storres | /**
|
121 | 128 | storres | * Parse a string to create a Sollya object.
|
122 | 128 | storres | * A very thin wrapper around the sollya_lib_parse_string() function.
|
123 | 128 | storres | * If the final ";" is forgotten in the expression, it is added by the
|
124 | 128 | storres | * function.
|
125 | 133 | storres | * @return a Sollya functional expression if successes, or a Sollya error
|
126 | 133 | storres | * if fails.
|
127 | 128 | storres | */
|
128 | 134 | storres | pobyso_func_exp_t |
129 | 26 | storres | pobyso_parse_string(const char* expression); |
130 | 26 | storres | |
131 | 26 | storres | /**
|
132 | 128 | storres | * A wrapper around the Sollya Remez function with the canonical monomials
|
133 | 128 | storres | * base.
|
134 | 128 | storres | */
|
135 | 128 | storres | |
136 | 130 | storres | pobyso_func_exp_t |
137 | 130 | storres | pobyso_remez_canonical_monomials_base(pobyso_func_exp_t function, |
138 | 128 | storres | long int degree, |
139 | 128 | storres | pobyso_range_t interval, |
140 | 130 | storres | pobyso_func_exp_t weight, |
141 | 128 | storres | double quality,
|
142 | 128 | storres | pobyso_range_t bounds); |
143 | 128 | storres | |
144 | 128 | storres | /**
|
145 | 128 | storres | * A wrapper around the Sollya Remez function with the a sparse monomials
|
146 | 128 | storres | * base.
|
147 | 128 | storres | */
|
148 | 128 | storres | |
149 | 130 | storres | pobyso_func_exp_t |
150 | 130 | storres | pobyso_remez_sparse_monomials_base(pobyso_func_exp_t); |
151 | 128 | storres | |
152 | 128 | storres | /**
|
153 | 128 | storres | * A wrapper around the Sollya Remez function with the canonical monomials
|
154 | 128 | storres | * base.
|
155 | 128 | storres | */
|
156 | 128 | storres | |
157 | 130 | storres | pobyso_func_exp_t |
158 | 130 | storres | pobyso_remez_arbitrary_base(pobyso_func_exp_t); |
159 | 128 | storres | |
160 | 132 | storres | /**
|
161 | 132 | storres | * Set the canonical mode.
|
162 | 132 | storres | */
|
163 | 128 | storres | |
164 | 132 | storres | int
|
165 | 132 | storres | pobyso_set_canonical_on(void);
|
166 | 128 | storres | |
167 | 128 | storres | /**
|
168 | 26 | storres | * Set the verbosity mode off (level 0).
|
169 | 132 | storres | * The current level of verbosity is returned.
|
170 | 26 | storres | */
|
171 | 134 | storres | int
|
172 | 128 | storres | pobyso_set_verbosity_off(void);
|
173 | 26 | storres | |
174 | 26 | storres | /**
|
175 | 26 | storres | * Set the verbosity level to newVerbosityLevel.
|
176 | 132 | storres | * @param newVerbosityLevel must be a Sollya object corresponding to an
|
177 | 26 | storres | * integer constant.
|
178 | 26 | storres | */
|
179 | 134 | storres | int
|
180 | 134 | storres | pobyso_set_verbosity_to(int newVerbosityLevel);
|
181 | 26 | storres | |
182 | 132 | storres | /**
|
183 | 134 | storres | * Wrapper around the sollya_lib_subpoly Sollya function.
|
184 | 134 | storres | */
|
185 | 132 | storres | |
186 | 134 | storres | pobyso_func_exp_t |
187 | 136 | storres | pobyso_subpoly(pobyso_func_exp_t polynomial, long expsNum, long* expsList); |
188 | 134 | storres | |
189 | 26 | storres | #if 0
|
190 | 26 | storres | /**
|
191 | 26 | storres | * Create the canonical (non sparse) base of monomials for a given degree.
|
192 | 26 | storres | */
|
193 | 26 | storres | chain*
|
194 | 26 | storres | pobyso_create_canonical_monomials_base(const unsigned int degree);
|
195 | 26 | storres | |
196 | 26 | storres | /**
|
197 | 26 | storres | * Create a chain from an array of int.
|
198 | 26 | storres | */
|
199 | 26 | storres | sollya_int_list
|
200 | 26 | storres | pobyso_create_int_list_from_int_Array(int* intArray,
|
201 | 26 | storres | const unsigned int arrayLength);
|
202 | 26 | storres | |
203 | 26 | storres | /**
|
204 | 26 | storres | * Create a chain from an array of int.
|
205 | 26 | storres | */
|
206 | 26 | storres | sollya_int_list_t
|
207 | 26 | storres | pobyso_create_int_list_from_unsigned_int_array(unsigned int* intArray,
|
208 | 26 | storres | const unsigned int arrayLength);
|
209 | 26 | storres | /**
|
210 | 26 | storres | * Differentiation of a function.
|
211 | 26 | storres | * A slim wrapper around the Sollya differentiate function.
|
212 | 26 | storres | * @param functionNode - the Sollya node to differentiate;
|
213 | 26 | storres | * @return a node representing the function differentiated or NULL, if
|
214 | 26 | storres | * something goes wrong.
|
215 | 26 | storres | */
|
216 | 26 | storres | |
217 | 26 | storres | sollya_obj_t
|
218 | 26 | storres | pobyso_diff(sollya_obj_t function);
|
219 | 26 | storres | |
220 | 26 | storres | /**
|
221 | 26 | storres | * A match to the Sollya dirtyinfnorm.
|
222 | 26 | storres | * A slim wrapper around the Sollya function.
|
223 | 26 | storres | * @param infnorm - out parameter to return the result, must be "inited"
|
224 | 26 | storres | * and "cleared" by the caller;
|
225 | 26 | storres | * @param functionNode - the Sollya node to compute the infinite norm of;
|
226 | 26 | storres | * @param lowerBound - the lower bound of the interval;
|
227 | 26 | storres | * @param upperBound - the upper bound of the interval;
|
228 | 26 | storres | * @param precision - the internal precision Sollya must use.
|
229 | 26 | storres | * @return 0 if everything is OK, != 0 if something goes wrong.
|
230 | 26 | storres | */
|
231 | 26 | storres | int
|
232 | 26 | storres | pobyso_dirty_infnorm(mpfr_t infNorm,
|
233 | 26 | storres | node *functionNode,
|
234 | 26 | storres | mpfr_t lowerBound,
|
235 | 26 | storres | mpfr_t upperBound,
|
236 | 26 | storres | mp_prec_t precision);
|
237 | 26 | storres | |
238 | 26 | storres | |
239 | 26 | storres | /**
|
240 | 26 | storres | * Faithful evaluation of an expression.
|
241 | 26 | storres | *
|
242 | 26 | storres | * @param faitufulEvaluation - holds the result, must be "inited" by the
|
243 | 26 | storres | * caller;
|
244 | 26 | storres | */
|
245 | 26 | storres | int
|
246 | 26 | storres | pobyso_evaluate_faithful(mpfr_t faithfulEvaluation,
|
247 | 26 | storres | node *nodeToEvaluate,
|
248 | 26 | storres | mpfr_t argument,
|
249 | 26 | storres | mpfr_prec_t precision);
|
250 | 26 | storres | |
251 | 26 | storres | /**
|
252 | 26 | storres | * Find the zeros of a function on a given interval.
|
253 | 26 | storres | */
|
254 | 26 | storres | chain*
|
255 | 26 | storres | pobyso_find_zeros(node *function,
|
256 | 26 | storres | mpfr_t *lowerBound,
|
257 | 26 | storres | mpfr_t *upperBound);
|
258 | 26 | storres | /**
|
259 | 26 | storres | * Free a chain of node.
|
260 | 26 | storres | * All elements of the chain have to be nodes.
|
261 | 26 | storres | */
|
262 | 26 | storres | void
|
263 | 26 | storres | pobyso_free_chain_of_nodes(chain *theChain);
|
264 | 26 | storres | |
265 | 26 | storres | /**
|
266 | 26 | storres | * Free a range.
|
267 | 26 | storres | * It involves clearing the mpfr_t elements and deallocating the
|
268 | 26 | storres | * pointers.
|
269 | 26 | storres | */
|
270 | 26 | storres | void
|
271 | 26 | storres | pobyso_free_range(rangetype range);
|
272 | 26 | storres | |
273 | 26 | storres | /**
|
274 | 26 | storres | * Computes a good polynomial approximation with fixed-point or floating-point
|
275 | 26 | storres | * coefficients.
|
276 | 26 | storres | */
|
277 | 26 | storres | node*
|
278 | 26 | storres | pobyso_fp_minimax_canonical_monomials_base(node *function,
|
279 | 26 | storres | int degree,
|
280 | 26 | storres | chain *formats,
|
281 | 26 | storres | chain *points,
|
282 | 26 | storres | mpfr_t lowerBound,
|
283 | 26 | storres | mpfr_t upperBound,
|
284 | 26 | storres | int fpFixedArg,
|
285 | 26 | storres | int absRel,
|
286 | 26 | storres | node *constPart,
|
287 | 26 | storres | node *minimax);
|
288 | 26 | storres | /**
|
289 | 26 | storres | * Parses a string to build the node representing the function.
|
290 | 26 | storres | * In fact, does nothing for the moment: the string must be a correct function
|
291 | 26 | storres | * definition. No error correction takes place here.
|
292 | 26 | storres | */
|
293 | 26 | storres | node*
|
294 | 26 | storres | pobyso_parse_function(char *functionString,
|
295 | 26 | storres | char *freeVariableNameString);
|
296 | 26 | storres | |
297 | 26 | storres | /** Compute a polynomial approximation in the canonical monomials basis for
|
298 | 26 | storres | * a function, for a given precision. The returned polynomial has the minimal
|
299 | 26 | storres | * degree to achieve the required precision.
|
300 | 26 | storres | */
|
301 | 26 | storres | node*
|
302 | 26 | storres | pobyso_remez_approx_canonical_monomials_base_for_error(node *functionNode,
|
303 | 26 | storres | unsigned int mode,
|
304 | 26 | storres | mpfr_t lowerBound,
|
305 | 26 | storres | mpfr_t upperBound,
|
306 | 26 | storres | mpfr_t eps);
|
307 | 26 | storres | |
308 | 26 | storres | /**
|
309 | 26 | storres | * Computes a the remez approximation of a function.
|
310 | 26 | storres | * @param function - the node holding the function to approximate;
|
311 | 26 | storres | * @param weight - the node holding the weight function, can be NULL. In
|
312 | 26 | storres | * this case a default weight of "1" will be provided and
|
313 | 26 | storres | * the approximation is related is with respect to the
|
314 | 26 | storres | * absolute error.
|
315 | 26 | storres | * @param degree - the degree of the approximation polynomial;
|
316 | 26 | storres | * @param lowerBound - the lower bound of the approximation interval;
|
317 | 26 | storres | * @param upperBound - the upper bound of the approximation interval;
|
318 | 26 | storres | * @param quality - quality = (eps - eps*) / eps*; the search stop when the required
|
319 | 26 | storres | * quality is achieved.
|
320 | 26 | storres | *
|
321 | 26 | storres | * @return a node holding the approximation polynomial in Horner form.
|
322 | 26 | storres | */
|
323 | 26 | storres | node*
|
324 | 26 | storres | pobyso_remez_canonical_monomials_base(node *function,
|
325 | 26 | storres | node *weight,
|
326 | 26 | storres | unsigned int degree,
|
327 | 26 | storres | mpfr_t lowerBound,
|
328 | 26 | storres | mpfr_t upperBound,
|
329 | 26 | storres | mpfr_t quality);
|
330 | 26 | storres | #endif
|
331 | 26 | storres | #define POBYSO_h
|
332 | 26 | storres | |
333 | 26 | storres | #endif
|