Re: [math-fun] Maxima help: polynomial manipulation
MRob>I think a few people here are familiar with Maxima. I'd also be perfectly happy with a solution in PARI or in Sage, if that turns out to be a better way of doing this. I've built up a sum like this: 1.2345/(x+1) + 2.3456/(x+2) + 3.4567/(x+3); (I won't show the output, since the alignment is funny, and if there's a way to turn off Maxima's ASCII pretty-printing please tell me) Then I want to "ratsimp" it, to get a ratio of polynomials. If I do this, Maxima gives me: (35184 x^2 + 129625 x + 106786) / (5000 x^3 + 30000 x^2 + 55000 x + 30000) The problem with this is that the imprecise numbers have all been made into integers, and the coefficients in the denominator are huge. What I really want is this: (7.0368 x^2 + 25.925 x + 21.3572) / (x^3 + 6 x^2 + 11 x + 6) I'm trying to prevent the automatic conversion from floats to rational fractions, so as to keep the coefficients in the denominator small. The "ratepsilon" and "bftorat" flags don't seem to help. ----- In Macsyma, block([fancy_display:false],playback(10))$ 3.4567 2.3456 1.2345 (d26) ------ + ------ + ------ x + 3 x + 2 x + 1 (c27) XTHRU(%); (d27) (x + 3) (1.2345 (x + 2) + 2.3456 (x + 1)) + 3.4567 (x + 1) (x + 2) ------------------------------------------------------------------ (x + 1) (x + 2) (x + 3) (c28) MAP(EXPAND,%); 2 7.0368 x + 25.925 x + 21.3572 (d28) ------------------------------ 3 2 x + 6 x + 11 x + 6 (c29) COMBINE(EXPAND(D27)); 2 7.0368 x + 25.925 x + 21.3572 (d29) ------------------------------ 3 2 x + 6 x + 11 x + 6 (c31) BLOCK([KEEPFLOAT : TRUE],RATSIMP(D26)); 2 7.0368 x + 25.925 x + 21.3572 (d31) ------------------------------ 3 2 x + 6 x + 11 x + 6 In 2.4, you can paste a displayed expression into an input section and it will become inputform, modulo a few bugs. Also, string(d26) gives "3.4567/(X+3)+2.3456/(X+2)+1.2345/(X+1)" --rwg PS, you undermoused: 77451915729367 should be 777451915729367 in MRob> This reminds me of something Neil Sloane mentions in his OEIS talks, namely that the function f(n) = floor(2n/log(2)) has the same value as the function g(n) = ceiling(2/(2^(1/n)-1)) (Sloane's sequence A78608) for all integer n from 1 to 77451915729367, but differs at n=77451915729368 (and at some other larger values, seeoeis.org/A129935).
Here's how. display2d:false$ keepfloat:true$ rat(1.2345/(x+1) + 2.3456/(x+2) + 3.4567/(x+3)); answer is (%o28) (7.0368*x^2+25.925*x+21.3572)/(x^3+6*x^2+11*x+6) RJF
participants (2)
-
Bill Gosper -
Richard Fateman