Getting the coefficients of a polynomial



On Tue, Apr 16, 2013 at 7:25 PM, Richard Fateman
<fateman at eecs.berkeley.edu>wrote:

>
>  I can loop like this:
>
>       coefs(p,v):=block([l:[]],while p # 0 do
> (l:cons(r:ratcoef(p,v,0),l),p:(p-r)/v),l)
>
>
> better would be somegthing like this  (no division, no re-ratting.)
>
>    coefs(p,v) := (p:rat(p,v), block([l:[]], while p#0 for i:hipow(p,v)
> step -1 thru 0 do(  l:cons(r:ratcoef(p,v,i),  p:p-r*v^i))  , l));
>

Well, if you're going to do the (grossly inefficient) hipow, then you
don't need the p:p-r*v^i at all -- you can just pick off the ratcoefs
directly.  And of course you don't re-rat each time -- I was assuming poly:
rat(input_poly,x)$

I agree about something like

      rat_hipow(p,x):=    ?cadadr(rat(p,x))

(with a bit of care for the edge and error cases).  My question was
whether there already existed something like that or close to it.

                  -s