poly of pow 2



-----maxima-bounces at math.utexas.edu wrote: -----

>To: maxima at math.utexas.edu
>From: Daniel Lakeland <dlakelan at street-artists.org>
>Sent by: maxima-bounces at math.utexas.edu
>Date: 11/28/2007 02:00PM
>Subject: Re: [Maxima] poly of pow 2
>

>What's wrong with it? Apparently it's useful enough that two different
>people have asked for it within a few months.

At least for polynomials in several variables, sfactor is buggy.
Here is a variant of sfactor (that is I suppose also buggy).

(%i52) nfactor(p,x) := block([n, cf, s, d],
  p : expand(p),
  n : hipow(p,x),
  (if n <= 1 then p else (
    cf : coeff(p,x,n),
    s : x,
    d : expand(cf * s^n - p),
    while hipow(d,x) > 0 do (
       d : expand(first(divide(cf * s^n - p, n * cf * s^(n-1)))),
       s : s - d),
     cf * s^n + nfactor(p - cf * s^n,x))))$

sfactor(p,x) := block([n, cf, s, d],
  p : expand(p),
  n : hipow(p,x),
  if oddp(n) or n = 0 then p else (
   cf : coeff(p,x,n),
   s : x^(n/2),
   d : expand(cf * s^2 - p),
   while hipow(d,x) > 0 do (
     d : expand(first(divide(cf * s^2 - p, 2 * cf * s))),
     s : s - d),
   cf * s^2 + sfactor(p - cf * s^2,x)))$

(%i54) p : x^4 + x^3 + x^2+x+1$

(%i55) nfactor(p,x);
(%o55) (5*(x+3/4)^2)/8+(x+1/4)^4+165/256

(%i56) sfactor(p,x);
(%o56) (x^2+x/2+3/8)^2+(5*x)/8+55/64

(%i57) p : expand((x-y)^4 + (x+6*y)^2 + 1)$

(%i58) nfactor(p,x);
(%o58) (6*y+x)^2+(x-y)^4+1

Yikes! Seems to endlessly loop....

(%i59) sfactor(p,x);

I understand what's going on, but I don't know the cure.

BW