RE: Re: Together, Apart, ? [2]

• To: mathgroup at smc.vnet.net
• Subject: [mg17102] RE: [mg17042] Re: Together, Apart, ? [2]
• From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
• Date: Sat, 17 Apr 1999 03:35:03 -0400
• Sender: owner-wri-mathgroup at wolfram.com

Allan Hayes wrote a very fast and very slick variation of Together.  His
version is shown below:
----------------------------

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 .

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

SimpleTogether[expr_]:= expr

----------------------------

Union has a SameTest option. Some of the nuances
of Union and it's option are discussed at:
http://www.wolfram.com/support/Kernal/Symbols/findsymbol.cgi

On that page it says the default test Union uses is stronger than using
Equal or SameQ!  I wonder if there are any situations where you would want
SimpleTogether to use a different setting for the SameTest option in Union.
Thinking there may be situations where you would want this I wrote a version
of Allan's program that uses this option.  Except it isn't "simple" anymore
so I call it MyTogether.  My new version is below.

Options[MyTogether]=Options[Union];
Attributes[MyTogether]={Listable};

MyTogether[expr_Plus,opts___]:=
With[{
st=SameTest/.Flatten[{opts,Options[MyTogether]}]
},
((Plus@@(# List@@expr))/#)&[Times@@Union[Denominator/@List@@expr,
SameTest->st]]]

MyTogether[expr_,opts___]:=expr

------------------
Note:
The built in Together function also has the options
{Extension->None, Modulus->, Trig->False}.
Does anyone want to modify the definitions above so it also uses the options
(Extension, Modulus, Trig)?

Regards,
Ted Ersek

• Prev by Date: Re: List of function-heads
• Next by Date: Stellar Oscillations
• Previous by thread: Re: Together, Apart, ? [2]
• Next by thread: Heip! How to draw a graph with log x axis.