MathGroup Archive 1999

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

Search the Archive

Re: Together, Apart, ? [2]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg17042] Re: Together, Apart, ? [2]
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Wed, 14 Apr 1999 02:11:55 -0400
  • References: <7ehj7k$nsb@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Here is simple direct version of together that is much faster than the one
in my previous posting - in general recursion is to be avoided .

Clear["`*"]

SimpleTogether[expr_Plus]:=
 ((Plus@@( # List@@expr))/ #)&[Times@@Union[Denominator/@List@@expr]]

SimpleTogether[expr_]:= expr

TESTS

expr=k/m+(a+b+c)/(c+d/g)+(e+f+g)/(g+h)+u/p+ v/p +q+1;

SimpleTogether[expr]
((c + d/g)*(g + h)*k*p + (c + d/g)*(e + f + g)*m*p +
    (a + b + c)*(g + h)*m*p + (c + d/g)*(g + h)*m*p +
    (c + d/g)*(g + h)*m*p*q + (c + d/g)*(g + h)*m*u +
    (c + d/g)*(g + h)*m*v)/((c + d/g)*(g + h)*m*p)

SimpleTogether//@expr
((d + c*g)*(g + h)*k*p + (e + f + g)*(d + c*g)*m*p +
    (a + b + c)*g*(g + h)*m*p +
    (d + c*g)*(g + h)*m*p + (d + c*g)*(g + h)*m*p*q +
    (d + c*g)*(g + h)*m*u + (d + c*g)*(g + h)*m*v)/
  ((d + c*g)*(g + h)*m*p)

Together[expr]
(d*g*k*p + c*g^2*k*p + d*h*k*p + c*g*h*k*p +
    d*e*m*p + d*f*m*p + 2*d*g*m*p + c*e*g*m*p +
    c*f*g*m*p + a*g^2*m*p + b*g^2*m*p + 3*c*g^2*m*p +
    d*h*m*p + a*g*h*m*p + b*g*h*m*p + 2*c*g*h*m*p +
    d*g*m*p*q + c*g^2*m*p*q + d*h*m*p*q +
    c*g*h*m*p*q + d*g*m*u + c*g^2*m*u + d*h*m*u +
    c*g*h*m*u + d*g*m*v + c*g^2*m*v + d*h*m*v +
    c*g*h*m*v)/((d + c*g)*(g + h)*m*p)

TIMINGS
Do[SimpleTogether[expr],{10}]//Timing
{0.06 Second,Null}

Do[SimpleTogether//@expr,{10}]//Timing
{0.11 Second,Null}

Do[MyTogether[expr],{10}]//Timing
{0.33 Second,Null}

Do[MyTogether//@expr,{10}]//Timing
{0.44 Second,Null}

Do[Together[expr],{10}]//Timing
{0.6 Second,Null}

Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565




  • Prev by Date: Re: ListDensityPlot[ ] and DensityGraphics
  • Next by Date: Heip! How to draw a graph with log x axis.
  • Previous by thread: Re: Border on Tables
  • Next by thread: RE: Re: Together, Apart, ? [2]