Documentation

CslibFrontier.Foundations.Data.Code.DuplicatedReedMuller

The duplicated first-order Reed–Muller code used by HQC #

HQC uses the binary first-order Reed–Muller code RM(1, 7), with parameters [128, 8, 64], as its inner code. Each encoded byte is repeated μ times; the HQC-1 parameter set uses μ = 3, while HQC-3 and HQC-5 use μ = 5. This gives the [384, 8, 192] and [640, 8, 320] duplicated codes [HQC2026, §3.5.3, pp. 32–37].

The source decoder sums the repeated received bits, applies the Walsh–Hadamard transform, subtracts 64 * μ from its constant coefficient, and scans the coefficient magnitudes using a strict comparison. Consequently the first (smallest) index wins a tie. A positive selected coefficient sets the most significant message bit.

The byte layout is the one specified immediately before RM.Encode on p. 32 and in its lines 2–5 on p. 34: byte bit 7 is the affine constant and byte bits 0,…,6 are the coefficients of the corresponding binary column bits. drmEncode matches the repetition in dRM.Encode, lines 2–6 (p. 33); drmExpandAndSum matches dRM.Decode.ExpandAndSum, lines 2–6 (p. 35); drmHadamardTransform and the zero-coefficient correction match dRM.Decode.Hadamard, lines 4–15 (p. 36); and drmFindPeak/drmDecode match the strict scan and sign step in dRM.Decode.FindPeaks, lines 4–12 (p. 37).

This module exposes the typed bit-word and source-byte-layout mathematics of that codec. Packing whole messages into byte arrays and the shortened Reed–Solomon outer code are separate layers. In particular, it does not yet compose the actual outer decoder or establish the Model-2 calculation in §6.1.4, Equation (9), or the numerical failure probabilities in Table 16.

Main definitions #

Main results #

References #

A byte for RM(1, 7): the most significant bit is the affine constant and the remaining seven bits select the linear character.

  • sign : Bool

    The most significant source-byte bit.

  • slope : BitString 7

    The seven low source-byte bits, read least-significant bit first.

Instances For

    A source byte is equivalently its sign bit paired with its seven low bits.

    The exact source-byte layout: the sign is bit 7 (the most significant bit), while slope coordinate i is byte bit i for 0 ≤ i < 7.

    @[reducible, inline]

    The 128 evaluation points of RM(1, 7).

    @[reducible, inline]

    One RM(1, 7) codeword.

    @[reducible, inline]
    abbrev Cslib.Code.DRMWord (μ : ℕ) :

    A Reed–Muller word repeated μ times.

    The source's RM.Encode: evaluate the affine Boolean function named by the byte.

    The source generator-matrix multiplication, stated in byte coordinates: byte bit 7 multiplies the all-one row, while byte bit i multiplies coordinate i of the binary column. Thus this also records the reversal between the source's top-to-bottom matrix rows and its least-significant-bit-first byte indices.

    The source's dRM.Encode: repeat the same RM(1, 7) word μ times.

    @[simp]
    theorem Cslib.Code.rmEncode_zero_slope (b : Bool) :
    rmEncode { sign := b, slope := 0 } = fun (x : RMPoint) => b

    RM.Encode with zero slope is the constant sign word.

    The encoder is the Hadamard word shifted by the source byte's most significant bit.

    The 128 points of RM(1, 7).

    A duplicated word has 128 * μ bits.

    @[simp]
    theorem Cslib.Code.drmEncode_apply (μ : ℕ) (m : RMMessage) (r : Fin μ) (x : RMPoint) :
    drmEncode μ m (r, x) = rmEncode m x

    Duplication does not change the bit within any repeated block.

    def Cslib.Code.drmExpandAndSum {μ : ℕ} (w : DRMWord μ) (x : RMPoint) :

    The source's dRM.Decode.ExpandAndSum: count the received one-bits at each of the 128 positions across all duplicated blocks.

    def Cslib.Code.walshSign {n : ℕ} (a x : BitString n) :

    A Walsh character, represented by +1 for Boolean inner product zero and -1 for one.

    The in-place butterfly computation in dRM.Decode.Hadamard, expressed recursively: first combine adjacent entries (coordinate 0, the least significant index bit), then perform the remaining stages on the two resulting halves. At width 7 this is exactly the source's seven Walsh–Hadamard rounds.

    The staged transform computes the direct Walsh correlation. This pins the source's butterfly implementation to the mathematical transform used in the decoder proof.

    The corrected Walsh–Hadamard coefficient used by the source decoder. The subtraction at the zero slope is line 15 of dRM.Decode.Hadamard.

    theorem Cslib.Code.drmHadamardCoeff_eq_hammingDist_sub {μ : ℕ} (w : DRMWord μ) (a : RMPoint) :
    drmHadamardCoeff w a = ↑(hammingDist (drmEncode μ { sign := false, slope := a }) w) - 64 * ↑μ

    The corrected coefficient at a is the distance from the received word to the unsigned affine word of slope a, centered at half the duplicated block length.

    The largest absolute corrected Hadamard coefficient.

    Slopes attaining the largest corrected coefficient magnitude.

    The source's strict left-to-right peak scan: the smallest slope attaining maximum absolute coefficient.

    If slope zero attains the maximum magnitude, the strict left-to-right scan returns it, including when other slopes tie it.

    The selected peak has coefficient magnitude at least that of every slope.

    theorem Cslib.Code.drmHadamardCoeff_encode (μ : ℕ) (m : RMMessage) :
    drmHadamardCoeff (drmEncode μ m) m.slope = if m.sign = true then 64 * ↑μ else -(64 * ↑μ)

    At the encoded slope, the corrected coefficient is -64 * μ for a clear source sign bit and 64 * μ for a set sign bit. This pins the source decoder's coefficient-sign convention.

    The source's deterministic best-effort duplicated Reed–Muller decoder.

    The source decoder chooses a nearest duplicated Reed–Muller codeword. Its strict peak update fixes one deterministic member when several messages are tied.

    Distinct affine RM(1, 7) messages have Hamming distance at least 64.

    Duplication multiplies the inner Reed–Muller distance by its parameter μ.

    theorem Cslib.Code.hammingDist_drmEncode_of_slope_ne (μ : ℕ) {m m' : RMMessage} (hslopes : m.slope ≠ m'.slope) :
    hammingDist (drmEncode μ m) (drmEncode μ m') = 64 * μ

    Messages with distinct slopes are exactly 64 * μ bits apart, independently of their sign bits. Thus the lower bound is attained for every positive multiplicity.

    theorem Cslib.Code.sixtyFour_mul_le_hammingDist_drmEncode (μ : ℕ) {m m' : RMMessage} (hmm' : m ≠ m') :
    64 * μ ≤ hammingDist (drmEncode μ m) (drmEncode μ m')

    Distinct messages in the multiplicity-μ code are at distance at least 64 * μ.

    theorem Cslib.Code.drmDecode_add_eq_of_two_mul_weight_lt {μ : ℕ} (m : RMMessage) (error : DRMWord μ) (herror : 2 * BitString.weight error < 64 * μ) :
    drmDecode (drmEncode μ m + error) = m

    Unique decoding below half distance. The actual HQC duplicated Reed–Muller decoder recovers a message after adding any error word whose weight e satisfies 2 * e < 64 * μ.

    For every positive multiplicity, decoding is a left inverse to duplicated encoding.