I'm looking for the equation to determine the index of a permutation with repetition with known parameters.
For example: A total of $9$ values, $4$ A's and $5$ B's Gives a total of $126$ permutations with repetition. $$\frac{9!}{4! \cdot 5!} = 126$$
The Zero-based lexicographical order goes from 0 = AAAABBBBB to 125 = BBBBBAAAA This data set is trivial enough that I just generated all the values with code, but large data sets are impractical. I know that index 76 = BABABABAB since I have a list of answers, but I don't want to generate a partial or a full list.
How do I direclty convert any sequence such as BABABABAB to the permutation with repetition index? How do I direclty do the reverse and convert the permutation with repetition index back to the sequence?
I'm looking for the equations / methods to use in a non-trivial example.
Lexicographical order is prefered, but not required as long as the method can convert in both directions (Sequence => Index and Index => Sequence).