Statistiques
| Révision :

root / pobysoC-4.0 / src / pobyso.c @ 26

Historique | Voir | Annoter | Télécharger (18,78 ko)

1 26 storres
/** @file pobyso.c
2 26 storres
 * Name & purpose
3 26 storres
 *
4 26 storres
 * @author S.T.
5 26 storres
 * @date 2011-10-12
6 26 storres
 *
7 26 storres
 */
8 26 storres
/******************************************************************************/
9 26 storres
/* Headers, applying the "particular to general" convention.*/
10 26 storres
11 26 storres
#include "pobyso.h"
12 26 storres
13 26 storres
/* includes of local headers */
14 26 storres
15 26 storres
/* includes of project headers */
16 26 storres
17 26 storres
/* includes of system headers */
18 26 storres
19 26 storres
/* Other declarations */
20 26 storres
21 26 storres
/* Internal prototypes */
22 26 storres
void
23 26 storres
pobyso_error_message(char *functionName, char *messageName, char* message);
24 26 storres
/* Types, constants and macros definitions */
25 26 storres
26 26 storres
/* Global variables */
27 26 storres
28 26 storres
/* Functions */
29 26 storres
void
30 26 storres
pobyso_autoprint(sollya_obj_t solObj, ...)
31 26 storres
{
32 26 storres
  va_list va;
33 26 storres
  va_start(va, solObj);
34 26 storres
  sollya_lib_v_autoprint(solObj, va);
35 26 storres
  va_end(va);
36 26 storres
} /* End pobyso_autoprint. */
37 26 storres
38 26 storres
sollya_obj_t
39 26 storres
pobyso_parse_string(const char* expression)
40 26 storres
{
41 26 storres
  if (expression == NULL)
42 26 storres
  {
43 26 storres
    pobyso_error_message("pobyso_parse_string",
44 26 storres
                        "NULL_POINTER_ARGUMENT",
45 26 storres
                        "The expression is a NULL pointer");
46 26 storres
    return(NULL);
47 26 storres
  }
48 26 storres
  return(sollya_lib_parse_string(expression));
49 26 storres
} /* pobyso_parse_string */
50 26 storres
51 26 storres
void
52 26 storres
pobyso_set_verbosity_off(sollya_obj_t* currentVerbosityLevel)
53 26 storres
{
54 26 storres
  sollya_obj_t verbosityLevelZero;
55 26 storres
  if (currentVerbosityLevel != NULL)
56 26 storres
  {
57 26 storres
     *currentVerbosityLevel = sollya_lib_get_verbosity();
58 26 storres
  }
59 26 storres
  verbosityLevelZero = sollya_lib_constant_from_int(0);
60 26 storres
  sollya_lib_set_verbosity(verbosityLevelZero);
61 26 storres
  sollya_lib_clear_obj(verbosityLevelZero);
62 26 storres
} /* End of pobyso_set_verbosity_off. */
63 26 storres
64 26 storres
void
65 26 storres
pobyso_set_verbosity_to(sollya_obj_t newVerbosityLevel)
66 26 storres
{
67 26 storres
  if (newVerbosityLevel == NULL)
68 26 storres
  {
69 26 storres
    pobyso_error_message("pobyso_set_verbosity_to",
70 26 storres
                        "NULL_POINTER_ARGUMENT",
71 26 storres
                        "The new verbosity level is a NULL pointer");
72 26 storres
    return;
73 26 storres
  }
74 26 storres
  sollya_lib_set_verbosity(newVerbosityLevel);
75 26 storres
} /* End of pobyso_set_verbosity_to. */
76 26 storres
77 26 storres
/* Attic from the sollya_lib < 4. */
78 26 storres
#if 0
79 26 storres
chain*
80 26 storres
pobyso_create_canonical_monomials_base(const unsigned int degree)
81 26 storres
{
82 26 storres
  int i    = 0;
83 26 storres
  chain *monomials  = NULL;
84 26 storres
  node  *monomial   = NULL;
85 26 storres

86 26 storres
  for(i = degree ; i >= 0  ; i--)
87 26 storres
  {
88 26 storres
     monomial   = makePow(makeVariable(), makeConstantDouble((double)i));
89 26 storres
     monomials  = addElement(monomials, monomial);
90 26 storres
     fprintf(stderr, "pobyso_create_canonical_monomials_base: %u\n", i);
91 26 storres
  }
92 26 storres
  if (monomials == NULL)
93 26 storres
  {
94 26 storres
    pobyso_error_message("pobyso_create_canonical_monomial_base",
95 26 storres
                        "CHAIN_CREATION_ERROR",
96 26 storres
                        "Could not create the monomials chain");
97 26 storres
    return(NULL);
98 26 storres
  }
99 26 storres
  return(monomials);
100 26 storres
} /* End pobyso_create_canonical_monomials_base. */
101 26 storres

102 26 storres
chain*
103 26 storres
pobyso_create_chain_from_int_array(int* intArray,
104 26 storres
                                    const unsigned int arrayLength)
105 26 storres
{
106 26 storres
  int i = 0;
107 26 storres
  chain *newChain = NULL;
108 26 storres
  int *currentInt;
109 26 storres

110 26 storres
  if (arrayLength == 0) return(NULL);
111 26 storres
  if (intArray == NULL)
112 26 storres
  {
113 26 storres
    pobyso_error_message("pobyso_create_chain_from_int_array",
114 26 storres
                        "NULL_POINTER_ARGUMENT",
115 26 storres
                        "The array is a NULL pointer");
116 26 storres
    return(NULL);
117 26 storres
  }
118 26 storres
  for (i = arrayLength - 1 ; i >= 0 ; i--)
119 26 storres
  {
120 26 storres
    currentInt = malloc(sizeof(int));
121 26 storres
    if (currentInt == NULL)
122 26 storres
    {
123 26 storres
      pobyso_error_message("pobyso_create_chain_from_int_array",
124 26 storres
                          "MEMORY_ALLOCATION_ERROR",
125 26 storres
                          "Could not allocate one of the integers");
126 26 storres
      freeChain(newChain, free);
127 26 storres
      return(NULL);
128 26 storres
    }
129 26 storres
    *currentInt = intArray[i];
130 26 storres
    newChain = addElement(newChain, currentInt);
131 26 storres
  }
132 26 storres
  return(newChain);
133 26 storres
} // End pobyso_create_chain_from_int_array. */
134 26 storres

135 26 storres
chain*
136 26 storres
pobyso_create_chain_from_unsigned_int_array(unsigned int* intArray,
137 26 storres
                                        const unsigned int arrayLength)
138 26 storres
{
139 26 storres
  int i = 0;
140 26 storres
  chain *newChain = NULL;
141 26 storres
  unsigned int *currentInt;
142 26 storres

143 26 storres
  /* Argument checking. */
144 26 storres
  if (arrayLength == 0) return(NULL);
145 26 storres
  if (intArray == NULL)
146 26 storres
  {
147 26 storres
    pobyso_error_message("pobyso_create_chain_from_unsigned_int_array",
148 26 storres
                        "NULL_POINTER_ARGUMENT",
149 26 storres
                        "The array is a NULL pointer");
150 26 storres
    return(NULL);
151 26 storres
  }
152 26 storres
  for (i = arrayLength - 1 ; i >= 0 ; i--)
153 26 storres
  {
154 26 storres
    currentInt = malloc(sizeof(unsigned int));
155 26 storres
    if (currentInt == NULL)
156 26 storres
    {
157 26 storres
      pobyso_error_message("pobyso_create_chain_from_unsigned_int_array",
158 26 storres
                          "MEMORY_ALLOCATION_ERROR",
159 26 storres
                          "Could not allocate one of the integers");
160 26 storres
      freeChain(newChain, free);
161 26 storres
      return(NULL);
162 26 storres
    }
163 26 storres
    *currentInt = intArray[i];
164 26 storres
    newChain = addElement(newChain, currentInt);
165 26 storres
  }
166 26 storres
  return(newChain);
167 26 storres
} // End pobyso_create_chain_from_unsigned_int_array. */
168 26 storres

169 26 storres
node*
170 26 storres
pobyso_differentiate(node *functionNode)
171 26 storres
{
172 26 storres
  /* Argument checking. */
173 26 storres
  node *differentialNode;
174 26 storres
  if (functionNode == NULL)
175 26 storres
  {
176 26 storres
    pobyso_error_message("pobyso_differentiate",
177 26 storres
                        "NULL_POINTER_ARGUMENT",
178 26 storres
                        "The function to differentiate is a NULL pointer");
179 26 storres
    return(NULL);
180 26 storres
  }
181 26 storres
  differentialNode = differentiate(functionNode);
182 26 storres
  if (differentialNode == NULL)
183 26 storres
  {
184 26 storres
    pobyso_error_message("pobyso_differentiate",
185 26 storres
                        "INTERNAL ERROR",
186 26 storres
                        "Sollya could not differentiate the function");
187 26 storres
  }
188 26 storres
  return(differentialNode);
189 26 storres
} // End pobyso_differentiate
190 26 storres

191 26 storres

192 26 storres
int
193 26 storres
pobyso_dirty_infnorm(mpfr_t infNorm,
194 26 storres
                      node *functionNode,
195 26 storres
                      mpfr_t lowerBound,
196 26 storres
                      mpfr_t upperBound,
197 26 storres
                      mp_prec_t precision)
198 26 storres
{
199 26 storres
  int functionCallResult;
200 26 storres
  /* Arguments checking. */
201 26 storres
  if (functionNode == NULL)
202 26 storres
  {
203 26 storres
    pobyso_error_message("pobyso_dirty_infnorm",
204 26 storres
                        "NULL_POINTER_ARGUMENT",
205 26 storres
                        "The function to compute is a NULL pointer");
206 26 storres
    return(1);
207 26 storres
  }
208 26 storres
  if (mpfr_cmp(lowerBound, upperBound) > 0)
209 26 storres
  {
210 26 storres
    pobyso_error_message("pobyso_dirty_infnorm",
211 26 storres
                        "INCOHERENT_INPUT_DATA",
212 26 storres
                        "The lower bond is greater than the upper bound");
213 26 storres
    return(1);
214 26 storres
  }
215 26 storres
  /* Particular cases. */
216 26 storres
  if (mpfr_cmp(lowerBound, upperBound) == 0)
217 26 storres
  {
218 26 storres
    functionCallResult = pobyso_evaluate_faithful(infNorm,
219 26 storres
                                                  functionNode,
220 26 storres
                                                  lowerBound,
221 26 storres
                                                  precision);
222 26 storres
    return(functionCallResult);
223 26 storres
  }
224 26 storres
  if (isConstant(functionNode))
225 26 storres
  {
226 26 storres
    functionCallResult = pobyso_evaluate_faithful(infNorm,
227 26 storres
                                                  functionNode,
228 26 storres
                                                  lowerBound,
229 26 storres
                                                  precision);
230 26 storres
    if (!functionCallResult)
231 26 storres
    {
232 26 storres
      mpfr_abs(infNorm, infNorm, MPFR_RNDN);
233 26 storres
    }
234 26 storres
    return(functionCallResult);
235 26 storres
  }
236 26 storres
  uncertifiedInfnorm(infNorm,
237 26 storres
                      functionNode,
238 26 storres
                      lowerBound,
239 26 storres
                      upperBound,
240 26 storres
                      POBYSO_DEFAULT_POINTS,
241 26 storres
                      precision);
242 26 storres
  return(0);
243 26 storres
} /* End pobyso_dirty_infnorm. */
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
  /* Check input arguments. */
252 26 storres
  if (nodeToEvaluate == NULL)
253 26 storres
  {
254 26 storres
    pobyso_error_message("pobyso_evaluate_faithful",
255 26 storres
                        "NULL_POINTER_ARGUMENT",
256 26 storres
                        "nodeToEvaluate is a NULL pointer");
257 26 storres
    return(1);
258 26 storres
  }
259 26 storres
  evaluateFaithful(faithfulEvaluation,
260 26 storres
                   nodeToEvaluate,
261 26 storres
                   argument,
262 26 storres
                   precision);
263 26 storres
  return(0);
264 26 storres
} /* End pobyso_evaluate_faithfull. */
265 26 storres

266 26 storres
chain*
267 26 storres
pobyso_find_zeros(node *function,
268 26 storres
                  mpfr_t *lower_bound,
269 26 storres
                  mpfr_t *upper_bound)
270 26 storres
{
271 26 storres
  mp_prec_t currentPrecision;
272 26 storres
  mpfr_t currentDiameter;
273 26 storres
  rangetype bounds;
274 26 storres

275 26 storres
  currentPrecision = getToolPrecision();
276 26 storres
  mpfr_init2(currentDiameter, currentPrecision);
277 26 storres

278 26 storres
  bounds.a = lower_bound;
279 26 storres
  bounds.b = upper_bound;
280 26 storres

281 26 storres
  if (bounds.a == NULL || bounds.b == NULL)
282 26 storres
  {
283 26 storres
    pobyso_error_message("pobyso_find_zeros",
284 26 storres
                        "MEMORY_ALLOCATION_ERROR",
285 26 storres
                        "Could not allocate one of the bounds");
286 26 storres
    return(NULL);
287 26 storres
  }
288 26 storres
  return(findZerosFunction(function,
289 26 storres
                            bounds,
290 26 storres
                            currentPrecision,
291 26 storres
                            currentDiameter));
292 26 storres
} /* End pobyso_find_zeros. */
293 26 storres

294 26 storres
void
295 26 storres
pobyso_free_chain_of_nodes(chain *theChainOfNodes)
296 26 storres
{
297 26 storres
  node *currentNode           = NULL;
298 26 storres
  chain *currentChainElement  = NULL;
299 26 storres
  chain *nextChainElement     = NULL;
300 26 storres

301 26 storres
  nextChainElement = theChainOfNodes;
302 26 storres

303 26 storres
  while(nextChainElement != NULL)
304 26 storres
  {
305 26 storres
    currentChainElement = nextChainElement;
306 26 storres
    currentNode = (node*)(currentChainElement->value);
307 26 storres
    nextChainElement = nextChainElement->next;
308 26 storres
    free_memory(currentNode);
309 26 storres
    free((void*)(currentChainElement));
310 26 storres
  }
311 26 storres
} /* End pobyso_free_chain_of_nodes. */
312 26 storres

313 26 storres
void
314 26 storres
pobyso_free_range(rangetype range)
315 26 storres
{
316 26 storres

317 26 storres
  mpfr_clear(*(range.a));
318 26 storres
  mpfr_clear(*(range.b));
319 26 storres
  free(range.a);
320 26 storres
  free(range.b);
321 26 storres
} /* End pobyso_free_range. */
322 26 storres

323 26 storres
node*
324 26 storres
pobyso_fp_minimax_canonical_monomials_base(node *function,
325 26 storres
                                      int degree,
326 26 storres
                                      chain *formats,
327 26 storres
                                      chain *points,
328 26 storres
                                      mpfr_t lowerBound,
329 26 storres
                                      mpfr_t upperBound,
330 26 storres
                                      int fpFixedArg,
331 26 storres
                                      int absRel,
332 26 storres
                                      node *constPart,
333 26 storres
                                      node *minimax)
334 26 storres
{
335 26 storres
  return(NULL);
336 26 storres
} /* End pobyso_fp_minimax_canonical_monomials_base. */
337 26 storres

338 26 storres
node*
339 26 storres
pobyso_parse_function(char *functionString,
340 26 storres
                      char *freeVariableNameString)
341 26 storres
{
342 26 storres
  if (functionString == NULL || freeVariableNameString == NULL)
343 26 storres
  {
344 26 storres
    pobyso_error_message("pobyso_parse_function",
345 26 storres
                        "NULL_POINTER_ARGUMENT",
346 26 storres
                        "One of the arguments is a NULL pointer");
347 26 storres
    return(NULL);
348 26 storres
  }
349 26 storres
  return(parseString(functionString));
350 26 storres

351 26 storres
} /* End pobyso_parse_function */
352 26 storres

353 26 storres
node*
354 26 storres
pobyso_remez_approx_canonical_monomials_base_for_error(node *functionNode,
355 26 storres
                                                  unsigned int mode,
356 26 storres
                                                  mpfr_t lowerBound,
357 26 storres
                                                  mpfr_t upperBound,
358 26 storres
                                                  mpfr_t eps)
359 26 storres
{
360 26 storres
  node *weight              = NULL;
361 26 storres
  node *bestApproxPolyNode  = NULL;
362 26 storres
  node *bestApproxHorner    = NULL;
363 26 storres
  node *errorNode           = NULL;
364 26 storres
  rangetype degreeRange;
365 26 storres
  mpfr_t quality;
366 26 storres
  mpfr_t currentError;
367 26 storres
  unsigned int degree;
368 26 storres

369 26 storres
  /* Check the parameters. */
370 26 storres
  if (functionNode == NULL)
371 26 storres
  {
372 26 storres
    pobyso_error_message("remezApproxCanonicalMonomialsBaseForError",
373 26 storres
                        "NULL_POINTER_ARGUMENT",
374 26 storres
                        "functionNode is a NULL pointer");
375 26 storres
    return(NULL);
376 26 storres
  }
377 26 storres
  if (mpfr_cmp(lowerBound, upperBound) >= 0)
378 26 storres
  {
379 26 storres
    pobyso_error_message("remezApproxCanonicalMonomialsBaseForError",
380 26 storres
                        "INCOHERENT_INPUT_DATA",
381 26 storres
                        "the lower_bound >= upper_bound");
382 26 storres
    return(NULL);
383 26 storres
  }
384 26 storres
  /* Set the weight. */
385 26 storres
  if (mode == POBYSO_ABSOLUTE)
386 26 storres
  {
387 26 storres
    /* Set the weight to 1 for the ABSOLUTE_MODE. */
388 26 storres
    weight = makeConstantDouble(1.0);
389 26 storres
  }
390 26 storres
  else
391 26 storres
  {
392 26 storres
    if (mode == POBYSO_RELATIVE)
393 26 storres
    {
394 26 storres
      pobyso_error_message("computeRemezApproxCanonicalMonomialsBaseForError",
395 26 storres
                          "NOT_IMPLEMENTED",
396 26 storres
                          "the search for relative error is not implemented yet");
397 26 storres
      return(NULL);
398 26 storres
    }
399 26 storres
    else
400 26 storres
    {
401 26 storres
      pobyso_error_message("computeRemezApproxCanonicalMonomialsBaseForError",
402 26 storres
                          "INCOHERENT_INPUT_DATA",
403 26 storres
                          "the mode is node of POBYSO_ABOLUTE or POBYSO_RELATIVE");
404 26 storres
      return(NULL);
405 26 storres
    }
406 26 storres
  }
407 26 storres
  //fprintf(stderr, "\n\n\n******* I'm here! ********\n\n\n");
408 26 storres
  degreeRange = guessDegree(functionNode,
409 26 storres
                            weight,
410 26 storres
                            lowerBound,
411 26 storres
                            upperBound,
412 26 storres
                            eps,
413 26 storres
                            POBYSO_GUESS_DEGREE_BOUND);
414 26 storres
  degree = mpfr_get_ui(*(degreeRange.a), MPFR_RNDN);
415 26 storres
  //fprintf(stderr, "\n\n\n******* I'm back! ********\n\n\n");
416 26 storres
  fprintf(stderr, "Guessed degree: ");
417 26 storres
  mpfr_out_str(stderr, 10, 17, *(degreeRange.a), MPFR_RNDN);
418 26 storres
  fprintf(stderr, " - as int: %u\n", degree);
419 26 storres
  /* Reduce the degree by 1 in the foolish hope it could work. */
420 26 storres
  if (degree > 0) degree--;
421 26 storres
  /* Both elements of degreeRange where "inited" within guessDegree. */
422 26 storres
  mpfr_clear(*(degreeRange.a));
423 26 storres
  mpfr_clear(*(degreeRange.b));
424 26 storres
  free(degreeRange.a);
425 26 storres
  free(degreeRange.b);
426 26 storres
  /* Mimic the default behavior of interactive Sollya. */
427 26 storres
  mpfr_init(quality);
428 26 storres
  mpfr_set_d(quality, 1e-5, MPFR_RNDN);
429 26 storres
  mpfr_init2(currentError, getToolPrecision());
430 26 storres
  mpfr_set_inf(currentError,1);
431 26 storres

432 26 storres
  /* Try to refine the initial guess: loop with increasing degrees until
433 26 storres
   * we find a satisfactory one. */
434 26 storres
  while(mpfr_cmp(currentError, eps) > 0)
435 26 storres
  {
436 26 storres
    /* Get rid of the previous polynomial, if any. */
437 26 storres
    if (bestApproxPolyNode != NULL)
438 26 storres
    {
439 26 storres
      free_memory(bestApproxPolyNode);
440 26 storres
    }
441 26 storres
    fprintf(stderr, "Degree: %u\n", degree);
442 26 storres
    fprintf(stderr, "Calling pobyso_remez_canonical_monomials_base...\n");
443 26 storres
    /* Try to find a polynomial with the guessed degree. */
444 26 storres
    bestApproxPolyNode = pobyso_remez_canonical_monomials_base(functionNode,
445 26 storres
                                                            weight,
446 26 storres
                                                            degree,
447 26 storres
                                                            lowerBound,
448 26 storres
                                                            upperBound,
449 26 storres
                                                            quality);
450 26 storres

451 26 storres
    if (bestApproxPolyNode == NULL)
452 26 storres
    {
453 26 storres
      pobyso_error_message("computeRemezApproxCanonicalMonomialsBaseForError",
454 26 storres
                          "INTERNAL_ERROR",
455 26 storres
                          "could not compute the bestApproxPolyNode");
456 26 storres
      mpfr_clear(currentError);
457 26 storres
      mpfr_clear(quality);
458 26 storres
      return(NULL);
459 26 storres
    }
460 26 storres

461 26 storres
    setDisplayMode(DISPLAY_MODE_DECIMAL);
462 26 storres
    fprintTree(stderr, bestApproxPolyNode);
463 26 storres
    fprintf(stderr, "\n\n");
464 26 storres

465 26 storres
    errorNode = makeSub(copyTree(functionNode), copyTree(bestApproxPolyNode));
466 26 storres
    /* Check the error with the computed polynomial. */
467 26 storres
    uncertifiedInfnorm(currentError,
468 26 storres
                        errorNode,
469 26 storres
                        lowerBound,
470 26 storres
                        upperBound,
471 26 storres
                        POBYSO_INF_NORM_NUM_POINTS,
472 26 storres
                        getToolPrecision());
473 26 storres
    fprintf(stderr, "Inf norm: ");
474 26 storres
    mpfr_out_str(stderr, 10, 17, currentError, MPFR_RNDN);
475 26 storres
    fprintf(stderr, "\n\n");
476 26 storres
    /* Free the errorNode but not the bestApproxPolyNode (we need it if
477 26 storres
     * we exit the loop at the next iteration). */
478 26 storres
    free_memory(errorNode);
479 26 storres
    degree++;
480 26 storres
  }
481 26 storres
  /* Use an intermediate variable, since horner() creates a new node
482 26 storres
   * and does not reorder the argument "in place". This allows for the memory
483 26 storres
   * reclaim of bestApproxHorner.
484 26 storres
   */
485 26 storres
  bestApproxHorner = horner(bestApproxPolyNode);
486 26 storres
  free_memory(bestApproxPolyNode);
487 26 storres
  mpfr_clear(currentError);
488 26 storres
  mpfr_clear(quality);
489 26 storres
  free_memory(weight);
490 26 storres
  return(bestApproxHorner);
491 26 storres
} /* End pobyso_remez_approx_canonical_monomials_base_for_error */
492 26 storres

493 26 storres
node*
494 26 storres
pobyso_remez_canonical_monomials_base(node *function,
495 26 storres
                                     node *weight,
496 26 storres
                                     unsigned int degree,
497 26 storres
                                     mpfr_t lowerBound,
498 26 storres
                                     mpfr_t upperBound,
499 26 storres
                                     mpfr_t quality)
500 26 storres
{
501 26 storres
  node  *bestApproxPoly = NULL;
502 26 storres
  chain *monomials      = NULL;
503 26 storres
  chain *curMonomial    = NULL;
504 26 storres

505 26 storres
  mpfr_t satisfying_error;
506 26 storres
  mpfr_t target_error;
507 26 storres

508 26 storres
  /* Argument checking */
509 26 storres
  /* Function tree. */
510 26 storres
  if (function == NULL)
511 26 storres
  {
512 26 storres
    pobyso_error_message("pobyso_remez_canonical_monomials_base",
513 26 storres
                        "NULL_POINTER_ARGUMENT",
514 26 storres
                        "the \"function\" argument is a NULL pointer");
515 26 storres
    return(NULL);
516 26 storres
  }
517 26 storres
  if (weight == NULL)
518 26 storres
  {
519 26 storres
    pobyso_error_message("pobyso_remez_canonical_monomials_base",
520 26 storres
                        "NULL_POINTER_ARGUMENT",
521 26 storres
                        "the \"weight\" argument is a NULL pointer");
522 26 storres
    return(NULL);
523 26 storres
  }
524 26 storres
  /* Check the bounds. */
525 26 storres
  if (mpfr_cmp(lowerBound, upperBound) >= 0)
526 26 storres
  {
527 26 storres
    pobyso_error_message("pobyso_remez_canonical_monomials_base",
528 26 storres
                        "INCOHERENT_IMPUT_DATA",
529 26 storres
                        "the lower_bound >= upper_bound");
530 26 storres
    return(NULL);
531 26 storres
  }
532 26 storres
  /* The quality must be a non null positive number. */
533 26 storres
  if (mpfr_sgn(quality) <= 0)
534 26 storres
  {
535 26 storres
    pobyso_error_message("pobyso_remez_canonical_monomials_base",
536 26 storres
                        "INCOHERENT_INPUT_DATA",
537 26 storres
                        "the quality <= 0");
538 26 storres
  }
539 26 storres
  /* End argument checking. */
540 26 storres
  /* Create the monomials nodes chains. */
541 26 storres
  monomials = pobyso_create_canonical_monomials_base(degree);
542 26 storres
  fprintf(stderr, "monomials chain length = %d\n", lengthChain(monomials));
543 26 storres
  if (monomials == NULL || (lengthChain(monomials) != degree + 1))
544 26 storres
  {
545 26 storres
    pobyso_error_message("pobyso_remez_canonical_monomials_base",
546 26 storres
                        "CHAIN_CREATION_ERROR",
547 26 storres
                        "could not create the monomials chain");
548 26 storres
    return(NULL);
549 26 storres
  }
550 26 storres
  curMonomial = monomials;
551 26 storres

552 26 storres
  while (curMonomial != NULL)
553 26 storres
  {
554 26 storres
    fprintf(stderr, "monomial tree: ");
555 26 storres
    //mpfr_out_str(stderr, 10, 17, *((mpfr_t*)((node*)(curMonomial->value))->value), MPFR_RNDN);
556 26 storres
    fprintTree(stderr, (node*)(curMonomial->value));
557 26 storres
    fprintf(stderr, "\n");
558 26 storres
    curMonomial = curMonomial->next;
559 26 storres
  }
560 26 storres

561 26 storres
  /* Deal with NULL weight. */
562 26 storres
  if (weight == NULL)
563 26 storres
  {
564 26 storres
    weight = makeConstantDouble(1.0);
565 26 storres
  }
566 26 storres
  /* Compute the best polynomial with the required quality.
567 26 storres
     The behavior is as if satisfying error and target_error had
568 26 storres
     not been used.*/
569 26 storres
  mpfr_init(satisfying_error);
570 26 storres
  mpfr_init(target_error);
571 26 storres
  mpfr_set_str(satisfying_error, "0", 10, MPFR_RNDN);
572 26 storres
  mpfr_set_inf(target_error, 1);
573 26 storres

574 26 storres

575 26 storres
  fprintf(stderr, "satisfying_error: ");
576 26 storres
  mpfr_out_str(stderr, 10, 17, satisfying_error, MPFR_RNDN);
577 26 storres
  fprintf(stderr, ".\n");
578 26 storres
  fprintf(stderr, "target_error: ");
579 26 storres
  mpfr_out_str(stderr, 10, 17, target_error,MPFR_RNDN);
580 26 storres
  fprintf(stderr, ".\n");
581 26 storres

582 26 storres
  fprintf(stderr,
583 26 storres
          "current precision: %li\n", getToolPrecision());
584 26 storres
  /* Call the Sollya function. */
585 26 storres
  bestApproxPoly = remez(function,
586 26 storres
                          weight,
587 26 storres
                          monomials,
588 26 storres
                          lowerBound,
589 26 storres
                          upperBound,
590 26 storres
                          quality,
591 26 storres
                          satisfying_error,
592 26 storres
                          target_error,
593 26 storres
                          getToolPrecision());
594 26 storres

595 26 storres
  mpfr_clear(satisfying_error);
596 26 storres
  mpfr_clear(target_error);
597 26 storres
  pobyso_free_chain_of_nodes(monomials);
598 26 storres

599 26 storres
  return(bestApproxPoly);
600 26 storres
} /* End pobyso_remez_canonical_monomials_base. */
601 26 storres

602 26 storres
#endif
603 26 storres
604 26 storres
void
605 26 storres
pobyso_error_message(char *functionName, char *messageName, char* message)
606 26 storres
{
607 26 storres
  fprintf(stderr, "?%s: %s.\n%s.\n", functionName, messageName, message);
608 26 storres
} /* End pobyso_error_message */