[BACK]Return to mpqs.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / pari-2.2 / src / modules

Diff for /OpenXM_contrib/pari-2.2/src/modules/Attic/mpqs.c between version 1.1 and 1.2

version 1.1, 2001/10/02 11:17:11 version 1.2, 2002/09/11 07:27:05
Line 132  mpqs_sort_lp_file(char *filename)
Line 132  mpqs_sort_lp_file(char *filename)
   char *old_s, **sort_table = (char**)avma, *buf, *cur_line;    char *old_s, **sort_table = (char**)avma, *buf, *cur_line;
   static char **buflist_head = NULL;    static char **buflist_head = NULL;
   char **buflist, **next_buflist;    char **buflist, **next_buflist;
   long i, j, bufspace, length, count, av=avma;    long i, j, bufspace, length, count;
     gpmem_t av=avma;
   
   if (!buflist_head)    if (!buflist_head)
   {    {
Line 183  mpqs_sort_lp_file(char *filename)
Line 184  mpqs_sort_lp_file(char *filename)
     /* sort_table is allocated on the stack, 0x100 cells at a time. Hence the      /* sort_table is allocated on the stack, 0x100 cells at a time. Hence the
      * stack must be left alone in the rest of the loop to keep the array       * stack must be left alone in the rest of the loop to keep the array
      * connected. In particular, buffers can't be new_chunk'ed --KB */       * connected. In particular, buffers can't be new_chunk'ed --KB */
     if ((i & 0xff) == 0) new_chunk(0x100);      if ((i & 0xff) == 0) (void)new_chunk(0x100);
     *sort_table = cur_line;      *sort_table = cur_line;
     cur_line += length;      cur_line += length;
   
Line 652  static byteptr
Line 653  static byteptr
 mpqs_iterate_primes(long *p, byteptr primes_ptr)  mpqs_iterate_primes(long *p, byteptr primes_ptr)
 {  {
   long prime = *p;    long prime = *p;
   if (*primes_ptr)    if (*primes_ptr) {
     prime += *primes_ptr++;      NEXT_PRIME_VIADIFF(prime,primes_ptr)
     }
   else    else
   {    {
     long av = avma;      gpmem_t av = avma;
     prime = itos(nextprime(stoi(prime + 1)));      prime = itos(nextprime(stoi(prime + 1)));
     avma = av;      avma = av;
   }    }
Line 677  mpqs_find_k(GEN N, long tries)
Line 679  mpqs_find_k(GEN N, long tries)
                                55,57,59,61,65,67,69,71,73,79,83,                                 55,57,59,61,65,67,69,71,73,79,83,
                                85,89,91,93,95,97,101,103,105,107,                                 85,89,91,93,95,97,101,103,105,107,
                                109,113,127,131,137,139};                                 109,113,127,131,137,139};
   long av = avma;    gpmem_t av = avma;
   long best_k = 1, k, p, N_mod_4 = smodis(N, 4), x;    long best_k = 1, k, p, N_mod_4 = smodis(N, 4), x;
   GEN kN;    GEN kN;
   double best_value = 1, value, dp;    double best_value = 1, value, dp;
Line 745  mpqs_find_maxprime(long size)
Line 747  mpqs_find_maxprime(long size)
  **/   **/
   
 static long  static long
 mpqs_count_primes()  mpqs_count_primes(void)
 {  {
   byteptr p = mpqs_diffptr;    byteptr p = mpqs_diffptr;
     long gaps = 0;
   
   for ( ; *p; p++) /* empty */;    for ( ; *p; p++)
   return (p - mpqs_diffptr);        if (*p == DIFFPTR_SKIP)
             gaps++;
     return (p - mpqs_diffptr - gaps);
 }  }
   
 /**  /**
Line 1126  mpqs_self_init(GEN A, GEN B, GEN N, GEN kN, long *FB, 
Line 1131  mpqs_self_init(GEN A, GEN B, GEN N, GEN kN, long *FB, 
                long start_index_FB_for_A, long *inv_A2, GEN inv_A4,                 long start_index_FB_for_A, long *inv_A2, GEN inv_A4,
                ulong *bin_index, GEN *f)                 ulong *bin_index, GEN *f)
 {  {
   long av;    gpmem_t av;
   GEN p1, p2;    GEN p1, p2;
   ulong size_of_FB, nu_2;    ulong size_of_FB, nu_2;
   long i, j, p, M_mod_p, tmp, tmp1, tmp2;    long i, j, p, M_mod_p, tmp, tmp1, tmp2;
Line 1593  mpqs_eval_candidates(GEN A, GEN inv_A4, GEN B, GEN kN,
Line 1598  mpqs_eval_candidates(GEN A, GEN inv_A4, GEN B, GEN kN,
 {  {
   GEN Qx, A_2x_plus_B, Y, Qx_div_p;    GEN Qx, A_2x_plus_B, Y, Qx_div_p;
   double a, b, inv_2_a;    double a, b, inv_2_a;
   long av, powers_of_2, p, tmp_p, remd_p, bi;    long powers_of_2, p, tmp_p, remd_p, bi;
     gpmem_t av;
   long z1, z2, x, number_of_relations, x_minus_M;    long z1, z2, x, number_of_relations, x_minus_M;
   char *relations;    char *relations;
   ulong i, pi, ei, size_of_FB;    ulong i, pi, ei, size_of_FB;
Line 1665  mpqs_eval_candidates(GEN A, GEN inv_A4, GEN B, GEN kN,
Line 1671  mpqs_eval_candidates(GEN A, GEN inv_A4, GEN B, GEN kN,
        debugging... --GN */         debugging... --GN */
 #ifdef MPQS_DEBUG  #ifdef MPQS_DEBUG
     {      {
       long av1 = avma, ks;        long ks;
         gpmem_t av1 = avma;
       GEN g = mppgcd(Qx, kN);        GEN g = mppgcd(Qx, kN);
 /*      if ((ks = kronecker(divii(Qx, g), divii(kN, g))) != 1) */  /*      if ((ks = kronecker(divii(Qx, g), divii(kN, g))) != 1) */
       if (is_pm1(g))        if (is_pm1(g))
Line 1794  mpqs_eval_candidates(GEN A, GEN inv_A4, GEN B, GEN kN,
Line 1801  mpqs_eval_candidates(GEN A, GEN inv_A4, GEN B, GEN kN,
         GEN Qx_2, prod_pi_ei, pi_ei;          GEN Qx_2, prod_pi_ei, pi_ei;
         long lr = strlen(relations);          long lr = strlen(relations);
         char *s, *t = gpmalloc(lr+1);          char *s, *t = gpmalloc(lr+1);
         long pi, ei, av1 = avma;          long pi, ei;
           gpmem_t av1 = avma;
   
 #ifdef MPQS_DEBUG_VERBOSE  #ifdef MPQS_DEBUG_VERBOSE
         fprintferr("\b(");          fprintferr("\b(");
Line 1856  mpqs_eval_candidates(GEN A, GEN inv_A4, GEN B, GEN kN,
Line 1864  mpqs_eval_candidates(GEN A, GEN inv_A4, GEN B, GEN kN,
         GEN Qx_2, prod_pi_ei, pi_ei;          GEN Qx_2, prod_pi_ei, pi_ei;
         long lr = strlen(relations);          long lr = strlen(relations);
         char *s, *t = gpmalloc(lr+1);          char *s, *t = gpmalloc(lr+1);
         long pi, ei, av1 = avma;          long pi, ei;
           gpmem_t av1 = avma;
   
 #ifdef MPQS_DEBUG_VERBOSE  #ifdef MPQS_DEBUG_VERBOSE
         fprintferr("\b(");          fprintferr("\b(");
Line 1983  mpqs_combine_large_primes(FILE *COMB, FILE *FNEW, long
Line 1992  mpqs_combine_large_primes(FILE *COMB, FILE *FNEW, long
   long old_q;    long old_q;
   GEN inv_q, Y1, Y2, new_Y, new_Y1;    GEN inv_q, Y1, Y2, new_Y, new_Y1;
   long i, l, c = 0;    long i, l, c = 0;
   long av = avma, av2;    gpmem_t av = avma, av2;
   
   *f = NULL;    *f = NULL;
   if (fgets(buf, MPQS_STRING_LENGTH, COMB) == NULL)    if (fgets(buf, MPQS_STRING_LENGTH, COMB) == NULL)
Line 2101  mpqs_combine_large_primes(FILE *COMB, FILE *FNEW, long
Line 2110  mpqs_combine_large_primes(FILE *COMB, FILE *FNEW, long
       char ejk [MPQS_STRING_LENGTH];        char ejk [MPQS_STRING_LENGTH];
       GEN Qx_2, prod_pi_ei, pi_ei;        GEN Qx_2, prod_pi_ei, pi_ei;
       char *s;        char *s;
       long pi, exi, av1 = avma;        long pi, exi;
         gpmem_t av1 = avma;
       Qx_2 = modii(sqri(new_Y), kN);        Qx_2 = modii(sqri(new_Y), kN);
   
       strcpy(ejk, new_relation);        strcpy(ejk, new_relation);
Line 2426  mpqs_add_relation(GEN Y_prod, GEN N_or_kN, long *ei, c
Line 2436  mpqs_add_relation(GEN Y_prod, GEN N_or_kN, long *ei, c
   GEN Y, res;    GEN Y, res;
   char relation [MPQS_STRING_LENGTH];    char relation [MPQS_STRING_LENGTH];
   char *s;    char *s;
   long av = avma, e, p;    long e, p;
     gpmem_t av = avma;
   
   strcpy(relation, r1);    strcpy(relation, r1);
   s = strchr(relation, ':') - 1;    s = strchr(relation, ':') - 1;
Line 2461  mpqs_get_relation(long pos, FILE *FREL)
Line 2472  mpqs_get_relation(long pos, FILE *FREL)
 }  }
   
 /* the following two reside in src/basemath/ifactor1.c */  /* the following two reside in src/basemath/ifactor1.c */
 long is_odd_power(GEN x, GEN *pt, long *mask);  extern long is_odd_power(GEN x, GEN *pt, long *mask);
 int miller(GEN n, long k);  extern int miller(GEN n, long k);
   
 #define isprobableprime(n) (miller((n),17))  #define isprobableprime(n) (miller((n),17))
   
Line 2472  mpqs_solve_linear_system(GEN kN, GEN N, long rel, long
Line 2483  mpqs_solve_linear_system(GEN kN, GEN N, long rel, long
   pariFILE *pFREL;    pariFILE *pFREL;
   FILE *FREL;    FILE *FREL;
   GEN X, Y_prod, N_or_kN, D1, base, res, new_res;    GEN X, Y_prod, N_or_kN, D1, base, res, new_res;
   long av=avma, av2, av3, lim, lim3, tetpil;    gpmem_t av=avma, av2, av3, lim, lim3, tetpil;
   long *fpos, *ei;    long *fpos, *ei;
   long i, j, H_cols, H_rows;    long i, j, H_cols, H_rows;
   long res_last, res_next, res_size, res_max;    long res_last, res_next, res_size, res_max;
Line 2954  mpqs(GEN N)
Line 2965  mpqs(GEN N)
   long vain_iterations = 0;    long vain_iterations = 0;
   long good_iterations = 0;    long good_iterations = 0;
   long iterations = 0;    long iterations = 0;
   long av = avma;    gpmem_t av = avma;
   
   /* state flags for cleanup if we get interrupted --GN */    /* state flags for cleanup if we get interrupted --GN */
   static char all_clean = 1;    /* set to 0 while mpqs() is busy */    static char all_clean = 1;    /* set to 0 while mpqs() is busy */
Line 3093  mpqs(GEN N)
Line 3104  mpqs(GEN N)
   
   for (i = 2; (ulong)i < size_of_FB + 2; i++)    for (i = 2; (ulong)i < size_of_FB + 2; i++)
   {    {
     long av1 = avma;      gpmem_t av1 = avma;
     p = FB[i];      p = FB[i];
   
     /* compute the approximations of the logarithms of p_i */      /* compute the approximations of the logarithms of p_i */
Line 3364  mpqs(GEN N)
Line 3375  mpqs(GEN N)
     }      }
     /* sort LPNEW and merge it into LPREL, diverting combinables into COMB */      /* sort LPNEW and merge it into LPREL, diverting combinables into COMB */
     pari_fclose(pLPNEW);      pari_fclose(pLPNEW);
     mpqs_sort_lp_file(LPNEW_str);      (void)mpqs_sort_lp_file(LPNEW_str);
     tp = mpqs_mergesort_lp_file(LPREL_str, LPNEW_str, 0);      tp = mpqs_mergesort_lp_file(LPREL_str, LPNEW_str, 0);
     pLPNEW = pari_fopen(LPNEW_str, WRITE); /* NOT safefopen */      pLPNEW = pari_fopen(LPNEW_str, WRITE); /* NOT safefopen */
     LPNEW = pLPNEW->file;      LPNEW = pLPNEW->file;
Line 3406  mpqs(GEN N)
Line 3417  mpqs(GEN N)
   
     /* sort FNEW and merge it into FREL */      /* sort FNEW and merge it into FREL */
     pari_fclose(pFNEW);      pari_fclose(pFNEW);
     mpqs_sort_lp_file(FNEW_str);      (void)mpqs_sort_lp_file(FNEW_str);
     total_full_relations = mpqs_mergesort_lp_file(FREL_str, FNEW_str, 1);      total_full_relations = mpqs_mergesort_lp_file(FREL_str, FNEW_str, 1);
     /* this being the definitive count (combinables combined, and      /* this being the definitive count (combinables combined, and
        duplicates removed) */         duplicates removed) */

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>