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