ratpow: Getting the coefficients of a polynomial -- CORRECTED



(Sorry, my last email contained a version of ratpow with some blunders;
thanks to Barton for picking them up.)

I've written a little code to find the hipow/lopow and coefficients of a
polynomial represented in CRE (rat) form.

These functions' names all begin with ratp_ and operate on the *numerator* of
rational functions represented in CRE form, with CRE conventions; they
distribute over bags (lists, matrices, equations).  In all of them the
second variable is the main variable in the CRE sense.  If the input is
already in CRE form with that same main variable, they are very efficient.

Some simple examples:

    ratp_hipow( x^3-y+1, x) => 3
    ratp_hipow( x^3-y+1, y) => 1
    ratp_hipow( x^3-y+1, z) => 0

ratp_coeffs returns a list of the powers and coefficients.  The result is a
list of expressions in CRE form. (This is a change from my draft version.)

    ratp_coeffs( x^3-y+1, x) => [ [3, 1], [0, 1-y] ]
    ratp_hipow( x^3-y+1, y) => [ [1, -1], [0, x^3+1] ]
    ratp_hipow( x^3-y+1, z) => [ [0, x^3-y+1] ]

ratp_dense_coeffs returns a list of the coefficients from the highest power
down:

    ratp_dense_coeffs( x^3-y+1, x) => [1, 0, 0, 1-y ]

In CRE, 'x' and 'sqrt(x)' are considered independent kernels, so

    ratp_hipow(x^(5/2)+x^2,x) => 2
    ratp_hipow(x^(5/2)+x^2,sqrt(x)) => 5 (because x^(5/2) is handled as
(x^(1/2))^5).

Similarly, if ratfac=true, they follow the factored form, for example :

    ratfac:true$
    t1: (x+1)^3*(y-x)^2 => (y-x)^2*(x+1)^3
    showratvars(t1) => [y-x,x+1]
    rat_coeffs(t1,x+1) => [[3, (y-x)^2]]
    rat_coeffs(t1,y-x) => [[2, (x+1)^3]]

This work was suggested by the issues that Alkis Akritas had in
manipulating polynomials efficiently.  Thanks to Rich, Barton, and Rupert
for comments on an earlier version.  Naturally, I'd be interested to hear
comments and suggestions from others as well.

                -s
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ratpow.lisp
Type: application/octet-stream
Size: 3080 bytes
Desc: not available
URL: <http://www.math.utexas.edu/pipermail/maxima/attachments/20130421/7ea56af3/attachment-0001.obj>;