This question is an extension of Need help in determining where this pascal's triangle-like sequence comes from.
To summarise, a binary sequence of length n can have 2^n possible values which the initial question grouped as being the number of cycles (c) and the number of ones (k) when the number is wrapped around itself
Eg. The sequence 0011011 has n=7, c=2 and k=4, so does 1001101 and 1100110
So the equation for the number of elements following this pattern can be given as:
$$ \begin{align} f(n,k,c) & = f_{00}(n,k,c)+2f_{01}(n,k,c)+f_{11}(n,k,c) \\ & = \binom{n-k}{c}\binom{k-1}{c-1}\left[1+\frac{k}{n-k}\right] \end{align} $$
I wish to determine the equation for a non-wrapped version for the distribution based on the number of ones (k) the number of 0->1 transitions (c0) and the number of 1->0 transitions (c1). Listing then summing all the permutations are(code in clojure):
(defn num-to-arr [m x]
(cond (= 0 m) []
:else
(let [arr (vec (repeat m 0))]
(reduce (fn [out i]
(assoc out i (bit-and 1 (bit-shift-right x (- m (inc i))))))
arr
(range m)))))
(defn measure [xs]
(loop [x (first xs)
acc [x 0 0]
xs (next xs)]
(cond (empty? xs)
acc
:else
(let [x-n (first xs)
i (+ x (bit-shift-left x-n 1))
acc-n (if (zero? x-n)
acc
(update-in acc [0] inc))
acc-n (if (#{1 2} i)
(update-in acc-n [i] inc)
acc-n)]
(recur x-n acc-n (next xs))))))
(defn dist [m]
(for [i (range (bigint (Math/pow 2 m)))]
(let [arr (common/num-to-arr m i)]
(measure arr))))
and the results for n=7 are:
(sort (frequencies (dist 7)))
[[k, c0, c1] f(n, k, c0, c1)]
([[0 0 0] 1]
[[1 0 1] 1]
[[1 1 0] 1]
[[1 1 1] 5]
[[2 0 1] 1]
[[2 1 0] 1]
[[2 1 1] 5]
[[2 1 2] 4]
[[2 2 1] 4]
[[2 2 2] 6]
[[3 0 1] 1]
[[3 1 0] 1]
[[3 1 1] 5]
[[3 1 2] 6]
[[3 2 1] 6]
[[3 2 2] 9]
[[3 2 3] 3]
[[3 3 2] 3]
[[3 3 3] 1]
[[4 0 1] 1]
[[4 1 0] 1]
[[4 1 1] 5]
[[4 1 2] 6]
[[4 2 1] 6]
[[4 2 2] 9]
[[4 2 3] 3]
[[4 3 2] 3]
[[4 3 3] 1]
[[5 0 1] 1]
[[5 1 0] 1]
[[5 1 1] 5]
[[5 1 2] 4]
[[5 2 1] 4]
[[5 2 2] 6]
[[6 0 1] 1]
[[6 1 0] 1]
[[6 1 1] 5]
[[7 0 0] 1])
Can this be expressed as an equation?