MathGroup Archive 2012

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

Search the Archive

Re: Symmetrizing function arguments


On 8/7/2012 2:04 AM, Hauke Reddmann wrote:

> g[a_,b_,c_]:=If[b>c,If[a>c,If[a>b,G[a,b,c],g[b,a,c]],g[c,b,a]],g[a,c,b]];

why not simply use Sort, that is what you are doing above?

You can defined your G to take a list as in {a_,b_,c_} from Sort
or use Sequence to splice the result from Sort before calling G.

Here is one example:

-----------------------
G[{a_, b_, c_}] := Print["a=", a, " b=", b, " c=", c]
g[a_, b_, c_] := G[Sort[{a, b, c}, #1 > #2 &]]
---------------------------

And another using Sequnece, so you do not need to change
G defintion

-----------------------
G[a_, b_, c_] := Print["a=", a, " b=", b, " c=", c]
g[a_, b_, c_] := G[Sequence @@ Sort[{a, b, c}, #1 > #2 &]]
---------------------------

--Nasser



  • Prev by Date: Re: Landau letter, Re: Mathematica as a New Approach...
  • Next by Date: how does Rotate in 2D work?
  • Previous by thread: Re: Symmetrizing function arguments
  • Next by thread: Re: Symmetrizing function arguments