Thanks for the idea! That works, but is much less efficient than 'reading
off' the coefficients from the internal form of the polynomial....
On Wed, Apr 17, 2013 at 12:55 PM, Evgeniy Maevskiy <emaevskiy at e-math.ru>wrote:
> Sorry to interfere. What about this:
>
> kill(x,t,n)$
> pw(t,n):=block(
> if t=x then L:endcons(n-2,L),
> x^(n-2)
> )$
> p:3*x^2-4*x^3-5*x^11+7*x+1;
> p:subst(pw,"^",expand(x^2*p))$
> L:[]$
> ''p$
> L;
>
>
> 17.04.2013 0:40, Stavros Macrakis ?????:
>
>> How can I get the coefficients of a polynomial in x?
>>
>> Clearly I first put into into CRE form with main variable x:
>>
>> poly: rat(input_poly,x)$
>>
>> Then what? The internal form of the CRE lets you just "read off" the
>> coefficients at this point, but I can't think of any Maxima function
>> that lets you access that.
>>
>> 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)
>>
>> but that seems like an awful lot of work (/n/ polynomial divisions). It
>>
>> also isn't very efficient for sparse polynomials like x^20000. You
>> could do similar things with bothcoef or ratcoef, but again you end up
>> building /n/ intermediate polynomials as you remove terms.
>>
>> You might think you could use ratcoef for i:0../n/, but how do you
>> determine /n/? hipow is inefficient in that it converts the expression
>>
>> into general representation first (!).
>>
>> Am I missing some obvious solution, or do we need to add rat_hipow and
>> rat_coeffs or something?
>>
>> rat_hipow(x^3+a*x+1,x) => 3
>> rat_coeffs(x^3+a*x+1,x) => [[3,1],[1,a],[0,1]]
>>
>> Edge cases to think about: CREs with negative powers, cf.
>> ratcoef(1/x^3,x,-3) => 1, ratcoef(a/(b-x),x,-5) => -a*b^4, etc.
>>
>> -s
>>
>>
>>
>> ______________________________**_________________
>> Maxima mailing list
>> Maxima at math.utexas.edu
>> http://www.math.utexas.edu/**mailman/listinfo/maxima<http://www.math.utexas.edu/mailman/listinfo/maxima>
>>
>>
> ______________________________**_________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/**mailman/listinfo/maxima<http://www.math.utexas.edu/mailman/listinfo/maxima>
>