1

I already asked this question in the mathoverflow forums, but it seems I won't get an answer as fast as I need one. So I'm moving the thread here. Besides, maybe it isn't as hard as to post it there.

This question has some references to programming and not as many mathematical terms as you might like, but I think it's more appropriate in a mathematics forum.


Introduction (Skip if you are familiar with k-permutations and permutations with one forbidden number):

I think everyone universally agrees that there are are n! permutations of a list of n numbers.

Assume we want one of the places in the permutations to only have certain values. Here's an example:

n=3 ; [1,2,3]; The permutation may not begin with a 2.

We now list all possible permutations.

[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]

When we apply the rule, we have

[1,2,3],[1,3,2],[3,1,2],[3,2,1]

so instead of six, we have four possibilities. This can be generally expressed as (n-1)(n!/n) or just (n-1)(n-1)! for a list of n numbers in which any one place has a forbidden number.


Introduction (continuing):

Now assume I want all permutations of r length from a list of n numbers. Example:

n=4 ; [1,2,3,4] ; r=2

[1,2],[1,3],[1,4],[2,1],[2,3],[2,4],[3,1],[3,2],[3,4],[4,1],[4,2],[4,3]

so as a result, we have 12 lists. Universally expressed: n!/(n-r)! This can be found on wikipedia here or just look at the comment of Matt right under this question.


Now for the real problem. What number of permutations of r length over n values are there when every place in the permutation has a list of forbidden values?

Let me get you another example.

n=5 ; [1,2,3,4,5] ; r=3 ; The permutations may not begin with a 1 or a 2, the second place may not be a 2, the third may not be a 2 or a 3.

First generate all permutations of 3 length over [1,2,3,4,5]. We get

[(1, 2, 3), (1, 2, 4), (1, 2, 5), (1, 3, 2), (1, 3, 4), (1, 3, 5), (1, 4, 2), (1, 4, 3), (1, 4, 5), (1, 5, 2), (1, 5, 3), (1, 5, 4), (2, 1, 3), (2, 1, 4), (2, 1, 5), (2, 3, 1), (2, 3, 4), (2, 3, 5), (2, 4, 1), (2, 4, 3), (2, 4, 5), (2, 5, 1), (2, 5, 3), (2, 5, 4), (3, 1, 2), (3, 1, 4), (3, 1, 5), (3, 2, 1), (3, 2, 4), (3, 2, 5), (3, 4, 1), (3, 4, 2), (3, 4, 5), (3, 5, 1), (3, 5, 2), (3, 5, 4), (4, 1, 2), (4, 1, 3), (4, 1, 5), (4, 2, 1), (4, 2, 3), (4, 2, 5), (4, 3, 1), (4, 3, 2), (4, 3, 5), (4, 5, 1), (4, 5, 2), (4, 5, 3), (5, 1, 2), (5, 1, 3), (5, 1, 4), (5, 2, 1), (5, 2, 3), (5, 2, 4), (5, 3, 1), (5, 3, 2), (5, 3, 4), (5, 4, 1), (5, 4, 2), (5, 4, 3)]

We have 60 possible answers. Now apply the first rule. Rule out all possibilities that start with 1 or 2. We get

[(3, 1, 2), (3, 1, 4), (3, 1, 5), (3, 2, 1), (3, 2, 4), (3, 2, 5), (3, 4, 1), (3, 4, 2), (3, 4, 5), (3, 5, 1), (3, 5, 2), (3, 5, 4), (4, 1, 2), (4, 1, 3), (4, 1, 5), (4, 2, 1), (4, 2, 3), (4, 2, 5), (4, 3, 1), (4, 3, 2), (4, 3, 5), (4, 5, 1), (4, 5, 2), (4, 5, 3), (5, 1, 2), (5, 1, 3), (5, 1, 4), (5, 2, 1), (5, 2, 3), (5, 2, 4), (5, 3, 1), (5, 3, 2), (5, 3, 4), (5, 4, 1), (5, 4, 2), (5, 4, 3)]

, so 36 possibilities. Applying the second rule (the second place may not be a two), we get

[(3, 1, 2), (3, 1, 4), (3, 1, 5), (3, 4, 1), (3, 4, 2), (3, 4, 5), (3, 5, 1), (3, 5, 2), (3, 5, 4), (4, 1, 2), (4, 1, 3), (4, 1, 5), (4, 2, 1), (4, 3, 1), (4, 3, 2), (4, 3, 5), (4, 5, 1), (4, 5, 2), (4, 5, 3), (5, 1, 2), (5, 1, 3), (5, 1, 4), (5, 3, 1), (5, 3, 2), (5, 3, 4), (5, 4, 1), (5, 4, 2), (5, 4, 3)]

...28 answers. With the third and final rule (the third place may not be a 2 or a 3), we get the final answer of

[(3, 1, 4), (3, 1, 5), (3, 4, 1), (3, 4, 5), (3, 5, 1), (3, 5, 4),(4, 1, 5), (4, 2, 1), (4, 3, 1), (4, 3, 5), (4, 5, 1), (5, 1, 4), (5, 3, 1), (5, 3, 4), (5, 4, 1)]

...15 permutations of r length over 5 values with the three rules applied.

It might be worth mentioning that a place can also have zero forbidden values, meaning it can be any value.


Now I would love to know how I can get to this number manually without the previous steps of generating all permutations and then applying the rules. I'm writing a program that deals with lists of r length over 9 values, with an unknown number of forbidden values for each place, and I do this in quite a big loop. So I don't want the computer generating all permutations every time it goes into the loop. A simple mathematical statement would be awesome. If anyone has the wits, I'd be absolutely thrilled if I got a pythonic answer. But really, a normal mathematical statement is enough (as long as you at least partly explain it), I'll be happy to convert it into code. Even a hint to keep me motivated is greatly appreciated. After hours of brain-teasing I've kind of given up on this.

Please do let me know if anything is unclear or if I made a mistake somewhere.

Many thanks in advance.

  • What notation are you using? In your $n=3$ example, it seems you are just listing all the values of the permutation, but then once you introduce $r$ it seems like you might have switched to cycle notation - except that then $[1,2]=[2,1]$, but you list them separately. I think it would be helpful to clarify the notation, and maybe explain more clearly what a "permutation of length $r$" is. – mdp Oct 22 '14 at 11:25
  • Actually, forget that, I should have followed your Wikipedia link - to flag it up for other readers, in this question a permutation of a set is an ordering of the elements, and a permutation of length $r$ (called an $r$-permutation on Wikipedia) is an ordering of any $r$-subset of the original set. – mdp Oct 22 '14 at 11:27
  • @MattPressland Exactly. Thanks for the input. – SmeltQuake Oct 22 '14 at 12:23
  • Your problem is equivalent to the problem of placing $r$ mutually non-attacking rooks (i.e., no two on the same row or column) on a $n \times r$ board with some of the squares forbidden. So, my hint is "rook polynomial". – Doug Chatham Oct 22 '14 at 13:25
  • @DougChatham First of all, great input! The only problem is I'm not at that level yet. I assume you mean that the answer is given when you try and figure out how many possibilities there are to place r non-challenging rooks on a "damaged" n*r board. Yet I have toyed arround with the idea and not gotten anywhere. I don't suppose you would be as nice as to give me some specific hints? There is, by the way, nothing too understandable on this on the interwebs. – SmeltQuake Oct 22 '14 at 15:23
  • Here is an article describing an algorithm for generating rook polynomials: http://www.mathematica-journal.com/issue/v9i2/contents/RookPolynomials/RookPolynomials.pdf. – Doug Chatham Oct 22 '14 at 22:29

0 Answers0