Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: efficient term collection algorithm

  • To: mathgroup at smc.vnet.net
  • Subject: [mg69475] Re: efficient term collection algorithm
  • From: "Blake" <blakeandteresa at gmail.com>
  • Date: Wed, 13 Sep 2006 04:03:23 -0400 (EDT)
  • References: <200608310839.EAA19589@smc.vnet.net><ed932v$pi5$1@smc.vnet.net>

Concerning the collection of terms with a shared denominator, I wish to
report that I ran into trouble with using an approach based on Collect
and found that the the "split list" approach suggested by Sseziwa
Mukasa and privately by Don Taylor seems to work the best for my
problem.

Here are the to snags I ran into (I'd be interested to know if I missed
something!)
1. It seems neccessary to use Collect[#,1/denominator]&, rather than
Collect[#,1/denominator]&
2. The order of the denominator list seems to be crucial, although
difficult

Consider the following example:
In[1]:=
stuff=(d/i) + c/(i*(1 + i)) + (a*(-1 + i))/(i*(1 + i))

Collecting inverse denominators almost works. (try removing "^-1" in
In[2] to see point 1)
In[2]:=
stuff//Collect[#,Union[Denominator[List@@#]]^-1]&
Out[2]:=d/i + a/(1 + i) + (-a + c)/(i*(1 + i))

If I sort the list of denominators in decreasing complexity (using
LeafCount or somethings similar--the criteria I gave in the previous
post is worthless), I can achieve the desired result for this example,
but not in general. (I can dig up an example)

I wish I understood why it's so difficult to use Collect this way--am I
missing something?

Here is the algorithm that works great for my problem:

collectByDenom[expr_Plus,func_:Simplify]:=
    Module[{commonDList,numerList,denomList},

      commonDList=(Split[
            Sort[ List @@ expr,
OrderedQ[{Denominator[#1],Denominator[#2]}]&],
            Denominator[#1]==Denominator[#2]&
            ]);

      numerList=Plus@@@Numerator[#]&;
      denomList=Flatten[{Union/@Denominator[#]}]&;

      Plus@@(func/@numerList[#]/denomList[#]&@commonDList)
      ];

Blake Laing


  • Prev by Date: Re: init.m of FrontEnd in M5.2
  • Next by Date: Re: Re: solve and Abs
  • Previous by thread: Re: efficient term collection algorithm
  • Next by thread: How to identify "intersections" between to data sets?