MathGroup Archive 2004

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

Search the Archive

Re: UnrankPermutation newbie problem .. Combinatorica Package

  • To: mathgroup at smc.vnet.net
  • Subject: [mg49964] Re: UnrankPermutation newbie problem .. Combinatorica Package
  • From: BV <dont at bug.me>
  • Date: Sun, 8 Aug 2004 05:37:47 -0400 (EDT)
  • References: <cf22sg$7tf$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

BV wrote:

> I found that calling NthPermutation via MathLink in C++ is rather costly 
>   for my purposes, therefore I'm inquiring to  re-write the function 
> entirely in C++. I hope by eliminating unnecessary calls to MathLink 
> this would speed up my program significantly.
> 
> As, I admit, I am not very versed in Mathematics itself can anyone point 
> me in the direction where to start; how this function works; what 
> formula is used, etc.
> Thank you
> 
I found in the "combinatorica.m" file that this function is obsolete and 
that UnrankPermutation[] function should be used instead. This is the 
code as it should work (from the "combinatorica.m" file):

UnrankPermutation[r_Integer, {}] := {}
UnrankPermutation[r_Integer, l_List] :=
         Module[{s = l, k, t, p = UP[Mod[r, Length[l]!], Length[l]]},
                Table[k = s[[t = p[[i]] ]];
                      s = Delete[s, t];
                      k,
                      {i, Length[ p ]}
                ]
         ]

UnrankPermutation[r_Integer, n_Integer?Positive] :=
         UnrankPermutation[r, Range[n]]

Can someone please write this as an algorithm or a formula as I don't 
have any books on Mathematica and this looks complicated; a plain 
formula for this would do!


  • Prev by Date: button to emulate Shift-Enter
  • Next by Date: Re: Another question about Compile[]:
  • Previous by thread: Re: button to emulate Shift-Enter
  • Next by thread: Re: Re: UnrankPermutation newbie problem .. Combinatorica Package