bridge/class-master/depend/pari/src/basemath/polarit3.c
/* assuming the PRS finishes on a degree 1 polynomial C0 + C1X, with
 * "generic" degree sequence as given by dglist, set *Ci and return
 * resultant(a,b). Modular version of Collins's subresultant */
assuming the PRS finishes on a degree 1 polynomial C0 + C1X, with
"generic" degree sequence as given by dglist, set *Ci and return
resultant(a,b). Modular version of Collins's subresultant
assuming the PRS finishes on a degree 1 polynomial C0 + C1X with " generic " degree sequence as given by dglist set * Ci and return resultant ( a b ) . Modular version of Collins ' s subresultant
static ulong
Flx_resultant_all(GEN a, GEN b, long *C0, long *C1, GEN dglist, ulong p)
{
  long da,db,dc, ind;
  ulong lb, res, g = 1UL, h = 1UL, ca = 1UL, cb = 1UL;
  int s = 1;
  pari_sp av = avma;
  *C0 = 1; *C1 = 0;
  if (lgpol(a)==0 || lgpol(b)==0) return 0;
  da = degpol(a);
  db = degpol(b);
  if (db > da)
  {
    swapspec(a,b, da,db);
    if (both_odd(da,db)) s = -s;
  }
  else if (!da) return 1; 
  ind = 0;
  while (db)
  { 
    GEN c = Flx_rem(a,b, p);
    long delta = da - db;
    if (both_odd(da,db)) s = -s;
    lb = Fl_mul(b[db+2], cb, p);
    a = b; b = c; dc = degpol(c);
    ind++;
    if (dc != dglist[ind]) { avma = av; return 0; } 
    if (g == h)
    { 
      ulong cc = Fl_mul(ca, Fl_powu(Fl_div(lb,g,p), delta+1, p), p);
      ca = cb;
      cb = cc;
    }
    else
    {
      ulong cc = Fl_mul(ca, Fl_powu(lb, delta+1, p), p);
      ulong ghdelta = Fl_mul(g, Fl_powu(h, delta, p), p);
      ca = cb;
      cb = Fl_div(cc, ghdelta, p);
    }
    da = db; 
    db = dc; 
    g = lb;
    if (delta == 1)
      h = g; 
    else
      h = Fl_mul(h, Fl_powu(Fl_div(g,h,p), delta, p), p);
    if (gc_needed(av,2))
    {
      if (DEBUGMEM>1) pari_warn(warnmem,"Flx_resultant_all");
      gerepileall(av, 2, &a,&b);
    }
  }
  if (da > 1) return 0; 
  *C0 = Fl_mul(ca, a[2], p);
  *C1 = Fl_mul(ca, a[3], p);
  res = Fl_mul(cb, b[2], p);
  if (s == -1) res = p - res;
  avma = av; return res;
}
static ulong Flx_resultant_all ( GEN a , GEN b , long * C0 , long * C1 , GEN dglist , ulong p ) { long da , db , dc , ind ; ulong lb , res , g = 1UL , h = 1UL , ca = 1UL , cb = 1UL ; int s = 1 ; pari_sp av = avma ; * C0 = 1 ; * C1 = 0 ; if ( lgpol ( a ) == 0 || lgpol ( b ) == 0 ) return 0 ; da = degpol ( a ) ; db = degpol ( b ) ; if ( db > da ) { swapspec ( a , b , da , db ) ; if ( both_odd ( da , db ) ) s = - s ; } else if ( ! da ) return 1 ; ind = 0 ; while ( db ) { GEN c = Flx_rem ( a , b , p ) ; long delta = da - db ; if ( both_odd ( da , db ) ) s = - s ; lb = Fl_mul ( b [ db + 2 ] , cb , p ) ; a = b ; b = c ; dc = degpol ( c ) ; ind ++ ; if ( dc != dglist [ ind ] ) { avma = av ; return 0 ; } if ( g == h ) { ulong cc = Fl_mul ( ca , Fl_powu ( Fl_div ( lb , g , p ) , delta + 1 , p ) , p ) ; ca = cb ; cb = cc ; } else { ulong cc = Fl_mul ( ca , Fl_powu ( lb , delta + 1 , p ) , p ) ; ulong ghdelta = Fl_mul ( g , Fl_powu ( h , delta , p ) , p ) ; ca = cb ; cb = Fl_div ( cc , ghdelta , p ) ; } da = db ; db = dc ; g = lb ; if ( delta == 1 ) h = g ; else h = Fl_mul ( h , Fl_powu ( Fl_div ( g , h , p ) , delta , p ) , p ) ; if ( gc_needed ( av , 2 ) ) { if ( DEBUGMEM > 1 ) pari_warn ( warnmem , " " ) ; gerepileall ( av , 2 , & a , & b ) ; } } if ( da > 1 ) return 0 ; * C0 = Fl_mul ( ca , a [ 2 ] , p ) ; * C1 = Fl_mul ( ca , a [ 3 ] , p ) ; res = Fl_mul ( cb , b [ 2 ] , p ) ; if ( s == -1 ) res = p - res ; avma = av ; return res ; }
assuming the PRS finishes on a degree 1 polynomial C0 + C1X, with
 "generic" degree sequence as given by dglist, set *Ci and return
 resultant(a,b).
assuming the PRS finishes on a degree 1 polynomial C0 + C1X with " generic " degree sequence as given by dglist set * Ci and return resultant ( a b ) .
/* = a[2] ^ db, since 0 <= db <= da = 0 */ /* sub-resultant algo., applied to ca * a and cb * b, ca,cb scalars,
     * da = deg a, db = deg b */ /* degenerates */ /* frequent */ /* = degpol(a) */ /* = degpol(b) */ /* frequent */ /* Failure */ /* last non-constant polynomial has degree 1 */