bridge/class-master/depend/pari/src/basemath/ifactor1.c
/* ellfacteur() tuned to be useful as a first stage before MPQS, especially for
 * large arguments, when 'insist' is false, and now also for the case when
 * 'insist' is true, vaguely following suggestions by Paul Zimmermann
 * (http://www.loria.fr/~zimmerma/records/ecmnet.html). --GN 1998Jul,Aug */
ellfacteur() tuned to be useful as a first stage before MPQS, especially for
large arguments, when 'insist' is false, and now also for the case when
'insist' is true, vaguely following suggestions by Paul Zimmermann
. --GN 1998Jul,Aug
ellfacteur () tuned to be useful as a first stage before MPQS especially for large arguments when ' insist ' is false and now also for the case when ' insist ' is true vaguely following suggestions by Paul Zimmermann . -- GN 1998Jul Aug
static GEN
ellfacteur(GEN N, int insist)
{
  const long size = expi(N) + 1;
  pari_sp av = avma;
  struct ECM E;
  long nbc, dsn, dsnmax, rep = 0;
  if (insist)
  {
    const long DSNMAX = numberof(TB1)-1;
    dsnmax = (size >> 2) - 10;
    if (dsnmax < 0) dsnmax = 0;
    else if (dsnmax > DSNMAX) dsnmax = DSNMAX;
    E.seed = 1 + (nbcmax<<7)*(size&0xffff); 
    dsn = (size >> 3) - 5;
    if (dsn < 0) dsn = 0; else if (dsn > 47) dsn = 47;
    nbc = dsn + (dsn >> 2) + 9; 
    nbc &= ~3; 
  }
  else
  {
    dsn = (size - 140) >> 3;
    if (dsn < 0)
    {
#ifndef __EMX__ 
      if (DEBUGLEVEL >= 4)
        err_printf("ECM: number too small to justify this stage\n");
      return NULL; 
#endif
      dsn = 0;
    } else if (dsn > 12) dsn = 12;
    rep = (size <= 248 ?
           (size <= 176 ? (size - 124) >> 4 : (size - 148) >> 3) :
           (size - 224) >> 1);
#ifdef __EMX__ 
    rep += 20;
#endif
    dsnmax = 72;
    E.seed = 1 + (nbcmax<<3)*(size & 0xf);
    nbc = -1;
  }
  ECM_init(&E, N, nbc);
  if (DEBUGLEVEL >= 4)
  {
    timer_start(&E.T);
    err_printf("ECM: working on %ld curves at a time; initializing", E.nbc);
    if (!insist)
    {
      if (rep == 1) err_printf(" for one round");
      else          err_printf(" for up to %ld rounds", rep);
    }
    err_printf("...\n");
  }
  if (dsn > dsnmax) dsn = dsnmax;
  for(;;)
  {
    ulong B1 = insist? TB1[dsn]: TB1_for_stage[dsn];
    GEN g = ECM_loop(&E, N, B1);
    if (g)
    {
      if (DEBUGLEVEL >= 4)
        err_printf("ECM: time = %6ld ms\n\tfound factor = %Ps\n",
                   timer_delay(&E.T), g);
      return gerepilecopy(av, g);
    }
    if (dsn < dsnmax)
    {
      if (insist) dsn++;
      else { dsn += 2; if (dsn > dsnmax) dsn = dsnmax; }
    }
    if (!insist && !--rep)
    {
      if (DEBUGLEVEL >= 4)
        err_printf("ECM: time = %6ld ms,\tellfacteur giving up.\n",
                   timer_delay(&E.T));
      avma = av; return NULL;
    }
  }
}
static GEN ellfacteur ( GEN N , int insist ) { const long size = expi ( N ) + 1 ; pari_sp av = avma ; struct ECM E ; long nbc , dsn , dsnmax , rep = 0 ; if ( insist ) { const long DSNMAX = numberof ( TB1 ) - 1 ; dsnmax = ( size >> 2 ) - 10 ; if ( dsnmax < 0 ) dsnmax = 0 ; else if ( dsnmax > DSNMAX ) dsnmax = DSNMAX ; E . seed = 1 + ( nbcmax << 7 ) * ( size & 0xffff ) ; dsn = ( size >> 3 ) - 5 ; if ( dsn < 0 ) dsn = 0 ; else if ( dsn > 47 ) dsn = 47 ; nbc = dsn + ( dsn >> 2 ) + 9 ; nbc &= ~ 3 ; } else { dsn = ( size - 140 ) >> 3 ; if ( dsn < 0 ) { #ifndef __EMX__ if ( DEBUGLEVEL >= 4 ) err_printf ( " \n " ) ; return NULL ; #endif dsn = 0 ; } else if ( dsn > 12 ) dsn = 12 ; rep = ( size <= 248 ? ( size <= 176 ? ( size - 124 ) >> 4 : ( size - 148 ) >> 3 ) : ( size - 224 ) >> 1 ) ; #ifdef __EMX__ rep += 20 ; #endif dsnmax = 72 ; E . seed = 1 + ( nbcmax << 3 ) * ( size & 0xf ) ; nbc = -1 ; } ECM_init ( & E , N , nbc ) ; if ( DEBUGLEVEL >= 4 ) { timer_start ( & E . T ) ; err_printf ( " " , E . nbc ) ; if ( ! insist ) { if ( rep == 1 ) err_printf ( " " ) ; else err_printf ( " " , rep ) ; } err_printf ( " \n " ) ; } if ( dsn > dsnmax ) dsn = dsnmax ; for ( ; ; ) { ulong B1 = insist ? TB1 [ dsn ] : TB1_for_stage [ dsn ] ; GEN g = ECM_loop ( & E , N , B1 ) ; if ( g ) { if ( DEBUGLEVEL >= 4 ) err_printf ( " \n \t \n " , timer_delay ( & E . T ) , g ) ; return gerepilecopy ( av , g ) ; } if ( dsn < dsnmax ) { if ( insist ) dsn ++ ; else { dsn += 2 ; if ( dsn > dsnmax ) dsn = dsnmax ; } } if ( ! insist && ! -- rep ) { if ( DEBUGLEVEL >= 4 ) err_printf ( " \t \n " , timer_delay ( & E . T ) ) ; avma = av ; return NULL ; } } }
ellfacteur() tuned to be useful as a first stage before MPQS, especially for
 large arguments, when 'insist' is false, and now also for the case when
 'insist' is true, vaguely following suggestions by Paul Zimmermann
 (http://www.loria.fr/~zimmerma/records/ecmnet.html).
ellfacteur () tuned to be useful as a first stage before MPQS especially for large arguments when ' insist ' is false and now also for the case when ' insist ' is true vaguely following suggestions by Paul Zimmermann ( http : // www . loria . fr / ~zimmerma / records / ecmnet . html ) .
/* seed for choice of curves */ /* pick up the torch where non-insistent stage would have given up */ /* 8 or more curves in parallel */ /* 4 | nbc */ /* unless DOS/EMX: MPQS's disk access is abysmally slow */ /* too small, decline the task */ /* DOS/EMX: extra rounds (shun MPQS) */ /* Use disjoint sets of curves for non-insist and insist phases; moreover,
     * repeated calls acting on factors of the same original number should try
     * to use fresh curves. The following achieves this */