TITLE: Weight enumerator classifiers
QUESTION [8 upvotes]: Let $f(x,y)$ be a polynomial with integer coefficients. What conditions guarantee that this is the weight enumerator of a binary linear code of size $n$ and dimension $k$?
I’m almost certain that the answer to this question is unknown...so instead i’ll settle for anything that is conjectural.
There’s a list of necessary conditions:

$f$ must be homogeneous of degree $n$ with non-negative coefficients.

The $x^n$ coefficient has to be $1$ since the zero vector is the unique weight $0$ vector.

The $y^n$ coefficient has to be $0$ or $1$ since the all $1$’s vector either belongs to the code or doesn’t.

The sum of the coefficients has to be $2^k$ since every vector has a unique weight and so is counted exactly once by some coefficient.

The MacWilliams transform ($g(x,y) = \frac{1}{2^k}f(x+y,x-y)$) has to have all of the above properties but with coefficient sum $2^{n-k}$ since if $f$ corresponds to a code then $g$ would correspond to the dual code.


Are there any more necessary conditions missing?

REPLY [4 votes]: This answer has grown so split it into sections. So, let me summarize.
First in Section 1 we give a counterexample showing more conditions are needed to guarantee we have the weight enumerator of a linear code. In Section 2 we show that the conditions in the question do classify weight enumerators for constant weight linear codes. Finally in Section 3 we give some additional necessary conditions (but not a complete solution).
Section 1. A "MacWilliams coincidence" example:
Let $f(x,y) = \sum_{j=0}^n a_j x^{n-j}y^j$. One other simple condition not in the question is $a_j \leq \binom{n}{j}$. But we also need some lower bounds of the coefficients $a_j$.
Consider the nonlinear code
\begin{align*}
    00000000 & & 11111111 \\
    11000000 & & 00111111 \\
    10100000 & & 01011111 \\
    10010000 & & 01101111 \\
    10001000 & & 01110111 \\
    10000100 & & 01111011 \\
    10000010 & & 01111101 \\
    10000001 & & 01111110
\end{align*}
which is binary of length $8$ with $16$ elements.
It's weight enumerator is
$$ f(x,y) = x^8 + 7x^6y^2 + 7x^2y^6 + y^8$$
and
$$ \frac{1}{16}f(x+y, x-y) = f(x,y).$$
This example is in "The MacWilliams identities for nonlinear codes" by MacWilliams, Sloane, and Goethals which can be viewed on Sloane's webpage.
We see $f$ satisfies all the conditions we have listed so far.
However, $f$ cannot be the weight enumerator of any linear code.
Indeed if it were for some linear code then $u+v$ must have weight $2$ for any two codewords $u$ and $v$ of weight $2$.
This means for any two weight $2$ codewords $u$ and $v$ they have exactly one coordinate in common.
We may assume the first two weight $2$ codewords are $11000000$ and $10100000$.
If the next weight $2$ codeword is $10010000$, then $11110000$ would be a codeword.
Alternatively the next weight $2$ codeword could be $01100000$, but then we cannot complete to seven codewords of weight $2$ without forcing a codeword on weight $4$.
In additional to the conditions in the question we need some lower bound on coefficients. We see here that the seven codewords of weight $2$ force the existence of a weight $4$ codeword. (I guess the above shows if $a_2 > 3$, then $a_4 > 0$.)
Section 2. MacWilliams is enough for constant weight:
A constant weight linear is a linear code where all codewords have the same weight (with the exception of the all zero codeword).
It is known that any $k$-dimensional constant weight binary linear code has generator matrix whose columns consist (with possible replication allowed) of all nonzero binary words of length $k$ along with zero columns.
For example, the matrix
$$
\begin{bmatrix} 
1 & 0 & 1 & 0 & 1 & 0 & 1 & 1 & 0 & 1 \\
0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & 1 & 1
\end{bmatrix}$$
generates $2$-dimension constant weight of weight $6$.
So, the weight generator of a constant weight linear code looks like
$$f(x,y) = x^n + (2^{k}-1)x^{n-m2^{k-1}}y^{m2^{k-1}}$$
for some $k$, $m$, and $n$.
It turns out that this is the only possible way to satisfy our conditions with only $x^n$ and one other monomial.
Assume $f(x,y) = x^n + (2^{k}-1)x^{n-a}y^a$ satisfies MacWilliams in the sense that
$$\frac{1}{2^k}f(x+y,x-y) = \frac{1}{2^k} \left( (x+y)^n + (2^k - 1)(x+y)^{n-a}(x-y)^a\right)$$
has integer coefficients.
This would mean that
$$\frac{1}{2^k} \left( (x+y)^n - (x+y)^{n-a}(x-y)^a\right)$$
has integer coefficients.
The coefficient of $x^{n-1}y$ in
$$(x+y)^n - (x+y)^{n-a}(x-y)^a$$
is $2a$.
Hence, $2^k$ divides $2a$ and so $a = m2^{k-1}$.
Section 3. some (easy) lower bounds:
Here are two fairly simple conditions based off of $a_1$ and $a_{n-1}$ to get lower bounds on the coefficients.
Let $[n] = \{1,2,\dots, n\}$ and let $\binom{A}{j}$ denote all $j$-element subsets of a set $A$. We let $\{e_i : i \in [n]\}$ denote the standard basis. For any $B \subseteq [n]$ set $e_B = \sum_{i \in B} e_i$. Assume $f(x,y)$ is the weight enumerator of a linear binary code $C$. Then there is some $A \subseteq [n]$ with $|A| = a_1$ such that $e_i \in C$ if and only if $i \in A$. It follows that $e_B \in C$ for $B \subseteq A$. So, $e_B$ is a codeword of weight $j$ for each $B \in \binom{A}{j}$. Hence, we get the condition
$$\binom{a_1}{j} \leq a_j$$
for each $1 \leq j \leq n$.
Also, we have $A \subseteq [n]$ with $|A| = a_{n-1}$ such that $e_{[n]} + e_i \in C$ if and only if $i \in A$. Now for any $B \subseteq A$ we have
$$\sum_{i \in B} (e_{[n]} + e_i) = |B|e_{[n]} + e_B$$
which is either $e_B$ or $e_{[n]} + e_B$ depending on the parity of $|B|$.
Hence, we have
$$\binom{a_{n-1}}{2j} \leq a_{2j}$$
and
$$\binom{a_{n-1}}{2j+1} \leq a_{n-2j-1}.$$
Ideally this sort of idea could be continued in a more complicated way with $a_2, a_3, \dots$ for codes with larger minimum distance. But this at least cuts down the candidate space some from the conditions in the original question. There are certainly more conditions. As we saw earlier $a_2 > 3$ implies $a_4 > 0$. It would be nice to find some rule saying $a_2 > m$ implies $a_4 > \phi(m)$ for some $\phi$.