       Re: efficient term collection algorithm

• To: mathgroup at smc.vnet.net
• Subject: [mg69377] Re: efficient term collection algorithm
• From: "Blake" <blakeandteresa at gmail.com>
• Date: Sat, 9 Sep 2006 03:26:59 -0400 (EDT)
• References: <ed68a7\$jci\$1@smc.vnet.net>

```Thank you everyone for your helpful responses. Many of you suggested
using Collect, which works very well for this problem!

I used David Park's algorithm, adding one modification--I sorted the
list of denominators in decreasing length. This modification prevents
undesirable behavior when denominators contains terms like i and i(i+1)

collectDenominators[expr_, func_] := Module[{answer, work =
Expand[expr],
factors}, factors = Union[Denominator /@ List @@ work];

factors = Sort[factors, Length[#1] > Length[#2] &]^-1;

answer = Collect[expr, factors, func];

];

Apart works well for the simple example I gave, but for some reason
does not combine fractions in my actual problem which share a common
denominator (perhaps due to the complexity of the numerators?). I have
found Apart very useful in a closely related probelm, however, so thank
you for bringing that function to my attention.

Blake Laing