bridge/class-master/depend/pari/src/basemath/nffactor.c
/* Select a prime ideal pr over which to factor pol.
 * Return the number of factors (or roots, according to flag fl) mod pr.
 * Set:
 *   lt: leading term of polbase (t_INT or NULL [ for 1 ])
 *   pr: a suitable maximal ideal
 *   Fa: factors found mod pr
 *   Tp: polynomial defining Fq/Fp */
Select a prime ideal pr over which to factor pol.
Return the number of factors (or roots, according to flag fl) mod pr.
Select a prime ideal pr over which to factor pol . Return the number of factors ( or roots according to flag fl ) mod pr .
static long
nf_pick_prime(GEN nf, GEN pol, long fl, GEN *lt, GEN *Tp, ulong *pp)
{
  GEN nfpol = nf_get_pol(nf), bad = mulii(nf_get_disc(nf), nf_get_index(nf));
  long nfdeg = degpol(nfpol), dpol = degpol(pol), nold = 0, fold = 1;
  long maxf = get_maxf(nfdeg), ct = get_nbprimes(nfdeg * dpol);
  ulong p;
  forprime_t S;
  pari_timer ti_pr;
  if (DEBUGLEVEL>3) timer_start(&ti_pr);
  *lt  = leading_coeff(pol); 
  if (gequal1(*lt)) *lt = NULL;
  *pp = 0;
  *Tp = NULL;
  (void)u_forprime_init(&S, 2, ULONG_MAX);
  while ((p = u_forprime_next(&S)))
  {
    GEN vT;
    long n, i, l, ok = 0;
    ulong ltp = 0;
    if (! umodiu(bad,p)) continue;
    if (*lt) { ltp = umodiu(*lt, p); if (!ltp) continue; }
    vT = get_good_factor(nfpol, p, maxf);
    if (!vT) continue;
    l = lg(vT);
    for (i = 1; i < l; i++)
    {
      pari_sp av2 = avma;
      GEN T = gel(vT,i), red = RgX_to_FlxqX(pol, T, p);
      long f = degpol(T);
      if (f == 1)
      { 
        red = FlxX_to_Flx(red);
        if (ltp) red = Flx_normalize(red, p);
        if (!Flx_is_squarefree(red, p)) { avma = av2; continue; }
        ok = 1;
        n = (fl == FACTORS)? Flx_nbfact(red,p): Flx_nbroots(red,p);
      }
      else
      {
        if (ltp) red = FlxqX_normalize(red, T, p);
        if (!FlxqX_is_squarefree(red, T, p)) { avma = av2; continue; }
        ok = 1;
        n = (fl == FACTORS)? FlxqX_nbfact(red,T,p): FlxqX_nbroots(red,T,p);
      }
      if (fl == ROOTS_SPLIT && n < dpol) return n; 
      if (n <= 1)
      {
        if (fl == FACTORS) return n; 
        if (!n) return 0; 
      }
      if (DEBUGLEVEL>3)
        err_printf("%3ld %s at prime (%ld,x^%ld+...)\n Time: %ld\n",
            n, (fl == FACTORS)? "factors": "roots", p,f, timer_delay(&ti_pr));
      if (fl == ROOTS && f==nfdeg) { *Tp = T; *pp = p; return n; }
      if (record(nold, n, fold, f)) { nold = n; fold = f; *Tp = T; *pp = p; }
      else avma = av2;
    }
    if (ok && --ct <= 0) break;
  }
  if (!nold) pari_err_OVERFLOW("nf_pick_prime [ran out of primes]");
  return nold;
}
static long nf_pick_prime ( GEN nf , GEN pol , long fl , GEN * lt , GEN * Tp , ulong * pp ) { GEN nfpol = nf_get_pol ( nf ) , bad = mulii ( nf_get_disc ( nf ) , nf_get_index ( nf ) ) ; long nfdeg = degpol ( nfpol ) , dpol = degpol ( pol ) , nold = 0 , fold = 1 ; long maxf = get_maxf ( nfdeg ) , ct = get_nbprimes ( nfdeg * dpol ) ; ulong p ; forprime_t S ; pari_timer ti_pr ; if ( DEBUGLEVEL > 3 ) timer_start ( & ti_pr ) ; * lt = leading_coeff ( pol ) ; if ( gequal1 ( * lt ) ) * lt = NULL ; * pp = 0 ; * Tp = NULL ; ( void ) u_forprime_init ( & S , 2 , ULONG_MAX ) ; while ( ( p = u_forprime_next ( & S ) ) ) { GEN vT ; long n , i , l , ok = 0 ; ulong ltp = 0 ; if ( ! umodiu ( bad , p ) ) continue ; if ( * lt ) { ltp = umodiu ( * lt , p ) ; if ( ! ltp ) continue ; } vT = get_good_factor ( nfpol , p , maxf ) ; if ( ! vT ) continue ; l = lg ( vT ) ; for ( i = 1 ; i < l ; i ++ ) { pari_sp av2 = avma ; GEN T = gel ( vT , i ) , red = RgX_to_FlxqX ( pol , T , p ) ; long f = degpol ( T ) ; if ( f == 1 ) { red = FlxX_to_Flx ( red ) ; if ( ltp ) red = Flx_normalize ( red , p ) ; if ( ! Flx_is_squarefree ( red , p ) ) { avma = av2 ; continue ; } ok = 1 ; n = ( fl == FACTORS ) ? Flx_nbfact ( red , p ) : Flx_nbroots ( red , p ) ; } else { if ( ltp ) red = FlxqX_normalize ( red , T , p ) ; if ( ! FlxqX_is_squarefree ( red , T , p ) ) { avma = av2 ; continue ; } ok = 1 ; n = ( fl == FACTORS ) ? FlxqX_nbfact ( red , T , p ) : FlxqX_nbroots ( red , T , p ) ; } if ( fl == ROOTS_SPLIT && n < dpol ) return n ; if ( n <= 1 ) { if ( fl == FACTORS ) return n ; if ( ! n ) return 0 ; } if ( DEBUGLEVEL > 3 ) err_printf ( " \n \n " , n , ( fl == FACTORS ) ? " " : " " , p , f , timer_delay ( & ti_pr ) ) ; if ( fl == ROOTS && f == nfdeg ) { * Tp = T ; * pp = p ; return n ; } if ( record ( nold , n , fold , f ) ) { nold = n ; fold = f ; * Tp = T ; * pp = p ; } else avma = av2 ; } if ( ok && -- ct <= 0 ) break ; } if ( ! nold ) pari_err_OVERFLOW ( " " ) ; return nold ; }
Select a prime ideal pr over which to factor pol.
Select a prime ideal pr over which to factor pol .
/* t_INT */ /* select pr such that pol has the smallest number of factors, ct attempts */ /* degree 1 */ /* not split */ /* irreducible */ /* no root */