question on factorization



In general, there is no well-defined solution to your problem.  What would
you want to do with, e.g.

        a*b + b*c + c*d  ?

It could be rewritten as

       (a+c)*b + c*d

or as

     (b+d)*c + a*b

It is easy enough to do get *all *factorizations of all partitions, like
this:

partition_factor(s):=
    if mapatom(s) or inpart(s,0) # "+" then {s}
    else map(
  lambda([t],
    apply("+",
                  listify(map(lambda([u],factor(apply("+",listify(u)))),
      t)))),
  set_partitions(setify(args(s))))$

partition_factor( a^2+b*a+b^2);
=>
{
 b*(b+a)+a^2,
 b^2+a*b+a^2,
 b^2+a*(b+a)
}

partition_factor( a*b*c*x + a*b*c^2*y + b*y + a*x)
=>
{
 a*b*c^2*y+b*y+a*b*c*x+a*x,
 a*b*c^2*y+b*y+a*(b*c+1)*x,
 b*(a*c^2+1)*y+a*b*c*x+a*x,
 b*(a*c^2+1)*y+a*(b*c+1)*x,
 b*(y+a*c*x)+a*b*c^2*y+a*x,
 a*b*c*(c*y+x)+b*y+a*x,
 b*(a*c^2*y+y+a*c*x)+a*x,
 a*(b*c^2*y+x)+b*y+a*b*c*x,
 a*(b*c^2*y+x)+b*(y+a*c*x),
 a*(b*c^2*y+b*c*x+x)+b*y
}

That said, that still doesn't get you everything you might want, because it
only uses existing terms.  For example:

partition_factor(b^2+a*b+a^2)
=>
{
 b*(b+a)+a^2,
 b^2+a*b+a^2,
 b^2+a*(b+a)
}

but that doesn't include

 (a+b)^2-a*b

which is just as short, and could be considered a 'better' factorization in
some cases....

             -s

On Sun, Nov 4, 2012 at 3:35 AM, lo <james.smith1 at freenet.de> wrote:

> On 11/04/12 04:56, Raymond Toy wrote:
>
>> "lo" == lo  <james.smith1 at freenet.de> writes:
>>>>>>>
>>>>>>      lo> hello Maxima users,
>>      lo> a question from a newby:
>>      lo> I define a function and take the derivative of it
>>      lo> wrt some variables. The result is horribly long
>>      lo> but it is the sum of many terms. If I examine those terms,
>>      lo> for each, some factorization could be done, but are not.
>>      lo> To simplify the problem, consider for instance:
>>      lo> f: y1*exp(x1)+y1*cos(x1)+(x1-x2)^**2;
>>      lo> How come that Maxima do not put y1 as a common factor for
>> exp(x1) and
>>      lo> cos(x1) ?
>>
>> Because sometimes that's not what you want.  Maxima can't read your
>> mind. :-)
>>
>>      lo> How to tell Maxima to factorize as much as possible (assuming I
>> do not
>>      lo> know myself that
>>      lo> y1 is a common factor for the first two terms)  ?
>>
>> collectterms(f, y1) will do what you want in this case.
>>
>>      lo> If I use radcan, I get the result I want, but (x1-x2)^2 gets
>> expanded,
>>      lo> something I would like to avoid.
>>
>> Be careful with radcan.  It can change expressions in unexpected ways
>> that you might not want.  Use ratsimp instead.
>>
>> Ray
>>
>> ______________________________**_________________
>> Maxima mailing list
>> Maxima at math.utexas.edu
>> http://www.math.utexas.edu/**mailman/listinfo/maxima<http://www.math.utexas.edu/mailman/listinfo/maxima>;
>>
>>
>>  thanks for the info;
>
> collectterms would do the work, except that my expression is often of the
> type:
>
> f: a*b*c*x1+a*b*c^2*x2;
> collectterms(f,a,b,c) does not return a*b*c*(x1+c*x2);
> how to force it ?
>
> moreover, as said, I do know what terms to collect
> only by visual inspection; is there a way to force Maxima
> to do this kind of simplification without specification ?
>
> thanks in advance;
>
> Laurent
>
>
> ______________________________**_________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/**mailman/listinfo/maxima<http://www.math.utexas.edu/mailman/listinfo/maxima>;
>