Skip to content

blakbodder/multiset_runs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

how many permutations of a multiset have k1 runs length 1, k2 runs length 2, ...? the python code here provides tools to answer such questions.
A = { x,x,x,y,y,z,z,z,z } is an example of a mulltiset.

notation.
1run refers to a run of length 1. 3run denotes a run, lenght 3. etc.

X:k1.k2.k3... is a run partition where objects labelled X occur in k (k=k1+k2+k3+...) runs, specifically k1 1runs, k2 2runs, ...
example i:3.4.1 has 3 1runs and 4 2runs and a 3run of the letter i. a run partition has a property f, which is the number of distinguishable ways the run partition can be realised. f = multinomial(k,(k1,k2,k3...)).
eg. x:1.1.1 ->
x xx xxx
x xxx xx
xx x xxx
xx xxx x
xxx x xx
xxx xx x
so f(x:1.1.1)=6. the runs of x can be thought of as delimited by other non-x elements or by gaps to be filled by potential interlopers.

two run partitions of different elements can be combined by an operation called mix. the character for the mix operator looks like:
mix operator)

let rpi = i:3.2.2 and rpj = j:4.0.2
consider rpi mix rpj. there are seven runs-of-i in rpi so there are 6 spaces in the runs-of-i that need to be filled by a run-of-j. these are mandatory spaces (mansp). if there are not enough runs-of-j to fill the mansp, the mix operation fails. rpi also has 2 optional spaces at the ends (endsp) that can be occupied by a run-of-j if 1 or 2 runs-of-j are left over after the mansp fill. if there are more runs-of-j than mansp+2, the operation fails. mix does the combinatorics of how many ways an achievable outcome can be contructed. it feels wrong to call the 'product' of a mix a 'mix' so it is called a fold. (imagine 2 blankets being folded and interleaved in a complicated fashion).
rpi mix rpj results in a tuple (i:3.2.2 , j:4.0.2) with f=3150.

5 x elements can be split up in a number of ways:
xxxxx
xxxx x
xxx xx
xxx x x
xx xx x
xx x x x
x x x x x
the set of these run partions { x:0.0.0.0.1 x:1.0.0.1 x:0.1.1 x:2.0.1 x:1.2 x:3.1 x:5 } is a called a run partition set. this one is called x:RPS5.

an RPS can be mixed with an RPS of a different element.
take i:RPS4 mix j:RPS3
construct a table where every row is labelled with a member of i:RPS4 and the columns are labelled by the j-run-partitions.

for each row:
    for each column:
        do rpi[row] mix rpj[column]

this is similar to multiplying polynomials. the result is a table of folds (implemented as a dictionary). the sum of the f-properties of the all table entries comes to multinomial(7, (4,3)) which is the number of permutations of the multiset { i,i,i,i,j,j,j } the table breaks down all the run patterns possible with this multiset. all the ways of building a multiset from a gaggle of run-building-blocks is the same as the number of permutations of the multiset containing said run components.

mixing more than 2 run partitions is also possible but more complicated. let xyzfold = ( x.2.3.1, y.4.1, z.0.1,1 ). the number of ways this can be done is computed by count_perms(xyzfold) using a recurrence relation. see mathstackexchange where adjacent letters must be different. the same logic applies here, only runs of same type cannot be consecutive.

this means that more than 2 run partition sets can be handled:

x5rps = RPS('x',5)
y3rps = RPS('y',3)
z4rps = RPS('z',4)

q = meeks(x5rps, y3rps, z4rps)

the meeks classifies every permutation of { x x x x x y y y z z z z ) according to its runs structure. the result is an enormous mess within which answers are buried.

kollapse(q) mushes the data together to give a dictionary with keys: x|y|z:k1.k2... where the numbers are counts of 1runs, 2runs ... ie runs-of-x-or-y-or-z.

fruit.py and classify.py show how to use the code.

About

count permutations of multiset with given run-structure

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages