bridge/class-master/depend/pari/src/basemath/gen1.c
/* assume x2, y2 are t_POLs in the same variable */
assume x2, y2 are t_POLs in the same variable
assume x2 y2 are t_POLs in the same variable
static GEN
add_rfrac(GEN x, GEN y)
{
  pari_sp av = avma;
  GEN x1 = gel(x,1), x2 = gel(x,2);
  GEN y1 = gel(y,1), y2 = gel(y,2), q, r, n, d, delta;
  delta = RgX_gcd(x2,y2);
  if (!degpol(delta))
  {
    n = simplify_shallow( gadd(gmul(x1,y2), gmul(y1,x2)) );
    d = RgX_mul(x2, y2);
    return gerepileupto(av, gred_rfrac_simple(n, d));
  }
  x2 = RgX_div(x2,delta);
  y2 = RgX_div(y2,delta);
  n = gadd(gmul(x1,y2), gmul(y1,x2));
  if (!signe(n))
  {
    n = simplify_shallow(n);
    if (isrationalzero(n)) return gerepileupto(av, zeropol(varn(x2)));
    return gerepilecopy(av, mkrfrac(n, RgX_mul(gel(x,2),y2)));
  }
  if (degpol(n) == 0)
    return gerepileupto(av, gred_rfrac_simple(gel(n,2), RgX_mul(gel(x,2),y2)));
  q = RgX_divrem(n, delta, &r); 
  if (isexactzero(r))
  {
    GEN z;
    d = RgX_mul(x2, y2);
    z = lg(d) == 3? RgX_Rg_div(q, gel(d,2)): gred_rfrac_simple(q, d);
    return gerepileupto(av, z);
  }
  r = RgX_gcd(delta, r);
  if (degpol(r))
  {
    n = RgX_div(n, r);
    d = RgX_mul(RgX_mul(x2,y2), RgX_div(delta, r));
  }
  else
    d = RgX_mul(gel(x,2), y2);
  return gerepileupto(av, gred_rfrac_simple(n, d));
}
static GEN add_rfrac ( GEN x , GEN y ) { pari_sp av = avma ; GEN x1 = gel ( x , 1 ) , x2 = gel ( x , 2 ) ; GEN y1 = gel ( y , 1 ) , y2 = gel ( y , 2 ) , q , r , n , d , delta ; delta = RgX_gcd ( x2 , y2 ) ; if ( ! degpol ( delta ) ) { n = simplify_shallow ( gadd ( gmul ( x1 , y2 ) , gmul ( y1 , x2 ) ) ) ; d = RgX_mul ( x2 , y2 ) ; return gerepileupto ( av , gred_rfrac_simple ( n , d ) ) ; } x2 = RgX_div ( x2 , delta ) ; y2 = RgX_div ( y2 , delta ) ; n = gadd ( gmul ( x1 , y2 ) , gmul ( y1 , x2 ) ) ; if ( ! signe ( n ) ) { n = simplify_shallow ( n ) ; if ( isrationalzero ( n ) ) return gerepileupto ( av , zeropol ( varn ( x2 ) ) ) ; return gerepilecopy ( av , mkrfrac ( n , RgX_mul ( gel ( x , 2 ) , y2 ) ) ) ; } if ( degpol ( n ) == 0 ) return gerepileupto ( av , gred_rfrac_simple ( gel ( n , 2 ) , RgX_mul ( gel ( x , 2 ) , y2 ) ) ) ; q = RgX_divrem ( n , delta , & r ) ; if ( isexactzero ( r ) ) { GEN z ; d = RgX_mul ( x2 , y2 ) ; z = lg ( d ) == 3 ? RgX_Rg_div ( q , gel ( d , 2 ) ) : gred_rfrac_simple ( q , d ) ; return gerepileupto ( av , z ) ; } r = RgX_gcd ( delta , r ) ; if ( degpol ( r ) ) { n = RgX_div ( n , r ) ; d = RgX_mul ( RgX_mul ( x2 , y2 ) , RgX_div ( delta , r ) ) ; } else d = RgX_mul ( gel ( x , 2 ) , y2 ) ; return gerepileupto ( av , gred_rfrac_simple ( n , d ) ) ; }
assume x2, y2 are t_POLs in the same variable
assume x2 y2 are t_POLs in the same variable
/* we want gcd(n,delta) */ /* "constant" denominator ? */