bridge/class-master/depend/pari/src/basemath/Flx.c
/* If resultant is 0, *ptU and *ptU are not set */
If resultant is 0, *ptU and *ptU are not set
If resultant is 0 * ptU and * ptU are not set
ulong
Flx_extresultant(GEN a, GEN b, ulong p, GEN *ptU, GEN *ptV)
{
  GEN z,q,u,v, x = a, y = b;
  ulong lb, res = 1UL;
  pari_sp av = avma;
  long dx, dy, dz;
  long vs=a[1];
  dx = degpol(x);
  dy = degpol(y);
  if (dy > dx)
  {
    swap(x,y); lswap(dx,dy); pswap(ptU, ptV);
    a = x; b = y;
    if (both_odd(dx,dy)) res = p-res;
  }
  if (dx < 0) return 0;
  u = pol0_Flx(vs);
  v = pol1_Flx(vs); 
  while (dy)
  { 
    lb = y[dy+2];
    q = Flx_divrem(x,y, p, &z);
    x = y; y = z; 
    dz = degpol(z); if (dz < 0) { avma = av; return 0; }
    z = Flx_sub(u, Flx_mul(q,v, p), p);
    u = v; v = z; 
    if (both_odd(dx,dy)) res = p - res;
    if (lb != 1) res = Fl_mul(res, Fl_powu(lb, dx-dz, p), p);
    dx = dy; 
    dy = dz; 
  }
  res = Fl_mul(res, Fl_powu(y[2], dx, p), p);
  lb = Fl_mul(res, Fl_inv(y[2],p), p);
  v = gerepileuptoleaf(av, Flx_Fl_mul(v, lb, p));
  av = avma;
  u = Flx_sub(Fl_to_Flx(res,vs), Flx_mul(b,v,p), p);
  u = gerepileuptoleaf(av, Flx_div(u,a,p)); 
  *ptU = u;
  *ptV = v; return res;
}
ulong Flx_extresultant ( GEN a , GEN b , ulong p , GEN * ptU , GEN * ptV ) { GEN z , q , u , v , x = a , y = b ; ulong lb , res = 1UL ; pari_sp av = avma ; long dx , dy , dz ; long vs = a [ 1 ] ; dx = degpol ( x ) ; dy = degpol ( y ) ; if ( dy > dx ) { swap ( x , y ) ; lswap ( dx , dy ) ; pswap ( ptU , ptV ) ; a = x ; b = y ; if ( both_odd ( dx , dy ) ) res = p - res ; } if ( dx < 0 ) return 0 ; u = pol0_Flx ( vs ) ; v = pol1_Flx ( vs ) ; while ( dy ) { lb = y [ dy + 2 ] ; q = Flx_divrem ( x , y , p , & z ) ; x = y ; y = z ; dz = degpol ( z ) ; if ( dz < 0 ) { avma = av ; return 0 ; } z = Flx_sub ( u , Flx_mul ( q , v , p ) , p ) ; u = v ; v = z ; if ( both_odd ( dx , dy ) ) res = p - res ; if ( lb != 1 ) res = Fl_mul ( res , Fl_powu ( lb , dx - dz , p ) , p ) ; dx = dy ; dy = dz ; } res = Fl_mul ( res , Fl_powu ( y [ 2 ] , dx , p ) , p ) ; lb = Fl_mul ( res , Fl_inv ( y [ 2 ] , p ) , p ) ; v = gerepileuptoleaf ( av , Flx_Fl_mul ( v , lb , p ) ) ; av = avma ; u = Flx_sub ( Fl_to_Flx ( res , vs ) , Flx_mul ( b , v , p ) , p ) ; u = gerepileuptoleaf ( av , Flx_div ( u , a , p ) ) ; * ptU = u ; * ptV = v ; return res ; }
If resultant is 0, *ptU and *ptU are not set
If resultant is 0 * ptU and * ptU are not set
/* dx <= dy */ /* v = 1 */ /* b u = x (a), b v = y (a) */ /* (x,y) = (y, x - q y) */ /* (u,v) = (v, u - q v) */ /* = degpol(x) */ /* = degpol(y) */ /* = (res - b v) / a */