ratpoints-2.1.3+dfsg.orig/0000755000175000017500000000000012153705323014073 5ustar tobitobiratpoints-2.1.3+dfsg.orig/sift.c0000644000175000017500000002304011536145472015212 0ustar tobitobi/*********************************************************************** * ratpoints-2.1.2 * * - A program to find rational points on hyperelliptic curves * * Copyright (C) 2008, 2009 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 . * ***********************************************************************/ /*********************************************************************** * sift.c * * * * The sieving procedure for ratpoints * * * * Michael Stoll, Apr 14, 2009 * ***********************************************************************/ #include "rp-private.h" /************************************************************************** * check if m and n are relatively prime * **************************************************************************/ static inline int relprime(long m, long n) { /* n (the denominator) is always positive here */ if(m == 0) { return(n == 1); } if(m < 0) m = -m; if(!(m & 1)) { if(!(n & 1)) { return(0); } m >>= 1; while(!(m & 1)) { m >>= 1; } } while(!(n & 1)) { n >>= 1; } while(n != m) { if(n > m) { n -= m; n >>= 1; while(!(n & 1)) { n >>= 1; } } else { m -= n; m >>= 1; while(!(m & 1)) { m >>= 1; } } } return(m == 1); } /************************************************************************** * Try to avoid divisions * **************************************************************************/ static inline long mod(long a, long b) { long b1 = b << 4; /* b1 = 16*b */ if(a < -b1) { a %= b; if(a < 0) { a += b; } return(a); } if(a < 0) { a += b1; } else { if(a >= b1) { return(a % b); } } b1 >>= 1; /* b1 = 8*b */ if(a >= b1) { a -= b1; } b1 >>= 1; /* b1 = 4*b */ if(a >= b1) { a -= b1; } b1 >>= 1; /* b1 = 2*b */ if(a >= b1) { a -= b1; } if(a >= b) { a -= b; } return(a); } /************************************************************************** * The inner loop of the sieving procedure * **************************************************************************/ long _ratpoints_sift0(long b, long w_low, long w_high, ratpoints_args *args, bit_selection which_bits, ratpoints_bit_array *survivors, sieve_spec *sieves, int *quit, int process(long, long, const mpz_t, void*, int*), void *info) { long total = 0; long range = w_high - w_low; long sp1 = args->sp1; long sp2 = args->sp2; #ifdef DEBUG { long n, c = 0; printf("\nsift0(b = %ld) @ start [high numerators to the left]:\n", b); for(n = range - 1; n >= 0; n--, c++) { if((c & (0xff >> RBA_SHIFT)) == 0) { printf("\n"); } #ifdef USE_SSE printf("%*.*lx%*.*lx ", WIDTH, WIDTH, EXT1(survivors[n]), WIDTH, WIDTH, EXT0(survivors[n])); #else printf("%*.*lx ", WIDTH, WIDTH, survivors[n]); #endif } printf("\n"); fflush(NULL); } #endif /* now do the sieving (fast!) */ #ifdef DEBUG printf("\nsift0: sp1 = %ld, sp2 = %ld\n\n", sp1, sp2); fflush(NULL); #endif { long n; for(n = 0; n < sp1; n++) { ratpoints_bit_array *sieve_n = sieves[n].ptr; register long p = sieves[n].p; long r = mod(-w_low-sieves[n].offset, p); register ratpoints_bit_array *surv = survivors; if(w_high < w_low + r) { /* if we get here, r > 0, since w_high >= w_low always */ register ratpoints_bit_array *siv1 = &sieve_n[p-r]; register ratpoints_bit_array *siv0 = siv1 + range; while(siv1 != siv0) #ifdef USE_SSE { *surv = AND(*surv, *siv1++); surv++; } #else { *surv++ &= *siv1++; } #endif } else { register ratpoints_bit_array *siv1 = &sieve_n[p-r]; register ratpoints_bit_array *surv_end = &survivors[range - p]; { register long i; for(i = r; i; i--) #ifdef USE_SSE { *surv = AND(*surv, *siv1++); surv++; } #else { *surv++ &= *siv1++; } #endif } siv1 -= p; while(surv <= surv_end) { register long i; for(i = p; i; i--) #ifdef USE_SSE { *surv = AND(*surv, *siv1++); surv++; } #else { *surv++ &= *siv1++; } #endif siv1 -= p; } surv_end += p; while(surv < surv_end) #ifdef USE_SSE { *surv = AND(*surv, *siv1++); surv++; } #else { *surv++ &= *siv1++; } #endif } #ifdef DEBUG { long k, c = 0; printf("\nsift0 after prime p = %ld [high numerators to the left]:", p); for(k = range - 1; k >= 0; k--, c++) { if((c & (0xff >> RBA_SHIFT)) == 0) { printf("\n"); } #ifdef USE_SSE printf("%*.*lx%*.*lx ", WIDTH, WIDTH, EXT1(survivors[k]), WIDTH, WIDTH, EXT0(survivors[k])); #else printf("%*.*lx ", WIDTH, WIDTH, survivors[k]); #endif } printf("\n"); fflush(NULL); } #endif } /* for n */ } #ifdef DEBUG { long n, c = 0; printf("\nsift0(b = %ld) after phase 1 [high numerators to the left]:\n", b); for(n = range - 1; n >= 0; n--, c++) { if((c & (0xff >> RBA_SHIFT)) == 0) { printf("\n"); } #ifdef USE_SSE printf("%*.*lx%*.*lx ", WIDTH, WIDTH, EXT1(survivors[n]), WIDTH, WIDTH, EXT0(survivors[n])); #else printf("%*.*lx ", WIDTH, WIDTH, survivors[n]); #endif } printf("\n\n"); fflush(NULL); } #endif /* Second phase of the sieve: test each surviving bit array with more primes */ { ratpoints_bit_array *surv0 = &survivors[0]; long i; for(i = w_low; i < w_high; i++) { register ratpoints_bit_array nums = *surv0++; sieve_spec *ssp = &sieves[sp1]; register long n; #ifdef DEBUG #ifdef USE_SSE if(TEST(nums)) { printf("\nsurviving word %*.*lx%*.*lx @ i = %ld\n", WIDTH, WIDTH, EXT1(nums), WIDTH, WIDTH, EXT0(nums), i); #else if(nums) { printf("\nsurviving word %*.*lx @ i = %ld\n", WIDTH, WIDTH, nums, i); #endif fflush(NULL); } #endif #ifdef USE_SSE for(n = sp2-sp1; n && TEST(nums); n--) #else for(n = sp2-sp1; n && nums; n--) #endif { register long p = ssp->p; #ifdef USE_SSE nums = AND(nums, ssp->ptr[mod(i + ssp->offset, p)]); #else nums &= ssp->ptr[mod(i + ssp->offset, p)]; #endif #ifdef DEBUG #ifdef USE_SSE printf("after prime p = %ld: %*.*lx%*.*lx\n", p, WIDTH, WIDTH, EXT1(nums), WIDTH, WIDTH, EXT0(nums)); #else printf("after prime p = %ld: %*.*lx\n", p, WIDTH, WIDTH, nums); #endif fflush(NULL); #endif ssp++; } /* Check the survivors of the sieve if they really give points */ #ifdef USE_SSE if(TEST(nums)) #else if(nums) #endif { long a0, a, da, d; /* a will be the numerator corresponding to the selected bit */ #ifdef DEBUG long bit = 0; #endif if(which_bits == num_all) { d = 1; a0 = i << RBA_SHIFT; da = RBA_LENGTH/2; } else { d = 2; a0 = i << (RBA_SHIFT+1); da = RBA_LENGTH; if(which_bits == num_odd) { a0++; } } { #ifdef USE_SSE unsigned long nums0 = EXT0(nums); unsigned long nums1 = EXT1(nums); #else unsigned long nums0 = nums; #endif for(a = a0; nums0; a += d, nums0 >>= 1) { /* test one bit */ if((nums0 & 1) && relprime(a, b)) { #ifdef DEBUG printf("\nsurviving bit no. %ld --> a = %ld. Check point...\n", bit, a); fflush(NULL); #endif total += _ratpoints_check_point(a, b, args, quit, process, info); if(*quit) return(total); } #ifdef DEBUG bit++; #endif } #ifdef USE_SSE #ifdef DEBUG bit = 0; #endif for(a = a0 + da; nums1; a += d, nums1 >>= 1) { /* test one bit */ if((nums1 & 1) && relprime(a, b)) { #ifdef DEBUG printf("\nsurviving bit no. %ld --> a = %ld. Check point...\n", bit+64, a); fflush(NULL); #endif total += _ratpoints_check_point(a, b, args, quit, process, info); if(*quit) return(total); } #ifdef DEBUG bit++; #endif } #endif } } } } return(total); } ratpoints-2.1.3+dfsg.orig/sturm.c0000644000175000017500000002712411536145472015426 0ustar tobitobi/*********************************************************************** * ratpoints-2.1.2 * * - A program to find rational points on hyperelliptic curves * * Copyright (C) 2008, 2009 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 . * ***********************************************************************/ /*********************************************************************** * sturm.c * * * * Sturm sequence and positivity intervals * * * * Michael Stoll, Jan 9, 2008 * ***********************************************************************/ #include "ratpoints.h" /************************************************************************** * Arguments of _ratpoints_compute_sturm() : (from the args argument) * * * * + cofs - points to an array of mpz_t's holding the coefficients of * * the polynomial * * + degree - the degree of the polynomial * * + iter - the number of iteration steps in the refinement of the * * intervals * * + ivlist - points to an array of intervals giving the current search * * domain * * + num_iv - the number of intervals in ivlist, must be > 0 * * * * NOTE: ivlist must be able to store 1 + floor(degree/2) additional * * intervals. * * * * Return values : * * + >0 - normal operation, ivlist modified (intersection with positivity * * domain), return value is number of intervals * * + 0 - polynomial is everywhere negative, ivlist may be changed * * + -1 - polynomial is not squarefree, ivlist unchanged * **************************************************************************/ /* A helper function: evaluate the polynomial in cofs[] of given degree at num/2^denexp and return the sign. */ static long eval_sign(ratpoints_args *args, mpz_t *cofs, long degree, long num, long denexp) { long n, e, s; mpz_t *work = args->work; /* Horner scheme... */ mpz_set(work[0], cofs[degree]); for(n = degree-1, e = denexp; n >= 0; n--, e += denexp) { mpz_mul_si(work[0], work[0], num); mpz_mul_2exp(work[1], cofs[n], e); mpz_add(work[0], work[0], work[1]); } s = mpz_cmp_si(work[0], 0); return(s); } long _ratpoints_compute_sturm(ratpoints_args *args) { mpz_t *cofs = args->cof; long degree = args->degree; long iter = args->sturm; ratpoints_interval *ivlist = args->domain; long num_iv = args->num_inter; long n, m, k, new_num; mpz_t sturm[degree+1][degree+1]; /* Array to hold the polynomials */ long sturm_degs[degree+1]; /* The degrees of the polynomials */ mpz_t *work = args->work; long count1 = 0, count2 = 0; /* first initialize */ for(n = 0; n <= degree; n++) for(m = 0; m <= degree; m++) { mpz_init(sturm[n][m]); } /* copy polynomial f into first entry */ for(n = 0; n <= degree; n++) mpz_set(sturm[0][n], cofs[n]); sturm_degs[0] = degree; /* compute derivative in second entry */ for(n = 0; n < degree; n++) { mpz_set(work[2], cofs[n+1]); mpz_mul_si(sturm[1][n], work[2], n+1); } sturm_degs[1] = degree - 1; /* now do polynomial divisions ... */ for(k = 2; k <= degree; k++) { long d1 = sturm_degs[k-1], d2 = sturm_degs[k-2]; /* first copy sturm[k-2] into sturm[k] */ for(n = 0; n <= degree - (k-2); n++) mpz_set(sturm[k][n], sturm[k-2][n]); /* now build linear combination that reduces the degree */ while(d2 >= d1) { mpz_gcd(work[2], sturm[k-1][d1], sturm[k][d2]); mpz_fdiv_q(work[0], sturm[k-1][d1], work[2]); mpz_fdiv_q(work[1], sturm[k][d2], work[2]); if(mpz_cmp_si(work[0], 0) < 0) { mpz_neg(work[0], work[0]); mpz_neg(work[1], work[1]); } /* sturm[k] = work[0] * sturm[k] - work[1] * x^(d2-d1) * sturm[k-1] */ for(n = 0; n <= d1; n++) { mpz_mul(sturm[k][n+d2-d1], sturm[k][n+d2-d1], work[0]); mpz_submul(sturm[k][n+d2-d1], work[1], sturm[k-1][n]); } for(n = 0; n < d2-d1; n++) { mpz_mul(sturm[k][n], sturm[k][n], work[0]); } d2--; while(mpz_cmp_si(sturm[k][d2], 0) == 0 && d2 >= 0) d2--; if(d2 < 0) /* not squarefree */ { for(n = 0; n <= degree; n++) for(m = 0; m <= degree; m++) { mpz_clear(sturm[n][m]); } return(-1); } } /* change sign */ for(n = 0; n <= d2; n++) mpz_neg(sturm[k][n], sturm[k][n]); /* normalize */ mpz_set_ui(work[2], 0); for(n = 0; n <= d2; n++) { mpz_gcd(work[2], work[2], sturm[k][n]); if(mpz_cmp_ui(work[2], 1) == 0) break; } if(mpz_cmp_ui(work[2], 1) != 0) { for(n = 0; n <= d2; n++) mpz_fdiv_q(sturm[k][n], sturm[k][n], work[2]); } sturm_degs[k] = d2; if(d2 == 0) break; /* sturm[k] is constant */ } /* compute number of real zeros */ for(n = 0; n < k; n++) { long d1 = sturm_degs[n], d2 = sturm_degs[n+1]; int s1 = mpz_cmp_si(sturm[n][d1], 0), s2 = mpz_cmp_si(sturm[n+1][d2], 0); if(s1 != s2) count1++; if(d1 & 1) s1 = -s1; if(d2 & 1) s2 = -s2; if(s1 != s2) count2++; } if(count2 == count1 && mpz_cmp_si(cofs[0], 0) < 0) { /* no real roots, negative constant term ==> no points */ for(n = 0; n <= degree; n++) for(m = 0; m <= degree; m++) { mpz_clear(sturm[n][m]); } args->num_inter = 0; return(0); } /* Find list of intervals that may contain points */ /* recall: typedef struct {double low; double up;} ratpoints_interval; */ { ratpoints_interval ivlocal[1 + (degree>>1)]; ratpoints_interval *iptr = &ivlocal[0]; long max = (long)(((unsigned long)(-1))>>1); long min = -max; long num_intervals; long slcf = mpz_cmp_si(cofs[degree], 0); /* recursive helper function */ void iterate(long nl, long nr, long del, long der, long cleft, long cright, long sl, long sr, long depth) { /* nl/2^del, nr/2^der : interval left/right endpoints, cleft, cright: sign change counts at endpoints, sl, sr: signs at endpoints, depth: iteration depth */ if(cleft == cright && sl < 0) { return; } /* here we know the polynomial is negative on the interval */ if((cleft == cright && sl > 0) || depth >= iter) /* we have to add/extend an interval if we either know that the polynomial is positive on the interval (first condition) or the maximal iteration depth has been reached (second condition) */ { double l = ((double)nl)/((double)(1<low = l; iptr->up = u; iptr++; } else { if((iptr-1)->up == l) /* extend interval */ { (iptr-1)->up = u; } else /* new interval */ { iptr->low = l; iptr->up = u; iptr++; } } return; } /* now we must split the interval and evaluate the sturm sequence at the midpoint */ { long nm, dem, s0, s1, s2, s, cmid = 0, n; if(nl == min) { if(nr == max) { nm = 0; dem = 0; } else { nm = (nr == 0) ? -1 : 2*nr; dem = 0; } } else { if(nr == max) { nm = (nl == 0) ? 1 : 2*nl; dem = 0; } else /* "normal" case */ { if(del == der) /* then both are zero */ { if(((nl+nr) & 1) == 0) { nm = (nl+nr)>>1; dem = 0; } else { nm = nl+nr; dem = 1; } } else /* here one de* is greater */ { if(del > der) { nm = nl + (nr<<(del-der)); dem = del+1; } else { nm = (nl<<(der-del)) + nr; dem = der+1; } } } } s0 = eval_sign(args, sturm[0], sturm_degs[0], nm, dem); s1 = eval_sign(args, sturm[1], sturm_degs[1], nm, dem); if(s0*s1 == -1) { cmid++; } s = (s1 == 0) ? s0 : s1; for(n = 2; n <= k; n++) { s2 = eval_sign(args, sturm[n], sturm_degs[n], nm, dem); if(s2 == -s) { cmid++; s = s2; } else if(s2 != 0) { s = s2; } } /* now recurse */ iterate(nl, nm, del, dem, cleft, (s0==0) ? (cmid+1) : cmid, sl, (s0==0) ? -s1 : s0, depth+1); iterate(nm, nr, dem, der, cmid, cright, (s0==0) ? s1 : s0, sr, depth+1); } } /* end iterate() */ iterate(min, max, 0, 0, count2, count1, (degree & 1) ? -slcf : slcf, slcf, 0); num_intervals = iptr - &ivlocal[0]; /* intersect with given intervals */ { ratpoints_interval local_copy[num_iv]; long n, n1, n2; /* make a copy of the given list */ for(n = 0; n < num_iv; n++) local_copy[n] = ivlist[n]; n1 = 0; n2 = 0; n = 0; while(n1 < num_intervals && n2 < num_iv) { if(ivlocal[n1].low <= local_copy[n2].low) { if(ivlocal[n1].up < local_copy[n2].low) { n1++; } /* can forget this interval */ else { if(ivlocal[n1].up <= local_copy[n2].up) { /* note intersection */ ivlist[n].low = local_copy[n2].low; ivlist[n].up = ivlocal[n1].up; n++; n1++; } else { /* note intersection */ ivlist[n] = local_copy[n2]; n++; n2++; } } } else /* here, ivlocal[n1].low > local_copy[n2].low */ { if(local_copy[n2].up < ivlocal[n1].low) { n2++; } /* can forget this interval */ else { if(local_copy[n2].up <= ivlocal[n1].up) { /* note intersection */ ivlist[n].low = ivlocal[n1].low; ivlist[n].up = local_copy[n2].up; n++; n2++; } else { /* note intersection */ ivlist[n] = ivlocal[n1]; n++; n1++; } } } } args->num_inter = new_num = n; } } for(n = 0; n <= degree; n++) for(m = 0; m <= degree; m++) { mpz_clear(sturm[n][m]); } return(new_num); } ratpoints-2.1.3+dfsg.orig/rp-private.h0000644000175000017500000001355011536145472016350 0ustar tobitobi/*********************************************************************** * ratpoints-2.1.2 * * - A program to find rational points on hyperelliptic curves * * Copyright (C) 2008, 2009 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 . * ***********************************************************************/ /*********************************************************************** * rp-private.h * * * * Header file with information local to the ratpoints code * * * * Michael Stoll, Apr 14, 2009 * ***********************************************************************/ #include #include #include #include #define LONG_LENGTH (8*sizeof(long)) /* number of bits in an unsigned long */ #define LONG_SHIFT ((LONG_LENGTH == 16) ? 4 : \ (LONG_LENGTH == 32) ? 5 : \ (LONG_LENGTH == 64) ? 6 : 0) #define LONG_MASK (~(-1L< #define AND(a,b) ((ratpoints_bit_array)__builtin_ia32_andps((__v4sf)(a), (__v4sf)(b))) #define EXT0(a) ((unsigned long)__builtin_ia32_vec_ext_v2di((__v2di)(a), 0)) #define EXT1(a) ((unsigned long)__builtin_ia32_vec_ext_v2di((__v2di)(a), 1)) #define TEST(a) (EXT0(a) || EXT1(a)) #define RBA(a,b) ((__v2di){(a), (b)}) /* Use SSE 128 bit registers for the bit arrays */ typedef __v2di ratpoints_bit_array; #define zero (RBA(0LL, 0LL)) #define RBA_LENGTH (128) /* number of bits in a ratpoints_bit_array */ #define RBA_SHIFT ((RBA_LENGTH == 128) ? 7 : 0) #define RBA_MASK (~(-1L<. * ***********************************************************************/ /*********************************************************************** * testdata.h * * * * A list of 1000 genus 2 curves to serve as test data for ratpoints * * * * Michael Stoll, Jan 9, 2008 * ***********************************************************************/ #define NUM_TEST 1000 long testdata[NUM_TEST][7] = { {-10,-8,1,-2,0,-5,-4}, {4,-6,-4,-7,-8,5,-3}, {4,-8,2,-3,-1,0,-6}, {0,5,6,2,-7,4,-8}, {-5,10,-9,-6,7,-1,3}, {0,-8,-6,-9,-8,-6,-9}, {-6,5,7,-10,-1,1,-2},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7,9,0,-9}, {-9,9,-7,9,-7,-10,0}, {-1,7,6,-6,4,-6,6}, {-9,-9,-7,8,-6,9,-3}, {5,-7,-1,-8,3,6,3}, {-1,-2,-10,2,-10,10,3}, {-5,-6,3,2,6,5,-7}, {-8,1,8,-1,7,-2,3}, {1,-6,-4,-8,2,2,6}, {3,0,1,6,-1,-1,-2}, {-10,0,1,8,2,0,3}, {6,-5,-6,7,9,-9,-10}, {-10,-10,-10,-5,-5,6,0}, {8,-4,-8,1,-10,8,-3}, {7,-3,3,-6,1,5,-6}, {8,10,10,7,6,-3,0}, {4,-6,6,-3,6,0,7}, {9,-7,-3,10,-2,-2,-4}, {4,-1,-4,-8,-3,7,-7}, {-8,2,9,-4,0,-5,-7}, {-2,9,7,7,3,7,-5}, {8,5,10,-5,-8,-6,-3}, {0,6,-10,-5,-6,-7,10}, {-9,-2,3,-10,5,-9,-1}, {9,-4,-6,-10,10,7,8}, {-7,-4,-1,-1,4,7,-7}, {-9,-3,-5,-2,-7,-5,7}, {-6,8,4,-3,10,-7,9}, {-10,-2,4,1,8,-2,-3}, {3,-3,-7,-2,9,8,7}, {8,9,8,9,9,9,-1}, {-3,10,6,-4,3,1,-4}, {5,1,1,5,-10,-4,-2}, {-7,7,3,2,1,-5,0}, {0,-4,-10,-2,9,-3,-3}, {2,8,-7,-4,5,7,-9}, {4,-4,4,4,0,5,5}, {5,-2,2,-3,9,3,8}, {4,3,-8,3,-9,4,6} }; ratpoints-2.1.3+dfsg.orig/gen_find_points_h.c0000644000175000017500000001006111536145472017720 0ustar tobitobi/*********************************************************************** * ratpoints-2.1.2 * * - A program to find rational points on hyperelliptic curves * * Copyright (C) 2008, 2009 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 . * ***********************************************************************/ /*********************************************************************** * gen_find_points_h.c * * * * This program writes the file find_points.h * * * * Michael Stoll, Mar 8, 2009 * ***********************************************************************/ #include "rp-private.h" #include "primes.h" long inv_mod_p(long p, long b) { /* invert b mod p */ /* doesn't have to be fast... -- actually this will be faster in our range than the usual XGCD. */ long i = 1, n = b; while(1) { if(n%p == 1) return(i); i++; n += b; } } int main(int argc, char *argv[]) { long n; { int work[RATPOINTS_MAX_PRIME]; printf("static const int " "squares[RATPOINTS_NUM_PRIMES+1][RATPOINTS_MAX_PRIME] =\n{\n"); for(n = 0; n < RATPOINTS_NUM_PRIMES; n++) { long p = prime[n]; long i; work[0] = 1; for(i = 1; i < p; i++) work[i] = 0; /* record non-zero squares mod p, p odd */ for(i = 1; i < p; i += 2) work[(i*i) % p] = 1; printf("{"); for(i = 0; i < p; i++) { printf("%d", work[i]); if(i < p-1) printf(","); } printf((n < RATPOINTS_NUM_PRIMES - 1) ? "},\n " : "}\n};\n"); } } printf("static const long offsets[RATPOINTS_NUM_PRIMES] =\n{"); for(n = 0; n < RATPOINTS_NUM_PRIMES; n++) { long p = prime[n]; { printf("%ld", inv_mod_p(p, (2*RBA_LENGTH)%p)); } printf((n < RATPOINTS_NUM_PRIMES - 1) ? "," : "};\n\n"); } printf("static const long " "inverses[RATPOINTS_NUM_PRIMES][RATPOINTS_MAX_PRIME] =\n{"); for(n = 0; n < RATPOINTS_NUM_PRIMES; n++) { long p = prime[n]; long i; printf("{0"); for(i = 1; i < p; i++) { printf(",%ld", inv_mod_p(p, i)); } printf((n < RATPOINTS_NUM_PRIMES - 1) ? "},\n " : "}\n};\n"); } { unsigned long work[RATPOINTS_MAX_PRIME]; printf("unsigned long " "sieves0[RATPOINTS_NUM_PRIMES][2*RATPOINTS_MAX_PRIME_EVEN] =\n{\n"); for(n = 0; n < RATPOINTS_NUM_PRIMES; n++) { long p = prime[n]; long i; for(i = 0; i < p; i++) work[i] = ~0UL; for(i = 0; i < LONG_LENGTH; i++) { work[(p*i)>>LONG_SHIFT] &= ~(1UL<<((p*i) & LONG_MASK)); } printf("{"); for(i = 0; i < p; i++) { printf("0x%*.*lx, ", 16, 16, work[i]); } for(i = 0; i < p; i++) { printf("0x%*.*lx", 16, 16, work[i]); if(i < p-1) printf(", "); } printf((n < RATPOINTS_NUM_PRIMES - 1) ? "},\n" : "}\n"); } printf("};\n\n"); } return(0); } ratpoints-2.1.3+dfsg.orig/init.c0000644000175000017500000002560311536145472015217 0ustar tobitobi/*********************************************************************** * ratpoints-2.1.2 * * - A program to find rational points on hyperelliptic curves * * Copyright (C) 2008, 2009 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 . * ***********************************************************************/ /*********************************************************************** * init.c * * * * Macro definitions for the sieve_init functions * * * * Michael Stoll, Apr 14, 2009 * ***********************************************************************/ #include "rp-private.h" #ifdef USE_SSE /* The following is for primes < LONG_LENGTH */ #define CODE_INIT_SIEVE1(prime) \ static ratpoints_bit_array *sieve_init_##prime(void *se1, long b1, void *args1) \ { \ ratpoints_sieve_entry *se = se1; \ ratpoints_args *args = args1; \ register int *isfs = se->is_f_square; \ register long b = b1; \ long lmp = LONG_LENGTH % (prime); \ long ldp = LONG_LENGTH / (prime); \ long p1 = (ldp + 1) * (prime); \ long diff_shift = p1 & LONG_MASK; \ long diff = LONG_LENGTH - diff_shift; \ register unsigned long help0;\ { register long a; \ register long d = se->inverses[b]; \ register long ab = 0; /* a/b mod p */ \ register unsigned long test = 1UL; \ register unsigned long he0 = 0UL; \ for(a = 0; a < (prime); a++) \ { if(isfs[ab]) { he0 |= test; } \ ab += d; \ if(ab >= (prime)) ab -= (prime); \ test <<= 1; \ } \ help0 = he0; \ } \ \ { register unsigned long help1; \ { /* repeat bit pattern floor(LONG_LENGTH/p) times */ \ register unsigned long pattern = help0; \ register long i; \ /* the p * (floor(LONG_LENGTH/p) + 1) - LONG_LENGTH \ = p - (LONG_LENGTH mod p) \ upper bits into help[b][1] : \ shift away the LONG_LENGTH mod p lower bits */ \ help1 = pattern >> lmp; \ for(i = (prime); i < LONG_LENGTH; i <<= 1) \ { help0 |= help0 << i; } \ /* \ for(i = ldp; i; i--) \ { pattern <<= (prime); help0 |= pattern; } \ */ \ } \ \ { /* fill the bit pattern from help0/help1 into sieve[b][]. \ sieve[b][a0] has the same semantics as help0/help1, \ but here, a0 runs from 0 to p-1 and all bits are filled. */ \ register long a; \ unsigned long *si = (unsigned long *)args->ba_next; \ \ args->ba_next += (prime)*sizeof(ratpoints_bit_array); \ /* copy the first chunk into sieve[b][] */ \ si[0] = help0; \ /* now keep repeating the bit pattern, \ rotating it in help0/help1 */ \ for(a = 1 ; a < (prime); a++) \ { register unsigned long temp = help0 >> diff; \ help0 = help1 | (help0 << diff_shift); \ si[a] = help0; \ help1 = temp; \ } \ /* copy into the next p long words */ \ for(a = 0; a < (prime); a++) \ { si[a+(prime)] = si[a]; } \ /* set sieve array */ \ se->sieve[b] = (ratpoints_bit_array *)si; \ return((ratpoints_bit_array *)si); \ } } \ } /* This is for p > LONG_LENGTH */ #define CODE_INIT_SIEVE2(prime) \ static ratpoints_bit_array *sieve_init_##prime(void *se1, long b1, void *args1) \ { \ ratpoints_sieve_entry *se = se1; \ ratpoints_args *args = args1; \ register long p = (prime); \ register int *isfs = se->is_f_square; \ register long b = b1; \ /* long ldp = 0; = LONG_LENGTH / p */ \ /* long p1 = p; = (ldp + 1) * p; */ \ long wp = p >> LONG_SHIFT; \ long diff_shift = p & LONG_MASK; \ long diff = LONG_LENGTH - diff_shift; \ unsigned long help[(p>>LONG_SHIFT) + 2]; \ \ /* initialize help */ \ { register unsigned long *he = &help[0]; \ register unsigned long *he1 = &he[(p>>LONG_SHIFT) + 2]; \ while(he1 != he) { he1--; *he1 = 0UL; } \ } \ { register unsigned long work = 0UL; \ register long a; \ register long ab = 0; /* a/b mod p */ \ register long d = se->inverses[b]; \ register long n = 0; \ register unsigned long test = 1UL; \ for(a = 0; a < p; ) \ { if(isfs[ab]) { work |= test; } \ ab += d; \ if(ab >= p) ab -= p; \ test <<= 1; \ a++; \ if((a & LONG_MASK) == 0) \ { help[n] = work; n++; work = 0UL; test = 1UL; } \ } \ help[n] = work; \ } \ \ { /* fill the bit pattern from help[] into sieve[b][]. \ sieve[b][a0] has the same semantics as help[b][a0], \ but here, a0 runs from 0 to p-1 and all bits are filled. */ \ register unsigned long *si = (unsigned long *)args->ba_next; \ register long a1; \ register long a; \ \ args->ba_next += p*sizeof(ratpoints_bit_array); \ /* copy the first chunk from help[] into sieve[num][b][] */ \ for(a = 0; a < wp; a++) si[a] = help[a]; \ /* now keep repeating the bit pattern, rotating it in help */ \ for(a1 = a ; a < p; a++) \ { register long t = (a1 == wp) ? 0 : a1+1; \ help[a1] |= help[t]<>= diff; \ } \ /* copy into the next p long words */ \ for(a = 0; a < p; a++) \ { si[a+p] = si[a]; } \ /* set sieve array */ \ se->sieve[b] = (ratpoints_bit_array *)si; \ return((ratpoints_bit_array *)si); \ } \ } #else /* The following is for primes < LONG_LENGTH */ #define CODE_INIT_SIEVE1(prime) \ static ratpoints_bit_array *sieve_init_##prime(void *se1, long b1, void *args1) \ { \ ratpoints_sieve_entry *se = se1; \ ratpoints_args *args = args1; \ register int *isfs = se->is_f_square; \ register long b = b1; \ long lmp = LONG_LENGTH % (prime); \ long ldp = LONG_LENGTH / (prime); \ long p1 = (ldp + 1) * (prime); \ long diff_shift = p1 & LONG_MASK; \ long diff = LONG_LENGTH - diff_shift; \ register unsigned long help0;\ { register long a; \ register long d = se->inverses[b]; \ register long ab = 0; /* a/b mod p */ \ register unsigned long test = 1UL; \ register unsigned long he0 = 0UL; \ for(a = 0; a < (prime); a++) \ { if(isfs[ab]) { he0 |= test; } \ ab += d; \ if(ab >= (prime)) ab -= (prime); \ test <<= 1; \ } \ help0 = he0; \ } \ \ { register unsigned long help1; \ { /* repeat bit pattern floor(LONG_LENGTH/p) times */ \ register unsigned long pattern = help0; \ register long i; \ /* the p * (floor(LONG_LENGTH/p) + 1) - LONG_LENGTH \ = p - (LONG_LENGTH mod p) \ upper bits into help[b][1] : \ shift away the LONG_LENGTH mod p lower bits */ \ help1 = pattern >> lmp; \ for(i = (prime); i < LONG_LENGTH; i <<= 1) \ { help0 |= help0 << i; } \ /* \ for(i = ldp; i; i--) \ { pattern <<= (prime); help0 |= pattern; } \ */ \ } \ \ { /* fill the bit pattern from help0/help1 into sieve[b][]. \ sieve[b][a0] has the same semantics as help0/help1, \ but here, a0 runs from 0 to p-1 and all bits are filled. */ \ register long a; \ unsigned long *si = (unsigned long *)args->ba_next; \ \ args->ba_next += (prime)*sizeof(ratpoints_bit_array); \ /* copy the first chunk into sieve[b][] */ \ si[0] = help0; \ /* now keep repeating the bit pattern, \ rotating it in help0/help1 */ \ for(a = 1 ; a < (prime); a++) \ { register unsigned long temp = help0 >> diff; \ help0 = help1 | (help0 << diff_shift); \ si[a] = help0; \ help1 = temp; \ } \ /* set sieve array */ \ se->sieve[b] = (ratpoints_bit_array *)si; \ return((ratpoints_bit_array *)si); \ } } \ } /* This is for p > LONG_LENGTH */ #define CODE_INIT_SIEVE2(prime) \ static ratpoints_bit_array *sieve_init_##prime(void *se1, long b1, void *args1) \ { \ ratpoints_sieve_entry *se = se1; \ ratpoints_args *args = args1; \ register long p = (prime); \ register int *isfs = se->is_f_square; \ register long b = b1; \ /* long ldp = 0; = LONG_LENGTH / p */ \ /* long p1 = p; = (ldp + 1) * p; */ \ long wp = p >> LONG_SHIFT; \ long diff_shift = p & LONG_MASK; \ long diff = LONG_LENGTH - diff_shift; \ unsigned long help[(p>>LONG_SHIFT) + 2]; \ \ /* initialize help */ \ { register unsigned long *he = &help[0]; \ register unsigned long *he1 = &he[(p>>LONG_SHIFT) + 2]; \ while(he1 != he) { he1--; *he1 = 0UL; } \ } \ { register unsigned long work = 0UL; \ register long a; \ register long ab = 0; /* a/b mod p */ \ register long d = se->inverses[b]; \ register long n = 0; \ register unsigned long test = 1UL; \ for(a = 0; a < p; ) \ { if(isfs[ab]) { work |= test; } \ ab += d; \ if(ab >= p) ab -= p; \ test <<= 1; \ a++; \ if((a & LONG_MASK) == 0) \ { help[n] = work; n++; work = 0UL; test = 1UL; } \ } \ help[n] = work; \ } \ \ { /* fill the bit pattern from help[] into sieve[b][]. \ sieve[b][a0] has the same semantics as help[b][a0], \ but here, a0 runs from 0 to p-1 and all bits are filled. */ \ register unsigned long *si = (unsigned long *)args->ba_next; \ register long a1; \ register long a; \ \ args->ba_next += p*sizeof(ratpoints_bit_array); \ /* copy the first chunk from help[] into sieve[num][b][] */ \ for(a = 0; a < wp; a++) si[a] = help[a]; \ /* now keep repeating the bit pattern, rotating it in help */ \ for(a1 = a ; a < p; a++) \ { register long t = (a1 == wp) ? 0 : a1+1; \ help[a1] |= help[t]<>= diff; \ } \ /* set sieve array */ \ se->sieve[b] = (ratpoints_bit_array *)si; \ return((ratpoints_bit_array *)si); \ } \ } #endif #include "init_sieve.h" ratpoints-2.1.3+dfsg.orig/find_points.c0000644000175000017500000017174611536145472016602 0ustar tobitobi/*********************************************************************** * ratpoints-2.1.3 * * - A program to find rational points on hyperelliptic curves * * Copyright (C) 2008, 2009 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 . * ***********************************************************************/ /*********************************************************************** * find_points.c * * * * Core program file for ratpoints * * * * Michael Stoll, September 21, 2009 * ***********************************************************************/ #include "rp-private.h" #include "primes.h" /* defines long prime[PRIMES1000]; */ #include "find_points.h" /* defines static const int squares[RATPOINTS_NUM_PRIMES+1][RATPOINTS_MAX_PRIME]; squares[n][x] = 1 if x is a square mod prime[n], 0 if not static const long offsets[RATPOINTS_NUM_PRIMES]; offset[n] = (2*LONG_LENGTH)^(-1) mod prime[n] static const long inverses[RATPOINTS_NUM_PRIMES][RATPOINTS_MAX_PRIME]; inverses[n][x] = x^(-1) mod prime[n] for x != 0 mod prime[n] ratpoints_bit_array sieves0[RATPOINTS_NUM_PRIMES][RATPOINTS_MAX_PRIME_EVEN] sieves0[n][x] has bit i set (0 <= x < prime[n]) <==> x*LONG_LENGTH + i is not divisible by prime[n] */ #define MAX_DIVISORS 512 /* Maximal length of array for squarefree divisors of leading coefficient */ extern ratpoints_init_fun sieve_init[RATPOINTS_NUM_PRIMES]; typedef struct { double r; ratpoints_sieve_entry *ssp; } entry; typedef struct { int p; int val; int slope; } use_squares1_info; typedef struct { long p; unsigned long *start; unsigned long *end; unsigned long *curr; } forbidden_entry; static const int squares16[16] = {1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0}; /* Says if a is a square mod 16, for a = 0..15 */ /************************************************************************** * Initialization and cleanup of ratpoints_args structure * **************************************************************************/ /* NOTE: args->degree must be set */ void find_points_init(ratpoints_args *args) { long work_len = 3 + (args->degree + 1); /* allocate space for work[] */ mpz_t *work = malloc(work_len*sizeof(mpz_t)); #ifdef DEBUG printf("\nfind_points: initialize..."); fflush(NULL); #endif /* and initialize the mpz_t's in it */ { long i; for(i = 0; i < work_len; i++) mpz_init(work[i]); } /* insert in args */ args->work = work; args->work_length = work_len; /* allocate space for se_buffer */ args->se_buffer = (ratpoints_sieve_entry*)malloc(RATPOINTS_NUM_PRIMES * sizeof(ratpoints_sieve_entry)); args->se_next = args->se_buffer; /* allocate space for ba_buffer */ { long need = 0; long n; for(n = 0; n < RATPOINTS_NUM_PRIMES; n++) { need += prime[n]*prime[n]; } args->ba_buffer = malloc(need*sizeof(ratpoints_bit_array)); args->ba_next = args->ba_buffer; } /* allocate space for int_buffer */ args->int_buffer = malloc(RATPOINTS_NUM_PRIMES*(RATPOINTS_MAX_PRIME+1)*sizeof(int)); args->int_next = args->int_buffer; /* allocate sieve_list */ args->sieve_list = malloc(RATPOINTS_NUM_PRIMES * sizeof(ratpoints_sieve_entry*)); args->den_info = malloc((PRIMES1000+2)*sizeof(use_squares1_info)); args->divisors = malloc((MAX_DIVISORS+1)*sizeof(long)); args->forb_ba = malloc((RATPOINTS_NUM_PRIMES + 1)*sizeof(forbidden_entry)); args->forbidden = malloc((RATPOINTS_NUM_PRIMES + 1)*sizeof(long)); #ifdef DEBUG printf("done.\n"); fflush(NULL); #endif return; } void find_points_clear(ratpoints_args *args) { #ifdef DEBUG printf("\nfind_points: clean up..."); fflush(NULL); #endif /* clear mpz_t's in work[] */ { long i; mpz_t *work = args->work; for(i = 0; i < args->work_length; i++) mpz_clear(work[i]); } /* free memory */ free(args->work); free(args->se_buffer); free(args->ba_buffer); free(args->int_buffer); free(args->sieve_list); free(args->den_info); free(args->divisors); free(args->forb_ba); free(args->forbidden); /* clear pointer in args */ args->work = NULL; args->work_length = 0; args->se_buffer = NULL; args->se_next = NULL; args->ba_buffer = NULL; args->ba_next = NULL; args->int_buffer = NULL; args->int_next = NULL; args->sieve_list = NULL; args->den_info = NULL; args->divisors = NULL; args->forb_ba = NULL; args->forbidden = NULL; #ifdef DEBUG printf("done.\n"); fflush(NULL); #endif return; } /************************************************************************** * Helper function: valuation of gmp-integer at a prime * **************************************************************************/ #define VERY_BIG 1000 static long valuation(const mpz_t n, long p, long *r, mpz_t vvv) { long v = 0; unsigned long rem; mpz_abs(vvv, n); if(mpz_cmp_ui(vvv, 0) == 0) { *r = 0; return(VERY_BIG); } rem = mpz_fdiv_q_ui(vvv, vvv, p); while(rem == 0) { v++; rem = mpz_fdiv_q_ui(vvv, vvv, p); } *r = rem; return(v); } static long valuation1(long n, long p) { long v = 0; unsigned long rem; unsigned long qn = abs(n); if(n == 0) { return(VERY_BIG); } rem = qn % p; while(rem == 0) { v++; qn = qn/p; rem = qn % p; } return(v); } /************************************************************************** * Try to avoid divisions * **************************************************************************/ static inline long mod(long a, long b) { long b1 = b << 4; /* b1 = 16*b */ if(a < -b1) { a %= b; if(a < 0) { a += b; } return(a); } if(a < 0) { a += b1; } else { if(a >= b1) { return(a % b); } } b1 >>= 1; /* b1 = 8*b */ if(a >= b1) { a -= b1; } b1 >>= 1; /* b1 = 4*b */ if(a >= b1) { a -= b1; } b1 >>= 1; /* b1 = 2*b */ if(a >= b1) { a -= b1; } if(a >= b) { a -= b; } return(a); } /************************************************************************** * Helper function: Jacobi symbol * **************************************************************************/ static inline int jacobi(long b, mpz_t tmp, const mpz_t lcf) { /* Jacobi symbol (leading coeff/b) */ long f; /* avoid divisions as far as possible! */ /* remove 2's from b */ while((b & 1) == 0) b >>= 1; f = mpz_fdiv_r_ui(tmp, lcf, (unsigned long)b); if(f == 0) return(1); while(1) { long s = 1; long n = f; long m = b; /* m is odd, n is positive and < m */ /* looking at (n/m) */ while(!(n & 1)) { if(m & 2) s = -s; /* change sign iff m = 3 or 5 mod 8 */ if(m & 4) s = -s; n >>= 1; } while(1) { /* switch roles */ if(n & m & 2) s = -s; /* change sign iff m, n = 3 mod 4 */ /* now we are looking at (m/n) */ while(m > n) { m -= n; do { if(n & 2) s = -s; /* change sign iff n = 3 or 5 mod 8 */ if(n & 4) s = -s; m >>= 1; } while(!(m & 1)); } if(m == n) { if(m == 1) return(s); /* otherwise, m is the gcd of f and b; remove it from b */ b /= m; if(f >= b) f %= b; if(f == 0) return(1); break; } /* here m < n */ /* switch roles */ if(n & m & 2) s = -s; /* change sign iff m, n = 3 mod 4 */ /* now we are looking at (n/m) */ while(n > m) { n -= m; do { if(m & 2) s = -s; /* change sign iff m = 3 or 5 mod 8 */ if(m & 4) s = -s; n >>= 1; } while(!(n & 1)); } if(m == n) { if(m == 1) return(s); /* otherwise, m is the gcd of f and b; remove it from b */ b /= m; if(f >= b) f %= b; if(f == 0) return(1); break; } } } } static inline int jacobi1(long b, const long lcf) { /* Jacobi symbol (leading coeff/b) */ long f; int neg = 0; /* avoid divisions as far as possible! */ /* remove 2's from b */ while((b & 1) == 0) b >>= 1; f = lcf; if(f < 0) { f = -f; neg = 1; } if(b < 1UL<<(LONG_LENGTH - 4)) f = mod(f, b); if(f == 0) return(1); while(1) { long s = (neg && (b & 2)) ? -1 : 1; long n = f; long m = b; /* m is odd, n is positive */ /* looking at (n/m) */ while(!(n & 1)) { if(m & 2) s = -s; /* change sign iff m = 3 or 5 mod 8 */ if(m & 4) s = -s; n >>= 1; } while(1) { /* switch roles */ if(n & m & 2) s = -s; /* change sign iff m, n = 3 mod 4 */ /* now we are looking at (m/n) */ while(m > n) { m -= n; do { if(n & 2) s = -s; /* change sign iff n = 3 or 5 mod 8 */ if(n & 4) s = -s; m >>= 1; } while(!(m & 1)); } if(m == n) { if(m == 1) return(s); /* otherwise, m is the gcd of f and b; remove it from b */ b /= m; /* if(f >= b) f %= b; */ if(f == 0) return(1); break; } /* here m < n */ /* switch roles */ if(n & m & 2) s = -s; /* change sign iff m, n = 3 mod 4 */ /* now we are looking at (n/m) */ while(n > m) { n -= m; do { if(m & 2) s = -s; /* change sign iff m = 3 or 5 mod 8 */ if(m & 4) s = -s; n >>= 1; } while(!(n & 1)); } if(m == n) { if(m == 1) return(s); /* otherwise, m is the gcd of f and b; remove it from b */ b /= m; /* if(f >= b) f %= b; */ if(f == 0) return(1); break; } } } } /************************************************************************ * Set up information on possible denominators * * when polynomial is of odd degree with leading coefficient != +-1 * ************************************************************************/ static void setup_us1(ratpoints_args *args) { mpz_t *work = args->work; /* abs. value of leading coeff. in work[0] */ long count = 0; unsigned long i, v; unsigned long rem; /* typedef struct { int p; int val; int slope; } use_squares1_info; */ use_squares1_info *den_info = (use_squares1_info *)args->den_info; long *divisors = (long *)args->divisors; /* find prime divisors of leading coefficient*/ /* first p = 2 */ #ifdef DEBUG printf("\nsetup_us1: find v_2(lcf)..."); fflush(NULL); #endif v = mpz_scan1(work[0], 0); /* find first 1-bit ==> 2-adic valuation */ #ifdef DEBUG printf(" = %ld\n", v); fflush(NULL); #endif if(v > 0) { /* prime divisor found; divide it off */ den_info[count].p = 2; mpz_fdiv_q_2exp(work[0], work[0], v); /* remove power of 2 */ den_info[count].val = v; count++; } for(i = 0; i < PRIMES1000 && mpz_cmp_si(work[0], 1); i++) { int p = prime[i]; if(mpz_cmp_si(work[0], p*p) < 0) { /* remaining part must be prime */ #ifdef DEBUG printf("\nsetup_us1: remaining factor"); fflush(NULL); #endif if(mpz_fits_slong_p(work[0])) { den_info[count].p = mpz_get_si(work[0]); den_info[count].val = 1; #ifdef DEBUG printf(" = %d ==> fits into a long\n", den_info[count].p); fflush(NULL); #endif count++; mpz_set_si(work[0], 1); /* divide it off */ } #ifdef DEBUG else { printf(" is too large\n"); fflush(NULL); } #endif break; } else { #ifdef DEBUG printf("\nsetup_us1: find v_%d(lcf)...", p); fflush(NULL); #endif v = 0; rem = mpz_fdiv_q_ui(work[1], work[0], p); if(rem == 0) { /* prime divisor found; divide it off */ den_info[count].p = p; while(rem == 0) { v++; mpz_set(work[0], work[1]); rem = mpz_fdiv_q_ui(work[1], work[0], p); } den_info[count].val = v; count++; } #ifdef DEBUG printf(" = %ld\n", v); fflush(NULL); #endif } } #ifdef DEBUG printf("\nsetup_us1: %ld entries in den_info\n", count); fflush(NULL); #endif den_info[count].p = 0; /* terminate array */ /* check if factorization is complete */ if(mpz_cmp_si(work[0], 1) == 0) { /* set up array of squarefree divisors */ long *div = &divisors[1]; divisors[0] = 1; for(i = 0; i < count; i++) { /* multiply all divisors known so far by next prime */ long *div0 = &divisors[0]; long *div1 = div; for( ; div0 != div1; div0++) { long t = *div0 * (long)den_info[i].p; if(t <= args->b_high) { *div++ = t; } if(div >= &divisors[MAX_DIVISORS]) { break; } } if(div >= &divisors[MAX_DIVISORS]) { break; } } if(div < &divisors[MAX_DIVISORS]) { *div = 0; /* terminate divisors array */ /* note that we can use the information */ args->flags |= RATPOINTS_USE_SQUARES1; /* set slopes in den_info */ #ifdef DEBUG printf("\nsetup_us1: compute slopes...\n"); fflush(NULL); #endif for(i = 0; i < count; i++) { /* compute min{n : (d-k)*n > v_p(f_d) - v_p(f_k), k = 0,...,d-1} */ int p = den_info[i].p; int v = den_info[i].val; int n = 1; int k; mpz_t *c = args->cof; long degree = args->degree; for(k = degree - 1; k >= 0; k--) { long dummy; int t = 1 + v - valuation(c[k], p, &dummy, work[0]); int m = CEIL(t, (degree - k)); if(m > n) { n = m; } } #ifdef DEBUG printf(" i = %ld (p = %d): slope = %d\n", i, p, n); fflush(NULL); #endif den_info[i].slope = n; } } else { #ifdef DEBUG printf("\nsetup_us1: too many divisors\n"); fflush(NULL); #endif } } else { #ifdef DEBUG printf("\nsetup_us1: no complete factorization\n"); fflush(NULL); #endif } return; } /************************************************************************ * Consider 2-adic information * ************************************************************************/ static bit_selection get_2adic_info(ratpoints_args *args, unsigned long *den_bits, ratpoints_bit_array *num_bits) { mpz_t *c = args->cof; long degree = args->degree; int is_f_square16[24]; long cmp[degree+1]; /* The coefficients of f reduced modulo 16 */ long npe = 0, npo = 0; bit_selection result; #ifdef DEBUG printf("\nget_2adic_info: start...\n"); fflush(NULL); #endif /* compute coefficients mod 16 */ { long n; for(n = 0; n <= degree; n++) { cmp[n] = mpz_get_si(c[n]) & 0xf; } } { long a; for(a = 0 ; a < 16; a++) { unsigned long s = cmp[degree]; long n; for(n = degree - 1 ; n >= 0 ; n--) { s *= a; s += cmp[n]; } s &= 0xf; if((is_f_square16[a] = squares16[s])) { if(a & 1) { npo++; } else { npe++; } } } } /* even denominators: is_f_square16[16+k] says if f((2k+1)/2) is a square, k = 0..3 is_f_square16[20+k] says if f((2k+1)/4) is a square, k = 0,1 is_f_square16[22] says if f(odd/8) is a square is_f_square16[23] says if f(odd/2^n), n >= 4, can be a square */ { long np1 = 0, np2 = 0, np3 = 0, np4 = 0; if(degree & 1) { long cf = 4*cmp[degree-1]; long a; if(degree >= 2) cf += 8*cmp[degree-2]; for(a = 0; a < 4; a++) { /* Compute 2 c[d] k^d + 4 c[d-1] k^(d-1) + 8 c[d-2] k^(d-2), k = 2a+1. Note that k^d = k mod 8, k^(d-1) = 1 mod 8. */ long k = 2*a+1; long s = (2*k*cmp[degree] + cf) & 0xf; if((is_f_square16[16+a] = squares16[s])) np1++; } if((is_f_square16[20] = squares16[(4*cmp[degree]) & 0xf])) np2++; if((is_f_square16[21] = squares16[(12*cmp[degree]) & 0xf])) np2++; if((is_f_square16[22] = squares16[(8*cmp[degree]) & 0xf])) np3++; is_f_square16[23] = 1; np4++; } else { long cf = (degree >= 2) ? 4*cmp[degree-2] : 0; long a; if(degree >= 3) cf += 8*cmp[degree-3]; for(a = 0; a < 4; a++) { /* compute c[d] k^d + 2 c[d-1] k^(d-1) + ... + 8 c[d-3] k^(d-3), k = 2a+1. Note that k^d = k^2 mod 16, k^(d-1) = k mod 8. */ long k = 2*a+1; long s = ((cmp[degree]*k + 2*cmp[degree-1])*k + cf) & 0xf; if((is_f_square16[16+a] = squares16[s])) np1++; } if((is_f_square16[20] = squares16[(cmp[degree]+4*cmp[degree-1]) & 0xf])) np2++; if((is_f_square16[21] = squares16[(cmp[degree]+12*cmp[degree-1]) & 0xf])) np2++; if((is_f_square16[22] = squares16[(cmp[degree]+8*cmp[degree-1]) & 0xf])) np3++; if((is_f_square16[23] = squares16[cmp[degree]])) np4++; } #ifdef DEBUG printf("\nis_f_square16 :\n["); { long a; for(a = 0; a < 23; a++) printf("%d,", is_f_square16[a]); printf("%d]\n", is_f_square16[23]); } fflush(NULL); #endif /* set den_bits */ { unsigned long db = 0; long i; if(npe + npo > 0) { db |= 0xaaaaUL; } /* odd denominators */ if(np1 > 0) { db |= 0x4444UL; } /* v_2(den) = 1 */ if(np2 > 0) { db |= 0x1010UL; } /* v_2(den) = 2 */ if(np3 > 0) { db |= 0x0100UL; } /* v_2(den) = 3 */ if(np4 > 0) { db |= 0x0001UL; } /* v_2(den) >= 4 */ if(db == 0) { *den_bits = 0UL; return(num_none); } for(i = 16; i < LONG_LENGTH; i <<= 1) { db |= db << i; } #ifdef DEBUG printf("\nden_bits :%*.*lx\n", WIDTH, WIDTH, db); fflush(NULL); #endif *den_bits = db; } /* determine result */ result = (npe == 0) ? ((npo == 0) ? num_none : num_odd) : ((npo == 0) ? num_even : num_all); } { /* set up num_bits[16] */ long b; /* odd denominators */ switch(result) { case num_all: for(b = 1; b < 16; b += 2) { unsigned long work = 0; unsigned long bit = 1; long i; long invb = b; /* inverse of b mod 16 */ if(b & 2) invb ^= 8; if(b & 4) invb ^= 8; for(i = 0; i < 16; i++) { if(is_f_square16[(invb*i) & 0xf]) { work |= bit; } bit <<= 1; } /* now repeat the 16 bits */ for(i = 16; i < LONG_LENGTH; i <<= 1) { work |= work << i; } #ifdef USE_SSE num_bits[b] = RBA(work, work); #else num_bits[b] = work; #endif } break; case num_odd: for(b = 1; b < 16; b += 2) { unsigned long work = 0; unsigned long bit = 1; long i; long invb = b; /* inverse of b mod 16 */ if(b & 2) invb ^= 8; if(b & 4) invb ^= 8; for(i = 1; i < 16; i += 2) { if(is_f_square16[(invb*i) & 0xf]) { work |= bit; } bit <<= 1; } /* now repeat the 8 bits */ for(i = 8; i < LONG_LENGTH; i <<= 1) { work |= work << i; } #ifdef USE_SSE num_bits[b] = RBA(work, work); #else num_bits[b] = work; #endif } break; case num_even: for(b = 1; b < 16; b += 2) { unsigned long work = 0; unsigned long bit = 1; long i; long invb = b; /* inverse of b mod 16 */ if(b & 2) invb ^= 8; if(b & 4) invb ^= 8; for(i = 0; i < 16; i += 2) { if(is_f_square16[(invb*i) & 0xf]) { work |= bit; } bit <<= 1; } /* now repeat the 8 bits */ for(i = 8; i < LONG_LENGTH; i <<= 1) { work |= work << i; } #ifdef USE_SSE num_bits[b] = RBA(work, work); #else num_bits[b] = work; #endif } break; case num_none: for(b = 1; b < 16; b += 2) { num_bits[b] = zero; } } /* v_2(den) = 1 : only odd numerators */ for(b = 1; b < 8; b += 2) { unsigned long work; unsigned long bit; long i; work = 0; bit = 1; for(i = 1; i < 16; i += 2) { if(is_f_square16[16 + (((b*i)>>1) & 0x3)]) { work |= bit; } bit <<= 1; } /* now repeat the 8 bits */ for(i = 8; i < LONG_LENGTH; i <<= 1) { work |= work << i; } #ifdef USE_SSE num_bits[2*b] = RBA(work, work); #else num_bits[2*b] = work; #endif } /* v_2(den) = 2 : only odd numerators */ for(b = 1; b < 4; b += 2) { unsigned long work = 0; unsigned long bit = 1; long i; work = 0; bit = 1; for(i = 1; i < 8; i += 2) { if(is_f_square16[20 + (((b*i)>>1) & 0x1)]) { work |= bit; } bit <<= 1; } /* now repeat the 4 bits */ for(i = 4; i < LONG_LENGTH; i <<= 1) { work |= work << i; } #ifdef USE_SSE num_bits[4*b] = RBA(work, work); #else num_bits[4*b] = work; #endif } /* v_2(den) = 3, >= 4 : only odd numerators */ #ifdef USE_SSE num_bits[8] = (is_f_square16[22]) ? RBA(~(0UL), ~(0UL)) : zero; num_bits[0] = (is_f_square16[23]) ? RBA(~(0UL), ~(0UL)) : zero; #else num_bits[8] = (is_f_square16[22]) ? ~(0UL) : zero; num_bits[0] = (is_f_square16[23]) ? ~(0UL) : zero; #endif } #ifdef DEBUG printf("\nget_2adic_info: done.\n"); fflush(NULL); #endif return(result); } /************************************************************************** * This is a comparison function needed for sorting in order to determine * * the `best' primes for sieving. * **************************************************************************/ static int compare_entries(const void *a, const void *b) { double diff = (((entry *)a)->r - ((entry *)b)->r); return (diff > 0) ? 1 : (diff < 0) ? -1 : 0; } /************************************************************************ * Collect the sieving information * ************************************************************************/ static long sieving_info(ratpoints_args *args, int use_c_long, long *c_long, ratpoints_sieve_entry **sieve_list) { mpz_t *c = args->cof; long degree = args->degree; long fba = 0; long fdc = 0; long pn; long pnp = 0; entry prec[RATPOINTS_NUM_PRIMES]; /* This array is used for sorting in order to determine the `best' sieving primes. */ forbidden_entry *forb_ba = (forbidden_entry *)args->forb_ba; long *forbidden = (long *)args->forbidden; /* initialize sieve in se_buffer */ for(pn = 0; pn < args->num_primes; pn++) { long coeffs_mod_p[degree+1]; /* The coefficients of f reduced modulo p */ long p = prime[pn]; long n, a, np; int *is_f_square = args->int_next; args->int_next += p + 1; /* need space for (p+1) int's */ #ifdef DEBUG printf("\nsieving_info: p = %ld\n", p); fflush(NULL); #endif /* compute coefficients mod p */ if(use_c_long) { for(n = 0; n <= degree; n++) { coeffs_mod_p[n] = mod(c_long[n], p); } } else { for(n = 0; n <= degree; n++) { coeffs_mod_p[n] = mpz_fdiv_r_ui(args->work[0], c[n], p); } } np = squares[pn][coeffs_mod_p[0]]; is_f_square[0] = np; for(a = 1 ; a < p; a++) { unsigned long s = coeffs_mod_p[degree]; if((degree+1)*RATPOINTS_MAX_BITS_IN_PRIME <= LONG_LENGTH) { for(n = degree - 1 ; n >= 0 ; n--) { s *= a; s += coeffs_mod_p[n]; } /* here, s < p^(degree+1) <= max. long */ s %= p; } else { for(n = degree - 1 ; n >= 0 ; n--) { s *= a; s += coeffs_mod_p[n]; if(s+1 >= (1UL)<<(LONG_LENGTH - RATPOINTS_MAX_BITS_IN_PRIME)) { s %= p; } } s %= p; } if((is_f_square[a] = squares[pn][s])) { np++; } } is_f_square[p] = (degree & 1) || squares[pn][coeffs_mod_p[degree]]; #ifdef DEBUG printf("\nis_f_square(p = %ld) : \n[", p); { long a; for(a = 0; a < p; a++) printf("%d,", is_f_square[a]); printf("%d]\n", is_f_square[p]); } fflush(NULL); #endif /* check if there are no solutions mod p */ if(np == 0 && !is_f_square[p]) { return(p); } /* Fill arrays with info for p */ if(np < p) { /* only when there is some information */ { double r = is_f_square[p] ? ((double)(np*(p-1) + p))/((double)(p*p)) : (double)np/(double)p; prec[pnp].r = r; } /* set up sieve_entry : typedef struct { ratpoints_init_fun init; long p; int *is_f_square; int *inverses; long offset; (ratpoints_bit_array *)sieve[RATPOINTS_MAX_PRIME]; } ratpoints_sieve_entry; */ { ratpoints_sieve_entry *se = (ratpoints_sieve_entry *)args->se_next; long i; args->se_next += sizeof(ratpoints_sieve_entry); /* one entry must be stored - note that se_next is of type void* */ se->init = sieve_init[pn]; se->p = p; se->is_f_square = is_f_square; se->inverses = &inverses[pn][0]; se->offset = offsets[pn]; se->sieve[0] = (ratpoints_bit_array *)&sieves0[pn][0]; for(i = 1; i < p; i++) { se->sieve[i] = NULL; } prec[pnp].ssp = se; } pnp++; } if((args->flags & RATPOINTS_CHECK_DENOM) && fba + fdc < args->max_forbidden && !is_f_square[p]) { /* record forbidden divisors of the denominator */ if(coeffs_mod_p[degree] == 0) { /* leading coeff. divisible by p */ long r; long v = valuation(c[degree], p, &r, args->work[0]); if((v & 1) || !squares[pn][r]) { /* Can only get something when valuation is odd or when valuation is even and lcf is not a p-adic square. Compute smallest n such that if v(den) >= n, the leading term determines the valuation. Then we must have v(den) < n. */ long n = 1; long k, pp; for(k = degree-1; k >= 0; k--) { if(coeffs_mod_p[k] == 0) { long dummy; long t = 1 + v - valuation(c[k], p, &dummy, args->work[0]); long m = CEIL(t, (degree-k)); if(m > n) { n = m; } } } if(n == 1) { forb_ba[fba].p = p; forb_ba[fba].start = &sieves0[pn][0]; forb_ba[fba].end = &sieves0[pn][p]; forb_ba[fba].curr = forb_ba[fba].start; fba++; pp = p; } else { for(pp = 1; n; n--) { pp *= p; } /* p^n */ forbidden[fdc] = pp; fdc++; } #ifdef DEBUG printf("\nexcluding denominators divisible by %ld\n", pp); fflush(NULL); #endif } } else /* leading coefficient is a non-square mod p */ { /* denominator divisible by p is excluded */ forb_ba[fba].p = p; forb_ba[fba].start = &sieves0[pn][0]; forb_ba[fba].end = &sieves0[pn][p]; forb_ba[fba].curr = forb_ba[fba].start; fba++; #ifdef DEBUG printf("\nexcluding denominators divisible by %ld\n", p); fflush(NULL); #endif } } } /* end for pn */ /* update sp2 and sp1 if necessary */ if(args->sp2 > pnp) { args->sp2 = pnp; } if(args->sp1 > args->sp2) { args->sp1 = args->sp2; } /* sort the array to get at the best primes */ qsort(prec, pnp, sizeof(entry), compare_entries); /* put the sorted entries into sieve_list */ { long n; for(n = 0; n < args->sp2; n++) { sieve_list[n] = prec[n].ssp; } } /* terminate array of forbidden divisors */ if(args->flags & RATPOINTS_CHECK_DENOM) { long n; for(n = args->num_primes; fba + fdc < args->max_forbidden && n < RATPOINTS_NUM_PRIMES; n++) { long p = prime[n]; if(p*p > args->b_high) break; if(mpz_kronecker_si(c[degree], p) == -1) { forb_ba[fba].p = p; forb_ba[fba].start = &sieves0[n][0]; forb_ba[fba].end = &sieves0[n][p]; forb_ba[fba].curr = forb_ba[fba].start; fba++; #ifdef DEBUG printf("\nexcluding denominators divisible by %ld\n", p); fflush(NULL); #endif } } forb_ba[fba].p = 0; /* terminating zero */ forbidden[fdc] = 0; /* terminating zero */ args->max_forbidden = fba + fdc; /* note actual number */ } if(fba + fdc == 0) { args->flags &= ~RATPOINTS_CHECK_DENOM; } #ifdef DEBUG printf("\nsieving_info: done.\n"); fflush(NULL); #endif return(0); } /************************************************************************** * The sieving procedure itself * **************************************************************************/ static long sift(long b, ratpoints_bit_array *survivors, ratpoints_args *args, bit_selection which_bits, ratpoints_bit_array bits16, ratpoints_sieve_entry **sieve_list, long *bp_list, int *quit, int process(long, long, const mpz_t, void*, int*), void *info) { long total = 0; /* typedef struct { long p; long offset; ratpoints_bit_array *ptr; } sieve_spec; */ sieve_spec ssp[args->sp2]; int do_setup = 1; #ifdef DEBUG printf("\nsift(b = %ld): start...\n", b); fflush(NULL); #endif if((b & 1) == 0) { which_bits = num_odd; } /* even denominator */ /* Note that b is new */ args->flags |= RATPOINTS_COMPUTE_BC; { long k; long height = args->height; for(k = 0; k < args->num_inter; k++) { long low, high; /* Determine relevant interval [low, high] of numerators. */ { ratpoints_interval inter = args->domain[k]; if(b*inter.low <= -height) { low = -height; } else { if(b*inter.low > height) { return(total); } low = ceil(b*inter.low); } if(b*inter.up >= height) { high = height; } else { if(b*inter.up < -height) { continue; } high = floor(b*inter.up); } } #ifdef DEBUG printf("\nsift: numerator interval [%ld, %ld]\n", low, high); fflush(NULL); #endif if(do_setup) { /* set up the sieve information */ long n; do_setup = 0; /* only do it once for every b */ #ifdef DEBUG printf("\nsift: set up sieve...\n"); fflush(NULL); #endif for(n = 0; n < args->sp2; n++) { ratpoints_sieve_entry *se = sieve_list[n]; long p = se->p; long bp = bp_list[n]; ratpoints_bit_array *sptr; if(which_bits != num_all) /* divide by 2 mod p */ { bp = (bp & 1) ? (bp+p) >> 1 : bp >> 1; } sptr = se->sieve[bp]; ssp[n].p = p; ssp[n].offset = (which_bits == num_odd) ? se->offset : 0; #ifdef DEBUG printf("\np = %ld, bp = %ld, offset = %ld\n", p, bp, ssp[n].offset); fflush(NULL); #endif /* copy if already initialized, else initialize */ ssp[n].ptr = sptr ? sptr : (*(se->init))(se, bp, args); #ifdef DEBUG if(!sptr) { long a, c = 0; printf("\nsieve(%ld, %ld) [high numerators to the left]:", p, bp); for(a = p-1; a >= 0; a--, c++) { if((c & (0xff >> RBA_SHIFT)) == 0) { printf("\n"); } #ifdef USE_SSE printf("%*.*lx%*.*lx ", WIDTH, WIDTH, EXT1(ssp[n].ptr[a]), WIDTH, WIDTH, EXT0(ssp[n].ptr[a])); #else printf("%*.*lx ", WIDTH, WIDTH, ssp[n].ptr[a]); #endif } printf("\n"); fflush(NULL); } #endif } } switch(which_bits) { case num_all: break; case num_none: break; case num_odd: low >>= 1; high--; high >>= 1; break; case num_even: low++; low >>= 1; high >>= 1; break; } /* now turn the bit interval into [low, high[ */ high++; if(low < high) { long w_low, w_high; long w_low0, w_high0; long range = args->array_size; /* Now the range of longwords (= bit_arrays) */ w_low = low >> RBA_SHIFT; /* FLOOR(low, RBA_LENGTH); */ w_high = (high + (long)(RBA_LENGTH-1)) >> RBA_SHIFT; /* CEIL(high, RBA_LENGTH); */ w_low0 = w_low; w_high0 = w_low0 + range; for( ; w_low0 < w_high; w_low0 = w_high0, w_high0 += range) { if(w_high0 > w_high) { w_high0 = w_high; range = w_high0 - w_low0; } /* initialise the bits */ { register long i; for(i = range; i; i--) { survivors[i-1] = bits16; } } /* boundary words */ if(w_low0 == w_low) { long sh = low - RBA_LENGTH * w_low; unsigned long *survl = (unsigned long *)survivors; #ifdef USE_SSE if(sh >= LONG_LENGTH) { survl[0] = 0UL; survl[1] &= (~0UL)<<(sh - LONG_LENGTH); } else { survl[0] &= ~(0UL)<= LONG_LENGTH) { survl[0] &= ~(0UL)>>(sh - LONG_LENGTH); survl[1] = 0UL; } else { survl[1] &= ~(0UL)>>sh; } #else survl[0] &= ~(0UL)>>sh; #endif } #ifdef DEBUG #ifdef USE_SSE printf("survivors[%ld] = %*.*lx%*.*lx\n", range-1, WIDTH, WIDTH, EXT1(survivors[range-1]), WIDTH, WIDTH, EXT0(survivors[range-1])); #else printf("survivors[%ld] = %*.*lx\n", range-1, WIDTH, WIDTH, survivors[range-1]); #endif fflush(NULL); #endif total += _ratpoints_sift0(b, w_low0, w_high0, args, which_bits, survivors, &ssp[0], quit, process, info); if(*quit) return(total); } } } } return(total); } /************************************************************************** * Find points by looping over the denominators and sieving numerators * **************************************************************************/ /* 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; long array_size; long sturm; long num_primes; long max_forbidden; unsigned int flags; ** from here: private data ** mpz_t *work; long work_length; void *se_buffer; void *se_next; void *ba_buffer; void *ba_next; int *int_buffer; int *int_next; void *den_info; void *divisors; void *forb_ba; void *forbidden; } ratpoints_args; */ /* The first three entries of work[] are temporary mpz_t storage, the remaining ones constitue an array bc[] that will hold the coefficents of the polynomial, multiplied by powers of the denominator b */ long find_points_work(ratpoints_args *args, int process(long, long, const mpz_t, void*, int*), void *info) { long total = 0; /* total counts the points */ int quit = 0; mpz_t *c = args->cof; long degree = args->degree; long height = args->height; mpz_t *work = args->work; int point_at_infty = 0; /* indicates if there are points at infinity */ int lcfsq = mpz_perfect_square_p(c[degree]); forbidden_entry *forb_ba = (forbidden_entry *)args->forb_ba; long *forbidden = (long *)args->forbidden; /* The forbidden divisors, a zero-terminated array. Used when degree is even and leading coefficient is not a square */ use_squares1_info *den_info = (use_squares1_info *)args->den_info; long *divisors = (long *)args->divisors; /* These are used when degree is odd and leading coeff. is not +-1 */ long c_long[degree+1]; /* Stores the coefficients as longs if possible */ int use_c_long = 0; /* Flag that says if c_long[] is set */ ratpoints_sieve_entry **sieve_list = (ratpoints_sieve_entry **)args->sieve_list; bit_selection which_bits = num_all; unsigned long den_bits; ratpoints_bit_array num_bits[16]; args->flags &= RATPOINTS_FLAGS_INPUT_MASK; args->flags |= RATPOINTS_CHECK_DENOM; /* initialize memory management */ args->se_next = args->se_buffer; args->ba_next = args->ba_buffer; args->int_next = args->int_buffer; #ifdef DEBUG printf("\nfind_points_work: start...\n"); fflush(NULL); #endif if(c == NULL) return(RATPOINTS_BAD_ARGS); if(args->work_length < 3 + degree+1) return(RATPOINTS_WORK_LENGTH_TOO_SMALL); /* Eliminate leading zero coefficients */ { long old_degree = degree; while(degree > 0 && mpz_cmp_si(c[degree], 0) == 0) { degree--; } args->degree = degree; if((degree+1)>>1 < (old_degree+1)>>1) { /* Polynomial not squarefree as a binary form of even degree */ return(RATPOINTS_NON_SQUAREFREE); } } if(degree <= 0) return(RATPOINTS_BAD_ARGS); #ifdef DEBUG printf("\nfind_points_work: sanity checks...\n"); fflush(NULL); #endif /* Some sanity checks */ if(args->num_inter < 0) { args->num_inter = 0; } if(args->num_primes < 0) { args->num_primes = RATPOINTS_DEFAULT_NUM_PRIMES; } if(args->sp1 < 0) { args->sp1 = RATPOINTS_DEFAULT_SP1; } if(args->sp2 < 0) { args->sp2 = RATPOINTS_DEFAULT_SP2; } if(args->num_primes > RATPOINTS_NUM_PRIMES) { args->num_primes = RATPOINTS_NUM_PRIMES; } if(args->sp2 > args->num_primes) { args->sp2 = args->num_primes; } if(args->sp1 > args->sp2) { args->sp1 = args->sp2; } if(height < 1) { return(RATPOINTS_BAD_ARGS); } if(args->b_low < 1) { args->b_low = 1; } if(args->b_high < 1) { args->b_high = height; } if(args->b_high > height) { args->b_high = height; } if(args->max_forbidden < 0) { args->max_forbidden = RATPOINTS_DEFAULT_MAX_FORBIDDEN; } if(args->max_forbidden > RATPOINTS_NUM_PRIMES) { args->max_forbidden = RATPOINTS_NUM_PRIMES; } if(args->array_size <= 0) { args->array_size = RATPOINTS_ARRAY_SIZE; } { long s = 2*CEIL(height, LONG_LENGTH); if(args->array_size > s) { args->array_size = s; } } if(args->sturm > (long)(LONG_LENGTH - 2)) { args->sturm = (long)(LONG_LENGTH - 2); } /* Don't reverse if intervals are specified or limits for the denominator are given */ if(args->num_inter > 0 || args->b_low > 1 || args->b_high < height) { args->flags |= RATPOINTS_NO_REVERSE; } if(args->flags & RATPOINTS_VERBOSE) { printf("\nfind_points:\n"); printf(" degree: %ld\n", args->degree); printf(" coefficients:"); { long n; for(n = 0; n <= degree; n++) { printf(" "); mpz_out_str(NULL, 10, args->cof[n]); } } printf("\n"); printf(" height bound: %ld\n", args->height); printf(" denominators from %ld to %ld\n", args->b_low, args->b_high); printf(" number of primes to consider: %3ld\n", args->num_primes); printf(" number of primes for sieving: %3ld\n", args->sp2); printf(" number of primes for first stage: %3ld\n", args->sp1); printf(" maximal number of `forbidden divisors': %ld\n", args->max_forbidden); if(args->sturm >= 0) { printf(" iterations for isolations of connected components: %ld\n", args->sturm); } else { printf(" no isolation of connected components to be done\n"); } if(args->flags & RATPOINTS_NO_CHECK) { printf(" do not verify the points\n"); } if(args->flags & RATPOINTS_NO_REVERSE) { printf(" do not reverse the polynomial\n"); } if(args->flags & RATPOINTS_NO_JACOBI) { printf(" do not perform Jacobi symbol test\n"); } printf("\n"); } #ifdef DEBUG printf("\nfind_points_work: check whether to reverse polynomial\n"); fflush(NULL); #endif /* Check if reversal of polynomial might be better: * case 1: degree is even, but trailing coefficient is zero * case 2: degree is even, leading coefficient is a square, but trailing coefficient is not * case 3: degree is odd, leadinf coefficient is not +-1, trailing coefficient is zero, coeff. of x is +-1 */ if(!((args->flags) & RATPOINTS_NO_REVERSE)) { if(args->flags & RATPOINTS_VERBOSE) { printf("Check if polynomial should be reversed " "for better performance:\n"); } if((degree & 1) == 0) { if(mpz_cmp_si(c[0], 0) == 0) /* case 1 */ { long n; if(mpz_cmp_si(c[1], 0) == 0) { return(RATPOINTS_NON_SQUAREFREE); /* divisible by x^2 */ } args->flags |= RATPOINTS_REVERSED; for(n = 0; n < degree>>1; n++) { mpz_set(work[0], c[n]); mpz_set(c[n], c[degree-n]); mpz_set(c[degree-n], work[0]); } degree--; args->degree = degree; if(args->flags & RATPOINTS_VERBOSE) { printf(" even degree, zero constant term ==> reverse\n\n"); } } else { if(lcfsq && !mpz_perfect_square_p(c[0])) /* case 2 */ { long n; args->flags |= RATPOINTS_REVERSED; for(n = 0; n < degree>>1; n++) { mpz_set(work[0], c[n]); mpz_set(c[n], c[degree-n]); mpz_set(c[degree-n], work[0]); } lcfsq = 0; if(args->flags & RATPOINTS_VERBOSE) { printf(" even degree, leading coefficient is a square, " "constant term is not a square ==> reverse\n\n"); } } } } else /* now degree is odd */ { mpz_abs(work[0], c[degree]); mpz_abs(work[1], c[1]); if(mpz_cmp_si(work[0], 1) != 0 && mpz_cmp_si(c[0], 0) == 0 && mpz_cmp_si(work[1], 1) == 0) /* case 3*/ { long n; args->flags |= RATPOINTS_REVERSED; for(n = 1; n < degree>>1; n++) { mpz_set(work[0], c[n]); mpz_set(c[n], c[degree+1-n]); mpz_set(c[degree+1-n], work[0]); } if(args->flags & RATPOINTS_VERBOSE) { printf(" odd degree, leading coefficient not +/-1, zero " "constant term, coefficient of x is +/-1 ==> reverse\n\n"); } } } } if(args->flags & RATPOINTS_VERBOSE) { if(!(args->flags & RATPOINTS_REVERSED)) { printf(" criteria are not met ==> don't reverse\n\n"); } } #ifdef DEBUG if(args->flags & RATPOINTS_REVERSED) { printf("\nfind_points_work: polynomial reversed.\n"); fflush(NULL); } #endif /* Check is coefficients are small (i.e., fit into a long) */ { long i; int flag = 1; for(i = 0; i <= degree; i++) { if(mpz_fits_slong_p(c[i])) { c_long[i] = mpz_get_si(c[i]); } else { flag = 0; break; } } use_c_long = flag; } #ifdef DEBUG printf("\nfind_points_work: compute connected components\n"); fflush(NULL); #endif /* Deal with the intervals */ if(args->num_inter == 0) /* default interval (effectively ]-infty,infty[) if none is given */ { if(args->domain == NULL) return(RATPOINTS_BAD_ARGS); args->domain[0].low = -height; args->domain[0].up = height; args->num_inter = 1; } if(args->sturm >= 0) { long ret; if(args->flags & RATPOINTS_VERBOSE) { printf("Isolate the connected components:\n"); } ret = _ratpoints_compute_sturm(args); if(args->flags & RATPOINTS_VERBOSE) { if(ret < 0) { printf(" polynomial is not squarefree ==> stop\n\n"); } else if(ret == 0) { printf(" polynomial is always negative ==> no points\n\n"); } else { long n; printf(" can restrict to the following intervals:\n "); for(n = 0; n < args->num_inter; n++) { printf("[%lf, %lf] ", args->domain[n].low, args->domain[n].up); } printf("\n\n"); } } if(ret <= 0) /* not squarefree or no real points */ { if(ret == 0) return(0); return(RATPOINTS_NON_SQUAREFREE); } } /* Point(s) at infinity? */ if((degree & 1) || lcfsq) { args->flags &= ~RATPOINTS_CHECK_DENOM; point_at_infty = 1; if(args->flags & RATPOINTS_VERBOSE) { printf("There are points at infinity\n\n"); } } /* Can use only squares as denoms if degree is odd and poly is +-monic */ if(degree & 1) { mpz_set(work[1], c[degree]); mpz_abs(work[0], work[1]); if(mpz_cmp_si(work[0], 1) == 0) { args->flags |= RATPOINTS_USE_SQUARES; if(args->flags & RATPOINTS_VERBOSE) { printf("Degree is odd, leading coefficient is +/-1\n"); printf(" ==> can restrict to squares as denominators\n\n"); } } else /* set up information on divisors of leading coefficient */ { if(args->flags & RATPOINTS_VERBOSE) { printf("Degree is odd, leading coefficient is not +/-1\n"); printf(" ==> can restrict denominators\n" " to squares times certain " "divisors of the leading coefficient:\n"); } setup_us1(args); if(args->flags & RATPOINTS_VERBOSE) { if(args->flags & RATPOINTS_USE_SQUARES1) { long n; printf(" divisors:"); for(n = 0; divisors[n]; n++) { printf(" %ld", divisors[n]); } printf("\n\n"); } else { printf(" no complete factorization obtained, or too many divisors\n" " ==> cannot use this feature\n\n"); } } } } /* deal with f mod powers of 2 */ if(args->flags & RATPOINTS_VERBOSE) { printf("Obtain information from the polynomial mod 16:\n"); } which_bits = get_2adic_info(args, &den_bits, &num_bits[0]); /* which_bits says whether to consider even and/or odd numerators when the denominator is odd. Bit k in den_bits is 0 if b congruent to k mod LONG_LENGTH need not be considered as a denominator. Bit k in num_bits[b] is 0 is numerators congruent to k (which_bits = den_all) / 2k (which_bits = den_even) / 2k+1 (which_bits = den_odd) need not be considered for denominators congruent to b mod 16. */ #ifdef DEBUG { long i, c = 0; printf("\nusing %s numerators for odd denominators\n", (which_bits == num_none) ? "no" : (which_bits == num_even) ? "even" : (which_bits == num_odd) ? "odd" : "all"); printf("\nden_ bits : %*.*lx\n", WIDTH, WIDTH, den_bits); printf("\nnum_bits for b = 15, 14, ..., 0 mod 16 " "[high numerators to the left]:"); for(i = 15; i >= 0; i--, c++) { if((c & (0xff >> LONG_SHIFT)) == 0) { printf("\n"); } #ifdef USE_SSE printf(" %*.*lx", WIDTH, WIDTH, EXT0(num_bits[i])); #else printf(" %*.*lx", WIDTH, WIDTH, num_bits[i]); #endif } printf("\n\n"); fflush(NULL); } #else if(args->flags & RATPOINTS_VERBOSE) { printf(" use %s numerators for odd denominators\n\n", (which_bits == num_none) ? "no" : (which_bits == num_even) ? "even" : (which_bits == num_odd) ? "odd" : "all"); } #endif /* set up the sieve data structure */ if(args->flags & RATPOINTS_VERBOSE) { printf("Find the points mod p for the first %ld odd primes p:\n", args->num_primes); } { long ret = sieving_info(args, use_c_long, &c_long[0], sieve_list); if(ret) { #ifdef DEBUG printf("\nno points mod p = %ld ==> return(0)\n", ret); #else if(args->flags & RATPOINTS_VERBOSE) { printf(" no points mod p = %ld ==> no rational points\n\n", ret); } #endif return(0); } } #ifdef DEBUG { long n; printf("\n%ld primes for first stage:\n", args->sp1); for(n = 0; n < args->sp1; n++) { printf(" %ld", sieve_list[n]->p); } printf("\n\n%ld primes for second stage:\n", args->sp2 - args->sp1); for( ; n < args->sp2; n++) { printf(" %ld", sieve_list[n]->p); } printf("\n"); fflush(NULL); } #else if(args->flags & RATPOINTS_VERBOSE) { long n; printf(" use %ld primes for first stage:\n ", args->sp1); for(n = 0; n < args->sp1; n++) { printf(" %ld", sieve_list[n]->p); } printf("\n use %ld primes for second stage:\n ", args->sp2 - args->sp1); for( ; n < args->sp2; n++) { printf(" %ld", sieve_list[n]->p); } printf("\n\n"); } #endif /* deal with point(s) at infinity */ if(point_at_infty) { long a = 1, b = 0; #ifdef DEBUG printf("\nfind_points_work: points at infinity...\n"); fflush(NULL); #else if(args->flags & RATPOINTS_VERBOSE) { printf("Points at infinity:\n"); } #endif if(args->flags & RATPOINTS_REVERSED) { a = 0; b = 1; } if((args->flags) & RATPOINTS_NO_CHECK) { mpz_set_si(work[0], 0); total += process(a, b, work[0], info, &quit); } else { if(degree & 1) { mpz_set_si(work[0], 0); total += process(a, b, work[0], info, &quit); } else { mpz_sqrt(work[0], c[degree]); total += process(a, b, work[0], info, &quit); if(!quit && !((args->flags) & RATPOINTS_NO_Y)) { mpz_neg(work[0], work[0]); total += process(a, b, work[0], info, &quit); } } } if(quit) { return(total); } if(args->flags & RATPOINTS_VERBOSE) { printf("\n"); } } #ifdef DEBUG printf("\nfind_points_work: start sieving...\n"); fflush(NULL); #else if(args->flags & RATPOINTS_VERBOSE) { printf("Now start the sieving procedure...\n\n"); } #endif /* now do the sieving */ { ratpoints_bit_array *survivors; #ifdef DEBUG printf("\nfind_points_work: allocating space for survivors..."); fflush(NULL); #endif survivors = (ratpoints_bit_array *)malloc((args->array_size) *sizeof(ratpoints_bit_array)); #ifdef DEBUG printf(" done\n"); fflush(NULL); #endif if(args->flags & (RATPOINTS_USE_SQUARES | RATPOINTS_USE_SQUARES1)) { if(args->flags & RATPOINTS_USE_SQUARES) /* need only take squares as denoms */ { long b, bb; long bp_list[args->sp2]; long last_b = args->b_low; #ifdef DEBUG printf("\n using squares\n"); fflush(NULL); #endif { long n; for(n = 0; n < args->sp2; n++) { bp_list[n] = mod(args->b_low, sieve_list[n]->p); } } for(b = 1; bb = b*b, bb <= args->b_high; b++) { if(bb >= args->b_low) { ratpoints_bit_array bits = num_bits[bb & 0xf]; #ifdef USE_SSE if(TEST(bits)) #else if(bits) #endif { long n; long d = bb - last_b; /* fill bp_list */ for(n = 0; n < args->sp2; n++) { bp_list[n] = mod(bp_list[n] + d, sieve_list[n]->p); } last_b = bb; total += sift(bb, survivors, args, which_bits, bits, sieve_list, &bp_list[0], &quit, process, info); if(quit) { break; } } #ifdef DEBUG else { printf("\nb = %ld: excluded mod 16\n", b); fflush(NULL); } #endif } } } else /* args->flags & RATPOINTS_USE_SQUARES1 */ { long *div = &divisors[0]; long b, bb; long bp_list[args->sp2]; #ifdef DEBUG printf("\n using squares times divisors of leading coefficient\n"); fflush(NULL); #endif for( ; *div; div++) { long last_b = *div; #ifdef DEBUG printf("\n divisor = %ld\n", *div); fflush(NULL); #endif { long n; for(n = 0; n < args->sp2; n++) { bp_list[n] = mod(*div, sieve_list[n]->p); } } for(b = 1; bb = (*div)*b*b, bb <= args->b_high; b++) { if(bb >= args->b_low) { int flag = 1; ratpoints_bit_array bits = num_bits[bb & 0xf]; #ifdef USE_SSE if(EXT0(bits)) #else if(bits) #endif { long i; long n; long d = bb - last_b; /* fill bp_list */ for(n = 0; n < args->sp2; n++) { bp_list[n] = mod(bp_list[n] + d, sieve_list[n]->p); } last_b = bb; for(i = 0; den_info[i].p; i++) { int v = valuation1(bb, den_info[i].p); if((v >= den_info[i].slope) && ((v + (den_info[i].val)) & 1)) { flag = 0; break; } } if(flag) { total += sift(bb, survivors, args, which_bits, bits, sieve_list, &bp_list[0], &quit, process, info); if(quit) { break; } } } #ifdef DEBUG else { printf("\nb = %ld: excluded mod 16\n", b); fflush(NULL); } #endif } } if(quit) { break; } } } } else { if(args->flags & RATPOINTS_CHECK_DENOM) { long *forb; long b; long bp_list[args->sp2]; long last_b = args->b_low; unsigned long b_bits; #ifdef DEBUG printf("\n taking account of forbidden divisors of the denominator\n"); fflush(NULL); #endif { long n; for(n = 0; n < args->sp2; n++) { bp_list[n] = mod(args->b_low, sieve_list[n]->p); } } #ifdef DEBUG printf("\n bp_list initialized\n"); fflush(NULL); #endif { forbidden_entry *fba = &forb_ba[0]; long b_low = args->b_low; long w_low = (b_low-1) >> LONG_SHIFT; b_bits = den_bits; while(fba->p) { fba->curr = fba->start + mod(w_low, fba->p); b_bits &= *(fba->curr); fba++; } b_bits >>= (b_low-1) & LONG_MASK; } #ifdef DEBUG printf("\n initial b_bits = %*.*lx\n", WIDTH, WIDTH, b_bits); fflush(NULL); #endif for(b = args->b_low; b <= args->b_high; b++) { ratpoints_bit_array bits = num_bits[b & 0xf]; if((b & LONG_MASK) == 0) { /* next b_bits */ forbidden_entry *fba = &forb_ba[0]; b_bits = den_bits; while(fba->p) { fba->curr++; if(fba->curr == fba->end) { fba->curr = fba->start; } b_bits &= *(fba->curr); fba++; } } else { b_bits >>= 1; } #ifdef DEBUG printf("\n b_bits = %*.*lx\n", WIDTH, WIDTH, b_bits); fflush(NULL); #endif #ifdef USE_SSE if((b_bits & 1) && EXT0(bits)) #else if((b_bits & 1) && bits) #endif { /* check if denominator is excluded */ for(forb = &forbidden[0] ; *forb && (b % (*forb)); forb++) {}; #ifdef DEBUG if(*forb) { printf("\nb = %ld: excluded mod %ld\n", b, *forb); fflush(NULL); } #endif if(*forb == 0 && ((args->flags & RATPOINTS_NO_JACOBI) || (use_c_long ? jacobi1(b, c_long[degree]) : jacobi(b, work[0], c[degree])) == 1)) { long n; long d = b - last_b; /* fill bp_list */ for(n = 0; n < args->sp2; n++) { long bp = bp_list[n] + d; long p = sieve_list[n]->p; while(bp >= p) { bp -= p; } bp_list[n] = bp; } last_b = b; total += sift(b, survivors, args, which_bits, bits, sieve_list, &bp_list[0], &quit, process, info); if(quit) { break; } } #ifdef DEBUG else { if(*forb == 0) { printf("\nb = %ld: excluded by Jacobi symbol\n", b); fflush(NULL); } } #endif } } } /* if(args->flags & RATPOINTS_CHECK_DENOM) */ else { long b; long bp_list[args->sp2]; long last_b = args->b_low; { long n; for(n = 0; n < args->sp2; n++) { bp_list[n] = mod(args->b_low, sieve_list[n]->p); } } for(b = args->b_low; b <= args->b_high; b++) { ratpoints_bit_array bits = num_bits[b & 0xf]; #ifdef USE_SSE if(EXT0(bits)) #else if(bits) #endif { long n; long d = b - last_b; /* fill bp_list */ for(n = 0; n < args->sp2; n++) { long bp = bp_list[n] + d; long p = sieve_list[n]->p; while(bp >= p) { bp -= p; } bp_list[n] = bp; } last_b = b; total += sift(b, survivors, args, which_bits, bits, sieve_list, &bp_list[0], &quit, process, info); if(quit) { break; } } #ifdef DEBUG else { printf("\nb = %ld: excluded mod 16\n", b); fflush(NULL); } #endif } } } free(survivors); } #ifdef DEBUG printf("\nfind_points_work: done. total = %ld.\n", total); fflush(NULL); #endif return(total); } /************************************************************************** * The wrapper function, doing init, work, and clear * **************************************************************************/ long find_points(ratpoints_args *args, int process(long, long, const mpz_t, void*, int*), void *info) { long result; /* first initialize */ find_points_init(args); /* then do the work */ result = find_points_work(args, process, info); /* now clean up */ find_points_clear(args); /* and return the result */ return(result); } /************************************************************************** * Check a `survivor' of the sieve if it really gives a point. * * This function is called by _ratpoints_sift0(), see sift.c . * **************************************************************************/ long _ratpoints_check_point(long a, long b, ratpoints_args *args, int *quit, int process(long, long, const mpz_t, void*, int*), void *info) { mpz_t *c = args->cof; long degree = args->degree; int reverse = args->flags & RATPOINTS_REVERSED; long total = 0; mpz_t *work = args->work; mpz_t *bc = &work[3]; if(!((args->flags) & RATPOINTS_NO_CHECK)) { long k; /* Compute F(a, b), where F is the homogenized version of f of smallest possible even degree */ if(args->flags & RATPOINTS_COMPUTE_BC) { /* compute entries bc[k] = c[k] * b^(degree-k), k < degree */ #ifdef DEBUG printf("\ncheck_point: compute bc[] (b = %ld)\n", b); fflush(NULL); #endif mpz_set_si(work[0], 1); for(k = degree-1; k >= 0; k--) { mpz_mul_ui(work[0], work[0], b); mpz_mul(bc[k], c[k], work[0]); } args->flags &= ~RATPOINTS_COMPUTE_BC; } #ifdef DEBUG printf("check_point: computing f(a = %ld, b = %ld)\n", a, b); fflush(NULL); #endif mpz_set(work[2], c[degree]); for(k = degree-1; k >= 0; k--) { mpz_mul_si(work[2], work[2], a); mpz_add(work[2], work[2], bc[k]); } if(degree & 1) mpz_mul_ui(work[2], work[2], b); /* check if f(x,z) is a square; if so, process the point(s) */ if(mpz_cmp_si(work[2], 0) >= 0) { mpz_sqrtrem(work[0], work[1], work[2]); /* work[0] = isqrt(work[2]), work[1] = remainder */ if(mpz_cmp_si(work[1], 0) == 0) { #ifdef DEBUG printf("check_point: found point (a = %ld, b = %ld)\n", a, b); fflush(NULL); #endif if(reverse) { if(a >= 0) { total += process(b, a, work[0], info, quit); } else { total += process(-b, -a, work[0], info, quit); } } else total += process(a, b, work[0], info, quit); if(!*quit && mpz_cmp_si(work[0], 0) != 0 && !((args->flags) & RATPOINTS_NO_Y)) { mpz_neg(work[0], work[0]); if(reverse) { if(a >= 0) { total += process(b, a, work[0], info, quit); } else { total += process(-b, -a, work[0], info, quit); } } else { total += process(a, b, work[0], info, quit); } } } } } /* if(!no_check) */ else { mpz_set_si(work[0], 0); if(reverse) { if(a >= 0) { total += process(b, a, work[0], info, quit); } else { total += process(-b, -a, work[0], info, quit); } } else { total += process(a, b, work[0], info, quit); } } return(total); } ratpoints-2.1.3+dfsg.orig/testbase0000644000175000017500000004006511536145472015644 0ustar tobitobi{} {[0,2,1],[0,-2,1]} {[0,2,1],[0,-2,1],[-2,346,5],[-2,-346,5]} {[0,0,1]} {} {[0,0,1],[-1,0,1]} {[-3,6,2],[-3,-6,2]} {} {} {} {} {[3,31,2],[3,-31,2],[2,51,3],[2,-51,3]} {} {[0,0,1],[-1,2,1],[-1,-2,1]} {} {} {} {[1,0,1]} {[-1,1,1],[-1,-1,1],[1,20,2],[1,-20,2]} {[-1,3,1],[-1,-3,1]} {[0,2,1],[0,-2,1]} {[-2,7,1],[-2,-7,1],[0,1,1],[0,-1,1]} {[-1,2,1],[-1,-2,1]} {[1,11,2],[1,-11,2]} {} {[1,2,0],[1,-2,0],[1,1,1],[1,-1,1]} {} {} {[-3,38,1],[-3,-38,1],[-1,2,1],[-1,-2,1],[1,2,1],[1,-2,1],[7,602,1],[7,-602,1],[1,513,6],[1,-513,6]} {} {[0,2,1],[0,-2,1]} {[1,1,1],[1,-1,1]} {[1,2,0],[1,-2,0]} {[0,0,1],[-1,3,2],[-1,-3,2],[1,3,0],[1,-3,0]} {[-1,3,1],[-1,-3,1]} {} {} {[0,0,1],[-1,3,1],[-1,-3,1]} {[0,2,1],[0,-2,1]} {} {[0,1,1],[0,-1,1]} {} {[0,1,1],[0,-1,1]} {[1,2,1],[1,-2,1]} {[0,3,1],[0,-3,1],[1,23,2],[1,-23,2]} {} {} {[0,2,1],[0,-2,1]} {[-1,4,1],[-1,-4,1]} {[1,3,1],[1,-3,1]} {} {[1,4,1],[1,-4,1]} {[-1,2,1],[-1,-2,1],[-1,4,2],[-1,-4,2]} {[-1,1,1],[-1,-1,1],[1,3,0],[1,-3,0]} {[0,0,1]} {[1,3,0],[1,-3,0],[1,3,1],[1,-3,1]} {[-1,4,1],[-1,-4,1],[0,3,1],[0,-3,1],[2,107,3],[2,-107,3],[38,1939745,83],[38,-1939745,83]} {[1,1,0],[1,-1,0],[0,1,1],[0,-1,1],[1,3,2],[1,-3,2],[-13,6499,9],[-13,-6499,9],[-49,198463,12],[-49,-198463,12]} {[1,0,1]} {} {} {[1,1,0],[1,-1,0],[0,3,1],[0,-3,1]} {} {[1,3,0],[1,-3,0]} {[0,3,1],[0,-3,1]} {[0,0,1],[1,3,0],[1,-3,0]} {} {} {} {[1,3,1],[1,-3,1]} {[1,1,0],[1,-1,0],[1,0,1]} {} {} {[0,0,1]} {[0,3,1],[0,-3,1]} {} {[0,3,1],[0,-3,1]} {[-1,4,1],[-1,-4,1]} {} {} {} {} {[1,1,0],[1,-1,0]} {[-1,2,1],[-1,-2,1]} {[1,0,0]} {} {} {} {} {[1,3,0],[1,-3,0]} {} {[1,1,1],[1,-1,1]} {} {[-1,0,1]} {[0,3,1],[0,-3,1],[4,23,1],[4,-23,1]} {[0,1,1],[0,-1,1]} {[0,2,1],[0,-2,1]} {[-1,2,1],[-1,-2,1],[1,2,1],[1,-2,1]} {} {[2,3461,11],[2,-3461,11]} {[-1,1,1],[-1,-1,1]} {[0,1,1],[0,-1,1]} {} {} {} {[1,0,0]} {} {[-1,5,1],[-1,-5,1]} {[-1,1,1],[-1,-1,1]} {[-2,8,1],[-2,-8,1],[-1,1,1],[-1,-1,1],[2,16,1],[2,-16,1]} {[0,3,1],[0,-3,1]} {} {[1,144,4],[1,-144,4]} {[1,1,0],[1,-1,0]} {[3,82,2],[3,-82,2]} {[1,0,0]} {[2,4,1],[2,-4,1]} {[-1,2,1],[-1,-2,1]} {} {} {[0,0,1],[1,2,1],[1,-2,1],[-2,16,1],[-2,-16,1]} {[0,2,1],[0,-2,1],[3,23,1],[3,-23,1]} {} {} {[1,3,1],[1,-3,1]} {} {[-1,1,1],[-1,-1,1]} {} {} {} {} {[0,3,1],[0,-3,1]} {} {[0,1,1],[0,-1,1]} {} {} {[0,2,1],[0,-2,1]} {} {} {[-1,3,1],[-1,-3,1],[2,3,1],[2,-3,1],[3,6,2],[3,-6,2]} {[0,3,1],[0,-3,1],[1,6,1],[1,-6,1],[-4,419,7],[-4,-419,7]} {[1,2,1],[1,-2,1],[7,2996,10],[7,-2996,10]} {[1,0,0]} {[1,2,1],[1,-2,1]} {[0,2,1],[0,-2,1]} {} {[3,49,2],[3,-49,2]} {[-1,18,2],[-1,-18,2]} {} {} {[0,0,1]} {[0,3,1],[0,-3,1]} {} {[1,2,0],[1,-2,0],[0,2,1],[0,-2,1]} {[-1,1,1],[-1,-1,1]} {[-2,22,1],[-2,-22,1]} {[1,1,0],[1,-1,0]} {[0,1,1],[0,-1,1]} {[1,1,1],[1,-1,1]} {} {[1,3,0],[1,-3,0]} {} {} {} {} {[-1,1,1],[-1,-1,1],[0,3,1],[0,-3,1]} {} {[3,1,1],[3,-1,1]} {} {} {[1,4,1],[1,-4,1]} {[-1,1,1],[-1,-1,1]} {[1,0,0],[0,3,1],[0,-3,1],[1,0,1]} {} {} {[1,5,1],[1,-5,1]} {[10,3648,7],[10,-3648,7]} {[-20,21952,1],[-20,-21952,1],[0,2,1],[0,-2,1]} {[-1,2,1],[-1,-2,1]} {} {[1,1,1],[1,-1,1],[-27,1795891,89],[-27,-1795891,89]} {[-1,5,2],[-1,-5,2]} {[1,3,0],[1,-3,0]} {} {[1,2,0],[1,-2,0]} {} {} {} {[-1,9,2],[-1,-9,2]} {} {} {} {[1,3,1],[1,-3,1]} {[-1,1,2],[-1,-1,2],[1,1,0],[1,-1,0],[1,1,1],[1,-1,1]} {} {[-1,1,1],[-1,-1,1]} {} {} {[0,2,1],[0,-2,1]} {} {[1,1,0],[1,-1,0],[7,357,4],[7,-357,4]} {[0,1,1],[0,-1,1]} {} {} {[1,2,0],[1,-2,0]} {[1,3,1],[1,-3,1]} {} {[0,0,1]} {[-2,9,1],[-2,-9,1]} {[1,0,1]} {[-1,7,2],[-1,-7,2]} {[0,2,1],[0,-2,1]} {[0,1,1],[0,-1,1]} {[0,2,1],[0,-2,1],[2,12,3],[2,-12,3]} {} {} {[-2,3,1],[-2,-3,1],[-1,0,1],[0,1,1],[0,-1,1],[-6,133,5],[-6,-133,5]} {[1,1,0],[1,-1,0]} {[-1,75,4],[-1,-75,4],[1,1,0],[1,-1,0]} {} {[-1,3,1],[-1,-3,1]} {} {[1,2,0],[1,-2,0],[1,3,1],[1,-3,1]} {} {[1,3,0],[1,-3,0]} {} {} {[0,3,1],[0,-3,1],[2,21,1],[2,-21,1]} {} {} {[0,1,1],[0,-1,1],[1,5,2],[1,-5,2]} {} {[0,3,1],[0,-3,1]} {} {} {[0,2,1],[0,-2,1]} {[-1,1,1],[-1,-1,1],[1,101,4],[1,-101,4]} {[-1,2,1],[-1,-2,1],[1,13,2],[1,-13,2]} {[-3,58,1],[-3,-58,1]} {[1,4,1],[1,-4,1],[3,1408,8],[3,-1408,8]} {} {[0,1,1],[0,-1,1]} {[1,2,1],[1,-2,1]} {} {} {[1,1,0],[1,-1,0],[-2,9,1],[-2,-9,1]} {[1,4,1],[1,-4,1]} {[-1,3,1],[-1,-3,1]} {} {} {} {} {} {} {[-1,1,1],[-1,-1,1]} {[1,1,0],[1,-1,0]} {} {} {[0,1,1],[0,-1,1]} {} {[1,3,0],[1,-3,0]} {} {[0,0,1]} {[0,1,1],[0,-1,1]} {} {} {[1,0,0],[1,1,1],[1,-1,1]} {} {[1,1,0],[1,-1,0]} {} {} {} {[0,2,1],[0,-2,1]} {[1,1,0],[1,-1,0],[-4,114,1],[-4,-114,1]} {[0,3,1],[0,-3,1]} {[1,2,0],[1,-2,0]} {} {} {} {[1,1,0],[1,-1,0]} {} {[0,2,1],[0,-2,1]} {[-1,3,1],[-1,-3,1]} {} {} {[0,3,1],[0,-3,1]} {[20,25315,19],[20,-25315,19]} {} {[-1,1,1],[-1,-1,1]} {[1,2,0],[1,-2,0]} {[0,3,1],[0,-3,1],[3,291,5],[3,-291,5]} {[1,3,0],[1,-3,0]} {} {} {[1,0,0]} {} {} {[1,1,0],[1,-1,0]} {[1,3,0],[1,-3,0]} {} {} {[0,3,1],[0,-3,1]} {} {[-2,37,3],[-2,-37,3]} {[-1,2,1],[-1,-2,1],[1,2,1],[1,-2,1]} {[1,0,0]} {} {} {[1,1,0],[1,-1,0]} {[1,2,0],[1,-2,0],[0,3,1],[0,-3,1]} {} {[0,3,1],[0,-3,1]} {[1,3,0],[1,-3,0]} {} {} {} {[0,2,1],[0,-2,1],[1,0,1]} {} {[0,3,1],[0,-3,1],[-704,40680297,933],[-704,-40680297,933]} {[0,0,1]} {[-1,1,1],[-1,-1,1],[1,5,1],[1,-5,1]} {} {[36,131678,1],[36,-131678,1]} {[1,1,0],[1,-1,0],[0,2,1],[0,-2,1]} {} {} {[1,3,0],[1,-3,0]} {[-1,1,1],[-1,-1,1],[1,1,0],[1,-1,0],[1,11,2],[1,-11,2],[1,503,6],[1,-503,6],[2,13,1],[2,-13,1],[3,113,5],[3,-113,5]} {[0,0,1],[1,0,0]} {[1,3,1],[1,-3,1]} {} {[1,3,1],[1,-3,1]} {} {} {} {[1,1,0],[1,-1,0],[-3,10,1],[-3,-10,1],[0,2,1],[0,-2,1],[-1,46,3],[-1,-46,3]} {[1,2,0],[1,-2,0]} {[0,0,1],[1,3,0],[1,-3,0]} {} {[0,1,1],[0,-1,1],[-1,16,2],[-1,-16,2]} {[93,594431,28],[93,-594431,28]} {[1,0,0],[0,1,1],[0,-1,1]} {[-1,2,1],[-1,-2,1]} {} {[1,0,1]} {[1,2,0],[1,-2,0],[0,2,1],[0,-2,1]} {[0,0,1]} {} {[0,2,1],[0,-2,1],[1,5,1],[1,-5,1]} {} {[-1,0,1],[0,2,1],[0,-2,1],[1,0,1]} {[0,2,1],[0,-2,1],[1,0,1]} {} {} {} {[0,3,1],[0,-3,1]} {[0,2,1],[0,-2,1]} {[0,0,1],[-1,2,1],[-1,-2,1],[1,1,0],[1,-1,0],[1,11,2],[1,-11,2]} {} {} {} {} {} {} {[1,3,1],[1,-3,1]} {} {} {[0,0,1]} {} {[0,3,1],[0,-3,1]} {[-1,0,1],[-2,0,7]} {} {[1,2,0],[1,-2,0]} {} {[-1,0,1]} {} {} {[1,2,0],[1,-2,0]} {[0,0,1]} {} {[0,2,1],[0,-2,1]} {[1,0,0]} {} {[-2,92,3],[-2,-92,3]} {} {[1,0,1]} {[0,0,1]} {[1,0,0]} {[1,2,0],[1,-2,0]} {[-1,4,1],[-1,-4,1]} {} {[-4,190,1],[-4,-190,1]} {} {[-1,0,1]} {} {[-1,3,1],[-1,-3,1]} {} {[1,3,0],[1,-3,0]} {[-1,2,1],[-1,-2,1]} {[1,2,1],[1,-2,1]} {[1,0,0],[-5,159,3],[-5,-159,3]} {} {[-1,3,1],[-1,-3,1]} {[-2,11,1],[-2,-11,1]} {} {} {} {[1,1,0],[1,-1,0],[2,6,1],[2,-6,1]} {} {} {[-2,13,1],[-2,-13,1]} {} {[1,2,0],[1,-2,0]} {[1,1,0],[1,-1,0],[-5,95,4],[-5,-95,4]} {} {} {[-1,6,1],[-1,-6,1]} {[2,1,1],[2,-1,1]} {[1,2,0],[1,-2,0]} {[1,2,2],[1,-2,2]} {} {} {} {[1,1,1],[1,-1,1]} {} {} {[-1,2,1],[-1,-2,1],[0,1,1],[0,-1,1]} {} {[-2,9,1],[-2,-9,1],[0,3,1],[0,-3,1]} {[1,2,0],[1,-2,0]} {} {[1,5,1],[1,-5,1]} {[4,43,5],[4,-43,5]} {} {[1,0,1],[-3,42,4],[-3,-42,4]} {} {} {[1,1,0],[1,-1,0],[1,3,1],[1,-3,1]} {[1,0,1]} {[1,2,1],[1,-2,1]} {[5,1735,8],[5,-1735,8],[-11,7265,16],[-11,-7265,16]} {} {[0,3,1],[0,-3,1]} {[-2,9,1],[-2,-9,1]} {[1,2,1],[1,-2,1]} {[-1,2,1],[-1,-2,1]} {} {} {[0,3,1],[0,-3,1]} {} {} {} {[1,3,0],[1,-3,0]} {[-1,2,1],[-1,-2,1]} {[1,0,0]} {} {} {} {[-1,0,1]} {[1,1,0],[1,-1,0]} {} {[-1,3,1],[-1,-3,1]} {} {[1,1,0],[1,-1,0]} {[0,1,1],[0,-1,1]} {[2,11,1],[2,-11,1]} {[0,0,1],[1,10,2],[1,-10,2]} {[-1,460,6],[-1,-460,6]} {[-2,20,1],[-2,-20,1]} {[-1,3,1],[-1,-3,1],[-6,368,5],[-6,-368,5]} {[1,3,1],[1,-3,1]} {} {[1,0,0]} {[0,2,1],[0,-2,1]} {[-1,3,1],[-1,-3,1],[1,2,0],[1,-2,0],[11,2535,1],[11,-2535,1]} {} {[1,19,2],[1,-19,2]} {} {[-1,3,1],[-1,-3,1],[0,2,1],[0,-2,1]} {} {[1,1,0],[1,-1,0]} {} {} {[1,2,1],[1,-2,1],[-1,11,2],[-1,-11,2]} {[1,3,0],[1,-3,0]} {} {[1,3,0],[1,-3,0],[1,3,1],[1,-3,1]} {} {[1,0,0],[-2,4,1],[-2,-4,1]} {[-1,27,2],[-1,-27,2]} {} {[1,3,0],[1,-3,0]} {} {[0,0,1]} {[0,1,1],[0,-1,1]} {[1,2,0],[1,-2,0]} {[1,2,0],[1,-2,0],[-1,3,1],[-1,-3,1],[0,1,1],[0,-1,1],[3,74,2],[3,-74,2],[-8,1591,7],[-8,-1591,7]} {} {} {} {[-1,5,1],[-1,-5,1],[1,3,0],[1,-3,0]} {[-1,4,1],[-1,-4,1]} {[0,1,1],[0,-1,1]} {} {[2,76,3],[2,-76,3],[7,7780,15],[7,-7780,15]} {[0,1,1],[0,-1,1],[1,1,1],[1,-1,1],[3,10,2],[3,-10,2]} {[1,1,0],[1,-1,0],[0,1,1],[0,-1,1],[-4,95,3],[-4,-95,3]} {[1,1,1],[1,-1,1],[-1,55,3],[-1,-55,3],[2,64,3],[2,-64,3]} {[3,57,2],[3,-57,2]} {[2,14,1],[2,-14,1]} {[-1,4,1],[-1,-4,1]} {} {[1,0,0],[-3,5,1],[-3,-5,1]} {[1,1,0],[1,-1,0],[0,3,1],[0,-3,1]} {} {[0,3,1],[0,-3,1]} {[-1,5,1],[-1,-5,1],[1,1,1],[1,-1,1],[1,22,2],[1,-22,2]} {} {[1,2,0],[1,-2,0]} {[-1,0,1],[0,1,1],[0,-1,1]} {[-7,521,5],[-7,-521,5]} {} {} {[1,3,0],[1,-3,0]} {} {[-2,20,1],[-2,-20,1],[1,2,1],[1,-2,1],[22,31638,15],[22,-31638,15]} {} {} {[1,3,1],[1,-3,1]} {} {} {[-1,1,1],[-1,-1,1]} {} {} {} {} {} {[1,4,1],[1,-4,1],[1,23,2],[1,-23,2]} {} {} {[0,3,1],[0,-3,1],[-5,257,4],[-5,-257,4]} {} {[-1,3,1],[-1,-3,1]} {} {[-1,0,1],[0,3,1],[0,-3,1]} {[-1,0,1]} {[0,0,1]} {[0,3,1],[0,-3,1],[-5,348,6],[-5,-348,6]} {} {} {} {[-1,1,1],[-1,-1,1]} {} {} {} {} {[1,2,0],[1,-2,0],[0,3,1],[0,-3,1]} {[1,0,0]} {[0,3,1],[0,-3,1]} {} {[-1,7,2],[-1,-7,2],[1,1,0],[1,-1,0]} {[1,1,0],[1,-1,0]} {[1,3,0],[1,-3,0]} {[1,1,0],[1,-1,0]} {[1,2,0],[1,-2,0]} {[3,3,2],[3,-3,2]} {} {} {} {} {} {[1,0,0]} {} {[1,1,0],[1,-1,0],[0,3,1],[0,-3,1]} {} {[1,4,1],[1,-4,1]} {} {} {} {[1,0,1]} {[1,1,0],[1,-1,0]} {[0,1,1],[0,-1,1]} {} {[-1,4,1],[-1,-4,1]} {[0,1,1],[0,-1,1]} {[0,1,1],[0,-1,1]} {} {} {[1,2,0],[1,-2,0],[4,100,1],[4,-100,1]} {[1,3,0],[1,-3,0],[1,0,1],[-313,27928221051,2496],[-313,-27928221051,2496]} {} {[0,1,1],[0,-1,1]} {} {[1,1,0],[1,-1,0]} {} {} {} {[1,3,0],[1,-3,0],[0,2,1],[0,-2,1]} {} {[1,3,1],[1,-3,1]} {} {[1,0,0],[-1,0,1]} {} {[-1,4,1],[-1,-4,1]} {[0,3,1],[0,-3,1]} {[1,1,1],[1,-1,1]} {} {[-3,81,1],[-3,-81,1]} {[-47,3295394,104],[-47,-3295394,104]} {[0,2,1],[0,-2,1]} {[-1,5,1],[-1,-5,1]} {[1,1,1],[1,-1,1]} {[1,0,0],[-1,5,1],[-1,-5,1]} {[1,0,1]} {[1,3,0],[1,-3,0]} {[-1,53,4],[-1,-53,4],[1,3,0],[1,-3,0]} {} {[-2,16,1],[-2,-16,1],[-1,0,1],[0,2,1],[0,-2,1],[5,198,1],[5,-198,1],[1,27,2],[1,-27,2],[7,5094,11],[7,-5094,11]} {[1,2,0],[1,-2,0],[0,2,1],[0,-2,1],[3,20,4],[3,-20,4]} {} {[0,0,1]} {} {} {[1,1,0],[1,-1,0],[1,4,1],[1,-4,1]} {} {} {} {[1,1,0],[1,-1,0],[0,1,1],[0,-1,1],[-57,543145,112],[-57,-543145,112]} {[0,3,1],[0,-3,1]} {[0,3,1],[0,-3,1]} {} {[-1,2,1],[-1,-2,1],[1,0,1]} {} {} {[1,0,0]} {} {[0,3,1],[0,-3,1]} {[-1,3,1],[-1,-3,1],[0,3,1],[0,-3,1]} {[-1,3,1],[-1,-3,1]} {} {[1,0,0]} {[-4,170,1],[-4,-170,1],[0,2,1],[0,-2,1]} {[1,0,0],[-8,604,1],[-8,-604,1],[-2,22,1],[-2,-22,1],[-1,5,1],[-1,-5,1],[0,0,1],[1,1,1],[1,-1,1],[-1,381,9],[-1,-381,9],[1,4,2],[1,-4,2],[-9,3228,8],[-9,-3228,8],[-1,95,5],[-1,-95,5],[9,1200,10],[9,-1200,10]} {[0,1,1],[0,-1,1],[1,3,1],[1,-3,1]} {} {} {[1,1,1],[1,-1,1]} {[0,1,1],[0,-1,1]} {[0,1,1],[0,-1,1]} {[1,1,0],[1,-1,0]} {[1,0,1],[-4,123,5],[-4,-123,5]} {} {[1,1,0],[1,-1,0],[0,3,1],[0,-3,1]} {} {[0,2,1],[0,-2,1]} {} {} {[0,1,1],[0,-1,1]} {} {} {[0,0,1],[-1,2,1],[-1,-2,1],[1,8,2],[1,-8,2]} {[0,2,1],[0,-2,1],[1,2,1],[1,-2,1]} {[-1,5,1],[-1,-5,1],[0,3,1],[0,-3,1],[2,17,1],[2,-17,1]} {[-1,3,1],[-1,-3,1],[1,1,0],[1,-1,0]} {[-3,112,2],[-3,-112,2]} {} {} {} {[-1,2,1],[-1,-2,1]} {[1,0,0],[1,2,1],[1,-2,1]} {} {[1,1,0],[1,-1,0]} {[-1,1,1],[-1,-1,1],[-1,7,2],[-1,-7,2]} {} {} {[0,1,1],[0,-1,1]} {} {[-1,1,1],[-1,-1,1]} {} {} {} {[0,0,1]} {[0,3,1],[0,-3,1]} {} {} {[1,2,1],[1,-2,1]} {} {} {[0,0,1]} {[2,5,1],[2,-5,1],[3,50,1],[3,-50,1]} {[0,3,1],[0,-3,1]} {[-1,25,3],[-1,-25,3],[1,2,0],[1,-2,0]} {} {} {} {} {} {} {} {[-1,4,1],[-1,-4,1]} {} {[-1,4,1],[-1,-4,1]} {[0,2,1],[0,-2,1],[1,1,1],[1,-1,1],[63,338641,71],[63,-338641,71],[168,8223850,205],[168,-8223850,205]} {[1,2,1],[1,-2,1]} {[4,10,3],[4,-10,3]} {} {} {} {[0,1,1],[0,-1,1]} {[-1,2,1],[-1,-2,1]} {[0,2,1],[0,-2,1]} {[-1,5,1],[-1,-5,1],[1,2,0],[1,-2,0],[-2,24,1],[-2,-24,1]} {} {[-4,16,1],[-4,-16,1],[0,2,1],[0,-2,1],[1,187,5],[1,-187,5]} {} {[-1,3,1],[-1,-3,1]} {} {[-1,0,1],[0,2,1],[0,-2,1]} {[-1,2,1],[-1,-2,1]} {[1,3,0],[1,-3,0]} {[1,0,0]} {[-1,3,1],[-1,-3,1]} {} {[1,16,2],[1,-16,2],[-1,71,3],[-1,-71,3],[-5,820,6],[-5,-820,6],[71,117115,51],[71,-117115,51]} {} {[1,2,0],[1,-2,0],[1,0,1]} {} {} {} {} {} {[1,5,2],[1,-5,2],[5,209,8],[5,-209,8]} {} {} {[-1,1,1],[-1,-1,1],[1,1,1],[1,-1,1],[4,1,1],[4,-1,1]} {} {} {[0,1,1],[0,-1,1]} {[1,0,1]} {[1,2,0],[1,-2,0]} {[0,2,1],[0,-2,1],[1,0,1],[10,2328,1],[10,-2328,1],[-9,767,4],[-9,-767,4]} {} {[1,4,1],[1,-4,1]} {[-1,1,1],[-1,-1,1]} {[-2,10,1],[-2,-10,1],[1,2,1],[1,-2,1]} {[1,2,0],[1,-2,0]} {[3,67,1],[3,-67,1],[-1,4,2],[-1,-4,2]} {} {} {[-2,12,1],[-2,-12,1]} {[1,3,0],[1,-3,0]} {} {} {[0,1,1],[0,-1,1]} {} {} {} {} {[0,2,1],[0,-2,1]} {[5,2086,13],[5,-2086,13]} {[0,3,1],[0,-3,1]} {[1,2,0],[1,-2,0]} {} {[0,1,1],[0,-1,1]} {[-2,23,3],[-2,-23,3]} {} {} {[1,4,1],[1,-4,1]} {[-1,537,6],[-1,-537,6],[1,3,0],[1,-3,0],[41,636063,51],[41,-636063,51]} {} {} {[-1,1,1],[-1,-1,1],[1,3,0],[1,-3,0]} {} {} {} {[1,3,0],[1,-3,0],[0,3,1],[0,-3,1],[1,25,2],[1,-25,2],[-1,209,4],[-1,-209,4]} {[0,2,1],[0,-2,1]} {[2,10,1],[2,-10,1]} {[0,1,1],[0,-1,1],[3,241,5],[3,-241,5]} {} {[1,2,0],[1,-2,0]} {} {} {[0,0,1],[-3,102,2],[-3,-102,2],[12,34950,23],[12,-34950,23]} {} {[1,3,0],[1,-3,0],[1,2,1],[1,-2,1]} {[-1,3,1],[-1,-3,1]} {[0,2,1],[0,-2,1]} {} {} {} {[-1,3,1],[-1,-3,1],[0,1,1],[0,-1,1]} {} {} {[0,0,1],[1,0,2]} {[-2,6,1],[-2,-6,1],[-1,0,1]} {[0,3,1],[0,-3,1]} {[-1,1,1],[-1,-1,1]} {} {[-1,1,1],[-1,-1,1],[0,3,1],[0,-3,1]} {[-2,17,1],[-2,-17,1],[5,368,1],[5,-368,1]} {} {} {[0,1,1],[0,-1,1],[1,0,1]} {[-1,0,1]} {[1,3,0],[1,-3,0]} {[0,2,1],[0,-2,1],[3,2357,10],[3,-2357,10]} {} {} {} {[-1,0,1],[0,3,1],[0,-3,1]} {} {[1,3,0],[1,-3,0]} {} {} {} {} {} {} {} {[1,3,0],[1,-3,0],[1,3,1],[1,-3,1]} {} {[0,3,1],[0,-3,1]} {} {[1,2,0],[1,-2,0],[-1,6,1],[-1,-6,1],[0,3,1],[0,-3,1]} {[-1,70,3],[-1,-70,3]} {} {[1,1,1],[1,-1,1]} {} {[0,2,1],[0,-2,1]} {[-1,0,1],[1,3,0],[1,-3,0],[4,190,1],[4,-190,1]} {} {[-2,1,1],[-2,-1,1]} {[-3,27,2],[-3,-27,2],[-1,9,2],[-1,-9,2]} {[-1,4,1],[-1,-4,1]} {} {[0,2,1],[0,-2,1]} {} {} {[1,12,2],[1,-12,2],[-1,180,4],[-1,-180,4],[4,9039,17],[4,-9039,17]} {[1,3,0],[1,-3,0],[0,2,1],[0,-2,1],[-1,25,2],[-1,-25,2]} {} {[-1,4,1],[-1,-4,1]} {} {} {[-1,4,1],[-1,-4,1]} {[3,265,5],[3,-265,5]} {} {} {} {} {} {} {[-1,3,1],[-1,-3,1]} {} {[1,2,0],[1,-2,0],[1,3,1],[1,-3,1]} {[1,3,0],[1,-3,0]} {[1,11,2],[1,-11,2]} {} {} {[1,0,0]} {} {[1,2,0],[1,-2,0],[2,12,1],[2,-12,1]} {[0,2,1],[0,-2,1]} {} {[0,2,1],[0,-2,1]} {[1,3,0],[1,-3,0]} {} {} {} {} {[1,1,0],[1,-1,0]} {} {[1,2,1],[1,-2,1]} {[1,3,0],[1,-3,0],[13,6807,9],[13,-6807,9]} {} {[-1,1,1],[-1,-1,1]} {[0,2,1],[0,-2,1],[1,2,1],[1,-2,1],[4,154,1],[4,-154,1]} {[1,24,2],[1,-24,2]} {} {} {[1,0,0],[1,3,1],[1,-3,1]} {[-1,1,1],[-1,-1,1]} {} {[-3,80,2],[-3,-80,2]} {} {[1,0,1]} {[1,3,0],[1,-3,0]} {[-1,4,1],[-1,-4,1],[1,2,0],[1,-2,0]} {} {[0,3,1],[0,-3,1],[92,14946963,209],[92,-14946963,209]} {} {} {[1,0,0]} {[-2,27,1],[-2,-27,1]} {} {[0,1,1],[0,-1,1],[-1,12,2],[-1,-12,2],[3,56,2],[3,-56,2]} {[0,1,1],[0,-1,1]} {} {[0,3,1],[0,-3,1]} {[0,2,1],[0,-2,1]} {[1,0,1]} {} {} {[1,0,1]} {} {} {} {[-1,3,1],[-1,-3,1]} {[1,0,0],[-1,2,1],[-1,-2,1]} {} {} {[-1,1,1],[-1,-1,1]} {} {[1,1,0],[1,-1,0]} {} {[1,0,0],[-1,3,1],[-1,-3,1],[0,1,1],[0,-1,1]} {[-1,3,1],[-1,-3,1],[-1,23,2],[-1,-23,2],[14,4236,13],[14,-4236,13]} {[1,3,0],[1,-3,0]} {[0,3,1],[0,-3,1]} {} {[1,1,0],[1,-1,0]} {} {} {} {[-1,1,1],[-1,-1,1],[1,1,1],[1,-1,1]} {} {} {[0,2,1],[0,-2,1],[1,0,1],[7,1990,11],[7,-1990,11]} {[1,1,0],[1,-1,0]} {[0,0,1]} {[-1,14,2],[-1,-14,2],[1,2,0],[1,-2,0]} {} {} {[1,0,0],[1,1,1],[1,-1,1]} {[0,0,1]} {[1,0,0]} {} {} {} {} {[0,1,1],[0,-1,1]} {} {[0,2,1],[0,-2,1],[1,2,2],[1,-2,2]} {} {[1,1,1],[1,-1,1]} {} {[1,0,0],[-2,8,1],[-2,-8,1],[-1,4,1],[-1,-4,1],[0,2,1],[0,-2,1],[3,38,1],[3,-38,1],[6,200,1],[6,-200,1],[127,3151792,49],[127,-3151792,49],[1,16,2],[1,-16,2],[325,2360754224,1058],[325,-2360754224,1058]} {[3,81,4],[3,-81,4]} {} {} {[1,2,1],[1,-2,1]} {[1,0,0]} {[-1,4,1],[-1,-4,1]} {} {[1,0,0],[1,2,2],[1,-2,2]} {} {} {[1,3,0],[1,-3,0],[1,19,2],[1,-19,2]} {} {} {} {[1,0,0],[-3,39,1],[-3,-39,1],[-2,9,1],[-2,-9,1]} {} {[2,3,1],[2,-3,1]} {[1,1,1],[1,-1,1]} {} {} {} {[0,1,1],[0,-1,1],[-3,287,5],[-3,-287,5]} {} {[1,2,1],[1,-2,1]} {} {[1,0,0]} {} {[-1,3,1],[-1,-3,1],[1,1,1],[1,-1,1]} {[1,0,0]} {[0,2,1],[0,-2,1]} {[0,3,1],[0,-3,1],[1,1,1],[1,-1,1]} {[0,2,1],[0,-2,1]} {[-1,1,1],[-1,-1,1]} {} {[1,1,1],[1,-1,1],[-1,23,2],[-1,-23,2]} {[0,0,1],[-1,0,1],[3,0,2]} {} {[0,3,1],[0,-3,1]} {} {} {[1,3,0],[1,-3,0]} {} {[-1,3,1],[-1,-3,1]} {} {[1,3,1],[1,-3,1]} {} {[1,0,0],[1,1,1],[1,-1,1]} {[0,0,1]} {} {[0,2,1],[0,-2,1]} {} {[0,2,1],[0,-2,1]} ratpoints-2.1.3+dfsg.orig/gpl-2.0.txt0000644000175000017500000004310311536145472015723 0ustar tobitobi GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 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 the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. ratpoints-2.1.3+dfsg.orig/primes.h0000644000175000017500000000512411536145472015554 0ustar tobitobi/*********************************************************************** * ratpoints-2.1.1 * * - A program to find rational points on hyperelliptic curves * * Copyright (C) 2008, 2009 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 . * ***********************************************************************/ /*********************************************************************** * primes.h * * * * The odd prime numbers up to 1024 * * * * Michael Stoll, Jan 9, 2008 * ***********************************************************************/ #define PRIMES1000 171 static const long prime[PRIMES1000] = {3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103, 107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199, 211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313, 317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433, 439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563, 569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673, 677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811, 821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941, 947,953,967,971,977,983,991,997,1009,1013,1019,1021}; ratpoints-2.1.3+dfsg.orig/Makefile0000644000175000017500000001117111536145472015543 0ustar tobitobi# ratpoints-2.1.3 # - A program to find rational points on hyperelliptic curves # Copyright (C) 2008, 2009 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 . # # # Makefile # # Michael Stoll, September 21, 2009 PRIME_SIZE = 7 CC = gcc RM = rm -f INSTALL = cp INSTALL_DIR = /usr/local CCFLAGS1 = -Wall -O2 -fomit-frame-pointer -DRATPOINTS_MAX_BITS_IN_PRIME=${PRIME_SIZE} -DUSE_SSE # for gcc on Apple, may have to add '-fnested-functions' to CCFLAGS1 CCFLAGS2 = -lgmp -lgcc -lc -lm CCFLAGS3 = -L. -lratpoints CCFLAGS = DISTFILES = Makefile ratpoints.h rp-private.h primes.h \ gen_find_points_h.c gen_init_sieve_h.c \ sift.c init.c sturm.c find_points.c \ main.c rptest.c testdata.h testbase ratpoints-doc.pdf \ gpl-2.0.txt TEMPFILES = sift.o init.o sturm.o find_points.o \ sift.s init.s find_points.h init_sieve.h \ gen_find_points_h gen_init_sieve_h \ rptest.out sift-debug.o find_points-debug.o main.o TARGETFILES = ratpoints libratpoints.a rptest ratpoints-debug all: ratpoints libratpoints.a test: rptest testbase time ./rptest > rptest.out # diff -q testbase rptest.out cmp -s testbase rptest.out || echo "Test failed!" install-bin: ratpoints ${INSTALL} ratpoints ${INSTALL_DIR}/bin/ chmod 755 ${INSTALL_DIR}/bin/ratpoints install-lib: ratpoints.h libratpoints.a ${INSTALL} ratpoints.h ${INSTALL_DIR}/include/ chmod 644 ${INSTALL_DIR}/include/ratpoints.h ${INSTALL} libratpoints.a ${INSTALL_DIR}/lib/ chmod 644 ${INSTALL_DIR}/lib/libratpoints.a install: install-bin install-lib dist: ${DISTFILES} mkdir -p ratpoints-2.1.3 cp ${DISTFILES} ratpoints-2.1.3/ tar --create --file=ratpoints-2.1.3-`date --rfc-3339=date`.tar.gz \ --gzip --dereference ratpoints-2.1.3 rm -r ratpoints-2.1.3 clean: ${RM} ${TEMPFILES} distclean: clean ${RM} ${TARGETFILES} debug: ratpoints-debug libratpoints.a: sift.o init.o sturm.o find_points.o ar rs libratpoints.a sift.o init.o sturm.o find_points.o ratpoints: libratpoints.a main.c ratpoints.h ${CC} main.c -o ratpoints ${CCFLAGS1} ${CCFLAGS2} ${CCFLAGS3} ${CCFLAGS} main.o: main.c ratpoints.h ${CC} main.c -c -o main.o ${CCFLAGS1} -O3 ${CCFLAGS} ratpoints-debug: sift-debug.o init.o sturm.o find_points-debug.o main.o ${CC} sift-debug.o init.o sturm.o find_points-debug.o main.o \ -o ratpoints-debug ${CCFLAGS1} ${CCFLAGS2} ${CCFLAGS} sift.o: sift.c ratpoints.h rp-private.h ${CC} sift.c -c -o sift.o ${CCFLAGS1} -funroll-loops ${CCFLAGS} sift-debug.o: sift.c ratpoints.h rp-private.h ${CC} sift.c -c -o sift-debug.o ${CCFLAGS1} -funroll-loops -DDEBUG ${CCFLAGS} sift.s: sift.c ratpoints.h rp-private.h ${CC} sift.c -S -o sift.s ${CCFLAGS1} -funroll-loops ${CCFLAGS} sift.i: sift.c ratpoints.h rp-private.h ${CC} sift.c -E -o sift.i ${CCFLAGS1} -funroll-loops ${CCFLAGS} init.o: init.c ratpoints.h rp-private.h init_sieve.h ${CC} init.c -c -o init.o ${CCFLAGS1} -funroll-loops -O3 ${CCFLAGS} init.s: init.c ratpoints.h rp-private.h init_sieve.h ${CC} init.c -S -o init.s ${CCFLAGS1} -funroll-loops -O3 ${CCFLAGS} sturm.o: sturm.c ratpoints.h rp-private.h ${CC} sturm.c -c -o sturm.o ${CCFLAGS1} ${CCFLAGS} find_points.o: find_points.c ratpoints.h rp-private.h primes.h find_points.h ${CC} find_points.c -c -o find_points.o ${CCFLAGS1} ${CCFLAGS} find_points-debug.o: find_points.c ratpoints.h rp-private.h primes.h find_points.h ${CC} find_points.c -c -o find_points-debug.o ${CCFLAGS1} -DDEBUG ${CCFLAGS} rptest: libratpoints.a rptest.c ratpoints.h testdata.h ${CC} rptest.c -o rptest ${CCFLAGS1} ${CCFLAGS2} ${CCFLAGS3} ${CCFLAGS} gen_init_sieve_h: gen_init_sieve_h.c ratpoints.h rp-private.h primes.h ${CC} gen_init_sieve_h.c -o gen_init_sieve_h ${CCFLAGS1} ${CCFLAGS2} ${CCFLAGS} gen_find_points_h: gen_find_points_h.c ratpoints.h rp-private.h primes.h ${CC} gen_find_points_h.c -o gen_find_points_h ${CCFLAGS1} ${CCFLAGS2} ${CCFLAGS} init_sieve.h: gen_init_sieve_h ./gen_init_sieve_h > init_sieve.h find_points.h: gen_find_points_h ./gen_find_points_h > find_points.h ratpoints-2.1.3+dfsg.orig/main.c0000644000175000017500000005436511536145472015207 0ustar tobitobi/*********************************************************************** * ratpoints-2.1.2 * * - A program to find rational points on hyperelliptic curves * * Copyright (C) 2008, 2009 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 . * ***********************************************************************/ /*********************************************************************** * main.c * * * * Main program file for the ratpoints executable * * * * Michael Stoll, May 27, 2009 * ***********************************************************************/ #include #include #include #include "ratpoints.h" /************************************************************************** * define * **************************************************************************/ #define RATPOINTS_VERSION \ "This is ratpoints-2.1.3 Copyright (C) 2008,2009 by Michael Stoll.\n\n" \ "This program comes with ABSOLUTELY NO WARRANTY.\n" \ "This is free software, and you are welcome to redistribute it under the\n" \ "terms of the GNU General Public License version 2 or later.\n\n" \ "Please acknowledge use of this program in published work.\n\n" /************************************************************************** * global variables * **************************************************************************/ mpz_t c[RATPOINTS_MAX_DEGREE+1]; /* The coefficients of f */ mpz_t tmp, tmp2; int quiet; /* A flag saying whether to suppress messages */ int one_point; /* A flag saying if one point is enough */ int points_at_infty; /* A flag saying if we should look for points at infty */ int no_output; /* A flag that indicates that no points should be printed */ char *print_format; /* The printf format for printing points */ char *string_before; /* String to be printed before the points */ char *string_between;/* String to be printed between the points */ char *string_after; /* String to be printed after the points */ ratpoints_interval domain[2*RATPOINTS_MAX_DEGREE]; /* This contains the intervals representing the search region */ char *usage_str = "Usage: ratpoints 'a_0 a_1 ... a_n' max_height\n" " [-dl low_den] [-du up_den]\n" " [-f format] [-fs str] [-fm str] [-fe str] [-y] [-Y]\n" " [[-l low1] -u up1 ... -l lown [-u upn]]\n" " [-n num_primes1] [-N num_primes2] [-p max_primes]\n" " [-F max_forbidden] [-s] [-S [iter]]\n" " [-q] [-v] [-z] [-Z] [-1] [-i] [-I]\n" " [-k] [-K] [-j] [-J] [-x] [-X]\n\n"; /************************************************************************** * prototypes * **************************************************************************/ int read_input(long, char *argv[], ratpoints_args*); char *scan_mpz(char*, mpz_t); void print_poly(mpz_t*, long); void print_string(char*); void message(long n, long total, ratpoints_args *args); void error(long); /************************************************************************** * function that processes the points * **************************************************************************/ typedef struct {int print_between; int no_output; int one_point; int points_at_infty; int no_y; char *pf; char* string_before; char *string_between;} data; int process(long a, long b, const mpz_t y, void *info0, int *quit) { data *info = (data *)info0; char *fmt = info->pf; if(b == 0 && !(info->points_at_infty)) return(0); *quit = info->one_point; if(info->no_output) return(1); if(info->print_between) { print_string(info->string_between); } else { print_string(info->string_before); info->print_between = 1; } while(*fmt) { char c = *fmt++; switch(c) { case '%': c = *fmt++; switch(c) { case 0: putchar('%'); return(1); case 'x': printf("%ld", a); break; case 'y': if(info->no_y) { putchar('%'); putchar('y'); } else { mpz_out_str((FILE *)NULL, 10, y); } break; case 'z': printf("%ld", b); break; default: putchar('%'); putchar(c); break; } break; case '\\': c = *fmt++; switch(c) { case 0: putchar('\\'); return(1); case 't': printf("\t"); break; case 'n': printf("\n"); break; case '\\': putchar('\\'); break; case '%': putchar('%'); break; default: putchar('\\'); putchar(c); break; } break; default: putchar(c); break; } } fflush(stdout); return(1); } /************************************************************************** * main * **************************************************************************/ int main(int argc, char *argv[]) { long total; ratpoints_args args; { long n; /* initialise multi-precision integer variables */ for(n = 0; n <= RATPOINTS_MAX_DEGREE; n++) { mpz_init(c[n]); } } mpz_init(tmp); mpz_init(tmp2);; /* read input */ if(argc < 3) error(2); if(read_input(argc-1, &argv[0], &args)) { message(1, 0, &args); return(0); } if(!quiet) { message(0, 0, &args); message(5, args.degree, &args); if(!(args.flags & RATPOINTS_VERBOSE)) { message(6, args.height, &args); printf("\n"); } } args.array_size = RATPOINTS_ARRAY_SIZE; if(!quiet && args.num_inter > 0) message(3, 0, &args); /* typedef struct {int print_between; int no_output; int one_point; int points_at_infty; int no_y; char *pf; char* string_before; char *string_between;} data; */ { data *info = malloc(sizeof(data)); info->print_between = 0; info->no_output = no_output; info->pf = print_format; info->one_point = one_point; info->points_at_infty = points_at_infty; info->string_before = string_before; info->string_between = string_between; info->no_y = args.flags & (RATPOINTS_NO_CHECK | RATPOINTS_NO_Y); total = find_points(&args, process, (void *)info); free(info); } if(total < 0) { mpz_clear(tmp); mpz_clear(tmp2); if(total == RATPOINTS_NON_SQUAREFREE) error(8); error(9); } if(total == 0) print_string(string_before); print_string(string_after); if(!quiet) { if(!(args.flags & RATPOINTS_VERBOSE)) { printf("\n\n"); message(4, 0, &args); message(7, 0, &args); message(8, 0, &args); } message(2, total, &args); } mpz_clear(tmp); mpz_clear(tmp2); { long n; /* initialise multi-precision integer variables */ for(n = 0; n <= RATPOINTS_MAX_DEGREE; n++) { mpz_clear(c[n]); } } return(0); } /************************************************************************** * procedures * **************************************************************************/ /************************************************************************** * get at the input * **************************************************************************/ int read_input(long argc, char *argv[], ratpoints_args *args) { int l_seen = 0; /* flag for dealing with -l -u */ mpz_t fff; long num_inter = 0; /* Initialize args */ /* 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 = 0; args->height = 0; args->domain = &domain[0]; args->num_inter = 0; /* No interval up to now */ args->b_low = 1; /* denominators go from 1 to h */ args->b_high = -1; args->sp1 = -1; /* gives default value */ args->sp2 = -1; /* gives default value */ args->array_size = RATPOINTS_ARRAY_SIZE; args->sturm = RATPOINTS_DEFAULT_STURM; args->num_primes = -1; /* gives default value */ args->max_forbidden = -1; /* gives default value */ args->flags = 0; /* do the check by default */ /* list y-coordinates by default */ /* allow reversal of polynomial */ /* use Jacobi symbol test */ mpz_init(fff); { char *s = argv[1]; long degree = 0; while((degree <= RATPOINTS_MAX_DEGREE) && (s = scan_mpz(s, c[degree]))) { degree++; } degree--; if(scan_mpz(s, fff)) error(3); if(degree == 0) error(5); args->degree = degree; } if(sscanf(argv[2], " %ld", &(args->height)) != 1 || args->height < 1) { error(4); } args->b_high = args->height; /* Set global variables to their default values */ no_output = 0; /* print points by default */ quiet = 0; /* don't be quiet */ one_point = 0; /* look for all points */ points_at_infty = 1; /* also find points at infinity */ print_format = NULL; string_before = NULL; string_between = NULL; string_after = NULL; /* recognise optional args */ { long i = 3; while(i <= argc) { if(*(argv[i]) != '-') error(6); switch(argv[i][1]) { case 'l': /* lower intevral endpoint */ if(argc == i) error(7); i++; if(l_seen) error(7); /* -l -l */ if(num_inter == RATPOINTS_MAX_DEGREE) error(7); if(sscanf(argv[i], " %lf", &domain[num_inter].low) != 1) error(7); if(num_inter > 0 && domain[num_inter-1].up >= domain[num_inter].low) error(7); i++; l_seen = 1; break; case 'u': /* upper interval endpoint */ if(argc == i) error(7); i++; if(!l_seen) { if(num_inter == 0) domain[0].low = -args->height; else error(7); /* -u -u */ } if(sscanf(argv[i], " %lf", &domain[num_inter].up) != 1) error(7); if(domain[num_inter].low > domain[num_inter].up) error(7); i++; l_seen = 0; num_inter++; break; case 'p': /* max number of primes used */ if(argc == i) error(6); i++; if(sscanf(argv[i], " %ld", &(args->num_primes)) != 1) error(6); i++; break; case 'F': /* max number of "forbidden divisors of denominator" */ if(argc == i) error(6); i++; if(sscanf(argv[i], " %ld", &(args->max_forbidden)) != 1) error(6); i++; break; case 'n': /* number of primes used for first stage of sieving */ if(argc == i) error(6); i++; if(sscanf(argv[i], " %ld", &(args->sp1)) != 1) error(6); i++; break; case 'N': /* number of primes used for sieving altogether */ if(argc == i) error(6); i++; if(sscanf(argv[i], " %ld", &(args->sp2)) != 1) error(6); i++; break; case 'f': /* printing format */ switch(argv[i][2]) { case 0: /* just -f */ if(argc == i) error(6); i++; { long l = strlen(argv[i]); print_format = malloc((l+1)*sizeof(char)); strcpy(print_format, argv[i]); } i++; break; case 's': /* starting string */ if(argc == i) error(6); i++; { long l = strlen(argv[i]); string_before = malloc((l+1)*sizeof(char)); strcpy(string_before, argv[i]); } i++; break; case 'm': /* in-between string */ if(argc == i) error(6); i++; { long l = strlen(argv[i]); string_between = malloc((l+1)*sizeof(char)); strcpy(string_between, argv[i]); } i++; break; case 'e': /* ending string */ if(argc == i) error(6); i++; { long l = strlen(argv[i]); string_after = malloc((l+1)*sizeof(char)); strcpy(string_after, argv[i]); } i++; break; default: error(6); } break; case 'q': /* quiet */ quiet = 1; i++; break; case 'v': /* verbose */ args->flags |= RATPOINTS_VERBOSE; i++; break; case 'j': /* do not use Jacobi symbol */ args->flags |= RATPOINTS_NO_JACOBI; i++; break; case 'J': /* do use Jacobi symbol */ args->flags &= ~RATPOINTS_NO_JACOBI; i++; break; case 'k': /* keep: do not reverse polynomial */ args->flags |= RATPOINTS_NO_REVERSE; i++; break; case 'K': /* allow reversal of polynomial */ args->flags &= ~RATPOINTS_NO_REVERSE; i++; break; case 'x': /* no check */ args->flags |= RATPOINTS_NO_CHECK; i++; break; case 'X': /* do check points */ args->flags &= ~RATPOINTS_NO_CHECK; i++; break; case 'y': /* print only x-coordinates */ args->flags |= RATPOINTS_NO_Y; i++; break; case 'Y': /* print all points */ args->flags |= RATPOINTS_NO_Y; i++; break; case 'z': /* no output */ no_output = 1; i++; break; case 'Z': /* output the points */ no_output = 0; i++; break; case '1': /* only one point */ one_point = 1; i++; break; case 'i': /* no points at infty */ points_at_infty = 0; i++; break; case 'I': /* print points at infty */ points_at_infty = 1; i++; break; case 's': /* don't use Sturm sequence computation */ args->sturm = -1; i++; break; case 'S': /* Sturm sequence */ args->sturm = RATPOINTS_DEFAULT_STURM; i++; if(i <= argc && argv[i][0] != '-') { if(sscanf(argv[i], " %ld", &(args->sturm)) != 1) error(6); i++; } break; case 'd': /* Bounds for denom */ switch(argv[i][2]) { case 'l': /* lower bound */ if(argc == i) error(6); i++; if(sscanf(argv[i], " %ld", &(args->b_low)) != 1) error(6); i++; break; case 'u': /* upper bound */ if(argc == i) error(6); i++; if(sscanf(argv[i], " %ld", &(args->b_high)) != 1) error(6); i++; break; default: error(6); } break; default: error(6); } } } if(l_seen) /* complete last interval */ { domain[num_inter].up = args->height; num_inter++; } args->num_inter = num_inter; if(!print_format) /* default print format */ { print_format = (args->flags & (RATPOINTS_NO_CHECK | RATPOINTS_NO_Y)) ? "(%x : %z)\n" : "(%x : %y : %z)\n"; } if(quiet) { args->flags &= ~RATPOINTS_VERBOSE; } mpz_clear(fff); return(0); } /* Read in a long long long integer. */ char *scan_mpz(char *s, mpz_t x) { long neg = 0; if(s == NULL || *s == 0) return NULL; while(*s == ' ') s++; if(*s == 0) return NULL; if(*s == '-') {neg = 1; s++;} else if(*s == '+') s++; mpz_set_si(tmp2, 0); while('0' <= *s && *s <= '9') { mpz_mul_ui(tmp2, tmp2, 10); mpz_add_ui(tmp2, tmp2, (long)(*s - '0')); s++; } if(neg) mpz_neg(tmp2, tmp2); mpz_set(x, tmp2); return s; } /************************************************************************** * output routines * **************************************************************************/ void print_poly(mpz_t *coeffs, long degree) { int flag = 0; int i; char *s; for(i = degree; i >= 0; i--) { mpz_set(tmp, coeffs[i]); if(mpz_cmp_si(tmp, 0) != 0) { if(mpz_cmp_si(tmp, 0) > 0) { printf(flag ? " + " : ""); } else { printf(flag ? " - " : "- "); mpz_neg(tmp, tmp); } flag = 1; switch(i) { case 0: s = mpz_get_str((char *) 0, 10, tmp); printf("%s", s); free(s); break; case 1: if(mpz_cmp_si(tmp, 1) == 0) { printf("x"); } else { s = mpz_get_str((char *) 0, 10, tmp); printf("%s x", s); free(s); } break; default: if(mpz_cmp_si(tmp, 1) == 0) { printf("x^%d", i); } else { s = mpz_get_str((char *) 0, 10, tmp); printf("%s x^%d", s, i); free(s); } break; } } } printf("\n"); fflush(stdout); } void print_string(char *str) { if(str) { while(*str) { char c = *str++; if(c == '\\') { c = *str++; switch(c) { case 0: putchar('\\'); return; case 't': printf("\t"); break; case 'n': printf("\n"); break; case '\\': putchar('\\'); break; case '%': putchar('%'); break; default: putchar('\\'); putchar(c); break; } } else putchar(c); } } } void message(long n, long total, ratpoints_args *args) { switch(n) { case 0: printf("\n%s\n", RATPOINTS_VERSION); break; case 1: printf("\n%s\n%s", RATPOINTS_VERSION, usage_str); break; case 2: if(args->flags & (RATPOINTS_NO_CHECK | RATPOINTS_NO_Y)) { printf("\n%ld rational point pairs found.\n\n", total); } else { printf("\n%ld rational points found.\n\n", total); } break; case 3: printf("Search region:\n "); { long i; for(i = 0; i < args->num_inter; i++) { if(i) printf(" U "); printf("[%f, %f]", args->domain[i].low, args->domain[i].up); } } printf("\n"); break; case 4: printf("%ld primes used for first stage of sieving,\n", args->sp1); printf("%ld primes used for both stages of sieving together.\n", args->sp2); break; case 5: printf("\nCurve equation is y^2 = "); print_poly(args->cof, args->degree); printf("\n"); break; case 6: printf("max. Height = %ld\n", args->height); break; case 7: if(args->flags & RATPOINTS_REVERSED) printf("Polynomial was reversed for better performance.\n"); if(args->flags & RATPOINTS_USE_SQUARES) { printf("(Reversed) polynomial is +-monic of odd degree:\n"); printf(" could restrict denominators to squares.\n"); } if(args->flags & RATPOINTS_USE_SQUARES1) { printf("(Reversed) polynomial has odd degree:\n"); printf(" could restrict denominators essentially to squares.\n"); } if(args->flags & RATPOINTS_NO_JACOBI) printf("Jacobi symbol test was not used.\n"); if(args->flags & RATPOINTS_NO_CHECK) { printf("Points were not checked exactly:\n"); printf(" some of the printed x-coordinates may not give points.\n"); } break; case 8: printf("Search intervals:\n"); { long i; for(i = 0; i < args->num_inter; i++) { printf("[%lf, %lf]", args->domain[i].low, args->domain[i].up); if(i < args->num_inter -1) printf(" U "); } printf("\n"); } break; } fflush(stdout); } void error(long errno) { switch(errno) { case 3: printf("\nToo many coefficients.\n\n"); break; case 4: printf("\nIncorrect height argument.\n\n"); break; case 5: printf("\nThe polynomial must have degree at least 1.\n\n"); break; case 6: printf("\nWrong syntax for optional arguments:\n\n"); case 2: printf("\n%s\n%s", RATPOINTS_VERSION, usage_str); break; case 7: printf("\nIncorrect interval arguments (not alternating, "); printf("too many, or not ordered).\n\n"); break; case 8: printf("\nPolynomial is not square-free.\n\n"); break; case 9: printf("\nBug no. 1 - please report!\n\n"); break; } fflush(stdout); exit(errno); } ratpoints-2.1.3+dfsg.orig/rptest.c0000644000175000017500000002147411536145472015577 0ustar tobitobi/*********************************************************************** * 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 . * ***********************************************************************/ /*********************************************************************** * 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 #include #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); } ratpoints-2.1.3+dfsg.orig/gen_init_sieve_h.c0000644000175000017500000000472411536145472017553 0ustar tobitobi/*********************************************************************** * ratpoints-2.1.2 * * - A program to find rational points on hyperelliptic curves * * Copyright (C) 2008, 2009 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 . * ***********************************************************************/ /*********************************************************************** * gen_init_sieve_h.c * * * * This program writes the file init_sieve.h * * * * Michael Stoll, Jan 9, 2008 * ***********************************************************************/ #include "rp-private.h" #include "primes.h" ratpoints_bit_array work[RATPOINTS_MAX_PRIME]; int main(int argc, char *argv[]) { long n; for(n = 0; n < RATPOINTS_NUM_PRIMES; n++) { long p = prime[n]; if(p < LONG_LENGTH) { printf("CODE_INIT_SIEVE1(%ld)\n", p); } else { printf("CODE_INIT_SIEVE2(%ld)\n", p); } } printf("\n"); printf("ratpoints_init_fun sieve_init[RATPOINTS_NUM_PRIMES] = \n{"); for(n = 0; n < RATPOINTS_NUM_PRIMES; n++) { long p = prime[n]; { printf("&sieve_init_%ld", p); } if(n < RATPOINTS_NUM_PRIMES - 1) printf(",\n "); } printf("};\n\n"); return(0); } ratpoints-2.1.3+dfsg.orig/ratpoints.h0000644000175000017500000001057311536145472016304 0ustar tobitobi/*********************************************************************** * ratpoints-2.1.3 * * - A program to find rational points on hyperelliptic curves * * Copyright (C) 2008, 2009 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 . * ***********************************************************************/ /*********************************************************************** * ratpoints.h * * * * Header file for the ratpoints program and library * * * * Michael Stoll, September 21, 2009 * ***********************************************************************/ #include #define RATPOINTS_MAX_DEGREE 100 /* max. degree of f(x) */ #define RATPOINTS_ARRAY_SIZE 256 /* Array size in longs */ #define RATPOINTS_DEFAULT_SP1 9 /* Default value for sp1 */ #define RATPOINTS_DEFAULT_SP2 16 /* Default value for sp2 */ #define RATPOINTS_DEFAULT_NUM_PRIMES 28 /* Default value for num_primes */ #define RATPOINTS_DEFAULT_STURM 10 /* Default value for sturm_iter */ #define RATPOINTS_DEFAULT_MAX_FORBIDDEN 30 /* Default value for max_forbidden */ typedef struct {double low; double up;} ratpoints_interval; 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; long array_size; long sturm; long num_primes; long max_forbidden; unsigned int flags; /* from here: private data */ mpz_t *work; long work_length; void *se_buffer; void *se_next; void *ba_buffer; void *ba_next; int *int_buffer; int *int_next; void *sieve_list; void *den_info; void *divisors; void *forb_ba; void *forbidden; } ratpoints_args; /* Define the flag bits for the flags component: */ #define RATPOINTS_NO_CHECK (unsigned int)0x0001 #define RATPOINTS_NO_Y (unsigned int)0x0002 #define RATPOINTS_NO_REVERSE (unsigned int)0x0004 #define RATPOINTS_NO_JACOBI (unsigned int)0x0008 #define RATPOINTS_VERBOSE (unsigned int)0x0010 #define RATPOINTS_FLAGS_INPUT_MASK \ (RATPOINTS_NO_CHECK | RATPOINTS_NO_Y | RATPOINTS_NO_REVERSE | \ RATPOINTS_NO_JACOBI | RATPOINTS_VERBOSE) /* Flags bits for internal purposes */ #define RATPOINTS_REVERSED (unsigned int)0x0100 #define RATPOINTS_CHECK_DENOM (unsigned int)0x0200 #define RATPOINTS_USE_SQUARES (unsigned int)0x0400 #define RATPOINTS_USE_SQUARES1 (unsigned int)0x0800 #define RATPOINTS_COMPUTE_BC (unsigned int)0x2000 /* Return values of find_points() */ #define RATPOINTS_NON_SQUAREFREE (-1) #define RATPOINTS_BAD_ARGS (-2) #define RATPOINTS_WORK_LENGTH_TOO_SMALL (-3) long find_points(ratpoints_args*, int proc(long, long, const mpz_t, void*, int*), void*); void find_points_init(ratpoints_args*); long find_points_work(ratpoints_args*, int proc(long, long, const mpz_t, void*, int*), void*); void find_points_clear(ratpoints_args*);