root / pobysoC / pobyso.h @ 3
Historique | Voir | Annoter | Télécharger (6,92 ko)
1 | 3 | storres | /** @file pobyso.h
|
---|---|---|---|
2 | 3 | storres | * Integration of Sollya to C programs
|
3 | 3 | storres | * @author S.T.
|
4 | 3 | storres | * @date 2011-10-11
|
5 | 3 | storres | * Note: pobyso stands for POwered BY SOllya.
|
6 | 3 | storres | * -- -- --
|
7 | 3 | storres | */
|
8 | 3 | storres | /******************************************************************************/
|
9 | 3 | storres | |
10 | 3 | storres | /*
|
11 | 3 | storres | * Add below all the headers needed to get this header work.
|
12 | 3 | storres | */
|
13 | 3 | storres | /* <stdio.h> is needed *before* <mpfr.h> for all MPFR input/output functions
|
14 | 3 | storres | * prototypes be defined. */
|
15 | 3 | storres | #include <stdio.h> |
16 | 3 | storres | #include <sollya.h> |
17 | 3 | storres | #include <mpfr.h> |
18 | 3 | storres | |
19 | 3 | storres | #ifndef POBYSO_h
|
20 | 3 | storres | |
21 | 3 | storres | #define POBYSO_ABSOLUTE 1 |
22 | 3 | storres | #define POBYSO_RELATIVE 2 |
23 | 3 | storres | /* Mimic the default behavior of interactive Sollya. */
|
24 | 3 | storres | #define POBYSO_DEFAULT_POINTS 501 |
25 | 3 | storres | #define POBYSO_INF_NORM_NUM_POINTS (POBYSO_DEFAULT_POINTS)
|
26 | 3 | storres | #define POBYSO_GUESS_DEGREE_BOUND 1024 |
27 | 3 | storres | |
28 | 3 | storres | /**
|
29 | 3 | storres | * Print object(s) to stdout.
|
30 | 3 | storres | * A very thin wrapper around the lib_sollya_v_autoprint() function.
|
31 | 3 | storres | * Should be called with NULL as the final argument.
|
32 | 3 | storres | */
|
33 | 3 | storres | void
|
34 | 3 | storres | pobyso_autoprint(sollya_obj_t soObj, ...); |
35 | 3 | storres | |
36 | 3 | storres | /**
|
37 | 3 | storres | * Print object(s) to stdout: the va_list companion function.
|
38 | 3 | storres | * A very thin wrapper around the lib_sollya_v_autoprint() function.
|
39 | 3 | storres | * The last argument in the va_list should be NULL.
|
40 | 3 | storres | */
|
41 | 3 | storres | |
42 | 3 | storres | void
|
43 | 3 | storres | pobyso_autoprint_v(sollya_obj_t soObj, va_list va); |
44 | 3 | storres | |
45 | 3 | storres | /**
|
46 | 3 | storres | * Parse a string to create a Sollya object.
|
47 | 3 | storres | * A very thin wrapper around the sollya_lib_parse_string() function.
|
48 | 3 | storres | */
|
49 | 3 | storres | sollya_obj_t |
50 | 3 | storres | pobyso_parse_string(const char* expression); |
51 | 3 | storres | |
52 | 3 | storres | /**
|
53 | 3 | storres | * Set the verbosity mode off (level 0).
|
54 | 3 | storres | * If currentVerbosity != NULL, currentVerbosity is set
|
55 | 3 | storres | * to the current verbosity level. It may be used to reset the
|
56 | 3 | storres | * verbosity level later.
|
57 | 3 | storres | */
|
58 | 3 | storres | void
|
59 | 3 | storres | pobyso_set_verbosity_off(sollya_obj_t* currentVerbosityLevel); |
60 | 3 | storres | |
61 | 3 | storres | /**
|
62 | 3 | storres | * Set the verbosity level to newVerbosityLevel.
|
63 | 3 | storres | * @param newVerbosityLevel must be a Sollay object corresponding to an
|
64 | 3 | storres | * integer constant.
|
65 | 3 | storres | */
|
66 | 3 | storres | void
|
67 | 3 | storres | pobyso_set_verbosity_to(sollya_obj_t newVerbosityLevel); |
68 | 3 | storres | |
69 | 3 | storres | #if 0
|
70 | 3 | storres | /**
|
71 | 3 | storres | * Create the canonical (non sparse) base of monomials for a given degree.
|
72 | 3 | storres | */
|
73 | 3 | storres | chain*
|
74 | 3 | storres | pobyso_create_canonical_monomials_base(const unsigned int degree);
|
75 | 3 | storres | |
76 | 3 | storres | /**
|
77 | 3 | storres | * Create a chain from an array of int.
|
78 | 3 | storres | */
|
79 | 3 | storres | sollya_int_list
|
80 | 3 | storres | pobyso_create_int_list_from_int_Array(int* intArray,
|
81 | 3 | storres | const unsigned int arrayLength);
|
82 | 3 | storres | |
83 | 3 | storres | /**
|
84 | 3 | storres | * Create a chain from an array of int.
|
85 | 3 | storres | */
|
86 | 3 | storres | sollya_int_list_t
|
87 | 3 | storres | pobyso_create_int_list_from_unsigned_int_array(unsigned int* intArray,
|
88 | 3 | storres | const unsigned int arrayLength);
|
89 | 3 | storres | /**
|
90 | 3 | storres | * Differentiation of a function.
|
91 | 3 | storres | * A slim wrapper around the Sollya differentiate function.
|
92 | 3 | storres | * @param functionNode - the Sollya node to differentiate;
|
93 | 3 | storres | * @return a node representing the function differentiated or NULL, if
|
94 | 3 | storres | * something goes wrong.
|
95 | 3 | storres | */
|
96 | 3 | storres | |
97 | 3 | storres | sollya_obj_t
|
98 | 3 | storres | pobyso_diff(sollya_obj_t function);
|
99 | 3 | storres | |
100 | 3 | storres | /**
|
101 | 3 | storres | * A match to the Sollya dirtyinfnorm.
|
102 | 3 | storres | * A slim wrapper around the Sollya function.
|
103 | 3 | storres | * @param infnorm - out parameter to return the result, must be "inited"
|
104 | 3 | storres | * and "cleared" by the caller;
|
105 | 3 | storres | * @param functionNode - the Sollya node to compute the infinite norm of;
|
106 | 3 | storres | * @param lowerBound - the lower bound of the interval;
|
107 | 3 | storres | * @param upperBound - the upper bound of the interval;
|
108 | 3 | storres | * @param precision - the internal precision Sollya must use.
|
109 | 3 | storres | * @return 0 if everything is OK, != 0 if something goes wrong.
|
110 | 3 | storres | */
|
111 | 3 | storres | int
|
112 | 3 | storres | pobyso_dirty_infnorm(mpfr_t infNorm,
|
113 | 3 | storres | node *functionNode,
|
114 | 3 | storres | mpfr_t lowerBound,
|
115 | 3 | storres | mpfr_t upperBound,
|
116 | 3 | storres | mp_prec_t precision);
|
117 | 3 | storres | |
118 | 3 | storres | |
119 | 3 | storres | /**
|
120 | 3 | storres | * Faithful evaluation of an expression.
|
121 | 3 | storres | *
|
122 | 3 | storres | * @param faitufulEvaluation - holds the result, must be "inited" by the
|
123 | 3 | storres | * caller;
|
124 | 3 | storres | */
|
125 | 3 | storres | int
|
126 | 3 | storres | pobyso_evaluate_faithful(mpfr_t faithfulEvaluation,
|
127 | 3 | storres | node *nodeToEvaluate,
|
128 | 3 | storres | mpfr_t argument,
|
129 | 3 | storres | mpfr_prec_t precision);
|
130 | 3 | storres | |
131 | 3 | storres | /**
|
132 | 3 | storres | * Find the zeros of a function on a given interval.
|
133 | 3 | storres | */
|
134 | 3 | storres | chain*
|
135 | 3 | storres | pobyso_find_zeros(node *function,
|
136 | 3 | storres | mpfr_t *lowerBound,
|
137 | 3 | storres | mpfr_t *upperBound);
|
138 | 3 | storres | /**
|
139 | 3 | storres | * Free a chain of node.
|
140 | 3 | storres | * All elements of the chain have to be nodes.
|
141 | 3 | storres | */
|
142 | 3 | storres | void
|
143 | 3 | storres | pobyso_free_chain_of_nodes(chain *theChain);
|
144 | 3 | storres | |
145 | 3 | storres | /**
|
146 | 3 | storres | * Free a range.
|
147 | 3 | storres | * It involves clearing the mpfr_t elements and deallocating the
|
148 | 3 | storres | * pointers.
|
149 | 3 | storres | */
|
150 | 3 | storres | void
|
151 | 3 | storres | pobyso_free_range(rangetype range);
|
152 | 3 | storres | |
153 | 3 | storres | /**
|
154 | 3 | storres | * Computes a good polynomial approximation with fixed-point or floating-point
|
155 | 3 | storres | * coefficients.
|
156 | 3 | storres | */
|
157 | 3 | storres | node*
|
158 | 3 | storres | pobyso_fp_minimax_canonical_monomials_base(node *function,
|
159 | 3 | storres | int degree,
|
160 | 3 | storres | chain *formats,
|
161 | 3 | storres | chain *points,
|
162 | 3 | storres | mpfr_t lowerBound,
|
163 | 3 | storres | mpfr_t upperBound,
|
164 | 3 | storres | int fpFixedArg,
|
165 | 3 | storres | int absRel,
|
166 | 3 | storres | node *constPart,
|
167 | 3 | storres | node *minimax);
|
168 | 3 | storres | /**
|
169 | 3 | storres | * Parses a string to build the node representing the function.
|
170 | 3 | storres | * In fact, does nothing for the moment: the string must be a correct function
|
171 | 3 | storres | * definition. No error correction takes place here.
|
172 | 3 | storres | */
|
173 | 3 | storres | node*
|
174 | 3 | storres | pobyso_parse_function(char *functionString,
|
175 | 3 | storres | char *freeVariableNameString);
|
176 | 3 | storres | |
177 | 3 | storres | /** Compute a polynomial approximation in the canonical monomials basis for
|
178 | 3 | storres | * a function, for a given precision. The returned polynomial has the minimal
|
179 | 3 | storres | * degree to achieve the required precision.
|
180 | 3 | storres | */
|
181 | 3 | storres | node*
|
182 | 3 | storres | pobyso_remez_approx_canonical_monomials_base_for_error(node *functionNode,
|
183 | 3 | storres | unsigned int mode,
|
184 | 3 | storres | mpfr_t lowerBound,
|
185 | 3 | storres | mpfr_t upperBound,
|
186 | 3 | storres | mpfr_t eps);
|
187 | 3 | storres | |
188 | 3 | storres | /**
|
189 | 3 | storres | * Computes a the remez approximation of a function.
|
190 | 3 | storres | * @param function - the node holding the function to approximate;
|
191 | 3 | storres | * @param weight - the node holding the weight function, can be NULL. In
|
192 | 3 | storres | * this case a default weight of "1" will be provided and
|
193 | 3 | storres | * the approximation is related is with respect to the
|
194 | 3 | storres | * absolute error.
|
195 | 3 | storres | * @param degree - the degree of the approximation polynomial;
|
196 | 3 | storres | * @param lowerBound - the lower bound of the approximation interval;
|
197 | 3 | storres | * @param upperBound - the upper bound of the approximation interval;
|
198 | 3 | storres | * @param quality - quality = (eps - eps*) / eps*; the search stop when the required
|
199 | 3 | storres | * quality is achieved.
|
200 | 3 | storres | *
|
201 | 3 | storres | * @return a node holding the approximation polynomial in Horner form.
|
202 | 3 | storres | */
|
203 | 3 | storres | node*
|
204 | 3 | storres | pobyso_remez_canonical_monomials_base(node *function,
|
205 | 3 | storres | node *weight,
|
206 | 3 | storres | unsigned int degree,
|
207 | 3 | storres | mpfr_t lowerBound,
|
208 | 3 | storres | mpfr_t upperBound,
|
209 | 3 | storres | mpfr_t quality);
|
210 | 3 | storres | #endif
|
211 | 3 | storres | #define POBYSO_h
|
212 | 3 | storres | |
213 | 3 | storres | #endif
|