Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Re: [mg5137] simplify problem
Replies: 0

 Francisco Edmundo de Andrade Posts: 9 Registered: 12/7/04
Re: [mg5137] simplify problem
Posted: Nov 9, 1996 2:06 AM

On Wed, 6 Nov 1996, Tomasz Bieruta wrote:

> I have following problem:
>
> In[1] u=(a+b)^2; v=(c+d)^2;
> In[2] uv=Expand[u+v]
> Out[2] a^2+2ab+b^2+c^2+2cd+d^2
>
> How can I revers the above Operation, in this example from
>
> a^2+2ab+b^2+c^2+2cd+d^2
>
> I want to have (a+b)^2 + (c+d)^2.
> Can someone help me, please ?
>
> Tomasz B.
>
> ----
> e-mail: bieruta@chemie.uni-halle.de
>
>

Consider a function called fullFactor that factors individuals
terms of any expression of sum defined as follow:

(* Edmundo's contribution 1996 *)
Clear[fullFactor,nextFactor]
fullFactor[Plus[args__]]:=
Module[{best=Factor[Plus[args]],next,tabu},
tabu={best};
AppendTo[tabu,next];
If[ByteCount[best]>ByteCount[next],best=next]
];
best
]
nextFactor[Plus[a__,b__],tabu_List] :=
Module[{x=Factor[Plus[a]]+Factor[Plus[b]]},
x /; Not[MemberQ[tabu,x]]
] /; Length[{a}]<=Length[{b}]

Then, here is an example of his working:

Expand[(a+b)^2+(c+d)^2]
fullFactor[%]

which returns:

2 2 2 2
a + 2 a b + b + c + 2 c d + d

2 2
(a + b) + (c + d)

This solution can be expanded easily for general simplifying of
expressions of sum by replacing the word "Factor" by "Simplify"
along the definitions of functions above. The new function called
fullSimplify is slightly slowest than fullFactor.

I hope this solve your problem.

With kindest regards,

Edmundo [8-)
-----------------------------