Statistiques
| Révision :

root / pobysoC-4.0 / pobyso.h @ 13

Historique | Voir | Annoter | Télécharger (6,92 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 <stdio.h>
16
#include <sollya.h>
17
#include <mpfr.h>
18

    
19
#ifndef POBYSO_h
20

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

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

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

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

    
45
/**
46
 * Parse a string to create a Sollya object.
47
 * A very thin wrapper around the sollya_lib_parse_string() function.
48
 */
49
sollya_obj_t
50
pobyso_parse_string(const char* expression);
51

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

    
61
/**
62
 * Set the verbosity level to newVerbosityLevel.
63
 * @param newVerbosityLevel must be a Sollay object corresponding to an
64
 *        integer constant.
65
 */
66
void
67
pobyso_set_verbosity_to(sollya_obj_t newVerbosityLevel);
68

    
69
#if 0
70
/**
71
 * Create the canonical (non sparse) base of monomials for a given degree.
72
 */
73
chain*
74
pobyso_create_canonical_monomials_base(const unsigned int degree);
75

76
/**
77
 * Create a chain from an array of int.
78
 */
79
sollya_int_list
80
pobyso_create_int_list_from_int_Array(int* intArray,
81
                                    const unsigned int arrayLength);
82

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

97
sollya_obj_t
98
pobyso_diff(sollya_obj_t function);
99

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

118

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

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

145
/**
146
 * Free a range.
147
 * It involves clearing the mpfr_t elements and deallocating the
148
 * pointers.
149
 */
150
void
151
pobyso_free_range(rangetype range);
152

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

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

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