bridge/class-master/depend/pari/src/basemath/polarit2.c
/* x, y are t_POL in the same variable */
x, y are t_POL in the same variable
x y are t_POL in the same variable
GEN
RgX_gcd(GEN x, GEN y)
{
  long dx, dy;
  pari_sp av, av1;
  GEN d, g, h, p1, p2, u, v;
  int simple = 0, rational = 1;
  if (isexactzero(y)) return RgX_copy(x);
  if (isexactzero(x)) return RgX_copy(y);
  if (RgX_is_monomial(x)) return gcdmonome(x,y);
  if (RgX_is_monomial(y)) return gcdmonome(y,x);
  if (isinexactall(x,&simple,&rational) || isinexactall(y,&simple,&rational))
  {
    av = avma; u = ggcd(content(x), content(y));
    return gerepileupto(av, scalarpol(u, varn(x)));
  }
  if (rational) return QX_gcd(x,y); 
  av = avma;
  if (simple > 0) x = RgX_gcd_simple(x,y);
  else
  {
    dx = lg(x); dy = lg(y);
    if (dx < dy) { swap(x,y); lswap(dx,dy); }
    if (dy==3)
    {
      d = ggcd(gel(y,2), content(x));
      return gerepileupto(av, scalarpol(d, varn(x)));
    }
    u = primitive_part(x, &p1); if (!p1) p1 = gen_1;
    v = primitive_part(y, &p2); if (!p2) p2 = gen_1;
    d = ggcd(p1,p2);
    av1 = avma;
    g = h = gen_1;
    for(;;)
    {
      GEN r = RgX_pseudorem(u,v);
      long degq, du, dv, dr = lg(r);
      if (!signe(r)) break;
      if (dr <= 3)
      {
        avma = av1; return gerepileupto(av, scalarpol(d, varn(x)));
      }
      if (DEBUGLEVEL > 9) err_printf("RgX_gcd: dr = %ld\n", degpol(r));
      du = lg(u); dv = lg(v); degq = du-dv;
      u = v; p1 = g; g = leading_coeff(u);
      switch(degq)
      {
        case 0: break;
        case 1:
          p1 = gmul(h,p1); h = g; break;
        default:
          p1 = gmul(gpowgs(h,degq), p1);
          h = gdiv(gpowgs(g,degq), gpowgs(h,degq-1));
      }
      v = RgX_Rg_div(r,p1);
      if (gc_needed(av1,1))
      {
        if(DEBUGMEM>1) pari_warn(warnmem,"RgX_gcd");
        gerepileall(av1,4, &u,&v,&g,&h);
      }
    }
    x = RgX_Rg_mul(primpart(v), d);
  }
  if (must_negate(x)) x = RgX_neg(x);
  return gerepileupto(av,x);
}
GEN RgX_gcd ( GEN x , GEN y ) { long dx , dy ; pari_sp av , av1 ; GEN d , g , h , p1 , p2 , u , v ; int simple = 0 , rational = 1 ; if ( isexactzero ( y ) ) return RgX_copy ( x ) ; if ( isexactzero ( x ) ) return RgX_copy ( y ) ; if ( RgX_is_monomial ( x ) ) return gcdmonome ( x , y ) ; if ( RgX_is_monomial ( y ) ) return gcdmonome ( y , x ) ; if ( isinexactall ( x , & simple , & rational ) || isinexactall ( y , & simple , & rational ) ) { av = avma ; u = ggcd ( content ( x ) , content ( y ) ) ; return gerepileupto ( av , scalarpol ( u , varn ( x ) ) ) ; } if ( rational ) return QX_gcd ( x , y ) ; av = avma ; if ( simple > 0 ) x = RgX_gcd_simple ( x , y ) ; else { dx = lg ( x ) ; dy = lg ( y ) ; if ( dx < dy ) { swap ( x , y ) ; lswap ( dx , dy ) ; } if ( dy == 3 ) { d = ggcd ( gel ( y , 2 ) , content ( x ) ) ; return gerepileupto ( av , scalarpol ( d , varn ( x ) ) ) ; } u = primitive_part ( x , & p1 ) ; if ( ! p1 ) p1 = gen_1 ; v = primitive_part ( y , & p2 ) ; if ( ! p2 ) p2 = gen_1 ; d = ggcd ( p1 , p2 ) ; av1 = avma ; g = h = gen_1 ; for ( ; ; ) { GEN r = RgX_pseudorem ( u , v ) ; long degq , du , dv , dr = lg ( r ) ; if ( ! signe ( r ) ) break ; if ( dr <= 3 ) { avma = av1 ; return gerepileupto ( av , scalarpol ( d , varn ( x ) ) ) ; } if ( DEBUGLEVEL > 9 ) err_printf ( " \n " , degpol ( r ) ) ; du = lg ( u ) ; dv = lg ( v ) ; degq = du - dv ; u = v ; p1 = g ; g = leading_coeff ( u ) ; switch ( degq ) { case 0 : break ; case 1 : p1 = gmul ( h , p1 ) ; h = g ; break ; default : p1 = gmul ( gpowgs ( h , degq ) , p1 ) ; h = gdiv ( gpowgs ( g , degq ) , gpowgs ( h , degq - 1 ) ) ; } v = RgX_Rg_div ( r , p1 ) ; if ( gc_needed ( av1 , 1 ) ) { if ( DEBUGMEM > 1 ) pari_warn ( warnmem , " " ) ; gerepileall ( av1 , 4 , & u , & v , & g , & h ) ; } } x = RgX_Rg_mul ( primpart ( v ) , d ) ; } if ( must_negate ( x ) ) x = RgX_neg ( x ) ; return gerepileupto ( av , x ) ; }
x, y are t_POL in the same variable
x y are t_POL in the same variable
/* Q[X] */