Statistiques
| Révision :

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

Historique | Voir | Annoter | Télécharger (7,09 ko)

1
/** @file pobyso.h
2
 * Integration of Sollya to C programs
3
 * @author S.T.
4
 * @date 2011-10-11
5
 * Note: pobyso stands for POwered BY SOllya.
6
 *                         --      -- --
7
 */
8
/******************************************************************************/
9
 
10
/*
11
 * Add below all the headers needed to get this header work.
12
 */
13
/* <stdio.h> is needed *before* <mpfr.h> for all MPFR input/output functions
14
 * prototypes be defined. */
15
#include <string.h>
16
#include <stdio.h>
17
#include <sollya.h>
18
#include <mpfr.h>
19

    
20
#ifndef POBYSO_h
21

    
22
#define POBYSO_ABSOLUTE 1
23
#define POBYSO_RELATIVE 2
24
/* Mimic the default behavior of interactive Sollya. */
25
#define POBYSO_DEFAULT_POINTS 501
26
#define POBYSO_INF_NORM_NUM_POINTS (POBYSO_DEFAULT_POINTS)
27
#define POBYSO_GUESS_DEGREE_BOUND 1024
28

    
29
/**
30
 * Print object(s) to stdout.
31
 * A very thin wrapper around the lib_sollya_v_autoprint() function.
32
 * Should be called with NULL as the final argument.
33
 */
34
void
35
pobyso_autoprint(sollya_obj_t soObj, ...);
36

    
37
/**
38
 * Print object(s) to stdout: the va_list companion function.
39
 * A very thin wrapper around the lib_sollya_v_autoprint() function.
40
 * The last argument in the va_list should be NULL.
41
 */
42

    
43
void
44
pobyso_autoprint_v(sollya_obj_t soObj, va_list va);
45

    
46
/**
47
 * Parse a string to create a Sollya object.
48
 * A very thin wrapper around the sollya_lib_parse_string() function.
49
 * If the final ";" is forgotten in the expression, it is added by the
50
 * function.
51
 * @return a Sollya expression if successes, a Sollya error if fails.
52
 */
53
sollya_obj_t
54
pobyso_parse_string(const char* expression);
55

    
56
/**
57
 * Set the verbosity mode off (level 0).
58
 * If currentVerbosity != NULL, currentVerbosity is set
59
 * to the current verbosity level. It may be used to reset the
60
 * verbosity level later.
61
 */
62
void
63
pobyso_set_verbosity_off(sollya_obj_t* currentVerbosityLevel);
64

    
65
/**
66
 * Set the verbosity level to newVerbosityLevel.
67
 * @param newVerbosityLevel must be a Sollay object corresponding to an
68
 *        integer constant.
69
 */
70
void
71
pobyso_set_verbosity_to(sollya_obj_t newVerbosityLevel);
72

    
73
#if 0
74
/**
75
 * Create the canonical (non sparse) base of monomials for a given degree.
76
 */
77
chain*
78
pobyso_create_canonical_monomials_base(const unsigned int degree);
79

80
/**
81
 * Create a chain from an array of int.
82
 */
83
sollya_int_list
84
pobyso_create_int_list_from_int_Array(int* intArray,
85
                                    const unsigned int arrayLength);
86

87
/**
88
 * Create a chain from an array of int.
89
 */
90
sollya_int_list_t
91
pobyso_create_int_list_from_unsigned_int_array(unsigned int* intArray,
92
                                            const unsigned int arrayLength);
93
/**
94
 * Differentiation of a function.
95
 * A slim wrapper around the Sollya differentiate function.
96
 * @param functionNode - the Sollya node to differentiate;
97
 * @return a node representing the function differentiated or NULL, if
98
 *         something goes wrong.
99
 */
100

101
sollya_obj_t
102
pobyso_diff(sollya_obj_t function);
103

104
/**
105
 * A match to the Sollya dirtyinfnorm.
106
 * A slim wrapper around the Sollya function.
107
 * @param infnorm - out parameter to return the result, must be "inited"
108
 *                  and "cleared" by the caller;
109
 * @param functionNode - the Sollya node to compute the infinite norm of;
110
 * @param lowerBound - the lower bound of the interval;
111
 * @param upperBound - the upper bound of the interval;
112
 * @param precision  - the internal precision Sollya must use.
113
 * @return 0 if everything is OK, != 0 if something goes wrong.
114
 */
115
int
116
pobyso_dirty_infnorm(mpfr_t infNorm,
117
                      node *functionNode,
118
                      mpfr_t lowerBound,
119
                      mpfr_t upperBound,
120
                      mp_prec_t precision);
121

122

123
/**
124
 * Faithful evaluation of an expression.
125
 *
126
 * @param faitufulEvaluation - holds the result, must be "inited" by the
127
 *                             caller;
128
 */
129
int
130
pobyso_evaluate_faithful(mpfr_t faithfulEvaluation,
131
                          node *nodeToEvaluate,
132
                          mpfr_t argument,
133
                          mpfr_prec_t precision);
134

135
/**
136
 * Find the zeros of a function on a given interval.
137
 */
138
chain*
139
pobyso_find_zeros(node *function,
140
                  mpfr_t *lowerBound,
141
                  mpfr_t *upperBound);
142
/**
143
 * Free a chain of node.
144
 * All elements of the chain have to be nodes.
145
 */
146
void
147
pobyso_free_chain_of_nodes(chain *theChain);
148

149
/**
150
 * Free a range.
151
 * It involves clearing the mpfr_t elements and deallocating the
152
 * pointers.
153
 */
154
void
155
pobyso_free_range(rangetype range);
156

157
/**
158
 * Computes a good polynomial approximation with fixed-point or floating-point
159
 * coefficients.
160
 */
161
node*
162
pobyso_fp_minimax_canonical_monomials_base(node *function,
163
                                          int degree,
164
                                          chain *formats,
165
                                          chain *points,
166
                                          mpfr_t lowerBound,
167
                                          mpfr_t upperBound,
168
                                          int fpFixedArg,
169
                                          int absRel,
170
                                          node *constPart,
171
                                          node *minimax);
172
/**
173
 * Parses a string to build the node representing the function.
174
 * In fact, does nothing for the moment: the string must be a correct function
175
 * definition. No error correction takes place here.
176
 */
177
node*
178
pobyso_parse_function(char *functionString,
179
                      char *freeVariableNameString);
180

181
/** Compute a polynomial approximation in the canonical monomials basis for
182
 *  a function, for a given precision. The returned polynomial has the minimal
183
 *  degree to achieve the required precision.
184
 */
185
node*
186
pobyso_remez_approx_canonical_monomials_base_for_error(node *functionNode,
187
                                                      unsigned int mode,
188
                                                      mpfr_t lowerBound,
189
                                                      mpfr_t upperBound,
190
                                                      mpfr_t eps);
191

192
/**
193
 * Computes a the remez approximation of a function.
194
 * @param function   - the node holding the function to approximate;
195
 * @param weight     - the node holding the weight function, can be NULL. In
196
 *                     this case a default weight of "1" will be provided and
197
 *                     the approximation is related is with respect to the
198
 *                     absolute error.
199
 * @param degree     - the degree of the approximation polynomial;
200
 * @param lowerBound - the lower bound of the approximation interval;
201
 * @param upperBound - the upper bound of the approximation interval;
202
 * @param quality    - quality = (eps - eps*) / eps*; the search stop when the required
203
 *                     quality is achieved.
204
 *
205
 * @return a node holding the approximation polynomial in Horner form.
206
 */
207
node*
208
pobyso_remez_canonical_monomials_base(node *function,
209
                                       node *weight,
210
                                       unsigned int degree,
211
                                       mpfr_t lowerBound,
212
                                       mpfr_t upperBound,
213
                                       mpfr_t quality);
214
#endif
215
#define POBYSO_h  
216
  
217
#endif
218