Decomposition of numbered permutations.

KingNothing
Messages
880
Reaction score
4
Say I have three elements: A, B, C. I can list all the permutations by going alphabetical in the first element, then the second, then the third, and so on, like so:

  1. ABC
  2. ACB
  3. BAC
  4. BCA
  5. CAB
  6. CBA
What I'm wondering, is given a number N, how do I decompose this into knowing what permutation it specifies?

For example, how do I figure that N=5 corresponds to CAB?
Is there a better order to list them in which makes this problem simpler?
 
Mathematics news on Phys.org
Thanks awkward for the information. I actually had seen that already, but dismissed it on the basis that I figured using FNS would be too computationally intensive. That is, I would have to first convert the decimal representation to a FNS representation, then convert the FNS representation into a permutation.

Wikipedia speaks of processing the FNS digit-by-digit, removing items from a lexicographically-sorted list as part of this process. I think in my case that may be a deal breaker, but I'm not sure.

Are you aware of any algorithms that decompose a decimal representation (does not need to be lexicographical order, that was just my example) without the use of lists or FNS?
 
The following should be suited to a recursive algorithm and uses your numbering scheme.

The first element can be given as \left\lceil\frac{x}{(N-1)!}\right\rceil where \left\lceil\right\rceil is the ceiling function, x is the index number and N is the total number of elements in the list. The second element can be obtained recursively by applying the same formula to the list obtained by removing the first element and with a new index of r which is the remainder of x when divided by (N-1)! (with 0 taken as (N-1)!)

As an example taking your ordering of the set {A, B, C}

1. ABC
2. ACB
3. BAC
4. BCA
5. CAB
6. CBA

notice that if we remove the first element, say C, then

AB
BA

is the same ordering applied to the set {A, B}. The same can be generalized into larger sets. For a 4 element set, say {A, B, C, D} let's try to apply our method. Say we want element number 22, then the first element is given by \left\lceil\frac{22}{6}\right\rceil = 4 which is the fourth element of our set, namely D. Now applying the same method to the set with D removed, that is {A, B, C} with new index 4. Applying the same method we obtain that the second element is \left\lceil\frac{4}{2}\right\rceil = 2 which is B. The remainder of division is 0, so we take it to be 2! = 2 instead. This is repeated a third time with the set {A, C} to yield a third element of C and final element of A.
 
Yuqing - let me see if I have this right. I'm going to rewrite it slightly using integer division (floor(x/y)) and modulus. A foreslash (/) will indicate integer division, and a % will indicate modulus. N will be the number of elements in the "available list". The lists will have a zero-based index. ":=" is the assignment operator.

We start with an ABCD list, and the index x=22.
22/(4-1)! = 3 -> D, so D is first element.
List becomes ABC. N:=3. x:=22%4=4.

4/(3-1)! = 2 -> C, so C is second element.
List becomes AB. N:=2. x:=2%(3-1)!=0.

0/(2-1)! = 0 -> A, so A is third element.
List becomes B. N:=1. x:=0%(2-1)!=0.

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

Ideally I would only compute the first denominator, and in each step divide it by N after N is decremented. One challenge is that list element removal and re-indexing is very non-trivial in a computer. I wonder if there might be a way mathematically to prevent an element from being selected from the list, without having to remove it.

0/(1-1)! = 0 -> B, so B is fourth element.
List becomes empty, and we are done.
 
KingNothing said:
Yuqing - let me see if I have this right. I'm going to rewrite it slightly using integer division (floor(x/y)) and modulus. A foreslash (/) will indicate integer division, and a % will indicate modulus. N will be the number of elements in the "available list". The lists will have a zero-based index. ":=" is the assignment operator.

We start with an ABCD list, and the index x=22.
22/(4-1)! = 3 -> D, so D is first element.
List becomes ABC. N:=3. x:=22%4=4.

4/(3-1)! = 2 -> C, so C is second element.
List becomes AB. N:=2. x:=2%(3-1)!=0.

0/(2-1)! = 0 -> A, so A is third element.
List becomes B. N:=1. x:=0%(2-1)!=0.

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

Ideally I would only compute the first denominator, and in each step divide it by N after N is decremented. One challenge is that list element removal and re-indexing is very non-trivial in a computer. I wonder if there might be a way mathematically to prevent an element from being selected from the list, without having to remove it.

0/(1-1)! = 0 -> B, so B is fourth element.
List becomes empty, and we are done.

The algorithm is more or less correct, but you have to make some adjustments for when x/(N-1)! is integer. In the second step above, the element chosen is supposed to be B and not C and this is a remnant of shifting the index and flooring the argument. I think subtracting one from the the case when x/(N-1)! should take care of it.

As for the list problem, I am a bit unsure. I myself am not a programmer, while I can write code I doubt it will be efficient enough for your purposes. I suppose you can keep an alternate list of indices which should not be selected, but again I'm unsure whether this is anymore efficient than simply reindexing.
 
Last edited:
Insights auto threads is broken atm, so I'm manually creating these for new Insight articles. In Dirac’s Principles of Quantum Mechanics published in 1930 he introduced a “convenient notation” he referred to as a “delta function” which he treated as a continuum analog to the discrete Kronecker delta. The Kronecker delta is simply the indexed components of the identity operator in matrix algebra Source: https://www.physicsforums.com/insights/what-exactly-is-diracs-delta-function/ by...
Fermat's Last Theorem has long been one of the most famous mathematical problems, and is now one of the most famous theorems. It simply states that the equation $$ a^n+b^n=c^n $$ has no solutions with positive integers if ##n>2.## It was named after Pierre de Fermat (1607-1665). The problem itself stems from the book Arithmetica by Diophantus of Alexandria. It gained popularity because Fermat noted in his copy "Cubum autem in duos cubos, aut quadratoquadratum in duos quadratoquadratos, et...
Thread 'Imaginary Pythagorus'
I posted this in the Lame Math thread, but it's got me thinking. Is there any validity to this? Or is it really just a mathematical trick? Naively, I see that i2 + plus 12 does equal zero2. But does this have a meaning? I know one can treat the imaginary number line as just another axis like the reals, but does that mean this does represent a triangle in the complex plane with a hypotenuse of length zero? Ibix offered a rendering of the diagram using what I assume is matrix* notation...

Similar threads

Replies
3
Views
1K
Replies
10
Views
2K
Replies
2
Views
2K
Replies
23
Views
3K
Replies
3
Views
2K
Replies
45
Views
4K
Replies
3
Views
2K
Back
Top