# [Maxima] The factor function is a little bit silly.

J.C. Pizarro jcpiza at gmail.com
Mon Apr 7 13:11:50 CDT 2008

```On Monday 07 April 2008 10:47:39 CDT 2008, Alexey Beshenov wrote:
> On Monday 07 April 2008 15:45, J.C. Pizarro wrote:
>
> > To fix this problem in the future: better artificial sustitution in the
> > solving of factor or intelligent lazy computation as
> > factor(expand(Alpha)) => Alpha.
>
> You're passing a verb to factor(...), so it's not "silly" when Maxima
> evaluates it and does expansion of such huge polynomial.

But Maxima sometimes can't factorize some factorizable huge polynomials
that were expanded or sometimes it is trying to factorize it for excess time.

> Your rule is obviously wrong, e.g.
>
>   factor(expand((x^2+4*x+4)^3)) => (x+2)^6
>
>
>   factor(expand((f)^n)) => (factor(f))^n,

Ohh, i did make a mistake, you're OK.

Officially, i'm not a mathematic expert when i did put above.

>
> but I guess it's not very useful---why not to remove expand(...) when it's not
> needed?
>
> > factor(expand((sqrt(x+a)+b)^10));
> >
> > i got once the imprecise solution
> >
> > 10 b x^4 sqrt(x+a) + 120 b^3 x^3 sqrt(x+a) + ... + 45 a^4 b^2 + a^5
> >
> > but i got many times (sqrt(x+a)+b)^10 .
> >
> > I think that the maxima system uses memoization that remember some internal
> > answers of previous computations but it's non-deterministic.
>
> Maybe you just have removed expand(...)?
>

No, no, i didn't remove expand(...)!

I did put exactly factor(expand((sqrt(x+a)+b)^10)) and
maxima did strange computations using Haible's
common lisp when i repeated many times the same formula.

\$ maxima
Maxima 5.14.0 http://maxima.sourceforge.net
Using Lisp CLISP 2.41 (2006-10-13)
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) factor(expand(((x+a)+b)^10));
10
(%o1)                            (x + b + a)
(%i2) factor(expand((sqrt(x+a)+b)^10));
4                    3  3                       3
(%o2) 10 b x  sqrt(x + a) + 120 b  x  sqrt(x + a) + 40 a b x  sqrt(x + a)
5  2                      3  2                   2    2
+ 252 b  x  sqrt(x + a) + 360 a b  x  sqrt(x + a) + 60 a  b x  sqrt(x + a)
7                        5                      2  3
+ 120 b  x sqrt(x + a) + 504 a b  x sqrt(x + a) + 360 a  b  x sqrt(x + a)
3                       9                      7
+ 40 a  b x sqrt(x + a) + 10 b  sqrt(x + a) + 120 a b  sqrt(x + a)
2  5                    3  3                   4                  5
+ 252 a  b  sqrt(x + a) + 120 a  b  sqrt(x + a) + 10 a  b sqrt(x + a) + x
2  4        4        4  3          2  3       2  3        6  2
+ 45 b  x  + 5 a x  + 210 b  x  + 180 a b  x  + 10 a  x  + 210 b  x
4  2        2  2  2       3  2       8            6          2  4
+ 630 a b  x  + 270 a  b  x  + 10 a  x  + 45 b  x + 420 a b  x + 630 a  b  x
3  2        4      10         8        2  6        3  4       4  2    5
+ 180 a  b  x + 5 a  x + b   + 45 a b  + 210 a  b  + 210 a  b  + 45 a  b  + a
(%i2) the same above
(%o2) the same above
...
(%i9) the same above
(%o9) the same above

but if i put sqrt2 instead of sqrt then the symbolic computation is "different":

(%i10) factor(expand((sqrt2(x+a)+b)^10));
10
(%o10)                       (sqrt2(x + a) + b)

It demonstrates that there is some strange symbolic computation.

>   factor(expand((sqrt(x+a)+b)^10)) =>
>     10*b*x^4*sqrt(x+a) + 120*b^3*x^3*sqrt(x+a) + ...,
>
>   factor(sqrt(x+a)+b)^10) =>
>     sqrt(x+a)+b)^10
>
> --
> Alexey Beshenov <al at beshenov.ru>
> http://beshenov.ru/

I'm still waiting the answer of

(%i11) factor(expand((x-y-z)^1000));

and the top says ~79 MB at 10:00 minutes of lisp.run,
~106 MB at 16:00 minutes of lisp.run, ... and
still running for only the above simple formula.

But i aborted it with Ctrl-C due to its excess time.

Maxima encountered a Lisp error:
Ctrl-C: User break
Automatically continuing.
To reenable the Lisp debugger set *debugger-hook* to nil.
(%i12)

If i remove the expression "-z" then it solved in few seconds:

(%i12) factor(expand((x-y)^1000));
1000
(%o12)                            (y - x)

Sincerely, J.C.Pizarro
```