Fact-checked by Grok 2 weeks ago

Hadamard code

The Hadamard code is a linear error-correcting code of length $2^m, dimension m, and minimum distance $2^{m-1} over the \mathbb{F}_2, named after the mathematician due to its construction involving Hadamard matrices. It belongs to the family of Reed-Muller codes and is the even-weight subcode of the first-order Reed-Muller code RM(1,m). It is notable for achieving a relative distance of $1/2, which is asymptotically optimal for codes with positive rate. This structure allows it to correct up to $2^{m-2} - 1 errors in a received word of length $2^m. The code is constructed by identifying codewords with linear functions over \mathbb{F}_2^m: for a message x \in \mathbb{F}_2^m, the corresponding codeword \mathrm{Enc}(x) is the vector of length $2^m whose a-th entry (indexed by a \in \mathbb{F}_2^m) is the inner product \langle x, a \rangle = \sum_{i=1}^m x_i a_i \pmod{2}. Equivalently, the generator matrix G is a $2^m \times m matrix whose rows are all distinct vectors in \mathbb{F}_2^m, ensuring the code spans all such evaluations. This linear encoding yields a code with rate R = m / 2^m, which decreases exponentially with m, prioritizing high distance over efficiency. Key properties of the Hadamard code include its perfect linearity and orthogonality derived from Hadamard matrices of order $2^m, where the parity-check matrix can be formed from the rows of a normalized Hadamard matrix (with entries \pm 1 mapped to $0/1). It supports efficient local decoding and correction algorithms that query only O(1) positions to recover the message with high probability against up to a $1/4 - \eta fraction of errors, making it valuable in theoretical computer science for proofs like the PCP theorem. Historically, variants have been applied in deep-space communications, such as NASA's 1969 Mariner missions for reliable image transmission over noisy channels.

Fundamentals

Definition

The Hadamard code is a over the GF(2), specifically a with parameters [2^k, k, 2^{k-1}]_2 for a positive integer k, where the length is $2^k, the dimension is k, and the minimum is $2^{k-1}. The codewords correspond to the evaluations of all possible inner products of a message vector x \in \{0,1\}^k with every vector y \in \{0,1\}^k. The encoding function is defined as \mathrm{Had}(x) = \left( \langle x, y \rangle \mod 2 \right)_{y \in \{0,1\}^k}, where the inner product \langle x, y \rangle = \sum_{i=1}^k x_i y_i \mod 2. For example, when k=2, assuming the vectors y are ordered lexicographically as $00, 01, 10, 11, the codewords are $0000 (for x=00), $0011 (for x=10), $0101 (for x=01), and $0110 (for x=11); this forms a [4, 2, 2]_2 code. An augmented version of the Hadamard code extends the dimension by including the all-ones vector, resulting in parameters [2^k, k+1, 2^{k-1}]_2 while preserving the length and distance. This augmentation can be achieved by incorporating the complements of the original codewords into the . The Hadamard code generalizes constructions based on Hadamard matrices, which provide orthogonal bases for higher-order variants.

Parameters

The Hadamard code is a characterized by a block length of n = 2^k, where k is both the (number of bits) and the parameter defining the code size. The minimum is d = 2^{k-1}, ensuring that any two distinct codewords differ in exactly half of the positions. All non-zero codewords have a constant of precisely $2^{k-1}. The coding rate is R = \frac{k}{2^k}, which decreases exponentially with k, reflecting the code's emphasis on high over density. The relative \delta = \frac{d}{n} = \frac{1}{2} remains constant across all k, achieving optimality in the Plotkin bound for codes with relative at least \frac{1}{2}. These parameters stem from the inner product construction, where each codeword corresponds to the parity-check evaluations of all possible vectors in \mathbb{F}_2^k.
knDimensiond
1211
3834
532516

Historical Background

Origins in Hadamard Matrices

A of order n is an n \times n H whose entries are either +1 or -1 and satisfies the condition H H^T = n I_n, where I_n is the n \times n . This orthogonality condition implies that the rows (and similarly the columns) of H are mutually vectors in \mathbb{R}^n. The Hadamard conjecture posits that such matrices exist for all positive integers n = 1, 2, or n a multiple of 4. Each row of H has Euclidean norm \sqrt{n}, as the inner product of a row with itself is n, and the inner product between any two distinct rows is 0, reflecting their perfect orthogonality. An early example of constructing such matrices was provided by Sylvester in 1867 through a recursive doubling method. In the context of , Hadamard matrices are often normalized to by mapping entries of +1 to 0 and -1 to 1, yielding a over the alphabet \{0,1\} that preserves the underlying orthogonal structure for .

Development and Early Applications

The foundations of Hadamard matrices, which underpin Hadamard codes, trace back to the work of English mathematician , who in 1867 introduced a doubling construction for generating such matrices from smaller ones, initially describing them as "anallagmatic pavements." French mathematician further advanced their study in 1893, proving a bound on the maximum of these matrices with entries restricted to -1 and 1, which highlighted their orthogonal properties and laid the groundwork for later applications in . These matrices transitioned from to practical error-correcting codes in the mid-20th century, as researchers recognized their utility in constructing codes with high minimum distance for reliable data transmission over noisy channels. A pivotal early application occurred in 1971 during NASA's , where a [32,6,16] —derived from a 32×32 —was employed to encode data, including of the Martian surface, enabling correction of up to 7 errors per 32-bit codeword in the presence of deep-space noise. This bi-orthogonal Reed-Muller code variant provided a coding gain of approximately 2.2 dB and was selected for its simplicity and effectiveness in low-rate . Decoding was performed using specialized hardware known as the "Green Machine," which implemented the fast Walsh-Hadamard transform (FWHT) to efficiently compute correlations between received signals and codewords, achieving near-maximum-likelihood performance with minimal computational overhead. Following the Mariner missions, Hadamard codes saw limited continued use in deep-space through the , but their adoption declined post-1990s as convolutional codes, particularly rate-1/2 variants with Viterbi decoding, offered superior performance for higher data rates and became the standard in missions like Voyager (1977 onward). Despite this shift in practical engineering applications, Hadamard codes endured in theoretical due to their optimal parameters and role in bounding constructions like the Plotkin bound. They also relate briefly to Walsh codes, which adapt Hadamard matrices for orthogonal spreading in communication systems.

Constructions

Inner Product Construction

The Hadamard code can be constructed as the image of the evaluation map from the vector space of linear functions over \mathbb{F}_2^k to \mathbb{F}_2^{2^k}. Specifically, for each message vector a \in \mathbb{F}_2^k, the corresponding codeword is given by \mathrm{ev}(f_a) = (f_a(y))_{y \in \mathbb{F}_2^k}, where f_a(x) = \langle a, x \rangle denotes the inner product modulo 2. This yields a linear code of length n = 2^k and dimension k, as the codewords are precisely the evaluations of all linear functions (including the zero function) over \mathbb{F}_2^k. The generator matrix G for this code is a k \times 2^k matrix over \mathbb{F}_2 whose columns are all distinct vectors in \mathbb{F}_2^k, ordered arbitrarily (e.g., in lexicographical order). A codeword for message a is then a G = (\langle a, y \rangle)_{y \in \mathbb{F}_2^k}, confirming the inner product interpretation. This matrix form directly implements the evaluation map, with each column corresponding to an evaluation point y. For k=3, the length is n=8 and the G has 3 rows and 8 columns listing all 3-bit vectors as columns:
Column index01234567
Row 100001111
Row 200110011
Row 301010101
This generates the [8, 3] where each nonzero codeword has weight 4.

Generator Matrix Construction

The generator matrix of the Hadamard code admits a systematic form, with rows corresponding to basis vectors representing linear functions over the vector space \mathbb{F}_2^m and columns indexing all evaluation points in \{0,1\}^m. For the basic Hadamard code of length n = 2^m and dimension m, the m \times 2^m generator matrix G has entries G_{i,j} equal to the i-th bit of the binary representation of the index j (for j = 0, \dots, 2^m - 1), ensuring that codewords are evaluations of linear polynomials at these points. This matrix arises from the recursive Sylvester construction of Hadamard matrices, which begins with H_1 = {{grok:render&&&type=render_inline_citation&&&citation_id=1&&&citation_type=wikipedia}} and proceeds as H_{2^k} = \begin{pmatrix} H_{2^{k-1}} & H_{2^{k-1}} \\ H_{2^{k-1}} & -H_{2^{k-1}} \end{pmatrix} for k \geq 1, yielding a matrix of order $2^m with orthogonal rows of equal . To derive the binary generator matrix, map entries of H_{2^m} by replacing +1 with $0 and -1 with $1, then take the row space over \mathbb{F}_2; the resulting code is generated by any m linearly independent rows, such as those aligned with the coordinate functions in the systematic form above. For the augmented Hadamard code, prepend or append an all-ones row to G, extending the dimension to m+1 while preserving the length $2^m and incorporating an overall parity check; this yields the first-order Reed-Muller code \mathrm{RM}(1,m). Codewords in this construction are constant on the cosets of hyperplanes in \mathbb{F}_2^m, as each corresponds to the evaluation of an , which remains invariant along translates of its kernel. The inner product construction offers an equivalent perspective on the same code.

Hadamard Matrix Construction

A general construction of Hadamard codes utilizes an n \times n H with entries in \{\pm 1\}, where the rows of H are pairwise orthogonal and each has norm \sqrt{n}. To form the code of length $2n, construct the [H \mid -H], whose n rows are vectors in \{\pm 1\}^{2n}. Include the n rows of the matrix [-H \mid H] to obtain a total of $2n vectors. Map each entry via +1 \mapsto 0 and -1 \mapsto 1 to yield codewords in \{0,1\}^{2n}. This produces a constant-weight code with each codeword of weight n and minimum n, equivalent to a [2n, \log_2(2n), n]_2 code in the nonlinear sense (with dimension approximately \log_2 n). The orthogonality of the rows in H ensures that any two distinct vectors from the augmented set have inner product 0 over \mathbb{R}, leading to exactly n positions of disagreement after the sign mapping, confirming the minimum distance n. For orders n that are powers of 2 via the Sylvester construction, this code is linear over \mathrm{GF}(2) with exact dimension \log_2(2n). In general, the code's existence requires a Hadamard matrix of order n, which is known to exist for n=1, 2 and all multiples of 4 up to large values, per the Hadamard conjecture; constructions for non-power-of-two orders often rely on conference matrices, as a symmetric conference matrix of order n \equiv 2 \pmod{4} yields a Hadamard matrix of order $2(n+1). As an example, consider the Sylvester Hadamard matrix of order n=4: H_4 = \begin{pmatrix} 1 & 1 & 1 & 1 \\ 1 & -1 & 1 & -1 \\ 1 & 1 & -1 & -1 \\ 1 & -1 & -1 & 1 \end{pmatrix}. The rows of [H_4 \mid -H_4] and [-H_4 \mid H_4], after mapping, produce the 8 codewords of the [8, 3, 4]_2 Hadamard code, including vectors like $00001111, $00110011, and their complements in the set, matching the parameters of the power-of-two construction. This code corrects up to 1 error and detects up to 3. When the order n = 2^{m-1}, puncturing this Hadamard code by removing the coordinate corresponding to the zero vector yields the simplex code of length $2^m - 1, dimension m, and distance $2^{m-1}, a maximal-distance linear code related to Reed-Muller codes.

Properties

Hamming Distance

The minimum Hamming distance of the Hadamard code is d = 2^{k-1}. Since the code is linear over \mathbb{F}_2, this distance equals the minimum weight of any nonzero codeword. For a nonzero codeword c = \text{Had}(x) with x \in \{0,1\}^k \setminus \{0\}, the weight \mathrm{wt}(c) is the number of positions y \in \{0,1\}^k where \langle x, y \rangle = 1 over \mathbb{F}_2. The inner product \langle x, y \rangle defines a nontrivial linear functional on \mathbb{F}_2^k, which takes value 1 on exactly half the elements of the space, or $2^{k-1} positions, because the kernel of the functional has index 2. For any two distinct codewords \text{Had}(x) and \text{Had}(x'), their sum is \text{Had}(x + x'), where x + x' \neq 0, so the is \mathrm{wt}(\text{Had}(x + x')) = 2^{k-1}. Equivalently, the codewords agree in exactly $2^{k-1} coordinates and differ in the remaining $2^{k-1}, as the linear functionals defined by x and x' agree on a of 1. The relative distance is thus \delta = d / n = 2^{k-1} / 2^k = 1/2. This constant relative distance implies that the code can correct up to $2^{k-2} - 1 errors via nearest-neighbor decoding. The following table illustrates the minimum d relative to the block n = 2^k for small values of k:
knd
121
242
384
4168
53216

Duality and Weights

The Hadamard code is the subcode of the Reed-Muller code RM(1,m) consisting of the evaluations of homogeneous linear functions over \mathbb{F}_2^m (i.e., without ). It is self-orthogonal for m \geq 3, satisfying C \subseteq C^\perp. The dual code C^\perp has dimension $2^m - m and can be described as the set of all vectors orthogonal to the linear functionals, which includes the constant functions and higher-degree terms in the Reed-Muller hierarchy. The of the Hadamard is : all have either (the codeword) or $2^{m-1}, with no intermediate weights possible. There are exactly $2^m - 1 nonzero codewords, each of constant $2^{m-1}, which classifies the code as a constant-weight code for nonzero elements (two-weight including ) and contributes to its optimality in certain detection scenarios. This follows directly from the of s over \mathbb{F}_2^m, where each nonzero takes the value 1 on precisely half the input points. A key property is the inner product between codewords. For distinct nonzero x, z \in \mathbb{F}_2^m, the inner product satisfies \langle \mathrm{Had}(x), \mathrm{Had}(z) \rangle = 2^{m-2} \pmod{2}, which equals 0 modulo 2 for m \geq 3. For x = z \neq 0, it is $2^{m-1} \pmod{2} = 0 for m \geq 2. This confirms self-orthogonality for m \geq 3. The Hadamard code has all even-weight codewords due to the balanced nature of the linear functions.

Decoding

Local Decodability

A (q, \delta, \varepsilon)-locally decodable code (LDC) is an error-correcting code that encodes a k-bit message x into an n-bit codeword c = C(x), such that for any position i \in and any received word r = c + e with |e| \leq \delta n (where + denotes componentwise addition over \mathbb{F}_2), there exists a randomized A_i that queries at most q positions of r and outputs x_i with success probability at least $1 - \varepsilon. The Hadamard code, which encodes a k-bit message into an n = 2^k-bit codeword with coordinates indexed by vectors y \in \mathbb{F}_2^k where C(x)_y = \langle x, y \rangle (the inner product over \mathbb{F}_2), is a (2, \delta, 2\delta)-LDC for all \delta \leq 1/4. This local decodability leverages the code's minimum of n/2, enabling tolerance to error rates up to \delta = 1/4 in the worst case. Lemma 1. For any non-zero x \in \mathbb{F}_2^k, \Pr_{y \sim \mathbb{F}_2^k} [\langle x, y \rangle = 1] = 1/2. Proof of Lemma 1. The inner product \langle x, y \rangle defines a non-constant functional on \mathbb{F}_2^k. Since y is chosen uniformly at random, the distribution of \langle x, y \rangle is uniform over \mathbb{F}_2, yielding the stated probability. The proof of local decodability follows from the of the and of inner products. To recover the i-th message bit x_i = \langle x, e_i \rangle (where e_i is the i-th ), the decoder samples a uniform random y \in \mathbb{F}_2^k, queries the received word r at positions y and y + e_i, and outputs r_y + r_{y + e_i}. If both positions are uncorrupted, then r_y + r_{y + e_i} = \langle x, y \rangle + \langle x, y + e_i \rangle = \langle x, e_i \rangle = x_i by of the inner product. For any fixed e with |e| \leq \delta n, the probability over y that at least one queried position is corrupted is at most $2\delta by the union bound, since each queried position is equally likely to be any coordinate. Thus, the success probability is at least $1 - 2\delta, as required.

Decoding Algorithm

The local decoding algorithm for the Hadamard code enables recovery of the i-th bit of the message x \in \{0,1\}^k from a noisy received word r = \mathrm{Had}(x) + e, where \mathrm{Had}(x)_y = \langle x, y \rangle \pmod{2} for y \in \{0,1\}^k and e has Hamming weight at most \delta n with \delta \leq 1/4. This 2-query decoder, which underlies the Goldreich-Levin hardcore predicate, operates by selecting a random vector y \in \{0,1\}^k conditioned on y_i = 1 and querying positions r_y and r_{y \oplus e_i}, where e_i is the i-th standard basis vector. The output \hat{a} = r_y \oplus r_{y \oplus e_i} equals x_i \oplus (e_y \oplus e_{y \oplus e_i}), so \hat{a} = x_i if and only if e_y = e_{y \oplus e_i}. The query pairs \{y, y \oplus e_i\} with y_i=1 form a perfect matching of the hypercube, partitioning the n positions into n/2 disjoint pairs differing only in the i-th coordinate. For any fixed adversarial e with |e| \leq \delta n, the fraction of pairs where exactly one position is corrupted (leading to failure) is at most $2\delta, since each error affects exactly one pair. Thus, the worst-case success probability of a single trial is at least $1 - 2\delta. For \delta \leq 1/4, this yields \Pr[\hat{a} = x_i] \geq 1/2, with bias \gamma = 1/2 - 2\delta \geq 0 over random guessing. This can be amplified via repetition: perform s = O\left( \frac{\log(1/\epsilon)}{\gamma^2} \right) independent trials and output the majority vote, succeeding with probability at least $1 - \epsilon by standard concentration bounds (e.g., Chernoff). For constant \epsilon (e.g., $1/3) and fixed \delta < 1/4 (constant \gamma > 0), s = O(\log(1/\epsilon)) = O(1); more generally, for \delta = 1/4 - \eta, \gamma = \Theta(\eta) and total queries are O(1/\eta^2). The algorithm requires O(1) queries per (hence O(s) total queries, constant for fixed \eta, \epsilon) and runs in time in k, as each step involves O(k)-time operations for generation and XOR; the fast Walsh-Hadamard transform is unnecessary for this local procedure but enables global decoding in O(2^k) time if full recovery is desired. Here is for decoding the i-th bit with amplification:
function LocalDecode(r, i, s):  // r: query access to received word, i: bit index, s: # repetitions
    votes = []  // List to collect trial outputs
    for j = 1 to s:
        y = random [vector](/page/Vector) in {0,1}^k with y_i = 1  // Uniform over 2^{k-1} choices
        z = y ⊕ e_i  // Flip i-th bit of y
        r_y = query r at y
        r_z = query r at z
        a_hat = r_y ⊕ r_z
        append a_hat to votes
    return majority of votes  // 0 if ≤ s/2 ones, else 1
For illustration, consider k=2 and x = (1,0), so \mathrm{Had}(x) = (0, 0, 1, 1) indexed by y=00,01,10,11. With a single error e at position $11(i.e.,r = (0,0,1,0)and\delta=1/4), decoding x_1=1 (i=1) yields correct output with probability 1/2: random ywithy_1=1 is &#36;10 (queries r_{10}=1, r_{00}=0, \hat{a}=1 \oplus 0 = 1, correct) or $11(queriesr_{11}=0, r_{01}=0, \hat{a}=0 \oplus 0 = 0, incorrect) each with probability 1/2. Repetition via majority over s trials boosts success to near &#36;1 as s grows.

Advanced Topics

Optimality

The Hadamard code of length n = 2^k and k achieves a minimum d = 2^{k-1}, corresponding to relative distance \delta = 1/2. This meets the Plotkin bound with equality for codes attaining these parameters, as the bound states that A(n, n/2) \leq 2n, and the code's size $2^k = n saturates the bound in the linear setting for this . For k \leq 7, the Hadamard code is the unique (up to equivalence) optimal linear with parameters [2^k, k, 2^{k-1}], meaning no other linear code of the same length and achieves a larger distance, by classification results on equidistant linear codes via Bonisoli's . For larger k, the Hadamard code remains near-optimal but can be outperformed in tradeoffs between and by advanced constructions, such as algebraic-geometric codes that achieve superior parameters for certain high-rate regimes over finite fields. In the context of locally decodable codes (LDCs), the Hadamard code serves as an optimal 2-query LDC for constant relative \delta > 0, with decoding radius up to $1/4 - \epsilon for any \epsilon > 0. Its $2^k matches the information-theoretic lower bound of \exp(\Omega(k)) up to constant factors, establishing it as asymptotically optimal among 2-query linear LDCs. To illustrate optimality for small dimensions, the following table compares the Hadamard code with the (binary) and Reed-Solomon code (non-binary, over \mathbb{F}_{2^3}) for comparable small lengths:
CodeLength nDimension kDistance dRate R = k/nRelative \delta = d/n
Hadamard (k=3)8340.3750.5
Extended Hamming8440.50.5
Hamming (m=3)743≈0.571≈0.429
Reed-Solomon744≈0.571≈0.571

Generalizations and Applications

Generalized Hadamard codes extend the framework to q-ary alphabets over finite fields GF(q), where q is a . These codes are constructed using generalized Hadamard matrices H(q, λ) of order qλ over GF(q), defined such that for any distinct rows i and j, the of differences {h_{is} - h_{js} : 1 ≤ s ≤ qλ} contains every element of GF(q) exactly λ times. The resulting code C_H, formed by the rows of H and their translations by elements of GF(q), achieves self-orthogonality for q > 3 or specific cases like q=3 with gcd(3, λ) ≠ 1, leading to dimension bounds like rank ≤ ⌊n/2⌋ for length n = qλ and meeting Plotkin-type bounds on minimum distance. Non-binary extensions also arise through bent functions generalized to p-ary alphabets, where p is prime. P-ary bent functions maximize nonlinearity via their Walsh-Hadamard transform S_f(u) = ∑_{v ∈ ℤ_p^n} ζ_p^{f(v) - u · v}, with ζ_p a primitive p-th , producing flat spectra analogous to cases. These functions yield q-ary Hadamard-like codes with optimal properties, useful for constructing constant-amplitude codes in multi-code division multiple access systems. Recent advancements include generalizations over Eisenstein integers in local rings ℤ_{2^s}[ω], where ω is a primitive cube root of unity satisfying ω² + ω + 1 = 0. These codes employ Gray mapping to binary representations, enabling classification based on linearity criteria and kernel structures, with applications in advanced error-correcting schemes. Such constructions, published in 2025, enhance data transmission reliability in complex algebraic settings. In wireless communications, Walsh-Hadamard sequences serve as orthogonal spreading codes in code-division multiple access (CDMA) systems, particularly for quasi-synchronous multi-code transmission. Assigned to users, these sequences of length 2^m ensure zero even cross-correlation across time shifts, minimizing inter-user interference and improving bit error rate (BER) performance in mobile environments, though they require multipath mitigation. The fast Walsh-Hadamard transform (FWHT) finds applications in signal processing and image compression, decomposing signals into orthogonal Walsh basis functions for efficient entropy reduction. In lossless image coding, a unified integer FWHT on blocks up to 8×8 minimizes entropy when coefficients are encoded jointly, outperforming smaller transforms in pyramid structures while avoiding multiplication operations for computational efficiency. Hadamard codes relate to cryptography through their association with difference sets and bent functions, which construct secure components like S-boxes. Hadamard difference sets from these matrices provide balanced, highly nonlinear mappings satisfying the strict avalanche criterion, resisting in block ciphers and hash functions such as . Theoretically, Hadamard codes underpin probabilistically checkable proofs (PCPs) by encoding functions into long linear forms testable for consistency with low query complexity. In PCP constructions for Circuit-SAT, the Walsh-Hadamard code enables soundness amplification via linearity tests, implying of approximation for problems like MAX-3SAT within factors close to 1, such as 1 - 1/20. In modern low-rate space communications, Hadamard codes persist in inter-satellite ranging for small satellites like , using spreading in frames to achieve meter-level accuracy and resilience to Doppler shifts up to 16 kHz, with 16 dB coding gain via integration.