Complete update...
OK, a method that solves it directly and is extremely fast for all sizes.
Since we are only concerned with parity relations, the only thing that matters is whether an element of $B_{N}$ is odd or even. Let an odd element be marked by 1
and an even element be marked by 0
. Call the matrix $P_{N}$ to denote a parity matrix. There are only $2^{16}=65536$ unique parity matrices. Of those, we can identify in advance the ones that satisfy the parity constraint.
tups = Tuples[{0, 1}, 16];
cmb[vec_] := Module[{mat = Partition[vec, 4], row, col},
row = Equal @@ (Boole /@ OddQ /@ Total /@ Rest@mat);
col = Equal @@ (Boole /@ OddQ /@ Total /@ Rest@Transpose@mat);
row && col
]
goodTups = Select[tups, cmb[#] &];
There are 4096 of them. but we don't actually care about the details of those matrices, just the number of odd elements that they have. So tally them up, counting the number with 0 odd elements, 1, etc.
qt = Tally[Total /@ goodTups] // Sort
(* {{0, 1}, {1, 1}, {3, 35}, {4, 140}, {5, 273}, {6, 448}, {7, 715},
{8,870}, {9, 715}, {10, 448}, {11, 273}, {12, 140}, {13, 35},
{15, 1}, {16, 1}} *)
Now we need a function that calculates how many permutations of integers satisfy the constraint that they sum to $N$, and that the number of odd elements = $N_{o}$ (and therefore number of even elements is $N_{e}=N-N_{o}$). Note that all odd numbers can be represented as $2i+1$ and even numbers as $2k$, so write
$$
(2i_{1}+1)+...+(2i_{N_{o}}+1)+2k_{1}+...+2k_{N_{e}}=N
$$
$$
2i_{1}+...+2i_{N_{o}}+2k_{1}+...+2k_{N_{e}}=N-N_{o}
$$
$$
i_{1}+...+i_{N_{o}}+k_{1}+...k_{N_{e}}=\frac{N-N_{o}}{2}
$$
We can count those using the property that the number of perms of integers with 16 elements summing to $m$ is
$$
\binom{m+15}{15}
$$
Note that if $m$ is fractional, let the answer be zero.
numPPO[n_, no_] := If[EvenQ@(n - no), Binomial[(n - no)/2 + 15, 15], 0]
Wrap it up into a function
numParityPerms[n_] := Total@Map[numPPO[n, #[[1]]]*#[[2]] &, qt]
Running it for $N$ from 1 to 15 gives this table. The third column is the ratio of perms satisfying the constraint to total perms. Generating the table is instantaneous.
$$
\left(
\begin{array}{ccc}
0 & 1 & 1 \\
1 & 1 & \frac{1}{16} \\
2 & 16 & \frac{2}{17} \\
3 & 51 & \frac{1}{16} \\
4 & 276 & \frac{23}{323} \\
5 & 969 & \frac{1}{16} \\
6 & 3504 & \frac{146}{2261} \\
7 & 10659 & \frac{1}{16} \\
8 & 30954 & \frac{469}{7429} \\
9 & 81719 & \frac{1}{16} \\
10 & 205040 & \frac{466}{7429} \\
11 & 482885 & \frac{1}{16} \\
12 & 1088100 & \frac{465}{7429} \\
13 & 2340135 & \frac{1}{16} \\
14 & 4850640 & \frac{13474}{215441} \\
15 & 9694845 & \frac{1}{16} \\
\end{array}
\right)
$$
Note the regularity in the third column. All odd values of $N$ result in the ratio being $1/16$. By fiddling around with the even number ratio terms I stumbled onto an orderly relationship, which leads to a function r[ ]
Even terms only for the ratio from the table above:
je = {1, 2/17, 23/323, 146/2261, 469/7429, 466/7429, 465/7429};
Ratios@(je - 1/16);
(* {1/17, 3/19, 5/21, 7/23, 9/25, 11/27} *)
From this we can derive
r[0] = 1;
r[n_?OddQ] = 1/16;
r[n_?EvenQ] := (r[n - 2] - 1/16) (n - 1)/(n + 15) + 1/16;
parityPermsR[n_] := Binomial[n + 15, 15] r[n];
While not formally proven, it checks out to as large a number as will compute.
parityPermsR[2001] == numParityPerms[2001] // Timing
(* 0., True *)
Partition[IntegerPartitions[n + 16, {16}] - 1, 4]
to generate matrix candidates, but then you also need to account for $16!$ permutations. $\endgroup$n
in my snippet with the $N$ in the OP, e.g.Partition[IntegerPartitions[17 + 16, {16}] - 1, 4]
to generate (some of) those matrices whose entries sum up to $17$. $\endgroup$