Consider the set of $5 \times 5$ matrices with $10$ entries equal to $1$ and the other $15$ entries equal to $0$. I would like to know how many such matrices have nonzero determinant. Is there a way to characterize them?

I experimented a little with some examples, but could not make much progress.


I have examined the $2^9=512$ matrices $3\times 3$. All possible distribution of $0$s and $1$s. The results are summarized in this matrix $$\left( \begin{array}{c|ccccc} 0 & 0 & 0 & 1 & 0 & 0 \\ 1 & 0 & 0 & 9 & 0 & 0 \\ 2 & 0 & 0 & 36 & 0 & 0 \\ 3 & 0 & 3 & 78 & 3 & 0 \\ 4 & 0 & 18 & 90 & 18 & 0 \\ 5 & 0 & 36 & 54 & 36 & 0 \\ 6 & 3 & 18 & 42 & 18 & 3 \\ 7 & 0 & 9 & 18 & 9 & 0 \\ 8 & 0 & 0 & 9 & 0 & 0 \\ 9 & 0 & 0 & 1 & 0 & 0 \\ \end{array} \right)$$ In the first column the number of $1$s; in the other $5$ columns the number of matrix having determinant $-2;\;-1;0;\;+1;\;+2$

For instance matrices with $5$ $1$s and $4$ $0$s with determinant $0$ are $54$ while those with determinant $1$ or $-1$ are $36$.

Do you see some regularity?

Hope this helps


This doesn't scale well, but should run quickly on anything up to $8\times 8$ matrices on modern hardware.

Let $D([k_1,k_2,\ldots,k_n])$ return a histogram of the determinants of an $n\times n$ matrix containing $k_1$ $1$'s in its first column, $k_2$ $1$'s in its second column, ..., and $k_n$ $1$'s in its $n$th column. Naturally, there are ${n \choose k_1} {n \choose k_2} \cdots {n \choose k_m}$ such matrices.

For $n = 2$, $$D([0,0]) = \left\{ 0: 1 \right\}$$ $$D([0,1]) = \left\{ 0: 2 \right\}$$ $$D([0,2]) = \left\{ 0: 1 \right\}$$ $$D([1,0]) = \left\{ 0: 2 \right\}$$ $$D([1,1]) = \left\{ -1: 1, 0: 2, 1: 1 \right\}$$ $$D([1,2]) = \left\{ -1: 1, 1: 1 \right\}$$ $$D([2,0]) = \left\{ 0: 1 \right\}$$ $$D([2,1]) = \left\{ -1: 1, 1: 1 \right\}$$ $$D([2,2]) = \left\{ 0: 1 \right\}$$

For each $n$ from $3$ to $n_{\max}$, where $n_{\max}$ is the size of the full matrix (5, in your case):

  1. generate all pairs $(k_1,k_2)$ with $0 \leq k_1 \leq n$, $0 \leq k_2 \leq n\left(n-1\right)$ such that $k_1 + k_2 \leq n_1$, where $n_1$ is the number of 1's in the matrix (10 in your case).
  2. for each $k_1$, produce $R(n,k_1)$, the set of all $n$-element row vectors containing $k_1$ 1's and $n-k_1$ 0's.
  3. for each $k_2$, produce $B(n,k_2)$, the set of all $n$-element row vectors whose elements are non-negative integers that sum to $k_2$.
  4. for each $(k_1,k_2)$ pair

    i. for each $r \in R(n,k_1)$ and each $b \in B(n,k_2)$

    1. Let $r$ be the topmost row of a matrix and let $b$ be the number of $1$'s in the columns of the $\left( n-1\right) \times n$ submatrix below the first row. For example, $r = [1,1,0]$, $b = [2,0,1]$ would have a top row of $[1\; 0\; 1]$, two $1$'s in the first column under the first row, zero $1$'s in the second column under the first row, and one $1$ in the third column under the first row.

    2. Suppose you have the matrix $$\left(\begin{array}[c] & 1 & 1 & 0 \\ \times & \times & \times \\ \times & \times & \times \end{array}\right)$$ with $b = [2,0,1]$. The histogram of all determinants for matrices of this type is given by $$H = 1\cdot D([0,1]) - 1\cdot D([2,1]) + 0\cdot D([2,0])$$ Since these are histograms, scalar multiplication by $0$ means moving all counts into the $0$ bin, scalar multiplication by $-1$ means negating the bins, and addition is accomplished through convolution. (If somebody knows how to word this better, please edit.)

    3. Add the histogram $H$ from (2) to a list associated with the vector $r+b$. For example, the above $H$ would be added to the list associated with $[3,1,1]$.

    ii. Compute $D(x)$ for all $n$-element vectors $x$ by letting $D(x)$ be the sum (convolution) of all histograms in the list associated with $x$.

The sum of $D(x)$ over all $n_{\max}$-element vectors $x$ yields the determinant histogram for an $n_{\max}\times n_{\max}$ matrix. The number of matrices with zero determinant will be the count in the $0$ bin; the number of matrices with nonzero determinant will be the sum of the counts in the remaining bins. Obviously, the two should sum to $n_{\max}^2 \choose n_1$.