I want to find the number of binary $n \times m$-matrices satisfying the following conditions:
- There are no columns that only have $1$s, i.e. all columns have at least one $0$.
- There are no four consecutive $0$s in any rows.
I tried to work each part on its own first, hoping it might get me some insight on how to solve the whole problem.
The first part on its own is easy. For a single-column matrix, there are exactly $2^n-1$ possibilities. Since we have $m$ columns, we get $(2^n-1)^m$ such matrices.
I think I worked out the second part on its own too. We consider a single row of size $m \geq 4$. Then to find all the valid combinations, we start with the combinations $1$, $01$, $001$, $0001$, and then combine them with all the combinations of valid rows of size $m-1$, $m-2$, $m-3$, $m-4$, respectively. So if $c_m$ is the number of valid combinations for an $m$-row, we get a recurrence relation:
$$c_m = c_{m-1} + c_{m-2} + c_{m-3} + c_{m-4}$$
with base cases $c_1 = 2$, $c_2 = 4$, $c_3 = 8$, $c_4 = 15$. (If someone knows how to translate this recurrence relation into a formula or relation with fewer different recurrence variables, that would also be a great help).
My issue is that I can't find a way to combine these two. I tried constructing matrices incrementally (e.g. assuming we know the number of valid matrices with $m$ columns, can we deduce the number of valid matrices with $m+1$ columns by constructing it from matrices with $m$ columns?).
It doesn't necessarily need to be a single formula or relation either, solving it algorithmically would also be nice, but I'm trying to find something that doesn't just go through all binary matrices and checks through each column and row if the conditions are satisfied.
EDIT:
Thanks to anon, I made huge progress. Thanks a lot. So here's what I got now:
We fix $n$. Let $c(m)$ be the number of "valid" $n \times m$-matrices, i.e. no columns consisting of $1$s and no more than three consecutive $0$s in any row. We say that a row has $x$ trailing $0$, if the last $x$ entries of the row are $0$ but the entry left to those $0$s (if it exists) is not $0$. So then we define the function (given by anon) $c(m, n_0, n_1, n_2, n_3)$ as the number of valid $n \times m$-matrices such that exactly $n_i$ rows have $i$ trailing $0$s. Then
$$c_m = \sum_{i,j,k \in \mathbb{N} \\ i+j+k \leq n} c(m, i, j, k, n-i-j-k)$$
As anon pointed out, there are some obvious cases like $c(m,n,0,0,0) = 0$. In fact, any time either $n_0,n_1,n_2,n_3 = n$, we get $0$ as it gives us a column of $1$s in the last, $2^{nd}$-last, $3^{rd}$-last, $4^{th}$-last column, respectively. This is how we consider the first condition, which means we can focus on the second one, which we get through a recurrence relation.
What we want to find is a relation that describes how to construct a valid $n \times m$-matrix with a given configuration of trailing $O$s from $n \times (m-1)$-matrices with different configurations. I.e., we want something like this:
$$c(m, n_0, n_1, n_2, n_3) = \sum_{i,j,k \in \mathbb{N} \\ i+j+k \leq n} C_{i,j,k} \cdot c(m-1, i, j, k, n-i-j-k)$$
for some coefficients $C_{i,j,k}$. The goal is to find these coefficients. So the question is if I have a valid matrix with a $i,j,k$ rows with $0,1,2$ trailing $0s$, respectively (and thus $n-i-j-k$ rows with $3$ trailing zeros), in how many ways can I create a matrix with $n_0, n_1, n_2, n_3$ rows with $0,1,2,3$ trailing zeros by adding a column to the right?
I had a hard time wrapping my head around this, so I reframed the question slightly differently. I translate a matrix to a sequence of $0$s-$3$s where the $i^{th}$ entry in the sequence is $x$ if the matrix has $x$ many trailing $0$s. Adding a column to the matrix is making a choice between incrementing each element of the sequence (representing a row to which a $0$ has been added, so there is one more trailing $0$), or resetting it to $0$ (representing a row to which a $1$ has been added, so there are no more trailing $0$s). I don't know why, but somehow this made it much simpler for me to understand it. If this isn't helping you personally, the thought process and calculations that follow this remain the same, just keep imagining the matrix.
So now the question is, given a sequence of $n$ elements in $\{0,1,2,3\}$, how many ways can you perform the following operation:
- you can either increment or reset any entry in the sequence
- you cannot increase any $3$s, they must all be reset (no $0000$s)
so that you end up with $n_0, n_1, n_2, n_3$ many $0$s, $1$s, $2$s, $3$s? We look at some cases:
- Since all $3$s are reset, we must obtain the $n_3$ many $3s$ by incrementing that many $2$s. But that means if $k < n_3$, then there are no possibilities. If $k \geq n_3$, then there are $\binom{k}{n_3}$ such choices. The remaining $k-n_3$ $2$s must be reset. Since $\binom{k}{n_3} = 0$ when $k < n_3$, the binomial coefficient sums up both cases.
- So now by the same logic, to obtain $n_2$ many $2$s, we must uptick that many $1$s, and reset the rest. Following the same logic, we get $\binom{j}{n_2}$ choices.
- Following the same logic, to get the $1$s, we uptick $\binom{i}{n_1}$ many $0$s and reset the rest.
- Just to verify, how many elements did we reset? $n-i-j-k + k-n3 + j-n_2 + j-n_1 = n - n_3 - n_2 - n_1 = n_0$, which is how many $0$s we needed.
So that means that $C_{i,j,k}$ is the product of the three binomial coefficients, and thus the relation is:
$$c(m, n_0, n_1, n_2, n_3) = \sum_{i,j,k \in \mathbb{N} \\ i+j+k \leq n} \binom{k}{n_3} \binom{j}{n_2} \binom{i}{n_1} \cdot c(m-1, i, j, k, n-i-j-k)$$
and $c(m, n_0, n_1, n_2, n_3) = 0$ if any $n_i = n$.
This is how far I've gotten. And if I didn't make any mistakes, I'm already happy about it. I do wonder if there is now a way to further reduce the calculation, since to calculate $c(m)$ I'm still using two sums, each of which goes through all combinations of $i,j,k$ that sum to $n$. I'm going to keep looking into it, but if anyone has any ideas until then, that would be much appreciated. Thanks again anon.
EDIT 2:
I think I found it. Let's use $A = (n_0,n_1,n_2,n_3)$ and $I = (i,j,k,n-i-j-k)$ to make the formulas easier to write. We will also omit all the summation bounds, but it's just $i,j,k \in \mathbb{N}$ s.t. $i+j+k \leq n$ everywhere. Then
$$c(m,A) - c(m-1, A) = \sum C_{i,j,k} (c(m-1,I) - c(m-2,I))$$
So now we can use this difference inside the sum on the right again, obtaining:
$$= \sum C_{i,j,k} (\sum C_{i,j,k} c(m-2,I) - c(m-3,I))$$
Note that we use $i,j,k$ in both sums, but they're their own indices. Technically, one should use $i_1,j_1,k_1$ in the first sum and $i_2,j_2,k_2$ for the second (etc.), but as long as we can keep track of them, we can simplify it that way. Either way, doing this over and over again, gives us:
$$= \sum C_{i,j,k} ( \sum C_{i,j,k} ( ... (\sum C_{i,j,k} (c(2,I) - c(1, I)))...))$$
where we have a total of $m-2$ summands. Now if we define $K(A) = \sum C_{i,j,k} (c(2,I) - c(1, I)))...))$, we can calculate that independently of the rest. So we can factorize it, and then we can factorize the first $m-3$ sums as well, which gives us:
$$c(m,A) - c(m-1,A) = K(A) (\sum C_{i,j,k})^{m-3} = K(A) \sigma^{m-3}$$
for $\sigma = \sum C_{i,j,k}$. Now we can use this recursively to calculate any $c(m,A) - c(m-x,A)$ and obtain parts of a geometric series with $x$ terms. In particular, for $x = m-2$, we obtain:
$$c(m,A) - c(2,A) = K(A) (\sigma^{m-3} + \sigma^{m-4} + ... + \sigma + 1)$$
Thus:
$$c(m,A) = K(A) (\sigma^{m-3} + ... + \sigma^{0}) + c(2,A)$$
Now, each of these components can be calculated easily without any recursion. So we get something that should calculate the correct number of valid matrices in polynomial time.