factorize as-much-as-you-can



This is a variant of a frequently asked question here. The quick answer is
that there is no general method to find the shortest or the
fastest-to-calculate form of an expression in Maxima.  It is certainly
possible to do a combinatorial search of various kinds of rewrites of an
expression, though some rewrites are harder to find than others.  For
example, I don't know how you'd find

     (x+y+3)^3-(x+2*y-4)^4

starting from its expanded form.

Some useful tools for reorganizing expressions for calculation include
factor, horner, rat, factorsum, and optimize.  Do not be deluded by the
name 'optimize' -- it is actually very simple-minded. By the way, to
'factor' an expression in Maxima means to represent as a product of
irreducible polynomial terms, *not* to rewrite it for efficiency or
accuracy of calculation.

Note also that *none* of these functions take into account things like
numerical accuracy and avoiding overflows -- which can be very subtle
problems.  See George Forsythe's classic How do you solve a quadratic
equation?<ftp://reports.stanford.edu/pub/cstr/reports/cs/tr/66/40/CS-TR-66-40.pdf>;

              -s




On Mon, Mar 25, 2013 at 12:02 PM, Emmanuel Michon <
emmanuel.michon+maxima at gmail.com> wrote:

> Hello,
>
> is there a way to tell maxima to factor the most it can out of
>
> x^2+3*x*y+5*a^2+z^2+a^3
>
> which I understand as answering this
>
> (x+y)^2+a^2*(a+5)+x*y
>
> If I had to define what I want in more scientific terms, that would be
> ?the form that would comprise the less possible symbols? directly
> related to a matter of evaluation speed.
>
> I found factorsum() but it's about inoperant for
>
> 4*p[2]*p[3]^2*q[4]^2-p[2]^3*q[4]^2-p[1]^2*p[2]*q[4]^2
>                            -2*p[3]^3*q[3]*q[4]+8*p[2]^2*p[3]*q[3]*q[4]
>                            -2*p[1]^2*p[3]*q[3]*q[4]
>
>  +10*p[1]*p[2]*q[2]*p[3]*q[4]-4*p[2]*p[3]^2*q[3]^2
>                            +p[2]^3*q[3]^2+p[1]^2*p[2]*q[3]^2
>                            -10*p[1]*q[1]*p[2]*p[3]*q[3]-2*q[1]*q[2]*p[3]^3
>                            -4*p[2]*q[2]^2*p[3]^2+4*q[1]^2*p[2]*p[3]^2
>                            +8*q[1]*p[2]^2*q[2]*p[3]-2*p[1]^2*q[1]*q[2]*p[3]
>                            +p[2]^3*q[2]^2+p[1]^2*p[2]*q[2]^2-q[1]^2*p[2]^3
>                            -p[1]^2*q[1]^2*p[2]
>
> Thanks!
>
> ***
>
> Sincerely yours,
>
> e.m.
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>