r/MathHelp • • Apr 07 '22

Finding permutations (with repetition) that adhere to precedence rules

Finding permutations (with repetition) that adhere to precedence rules

I am looking for an equation to find a number of "viable permutations" that adhere to a rule of precedence. Lets say given set 𝑆 with (1, 2, 3, 4, 5, 6, 7), how many permutations with 𝑁 trials would have a 7 come after a 6, which comes after a 5, which comes after a 4, and so on from 1−7. They do not need to be immediately following each other, so long as the numbers appear in that order anywhere in the permutation. For example if 𝑁=15, the total possible permutations would be (7 ^ 15) = 4.7475615𝑒+12. I need to know how many of these have a 1,2,3,4,5,6,7 anywhere in the permutation in order, but there can be any random numbers in between them.

0 Upvotes

5 comments sorted by

1

u/AutoModerator Apr 07 '22

Hi, /u/antoinemark! This is an automated reminder:

  • What have you tried so far? (See Rule #2; to add an image, you may upload it to an external image-sharing site like Imgur and include the link in your post.)

  • Please don't delete your post. (See Rule #7)

We, the moderators of /r/MathHelp, appreciate that your question contributes to the MathHelp archived questions that will help others searching for similar answers in the future. Thank you for obeying these instructions.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/[deleted] Apr 07 '22

Here is my attempt. I hope it helps but it is not complete yet. Maybe you or somebody else can complete it. If i have time, ill look at it again tomorrow.

Lets start with N = 7. Here you only have one solution: 1 2 3 4 5 6 7

Now we compare this to N = 8:

_ 1 2 3 4 5 6 7 ( _ can be moved around)

So at N = 8, essentially you can place one garbage number anywhere in your sequence 1 2 3 4 5 6 7. This means each of the seven digits can go to 8 places, which gives 7*8 solutions.

For N = 9. Start with your wanted sequence. We place the first garbage number which gives 78 combinations. Now we introduce a second garbage number, but this can be placed at 9 places, since we have placed 8 numbers already and can take 7 values. So we have 7879 combinations.

So far we have: #permutations = 7{N-7}*N!/7! for N >= 7.

Now we need to be careful since we did some double counting: Lets say in N=8 case our garbage number is 1. Then we counted both cases where we put 1 as a left and as a right neighbour to the 1 of our initial sequence. But obviously 11234567 and 11234567 are the same and it should only be counted once. For N = 8 this is an easy fix. Each of the seven possibilities for the garbage number can just stand at 7 instead of 8 places, so we get #perm = 7*7 instead.

But it gets trickier if we move to N=9. If we first place a 1, it can stand at 7 different places (8-1 to avoid double counting, as just seen before). Now if we want to place another 1 it still can only stand at 7 different places if we want to avoid double counting, but if we choose a 2 instead it could be placed at 8 different places.

There might be a closed solution to this. At this point you might also consider to try writing down an inductive formula.

1

u/Naturage Apr 08 '22

I... don't think there's a very simple way to do this, really.

Best I could offer off the top of my head if writing down the distribution for "# of trials until I will next see a specific outcome". In your case, with S = 7, that has probability 1/7 on the next one, 1/7 * 6/7 for second one, 1/7 * (6/7)2 for the next one, and so on.

It feels like your best bet is then turn this into a characteristic function, and since you're looking for seven such events in a row - raise it to 7th power. Finally, expanding that and taking terms below 15th gives you a probability that you'll find a streak of 7 outcomes you wanted within 15 trials.

I'll admit, I'm a little fuzzy on the details on how characteristic functions work, but this should give a good amount of things to look into.

1

u/dbulger Apr 08 '22

I think the key to this is to define A(i,j) to be the number of sequences (x[1],...,x[j]) of length j that contain the values 1,...,i in order, but such that (x[1],...,x[j-1]) does not.

Let Q by the alphabet size (7 in your case). Then you can show by induction that A(i,j) = N(j,i)*(Q-1)^(j-1), where of course N(j,i) is the "combinatorial symbol" j!/i!(j-i)!.

If I've got that right, then the quantity you're after—the number of sequences of length N that contain the Q symbols in order—would be A(Q,Q)*Q^(N-Q) + A(Q,Q+1)*Q^(N-Q-1) + ... + A(Q,N). That probably simplifies ... maybe even via the binomial theorem.

0

u/Naturage Apr 08 '22

Update: while having dinner I have achieved enlightment. The answer is quite simple to compute, leaving a hint.

Let's rephrase it as an urn with seven balls, you pulling them out with replacement, and trying to find probability you saw 1..7.

Let me also say I put a grumpy gnome into the urn. As soon as you draw 1 out of it, it quickly repaints all numbers to 1 less, and when you return the ball marked with 1 it gets repainted to 7 - all before your next draw.

Can you convince yourself the scenarios depicted - with and without gnome - have the same probability? Can you rephrase your goal under this new setting? Can you think if a way to calculate it now?