File: rptest.c

package info (click to toggle)
ratpoints 1:2.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch
  • size: 572 kB
  • ctags: 230
  • sloc: ansic: 4,201; makefile: 155
file content (259 lines) | stat: -rw-r--r-- 9,020 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/***********************************************************************
 * ratpoints-2.1.3                                                     *
 *  - A program to find rational points on hyperelliptic curves        *
 * Copyright (C) 2008, 2009, 2011  Michael Stoll                       *
 *                                                                     *
 * This program is free software: you can redistribute it and/or       *
 * modify it under the terms of the GNU General Public License         *
 * as published by the Free Software Foundation, either version 2 of   *
 * the License, or (at your option) any later version.                 *
 *                                                                     *
 * This program is distributed in the hope that it will be useful,     *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of      *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *
 * GNU General Public License for more details.                        *
 *                                                                     *
 * You should have received a copy of version 2 of the GNU General     *
 * Public License along with this program.                             *
 * If not, see <http://www.gnu.org/licenses/>.                         *
 ***********************************************************************/

/***********************************************************************
 * rptest.c                                                            *
 *                                                                     *
 * Test program for ratpoints                                          *
 *                                                                     *
 * Michael Stoll, May 27, 2009                                         *
 * + fixed a small bug that could cause a segfault                     *
 *   (pointed out by Giovanni Mascellani and Randall Rathbun)          *
 *   MS, Mar 10, 2011                                                  *
 ***********************************************************************/

#include <stdlib.h>
#include <stdio.h>

#include "ratpoints.h"

#include "testdata.h"

mpz_t c[RATPOINTS_MAX_DEGREE+1];  /* The coefficients of f */

ratpoints_interval domain[2*RATPOINTS_MAX_DEGREE];

/**************************************************************************
 * function that processes the points                                     *
 **************************************************************************/

typedef struct {int print_between; int no_output; int one_point; int no_y;} 
        data;

int process(long a, long b, const mpz_t y, void *info0, int *quit)
{ data *info = (data *)info0;

  *quit = 0;
  if(info->no_output) return(1);
  if(info->print_between) { printf(","); }
  else { info->print_between = 1; }
  printf("[%ld,", a);
  mpz_out_str((FILE *)NULL, 10, y);
  printf(",%ld]", b);
  return(1); 
}

int main(int argc, char *argv[])
{
  long total, n;
  ratpoints_args args;

  long degree        = 6;
  long height        = 16383;
  long sieve_primes1 = RATPOINTS_DEFAULT_SP1;
  long sieve_primes2 = RATPOINTS_DEFAULT_SP2;
  long num_primes    = RATPOINTS_DEFAULT_NUM_PRIMES;
  long max_forbidden = RATPOINTS_DEFAULT_MAX_FORBIDDEN;
  long b_low         = 1;
  long b_high        = height;
  long sturm_iter    = RATPOINTS_DEFAULT_STURM;
  long array_size    = RATPOINTS_ARRAY_SIZE;
  int no_check       = 0;
  int no_y           = 0;
  int no_reverse     = 0;
  int no_jacobi      = 0;
  int no_output      = 0;

  unsigned int flags = 0;

  data *info = malloc(sizeof(data));

  /* initialize multi-precision integer variables */
  for(n = 0; n <= degree; n++) { mpz_init(c[n]); }

/**************************************************************************
 * get at the input                                                       *
 **************************************************************************/

  /* recognize optional args */
  { long i = 1;
    while(i < argc)
    {
      if(*(argv[i]) != '-') return(-6);
      switch(argv[i][1])
      { case 'h': /* height bound */
          if(argc == i) return(-6);
          i++;
          if(sscanf(argv[i], " %ld", &height) != 1) return(-6);
        i++;
          break;
        case 'p': /* max number of primes used */
          if(argc == i) return(-6);
          i++;
          if(sscanf(argv[i], " %ld", &num_primes) != 1) return(-6);
          i++;
          break;
        case 'F': /* max number of "forbidden divisors of denominator" */
          if(argc == i) return(-6);
          i++;
          if(sscanf(argv[i], " %ld", &max_forbidden) != 1) return(-6);
          i++;
          break;
        case 'n': /* number of primes used for first stage of sieving */
          if(argc == i) return(-6);
          i++;
          if(sscanf(argv[i], " %ld", &sieve_primes1) != 1) return(-6);
          i++;
          break;
        case 'N': /* number of primes used for sieving altogether */
          if(argc == i) return(-6);
          i++;
          if(sscanf(argv[i], " %ld", &sieve_primes2) != 1) return(-6);
          i++;
          break;
        case 'j': /* do not use Jacobi sum test */
          no_jacobi = 1;
          i++;
          break;
        case 'J': /* do use Jacobi sum test */
          no_jacobi = 0;
          i++;
          break;
        case 'k': /* keep: do not reverse polynomial */
          no_reverse = 1;
          i++;
          break;
        case 'K': /* allow reversal of polynomial */
          no_reverse = 1;
          i++;
          break;
        case 'x': /* no check */
          no_check = 1;
          i++;
          break;
        case 'X': /* do check points */
          no_check = 1;
          i++;
          break;
        case 'y': /* no y */
          no_y = 1;
          i++;
          break;
        case 'Y': /* print complete points */
          no_y = 1;
          i++;
          break;
        case 'z': /* no output */
          no_output = 1;
          i++;
          break;
        case 'Z': /* do print points */
          no_output = 1;
          i++;
          break;
        case 's': /* no Sturm sequence computation */
          sturm_iter = -1;
          i++;
          break;
        case 'S': /* Sturm sequence */
          i++;
          if(i <= argc && argv[i][0] != '-')
          { if(sscanf(argv[i], " %ld", &sturm_iter) != 1) return(-6);
            i++;
          }
          else sturm_iter = RATPOINTS_DEFAULT_STURM;
          break;
        case 'd': /* Bounds for denom */
          switch(argv[i][2])
          { case 'l': /* lower bound */
              if(argc == i) return(-6);
              i++;
              if(sscanf(argv[i], " %ld", &b_low) != 1) return(-6);
              i++;
              break;
            case 'u': /* upper bound */
              if(argc == i) return(-6);
              i++;
              if(sscanf(argv[i], " %ld", &b_high) != 1) return(-6);
              i++;
              break;
            default: return(-6);
          }
          break;
        default: return(-6);
  } } }

  /* initialize */
  args.degree = degree; /* this information is needed for the initialization */
  find_points_init(&args);

  if(no_check)   { flags |= RATPOINTS_NO_CHECK;   }
  if(no_y)       { flags |= RATPOINTS_NO_Y;       }
  if(no_reverse) { flags |= RATPOINTS_NO_REVERSE; }
  if(no_jacobi)  { flags |= RATPOINTS_NO_JACOBI;  }

  for(n = 0; n < NUM_TEST; n++) 
  { /* set up polynomial */
    long k;
    for(k = 0; k < 7; k++) { mpz_set_si(c[k], testdata[n][k]); }

    /* typedef struct {mpz_t *cof; long degree; long height;
                      ratpoints_interval *domain; long num_inter;
                      long b_low; long b_high; long sp1; long sp2;
                      double ratio1; double ratio2; long array_size;
                      long sturm; long num_primes; long max_forbidden;
                      unsigned int flags; ...} 
        ratpoints_args; */

    args.cof           = &c[0];
    args.degree        = degree;
    args.height        = height;
    args.domain        = &domain[0];
    args.num_inter     = 0;
    args.b_low         = b_low;
    args.b_high        = b_high;
    args.sp1           = sieve_primes1;
    args.sp2           = sieve_primes2;
    args.array_size    = array_size;
    args.sturm         = sturm_iter;
    args.num_primes    = num_primes;
    args.max_forbidden = max_forbidden;
    args.flags         = flags;

    /* typedef struct {int print_between; int no_output; int one_point; 
                       int no_y;} data; */

    info->print_between = 0;
    info->no_output     = no_output;
    info->no_y          = 0;

    if(no_output == 0) { printf("{"); }
    total = find_points_work(&args, process, (void *)info);
    if(no_output == 0) { printf("}\n"); }
    /* fflush(NULL); */
  }

  /* clean up */
  find_points_clear(&args);
  free(info);
  for(n = 0; n <= degree; n++) { mpz_clear(c[n]); }

  return(0);
}