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.HammingWeightEnumerator — Method
HammingWeightEnumerator(
cwe::CodingTheory.CompleteWeightEnumerator
) -> HammingWeightEnumerator
Reduces a Complete Weight Enumerator down to a Homogeneous Hamming Weight Enumerator.
AbstractAlgebra.polynomial — Method
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}).
AbstractAlgebra.polynomial — Method
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"]).
CodingTheory.Krawtchouk — Method
Krawtchouk(i::Int64, j::Int64, n::Int64, q::Int64) -> BigInt
Return the value of the Krawtchouk polynomial $P_i(j; n, q)$.
CodingTheory.MacWilliams_HWE_transform — Method
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.
CodingTheory.MacWilliams_transform — Method
MacWilliams_transform(
input_hwe::HammingWeightEnumerator,
k_in::Int64,
q::Int64
) -> HammingWeightEnumerator
Return the dual Hamming weight enumerator of input_hwe by applying the MacWilliams identity. Delegates to MacWilliams_HWE_transform over the internal dictionary.
CodingTheory.complete_weight_distribution — Method
complete_weight_distribution(
C::AbstractLinearCode;
verbose
) -> Any
Return the complete weight distribution as a Dict{Tuple, BigInt} mapping field-element frequencies to codeword counts.
CodingTheory.complete_weight_enumerator — Method
complete_weight_enumerator(
C::AbstractLinearCode;
verbose
) -> Any
Return the cached complete weight enumerator of C, computing its complete weight distribution when necessary.
CodingTheory.weight_distribution — Method
weight_distribution(C::AbstractLinearCode; verbose) -> Any
Return the cached or newly computed Hamming weight distribution as a Dict{Int, BigInt}.
CodingTheory.weight_distribution_array — Method
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.
CodingTheory.weight_enumerator — Method
weight_enumerator(C::AbstractLinearCode; verbose) -> Any
Retrieves the cached Hamming Weight Enumerator, or builds it from the distribution. Return a HammingWeightEnumerator struct.
CodingTheory.weight_enumerator — Method
weight_enumerator(C::CodingTheory.DirectSumCode) -> Any
Return the exact Hamming weight enumerator of a direct-sum code, computed by discrete convolution.
CodingTheory.weight_plot — Function
weight_plot(C::AbstractLinearCode; alg::Symbol = :auto)Return a bar graph of the weight distribution of C.
Note
- Run
using Makieto activate this extension.
CodingTheory.words_of_minimum_weight — Method
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.
CodingTheory.words_of_weight — Method
words_of_weight(
C::AbstractLinearCode,
w::Int64;
kwargs...
) -> Vector
Fallback to extract codewords of a single specific weight w.
CodingTheory.words_of_weight — Method
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.
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.