On 6/30/2011 3:37 PM, drgst (at) web (dot) de wrote:
> Hi all,
>
> is there any command (flag to be used with horner()-command, e.g.) or
> other procedure (or even trick) to force Maxima not only to
> recursively extract the powers of a variable from a series, but the
> corresponding coeffients, too? I'd really appreciate a result like
> A*x*(1+B*X*(1+C*X*(1+D*X))) , e.g., instead of x*(A+x*(F+x*(G+x*H))),
> which is of the kind that horner() gives me.
You can extract all of the coefficients, A, B, C, ... of a polynomial
and do anything you wish with them.
You may find hipow and bothcoef to be useful.
> BTW: when searching the web for an answer to the question above, I
> found Mr. Fateman's remarks on numerical problems in case of
> evaluating Legendre's polynomials in Horner()-form as floats. I
> (fortunately unseccessfully, i.e., LP(20,1.0)=1.0) tried to reproduce
> Mr. Fateman's results. But indeed, I encountered numerical problems
> when "rat" was involved automatically: (wx)Maxima told me that "rat"
> had (quite pathetically!!, i.e., only to 10 significant digits or so)
> tried to rationalize floats by listing the original float together
> with the automatically derived fraction of integer numbers as well as
> the float that fraction represents.
If you believe that your floating point numbers deserve to be believed
to more digits when converting to rationals, you
can set ratepsilon to some value of your choice. It is, by default,
2.0*10^(-8).
The paper you are presumably referring to is
http://www.cs.berkeley.edu/~fateman/papers/horner.pdf
but that starts with, and mostly keeps the coefficients in exact
rational form until someone tries to do
floating point arithmetic with them.
the following expression gives an exact rational computation for
p[20](x), and given any rational
value for x will produce an exact value. So there will be no error
whatsoever. However, doing rational
arithmetic tends to be expensive. Putting in a float for x means the
arithmetic will be done in double-float.
(x^2*(x^2*(x^2*(x^2*(x^2*(x^2*
(x^2*(x^2*(x^2*(34461632205*x^2-167890003050)+347123925225)-396713057400)+273491577450)-
116454478140)+30117537450)-4461857400)+334639305)-9699690)+46189)/(262144)
I don't know if you want to convert these integers to floats; they
should all work fine in double precision.
They would not be fully accurate in 8 decimal digit representations.
Carrying the computations along in
double precision may not be adequate for all values of x, of course.
> Is it meanwhile common sense, that
> these problems described by Mr. Fateman were caused by "rat" rather
> than by "horner"?
I hope not. I redid some of the calculations and I get exactly the same
answers either way, so
I'm not sure what I did in that paper. I don't have time right now to
look at it though.
RJF
> Kind regards
> Dragan Stoikovitch
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima