46.07.01 · information-theory / algebraic-coding-advanced

Weight Enumerators, the MacWilliams Identity, and the Linear-Programming Bound

shipped3 tiersLean: none

Anchor (Master): MacWilliams & Sloane 1977 The Theory of Error-Correcting Codes (North-Holland) Chapter 5-7; Cover & Thomas 2006 Elements of Information Theory 2e (Wiley) Chapter 7; Delsarte 1973 An Algebraic Approach to the Association Schemes of Coding Theory (the LP bound, Delsarte theory, MRRW bound)

Intuition Beginner

Every codeword in a linear code has a "weight" — the number of positions where its symbol is not zero. A codeword like has weight 3 because three positions are nonzero. The all-zero codeword has weight 0. Weight measures how far a codeword is from the origin.

For a code with many codewords, listing every individual weight is tedious. Instead, count how many codewords have weight 0, weight 1, weight 2, and so on up to the code length. This count is the weight distribution — a histogram with one entry per possible weight. A code with good error-correcting ability has most nonzero codewords at high weight.

Pack this histogram into a polynomial called the weight enumerator. If three codewords have weight 5, the polynomial contains the term . The coefficient of tells you how many codewords have weight . This single polynomial encodes the entire weight structure of the code.

Here is the surprise: the weight enumerator of a linear code completely determines the weight enumerator of its dual code. This is the MacWilliams identity, discovered by Jessie MacWilliams in 1963. Given one polynomial, you compute the other by a substitution — no need to look at the dual code at all.

The MacWilliams identity produces linear constraints on the weight distribution. Combined with the requirement that weight counts be non-negative, these constraints form a linear program. Solving it gives the tightest known upper bounds on how large a code can be for a given length and minimum distance. This is the linear-programming bound.

Visual Beginner

Figure: two histograms side by side. The left histogram shows the weight distribution of the binary [7,4,3] Hamming code — bars at weights 0, 3, 4, and 7 with heights 1, 7, 7, and 1. The right histogram shows its dual [7,3,4] simplex code — bars at weights 0 and 4 with heights 1 and 7. An arrow between them is labelled "MacWilliams identity" to indicate that the right histogram is computed from the left by the substitution formula.

Code Total
[7,4,3] Hamming 1 0 0 7 7 0 0 1 16
[7,3,4] Dual 1 0 0 0 7 0 0 0 8

The Hamming code has 16 codewords; its dual has 8. The MacWilliams identity connects these two rows by a single algebraic formula. Notice that the dual has no codewords of weight 1, 2, 3, 5, 6, or 7 — a structural fact that follows from the identity, not from inspecting the dual directly.

Worked example Beginner

The binary [7,4,3] Hamming code has length 7, dimension 4, and minimum distance 3. It contains codewords. Its weight distribution is well known: one codeword of weight 0, seven of weight 3, seven of weight 4, and one of weight 7. No codewords have weight 1, 2, 5, or 6.

Step 1. Write the weight enumerator. Each coefficient records the count at that weight:

The constant term is 1 (one zero vector). The coefficient of is 7. Setting gives , the total number of codewords — a useful sanity check.

Step 2. The dual code is a [7,3,4] code with 8 codewords. Its weight distribution has one codeword of weight 0 and seven of weight 4:

Step 3. Verify the MacWilliams identity at two test points. For binary codes (, , ), the identity reads:

At : the left side is . The right side is . Both sides match.

At : the left side is . The right side is . Both sides match.

Step 4. Check at one more point for confidence. At , the left side gives . The right side requires computing . Working in 2187ths: . Then . Both sides match again.

The identity holds at all test points, and a full symbolic expansion confirms it for every . From the primal weight enumerator alone, we recovered the dual's entire weight distribution — this is the power of the MacWilliams identity.

Check your understanding Beginner

Formal definition Intermediate+

Let be a linear code over the finite field .

Definition (Hamming weight). The Hamming weight of a vector is the number of nonzero coordinates:

Definition (Weight distribution). The weight distribution of is the sequence where

By convention, since the zero vector is always a codeword. For an code, for because the minimum weight of any nonzero codeword equals the minimum distance (see 40.06.06).

Definition (Weight enumerator). The weight enumerator of is the polynomial

This is a polynomial of degree at most with non-negative integer coefficients, satisfying and .

Definition (Dual weight enumerator). If is the dual code of , its weight enumerator is

where .

Counterexamples to common slips

  • The weight enumerator does not determine the code. Two non-equivalent codes can share the same weight distribution. The enumerator records the histogram of weights but not the geometric arrangement of codewords in . Knowing tells you how many codewords sit at each distance from the origin, but not which subspaces they span.

  • The MacWilliams identity requires linearity. For a nonlinear code, there is no dual code in the usual sense, and the identity does not apply directly. Delsarte's association-scheme theory extends MacWilliams-type inequalities to certain nonlinear codes, but the formulation uses the distance distribution rather than the weight distribution.

  • is the dual code's enumerator, not the reciprocal. The notation refers to the weight enumerator of the entirely separate code . It does not mean or .

Key theorem with proof Intermediate+

Theorem (MacWilliams identity). Let be an linear code over with weight enumerator . The weight enumerator of the dual code is

Proof. The proof uses additive characters on and the Poisson summation formula.

Characters. Let be the characteristic of . Define the additive character by where is the trace from to . For vectors , define . The key properties are: for all , and for , .

Hadamard transform. For any function , the Hadamard transform is .

Poisson summation. For any subspace :

This follows from the character orthogonality: the left side equals because the inner sum is if and otherwise.

Transform of the weight function. Take . For with , separate coordinates by whether or :

  • If : the sum over gives .
  • If : the sum gives , using for .

Therefore:

Combine. Apply Poisson summation with the roles of and swapped (using ):

Factor out and group by weight:

Bridge. The MacWilliams identity is the central insight of algebraic coding theory: the weight structures of a code and its dual are not independent but are two views of the same algebraic object, linked by a substitution in the weight enumerator polynomial. This identity builds toward the linear-programming bound developed later in this unit, where the MacWilliams constraints on the dual weight enumerator generate the inequalities that bound . It appears again in the theory of association schemes 40.06.06, where Delsarte's inequalities generalise MacWilliams to nonlinear codes. The identity generalises to higher-order weight enumerators for codes over rings and to the split weight enumerator for arbitrary partitions. The foundational reason it works is the Poisson summation formula — the same harmonic-analysis tool that underlies the Fourier inversion theorem. Putting these together, the MacWilliams identity is not a computational convenience but a duality principle with the same structural depth as the Fourier transform. The bridge is that algebraic coding theory gains its power from converting combinatorial questions about code size into algebraic questions about polynomials.

Exercises Intermediate+

Lean formalization Intermediate+

Mathlib has VectorSpace, FiniteField, and Subspace for finite-dimensional vector spaces over finite fields, and the Hamming distance on Fin-valued vectors exists in contrib. However, there is no definition of linear code as a Subspace equipped with a minimum-distance field, no weight enumerator polynomial, no dual-code weight enumerator, and no MacWilliams identity. The Krawtchouk polynomials, the Poisson summation formula for finite abelian groups, and the LP bound are entirely absent. A Codex.CodingTheory.WeightEnumerator module defining the weight distribution as a function on a Subspace representation of a code, the weight enumerator as a polynomial over the integers, and the MacWilliams identity as a polynomial identity derived from character theory would be the load-bearing first step. This unit ships without a Lean module.

Advanced results Master

Krawtchouk polynomials

The MacWilliams identity has a natural expansion in terms of the Krawtchouk polynomials, which are the orthogonal polynomials for the binomial distribution on . For a code over , the Krawtchouk polynomial of degree is

The generating function identity is the key link to MacWilliams:

This identity means that when we expand the Hadamard transform of , the coefficients are exactly the Krawtchouk polynomials evaluated at the weight. The MacWilliams identity in Krawtchouk form becomes

which is a linear system relating the weight distribution of to that of . By the orthogonality of Krawtchouk polynomials with respect to the weight on , the inverse relation is

The Krawtchouk polynomials satisfy a three-term recurrence

starting from and . This recurrence provides an efficient way to compute the linear constraints for the LP bound without expanding the full substitution.

The linear-programming bound

The MacWilliams identity generates linear inequalities that bound , the maximum number of codewords in any code of length and minimum distance over . The formulation proceeds as follows.

Consider a linear code . Its weight distribution satisfies:

  1. .
  2. for .
  3. for all .
  4. for all (since each counts codewords in ).

By the Krawtchouk form of MacWilliams, constraint 4 becomes

The LP bound. Maximise subject to:

The maximum satisfies .

For the general (nonlinear) case, Delsarte showed that the distance distribution of any code satisfies the same MacWilliams-type inequalities through the association-scheme framework. The Delsarte inequalities state that the "inner distribution vector" of any code is positive semidefinite with respect to the Krawtchouk transform, and the LP bound applies to all codes, not just linear ones.

The LP bound dominates the Hamming (sphere-packing) bound and the Singleton bound for most parameter ranges. For example, for binary codes of length and : the Hamming (sphere-packing) bound gives by counting disjoint balls of radius ; the Plotkin bound gives ; the LP bound gives . The true value is (achieved by the nonlinear Nordstrom-Robinson code), so the LP bound is tight here.

The LP bound is computed by solving a linear program with non-negative unknowns and roughly inequality constraints. Modern LP solvers handle this in milliseconds even for in the hundreds. The bound is also useful in the negative: when a code is constructed whose size matches the LP bound, the code is provably optimal and no further search can improve it.

The McEliece-Rodemich-Rumsey-Welch bound

The LP bound gives numerical upper bounds for fixed . For the asymptotic regime, McEliece, Rodemich, Rumsey, and Welch (1977) solved the LP dual problem analytically to obtain the tightest known asymptotic upper bound on the rate of a binary code with relative distance .

Theorem (MRRW bound). For binary codes with relative distance :

where is the binary entropy function.

The proof constructs an optimal dual feasible solution for the LP by choosing coefficients from a carefully designed polynomial expressed in the Krawtchouk basis. The polynomial satisfies the positivity constraints by construction, and the objective value evaluates to the stated bound via the Christoffel-Darboux formula for orthogonal polynomials. The key technical insight is that the LP dual variables correspond to a polynomial of bounded degree that is non-negative on and whose Krawtchouk expansion coefficients are also non-negative. The MRRW construction picks for a suitable Krawtchouk polynomial , exploiting the squaring trick to enforce both positivity conditions simultaneously.

The MRRW bound sits between the Gilbert-Varshamov lower bound and the McEliece et al. first bound. For , MRRW gives while the GV bound gives , so at this point the bounds nearly meet. For larger , a gap remains between the GV lower bound and the MRRW upper bound, and closing this gap is one of the central open problems in coding theory.

Synthesis. The weight enumerator compresses the combinatorial weight distribution into a polynomial, and the MacWilliams identity reveals that this polynomial for the dual code is obtained by a substitution — the central insight that one code's structure determines its dual's. The Krawtchouk polynomials are the spectral decomposition of this duality: they diagonalise the MacWilliams transform, the bridge is that the linear constraints become inequalities on the primal weight distribution when expanded in the Krawtchouk basis, and the LP bound extracts numerical upper bounds on from these inequalities. This is exactly the operational content of the MacWilliams identity: algebraic structure constrains code size. The identity generalises to the split weight enumerator and to codes over rings, and appears again in the invariant-theory classification of self-dual codes via Gleason's theorem. The foundational reason the LP bound is so powerful is that Delsarte's association-scheme framework extends MacWilliams-type inequalities to all codes, not just linear ones, putting these together into a unified bound that dominates classical combinatorial bounds. The arc from weight distribution to polynomial identity to linear program demonstrates that the deepest bounds in coding theory come not from counting arguments alone but from the algebraic structure of the Hamming scheme.

Full proof set Master

Proposition (Krawtchouk expansion of MacWilliams). Let be an linear code over with weight distribution and dual weight distribution . Then for each :

Proof. From the MacWilliams identity:

Write . Then , so:

Apply the generating function identity :

Comparing coefficients of on both sides gives .

Proposition (LP constraint from MacWilliams). For a binary code, the weight distribution satisfies

for each .

Proof. By the Krawtchouk expansion, . Since for and :

Since (it counts codewords in the dual) and :

Rearranging: . For , and the constraint is , which is automatically satisfied. For , , giving , a nontrivial inequality relating the weight distribution to the code parameters.

Proposition (MacWilliams for the binary simplex code). The binary simplex code of dimension has parameters and every nonzero codeword has weight . Its dual is the Hamming code. Verify the MacWilliams identity connects their weight enumerators.

Proof. The simplex code has weight enumerator

Its dual is the Hamming code with parameters . By MacWilliams:

For (): and

recovering the weight enumerator of the [7,4,3] Hamming code. The general case is verified by the same substitution.

Connections Master

  • 40.06.06 — Linear codes, the Hamming/Singleton/Gilbert-Varshamov bounds; this unit extends that material by using the algebraic structure of the dual code to obtain tighter bounds via the MacWilliams identity.
  • 46.01.01 — Entropy and the chain rule; the MRRW bound is expressed in terms of the binary entropy function , and the asymptotic GV bound is the information-theoretic lower bound that the LP upper bound constrains from above.
  • 01.01.01 — Vector spaces over fields; the entire theory rests on and being complementary subspaces of .
  • 46.07.02 — Future unit on algebraic-geometry codes, whose weight enumerators are the primary examples where the LP bound is tested and sometimes beaten.
  • 37.07.02 — Cramer's theorem and large deviations; the GV bound has a large-deviations interpretation (random codes achieve distance with high probability when is below the GV threshold), complementing the deterministic LP upper bound.
  • 40.06.07 — Future unit on BCH and Reed-Solomon codes; their weight enumerators are special cases where MacWilliams can be computed in closed form.

Historical & philosophical context Master

Jessie MacWilliams discovered the identity bearing her name in 1963, while working as a graduate student at Harvard under the supervision of Andrew Gleason. Her original proof appeared in "A theorem on the distribution of weights in a systematic code" (Bell System Technical Journal 42, 1485-1505). The result was striking because it showed that the weight distribution of a linear code and its dual are not independent — knowing one determines the other completely. At the time, this was one of the deepest results in algebraic coding theory, connecting the combinatorial structure of codes to polynomial algebra.

The generalisation to non-binary alphabets and to higher-order weight enumerators followed quickly, with MacWilliams herself extending the result to codes over in her 1969 monograph with Neil Sloane. The connection to characters and the Poisson summation formula (the proof presented in this unit) is due to several authors, with the cleanest formulation appearing in MacWilliams and Sloane's 1977 book The Theory of Error-Correcting Codes (North-Holland), which remains the standard reference.

Philippe Delsarte's 1973 thesis "An Algebraic Approach to the Association Schemes of Coding Theory" (Philips Research Reports Supplement 10) placed the MacWilliams identity in a far more general framework. Delsarte showed that the Hamming scheme — the association scheme on where two vectors are in relation if their Hamming distance is — carries enough algebraic structure to derive MacWilliams-type inequalities for any code, not just linear ones. The "inner distribution" of a code (the distance histogram, not the weight histogram) satisfies the same positivity constraints under the Krawtchouk transform, giving the Delsarte inequalities. This was a conceptual breakthrough: it showed that the MacWilliams identity is not really about duality of subspaces but about the algebraic structure of the ambient space itself.

Delsarte's framework also unified several previously disconnected results. The sphere-packing bound and the Singleton bound become special cases of the LP bound obtained by choosing particular feasible solutions. The Johnson bound, which improves on the Hamming bound by considering the distance distribution rather than just disjoint balls, is another specialisation. This unification gave coding theorists a single optimisation problem that subsumed all known combinatorial bounds.

The linear-programming bound is a direct consequence of Delsarte's framework. The bound was first applied numerically in the 1970s, but the crowning achievement came in 1977 when McEliece, Rodemich, Rumsey, and Welch solved the LP dual analytically to obtain the MRRW bound. Their result remains the tightest known asymptotic upper bound for binary codes for most values of , and closing the gap between the MRRW upper bound and the Gilbert-Varshamov lower bound remains one of the central open problems in information theory.

Bibliography Master

@book{macwilliams-sloane1977,
  author    = {MacWilliams, F. J. and Sloane, N. J. A.},
  title     = {The Theory of Error-Correcting Codes},
  publisher = {North-Holland},
  year      = {1977},
}
@book{cover-thomas2006,
  author    = {Cover, T. M. and Thomas, J. A.},
  title     = {Elements of Information Theory},
  edition   = {2nd},
  publisher = {Wiley},
  year      = {2006},
}
@article{mceliece-rodemich-rumsey-welch1977,
  author  = {McEliece, R. J. and Rodemich, E. R. and Rumsey, H. and Welch, L. R.},
  title   = {New Upper Bounds on the Rate of a Code via the Delsarte-{M}ac{W}illiams Inequalities},
  journal = {IEEE Trans. Inform. Theory},
  volume  = {IT-23},
  pages   = {157--166},
  year    = {1977},
}
@phdthesis{delsarte1973,
  author = {Delsarte, P.},
  title  = {An Algebraic Approach to the Association Schemes of Coding Theory},
  school = {Universit\'e Catholique de Louvain},
  year   = {1973},
  note   = {Philips Res. Rep. Suppl. 10},
}
@article{macwilliams1963,
  author  = {MacWilliams, F. J.},
  title   = {A Theorem on the Distribution of Weights in a Systematic Code},
  journal = {Bell System Technical Journal},
  volume  = {42},
  pages   = {1485--1505},
  year    = {1963},
}