factorize as-much-as-you-can



I said it would be "easy enough", not that there was a built-in command to
do it (though there might be!).

Something like this:

collect_denominator_powers(expr):=
    if mapatom(expr) or inpart(expr,0)#"+" then expr
    else
      block([], local(d),
                 d[i] := [],
                 for i in expr do
                     if mapatom(denom(i)) or inpart(denom(i),0) # "^"
                         then d[denom(i)] : cons(i,d[denom(i)])
                         else d[inpart(denom(i),1)] : cons(i,
d[inpart(denom(i),1)]),

 xreduce("+",makelist(factor(xreduce("+",j)),j,listarray(d))))$

This does *not* handle the case where there is a constant factor in the
denominator, e.g. 1/x+1/(2*x^2), but I'm sure you can figure out how to add
code to handle that....

        -s


On Wed, Mar 27, 2013 at 9:22 AM, Henry Baker <hbaker1 at pipeline.com> wrote:

> Sorry to belabor the point, but what command would 'combine them after the
> fact' ?
>
> At 06:00 AM 3/27/2013, Stavros Macrakis wrote:
> >On Mar 27, 2013 12:28 AM, "Henry Baker" <hbaker1 at pipeline.com> wrote:
> >(%i7) (a*x^2+b*x+c)/(x+d)^3;
> >                                   2
> >                                a x  + b x + c
> >(%o7)                           --------------
> >                                          3
> >                                   (x + d)
> >(%i8) partfrac(%,x);
> >                                             2
> >                        a     b - 2 a d   a d  - b d + c
> >(%o8)                 ----- + --------- + --------------
> >                      x + d          2              3
> >                              (x + d)        (x + d)
> >
> >Is there any way to tell partfrac to keep the (x+d) denominators
> together, as in %o7 ?
> >
> >
> >No, but it would be easy enough to combine them after the fact.
> >
> >          -s
> >
> >At 08:14 PM 3/26/2013, Stavros Macrakis wrote:
> >>? partfrac
> >>On Mar 26, 2013 11:11 PM, "Henry Baker" <hbaker1 at pipeline.com> wrote:
> >>Thanks, Stavros!
> >>
> >>While you're at it, is there a way to put a rational expression into
> complete 'partial fraction' form (analogous to 'Egyptian fractions' of
> rational numbers), where the numerators of the fraction terms have lower
> degree than the denominators, except for the polynomial term ?
> >>
> >>At 07:22 PM 3/26/2013, Stavros Macrakis wrote:
> >>>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?
> >>>
> >>>              -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.
>
>