bridge/class-master/depend/pari/src/basemath/bibli2.c
/********************************************************************/
/**              CONVOLUTION PRODUCT (OF TWO SERIES)               **/
/********************************************************************/
CONVOLUTION PRODUCT (OF TWO SERIES)
CONVOLUTION PRODUCT ( OF TWO SERIES )
GEN
convol(GEN x, GEN y)
{
  long j, lx, ly, ex, ey, vx = varn(x);
  GEN z;
  if (typ(x) != t_SER) pari_err_TYPE("convol",x);
  if (typ(y) != t_SER) pari_err_TYPE("convol",y);
  if (varn(y) != vx) pari_err_VAR("convol", x,y);
  ex = valp(x);
  ey = valp(y);
  if (ser_isexactzero(x))
    return scalarser(gadd(Rg_get_0(x), Rg_get_0(y)), varn(x), maxss(ex,ey));
  lx = lg(x) + ex; x -= ex;
  ly = lg(y) + ey; y -= ey;
  if (ly < lx) lx = ly; 
  if (ex < ey) ex = ey; 
  if (lx - ex < 3) return zeroser(vx, lx-2);
  z = cgetg(lx - ex, t_SER);
  z[1] = evalvalp(ex) | evalvarn(vx);
  for (j = ex+2; j<lx; j++) gel(z,j-ex) = gmul(gel(x,j),gel(y,j));
  return normalize(z);
}
GEN convol ( GEN x , GEN y ) { long j , lx , ly , ex , ey , vx = varn ( x ) ; GEN z ; if ( typ ( x ) != t_SER ) pari_err_TYPE ( " " , x ) ; if ( typ ( y ) != t_SER ) pari_err_TYPE ( " " , y ) ; if ( varn ( y ) != vx ) pari_err_VAR ( " " , x , y ) ; ex = valp ( x ) ; ey = valp ( y ) ; if ( ser_isexactzero ( x ) ) return scalarser ( gadd ( Rg_get_0 ( x ) , Rg_get_0 ( y ) ) , varn ( x ) , maxss ( ex , ey ) ) ; lx = lg ( x ) + ex ; x -= ex ; ly = lg ( y ) + ey ; y -= ey ; if ( ly < lx ) lx = ly ; if ( ex < ey ) ex = ey ; if ( lx - ex < 3 ) return zeroser ( vx , lx - 2 ) ; z = cgetg ( lx - ex , t_SER ) ; z [ 1 ] = evalvalp ( ex ) | evalvarn ( vx ) ; for ( j = ex + 2 ; j < lx ; j ++ ) gel ( z , j - ex ) = gmul ( gel ( x , j ) , gel ( y , j ) ) ; return normalize ( z ) ; }
CONVOLUTION PRODUCT (OF TWO SERIES)
CONVOLUTION PRODUCT ( OF TWO SERIES )
/* inputs shifted: x[i] and y[i] now correspond to monomials of same degree */ /* min length */ /* max valuation */