Weight Enumerators and Distributions

The weight distribution of a code is the multiplicity of each Hamming weight among its codewords; the weight enumerator is the same data as a polynomial. Coefficients are kept as exact BigInt values, since they grow like the size of the code.

Enumeration uses bit-packed Gray-code sweeps and the result is cached on the code. For a high-rate code this is the wrong way around, because the dual has far fewer codewords: weight_distribution therefore computes the dual distribution and applies the MacWilliams transform automatically when that is cheaper.

The complete weight distribution refines the Hamming distribution by recording how many coordinates take each field value, so it is only interesting over non-binary fields, and it reduces to the Hamming version by summing over the nonzero values.

Plotting requires a Makie backend to be loaded.

CodingTheory.HammingWeightEnumeratorMethod
HammingWeightEnumerator(
    cwe::CodingTheory.CompleteWeightEnumerator
) -> HammingWeightEnumerator

Reduces a Complete Weight Enumerator down to a Homogeneous Hamming Weight Enumerator.

source
AbstractAlgebra.polynomialMethod
polynomial(
    cwe::CodingTheory.CompleteWeightEnumerator,
    R
) -> Any

Converts the CompleteWeightEnumerator into an Oscar multivariate polynomial. Requires an MPolyRing R with at least q variables (e.g., z0, z1, ..., z_{q-1}).

source
AbstractAlgebra.polynomialMethod
polynomial(hwe::HammingWeightEnumerator, R) -> Any

Converts the HammingWeightEnumerator into an actual Oscar polynomial. Requires a bivariate polynomial ring R, e.g., R, (x, y) = PolynomialRing(ZZ, ["x", "y"]).

source
CodingTheory.KrawtchoukMethod
Krawtchouk(i::Int64, j::Int64, n::Int64, q::Int64) -> BigInt

Return the value of the Krawtchouk polynomial $P_i(j; n, q)$.

source
CodingTheory.MacWilliams_HWE_transformMethod
MacWilliams_HWE_transform(
    input_hwe::Dict{Int64, BigInt},
    n::Int64,
    k_in::Int64,
    q::Int64
) -> Dict{Int64, BigInt}

Return the dual Hamming weight distribution of input_hwe by applying the MacWilliams identity via Krawtchouk polynomials.

source
CodingTheory.complete_weight_distributionMethod
complete_weight_distribution(
    C::AbstractLinearCode;
    verbose
) -> Any

Return the complete weight distribution as a Dict{Tuple, BigInt} mapping field-element frequencies to codeword counts.

source
CodingTheory.complete_weight_enumeratorMethod
complete_weight_enumerator(
    C::AbstractLinearCode;
    verbose
) -> Any

Return the cached complete weight enumerator of C, computing its complete weight distribution when necessary.

source
CodingTheory.weight_distributionMethod
weight_distribution(C::AbstractLinearCode; verbose) -> Any

Return the cached or newly computed Hamming weight distribution as a Dict{Int, BigInt}.

source
CodingTheory.weight_distribution_arrayMethod
weight_distribution_array(
    C::AbstractLinearCode;
    verbose
) -> Any

Return the Hamming weight distribution as a Vector{BigInt} of length n + 1, where entry i is the number of codewords of weight i - 1.

source
CodingTheory.weight_enumeratorMethod
weight_enumerator(C::AbstractLinearCode; verbose) -> Any

Retrieves the cached Hamming Weight Enumerator, or builds it from the distribution. Return a HammingWeightEnumerator struct.

source
CodingTheory.weight_enumeratorMethod
weight_enumerator(C::CodingTheory.DirectSumCode) -> Any

Return the exact Hamming weight enumerator of a direct-sum code, computed by discrete convolution.

source
CodingTheory.weight_plotFunction
weight_plot(C::AbstractLinearCode; alg::Symbol = :auto)

Return a bar graph of the weight distribution of C.

Note

  • Run using Makie to activate this extension.
source
CodingTheory.words_of_minimum_weightMethod
words_of_minimum_weight(
    C::AbstractLinearCode;
    expand,
    verbose
) -> Tuple{Any, Any}

Return the minimum weight and all codewords of that weight, computed in one pass with an engine selected for the field size.

source
CodingTheory.words_of_weightMethod
words_of_weight(
    C::AbstractLinearCode,
    w::Int64;
    kwargs...
) -> Vector

Fallback to extract codewords of a single specific weight w.

source
CodingTheory.words_of_weightMethod
words_of_weight(
    C::AbstractLinearCode,
    w_range::UnitRange{Int64};
    max_span,
    expand,
    verbose
) -> Vector

Extracts all codewords whose weight falls within w_range (e.g., 1:4). Dynamically routes to a Trellis Traceback sweep for low-complexity codes, or a bit-packed DFS for dense codes.

source

The MacWilliams transform

The transform maps the Hamming weight distribution of a code to that of its dual by evaluating Krawtchouk polynomials. MacWilliams_transform works on a HammingWeightEnumerator and MacWilliams_HWE_transform on a raw weight-to-multiplicity dictionary; both keep exact BigInt coefficients.

Distributions from a trellis

A trellis gives a second route to the weight distribution that does not enumerate codewords one at a time; see Trellises.