Statistiques
| Révision :

root / pobysoC-4.0 / src / test-pobyso-dirty-find-zeros.c @ 298

Historique | Voir | Annoter | Télécharger (5,53 ko)

1
/** @file test-pobyso-dirty-find-zeros.c
2
 * Name & purpose
3
 *
4
 * Three arguments are expected : an functional expression, a lowerBound
5
 * and an upper bound. The zeroes of the functional expression are
6
 * searched for over the [lower bound, upper bound] interval.
7
 * If only the functional expression is literally "NULL" the
8
 * pobyso_dirty_find_zeros is tested with a NULL argument as for the function.
9
 *
10
 * The others arguments are not looked for.
11
 *
12
 * @author S. T.
13
 * @date 2014-12-05
14
 *
15
 * @details Verbosity manipulation are performed  to make sur  that verbosity
16
 *  suppression is correctly managed in pobyso_is_constant_expression()
17
 *  function.
18
 */
19
/******************************************************************************/
20
/* Headers, applying the "particular to general" convention.*/
21

    
22
#include "pobyso.h"
23

    
24
/* includes of local headers */
25

    
26
/* includes of project headers */
27

    
28
/* includes of system headers */
29
#include <stdlib.h>
30
/* Other declarations */
31

    
32
/* Internal prototypes */
33

    
34
/* Types, constants and macros definitions */
35

    
36
/* Global variables */
37

    
38
/* Functions */
39

    
40
int
41
main(int argc, char** argv)
42
{
43
  pobyso_func_exp_t funcExpSo  = NULL;
44
  sollya_obj_t lowerBoundSo = NULL;
45
  sollya_obj_t upperBoundSo = NULL;
46
  mpfr_t lowerBoundMp;
47
  mpfr_t upperBoundMp;
48
  int zerosCount = 0;
49
  mpfr_t* zerosArrayMp = NULL;
50
  int i;
51

    
52
  sollya_lib_init();
53

    
54
  /* Two command line arguments expected. */
55
  if (argc < 4)
56
  {
57
    fprintf(stderr,"\n\n");
58
    fprintf(stderr, "Usage: %s funcExp lowerBound upperBound\n", argv[0]);
59
    fprintf(stderr,
60
            "            funcExp: a quoted functional expression for Sollya;\n");
61
    fprintf(stderr,
62
            "            lowerBound: a (possibly quoted) Sollya constant expression for the lower bound;\n");
63
    fprintf(stderr,
64
            "            upperBound: a (possibly quoted) Sollya constant expression for the upper bound.");
65
    fprintf(stderr,"\n\n");
66
    sollya_lib_close();
67
    return 1;
68
  }
69

    
70
  if (! strcmp(argv[1], "NULL")) /* First parameter is the "NULL" string) */
71
  {
72
    zerosArrayMp = pobyso_dirty_find_zeros_bounds(NULL,
73
                                                  lowerBoundMp,
74
                                                  upperBoundMp,
75
                                                  &zerosCount);
76
    sollya_lib_close();
77
    /* No clean up needed. */
78
    return 1;
79
  }
80
  pobyso_set_canonical_on();
81
  lowerBoundSo = pobyso_parse_string(argv[2]);
82
  if (lowerBoundSo == NULL)
83
  {
84
    fprintf(stderr,
85
        "\n\n%s: can't parse \"%s\" to a valid expression. Aborting!\n\n",
86
        argv[0], argv[2]);
87
    sollya_lib_close();
88
    return 1;
89
  }
90
  upperBoundSo = pobyso_parse_string(argv[3]);
91
  if (upperBoundSo == NULL)
92
  {
93
    fprintf(stderr,
94
        "\n\n%s: can't parse \"%s\" to a valid expression. Aborting!\n\n",
95
        argv[0], argv[3]);
96
    sollya_lib_clear_obj(lowerBoundSo);
97
    sollya_lib_close();
98
    return 1;
99
  }
100
  if (! pobyso_is_constant_expression(lowerBoundSo) ||
101
      ! pobyso_is_constant_expression(upperBoundSo))
102
  {
103
    fprintf(stderr,
104
        "\n\n%s: can't evaluate \"%s\" nor  \"%s\" to a constant expression. Aborting!\n\n",
105
        argv[0], argv[2], argv[3]);
106
    sollya_lib_clear_obj(lowerBoundSo);
107
    sollya_lib_clear_obj(upperBoundSo);
108
    sollya_lib_close();
109
    return 1;
110
  }
111
  mpfr_init2(lowerBoundMp, 512);
112
  if (! sollya_lib_get_constant(lowerBoundMp, lowerBoundSo))
113
  {
114
    fprintf(stderr,
115
        "\n\n%s: can't recover the value of \"%s\". Aborting!\n\n",
116
        argv[0], argv[2]);
117
    mpfr_clear(lowerBoundMp);
118
    sollya_lib_clear_obj(lowerBoundSo);
119
    sollya_lib_clear_obj(upperBoundSo);
120
    sollya_lib_close();
121
    return 1;
122
  }
123
  mpfr_init2(upperBoundMp, 512);
124
  if (! sollya_lib_get_constant(upperBoundMp, upperBoundSo))
125
  {
126
    fprintf(stderr,
127
        "\n\n%s: can't recover the value of \"%s\". Aborting!\n\n",
128
        argv[0], argv[3]);
129
    mpfr_clear(lowerBoundMp);
130
    mpfr_clear(upperBoundMp);
131
    sollya_lib_clear_obj(lowerBoundSo);
132
    sollya_lib_clear_obj(upperBoundSo);
133
    sollya_lib_close();
134
    return 1;
135
  }
136
  if (argc > 4)
137
  {
138
    fprintf(stdout, "Bounds: [");
139
    mpfr_out_str(stdout, 10, 0, lowerBoundMp, MPFR_RNDN);
140
    fprintf(stdout, ", ");
141
    mpfr_out_str(stdout, 10, 0, upperBoundMp, MPFR_RNDN);
142
    fprintf(stdout, "]\n");
143
  }
144
  /* Not needed any more. */
145
  sollya_lib_clear_obj(lowerBoundSo);
146
  sollya_lib_clear_obj(upperBoundSo);
147
  funcExpSo = pobyso_parse_string(argv[1]);
148
  if (funcExpSo == NULL)
149
  {
150
    fprintf(stderr,
151
        "\n\n%s: could not parse \"%s\" as a valid Sollya expression. Aborting!\n\n",
152
        argv[0], argv[1]);
153
    mpfr_clear(lowerBoundMp);
154
    mpfr_clear(upperBoundMp);
155
    sollya_lib_close();
156
    return 1;
157
  }
158
  if (argc > 4)
159
  {
160
    fprintf(stdout, "Functional expression: ");
161
    pobyso_autoprint(funcExpSo);
162
  }
163
  zerosArrayMp = pobyso_dirty_find_zeros_bounds(funcExpSo,
164
                                              lowerBoundMp,
165
                                              upperBoundMp,
166
                                              &zerosCount);
167
  sollya_lib_clear_obj(funcExpSo);
168
  mpfr_clear(lowerBoundMp);
169
  mpfr_clear(upperBoundMp);
170
  if (zerosCount < 0)
171
  {
172
    return 1;
173
  }
174
  if (zerosCount == 0)
175
  {
176
    return 0;
177
  }
178
  if (zerosCount > 0)
179
  {
180
    fprintf(stdout, "Zeroes: ");
181
    for (i = 0 ; i < zerosCount ; i++)
182
    {
183
      mpfr_out_str(stdout, 10, 0, zerosArrayMp[i], MPFR_RNDN);
184
      mpfr_clear(zerosArrayMp[i]);
185
      if (i < zerosCount-1) fprintf(stdout, ", ");
186
    }
187
    fprintf(stdout, ".\n");
188
  }
189
  else
190
  {
191
    fprintf(stdout, "No zeroes!\n");
192
  }
193
  if (zerosCount > 0) free(zerosArrayMp);
194
  sollya_lib_close();
195
  return 0;
196
} /* End main */