Jacques Gélinas on Sat, 16 Nov 2019 16:47:17 +0100

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: List of polynomial coefficients in GP - using gp2c

> How easy is it to modify polcoef to return a vector 
I just inserted the GP code below in a file cofs.gp and typed in a cygwin shell window
# gp2c-run cofs.gp
This generates the C code

GEN cofs(GEN p, GEN v)	  /* vec */
{  GEN p1;  GEN p2;	  /* vec */
  if (!v)    v = pol_x(fetch_user_var("x"));
 p1 = gaddsg(1, gmaxsg(0, gppoldegree(p, gvar(v))));
    long k;
    p2 = cgetg(gtos(p1)+1, t_VEC);
    for (k = 1; gcmpsg(k, p1) <= 0; ++k)
      gel(p2, k) = polcoeff0(p, k - 1, gvar(v));
  return p2;

Now I must figure out where to put the .so file and the install commands on my Windows laptop. No need to mess up the polcoef code which is working fine, but this uses another function name to remember. Note that for some reason,  cofs(z*x)[1] === 0*z, not 0.

Jacques Gélinas

/*		Vecteur des coefficients d'un polynôme de la variable v
			Jacques Gélinas, novembre 2019
cofs(p,v='x) = vector(1+max(0,poldegree(p,v)),k,polcoeff(p,k-1,v));
ckcofs() = {[
  cofs(0)===[0], cofs(0*x)===[0], cofs(0*z)===[0], cofs(0*z,z)===[0],
  cofs(1)===[1], cofs(x)===[0,1], cofs(x,x)===[0,1], cofs(z)===[z], cofs(z,z)===[0,1],
  cofs(x-z*x^2+z^2*x^3) === [z-z,z',-z,z^2],  cofs(x-z*x^2+z^2*x^3,z) === [x,-x^2,x^3],
  cofs(subst(1*u+2*P-6,u,x+3)) === [2*P-3, 1],
  cofs(subst(0*u+2*P-6,u,x+3)) === [2*P-6],