Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

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

Advanced Search

Back to Topic List Back to Topic List  
Francisco Edmundo de Andrade

Posts: 9
Registered: 12/7/04
Re: [mg5137] simplify problem
Posted: Nov 9, 1996 2:06 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply



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};
While[Head[next=nextFactor[Plus[args],tabu]]=!=nextFactor,
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-)
-----------------------------
Universidade Federal do Ceara
Department of Computing
edmundo@lia.ufc.br
-----------------------------








Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.