MathGroup Archive 2006

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

Search the Archive

Re: efficient term collection algorithm

  • To: mathgroup at smc.vnet.net
  • Subject: [mg69176] Re: [mg69155] efficient term collection algorithm
  • From: "Carl K. Woll" <carlw at wolfram.com>
  • Date: Fri, 1 Sep 2006 06:40:27 -0400 (EDT)
  • References: <200608310839.EAA19589@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Blake Laing wrote:
> Dear Math Group
> 
> I wish to combine terms in a expression which share a denominator, such 
> as in the following simple case:
> 
> In[1]:=
> a/i+b/j+c/i//.Plus[Times[A_.,Power[denom_,-1]],Times[B_.,Power[denom_,-1]]]:>
>       Factor[Plus[A,B]Power[denom,-1]]//InputForm
> Out[1]//InputForm=
> (a + c)/i + b/j
> 
> The actual expression I am working with contains thousands of terms, and 
> a pairwise algorithm such as this is wholly inadequate. Will one of you 
> please suggest a more efficient way to combine each additive term in a 
> large expression with a shared denominator?
> 
> Thanks,
> 
> Blake Laing
> physics grad student
> University of Oklahoma
>  

If you know the denominator(s), you could use Collect:

expr = a/i + b/j + c/i;

In[13]:= Collect[expr, i]

Out[13]= b/j + (a + c)/i

If you don't know the denominators, you could try:

In[15]:= Collect[expr, Union@Denominator[List @@ expr]]

Out[15]= b/j + (a + c)/i

Carl Woll
Wolfram Research


  • Prev by Date: Re: Unexpected "Invalid comparison" error when plotting function defined with a Condition pattern
  • Next by Date: RE: efficient term collection algorithm
  • Previous by thread: Re: efficient term collection algorithm
  • Next by thread: RE: efficient term collection algorithm