bridge/class-master/depend/pari/src/basemath/rootpol.c
/* return 0 if fails, 1 else */
return 0 if fails, 1 else
return 0 if fails 1 else
static long
refine_F(GEN p, GEN *F, GEN *G, GEN H, long bit, double gamma)
{
  GEN f0, FF, GG, r, HH = H;
  long error, i, bit1 = 0, bit2, Sbit, Sbit2,  enh, normF, normG, n = degpol(p);
  pari_sp av = avma;
  FF = *F; GG = RgX_divrem(p, FF, &r);
  error = gexpo(r); if (error <= -bit) error = 1-bit;
  normF = gexpo(FF);
  normG = gexpo(GG);
  enh = gexpo(H); if (enh < 0) enh = 0;
  Sbit = normF + 2*normG + enh + (long)(4.*log2((double)n)+gamma) + 1;
  Sbit2 = enh + 2*(normF+normG) + (long)(2.*gamma+5.*log2((double)n)) + 1;
  bit2 = bit + Sbit;
  for (i=0; error>-bit && i<NEWTON_MAX && error<=0; i++)
  {
    if (bit1 == bit2 && i >= 2) { Sbit += n; Sbit2 += n; bit2 += n; }
    if (gc_needed(av,1))
    {
      if(DEBUGMEM>1) pari_warn(warnmem,"refine_F");
      gerepileall(av,4, &FF,&GG,&r,&HH);
    }
    bit1 = -error + Sbit2;
    HH = refine_H(mygprec(FF,bit1), mygprec(GG,bit1), mygprec(HH,bit1),
                  1-error, Sbit2);
    if (!HH) return 0; 
    bit1 = -error + Sbit;
    r = RgX_mul(mygprec(HH,bit1), mygprec(r,bit1));
    f0 = RgX_rem(mygprec(r,bit1), mygprec(FF,bit1));
    bit1 = -2*error + Sbit; if (bit1 > bit2) bit1 = bit2;
    FF = gadd(mygprec(FF,bit1),f0);
    bit1 = -3*error + Sbit; if (bit1 > bit2) bit1 = bit2;
    GG = RgX_divrem(mygprec(p,bit1), mygprec(FF,bit1), &r);
    error = gexpo(r); if (error < -bit1) error = -bit1;
  }
  if (error>-bit) return 0; 
  *F = FF; *G = GG; return 1;
}
static long refine_F ( GEN p , GEN * F , GEN * G , GEN H , long bit , double gamma ) { GEN f0 , FF , GG , r , HH = H ; long error , i , bit1 = 0 , bit2 , Sbit , Sbit2 , enh , normF , normG , n = degpol ( p ) ; pari_sp av = avma ; FF = * F ; GG = RgX_divrem ( p , FF , & r ) ; error = gexpo ( r ) ; if ( error <= - bit ) error = 1 - bit ; normF = gexpo ( FF ) ; normG = gexpo ( GG ) ; enh = gexpo ( H ) ; if ( enh < 0 ) enh = 0 ; Sbit = normF + 2 * normG + enh + ( long ) ( 4. * log2 ( ( double ) n ) + gamma ) + 1 ; Sbit2 = enh + 2 * ( normF + normG ) + ( long ) ( 2. * gamma + 5. * log2 ( ( double ) n ) ) + 1 ; bit2 = bit + Sbit ; for ( i = 0 ; error > - bit && i < NEWTON_MAX && error <= 0 ; i ++ ) { if ( bit1 == bit2 && i >= 2 ) { Sbit += n ; Sbit2 += n ; bit2 += n ; } if ( gc_needed ( av , 1 ) ) { if ( DEBUGMEM > 1 ) pari_warn ( warnmem , " " ) ; gerepileall ( av , 4 , & FF , & GG , & r , & HH ) ; } bit1 = - error + Sbit2 ; HH = refine_H ( mygprec ( FF , bit1 ) , mygprec ( GG , bit1 ) , mygprec ( HH , bit1 ) , 1 - error , Sbit2 ) ; if ( ! HH ) return 0 ; bit1 = - error + Sbit ; r = RgX_mul ( mygprec ( HH , bit1 ) , mygprec ( r , bit1 ) ) ; f0 = RgX_rem ( mygprec ( r , bit1 ) , mygprec ( FF , bit1 ) ) ; bit1 = -2 * error + Sbit ; if ( bit1 > bit2 ) bit1 = bit2 ; FF = gadd ( mygprec ( FF , bit1 ) , f0 ) ; bit1 = -3 * error + Sbit ; if ( bit1 > bit2 ) bit1 = bit2 ; GG = RgX_divrem ( mygprec ( p , bit1 ) , mygprec ( FF , bit1 ) , & r ) ; error = gexpo ( r ) ; if ( error < - bit1 ) error = - bit1 ; } if ( error > - bit ) return 0 ; * F = FF ; * G = GG ; return 1 ; }
return 0 if fails, 1 else
return 0 if fails 1 else
/* FAIL */ /* FAIL */