I stumbled across the following formula when working on a research problem in theoretical computer science. I am looking for a simple proof of it, or any idea which might prove useful.

I checked its correctness up to $N=5$ with a computer. Brendan McKay (see comment) was able to check its correctness up to $N=8$.

This question was first asked on Maths StackExchange two weeks ago.

**Basic version**

Let $\mathcal M_N$ be the set of all 0-1 square matrices without any row/column of zeros (we want all the denominators to be non-zero in the formula below). One could also define $\mathcal M_N$ to be A227414. $$ \sum_{M \in \mathcal M_N} \frac{\det(M)^2 \cdot (-1)^{\|M\|_0 - N}} {\prod_{i=1}^N\Big(\sum_{j=1}^N M_{i,j}\Big)\prod_{j=1}^N\Big(\sum_{i=1}^N M_{i,j}\Big)} = 1 $$ where $\|M\|_0 = \sum_{i,j} M_{i,j}$ is the number of non-zero entry of $M$.

**Weighted generalization**

Note that the formula is also true when "positive weights" are associated to every coefficient. Let $P$ and $Q$ be two matrices with positive coefficients. Alternatively one can think of $P$ and $Q$'s coefficients to be indeterminates ($P_{i,j} = x_{i,j}$ and $Q_{i,j} = y_{i,j}$ for all $i,j$).

Let $M \circ P$ (resp. $M \circ Q$) be the elementwise product of $M$ and $P$ (resp. $Q$).

$$ \sum_{M \in \mathcal M_N} (-1)^{\|M\|_0 - N} \cdot \frac{\det(P \circ M)} {\prod_{j=1}^N\sum_{i=1}^N [P \circ M]_{i,j}} \cdot \frac{\det(Q \circ M)} {\prod_{i=1}^N\sum_{j=1}^N [Q \circ M]_{i,j}} = 1 $$

This version might help to understand how the sum does simplify. When $P$ and $Q$'s coefficients are indeterminates, the sum is a rational function which is identically equal to 1.

Here is some python code to check (empirically) my claim (slow when $N > 4$).

```
from sympy import Matrix, Symbol
from itertools import product
import random
N = 2
P = Matrix([random.randint(1,100) for _ in range(N*N)]).reshape(N,N)
Q = Matrix([random.randint(1,100) for _ in range(N*N)]).reshape(N,N)
print(P)
print(Q)
prettyprint = "= (-1)^%d * (%d / %d) * (%d / %d)"
result = 0
for p in product([0,1], repeat=N**2):
MP = Matrix(p).reshape(N, N).multiply_elementwise(P)
MQ = Matrix(p).reshape(N, N).multiply_elementwise(Q)
dP, dQ = MP.det(), MQ.det()
if dP * dQ != 0:
vP, vQ = 1, 1
for i in range(N):
vP *= sum(MP[:,i])
vQ *= sum(MQ[i,:])
val = (-1) ** (sum(p)-N) * dP * dQ / (vP * vQ)
print(p, val, prettyprint%(sum(p)-N, dP, vP, dQ, vQ))
result += val
print(result)
```

And for those of you who don't want to run this program, here is one output.

```
Matrix([[19, 33], [49, 7]])
Matrix([[11, 53], [7, 86]])
(0, 1, 1, 0) 1 = (-1)^0 * (-1617 / 1617) * (-371 / 371)
(0, 1, 1, 1) -77/1240 = (-1)^1 * (-1617 / 1960) * (-371 / 4929)
(1, 0, 0, 1) 1 = (-1)^0 * (133 / 133) * (946 / 946)
(1, 0, 1, 1) -817/3162 = (-1)^1 * (133 / 476) * (946 / 1023)
(1, 1, 0, 1) -77/2560 = (-1)^1 * (133 / 760) * (946 / 5504)
(1, 1, 1, 0) -2597/4352 = (-1)^1 * (-1617 / 2244) * (-371 / 448)
(1, 1, 1, 1) -42665/809472 = (-1)^2 * (-1484 / 2720) * (575 / 5952)
1
```

**An easier/intermediate formula?**

The two formula above are not entirely satisfying, because of the no-zero-row/column constraint in the sum.

Let $\mathcal H_N$ be the set of all $N$ by $N$ matrices, such that coefficient $(i,j)$ is either $a_{i,j}$ or $b_{i,j}$.

For all $M \in \mathcal H_N$, define $A(M)$ to be the number of $a_{i,j}$ coefficients in $M$.

Intuitively, $\mathcal H_N$ is an hypercube and $(-1)^{A(M)}$ tells you if you are on an even or an odd "level".

Let $P$ and $Q$ be two square matrices of size $N$, where $P_{i,j} = x_{i,j}$ and $Q_{i,j} = y_{i,j}$.

$$ \sum_{M \in \mathcal H_N} (-1)^{A(M)} \cdot \frac{\det(P \circ M)} {\prod_{j=1}^N\sum_{i=1}^N [P \circ M]_{i,j}} \cdot \frac{\det(Q \circ M)} {\prod_{i=1}^N\sum_{j=1}^N [Q \circ M]_{i,j}} = 0 $$

Which means that the sum on the odd and even "levels" of the hypercube are equal.

I believe this formula might be easier to prove, because of additionnal symmetries. Sam Hopkins' idea to use a sign reversing involution (see comment) might be helpful.

And perhaps it is a first step towards one of the formula above (where we need to subtract the terms with a row/column of $a$'s).

Here is some python code to check (empirically) my claim (slow when $N > 4$).

```
from sympy import Matrix
from itertools import product
import random
prettyprint = "= (%d / %d) * (%d / %d)"
def getVal(v):
global P, Q, prettyprint
MP = Matrix(v).reshape(N, N).multiply_elementwise(P)
MQ = Matrix(v).reshape(N, N).multiply_elementwise(Q)
dP, dQ = MP.det(), MQ.det()
if dP * dQ == 0: return 0
vP, vQ = 1, 1
for i in range(N):
vP *= sum(MP[:,i])
vQ *= sum(MQ[i,:])
val = dP * dQ / (vP * vQ)
print(val, prettyprint%(dP, vP, dQ, vQ))
return val
N = 2
H = [[random.randint(1,100) for _ in range(2)] for i in range(N*N)]
P = Matrix([random.randint(1,100) for _ in range(N*N)]).reshape(N,N)
Q = Matrix([random.randint(1,100) for _ in range(N*N)]).reshape(N,N)
print(H)
print(P)
print(Q)
result = 0
for p in product([0,1], repeat=N**2):
print(p, end=" ")
v = [ H[i][x] for i,x in enumerate(p)]
result += getVal(v) * (-1) ** int(sum(p))
print(result)
```

And for those of you who don't want to run this program, here is one output.

```
[[9, 52], [11, 59], [14, 41], [34, 93]]
Matrix([[26, 19], [46, 29]])
Matrix([[83, 21], [36, 24]])
(0, 0, 0, 0) 164595168/4703083825 = (96128 / 1049210) * (493128 / 1290960)
(0, 0, 0, 1) 445610545/3950948198 = (496502 / 2551468) * (1550880 / 2675808)
(0, 0, 1, 0) -24390009/3154893688 = (-163450 / 2533400) * (268596 / 2241576)
(0, 0, 1, 1) 727415911/51716164040 = (236924 / 6160720) * (1326348 / 3626424)
(0, 1, 0, 0) 5083920/3367826693 = (-491200 / 1849946) * (-14904 / 2621520)
(0, 1, 0, 1) -54813491/10541005478 = (-90826 / 3352204) * (1042848 / 5433696)
(0, 1, 1, 0) 601772499/5328265880 = (-1883482 / 4466840) * (-1219212 / 4551912)
(0, 1, 1, 1) 4820101/1199800856 = (-1483108 / 8094160) * (-161460 / 7364088)
(1, 0, 0, 0) 42513838767/149126935925 = (1198476 / 2385220) * (3405432 / 6002040)
(1, 0, 0, 1) 116044834723/250555941884 = (3511748 / 5800376) * (9516888 / 12440592)
(1, 0, 1, 0) 24887838735/336049358857 = (938898 / 3869410) * (3180900 / 10421724)
(1, 0, 1, 1) 419726686285/2203457293574 = (3252170 / 9409628) * (9292356 / 16860276)
(1, 1, 0, 0) 67073493/1168097623 = (611148 / 4205572) * (2897400 / 7332600)
(1, 1, 0, 1) 18295610183/80432973676 = (2924420 / 7620728) * (9008856 / 15198480)
(1, 1, 1, 0) -545598897/35835002665 = (-781134 / 6822466) * (1693092 / 12732060)
(1, 1, 1, 1) 166078396717/3536747545430 = (1532138 / 12362684) * (7804548 / 20597940)
0
```

*[Edit 05/20]** I realized that the formula is true with two different weights (before we had $P = Q$). The description has been updated accordingly.*

*[Edit 05/24]** I included Timothy Chow's remark (we can choose $P$ and $Q$'s coefficients to be indeterminates, and get a rational function identically equal to 1).*

*[Edit 05/24]** I updated the description of the basic version to adress Brendan McKay's comment. Before the set $\mathcal M_N$ was (awkwardly) defined as the set of invertible 0-1 matrices.*

*[Edit 05/25]** I included a new formula, which might be an easier/intermediate step.*

13more comments