bridge/class-master/depend/pari/src/modules/algebras.c
/* Assumes pol has coefficients in the same ring as the COL x; x either
 * in basis or algebraic form or [x,mx] where mx is the mult. table of x.
 TODO more general version: pol with coeffs in center and x in basis form */
Assumes pol has coefficients in the same ring as the COL x; x either
in basis or algebraic form or [x,mx] where mx is the mult. table of x.
TODO more general version: pol with coeffs in center and x in basis form
Assumes pol has coefficients in the same ring as the COL x ; x either in basis or algebraic form or [ x mx ] where mx is the mult . table of x . TODO more general version : pol with coeffs in center and x in basis form
GEN
algpoleval(GEN al, GEN pol, GEN x)
{
  pari_sp av = avma;
  GEN p, mx = NULL, res;
  long i;
  checkalg(al);
  p = alg_get_char(al);
  if (typ(pol) != t_POL) pari_err_TYPE("algpoleval", pol);
  if (typ(x) == t_VEC)
  {
    if (lg(x) != 3) pari_err_TYPE("algpoleval [vector must be of length 2]", x);
    mx = gel(x,2);
    x = gel(x,1);
    if (typ(mx)!=t_MAT || !gequal(x,gel(mx,1)))
      pari_err_TYPE("algpoleval [mx must be the multiplication table of x]", mx);
  }
  else
  {
    switch(alg_model(al,x))
    {
      case al_ALGEBRAIC: mx = algalgmultable(al,x); break;
      case al_BASIS: if (!RgX_is_QX(pol))
        pari_err_IMPL("algpoleval with x in basis form and pol not in Q[x]");
      case al_TRIVIAL: mx = algbasismultable(al,x); break;
      default: pari_err_TYPE("algpoleval", x);
    }
  }
  res = zerocol(lg(mx)-1);
  if (signe(p)) {
    for (i=lg(pol)-1; i>1; i--)
    {
      gel(res,1) = Fp_add(gel(res,1), gel(pol,i), p);
      if (i>2) res = FpM_FpC_mul(mx, res, p);
    }
  }
  else {
    for (i=lg(pol)-1; i>1; i--)
    {
      gel(res,1) = gadd(gel(res,1), gel(pol,i));
      if (i>2) res = RgM_RgC_mul(mx, res);
    }
  }
  return gerepileupto(av, res);
}
GEN algpoleval ( GEN al , GEN pol , GEN x ) { pari_sp av = avma ; GEN p , mx = NULL , res ; long i ; checkalg ( al ) ; p = alg_get_char ( al ) ; if ( typ ( pol ) != t_POL ) pari_err_TYPE ( " " , pol ) ; if ( typ ( x ) == t_VEC ) { if ( lg ( x ) != 3 ) pari_err_TYPE ( " " , x ) ; mx = gel ( x , 2 ) ; x = gel ( x , 1 ) ; if ( typ ( mx ) != t_MAT || ! gequal ( x , gel ( mx , 1 ) ) ) pari_err_TYPE ( " " , mx ) ; } else { switch ( alg_model ( al , x ) ) { case al_ALGEBRAIC : mx = algalgmultable ( al , x ) ; break ; case al_BASIS : if ( ! RgX_is_QX ( pol ) ) pari_err_IMPL ( " " ) ; case al_TRIVIAL : mx = algbasismultable ( al , x ) ; break ; default : pari_err_TYPE ( " " , x ) ; } } res = zerocol ( lg ( mx ) - 1 ) ; if ( signe ( p ) ) { for ( i = lg ( pol ) - 1 ; i > 1 ; i -- ) { gel ( res , 1 ) = Fp_add ( gel ( res , 1 ) , gel ( pol , i ) , p ) ; if ( i > 2 ) res = FpM_FpC_mul ( mx , res , p ) ; } } else { for ( i = lg ( pol ) - 1 ; i > 1 ; i -- ) { gel ( res , 1 ) = gadd ( gel ( res , 1 ) , gel ( pol , i ) ) ; if ( i > 2 ) res = RgM_RgC_mul ( mx , res ) ; } } return gerepileupto ( av , res ) ; }
Assumes pol has coefficients in the same ring as the COL x; x either
 in basis or algebraic form or [x,mx] where mx is the mult.
Assumes pol has coefficients in the same ring as the COL x ; x either in basis or algebraic form or [ x mx ] where mx is the mult .